1 package eu
.etaxonomy
.taxeditor
.propertysheet
;
3 import java
.util
.HashSet
;
6 import org
.eclipse
.core
.databinding
.beans
.BeansObservables
;
7 import org
.eclipse
.core
.databinding
.observable
.list
.WritableList
;
8 import org
.eclipse
.core
.databinding
.observable
.map
.IObservableMap
;
9 import org
.eclipse
.jface
.action
.Action
;
10 import org
.eclipse
.jface
.action
.MenuManager
;
11 import org
.eclipse
.jface
.databinding
.viewers
.ObservableListContentProvider
;
12 import org
.eclipse
.jface
.databinding
.viewers
.ObservableMapLabelProvider
;
13 import org
.eclipse
.jface
.viewers
.TableViewer
;
14 import org
.eclipse
.swt
.SWT
;
15 import org
.eclipse
.swt
.events
.MouseAdapter
;
16 import org
.eclipse
.swt
.events
.MouseEvent
;
17 import org
.eclipse
.swt
.events
.SelectionAdapter
;
18 import org
.eclipse
.swt
.events
.SelectionEvent
;
19 import org
.eclipse
.swt
.layout
.FillLayout
;
20 import org
.eclipse
.swt
.layout
.GridData
;
21 import org
.eclipse
.swt
.layout
.GridLayout
;
22 import org
.eclipse
.swt
.widgets
.Button
;
23 import org
.eclipse
.swt
.widgets
.Composite
;
24 import org
.eclipse
.swt
.widgets
.Dialog
;
25 import org
.eclipse
.swt
.widgets
.Display
;
26 import org
.eclipse
.swt
.widgets
.Label
;
27 import org
.eclipse
.swt
.widgets
.Menu
;
28 import org
.eclipse
.swt
.widgets
.Shell
;
29 import org
.eclipse
.swt
.widgets
.Table
;
30 import org
.eclipse
.swt
.widgets
.Text
;
32 import eu
.etaxonomy
.cdm
.model
.common
.AnnotatableEntity
;
33 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
35 public class AnnotationsDialog
extends Dialog
{
39 protected Object result
;
40 protected Shell shell
;
42 private WritableList list
= new WritableList();
43 private AnnotatableEntity entity
;
50 public AnnotationsDialog(Shell parent
, int style
) {
58 public AnnotationsDialog(Shell parent
) {
59 this(parent
, SWT
.NONE
);
62 public AnnotationsDialog(Shell parent
, AnnotatableEntity entity
) {
63 this(parent
, SWT
.NONE
);
65 Set
<Annotation
> annotations
= entity
.getAnnotations();
66 for (Annotation annotation
: annotations
) {
75 public Object
open() {
79 Display display
= getParent().getDisplay();
80 while (!shell
.isDisposed()) {
81 if (!display
.readAndDispatch())
88 * Create contents of the dialog
90 protected void createContents() {
92 // Create shell for popup dialog
93 shell
= new Shell(getParent(), SWT
.DIALOG_TRIM
| SWT
.APPLICATION_MODAL
);
94 shell
.setLayout(new FillLayout());
95 shell
.setSize(500, 375);
96 shell
.setText("Annotations");
98 // Create composite for entire shell
99 final Composite composite
= new Composite(shell
, SWT
.NONE
);
100 final GridLayout gridLayout
= new GridLayout();
101 gridLayout
.numColumns
= 3;
102 composite
.setLayout(gridLayout
);
104 text
= new Text(composite
, SWT
.BORDER
);
105 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 2, 1));
107 final Button addButton
= new Button(composite
, SWT
.NONE
);
108 addButton
.setLayoutData(new GridData());
109 addButton
.setText("Add");
110 addButton
.addMouseListener(new MouseAdapter() {
112 public void mouseDown(MouseEvent e
) {
113 if (text
.getText().equals("")) {
116 Annotation annotation
= Annotation
.NewInstance(text
.getText(), null);
117 list
.add(annotation
);
118 entity
.addAnnotation(annotation
);
123 final TableViewer tableViewer
= new TableViewer(composite
, SWT
.BORDER
| SWT
.MULTI
);
124 table
= tableViewer
.getTable();
125 table
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 3, 1));
126 table
.setLinesVisible(false);
127 table
.setHeaderVisible(false);
128 new Label(composite
, SWT
.NONE
);
130 ObservableListContentProvider providerList
= new ObservableListContentProvider();
131 tableViewer
.setContentProvider(providerList
);
133 IObservableMap
[] providerMaps
= BeansObservables
.observeMaps(
134 providerList
.getKnownElements(), Annotation
.class, new String
[]{"text"});
135 tableViewer
.setLabelProvider(new ObservableMapLabelProvider(providerMaps
));
136 tableViewer
.setInput(list
);
138 final MenuManager manager
= new MenuManager();
139 final Menu menu
= manager
.createContextMenu(table
);
142 table
.addSelectionListener(new SelectionAdapter() {
143 public void widgetSelected(SelectionEvent e
) {
145 Object data
= e
.item
.getData();
147 if (data
instanceof Annotation
) {
149 manager
.add(new RemoveAnnotationAction((Annotation
) data
));
154 final Button cancelButton
= new Button(composite
, SWT
.NONE
);
155 cancelButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
156 cancelButton
.setText("Cancel");
157 cancelButton
.addMouseListener(new MouseAdapter() {
159 public void mouseUp(MouseEvent e
) {
164 final Button okButton
= new Button(composite
, SWT
.NONE
);
165 final GridData gd_okButton
= new GridData();
166 okButton
.setLayoutData(gd_okButton
);
167 okButton
.setText("OK");
168 okButton
.addMouseListener(new MouseAdapter() {
170 public void mouseUp(MouseEvent e
) {
171 result
= new HashSet
<Object
>(list
);
177 public class RemoveAnnotationAction
extends Action
{
179 private Annotation annotation
;
181 RemoveAnnotationAction(Annotation annotation
) {
183 this.annotation
= annotation
;
187 list
.remove(annotation
);
188 entity
.removeAnnotation(annotation
);