ref #5828 abbrevTitle and titlecache are displayed in nomenclatural selectionDialogs
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / selection / CdmFilteredItemsSelectionDialog.java
index 1180e7ce0179c8d90f97e3bdbbc30dd04529d19f..b0883e1941179100f579cc0e693d37e6cd902091 100644 (file)
@@ -524,7 +524,7 @@ public abstract class CdmFilteredItemsSelectionDialog extends SelectionStatusDia
                 public void keyTraversed(TraverseEvent e) {
                     if (e.detail == SWT.TRAVERSE_MNEMONIC && e.doit) {
                         e.detail = SWT.TRAVERSE_NONE;
-                        list.getTable().setFocus();
+                        getList().getTable().setFocus();
                     }
                 }
             });
@@ -612,7 +612,7 @@ public abstract class CdmFilteredItemsSelectionDialog extends SelectionStatusDia
          * @since 3.5
          */
         protected void fillContextMenu(IMenuManager menuManager) {
-            List selectedElements= ((StructuredSelection)list.getSelection()).toList();
+            List selectedElements= ((StructuredSelection)getList().getSelection()).toList();
 
             Object item= null;
 
@@ -645,7 +645,7 @@ public abstract class CdmFilteredItemsSelectionDialog extends SelectionStatusDia
                 }
             });
 
-            final Table table = list.getTable();
+            final Table table = getList().getTable();
             Menu menu= contextMenuManager.createContextMenu(table);
             table.setMenu(menu);
         }
@@ -693,9 +693,9 @@ public abstract class CdmFilteredItemsSelectionDialog extends SelectionStatusDia
 
             final Label listLabel = createLabels(content);
 
-            list = new TableViewer(content, (multi ? SWT.MULTI : SWT.SINGLE)
-                    | SWT.BORDER | SWT.V_SCROLL | SWT.VIRTUAL);
-            list.getTable().getAccessible().addAccessibleListener(
+            setList(new TableViewer(content, (multi ? SWT.MULTI : SWT.SINGLE)
+                    | SWT.BORDER | SWT.V_SCROLL | SWT.VIRTUAL));
+            getList().getTable().getAccessible().addAccessibleListener(
                     new AccessibleAdapter() {
                         @Override
                         public void getName(AccessibleEvent e) {
@@ -705,14 +705,14 @@ public abstract class CdmFilteredItemsSelectionDialog extends SelectionStatusDia
                             }
                         }
                     });
-            list.setContentProvider(contentProvider);
-            list.setLabelProvider(getItemsListLabelProvider());
-            list.setInput(new Object[0]);
-            list.setItemCount(contentProvider.getNumberOfElements());
+            getList().setContentProvider(contentProvider);
+            getList().setLabelProvider(getItemsListLabelProvider());
+            getList().setInput(new Object[0]);
+            getList().setItemCount(contentProvider.getNumberOfElements());
             gd = new GridData(GridData.FILL_BOTH);
-            applyDialogFont(list.getTable());
-            gd.heightHint= list.getTable().getItemHeight() * 15;
-            list.getTable().setLayoutData(gd);
+            applyDialogFont(getList().getTable());
+            gd.heightHint= getList().getTable().getItemHeight() * 15;
+            getList().getTable().setLayoutData(gd);
 
             createPopupMenu();
 
@@ -727,14 +727,14 @@ public abstract class CdmFilteredItemsSelectionDialog extends SelectionStatusDia
                 @Override
                 public void keyPressed(KeyEvent e) {
                     if (e.keyCode == SWT.ARROW_DOWN) {
-                        if (list.getTable().getItemCount() > 0) {
-                            list.getTable().setFocus();
+                        if (getList().getTable().getItemCount() > 0) {
+                            getList().getTable().setFocus();
                         }
                     }
                 }
             });
 
