1 package com.generalrobotix.ui.grxui;
4 import java.util.ArrayList;
5 import java.util.Iterator;
7 import org.eclipse.jface.dialogs.InputDialog;
8 import org.eclipse.jface.preference.PreferencePage;
9 import org.eclipse.jface.viewers.ArrayContentProvider;
10 import org.eclipse.jface.viewers.CellEditor;
11 import org.eclipse.jface.viewers.CheckboxCellEditor;
12 import org.eclipse.jface.viewers.ICellModifier;
13 import org.eclipse.jface.viewers.IStructuredSelection;
14 import org.eclipse.jface.viewers.ITableColorProvider;
15 import org.eclipse.jface.viewers.ITableLabelProvider;
16 import org.eclipse.jface.viewers.LabelProvider;
17 import org.eclipse.jface.viewers.TableViewer;
18 import org.eclipse.jface.viewers.TextCellEditor;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.events.SelectionEvent;
21 import org.eclipse.swt.events.SelectionListener;
22 import org.eclipse.swt.graphics.Color;
23 import org.eclipse.swt.graphics.Image;
24 import org.eclipse.swt.layout.GridData;
25 import org.eclipse.swt.layout.GridLayout;
26 import org.eclipse.swt.widgets.Button;
27 import org.eclipse.swt.widgets.Composite;
28 import org.eclipse.swt.widgets.Control;
29 import org.eclipse.swt.widgets.Table;
30 import org.eclipse.swt.widgets.TableColumn;
31 import org.eclipse.ui.IWorkbench;
32 import org.eclipse.ui.IWorkbenchPreferencePage;
37 TableViewer viewer_=
null;
38 ArrayList<Item> input_=
null;
39 String oldValue_=
null;
47 parent.setLayout(
new GridLayout(2,
false));
49 viewer_ =
new TableViewer(parent, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
50 viewer_.setContentProvider(
new ArrayContentProvider());
53 Table table = viewer_.getTable();
54 String[] properties =
new String[]{
"class",
"classPath",
"visible" };
55 viewer_.setColumnProperties(properties);
56 CellEditor[] editors =
new CellEditor[]{
57 new TextCellEditor(table),
58 new TextCellEditor(table),
59 new CheckboxCellEditor(table)
61 viewer_.setCellEditors(editors);
63 table.setLinesVisible(
true);
64 table.setHeaderVisible(
true);
66 TableColumn column =
new TableColumn(table, SWT.NONE);
68 column =
new TableColumn(table, SWT.NONE);
70 column =
new TableColumn(table,SWT.NONE);
72 viewer_.setInput(input_);
74 TableColumn[] columns = table.getColumns();
75 for(
int i = 0;
i < columns.length;
i++) {
79 final Composite buttons =
new Composite(parent, SWT.NONE);
80 GridData layoutData =
new GridData();
81 layoutData.verticalAlignment = GridData.FILL;
82 buttons.setLayoutData(layoutData);
83 buttons.setLayout(
new GridLayout());
85 Button addButton =
new Button(buttons, SWT.PUSH);
86 layoutData =
new GridData();
87 layoutData.horizontalAlignment = GridData.FILL;
88 addButton.setLayoutData(layoutData);
90 addButton.addSelectionListener(
new SelectionListener() {
91 public void widgetSelected(SelectionEvent e) {
92 InputDialog dialog =
new InputDialog( buttons.getShell(),
MessageBundle.
get(
"PreferenceItemPage.dialog.title"),
94 if(dialog.open()==InputDialog.OK){
95 String
name = dialog.getValue();
97 input_.add(
new Item(name,
"",
"true",
true));
102 public void widgetDefaultSelected(SelectionEvent e) {
106 Button delButton =
new Button(buttons, SWT.PUSH);
107 layoutData =
new GridData();
108 layoutData.horizontalAlignment = GridData.FILL;
109 delButton.setLayoutData(layoutData);
111 delButton.addSelectionListener(
new SelectionListener() {
112 public void widgetSelected(SelectionEvent e) {
113 Item item = (
Item) ((IStructuredSelection) viewer_.getSelection()).getFirstElement();
119 public void widgetDefaultSelected(SelectionEvent e) {
123 return viewer_.getControl();
131 for(
int i=0;
i<item.length;
i++){
132 input_.add(
new Item(item[
i],
"", visible[i],
false));
140 for(
int i=0;
i<item.length;
i++){
141 if(!item[
i].equals(
""))
142 input_.add(
new Item(item[
i], path[i], visible[i],
true));
146 public void init(IWorkbench workbench) {
147 input_ =
new ArrayList<Item>();
158 public Item(String
name, String path, String visible,
boolean isUser){
161 visible_=visible.equals(
"true")? true :
false;
166 private class ItemLabelProvider extends LabelProvider implements ITableLabelProvider, ITableColorProvider {
173 switch (columnIndex) {
179 return item.
visible_==
true?
"true" :
"false";
203 this.viewer = viewer;
206 public boolean canModify(Object element, String property) {
214 public Object
getValue(Object element, String property) {
216 if (property ==
"class")
218 if (property ==
"classPath")
220 if (property ==
"visible")
225 public void modify(Object element, String property, Object
value) {
226 if (element instanceof
org.eclipse.swt.widgets.Item) {
227 element = ((
org.eclipse.swt.widgets.Item) element).getData();
230 if(property ==
"class") {
231 item.
name_=(String)value;
233 if(property ==
"classPath") {
234 item.
path_=(String)value;
236 if(property ==
"visible") {
239 viewer.update(element,
null);
247 Iterator<Item> it = input_.iterator();
253 visible += item.
visible_?
"true" :
"false";
264 getPreferenceStore().firePropertyChangeEvent(
"userItemChange", oldValue_, name);
static final String USERITEM
static final String VISIBLE
static final String get(String key)
#define null
our own NULL pointer
boolean canModify(Object element, String property)
void init(IWorkbench workbench)
void modify(Object element, String property, Object value)
png_infop png_charpp name
Control createContents(Composite parent)
Color getBackground(Object element, int columnIndex)
static final String SEPARATOR
static Activator getDefault()
static final String CLASSPATH
Object getValue(Object element, String property)
Image getColumnImage(Object element, int columnIndex)
Color getForeground(Object element, int columnIndex)
Item(String name, String path, String visible, boolean isUser)
CellModifier(TableViewer viewer)
static final String CLASS
String getColumnText(Object element, int columnIndex)