fix #7237: description editor: when status is empty and no description exist, do...
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / checklist / ChecklistEditor.java
index 0d5cee3e09c5db800d7e100aa26f3acc51a9df5c..f9719cc74f22a888fc1b799e1a768edddaab3a9e 100644 (file)
@@ -1,4 +1,3 @@
-// $Id$
 /**
  * Copyright (C) 2007 EDIT
  * European Distributed Institute of Taxonomy
@@ -64,6 +63,7 @@ import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.editor.SimpleSelectionProvider;
+import eu.etaxonomy.taxeditor.editor.l10n.Messages;
 import eu.etaxonomy.taxeditor.editor.view.checklist.edit.DistributionEditingSupport;
 import eu.etaxonomy.taxeditor.editor.view.checklist.filter.ChecklistEditorFilter;
 import eu.etaxonomy.taxeditor.editor.view.checklist.listener.ChecklistDropdownSelectionListener;
@@ -88,15 +88,14 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  * @version 1.0
  */
 public class ChecklistEditor extends EditorPart implements ISelectionListener, IPartContentHasFactualData, IConversationEnabled,
-        IContextListener, IPartContentHasDetails, IDirtyMarkable{//, ICdmEntitySessionEnabled {
-
-    private static final Logger logger = Logger.getLogger(ChecklistEditor.class);
-    /**
-     * Key used for storing Checklist Editor View
-     */
-    private static final String CHECKLIST_EDITOR_MEMENTO_KEY = "checklistEditor";
+        IContextListener, IDirtyMarkable, IPartContentHasDetails{
 
+    private static final String LOADING_TAXA = Messages.ChecklistEditor_LOAD_TAXA;
+    private static final String UNKNOWN = Messages.ChecklistEditor_UNKNOWN;
+    private static final String ELEMENT_COUNT = Messages.ChecklistEditor_ELEMENT_COUNT;
+    public static final String TYPE_FILTER_TEXT = "type filter text"; //$NON-NLS-1$
 
+    private static final Logger logger = Logger.getLogger(ChecklistEditor.class);
 
 
     private class ChecklistJob extends Job {
@@ -122,8 +121,8 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
         @Override
         public IStatus run(final IProgressMonitor monitor) {
             try {
-                logger.debug("Begin of eclipse core runtime Job to Retrieve datasources");
-                monitor.beginTask("Retrieving TaxonNodes", taxonNodes.size() + 1);
+                logger.debug("Begin of eclipse core runtime Job to Retrieve datasources"); //$NON-NLS-1$
+                monitor.beginTask(Messages.ChecklistEditor_RETRIEVE_NODES, taxonNodes.size() + 1);
 
                 final List<Taxon> taxonList = new ArrayList<Taxon>();
 
@@ -154,7 +153,7 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
      * Constant
      * <code>ID="eu.etaxonomy.taxeditor.store.datasource"{trunked}</code>
      */
-    public static String ID = "eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditor";
+    public static String ID = "eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditor"; //$NON-NLS-1$
 
     private TableViewer viewer;
 
@@ -186,7 +185,7 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
 
     private Label statusLabel;
 
-   // private final ICdmEntitySession cdmEntitySession;
+//    private ICdmEntitySession cdmEntitySession;
 
     private ChecklistLabelProvider labelProvider;
 
@@ -222,17 +221,27 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
     /** {@inheritDoc} */
     @Override
     public void createPartControl(Composite parent) {
-        service = (IWorkbenchSiteProgressService) getSite().getAdapter(IWorkbenchSiteProgressService.class);
+        service = getSite().getAdapter(IWorkbenchSiteProgressService.class);
         taxonNodeService = CdmStore.getService(ITaxonNodeService.class);
         selectionService = getSite().getWorkbenchWindow().getSelectionService();
         selectionService.addSelectionListener(this);
         viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
+
+//        viewer.addSelectionChangedListener(new ISelectionChangedListener() {
+//               @Override
+//               public void selectionChanged(SelectionChangedEvent event) {
+//                 IStructuredSelection selection = viewer.getStructuredSelection();
+//                 Object firstElement = selection.getFirstElement();
+//                 // do something with it
+//               }
+//
+//
+//             });
         labelProvider = new ChecklistLabelProvider(this.viewer);
-        
+
         terms = labelProvider.getNamedAreas();
         if (terms == null){
-                       MessagingUtils.informationDialog("No Areas to display", "Please choose the areas you want to display. "
-                                       + "Therefore go to the preferences, choose the Checklist Editor and choose the areas in the Distribution Selection Wizard.");
+                       MessagingUtils.informationDialog(Messages.ChecklistEditor_NO_AREAS, Messages.ChecklistEditor_NO_AREAS_MESSAGE);
                        this.dispose();
                        return;
                }
@@ -253,7 +262,7 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
         final Text searchText = createSearchBar(parent);
         createToolbar(parent);
 
-        getSite().setSelectionProvider(viewer);
+       // getSite().setSelectionProvider(viewer);
 
         final ModifyListener modifyListener = new ChecklistModifyListener(viewer, filter, searchText);
 
@@ -288,11 +297,11 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
      */
     private Text createSearchBar(Composite parent) {
         Label searchLabel = new Label(parent, SWT.NONE);
-        searchLabel.setText("Search: ");
+        searchLabel.setText(Messages.ChecklistEditor_SEARCH);
         final Text searchText = new Text(parent, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH | SWT.CANCEL);
         searchText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
         searchText.setForeground(EditorUtil.getColor(Resources.SEARCH_VIEW_FOREGROUND));
-        searchText.setText("type filter text");
+        searchText.setText(TYPE_FILTER_TEXT);
         return searchText;
     }
 
@@ -302,8 +311,8 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
     private void createToolbar(Composite parent) {
         ToolBar toolBar = new ToolBar(parent, SWT.NONE);
         toolItem = new ToolItem(toolBar, SWT.DROP_DOWN | SWT.BORDER);
-        toolItem.setText("Distribution Status");
-        toolItem.setToolTipText("Show Distribution Status for selected Areas");
+        toolItem.setText(Messages.ChecklistEditor_DIST_STATUS);
+        toolItem.setToolTipText(Messages.ChecklistEditor_DIST_STATUS_TOOLTIP);
         createToolbarItems();
         toolItem.addSelectionListener(dropListener);
         toolBar.pack();
@@ -311,7 +320,7 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
 
        private void createToolbarItems() {
                dropListener = new ChecklistDropdownSelectionListener(toolItem, this, terms);
-               
+
         for (DefinedTermBase<DefinedTermBase> term : terms) {
             if(term!=null){
                 dropListener.add(term);
@@ -326,7 +335,7 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
         gridData.horizontalAlignment = GridData.FILL;
 
         statusLabel = new Label(composite, SWT.LEFT);
-        statusLabel.setText("Anzahl der Elemente: " + (countNodes != null ? countNodes : "uknown"));
+        statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
         statusLabel.setLayoutData(gridData);
     }
 
@@ -335,10 +344,10 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
         List<String> titles = new ArrayList<String>();
         List<Integer> bounds = new ArrayList<Integer>();
         if (PreferencesUtil.isShowRankInChecklistEditor()){
-            Collections.addAll(titles, "Taxon",  "Rank");
+            Collections.addAll(titles, Messages.ChecklistEditor_TAXON,  Messages.ChecklistEditor_RANK);
             Collections.addAll(bounds, 300, 200);
         } else{
-            Collections.addAll(titles, "Taxon");
+            Collections.addAll(titles, Messages.ChecklistEditor_TAXON);
             Collections.addAll(bounds, 300);
         }
 
@@ -458,7 +467,7 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
         TaxonNode taxonNode = checklistEditorInput.getTaxonNode();
         if (classification != null && taxonNode == null) {
             countNodes = taxonNodeService.countAllNodesForClassification(classification);
-            statusLabel.setText("Anzahl der Elemente: " + (countNodes != null ? countNodes : "unknown"));
+//            statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
             // This should not kill the view nor the editor if something goes
             // wrong
             // TODO: don't load the whole taxonNode Object but rather a small
@@ -466,23 +475,27 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
             // FIXME: May be don't open classification which are greater than
             // 3000 Taxa
             selectedTaxonNodes = taxonNodeService.listAllNodesForClassification(classification, 0, countNodes);
-            getService().schedule(new ChecklistJob("loading Taxa", selectedTaxonNodes), Job.LONG);
+            countNodes = selectedTaxonNodes.size();
+            statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
+            getService().schedule(new ChecklistJob(LOADING_TAXA, selectedTaxonNodes), Job.LONG);
         }
         if (taxonNode != null) {
             selectedTaxonNodes = taxonNodeService.loadChildNodesOfTaxonNode(taxonNode, NODE_INIT_STRATEGY, true, null);
-            getService().schedule(new ChecklistJob("loading Taxa", selectedTaxonNodes), Job.LONG);
+            getService().schedule(new ChecklistJob(LOADING_TAXA, selectedTaxonNodes), Job.LONG);
+            countNodes = selectedTaxonNodes.size();
+            statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
         }
     }
 
     /** {@inheritDoc} */
     @Override
     public void dispose() {
-       this.checklistEditorInput.dispose();
+//     this.checklistEditorInput.dispose();
        super.dispose();
-        
+
         conversation.unregisterForDataStoreChanges(this);
         conversation.unbind();
-       
+
         //conversation.close();
                conversation = null;
     }
@@ -506,7 +519,7 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
         // viewer.getTable().setEnabled(!busy);
         if (busy) {
             partNameCache = getPartName();
-            setPartName("Loading " + countNodes + " Taxa...");
+            setPartName(String.format(Messages.ChecklistEditor_LOAD_CNT_TAXA, countNodes));
         } else {
             if (partNameCache != null) {
                 setPartName(partNameCache);
@@ -559,7 +572,7 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
                acitivateNewColumnInDropDownMenu(term);
        }
         viewer.setLabelProvider(labelProvider);
-        getService().schedule(new ChecklistJob("loading Taxa", selectedTaxonNodes), Job.LONG);
+        getService().schedule(new ChecklistJob(LOADING_TAXA, selectedTaxonNodes), Job.LONG);
         table.setRedraw(true);
        viewer.refresh();
     }
@@ -625,7 +638,7 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
     @Override
     public void doSave(IProgressMonitor monitor) {
         try {
-            monitor.beginTask("Saving Editor", 1);
+            monitor.beginTask(Messages.ChecklistEditor_SAVE_EDITOR, 1);
             if (!conversation.isBound()) {
                 conversation.bind();
             }
@@ -650,7 +663,7 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
         setInput(input);
         if (input instanceof ChecklistEditorInput) {
             checklistEditorInput = (ChecklistEditorInput) input;
-            setPartName(getPartName() + ": " + checklistEditorInput.getName());
+            setPartName(getPartName() + ": " + checklistEditorInput.getName()); //$NON-NLS-1$
             conversation = checklistEditorInput.getConversation();
             conversation.registerForDataStoreChanges(this);
         }
@@ -672,6 +685,8 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
      */
     @Override
     public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+//     System.out.println(selection.getClass().getSimpleName());
+//     viewer.setSelection(selection, true);
     }
 
 
@@ -749,11 +764,11 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
         conversation = null;
     }
 
-    private static final List<String> NODE_INIT_STRATEGY = Arrays.asList(new String[] { "descriptions",
-            "descriptions.*", "description.state", "feature", "feature.*", "childNodes", "childNodes.taxon",
-            "childNodes.taxon.name", "taxonNodes", "taxonNodes.*", "taxonNodes.taxon.*", "taxon.*",
-            "taxon.descriptions", "taxon.sec", "taxon.name.*", "terms", "name.*",
-            "name.rank.representations", "name.status.type.representations", "stateData.$" });
+    private static final List<String> NODE_INIT_STRATEGY = Arrays.asList(new String[] { "descriptions", //$NON-NLS-1$
+            "descriptions.*", "description.state", "feature", "feature.*", "childNodes", "childNodes.taxon", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
+            "childNodes.taxon.name", "taxonNodes", "taxonNodes.*", "taxonNodes.taxon.*", "taxon.*", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+            "taxon.descriptions", "taxon.sec", "taxon.name.*", "terms", "name.*", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+            "name.rank.representations", "name.status.type.representations", "stateData.$" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 
     /*
      * (non-Javadoc)
@@ -766,6 +781,9 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
     public void changed(Object element) {
         if (element != null) {
             viewer.update(element, null);
+            if (element instanceof Taxon){
+                checklistEditorInput.addTaxonToSave((Taxon)element);
+            }
             setDirty(true);
             firePropertyChange(PROP_DIRTY);
         }
@@ -841,6 +859,6 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
 
         return conversation;
     }
-    
-    
+
+
 }