code cleaning
authorKatja Luther <k.luther@bgbm.org>
Fri, 17 Nov 2017 12:15:08 +0000 (13:15 +0100)
committerKatja Luther <k.luther@bgbm.org>
Fri, 17 Nov 2017 12:15:08 +0000 (13:15 +0100)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/AbstractFilteredCdmResourceSelectionDialog.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/SearchDialog.java

index f51e2ac829cd5bb5a5212a9eecb809bbd5f216c7..a3afdcfa2ba7c390c569ff118cecf76aa6e25626 100644 (file)
@@ -205,16 +205,6 @@ public abstract class AbstractFilteredCdmResourceSelectionDialog<T extends ICdmB
        }
 
 
-       /** {@inheritDoc} */
-       @Override
-       public void refresh() {
-               super.refresh();
-       }
-
-
-
-
-
 
        /**
         * Set the filter input to the Agent's title cache
index 108422db375ed42f491f3b059401073138acf2fc..ba70bd49385bc9d4edabd48d653315bde97818a8 100755 (executable)
@@ -34,10 +34,8 @@ import org.eclipse.jface.viewers.DoubleClickEvent;
 import org.eclipse.jface.viewers.IColorProvider;
 import org.eclipse.jface.viewers.IDoubleClickListener;
 import org.eclipse.jface.viewers.IFontProvider;
-import org.eclipse.jface.viewers.ILabelDecorator;
 import org.eclipse.jface.viewers.ILabelProvider;
 import org.eclipse.jface.viewers.ILabelProviderListener;
-import org.eclipse.jface.viewers.ILazyContentProvider;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.IStructuredContentProvider;
 import org.eclipse.jface.viewers.LabelProvider;
@@ -86,7 +84,6 @@ import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
 import org.eclipse.ui.internal.WorkbenchImages;
 import org.eclipse.ui.internal.WorkbenchMessages;
 import org.eclipse.ui.internal.WorkbenchPlugin;
-import org.eclipse.ui.progress.UIJob;
 
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
 import eu.etaxonomy.cdm.model.common.ICdmBase;
@@ -101,30 +98,21 @@ import eu.etaxonomy.taxeditor.ui.dialog.selection.CdmFilteredItemsSelectionDialo
 public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements IConversationEnabled{
 
         private TableViewer list;
-
-
         private Text searchField;
         private String title;
+        private StructuredSelection currentSelection;
 
         // message to show user
         private String message = ""; //$NON-NLS-1$
 
         protected final ContentProvider contentProvider;
-
-        private StructuredSelection currentSelection;
         ItemsListLabelProvider itemsListLabelProvider;
 
         private final RefreshCacheJob refreshCacheJob;
 
         private ToolBar toolBar;
-
         private ToolItem toolItem;
         private MenuManager menuManager;
-
-        private ILabelProvider provider;
-
-        private ILabelDecorator selectionDecorator;
-
         // Need to keep our own list of listeners
         private final ListenerList listeners = new ListenerList();
 
@@ -143,7 +131,7 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
         @Override
         protected Control createDialogArea(Composite parent) {
             Composite container = (Composite) super.createDialogArea(parent);
-//            Composite content = new Composite(container, SWT.NONE);
+
             GridData gd = new GridData(GridData.FILL_BOTH);
             container.setLayoutData(gd);
 
@@ -182,20 +170,9 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
             gd_1.widthHint = 575;
             searchField.setLayoutData(gd_1);
 
-//            final Label listLabel = createLabels(content);
-
             setList(new TableViewer(container,  SWT.SINGLE
                     | SWT.BORDER | SWT.V_SCROLL | SWT.VIRTUAL));
-//            getList().getTable().getAccessible().addAccessibleListener(
-//                    new AccessibleAdapter() {
-//                        @Override
-//                        public void getName(AccessibleEvent e) {
-//                            if (e.childID == ACC.CHILDID_SELF) {
-//                                e.result = LegacyActionTools
-//                                        .removeMnemonics(listLabel.getText());
-//                            }
-//                        }
-//                    });
+
             getList().setContentProvider(contentProvider);
             getList().setLabelProvider(getItemsListLabelProvider());
             getList().setInput(new Object[0]);
@@ -258,36 +235,29 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
             new Label(header, SWT.NONE);
             new Label(header, SWT.NONE);
 
-                        Label headerLabel = new Label(header, SWT.NONE);
-                        headerLabel.setText((getMessage() != null && getMessage().trim()
-                                .length() > 0) ? getMessage()
-                                : Messages.SearchDialog_patternLabel);
-                        headerLabel.addTraverseListener(new TraverseListener() {
-                            @Override
-                            public void keyTraversed(TraverseEvent e) {
-                                if (e.detail == SWT.TRAVERSE_MNEMONIC && e.doit) {
-                                    e.detail = SWT.TRAVERSE_NONE;
-                                    searchField.setFocus();
-                                }
-                            }
-                        });
-                        GridData gd_headerLabel = new GridData(GridData.FILL_HORIZONTAL);
-                        gd_headerLabel.horizontalAlignment = SWT.LEFT;
-                        gd_headerLabel.grabExcessHorizontalSpace = false;
-                        gd_headerLabel.verticalAlignment = SWT.BOTTOM;
-                        gd_headerLabel.minimumHeight = 10;
-                        headerLabel.setLayoutData(gd_headerLabel);
-
-                        //            createViewMenu(header);
-
-                                    return headerLabel;
+            Label headerLabel = new Label(header, SWT.NONE);
+            headerLabel.setText((getMessage() != null && getMessage().trim()
+                    .length() > 0) ? getMessage()
+                    : Messages.SearchDialog_patternLabel);
+            headerLabel.addTraverseListener(new TraverseListener() {
+                @Override
+                public void keyTraversed(TraverseEvent e) {
+                    if (e.detail == SWT.TRAVERSE_MNEMONIC && e.doit) {
+                        e.detail = SWT.TRAVERSE_NONE;
+                        searchField.setFocus();
+                    }
+                }
+            });
+            GridData gd_headerLabel = new GridData(GridData.FILL_HORIZONTAL);
+            gd_headerLabel.horizontalAlignment = SWT.LEFT;
+            gd_headerLabel.grabExcessHorizontalSpace = false;
+            gd_headerLabel.verticalAlignment = SWT.BOTTOM;
+            gd_headerLabel.minimumHeight = 10;
+            headerLabel.setLayoutData(gd_headerLabel);
+
+            return headerLabel;
         }
 
-        /**
-         * Returns the message for this dialog.
-         *
-         * @return the message for this dialog
-         */
         protected String getMessage() {
             return message;
         }
