fix #6437 Generate title caches to avoid outdated information
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / selection / EntitySelectionElement.java
index 0f6aecbbd1ac530046506c5f0f376d4877d95341..30ebf05424735d0362dbfb1c6fc614e09cd73e48 100644 (file)
@@ -31,7 +31,7 @@ import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
 import eu.etaxonomy.cdm.model.common.User;
 import eu.etaxonomy.cdm.model.molecular.Amplification;
 import eu.etaxonomy.cdm.model.molecular.Primer;
-import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
+import eu.etaxonomy.cdm.model.reference.Reference;
 import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
 import eu.etaxonomy.taxeditor.model.ImageResources;
 import eu.etaxonomy.taxeditor.preference.Resources;
@@ -58,7 +58,8 @@ import eu.etaxonomy.taxeditor.ui.section.grantedAuthority.GrantedAuthorityLabelT
  * @param <T>
  */
 public class EntitySelectionElement<T extends CdmBase> extends
-               AbstractCdmFormElement implements  SelectionListener, IEnableableFormElement, ISelectableElement, IEntityElement<T>, ILabeledElement, IConversationEnabled, Observer {
+               AbstractCdmFormElement implements  SelectionListener, IEnableableFormElement, ISelectableElement, IEntityElement<T>, ILabeledElement, //IConversationEnabled,
+               Observer {
 
        private static final EnumSet<CRUD> UPDATE = EnumSet.of(CRUD.UPDATE);
        private static final EnumSet<CRUD> DELETE = EnumSet.of(CRUD.DELETE);
@@ -67,12 +68,13 @@ public class EntitySelectionElement<T extends CdmBase> extends
        /**
         * Bitmask for configuring functionality of selection element
         */
-       public static final int NOTHING = 0; // 000
-       public static final int EDITABLE = 1 << 0; // 001
-       public static final int DELETABLE = 1 << 1; // 010
-       public static final int SELECTABLE = 1 << 2; // 100
-       public static final int ALL = EDITABLE | DELETABLE | SELECTABLE; // 111
-
+       public static final int NOTHING = 0; // 0000
+       public static final int EDITABLE = 1 << 0; // 0001
+       public static final int DELETABLE = 1 << 1; // 0010
+       public static final int SELECTABLE = 1 << 2; // 0100
+       public static final int EXTERNAL = 1 << 3; // 1000
+       public static final int ALL = EDITABLE | DELETABLE | SELECTABLE ; // 0111
+       public static final int ALL_WITH_EXT = EDITABLE | DELETABLE | SELECTABLE | EXTERNAL ; // 1111
        protected T entity;
        protected T filteredEntity;
 
@@ -80,6 +82,8 @@ public class EntitySelectionElement<T extends CdmBase> extends
        protected Text text;
        protected Button button_selection;
 
+       protected Button button_selectionExt;
+
        private SelectionArbitrator selectionArbitrator;
 
        protected Button button_edit;
@@ -93,23 +97,26 @@ public class EntitySelectionElement<T extends CdmBase> extends
        private final boolean isEditable;
 
        private final boolean isDeletable;
+       private final boolean isExternal;
 
-       private final ConversationHolder conversation;
+//     private final ConversationHolder conversation;
        private Class<T> clazz;
 
        public EntitySelectionElement(CdmFormFactory formFactory,
-                       ConversationHolder conversation, ICdmFormElement parentElement, Class<T> clazz,
+//                     ConversationHolder conversation,
+               ICdmFormElement parentElement, Class<T> clazz,
                        String labelString, T entity, int mode, int style, boolean filterElement) {
                super(formFactory, parentElement);
 
                this.clazz = clazz;
                this.isEditable = (mode & EDITABLE) == EDITABLE;
                this.isDeletable = (mode & DELETABLE) == DELETABLE;
+               this.isExternal= (mode & EXTERNAL) == EXTERNAL;
                boolean isSelectable = (mode & SELECTABLE) == SELECTABLE;
 
                this.labelString = (labelString == null || labelString.equals("")) ? "" : labelString;
 
-               this.conversation = conversation;
+//             this.conversation = conversation;
 
                if (isSelectable && formFactory.getSelectionProvider() != null) {
                        selectionArbitrator = formFactory.createSelectionArbitrator(this);
@@ -128,10 +135,11 @@ public class EntitySelectionElement<T extends CdmBase> extends
 
     }
 
-    public EntitySelectionElement(CdmFormFactory formFactory,
-            ConversationHolder conversation, ICdmFormElement parentElement, Class<T> clazz,
+    public EntitySelectionElement(CdmFormFactory formFactory,//ConversationHolder conversation,
+             ICdmFormElement parentElement, Class<T> clazz,
             String labelString, T entity, int mode, int style){
-        this(formFactory, conversation, parentElement, clazz, labelString, entity, mode, style, false);
+        this(formFactory, //conversation,
+                parentElement, clazz, labelString, entity, mode, style, false);
     }
 
        private void createControls(Composite parent, int style) {
@@ -150,6 +158,9 @@ public class EntitySelectionElement<T extends CdmBase> extends
                if (isDeletable) {
                        columns += 1;
                }
+               if (isExternal) {
+            columns += 1;
+        }
 
                selectableComposite.setLayout(LayoutConstants.LAYOUT(columns, false));
                selectableComposite.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
@@ -172,7 +183,16 @@ public class EntitySelectionElement<T extends CdmBase> extends
 
                addControl(button_selection);
                button_selection.addSelectionListener(this);
-
+               if (isExternal){
+               button_selectionExt = formFactory.createButton(selectableComposite, null,
+                    SWT.PUSH);
+               button_selectionExt.setImage(ImageResources
+                    .getImage(ImageResources.BROWSE_ICON));
+               button_selectionExt.setToolTipText("Browse existing from external cdm store");
+               button_selectionExt.setText("Ext");
+            addControl(button_selectionExt);
+            button_selectionExt.addSelectionListener(this);
+               }
                if (isEditable) {
                        button_edit = formFactory.createButton(selectableComposite, null,
                                        SWT.PUSH);
@@ -196,8 +216,16 @@ public class EntitySelectionElement<T extends CdmBase> extends
 
        @Override
     public void widgetSelected(SelectionEvent e) {
-               T selection = SelectionDialogFactory.getSelectionFromDialog(clazz, getShell(), getConversationHolder(), getFilteredEntity(), getParentElement());
-               setSelectionInternal(selection);
+           if (e.getSource().equals(button_selection) ){
+               T selection = SelectionDialogFactory.getSelectionFromDialog(clazz, getShell(), //getConversationHolder(),
+                       getFilteredEntity(), getParentElement());
+            setSelectionInternal(selection);
+           }else{
+               Reference selection = SelectionDialogFactory.getSelectionFromExtDialog(Reference.class, getShell(),//null,
+                       getParentElement());
+            setSelectionInternal((T)selection);
+           }
+
        }
 
        /**
@@ -437,9 +465,12 @@ public class EntitySelectionElement<T extends CdmBase> extends
         * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
         *         object.
         */
-       @Override
+//     @Override
        public ConversationHolder getConversationHolder() {
-               return conversation;
+           if(getParentElement() instanceof IConversationEnabled) {
+            return ((IConversationEnabled)getParentElement()).getConversationHolder();
+        }
+           return null;
        }
 
        /** {@inheritDoc} */
@@ -474,9 +505,9 @@ public class EntitySelectionElement<T extends CdmBase> extends
        }
 
        /** {@inheritDoc} */
-       @Override
-       public void update(CdmDataChangeMap changeEvents) {
-       }
+//     @Override
+//     public void update(CdmDataChangeMap changeEvents) {
+//     }
 
        /* (non-Javadoc)
         * @see eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement#removeElements()