19 package com.generalrobotix.ui.view;
22 import java.util.Properties;
24 import org.eclipse.jface.action.Action;
25 import org.eclipse.jface.action.MenuManager;
26 import org.eclipse.jface.dialogs.InputDialog;
27 import org.eclipse.jface.viewers.CellEditor;
28 import org.eclipse.jface.viewers.ColumnWeightData;
29 import org.eclipse.jface.viewers.ComboBoxCellEditor;
30 import org.eclipse.jface.viewers.ICellModifier;
31 import org.eclipse.jface.viewers.ILabelProviderListener;
32 import org.eclipse.jface.viewers.IStructuredContentProvider;
33 import org.eclipse.jface.viewers.ITableLabelProvider;
34 import org.eclipse.jface.viewers.TableLayout;
35 import org.eclipse.jface.viewers.TableViewer;
36 import org.eclipse.jface.viewers.TextCellEditor;
37 import org.eclipse.jface.viewers.Viewer;
38 import org.eclipse.jface.viewers.ViewerSorter;
39 import org.eclipse.swt.SWT;
40 import org.eclipse.swt.custom.CCombo;
41 import org.eclipse.swt.events.KeyEvent;
42 import org.eclipse.swt.events.KeyListener;
43 import org.eclipse.swt.events.SelectionEvent;
44 import org.eclipse.swt.events.SelectionListener;
45 import org.eclipse.swt.graphics.Image;
46 import org.eclipse.swt.layout.GridData;
47 import org.eclipse.swt.layout.GridLayout;
48 import org.eclipse.swt.widgets.Composite;
49 import org.eclipse.swt.widgets.Event;
50 import org.eclipse.swt.widgets.Listener;
51 import org.eclipse.swt.widgets.Table;
52 import org.eclipse.swt.widgets.TableColumn;
53 import org.eclipse.swt.widgets.TableItem;
54 import org.eclipse.swt.widgets.Text;
67 @SuppressWarnings(
"serial")
73 public static final String TITLE =
"Property";
77 private TableViewer viewer_ =
null;
79 private Table table_ =
null;
81 private Text nameText_ =
null;
82 private String oldText =
"";
86 private MenuManager menuMgr_=
new MenuManager();
101 super(name, manager, vp, parent);
105 GridLayout gl =
new GridLayout(1,
false);
106 composite_.setLayout( gl );
108 nameText_ =
new Text(composite_, SWT.SINGLE|SWT.BORDER);
109 GridData textGridData =
new GridData(GridData.FILL_HORIZONTAL);
110 textGridData.heightHint = 20;
111 nameText_.setLayoutData(textGridData);
114 nameText_.addKeyListener(
new KeyListener(){
115 public void keyPressed(KeyEvent e) {}
116 public void keyReleased(KeyEvent e) {
117 if (e.character == SWT.CR && !nameText_.getText().equals(oldText)) {
119 if ((p = manager_.getView(nameText_.getText(),
true)) !=
null){
120 if(currentPlugin_ != p){
121 if(currentPlugin_ !=
null)
127 }
else if ((p = manager_.getItem(nameText_.getText())) !=
null){
130 nameText_.setText(
"");
131 if(currentPlugin_ !=
null)
134 currentPlugin_ =
null;
140 viewer_ =
new TableViewer(composite_, SWT.MULTI | SWT.FULL_SELECTION
141 | SWT.BORDER | SWT.VIRTUAL);
143 TableLayout layout =
new TableLayout();
144 layout.addColumnData(
new ColumnWeightData(40,
true));
145 layout.addColumnData(
new ColumnWeightData(60,
true));
146 table_ = viewer_.getTable();
147 table_.setLayout(layout);
148 GridData tableGridData =
new GridData(GridData.FILL_BOTH);
149 table_.setLayoutData(tableGridData);
151 TableColumn column1 =
new TableColumn(table_, SWT.LEFT);
152 TableColumn column2 =
new TableColumn(table_, SWT.LEFT);
153 column1.setText(clmName_[0]);
154 column2.setText(clmName_[1]);
155 column1.setMoveable(
true);
156 column2.setMoveable(
true);
160 viewer_.setColumnProperties(clmName_);
164 CellEditor[] editors =
new CellEditor[] {
165 new TextCellEditor(table_),
166 new TextCellEditor(table_) };
167 viewer_.setCellEditors(editors);
171 table_.setLinesVisible(
true);
172 table_.setHeaderVisible(
true);
174 setScrollMinSize(SWT.DEFAULT,SWT.DEFAULT);
177 manager_.registerItemChangeListener(
this,
GrxBaseItem.class);
180 table_.setMenu(menuMgr_.createContextMenu( table_ ));
181 table_.addListener ( SWT.MenuDetect,
new Listener () {
182 public void handleEvent (Event event) {
183 final TableItem[] selection = table_.getSelection();
184 menuMgr_.removeAll();
185 if(selection.length!=0)
186 menuMgr_.add(
new Action(){
189 InputDialog dialog =
new InputDialog(
null,
getText(),
191 if ( dialog.open() == InputDialog.OK && dialog.getValue() !=
null){
192 String _value = dialog.getValue();
193 String[] _key =
new String[selection.length];
194 for(
int i=0;
i<selection.length;
i++){
195 _key[
i] = selection[
i].getText(0);
197 for(
int i=0;
i<_key.length;
i++){
198 if(isValidChangeValue(_key[
i], _value) ==
false)
201 if(!currentPlugin_.getProperty(_key[i]).
equals(_value)){
218 if(currentPlugin_!=
null)
220 currentPlugin_ = manager_.focusedItem();
221 _setInput(currentPlugin_);
222 if(currentPlugin_ !=
null)
231 String[] items = ((ValueEditCombo)editType).GetItems();
232 for(
int idx=0; idx<items.length; idx++){
233 if(items[idx].equals(value)){
245 if(currentPlugin_ != item){
246 if(currentPlugin_ !=
null)
249 currentPlugin_ =
item;
254 if(currentPlugin_ == item){
257 currentPlugin_ =
null;
266 if((String)
arg[0]!=
"PropertyChange")
272 IStructuredContentProvider {
276 return ((Properties)inputElement).entrySet().toArray();
278 return new Object[0];
284 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
297 if (element instanceof Map.Entry && columnIndex < clmName_.length) {
298 switch (columnIndex) {
300 str = (String) ((Map.Entry)element).getKey();
303 str = (String) ((Map.Entry)element).getValue();
330 public boolean canModify(Object element, String property) {
333 if(property.equals(clmName_[1])){
334 if (element instanceof Map.Entry) {
335 Map.Entry<String, String> _element = (Map.Entry)element;
336 if(_element.getKey().equals(
"url"))
340 CellEditor[] editors =
new CellEditor[] {
341 new TextCellEditor(table_),
342 new ComboBoxCellEditor(table_, ((ValueEditCombo) editType).GetItems()) };
343 viewer_.setCellEditors(editors);
345 CellEditor[] editors =
new CellEditor[] {
346 new TextCellEditor(table_),
347 new TextCellEditor(table_) };
348 viewer_.setCellEditors(editors);
358 public Object
getValue(Object element, String property) {
359 if (property.equals(clmName_[1]) &&
360 element instanceof Map.Entry) {
361 Map.Entry<String, String> _element = (Map.Entry)element;
362 CellEditor[] ce = viewer_.getCellEditors();
363 if(2 <= ce.length && ce[1] instanceof ComboBoxCellEditor){
364 String[] items = ((ComboBoxCellEditor)ce[1]).getItems();
365 for(
int i=0;
i<items.length;
i++)
366 if(_element.getValue().equals(items[
i]))
367 return new Integer(i);
368 return new Integer(0);
370 return _element.getValue();
376 @SuppressWarnings(
"unchecked")
377 public
void modify(Object element, String property, Object
value) {
379 if (element instanceof TableItem){
380 TableItem
item = (TableItem) element;
381 String _value =
null;
382 if( value instanceof String) {
383 _value = (String)value;
384 }
else if(value instanceof Integer){
385 int idx = ((Integer)value).intValue();
386 CellEditor[] ce = viewer_.getCellEditors();
387 if(2 <= ce.length && ce[1] instanceof ComboBoxCellEditor){
389 String[] items = ((ComboBoxCellEditor)ce[1]).getItems();
390 if(0 <= idx && idx < items.length)
394 String str = ((CCombo)ce[1].getControl()).
getText();
395 for(
int i = 0;
i < items.length;
i++)
397 if(items[
i].equals(str))
408 !currentPlugin_.getProperty(item.getText()).equals(_value)){
411 currentPlugin_.
setProperty(item.getText(), _value);
416 }
catch(Exception ex){
417 ex.printStackTrace();
425 table_.setVisible(
false);
426 nameText_.setText(
"");
428 }
else if (p != currentPlugin_) {
429 table_.setVisible(
false);
430 nameText_.setText(p.
getName());
433 table_.setVisible(
true);
440 table_.setVisible(
false);
441 nameText_.setText(currentPlugin_.getName());
442 oldText=currentPlugin_.getName();
443 viewer_.setInput(currentPlugin_);
444 table_.setVisible(
true);
449 public int compare(Viewer viewer, Object e1, Object e2) {
450 Table table = ((TableViewer)viewer).getTable();
451 if(table.getSortColumn() ==
null){
454 TableColumn sortColumn = table.getSortColumn();
455 int direction = table.getSortDirection();
457 String comperedFactor1 =
"";
458 String comperedFactor2 =
"";
460 if(sortColumn.getText().equals(clmName_[0])){
461 comperedFactor1 = (String)((Map.Entry)e1).getKey();
462 comperedFactor2 = (String)((Map.Entry)e2).getKey();
464 else if(sortColumn.getText().equals(clmName_[1])){
465 comperedFactor1 = (String)((Map.Entry)e1).getValue();
466 comperedFactor2 = (String)((Map.Entry)e2).getValue();
472 if (direction == SWT.NONE) {
475 else if(direction == SWT.UP){
476 return comperedFactor1.compareTo(comperedFactor2);
478 else if(direction == SWT.DOWN){
479 return (-1) * comperedFactor1.compareTo(comperedFactor2);
495 TableColumn column = (TableColumn)e.widget;
497 int currentDirection = table_.getSortDirection();
499 if(column != table_.getSortColumn() || currentDirection == SWT.NONE){
500 table_.setSortDirection(SWT.UP);
502 else if(currentDirection == SWT.DOWN){
503 table_.setSortDirection(SWT.NONE);
505 else if(currentDirection == SWT.UP){
506 table_.setSortDirection(SWT.DOWN);
509 table_.setSortDirection(SWT.NONE);
511 table_.setSortColumn(column);
518 manager_.removeItemChangeListener(
this,
GrxBaseItem.class);
519 if(currentPlugin_ !=
null)
520 currentPlugin_.deleteObserver(
this);
boolean canModify(Object element, String property)
static final String get(String key)
boolean propertyChanged(String property, String value)
check validity of new value of property and update if valid
void addObserver(GrxObserver v)
#define null
our own NULL pointer
png_infop png_charpp name
void deleteObserver(GrxObserver v)
boolean equals(Object obj)
check whether obj equals to this
void update(GrxBasePlugin plugin, Object... arg)
Object [] getElements(Object inputElement)
GrxPropertyView(String name, GrxPluginManager manager, GrxBaseViewPart vp, Composite parent)
constructor
ValueEditType GetValueEditType(String key)
Return editing type of the key item.
void registerItemChange(GrxBaseItem item, int event)
static Activator getDefault()
static final int FOCUSED_ITEM
void widgetDefaultSelected(SelectionEvent e)
void inputChanged(Viewer viewer, Object oldInput, Object newInput)
static final int REMOVE_ITEM
void removeListener(ILabelProviderListener listener)
Image getColumnImage(Object element, int columnIndex)
static void println(String s)
Object setProperty(String key, String value)
set property value associated with a keyword
Font getFont(String fontName)
int compare(Viewer viewer, Object e1, Object e2)
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
Object getValue(Object element, String property)
void widgetSelected(SelectionEvent e)
def getText(self, nodes=None)
boolean isValidChangeValue(String key, String value)
final String getName()
get name
boolean isLabelProperty(Object element, String property)
void _refresh()
refresh contents of table
String getColumnText(Object element, int columnIndex)
void addListener(ILabelProviderListener listener)
void _setInput(GrxBasePlugin p)