@@ -305,11 +275,6 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
             this.searchField = searchField;
         }
 
-        /**
-         * Returns the item list label provider.
-         *
-         * @return the item list label provider
-         */
         private ItemsListLabelProvider getItemsListLabelProvider() {
             if (itemsListLabelProvider == null) {
                 itemsListLabelProvider = new ItemsListLabelProvider(
@@ -317,43 +282,6 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
             }
             return itemsListLabelProvider;
         }
-
-//        /**
-//         * Create the labels for the list and the progress. Return the list label.
-//         *
-//         * @param parent
-//         * @return Label
-//         */
-//        private Label createLabels(Composite parent) {
-//            Composite labels = new Composite(parent, SWT.NONE);
-//
-//            GridLayout layout = new GridLayout();
-//            layout.numColumns = 2;
-//            layout.marginWidth = 0;
-//            layout.marginHeight = 0;
-//            labels.setLayout(layout);
-//
-////            Label listLabel = new Label(labels, SWT.NONE);
-////            listLabel
-////                    .setText(Messages.SearchDialog_listLabel);
-//
-//            listLabel.addTraverseListener(new TraverseListener() {
-//                @Override
-//                public void keyTraversed(TraverseEvent e) {
-//                    if (e.detail == SWT.TRAVERSE_MNEMONIC && e.doit) {
-//                        e.detail = SWT.TRAVERSE_NONE;
-//                        getList().getTable().setFocus();
-//                    }
-//                }
-//            });
-//            listLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-//            new Label(labels, SWT.NONE);
-//
-//
-//            return listLabel;
-//        }
-
-
         private void createViewMenu(Composite parent) {
             toolBar = new ToolBar(parent, SWT.FLAT);
             toolItem = new ToolItem(toolBar, SWT.PUSH, 0);
@@ -393,9 +321,6 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
                     return null;
                 }
             };