-            list.addSelectionChangedListener(new ISelectionChangedListener() {
+            getList().addSelectionChangedListener(new ISelectionChangedListener() {
                 @Override
                 public void selectionChanged(SelectionChangedEvent event) {
                     StructuredSelection selection = (StructuredSelection) event
@@ -743,20 +743,20 @@ public abstract class CdmFilteredItemsSelectionDialog extends SelectionStatusDia
                 }
             });
 
-            list.addDoubleClickListener(new IDoubleClickListener() {
+            getList().addDoubleClickListener(new IDoubleClickListener() {
                 @Override
                 public void doubleClick(DoubleClickEvent event) {
                     handleDoubleClick();
                 }
             });
 
-            list.getTable().addKeyListener(new KeyAdapter() {
+            getList().getTable().addKeyListener(new KeyAdapter() {
                 @Override
                 public void keyPressed(KeyEvent e) {
 
                     if (e.keyCode == SWT.DEL) {
 
-                        List selectedElements = ((StructuredSelection) list
+                        List selectedElements = ((StructuredSelection) getList()
                                 .getSelection()).toList();
 
                         Object item = null;
@@ -779,20 +779,20 @@ public abstract class CdmFilteredItemsSelectionDialog extends SelectionStatusDia
 
                     if (e.keyCode == SWT.ARROW_UP && (e.stateMask & SWT.SHIFT) != 0
                             && (e.stateMask & SWT.CTRL) != 0) {
-                        StructuredSelection selection = (StructuredSelection) list
+                        StructuredSelection selection = (StructuredSelection) getList()
                                 .getSelection();
 
                         if (selection.size() == 1) {
                             Object element = selection.getFirstElement();
-                            if (element.equals(list.getElementAt(0))) {
+                            if (element.equals(getList().getElementAt(0))) {
                                 pattern.setFocus();
                             }
-                            if (list.getElementAt(list.getTable()
+                            if (getList().getElementAt(getList().getTable()
                                     .getSelectionIndex() - 1) instanceof ItemsListSeparator) {
-                                list.getTable().setSelection(
-                                        list.getTable().getSelectionIndex() - 1);
+                                getList().getTable().setSelection(
+                                        getList().getTable().getSelectionIndex() - 1);
                             }
-                            list.getTable().notifyListeners(SWT.Selection,
+                            getList().getTable().notifyListeners(SWT.Selection,
                                     new Event());
 
                         }
@@ -802,12 +802,12 @@ public abstract class CdmFilteredItemsSelectionDialog extends SelectionStatusDia
                             && (e.stateMask & SWT.SHIFT) != 0
                             && (e.stateMask & SWT.CTRL) != 0) {
 
-                        if (list
-                                .getElementAt(list.getTable().getSelectionIndex() + 1) instanceof ItemsListSeparator) {
-                            list.getTable().setSelection(
-                                    list.getTable().getSelectionIndex() + 1);
+                        if (getList()
+                                .getElementAt(getList().getTable().getSelectionIndex() + 1) instanceof ItemsListSeparator) {
+                            getList().getTable().setSelection(
+                                    getList().getTable().getSelectionIndex() + 1);
                         }
-                        list.getTable().notifyListeners(SWT.Selection, new Event());
+                        getList().getTable().notifyListeners(SWT.Selection, new Event());
                     }
 
                 }
@@ -891,9 +891,9 @@ public abstract class CdmFilteredItemsSelectionDialog extends SelectionStatusDia
             IStatus status = new Status(IStatus.OK, PlatformUI.PLUGIN_ID,
                     IStatus.OK, EMPTY_STRING, null);
 
-            Object[] lastSelection = currentSelection;
+            Object[] lastSelection = getCurrentSelection();
 
-            currentSelection = selection.toArray();
+            setCurrentSelection(selection.toArray());
 
             if (selection.size() == 0) {
                 status = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID,
@@ -901,10 +901,10 @@ public abstract class CdmFilteredItemsSelectionDialog extends SelectionStatusDia
 
                 if (lastSelection != null
                         && getListSelectionLabelDecorator() != null) {
-                    list.update(lastSelection, null);
+                    getList().update(lastSelection, null);
                 }
 
-                currentSelection = null;
+                setCurrentSelection(null);
 
             } else {
                 status = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID,
@@ -938,11 +938,11 @@ public abstract class CdmFilteredItemsSelectionDialog extends SelectionStatusDia
 
                 if (lastSelection != null
                         && getListSelectionLabelDecorator() != null) {
-                    list.update(lastSelection, null);
+                    getList().update(lastSelection, null);
                 }
 
                 if (getListSelectionLabelDecorator() != null) {
-                    list.update(currentSelection, null);
+                    getList().update(getCurrentSelection(), null);
                 }
             }
 
@@ -978,28 +978,28 @@ public abstract class CdmFilteredItemsSelectionDialog extends SelectionStatusDia
          * Refreshes the dialog - has to be called in UI thread.
          */
         public void refresh() {
-            if (list != null && !list.getTable().isDisposed()) {
+            if (getList() != null && !getList().getTable().isDisposed()) {
 
-                List lastRefreshSelection = ((StructuredSelection) list
+                List lastRefreshSelection = ((StructuredSelection) getList()
                         .getSelection()).toList();
-                list.getTable().deselectAll();
+                getList().getTable().deselectAll();
 
-                list.setItemCount(contentProvider.getNumberOfElements());
-                list.refresh();
+                getList().setItemCount(contentProvider.getNumberOfElements());
+                getList().refresh();
 
-                if (list.getTable().getItemCount() > 0) {
+                if (getList().getTable().getItemCount() > 0) {
                     // preserve previous selection
                     if (refreshWithLastSelection && lastRefreshSelection != null
                             && lastRefreshSelection.size() > 0) {
-                        list.setSelection(new StructuredSelection(
+                        getList().setSelection(new StructuredSelection(
                                 lastRefreshSelection));
                     } else {
                         refreshWithLastSelection = true;
-                        list.getTable().setSelection(0);
-                        list.getTable().notifyListeners(SWT.Selection, new Event());
+                        getList().getTable().setSelection(0);
+                        getList().getTable().notifyListeners(SWT.Selection, new Event());
                     }
                 } else {
-                    list.setSelection(StructuredSelection.EMPTY);
+                    getList().setSelection(StructuredSelection.EMPTY);
                 }
 
             }
@@ -1033,7 +1033,7 @@ public abstract class CdmFilteredItemsSelectionDialog extends SelectionStatusDia
          *            available
          */
         public void reloadCache(boolean checkDuplicates, IProgressMonitor monitor) {
-            if (list != null && !list.getTable().isDisposed()
+            if (getList() != null && !getList().getTable().isDisposed()
                     && contentProvider != null) {
                 contentProvider.reloadCache(checkDuplicates, monitor);
             }
@@ -1065,7 +1065,7 @@ public abstract class CdmFilteredItemsSelectionDialog extends SelectionStatusDia
         @Override
         protected void computeResult() {
 
-            List selectedElements = ((StructuredSelection) list.getSelection())
+            List selectedElements = ((StructuredSelection) getList().getSelection())
                     .toList();
 
             List objectsToReturn = new ArrayList();
@@ -1151,7 +1151,7 @@ public abstract class CdmFilteredItemsSelectionDialog extends SelectionStatusDia
          */
         protected StructuredSelection getSelectedItems() {
 
-            StructuredSelection selection = (StructuredSelection) list
+            StructuredSelection selection = (StructuredSelection) getList()
                     .getSelection();
 
             List selectedItems = selection.toList();
@@ -1594,13 +1594,13 @@ public abstract class CdmFilteredItemsSelectionDialog extends SelectionStatusDia
              */
             @Override
             public void run() {
-                List selectedElements = ((StructuredSelection) list.getSelection())
+                List selectedElements = ((StructuredSelection) getList().getSelection())
                         .toList();
                 removeSelectedItems(selectedElements);
             }
         }
 
-        private static boolean showColoredLabels() {
+        protected static boolean showColoredLabels() {
             return PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.USE_COLORED_LABELS);
         }
 
@@ -1695,9 +1695,9 @@ public abstract class CdmFilteredItemsSelectionDialog extends SelectionStatusDia
             }
 
             private boolean isSelected(Object element) {
-                if (element != null && currentSelection != null) {
-                    for (int i = 0; i < currentSelection.length; i++) {
-                        if (element.equals(currentSelection[i])) {
+                if (element != null && getCurrentSelection() != null) {
+                    for (int i = 0; i < getCurrentSelection().length; i++) {
+                        if (element.equals(getCurrentSelection()[i])) {
                             return true;
                         }
                     }
@@ -1762,17 +1762,17 @@ public abstract class CdmFilteredItemsSelectionDialog extends SelectionStatusDia
             }
 
             private String getSeparatorLabel(String separatorLabel) {
-                Rectangle rect = list.getTable().getBounds();
+                Rectangle rect = getList().getTable().getBounds();
 
-                int borderWidth = list.getTable().computeTrim(0, 0, 0, 0).width;
+                int borderWidth = getList().getTable().computeTrim(0, 0, 0, 0).width;
 
                 int imageWidth = WorkbenchImages.getImage(
                         IWorkbenchGraphicConstants.IMG_OBJ_SEPARATOR).getBounds().width;
 
                 int width = rect.width - borderWidth - imageWidth;
 
-                GC gc = new GC(list.getTable());
-                gc.setFont(list.getTable().getFont());
+                GC gc = new GC(getList().getTable());
+                gc.setFont(getList().getTable().getFont());
 
                 int fSeparatorWidth = gc.getAdvanceWidth('-');
                 int fMessageLength = gc.textExtent(separatorLabel).x;
@@ -1897,7 +1897,7 @@ public abstract class CdmFilteredItemsSelectionDialog extends SelectionStatusDia
          * Used in ItemsListContentProvider, separates history and non-history
          * items.
          */
-        private class ItemsListSeparator {
+        protected class ItemsListSeparator {
 
             private final String name;
 
@@ -2987,7 +2987,7 @@ public abstract class CdmFilteredItemsSelectionDialog extends SelectionStatusDia
             @Override
             public void updateElement(int index) {
 
-                CdmFilteredItemsSelectionDialog.this.list.replace((lastFilteredItems
+                CdmFilteredItemsSelectionDialog.this.getList().replace((lastFilteredItems
                         .size() > index) ? lastFilteredItems.get(index) : null,
                         index);
 
@@ -3023,7 +3023,7 @@ public abstract class CdmFilteredItemsSelectionDialog extends SelectionStatusDia
 
                 // the TableViewer's root (the input) is treated as parent
 
-                lastFilteredItems = Arrays.asList(getFilteredItems(list.getInput(),
+                lastFilteredItems = Arrays.asList(getFilteredItems(getList().getInput(),
                         monitor != null ? new SubProgressMonitor(monitor, 100)
                                 : null));
 
@@ -3117,7 +3117,7 @@ public abstract class CdmFilteredItemsSelectionDialog extends SelectionStatusDia
                 if (filters != null && filteredElements != null) {
                     for (Iterator iter = filters.iterator(); iter.hasNext();) {
                         ViewerFilter f = (ViewerFilter) iter.next();
-                        filteredElements = f.filter(list, parent, filteredElements);
+                        filteredElements = f.filter(getList(), parent, filteredElements);
                         monitor.worked(ticks);
                     }
                 }
@@ -3423,6 +3423,22 @@ public abstract class CdmFilteredItemsSelectionDialog extends SelectionStatusDia
          */
         abstract protected void initModel();
 
+               public Object[] getCurrentSelection() {
+                       return currentSelection;
+               }
+
+               public void setCurrentSelection(Object[] currentSelection) {
+                       this.currentSelection = currentSelection;
+               }
+
+               public TableViewer getList() {
+                       return list;
+               }
+
+               public void setList(TableViewer list) {
+                       this.list = list;
+               }
+
     }