ref #8162 move OriginalSourceXXX to reference package
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / selection / SearchDialog.java
index 4be7699a8eb195fa33f2d843cc0fb7b641653571..3e731f3286c877fd56667f46b82b1b83167386ec 100644 (file)
@@ -25,8 +25,8 @@ import org.eclipse.core.runtime.ListenerList;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.jface.action.LegacyActionTools;
-import org.eclipse.jface.action.MenuManager;
 import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
 import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
 import org.eclipse.jface.viewers.DoubleClickEvent;
 import org.eclipse.jface.viewers.IColorProvider;
@@ -48,6 +48,8 @@ import org.eclipse.jface.viewers.ViewerCell;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.accessibility.AccessibleAdapter;
 import org.eclipse.swt.accessibility.AccessibleEvent;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
 import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.events.TraverseEvent;
@@ -68,7 +70,6 @@ import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.swt.widgets.Text;
-import org.eclipse.swt.widgets.ToolBar;
 import org.eclipse.ui.IWorkbenchPreferenceConstants;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.dialogs.FilteredItemsSelectionDialog;
@@ -97,6 +98,7 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog{// impleme
 
         protected Button newButton2;
         protected Button filterButton;
+        protected Button btnCheckButton;
         private StructuredSelection currentSelection;
 
         // message to show user
@@ -107,28 +109,39 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog{// impleme
 
         private final RefreshCacheJob refreshCacheJob;
 
-        private ToolBar toolBar;
-        private MenuManager menuManager;
-
         protected Object preferenceID;
 
         protected final int new_id = 4;
         protected final int new_id2 = 5;
+        protected final int space_id = 6;
         // Need to keep our own list of listeners
         private final ListenerList listeners = new ListenerList();
 
 
         private static final String EMPTY_STRING = ""; //$NON-NLS-1$
         private GridData gd_1;
+        protected boolean useIdentifier;
 
-        public SearchDialog(Shell parent, boolean multi) {
+        public SearchDialog(Shell parent, String title) {
             super(parent);
+            this.title = title;
             contentProvider = new ContentProvider();
             refreshCacheJob = new RefreshCacheJob();
 
+        }
 
+        @Override
+        public void create() {
+            // TODO Auto-generated method stub
+            super.create();
+            refresh();
         }
 
+        @Override
+        protected void configureShell(Shell shell) {
+            super.configureShell(shell);
+            shell.setText(title);
+         }
 
         @Override
         protected Control createDialogArea(Composite parent) {
@@ -146,10 +159,8 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog{// impleme
             final Label headerLabel = createHeader(container);
 
             Composite searchAndFilter = new Composite(container, container.getStyle());
-//            GridData gd_searchAndFilter = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
-            GridData gd_searchAndFilter =new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL);
-//            gd_searchAndFilter.widthHint = 576;
-            searchAndFilter.setLayoutData(gd_searchAndFilter);
+
+            searchAndFilter.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
             GridLayout searchAndFilterLayout = new GridLayout();
             searchAndFilterLayout.numColumns = 2;
             searchAndFilter.setLayout(searchAndFilterLayout);
@@ -165,23 +176,19 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog{// impleme
                 @Override
                 public void modifyText(ModifyEvent e) {
                     search();
-                    try {
-                        fillContentProvider(null);
-                    } catch (CoreException coreException) {
-                        // TODO Auto-generated catch block
-                        coreException.printStackTrace();
-                    }
+//                    fillContentProvider(null);
+
                 }
             });
             gd_1 = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL);
+            gd_1.horizontalIndent = 7;
 
-//            gd_1.horizontalIndent = 2;
-//            gd_1.horizontalAlignment = SWT.CENTER;
-//            gd_1.grabExcessHorizontalSpace = true;
-//            gd_1.widthHint = 500;
             searchField.setLayoutData(gd_1);
 
             createFilterButton(searchAndFilter);
+
+            addIdentifierCheckButton(searchAndFilter);
+//            new Label(searchAndFilter, SWT.NONE);
             setList(new TableViewer(container,  SWT.SINGLE
                     | SWT.BORDER | SWT.V_SCROLL | SWT.VIRTUAL));
 
@@ -203,35 +210,34 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog{// impleme
                     okPressed();
                 }
             });
+            searchField.addKeyListener(new KeyAdapter() {
+                @Override
+                public void keyPressed(KeyEvent e) {
+                    if (e.keyCode == SWT.ARROW_DOWN) {
+                        if (getList().getTable().getItemCount() > 0) {
+                            getList().getTable().setFocus();
+                        }
+                    }
+                }
+            });
+
 //            createExtendedContentArea(container);
             new Label(container, SWT.NONE);