-//            showViewHandler = service.activateHandler(
-//                    IWorkbenchCommandConstants.WINDOW_SHOW_VIEW_MENU, handler,
-//                    new ActiveShellExpression(getShell()));
         }
 
         /**
@@ -405,8 +330,7 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
          *            the menu manager
          */
         protected void fillViewMenu(IMenuManager menuManager) {
-//            toggleStatusLineAction = new ToggleStatusLineAction();
-//            menuManager.add(toggleStatusLineAction);
+
         }
 
         private void showViewMenu() {
@@ -449,36 +373,11 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
 
 
 
-        /**
-         * Collects filtered elements. Contains one synchronized, sorted set for
-         * collecting filtered elements. All collected elements are sorted using
-         * comparator. Comparator is returned by getElementComparator() method.
-         * Implementation of <code>ItemsFilter</code> is used to filter elements.
-         * The key function of filter used in to filtering is
-         * <code>matchElement(Object item)</code>.
-         * <p>
-         * The <code>ContentProvider</code> class also provides item filtering
-         * methods. The filtering has been moved from the standard TableView
-         * <code>getFilteredItems()</code> method to content provider, because
-         * <code>ILazyContentProvider</code> and virtual tables are used. This
-         * class is responsible for adding a separator below history items and
-         * marking each items as duplicate if its name repeats more than once on the
-         * filtered list.
-         */
         class ContentProvider implements
-                IStructuredContentProvider, ILazyContentProvider {
-
-
+                IStructuredContentProvider {
 
-            /**
-             * Raw result of the searching (unsorted, unfiltered).
-             * <p>
-             * Standard object flow:
-             * <code>items -> lastSortedItems -> lastFilteredItems</code>
-             */
             private List items;
 
-
             /**
              * Creates new instance of <code>ContentProvider</code>.
              */
@@ -487,8 +386,6 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
 
             }
 
-
-
             /**
              * Removes all content items and resets progress message.
              */
@@ -497,21 +394,10 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
 
             }
 
-
-
-            /**
-             * Adds filtered item.
-             *
-             * @param item
-             * @param itemsFilter
-             */
-
             public void add(Object item) {
                 this.items.add(item);
             }
 
-
-
             /**
              * Refresh dialog.
              */
@@ -527,7 +413,6 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
                 refreshCacheJob.schedule();
             }
 
-
             /*
              * (non-Javadoc)
              *
@@ -536,11 +421,9 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
             @Override
             public Object[] getElements(Object inputElement) {
                 return items.toArray();
-//                return lastFilteredItems.toArray();
             }
 
             public int getNumberOfElements() {
-
                return items.size();
             }
 
@@ -562,27 +445,9 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
             @Override
             public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
             }
-
-            /*
-             * (non-Javadoc)
-             *
-             * @see org.eclipse.jface.viewers.ILazyContentProvider#updateElement(int)
-             */
-            @Override
-            public void updateElement(int index) {
-
-                SearchDialog.this.getList().replace((items
-                        .size() > index) ? items.get(index) : null,
-                        index);
-
-            }
-
-
         }
 
