4 package eu
.etaxonomy
.taxeditor
.propertysheet
;
6 import java
.util
.ArrayList
;
7 import java
.util
.HashSet
;
10 import org
.eclipse
.jface
.action
.Action
;
11 import org
.eclipse
.jface
.viewers
.ArrayContentProvider
;
12 import org
.eclipse
.jface
.viewers
.LabelProvider
;
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
.layout
.FillLayout
;
18 import org
.eclipse
.swt
.layout
.GridData
;
19 import org
.eclipse
.swt
.layout
.GridLayout
;
20 import org
.eclipse
.swt
.widgets
.Button
;
21 import org
.eclipse
.swt
.widgets
.Composite
;
22 import org
.eclipse
.swt
.widgets
.Dialog
;
23 import org
.eclipse
.swt
.widgets
.Display
;
24 import org
.eclipse
.swt
.widgets
.Label
;
25 import org
.eclipse
.swt
.widgets
.Shell
;
26 import org
.eclipse
.swt
.widgets
.Table
;
27 import org
.eclipse
.swt
.widgets
.TableItem
;
28 import org
.eclipse
.swt
.widgets
.Text
;
30 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
31 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
32 import eu
.etaxonomy
.cdm
.model
.description
.TaxonNameDescription
;
33 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
34 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
35 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentation
;
36 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentationPart
;
37 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
43 public class ProtologuesDialog
extends Dialog
{
45 private TableViewer tableViewer
;
46 protected Object result
;
47 protected Shell shell
;
49 // private WritableList list = new WritableList();
50 List
<TextData
> protologues
= new ArrayList
<TextData
>();
51 private TaxonNameBase name
;
52 protected RemoveDescriptionElementAction removeAction
;
53 private TaxonNameDescription description
;
60 public ProtologuesDialog(Shell parent
, int style
) {
68 public ProtologuesDialog(Shell parent
) {
69 this(parent
, SWT
.NONE
);
72 public ProtologuesDialog(Shell parent
, TaxonNameDescription description
) {
73 this(parent
, SWT
.NONE
);
74 this.description
= description
;
75 // FIXME this is a quick and dirty implementation. Will be obsolete with tabbed properties anyways
76 // we are looking for description elements with the feature protolog
77 // TODO this might change very soon because Feature.PROTOLOG is currently in
78 // the set of Taxon features which does not make sense
79 // as we want to be able to enter multiple protologues, we are done with filling the list now
80 for(DescriptionElementBase descriptionElement
: description
.getElements()){
81 if(descriptionElement
.getFeature().equals(Feature
.PROTOLOG())){
82 protologues
.add((TextData
) descriptionElement
);
91 public Object
open() {
95 Display display
= getParent().getDisplay();
96 while (!shell
.isDisposed()) {
97 if (!display
.readAndDispatch())
104 * Create contents of the dialog
106 protected void createContents() {
108 // Create shell for popup dialog
109 shell
= new Shell(getParent(), SWT
.DIALOG_TRIM
| SWT
.APPLICATION_MODAL
);
110 shell
.setLayout(new FillLayout());
111 shell
.setSize(500, 375);
112 shell
.setText("Protologues");
114 // Create composite for entire shell
115 final Composite composite
= new Composite(shell
, SWT
.NONE
);
116 final GridLayout gridLayout
= new GridLayout();
117 gridLayout
.numColumns
= 3;
118 composite
.setLayout(gridLayout
);
120 text
= new Text(composite
, SWT
.BORDER
);
121 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 2, 1));
123 final Button addButton
= new Button(composite
, SWT
.NONE
);
124 addButton
.setLayoutData(new GridData());
125 addButton
.setText("Add");
126 addButton
.addMouseListener(new MouseAdapter() {
128 public void mouseUp(MouseEvent e
) {
129 if (text
.getText().equals("")) {
132 TextData descriptionElement
= createNewProtologMediaElement(text
.getText());
134 protologues
.add(descriptionElement
);
135 description
.addElement(descriptionElement
);
136 tableViewer
.refresh();
141 final Button removeButton
= new Button(composite
, SWT
.NONE
);
142 removeButton
.setLayoutData(new GridData());
143 removeButton
.setText("Remove");
144 removeButton
.setEnabled(false);
145 removeButton
.addMouseListener(new MouseAdapter() {
147 * @see org.eclipse.swt.events.MouseAdapter#mouseDown(org.eclipse.swt.events.MouseEvent)
150 public void mouseUp(MouseEvent e
) {
151 removeDescriptionElement();
155 tableViewer
= new TableViewer(composite
, SWT
.BORDER
| SWT
.MULTI
);
156 Table table
= tableViewer
.getTable();
157 table
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 3, 1));
158 table
.setLinesVisible(false);
159 table
.setHeaderVisible(false);
160 new Label(composite
, SWT
.NONE
);
162 tableViewer
.setContentProvider(new ArrayContentProvider());
164 tableViewer
.setLabelProvider(new LabelProvider() {
166 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
169 public String
getText(Object element
) {
170 DescriptionElementBase descriptionElement
= (DescriptionElementBase
) element
;
172 for(Media media
: descriptionElement
.getMedia()){
173 for(MediaRepresentation mediaRepresentation
: media
.getRepresentations()){
174 for(MediaRepresentationPart mediaRepresentationPart
: mediaRepresentation
.getParts()){
175 return mediaRepresentationPart
.getUri();
183 tableViewer
.setInput(protologues
);
185 // final MenuManager manager = new MenuManager();
186 // final Menu menu = manager.createContextMenu(table);
187 // table.setMenu(menu);
189 // table.addSelectionListener(new SelectionAdapter() {
190 // public void widgetSelected(SelectionEvent e) {
192 // Object data = e.item.getData();
194 // if (data instanceof DescriptionElementBase) {
195 // manager.removeAll();
196 // removeAction = new RemoveDescriptionElementAction();
197 // manager.add(removeAction);
200 // removeButton.setEnabled(true);
204 final Button cancelButton
= new Button(composite
, SWT
.NONE
);
205 cancelButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
206 cancelButton
.setText("Cancel");
207 cancelButton
.addMouseListener(new MouseAdapter() {
209 public void mouseUp(MouseEvent e
) {
214 final Button okButton
= new Button(composite
, SWT
.NONE
);
215 final GridData gd_okButton
= new GridData();
216 okButton
.setLayoutData(gd_okButton
);
217 okButton
.setText("OK");
218 okButton
.addMouseListener(new MouseAdapter() {
220 public void mouseUp(MouseEvent e
) {
221 result
= new HashSet
<TextData
>(protologues
);
227 private TextData
createNewProtologMediaElement(String text
) {
228 TextData descriptionElement
= TextData
.NewInstance(Feature
.PROTOLOG());
230 MediaRepresentationPart mediaRepresentationPart
= MediaRepresentationPart
.NewInstance(text
, 0);
232 MediaRepresentation representation
= MediaRepresentation
.NewInstance("application/pdf", "pdf");
233 representation
.addRepresentationPart(mediaRepresentationPart
);
235 Media media
= Media
.NewInstance();
236 media
.addRepresentation(representation
);
238 descriptionElement
.addMedia(media
);
240 return descriptionElement
;
243 private void removeDescriptionElement() {
244 TableItem
[] selectedItems
= tableViewer
.getTable().getSelection();
245 for (TableItem item
: selectedItems
) {
246 removeDescriptionElement((DescriptionElementBase
) item
.getData());
248 tableViewer
.refresh();
251 private void removeDescriptionElement(DescriptionElementBase descriptionElement
) {
252 protologues
.remove(descriptionElement
);
253 description
.removeElement(descriptionElement
);
256 public class RemoveDescriptionElementAction
extends Action
{
258 RemoveDescriptionElementAction() {
263 removeDescriptionElement();