+            search();
 
             return container;
         }
 
 
+        protected void addIdentifierCheckButton(Composite searchAndFilter) {
+           //as default do nothing
+        }
+
+
         abstract void createFilterButton(Composite searchAndFilter) ;
 
         protected abstract void search();
 
-        /**
-         * Creates an extra content area, which will be located above the details.
-         *
-         * @param parent
-         *            parent to create the dialog widgets in
-         * @return an extra content area
-         */
-//        protected abstract Control createExtendedContentArea(Composite parent);
-
-        /**
-         * Sets the title for this dialog.
-         *
-         * @param title
-         *            the title
-         */
-        public void setTitle(String title) {
-            this.title = title;
-        }
 
         /**
          * Create a new header which is labelled by headerLabel.
@@ -242,10 +248,13 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog{// impleme
         private Label createHeader(Composite parent) {
             Composite header = new Composite(parent, SWT.NONE);
             GridData gd_header = new GridData(SWT.CENTER, SWT.CENTER, false, false, 2, 1);
+            gd_header.horizontalIndent = 5;
             gd_header.widthHint = 575;
             header.setLayoutData(gd_header);
 
             GridLayout layout = new GridLayout();
+            layout.marginLeft = 5;
+            layout.horizontalSpacing = 0;
             layout.verticalSpacing = 1;
             layout.marginWidth = 0;
             layout.marginHeight = 0;
@@ -297,47 +306,7 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog{// impleme
             }
             return itemsListLabelProvider;
         }
-//        private void createViewMenu(Composite parent) {
-//            toolBar = new ToolBar(parent, SWT.FLAT);
-//
-//            GridData data = new GridData();
-//            data.horizontalAlignment = GridData.END;
-//            data.grabExcessHorizontalSpace = true;
-//            toolBar.setLayoutData(data);
-//
-//            menuManager = new MenuManager();
-//
-//            fillViewMenu(menuManager);
-//
-//            IHandlerService service = PlatformUI.getWorkbench()
-//                    .getService(IHandlerService.class);
-//            IHandler handler = new AbstractHandler() {
-//                @Override
-//                public Object execute(ExecutionEvent event) {
-//                    showViewMenu();
-//                    return null;
-//                }
-//            };
-//        }
-
-//        /**
-//         * Fills the menu of the dialog.
-//         *
-//         * @param menuManager
-//         *            the menu manager
-//         */
-//        protected void fillViewMenu(IMenuManager menuManager) {
-//
-//        }
-
-//        private void showViewMenu() {
-//            Menu menu = menuManager.createContextMenu(getShell());
-//            Rectangle bounds = toolItem.getBounds();
-//            Point topLeft = new Point(bounds.x, bounds.y + bounds.height);
-//            topLeft = toolBar.toDisplay(topLeft);
-//            menu.setLocation(topLeft.x, topLeft.y);
-//            menu.setVisible(true);
-//        }
+
 
         public TableViewer getList() {
             return list;
@@ -491,6 +460,10 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog{// impleme
         }
 
 
+        public boolean isUseIdentifier() {
+            return useIdentifier;
+        }
+
 
         public StructuredSelection getCurrentSelection() {
             return currentSelection;
@@ -504,7 +477,7 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog{// impleme
          *            progress monitor reflects the state of the filtering process.
          * @throws CoreException
          */
-        protected abstract void fillContentProvider(IProgressMonitor progressMonitor) throws CoreException;
+        protected abstract void fillContentProvider(IProgressMonitor progressMonitor) ;
 
 
         /**
@@ -531,6 +504,9 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog{// impleme
                         getList().getTable().setSelection(0);
                         getList().getTable().notifyListeners(SWT.Selection, new Event());
                     }
+                    if ( super.getButton(IDialogConstants.OK_ID) != null){
+                        super.getButton(IDialogConstants.OK_ID).setEnabled(true);
+                    }
                 } else {
                     getList().setSelection(StructuredSelection.EMPTY);
                 }
@@ -573,13 +549,7 @@ public abstract class SearchDialog<T extends ICdmBase> extends Dialog{// impleme
                 }
 
                 if (SearchDialog.this != null) {
-
-                    try {
-                        SearchDialog.this.fillContentProvider(monitor);
-                    } catch (CoreException e) {
-                        // TODO Auto-generated catch block
-                        e.printStackTrace();
-                    }
+                    SearchDialog.this.fillContentProvider(monitor);
                 }
 
                 return new Status(IStatus.OK, PlatformUI.PLUGIN_ID, IStatus.OK,