-//        protected static boolean showColoredLabels() {
-//            return PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.USE_COLORED_LABELS);
-//        }
+
 
         public StructuredSelection getCurrentSelection() {
             return currentSelection;
@@ -591,12 +456,6 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
         /**
          * Fills the content provider with matching items.
          *
-         * @param contentProvider
-         *            collector to add items to.
-         *            {@link FilteredItemsSelectionDialog.AbstractContentProvider#add(Object, FilteredItemsSelectionDialog.ItemsFilter)}
-         *            only adds items that pass the given <code>itemsFilter</code>.
-         * @param itemsFilter
-         *            the items filter
          * @param progressMonitor
          *            must be used to report search progress. The state of this
          *            progress monitor reflects the state of the filtering process.
@@ -634,76 +493,8 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
                 }
 
             }
-
-//            scheduleProgressMessageRefresh();
         }
 
-        /**
-         * Only refreshes UI on the basis of an already sorted and filtered set of
-         * items.
-         * <p>
-         * Standard invocation scenario:
-         * <ol>
-         * <li>filtering job (<code>FilterJob</code> class extending
-         * <code>Job</code> class)</li>
-         * <li>cache refresh without checking for duplicates (<code>RefreshCacheJob</code>
-         * class extending <code>Job</code> class)</li>
-         * <li>UI refresh (<code>RefreshJob</code> class extending
-         * <code>UIJob</code> class)</li>
-         * <li>cache refresh with checking for duplicates (<cod>CacheRefreshJob</code>
-         * class extending <code>Job</code> class)</li>
-         * <li>UI refresh (<code>RefreshJob</code> class extending <code>UIJob</code>
-         * class)</li>
-         * </ol>
-         * The scenario is rather complicated, but it had to be applied, because:
-         * <ul>
-         * <li> refreshing cache is rather a long action and cannot be run in the UI -
-         * cannot be run in a UIJob</li>
-         * <li> refreshing cache checking for duplicates is twice as long as
-         * refreshing cache without checking for duplicates; results of the search
-         * could be displayed earlier</li>
-         * <li> refreshing the UI have to be run in a UIJob</li>
-         * </ul>
-         *
-         * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.FilterJob
-         * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.RefreshJob
-         * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.RefreshCacheJob
-         */
-        private class RefreshJob extends UIJob {
-
-            /**
-             * Creates a new instance of the class.
-             */
-            public RefreshJob() {
-                super(SearchDialog.this.getParentShell()
-                        .getDisplay(),
-                        WorkbenchMessages.FilteredItemsSelectionDialog_refreshJob);
-                setSystem(true);
-            }
-
-            /*
-             * (non-Javadoc)
-             *
-             * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
-             */
-            @Override
-            public IStatus runInUIThread(IProgressMonitor monitor) {
-                if (monitor.isCanceled()) {
-                    return new Status(IStatus.OK, WorkbenchPlugin.PI_WORKBENCH,
-                            IStatus.OK, EMPTY_STRING, null);
-                }
-
-                if (SearchDialog.this != null) {
-                    SearchDialog.this.refresh();
-                }
-
-                return new Status(IStatus.OK, PlatformUI.PLUGIN_ID, IStatus.OK,
-                        EMPTY_STRING, null);
-            }
-
-        }
-
-
         /**
          * A job responsible for computing filtered items list presented using
          * <code>RefreshJob</code>.
@@ -713,11 +504,6 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
          */
         private class RefreshCacheJob extends Job {
 
-            private final RefreshJob refreshJob = new RefreshJob();
-
-            /**
-             * Creates a new instance of the class.
-             */
             public RefreshCacheJob() {
                 super(
                         WorkbenchMessages.FilteredItemsSelectionDialog_cacheRefreshJob);
@@ -729,7 +515,6 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
              */
             public void cancelAll() {
                 cancel();
-                refreshJob.cancel();
             }
 
             /*
@@ -754,10 +539,6 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
                     }
                 }
 
-                if (!monitor.isCanceled()) {
-                    refreshJob.schedule();
-                }
-
                 return new Status(IStatus.OK, PlatformUI.PLUGIN_ID, IStatus.OK,
                         EMPTY_STRING, null);
 
@@ -771,7 +552,6 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
             @Override
             protected void canceling() {
                 super.canceling();
-//                contentProvider.stopReloadingCache();
             }
 
         }
@@ -791,43 +571,7 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
     public ItemsListLabelProvider(ILabelProvider provider) {
         Assert.isNotNull(provider);
         this.provider = provider;
-
-
-//        setOwnerDrawEnabled(showColoredLabels() && provider instanceof IStyledLabelProvider);
-
-        provider.addListener(this);
-
-        if (selectionDecorator != null) {
-            selectionDecorator.addListener(this);
-        }
-    }
-
-    /**
-     * Sets new selection decorator.
-     *
-     * @param newSelectionDecorator
-     *            new label decorator for selected items in the list
-     */
-    public void setSelectionDecorator(ILabelDecorator newSelectionDecorator) {
-        if (selectionDecorator != null) {
-            selectionDecorator.removeListener(this);
-            selectionDecorator.dispose();
-        }
-
-        selectionDecorator = newSelectionDecorator;
-
-        if (selectionDecorator != null) {
-            selectionDecorator.addListener(this);
-        }
-    }
-
-    /**
-     * Gets selection decorator.
-     *
-     * @return the label decorator for selected items in the list
-     */
-    public ILabelDecorator getSelectionDecorator() {
-        return selectionDecorator;
+        this.provider.addListener(this);
     }
 
     /**
@@ -841,14 +585,11 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
         Assert.isNotNull(newProvider);
         provider.removeListener(this);
         provider.dispose();
-
         provider = newProvider;
 
         if (provider != null) {
             provider.addListener(this);
         }
-
-//        setOwnerDrawEnabled(showColoredLabels() && provider instanceof IStyledLabelProvider);
     }
 
 
@@ -872,12 +613,7 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
             return getSeparatorLabel(((ItemsListSeparator) element)
                     .getName());
         }
-
         String str = provider.getText(element);
-        if (selectionDecorator != null && isSelected(element)) {
-            return selectionDecorator.decorateText(str.toString(), element);
-        }
-
         return str;
     }
 
@@ -885,12 +621,6 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
             IStyledLabelProvider provider) {
         StyledString string = provider.getStyledText(element);
 
-        if (selectionDecorator != null && isSelected(element)) {
-            String decorated = selectionDecorator.decorateText(string
-                    .getString(), element);
-            return StyledCellLabelProvider.styleDecoratedString(decorated, null, string);
-            // no need to add colors when element is selected
-        }
         return string;
     }
 
@@ -968,12 +698,6 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
     public void dispose() {
         provider.removeListener(this);
         provider.dispose();
-
-        if (selectionDecorator != null) {
-            selectionDecorator.removeListener(this);
-            selectionDecorator.dispose();
-        }
-
         super.dispose();
     }
 
@@ -988,10 +712,6 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
         if (provider.isLabelProperty(element, property)) {
             return true;
         }
-        if (selectionDecorator != null
-                && selectionDecorator.isLabelProperty(element, property)) {
-            return true;
-        }
         return false;
     }
 
@@ -1054,6 +774,6 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog implements
     protected Point getInitialSize() {
         return new Point(593, 399);
     }
-    }
+}