--- /dev/null
+/**
+ *
+ */
+package eu.etaxonomy.taxeditor.propertysheet;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Dialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
+
+import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
+import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
+import eu.etaxonomy.cdm.model.description.TextData;
+import eu.etaxonomy.cdm.model.media.Media;
+import eu.etaxonomy.cdm.model.media.MediaRepresentation;
+import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
+import eu.etaxonomy.cdm.model.name.TaxonNameBase;
+
+/**
+ * @author nho
+ *
+ */
+public class ProtologuesDialog extends Dialog {
+ private Text text;
+ private TableViewer tableViewer;
+ protected Object result;
+ protected Shell shell;
+
+// private WritableList list = new WritableList();
+ List<TextData> protologues = new ArrayList<TextData>();
+ private TaxonNameBase name;
+ protected RemoveDescriptionElementAction removeAction;
+ private TaxonNameDescription description;
+
+ /**
+ * Create the dialog
+ * @param parent
+ * @param style
+ */
+ public ProtologuesDialog(Shell parent, int style) {
+ super(parent, style);
+ }
+
+ /**
+ * Create the dialog
+ * @param parent
+ */
+ public ProtologuesDialog(Shell parent) {
+ this(parent, SWT.NONE);
+ }
+
+ public ProtologuesDialog(Shell parent, TaxonNameDescription description) {
+ this(parent, SWT.NONE);
+ this.description = description;
+ // FIXME this is a quick and dirty implementation. Will be obsolete with tabbed properties anyways
+ // we are looking for description elements with the feature protolog
+ // TODO this might change very soon because Feature.PROTOLOG is currently in
+ // the set of Taxon features which does not make sense
+ // as we want to be able to enter multiple protologues, we are done with filling the list now
+ for(DescriptionElementBase descriptionElement : description.getElements()){
+ if(descriptionElement.getFeature().equals(Feature.PROTOLOG())){
+ protologues.add((TextData) descriptionElement);
+ }
+ }
+ }
+
+ /**
+ * Open the dialog
+ * @return the result
+ */
+ public Object open() {
+ createContents();
+ shell.open();
+ shell.layout();
+ Display display = getParent().getDisplay();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ return result;
+ }
+
+ /**
+ * Create contents of the dialog
+ */
+ protected void createContents() {
+
+ // Create shell for popup dialog
+ shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
+ shell.setLayout(new FillLayout());
+ shell.setSize(500, 375);
+ shell.setText("Protologues");
+
+ // Create composite for entire shell
+ final Composite composite = new Composite(shell, SWT.NONE);
+ final GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 3;
+ composite.setLayout(gridLayout);
+
+ text = new Text(composite, SWT.BORDER);
+ text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
+
+ final Button addButton = new Button(composite, SWT.NONE);
+ addButton.setLayoutData(new GridData());
+ addButton.setText("Add");
+ addButton.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseUp(MouseEvent e) {
+ if (text.getText().equals("")) {
+ return;
+ }
+ TextData descriptionElement = createNewProtologMediaElement(text.getText());
+
+ protologues.add(descriptionElement);
+ description.addElement(descriptionElement);
+ tableViewer.refresh();
+ text.setText("");
+ }
+ });
+
+ final Button removeButton = new Button(composite, SWT.NONE);
+ removeButton.setLayoutData(new GridData());
+ removeButton.setText("Remove");
+ removeButton.setEnabled(false);
+ removeButton.addMouseListener(new MouseAdapter() {
+ /* (non-Javadoc)
+ * @see org.eclipse.swt.events.MouseAdapter#mouseDown(org.eclipse.swt.events.MouseEvent)
+ */
+ @Override
+ public void mouseUp(MouseEvent e) {
+ removeDescriptionElement();
+ }
+ });
+
+ tableViewer = new TableViewer(composite, SWT.BORDER | SWT.MULTI);
+ Table table = tableViewer.getTable();
+ table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
+ table.setLinesVisible(false);
+ table.setHeaderVisible(false);
+ new Label(composite, SWT.NONE);
+
+ tableViewer.setContentProvider(new ArrayContentProvider());
+
+ tableViewer.setLabelProvider(new LabelProvider() {
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
+ */
+ @Override
+ public String getText(Object element) {
+ DescriptionElementBase descriptionElement = (DescriptionElementBase) element;
+
+ for(Media media : descriptionElement.getMedia()){
+ for(MediaRepresentation mediaRepresentation : media.getRepresentations()){
+ for(MediaRepresentationPart mediaRepresentationPart : mediaRepresentation.getParts()){
+ return mediaRepresentationPart.getUri();
+ }
+ }
+ }
+
+ return null;
+ }
+ });
+ tableViewer.setInput(protologues);
+
+// final MenuManager manager = new MenuManager();
+// final Menu menu = manager.createContextMenu(table);
+// table.setMenu(menu);
+//
+// table.addSelectionListener(new SelectionAdapter() {
+// public void widgetSelected(SelectionEvent e) {
+//
+// Object data = e.item.getData();
+//
+// if (data instanceof DescriptionElementBase) {
+// manager.removeAll();
+// removeAction = new RemoveDescriptionElementAction();
+// manager.add(removeAction);
+// }
+//
+// removeButton.setEnabled(true);
+// }
+// });
+
+ final Button cancelButton = new Button(composite, SWT.NONE);
+ cancelButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ cancelButton.setText("Cancel");
+ cancelButton.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseUp(MouseEvent e) {
+ shell.dispose();
+ }
+ });
+
+ final Button okButton = new Button(composite, SWT.NONE);
+ final GridData gd_okButton = new GridData();
+ okButton.setLayoutData(gd_okButton);
+ okButton.setText("OK");
+ okButton.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseUp(MouseEvent e) {
+ result = new HashSet<TextData>(protologues);
+ shell.dispose();
+ }
+ });
+ }
+
+ private TextData createNewProtologMediaElement(String text) {
+ TextData descriptionElement = TextData.NewInstance(Feature.PROTOLOG());
+
+ MediaRepresentationPart mediaRepresentationPart = MediaRepresentationPart.NewInstance(text, 0);
+
+ MediaRepresentation representation = MediaRepresentation.NewInstance("application/pdf", "pdf");
+ representation.addRepresentationPart(mediaRepresentationPart);
+
+ Media media = Media.NewInstance();
+ media.addRepresentation(representation);
+
+ descriptionElement.addMedia(media);
+
+ return descriptionElement;
+ }
+
+ private void removeDescriptionElement() {
+ TableItem[] selectedItems = tableViewer.getTable().getSelection();
+ for (TableItem item : selectedItems) {
+ removeDescriptionElement((DescriptionElementBase) item.getData());
+ }
+ tableViewer.refresh();
+ }
+
+ private void removeDescriptionElement(DescriptionElementBase descriptionElement) {
+ protologues.remove(descriptionElement);
+ description.removeElement(descriptionElement);
+ }
+
+ public class RemoveDescriptionElementAction extends Action {
+
+ RemoveDescriptionElementAction() {
+ setText("Remove");
+ }
+
+ public void run() {
+ removeDescriptionElement();
+ }
+ }
+}
\r
import eu.etaxonomy.cdm.common.CdmUtils;\r
import eu.etaxonomy.cdm.model.common.Marker;\r
+import eu.etaxonomy.cdm.model.description.TaxonNameDescription;\r
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;\r
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;\r
import eu.etaxonomy.cdm.model.name.NonViralName;\r
import eu.etaxonomy.taxeditor.propertysheet.AnnotationsPropertyDescriptor;\r
import eu.etaxonomy.taxeditor.propertysheet.ICdmBasePropertySource;\r
import eu.etaxonomy.taxeditor.propertysheet.MarkersPropertySource;\r
+import eu.etaxonomy.taxeditor.propertysheet.ProtologuePropertyDescriptor;\r
+import eu.etaxonomy.taxeditor.propertysheet.ProtologuePropertySource;\r
import eu.etaxonomy.taxeditor.propertysheet.reference.NomenclaturalReferencePropertySource;\r
import eu.etaxonomy.taxeditor.propertysheet.reference.ReferencePropertySource;\r
import eu.etaxonomy.taxeditor.propertysheet.reference.ReferenceSearchDescriptor;\r
public static final String P_ID_NAMERELATIONS = "namerelations";\r
public static final String P_ID_TYPE = "type";\r
public static final String P_ID_ANNOTATIONS = "annotations";\r
+ public static final String P_ID_PROTOLOGUES = "protologues";\r
public static final String P_ID_NOMSTATUS = "nomstatus";\r
public static final String P_ID_UUID = "uuid"; \r
public static final String P_ID_NUM_OF_BASES = "numberofbases";\r
public static final String P_NAMERELATIONS = "Name Relations";\r
public static final String P_TYPE = "Type";\r
public static final String P_ANNOTATIONS = "Annotations";\r
+ public static final String P_PROTOLOGUES = "Protologues";\r
public static final String P_NOMSTATUS = "Nomenclatural Status";\r
public static final String P_UUID = "UUID";\r
public static final String P_NUM_OF_BASES = "Number of Bases";\r
P_ID_NOMSTATUS, \r
P_ID_NAMERELATIONS,\r
P_ID_ANNOTATIONS, \r
+ P_ID_PROTOLOGUES,\r
P_ID_CREATED, \r
P_ID_CREATEDBY }; \r
\r
);\r
};\r
\r
+ // Annotations, listed in custom property descriptor\r
+ if (id.equals(P_ID_PROTOLOGUES)) {\r
+ descriptors.addElement(\r
+ new ProtologuePropertyDescriptor(P_ID_PROTOLOGUES, P_PROTOLOGUES, getFirstTaxonNameDescription()) {\r
+ protected void saveProtologue(Set set) {\r
+ setPropertyValue(P_ID_PROTOLOGUES, set);\r
+ }\r
+ }\r
+ );\r
+ };\r
+ \r
// Nomenclatural status\r
if (id.equals(P_ID_NOMSTATUS)) {\r
if (nomStatusTypes == null) {\r
return new AnnotationPropertySource(name);\r
}\r
\r
+ // Protologues, listed in custom property descriptor\r
+ if(id.equals(P_ID_PROTOLOGUES)){\r
+ return new ProtologuePropertySource(getFirstTaxonNameDescription());\r
+ }\r
+ \r
// Nomenclatural status \r
if (id.equals(P_ID_NOMSTATUS)) {\r
Set<NomenclaturalStatus> nomStatusSet = this.name.getStatus();\r
ReferenceType.Generic,\r
ReferenceType.Thesis };\r
}\r
+ /**\r
+ * TODO for the quick and dirty implementation we always assume \r
+ * the first TaxonNameDescription element to be the relevant\r
+ * @return\r
+ */\r
+ private TaxonNameDescription getFirstTaxonNameDescription(){\r
+ // we assume that the first name description holds our information and if there is none we create one\r
+ Set<TaxonNameDescription> descriptions = name.getDescriptions();\r
+ if(descriptions != null && descriptions.iterator().hasNext()){\r
+ return descriptions.iterator().next();\r
+ }else{\r
+ return TaxonNameDescription.NewInstance(name);\r
+ }\r
+ }\r
}\r