From: n.hoffmann Date: Tue, 20 Jan 2009 19:05:15 +0000 (+0000) Subject: Massive refactoring of the methodology in former class UiUtils X-Git-Tag: rcp.ss-first-working-version~969 X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/d086b1f5ed7565d37e96b4ca907321b526f9f07d Massive refactoring of the methodology in former class UiUtils --- diff --git a/.gitattributes b/.gitattributes index 83142093f..b026adf7c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -396,7 +396,6 @@ eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/ITaxEditorCons eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/Messages.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/SideBySidePerspective.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/TaxEditorPlugin.java -text -eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/UiUtil.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/NameTransfer.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/SaveAllAction.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/SynonymRelationshipTransfer.java -text @@ -440,6 +439,11 @@ eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/Ope eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/OpenTaxonEditorAction.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/description/AddDescriptionElementCompositeAction.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/description/DeleteElementCompositeAction.java -text +eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/controller/EditorController.java -text +eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/controller/GlobalController.java -text +eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/controller/PropertySheetController.java -text +eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/controller/SearchController.java -text +eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/controller/TreeController.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/CdmDataSourceDialog.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/CdmDataSourceRepository.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/CdmTransactionController.java -text @@ -509,6 +513,7 @@ eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/Tax eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/TaxonomicTreeView.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/TaxonomicTreeViewer.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/AbstractEditorOperation.java -text +eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/ChangeTaxonToSynonymOperation.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/DeleteTaxonOperation.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/MoveTaxonOperation.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/name/ChangeHomotypicGroupOperation.java -text diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/com/swtdesigner/ResourceManager.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/com/swtdesigner/ResourceManager.java index b8480f6eb..8e426869a 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/com/swtdesigner/ResourceManager.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/com/swtdesigner/ResourceManager.java @@ -141,10 +141,26 @@ public class ResourceManager extends SWTResourceManager { */ public static void disposeImages() { SWTResourceManager.disposeImages(); - // - for (Iterator I = m_DescriptorImageMap.values().iterator(); I.hasNext();) - I.next().dispose(); - m_DescriptorImageMap.clear(); + // dispose ImageDescriptor images + { + for (Iterator I = m_DescriptorImageMap.values().iterator(); I.hasNext();) + I.next().dispose(); + m_DescriptorImageMap.clear(); + } + // dispose plugin images + { + for (Iterator I = m_URLImageMap.values().iterator(); I.hasNext();) + I.next().dispose(); + m_URLImageMap.clear(); + } + // dispose decorated images + for (Iterator> I = m_ImageToDecoratorMap.values().iterator(); I.hasNext();) { + HashMap decoratedMap = I.next(); + for (Iterator J = decoratedMap.values().iterator(); J.hasNext();) { + Image decoratedImage = J.next(); + decoratedImage.dispose(); + } + } } ////////////////////////////// @@ -213,22 +229,21 @@ public class ResourceManager extends SWTResourceManager { * @return URL The URL representing the file at the specified path * @throws Exception */ - @SuppressWarnings("unchecked") //$NON-NLS-1$ private static URL getPluginImageURL(Object plugin, String name) throws Exception { // try to work with 'plugin' as with OSGI BundleContext try { - Class bundleClass = Class.forName("org.osgi.framework.Bundle"); //$NON-NLS-1$ - Class bundleContextClass = Class.forName("org.osgi.framework.BundleContext"); //$NON-NLS-1$ + Class bundleClass = Class.forName("org.osgi.framework.Bundle"); //$NON-NLS-1$ + Class bundleContextClass = Class.forName("org.osgi.framework.BundleContext"); //$NON-NLS-1$ if (bundleContextClass.isAssignableFrom(plugin.getClass())) { - Method getBundleMethod = bundleContextClass.getMethod("getBundle", new Class[]{}); //$NON-NLS-1$ - Object bundle = getBundleMethod.invoke(plugin, new Object[]{}); + Method getBundleMethod = bundleContextClass.getMethod("getBundle", new Class[0]); //$NON-NLS-1$ + Object bundle = getBundleMethod.invoke(plugin, new Object[0]); // - Class ipathClass = Class.forName("org.eclipse.core.runtime.IPath"); //$NON-NLS-1$ - Class pathClass = Class.forName("org.eclipse.core.runtime.Path"); //$NON-NLS-1$ - Constructor pathConstructor = pathClass.getConstructor(new Class[]{String.class}); + Class ipathClass = Class.forName("org.eclipse.core.runtime.IPath"); //$NON-NLS-1$ + Class pathClass = Class.forName("org.eclipse.core.runtime.Path"); //$NON-NLS-1$ + Constructor pathConstructor = pathClass.getConstructor(new Class[]{String.class}); Object path = pathConstructor.newInstance(new Object[]{name}); // - Class platformClass = Class.forName("org.eclipse.core.runtime.Platform"); //$NON-NLS-1$ + Class platformClass = Class.forName("org.eclipse.core.runtime.Platform"); //$NON-NLS-1$ Method findMethod = platformClass.getMethod("find", new Class[]{bundleClass, ipathClass}); //$NON-NLS-1$ return (URL) findMethod.invoke(null, new Object[]{bundle, path}); } @@ -237,12 +252,12 @@ public class ResourceManager extends SWTResourceManager { } // else work with 'plugin' as with usual Eclipse plugin { - Class pluginClass = Class.forName("org.eclipse.core.runtime.Plugin"); //$NON-NLS-1$ + Class pluginClass = Class.forName("org.eclipse.core.runtime.Plugin"); //$NON-NLS-1$ if (pluginClass.isAssignableFrom(plugin.getClass())) { // - Class ipathClass = Class.forName("org.eclipse.core.runtime.IPath"); //$NON-NLS-1$ - Class pathClass = Class.forName("org.eclipse.core.runtime.Path"); //$NON-NLS-1$ - Constructor pathConstructor = pathClass.getConstructor(new Class[]{String.class}); + Class ipathClass = Class.forName("org.eclipse.core.runtime.IPath"); //$NON-NLS-1$ + Class pathClass = Class.forName("org.eclipse.core.runtime.Path"); //$NON-NLS-1$ + Constructor pathConstructor = pathClass.getConstructor(new Class[]{String.class}); Object path = pathConstructor.newInstance(new Object[]{name}); // Method findMethod = pluginClass.getMethod("find", new Class[]{ipathClass}); //$NON-NLS-1$ diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/com/swtdesigner/SWTResourceManager.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/com/swtdesigner/SWTResourceManager.java index f0b8891af..4d4f81293 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/com/swtdesigner/SWTResourceManager.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/com/swtdesigner/SWTResourceManager.java @@ -384,9 +384,14 @@ public class SWTResourceManager { * Dispose all of the cached fonts */ public static void disposeFonts() { + // clear fonts for (Iterator iter = m_FontMap.values().iterator(); iter.hasNext();) iter.next().dispose(); m_FontMap.clear(); + // clear bold fonts + for (Iterator iter = m_FontToBoldFontMap.values().iterator(); iter.hasNext();) + iter.next().dispose(); + m_FontToBoldFontMap.clear(); } ////////////////////////////// diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/ApplicationActionBarAdvisor.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/ApplicationActionBarAdvisor.java index 7c90b5a01..318a0c9bc 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/ApplicationActionBarAdvisor.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/ApplicationActionBarAdvisor.java @@ -28,6 +28,7 @@ import eu.etaxonomy.cdm.io.common.ImportWrapper; import eu.etaxonomy.taxeditor.actions.io.ExportAction; import eu.etaxonomy.taxeditor.actions.io.ImportAction; import eu.etaxonomy.taxeditor.actions.ui.OpenTaxonEditorAction; +import eu.etaxonomy.taxeditor.controller.GlobalController; /** * An action bar advisor is responsible for creating, adding, and disposing of @@ -70,7 +71,7 @@ public class ApplicationActionBarAdvisor extends ActionBarAdvisor { // Registering also provides automatic disposal of the actions when // the window is closed. - UiUtil.setStatusLineManager(getActionBarConfigurer().getStatusLineManager()); + GlobalController.setStatusLineManager(getActionBarConfigurer().getStatusLineManager()); saveAction = ActionFactory.SAVE.create(window); register(saveAction); diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/ApplicationWorkbenchAdvisor.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/ApplicationWorkbenchAdvisor.java index 430af0dfb..a34eb46fc 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/ApplicationWorkbenchAdvisor.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/ApplicationWorkbenchAdvisor.java @@ -21,9 +21,12 @@ public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor { public void initialize(IWorkbenchConfigurer configurer) { super.initialize(configurer); - // Remembers the user's layout and window size + // Remembers the user's view layout, window size, window location etc. // for the next time application is started -// configurer.setSaveAndRestore(true); + + // IMPORTANT as we don not have a mechanism to open views via a menu + // at the moment this has to be set to false everytime a new view is added, + // otherwise the view will not show because it is not stored in the memento + configurer.setSaveAndRestore(false); } - } diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/ApplicationWorkbenchWindowAdvisor.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/ApplicationWorkbenchWindowAdvisor.java index 5bb702e38..6cd9385ec 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/ApplicationWorkbenchWindowAdvisor.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/ApplicationWorkbenchWindowAdvisor.java @@ -20,6 +20,7 @@ import org.eclipse.ui.application.IWorkbenchWindowConfigurer; import org.eclipse.ui.application.WorkbenchWindowAdvisor; import eu.etaxonomy.cdm.model.name.NomenclaturalCode; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.preference.InitNomenclaturalCodePrefDialog; import eu.etaxonomy.taxeditor.preference.PreferencesUtil; @@ -59,12 +60,12 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { if (PreferencesUtil.getPreferredNomenclaturalCode() == null) { // Query user re: preferred nom. code - Dialog dialog = new InitNomenclaturalCodePrefDialog(UiUtil.getShell()); + Dialog dialog = new InitNomenclaturalCodePrefDialog(GlobalController.getShell()); int returnCode = dialog.open(); // Short message confirming user's choice String code = PreferencesUtil.getPreferredNomenclaturalCodeAsString(); - MessageDialog.openInformation(UiUtil.getShell(), "Nomenclatural code set", + MessageDialog.openInformation(GlobalController.getShell(), "Nomenclatural code set", "The following has been set as your preferred nomenclatural code:\n\n\t" + code + "\n\nYou can change the botanical code at any time in the \"Preferences\" menu."); } diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/FreetextPropertiesPerspective.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/FreetextPropertiesPerspective.java index bad0134b6..99a83b895 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/FreetextPropertiesPerspective.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/FreetextPropertiesPerspective.java @@ -29,6 +29,12 @@ public class FreetextPropertiesPerspective implements IPerspectiveFactory { * To remember the user's layout and window sizes for the next time they * start your application, add configurer.setSaveAndRestore(true); to the * initialize() method of WorkbenchAdvisor. + * + * IMPORTANT: + * If you set configurer.setSaveAndRestore(true) and you are adding a new view + * to the perspective make sure you set it to false for at least one start. + * Otherwise the new view will not show. + * */ public static final String ID = "eu.etaxonomy.taxeditor.perspective.freetextproperties"; diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/ITaxEditorConstants.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/ITaxEditorConstants.java index eee19a0ee..20bee80f3 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/ITaxEditorConstants.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/ITaxEditorConstants.java @@ -9,7 +9,6 @@ package eu.etaxonomy.taxeditor; -import org.apache.log4j.Logger; /** * @author p.ciardelli @@ -17,8 +16,6 @@ import org.apache.log4j.Logger; * @version 1.0 */ public class ITaxEditorConstants { - private static final Logger logger = Logger - .getLogger(ITaxEditorConstants.class); /* *************************************************************************************** ICONS diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/UiUtil.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/UiUtil.java deleted file mode 100644 index 0795d2260..000000000 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/UiUtil.java +++ /dev/null @@ -1,630 +0,0 @@ -/** - * Copyright (C) 2007 EDIT - * European Distributed Institute of Taxonomy - * http://www.e-taxonomy.eu - * - * The contents of this file are subject to the Mozilla Public License Version 1.1 - * See LICENSE.TXT at the top of this package for the full license terms. - */ - -package eu.etaxonomy.taxeditor; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.SortedSet; - -import org.apache.log4j.Logger; -import org.eclipse.core.commands.operations.IOperationHistory; -import org.eclipse.core.commands.operations.IUndoContext; -import org.eclipse.core.commands.operations.OperationHistoryFactory; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.action.IStatusLineManager; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.swt.widgets.TreeItem; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IEditorReference; -import org.eclipse.ui.IPageLayout; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IViewReference; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.operations.IWorkbenchOperationSupport; -import org.eclipse.ui.views.properties.PropertySheet; -import org.eclipse.ui.views.properties.PropertySheetPage; - -import eu.etaxonomy.cdm.model.description.Feature; -import eu.etaxonomy.cdm.model.name.NameRelationshipType; -import eu.etaxonomy.cdm.model.name.Rank; -import eu.etaxonomy.cdm.model.name.TaxonNameBase; -import eu.etaxonomy.cdm.model.taxon.Taxon; -import eu.etaxonomy.taxeditor.actions.cdm.SaveTaxonAction; -import eu.etaxonomy.taxeditor.datasource.CdmTransactionController; -import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor; -import eu.etaxonomy.taxeditor.editor.name.CdmParserController; -import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor; -import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository; -import eu.etaxonomy.taxeditor.model.NameEditorInput; -import eu.etaxonomy.taxeditor.navigation.SearchResult; -import eu.etaxonomy.taxeditor.navigation.SearchResultView; -import eu.etaxonomy.taxeditor.navigation.RecentNamesView; -import eu.etaxonomy.taxeditor.navigation.TaxonomicTreeView; -import eu.etaxonomy.taxeditor.navigation.TaxonomicTreeViewer; -import eu.etaxonomy.taxeditor.propertysheet.CustomSortPropertySheetEntry; - -/** - * A collection of useful methods related to the UI. - * - * @author p.ciardelli - * @created 27.05.2008 - * @version 1.0 - */ -public class UiUtil { - private static final Logger logger = Logger.getLogger(UiUtil.class); - - public static Set preferredFeatureSet; - public static Set preferredRankSet; - private static IViewPart treeView; - - private static IOperationHistory operationHistory; - - public static IViewPart getPropertySheet() { - for (IViewReference reference : getActivePage().getViewReferences()) { - if (reference.getId().equals(IPageLayout.ID_PROP_SHEET)) { - logger.warn(reference.getView(false).getSite().getPart().getTitle()); - return reference.getView(false); - } - } - return null; - } - - /** - * By default, property sheet has buttons in the toolbar for - * "Show advanced properties" and "Show categories". - *

- * This is confusing for the user, hence a method to remove them - * until such time as advanced properties or categories are implemented. - */ - public static void hidePropertySheetToolbar() { - PropertySheet propertySheet = (PropertySheet) getPropertySheet(); - IActionBars actionBars = propertySheet.getViewSite().getActionBars(); - actionBars.getToolBarManager().removeAll(); - actionBars.getMenuManager().removeAll(); - } - - /** - * The property sheet listener ensures only property sheets - * with data cause the Property Sheet to be updated. - */ - public static void addPropertySheetInputListener() { - IViewPart propertySheet = getPropertySheet(); -// propertySheet.get - PropertySheet ps = (PropertySheet) propertySheet; -// ps.addPartPropertyListener(listener) -// ps.addPropertyListener(l) - } - - public static void saveAll(){ - setIsSaving(true); - - // Get all open windows - for (IEditorPart taxonEditor : getOpenTaxonEditors()) { - - // Save the dirty ones - if (taxonEditor.isDirty()) { - - - IEditorInput input = taxonEditor.getEditorInput(); - if (input.getAdapter(Taxon.class) != null) { - Taxon taxon = (Taxon) input.getAdapter(Taxon.class); - CdmSessionDataRepository.getDefault().saveTaxon(taxon); - if (taxonEditor instanceof MultiPageTaxonEditor) { - ((MultiPageTaxonEditor) taxonEditor).setDirtyExtern(false); - } - } - } - } - - // Commit the transaction - CdmTransactionController.commitTransaction(); - - // Force library objects to be associated with new transaction - CdmSessionDataRepository.getDefault().clearNonTaxonData(); - - // Start a new transaction - CdmTransactionController.startTransaction(); - - // Put all open taxa in the new transaction - CdmTransactionController.addSessionTaxaToTransaction(); - - setIsSaving(false); - // TODO: delete undoHistory - } - - //public void deleteTaxon() - - /** - * @param input - * @return - * @throws PartInitException - */ - public static IEditorPart getEditorByInput(IEditorInput input) - throws PartInitException { - for (IEditorReference reference : getActivePage().getEditorReferences()) { - if (reference.getEditorInput().equals(input)) { - IEditorPart editor = reference.getEditor(false); - return editor; - } - } - return null; - } - - /** - * Returns a set of all currently open - * MultiPageTaxonEditors. - * - * @return - */ - public static Set getOpenTaxonEditors() { - - Set taxonEditors = new HashSet(); - - for (IEditorReference reference : getActivePage().getEditorReferences()) { - IEditorPart editor = reference.getEditor(false); - if (editor instanceof MultiPageTaxonEditor) { - taxonEditors.add(editor); - } - } - return taxonEditors; - } - - public static boolean closeOpenTaxonEditors() { - for (IEditorPart editor : getOpenTaxonEditors()) { - if (!getActivePage().closeEditor(editor, true)) { - return false; - } - } - return true; - } - - public static IEditorPart getEditorByTaxon(Taxon taxon) - throws PartInitException { - IEditorInput input = new NameEditorInput(taxon); - return getEditorByInput(input); - } - - /** - * @return - */ - public static IWorkbenchPage getActivePage() { - return TaxEditorPlugin.getDefault().getWorkbench() - .getActiveWorkbenchWindow().getActivePage(); - } - - /** - * @return - */ - public static Shell getShell() { - return TaxEditorPlugin.getDefault().getWorkbench() - .getActiveWorkbenchWindow().getShell(); - } - - /** - * @param input - * @param editorId - * @return - * @throws PartInitException - */ - public static IEditorPart openEditor(IEditorInput input, String editorId) - throws PartInitException { - return getActivePage().openEditor(input, editorId); - } - - /** - * Open an emtpy taxon editor - * - * @return - * @throws PartInitException - */ - public static IEditorPart openTaxonEditor() - throws PartInitException{ - return openTaxonEditor(null); - } - - /** - * Open a taxon editor for the given taxon - * - * @param taxon - * @return - * @throws PartInitException - */ - public static IEditorPart openTaxonEditor(Taxon taxon) - throws PartInitException{ - if(taxon == null){ - TaxonNameBase name = CdmParserController.parseFullReference("", null, null); - name.setFullTitleCache("", false); - name.setTitleCache("", false); - taxon = Taxon.NewInstance(name, - CdmSessionDataRepository.getDefault().getDefaultSec()); - }else{ - // If this taxon is not visible in the tree, open node - TaxonomicTreeViewer treeViewer = getTreeViewer(); - if (treeViewer != null) { - treeViewer.revealTaxon(taxon); - } - - // Add to recent names list - RecentNamesView.addRecentName(taxon); - } - - IEditorInput input = new NameEditorInput(taxon); - return openEditor(input, MultiPageTaxonEditor.ID); - } - - /** - * Redraws an open editor if it exists for the given taxon - * - * @param taxon - * @return - */ - public static boolean redrawEditor(Taxon taxon){ - - TaxonNameEditor editor = UiUtil.getTaxonNameEditor(taxon); - - if(editor == null || editor.redraw()){ - - // Mark editor as changed and unsaved - editor.setDirty(); - - return true; - } - return false; - } - - /** - * @param taxon - * @param save - * @throws PartInitException - */ - public static void closeEditor(Taxon taxon, boolean save) - throws PartInitException { - IEditorPart editor = getEditorByTaxon(taxon); - closeEditor(editor, save); - } - - /** - * @param input - * @param save - * @throws PartInitException - */ - public static void closeEditor(IEditorInput input, boolean save) - throws PartInitException { - IEditorPart editor = getEditorByInput(input); - closeEditor(editor, save); - } - - /** - * @param editor - * @param save - * @throws PartInitException - */ - public static void closeEditor(IEditorPart editor, boolean save) - throws PartInitException { - if (editor != null) { - getActivePage().closeEditor(editor, save); - } - } - - public static IViewPart getViewById(String id) { - return TaxEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow(). - getActivePage().findView(id); - } - - - /** - * Returns the TaxonomicTreeViewer used for navigation. Not to - * be confused with the window that contains it, TaxonomicTreeView. - * - * @return - */ - public static TaxonomicTreeViewer getTreeViewer() { - TaxonomicTreeView view = getTreeView(); - if (view == null) { - return null; - } - return view.getTreeViewer(); - } - - /** - * @see eu.etaxonomy.taxeditor.navigation.TaxonomicTreeView#createTreeViewer() - * - * @return - */ - public static TaxonomicTreeViewer createTreeViewer() { - TaxonomicTreeView view = getTreeView(); - if (view == null) { - return null; - } - return view.createTreeViewer(); - } - - /** - * Returns the TaxonomicTreeView containing the - * TaxonomicTreeViewer used for navigation. - * - * @return - */ - public static TaxonomicTreeView getTreeView() { - if (treeView == null) { - treeView = getViewById(TaxonomicTreeView.ID); - if (!(treeView instanceof TaxonomicTreeView)) { - treeView = null; - } - } - return (TaxonomicTreeView) treeView; - } - - - public static IWorkbenchOperationSupport getOperationSupport() { - IWorkbench workbench = TaxEditorPlugin.getDefault().getWorkbench(); - return workbench.getOperationSupport(); - } - - public static IOperationHistory getOperationHistory() { -// if (operationHistory == null) { -//// operationHistory = getOperationSupport().getOperationHistory(); -// operationHistory = OperationHistoryFactory.getOperationHistory(); -// } -// return operationHistory; - return getOperationSupport().getOperationHistory(); - } - - public static IUndoContext getWorkbenchUndoContext() { - // TODO make this more specific than GLOBAL_UNDO_CONTEXT -// return getOperationSupport().getUndoContext(); - return IOperationHistory.GLOBAL_UNDO_CONTEXT; - } - - public static void doEditorSave(Taxon taxon, boolean confirm) { - IEditorPart editor = null; - try { - editor = getEditorByTaxon(taxon); - } catch (PartInitException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - if (editor != null) { - getActivePage().saveEditor(editor, confirm); - } - } - - -// public static EditorGroupComposite getMisappliedNameGroupComposite( -// IManagedForm managedForm) { -// -// // Iterate through parent's children until we find a composite which has a data field -// // for MISAPPLIED_NAME -// Composite parent = managedForm.getForm().getBody(); -// for (Control groupComposite : parent.getChildren()) { -// if (groupComposite instanceof EditorGroupComposite) { -// if (groupComposite.getData(ITaxEditorConstants.MISAPPLIED_NAME) != null) { -// return (EditorGroupComposite) groupComposite; -// } -// } -// } -// return null; -// } - -// public static EditorGroupComposite createMisappliedNameGroupComposite( -// IManagedForm managedForm) { -// -// Composite parent = managedForm.getForm().getBody(); -// -// EditorGroupComposite composite = new EditorGroupComposite(parent, managedForm); -// composite.setData(ITaxEditorConstants.MISAPPLIED_NAME,""); -// new CompositeBorderDecorator(composite, managedForm); -// return composite; -// } - - public static void setStatusMessage(String msg) { - getPropertySheet().getViewSite().getActionBars().getStatusLineManager().setMessage(msg); - } - - public static void setPropertySheetTree(Tree tree) { - TaxEditorPlugin.getDefault().setPropertySheetTree(tree); - } - - public static Tree getPropertySheetTree() { - return TaxEditorPlugin.getDefault().getPropertySheetTree(); - } - - public static void setPropertySheetPage(PropertySheetPage page) { - TaxEditorPlugin.getDefault().setPropertySheetPage(page); - } - - public static PropertySheetPage getPropertySheetPage() { - return TaxEditorPlugin.getDefault().getPropertySheetPage(); - } - - /** - * UiUtil.paintPropertySheetRow(P_DATEPUBLISHED, new Color(Display.getDefault(), WarningAnnotation.WARNING_RGB), true); - * UiUtil.unpaintPropertySheetRow(P_DATEPUBLISHED); - * - * @param id - * @param color - * @param doPaintChildren - */ - public static void paintPropertySheetRow(String id, Color color, boolean doPaintChildren) { - - // Catch null property sheet name - if (id == null) { - return; - } - - // Catch uninit'ed property sheet tree - if (getPropertySheetTree() == null) { - return; - } - - paintPropertySheetRow(id, color, doPaintChildren, getPropertySheetTree()); - } - - private static void paintPropertySheetRow(String id, Color color, boolean doPaintChildren, Object treeOrItem) { - - // Init items w zero-length array - TreeItem[] items = new TreeItem[]{}; - - // Get child items depending to class - if (treeOrItem instanceof Tree) { - items = ((Tree) treeOrItem).getItems(); - } - if (treeOrItem instanceof TreeItem) { - items = ((TreeItem) treeOrItem).getItems(); - } - - // If array hasn't been populated by the above, return - if (items.length == 0) { - return; - } - - // Prop. sheet id's take the form "01:xxxx" for sorting - truncate - id = CustomSortPropertySheetEntry.truncateDisplayName(id); - - // Iterate through child items - for (TreeItem item : items) { - - // Item found, paint it - if (id.equals(item.getText())) { - paintItem(item, color, doPaintChildren); - return; - } - - // Recursively search for item to paint in child items - if (item.getItemCount() > 0) { - paintPropertySheetRow(id, color, doPaintChildren, item); - } - } - } - - /** - * Note: children are only painted if submenu has already been created, i.e. opened once. - * - * @param item - * @param color - * @param doPaintChildren - */ - private static void paintItem(TreeItem item, Color color, boolean doPaintChildren) { - - // Paint the item - item.setBackground(color); - - // Recursively paint child items if requested - if (doPaintChildren) { - for (TreeItem childItem : item.getItems()) { - paintItem(childItem, color, doPaintChildren); - } - } - } - - public static void unpaintPropertySheetRow(String id) { - - // Catch uninit'ed property sheet tree - if (getPropertySheetTree() == null) { - return; - } - - // Get tree's background color to "unpaint" - Color color = getPropertySheetTree().getBackground(); - - paintPropertySheetRow(id, color, true); - } - - /** - * Get the name out of the session's name relations vocabulary, not directly - * from the object. - * - * @param type - * @return - */ - public static String getNameRelationLabelType(NameRelationshipType type) { - SortedSet vocab = - CdmSessionDataRepository.getDefault().getNameRelationshipTypes(); - for (NameRelationshipType type1 : vocab) { - if (type1.equals(type)) { - return type1.getLabel(); - } - } - return ""; - } - - static boolean isSaving = false; - - private static IStatusLineManager statusLineManager; - - private static Map taxonNameEditors; - - public static void setIsSaving(boolean isSavin) { - isSaving = isSavin; - } - - public static boolean getIsSaving() { - return isSaving; - } - - public static void setStatusLineManager(IStatusLineManager manager) { - statusLineManager = manager; - } - - public static void setStatusLine(String message) { - statusLineManager.setMessage(message); - } - - public static IProgressMonitor getStatusLineProgressMonitor() { - statusLineManager.setCancelEnabled(false); - return statusLineManager.getProgressMonitor(); - } - - public static void addTaxonNameEditor( - Taxon taxon, TaxonNameEditor taxonNameEditor) { - if (taxonNameEditors == null) { - taxonNameEditors = new HashMap(); - } - taxonNameEditors.put(taxon, taxonNameEditor); - } - - public static TaxonNameEditor getTaxonNameEditor(Taxon taxon) { - if (taxonNameEditors == null) { - return null; - } - return taxonNameEditors.get(taxon); - } - - public static IUndoContext getTaxonNameEditorUndoContext(Taxon taxon) { - // TODO make this taxon name editor specific -// return getTaxonNameEditor(taxon).getUndoContext(); - return IOperationHistory.GLOBAL_UNDO_CONTEXT; - } - - static String srv = ""; - - public static void openSearchResultsView(SearchResult searchResult) { - srv += "1"; - logger.warn("opening search results window " + srv); - try { - IViewPart resultsView = getActivePage().showView(SearchResultView.ID, - srv, IWorkbenchPage.VIEW_VISIBLE); - ((SearchResultView) resultsView).setResult(searchResult); - } catch (PartInitException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } -} \ No newline at end of file diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/SaveAllAction.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/SaveAllAction.java index 6e8c7373a..ed76c618f 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/SaveAllAction.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/SaveAllAction.java @@ -18,8 +18,8 @@ import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; import eu.etaxonomy.cdm.model.taxon.Taxon; -import eu.etaxonomy.taxeditor.UiUtil; import eu.etaxonomy.taxeditor.actions.cdm.SaveTaxonAction; +import eu.etaxonomy.taxeditor.controller.EditorController; import eu.etaxonomy.taxeditor.datasource.CdmTransactionController; import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor; import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository; @@ -54,10 +54,10 @@ public class SaveAllAction implements IWorkbenchWindowActionDelegate { */ public void run(IAction action) { - UiUtil.setIsSaving(true); + EditorController.setSaving(true); // Get all open windows - for (IEditorPart taxonEditor : UiUtil.getOpenTaxonEditors()) { + for (IEditorPart taxonEditor : EditorController.getOpenEditors()) { // Save the dirty ones if (taxonEditor.isDirty()) { @@ -84,7 +84,7 @@ public class SaveAllAction implements IWorkbenchWindowActionDelegate { // Put all open taxa in the new transaction CdmTransactionController.addSessionTaxaToTransaction(); - UiUtil.setIsSaving(false); + EditorController.setSaving(false); // TODO: delete undoHistory } diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/UndoableAction.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/UndoableAction.java index 47576da82..0940553b3 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/UndoableAction.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/UndoableAction.java @@ -21,7 +21,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.action.Action; import org.eclipse.jface.resource.ImageDescriptor; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.GlobalController; /** * @author p.ciardelli @@ -44,8 +44,8 @@ public abstract class UndoableAction extends Action { public void run() { - IOperationHistory operationHistory = UiUtil.getOperationHistory(); - IUndoContext undoContext = UiUtil.getWorkbenchUndoContext(); + IOperationHistory operationHistory = GlobalController.getOperationHistory(); + IUndoContext undoContext = GlobalController.getWorkbenchUndoContext(); operation.addContext(undoContext); try { operationHistory.execute(operation, null, null); diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/cdm/DeleteTaxonAction.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/cdm/DeleteTaxonAction.java index fabf90a7d..e58766f15 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/cdm/DeleteTaxonAction.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/cdm/DeleteTaxonAction.java @@ -27,7 +27,7 @@ import org.eclipse.jface.resource.ImageDescriptor; import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.taxeditor.ITaxEditorConstants; import eu.etaxonomy.taxeditor.TaxEditorPlugin; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.operations.DeleteTaxonOperation; /** @@ -44,7 +44,6 @@ public class DeleteTaxonAction extends Action { private ImageDescriptor image = TaxEditorPlugin.getDefault() .getImageDescriptor(ITaxEditorConstants.ACTIVE_DELETE_ICON); - private IOperationHistory operationHistory; private IUndoContext undoContext; Taxon taxon; @@ -53,8 +52,7 @@ public class DeleteTaxonAction extends Action { super(text); setImageDescriptor(image); - operationHistory = UiUtil.getOperationHistory(); - undoContext = UiUtil.getWorkbenchUndoContext(); + undoContext = GlobalController.getWorkbenchUndoContext(); } public DeleteTaxonAction(Taxon taxon) { @@ -67,66 +65,6 @@ public class DeleteTaxonAction extends Action { IUndoableOperation operation = new DeleteTaxonOperation (this.getText(), undoContext, taxon); - IProgressMonitor monitor = UiUtil.getStatusLineProgressMonitor(); - - try { - IStatus status = operationHistory.execute(operation, monitor, null); - } catch (ExecutionException e) { - logger.error("Error deleting taxon", e); - } - - // Handle this in an operation so we are able to undo it - -// -// // Get taxon name for progress monitor -// String taxonName = CdmUtil.getDisplayName(taxon); -// -// // Get and start progress monitor -// IProgressMonitor monitor = UiUtil.getStatusLineProgressMonitor(); -// monitor.beginTask("Deleting taxon '" + taxonName + "'.", 10); -// -// // Call save all action -// new SaveAllAction().run(null); -// monitor.worked(2); -// -// // If the taxon has children, cancel operation -// // TODO add option to continue, and delete children -// if (taxon.hasTaxonomicChildren()) { -// MessageDialog.openInformation(UiUtil.getShell(), "Cannot delete taxon", -// "'" + CdmUtil.getDisplayName(taxon) + "' has taxonomic children. " + -// "These must be manually deleted before their parent."); -// monitor.done(); -// return; -// } -// monitor.worked(1); -// -// -// // Close taxon's editor, if any is active -// try { -// UiUtil.closeEditor(taxon, true); -// } catch (PartInitException e) { -// e.printStackTrace(); -// } -// monitor.worked(1); -// -// // Delete taxon from CDM layer -// CdmSessionDataRepository.getDefault().deleteTaxon(taxon); -// monitor.worked(4); -// -// -// -// // Call save all action -// new SaveAllAction().run(null); -// monitor.worked(2); -// -// // Close the progress monitor -// monitor.done(); -// -// // Announce taxon was deleted on status line -// UiUtil.setStatusLine("Deleted taxon '" + taxonName + "'."); -// -//// Status status = new Status(IStatus.INFO, TaxEditorPlugin.PLUGIN_ID, -//// "Deleted.", null); -//// StatusManager.getManager().handle(status, StatusManager.SHOW); + GlobalController.executeOperation(operation); } } \ No newline at end of file diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/cdm/MoveTaxonAction.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/cdm/MoveTaxonAction.java index 609be0b86..8b8b10cc2 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/cdm/MoveTaxonAction.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/cdm/MoveTaxonAction.java @@ -15,7 +15,7 @@ import org.eclipse.jface.viewers.ISelection; import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.taxeditor.TaxEditorPlugin; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository; import eu.etaxonomy.taxeditor.navigation.TaxonomicTreeViewer; diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/cdm/SaveTaxonAction.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/cdm/SaveTaxonAction.java index f73a36b48..e3160a9b6 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/cdm/SaveTaxonAction.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/cdm/SaveTaxonAction.java @@ -15,7 +15,7 @@ import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository; public class SaveTaxonAction extends Action { private static final Logger logger = Logger.getLogger(SaveTaxonAction.class); - Taxon taxon; + private Taxon taxon; public SaveTaxonAction(Taxon taxon) { this.taxon = taxon; @@ -25,6 +25,5 @@ public class SaveTaxonAction extends Action { // Save the taxon to the CDM CdmSessionDataRepository.getDefault().saveTaxon(taxon); - // TODO delete undoHistory for this editor } } \ No newline at end of file diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/cdm/SwapSynonymAndTaxonAction.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/cdm/SwapSynonymAndTaxonAction.java index fa58e68ef..cd88519b8 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/cdm/SwapSynonymAndTaxonAction.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/cdm/SwapSynonymAndTaxonAction.java @@ -24,7 +24,8 @@ import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType; import eu.etaxonomy.taxeditor.ITaxEditorConstants; import eu.etaxonomy.taxeditor.TaxEditorPlugin; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.EditorController; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.model.CdmUtil; /** @@ -54,9 +55,9 @@ public class SwapSynonymAndTaxonAction extends Action { // instead of implementing the logic here try { - IEditorPart oldEditor = UiUtil.getEditorByTaxon(taxon); + IEditorPart oldEditor = EditorController.getEditorByTaxon(taxon); if (oldEditor.isDirty()) { - if (!MessageDialog.openConfirm(UiUtil.getShell(), "Save before proceeding", + if (!MessageDialog.openConfirm(GlobalController.getShell(), "Save before proceeding", "All changes must be saved before proceeding with this action.\n\n" + "Press \"OK\" to save and continue, or \"Cancel\" to cancel this action.")) { return; @@ -65,7 +66,7 @@ public class SwapSynonymAndTaxonAction extends Action { } } catch (PartInitException e) { e.printStackTrace(); - MessageDialog.openError(UiUtil.getShell(), "Error", "Error swapping synonym and taxon"); + MessageDialog.openError(GlobalController.getShell(), "Error", "Error swapping synonym and taxon"); return; } diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/io/ExportAction.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/io/ExportAction.java index 8ea428766..a719b848d 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/io/ExportAction.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/io/ExportAction.java @@ -21,7 +21,7 @@ import org.eclipse.swt.widgets.FileDialog; import eu.etaxonomy.cdm.database.ICdmDataSource; import eu.etaxonomy.cdm.io.common.CdmDefaultExport; import eu.etaxonomy.cdm.io.jaxb.JaxbExportConfigurator; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository; /** @@ -62,7 +62,7 @@ public class ExportAction extends Action { String title = "Export " + getText(); // Get file from user - dialog = new FileDialog(UiUtil.getShell(), SWT.SAVE); + dialog = new FileDialog(GlobalController.getShell(), SWT.SAVE); dialog.setFileName("export.xml"); String filePath = dialog.open(); file = new File(filePath); @@ -84,9 +84,9 @@ public class ExportAction extends Action { // Tell user whether import was a success or a dismal failure if (isSuccessfulExport) { - MessageDialog.openInformation(UiUtil.getShell(), title, "Export successful"); + MessageDialog.openInformation(GlobalController.getShell(), title, "Export successful"); } else { - MessageDialog.openError(UiUtil.getShell(), title, "Export was unsuccessful."); + MessageDialog.openError(GlobalController.getShell(), title, "Export was unsuccessful."); } } } diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/io/ImportAction.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/io/ImportAction.java index f27c09b20..26a3d6c59 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/io/ImportAction.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/io/ImportAction.java @@ -19,7 +19,8 @@ import org.eclipse.swt.widgets.FileDialog; import eu.etaxonomy.cdm.database.ICdmDataSource; import eu.etaxonomy.cdm.io.common.ImportWrapper; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.TreeController; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository; /** @@ -57,7 +58,7 @@ public class ImportAction extends Action { String title = "Import " + getText(); // Make sure user is aware of the implications of an import - boolean doProceed = MessageDialog.openConfirm(UiUtil.getShell(), title, + boolean doProceed = MessageDialog.openConfirm(GlobalController.getShell(), title, "Import may require a great deal of time and system resources.\n\n" + "Are you sure you would like to proceed?"); if (!doProceed) { @@ -65,7 +66,7 @@ public class ImportAction extends Action { } // Get file from user - dialog = new FileDialog(UiUtil.getShell()); + dialog = new FileDialog(GlobalController.getShell()); String filePath = dialog.open(); file = new File(filePath); @@ -83,7 +84,7 @@ public class ImportAction extends Action { source = file.toURI().toURL().toString(); //source = file.toString(); } catch (/*MalformedURL*/Exception e) { - MessageDialog.openError(UiUtil.getShell(), title, "File could not be read."); + MessageDialog.openError(GlobalController.getShell(), title, "File could not be read."); return; } @@ -92,10 +93,10 @@ public class ImportAction extends Action { // Tell user whether import was a success or a dismal failure if (isSuccessfulImport) { - MessageDialog.openInformation(UiUtil.getShell(), title, "Import successful"); - UiUtil.getTreeViewer().refresh(); + MessageDialog.openInformation(GlobalController.getShell(), title, "Import successful"); + TreeController.getTreeViewer().refresh(); } else { - MessageDialog.openError(UiUtil.getShell(), title, "Import was unsuccessful."); + MessageDialog.openError(GlobalController.getShell(), title, "Import was unsuccessful."); } } diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/AddQuickNameAction.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/AddQuickNameAction.java index 31e8160c2..d956d6d0a 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/AddQuickNameAction.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/AddQuickNameAction.java @@ -18,7 +18,7 @@ import eu.etaxonomy.cdm.model.reference.ReferenceBase; import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.taxeditor.ITaxEditorConstants; import eu.etaxonomy.taxeditor.TaxEditorPlugin; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.TreeController; import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository; import eu.etaxonomy.taxeditor.navigation.TaxonomicTreeViewer; import eu.etaxonomy.taxeditor.preference.PreferencesUtil; @@ -70,7 +70,7 @@ public class AddQuickNameAction extends Action { firePropertyChange(ITaxEditorConstants.QUICK_NAME_TAXON, null, quickNameTaxon); - TaxonomicTreeViewer treeViewer = UiUtil.getTreeViewer(); + TaxonomicTreeViewer treeViewer = TreeController.getTreeViewer(); if (treeViewer == null) { return; } diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/ChangeCompositeToNewTaxonAction.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/ChangeCompositeToNewTaxonAction.java index 428099b7d..53957c821 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/ChangeCompositeToNewTaxonAction.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/ChangeCompositeToNewTaxonAction.java @@ -30,6 +30,9 @@ import eu.etaxonomy.taxeditor.editor.name.NameComposite; * @author p.ciardelli * @created 09.06.2008 * @version 1.0 + * + * @deprecated + * TODO seems like this is not beeing used at the moment */ public class ChangeCompositeToNewTaxonAction extends UndoableAction { private static final Logger logger = Logger diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/ChangeSynonymToTaxonUiAction.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/ChangeSynonymToTaxonUiAction.java index 5ae5d2cd6..589090728 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/ChangeSynonymToTaxonUiAction.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/ChangeSynonymToTaxonUiAction.java @@ -23,9 +23,9 @@ import eu.etaxonomy.cdm.model.taxon.Synonym; import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.taxeditor.ITaxEditorConstants; import eu.etaxonomy.taxeditor.TaxEditorPlugin; -import eu.etaxonomy.taxeditor.UiUtil; import eu.etaxonomy.taxeditor.actions.UndoableAction; import eu.etaxonomy.taxeditor.actions.cdm.SwapSynonymAndTaxonAction; +import eu.etaxonomy.taxeditor.controller.EditorController; import eu.etaxonomy.taxeditor.editor.name.NameComposite; import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository; import eu.etaxonomy.taxeditor.navigation.RecentNamesView; @@ -65,14 +65,8 @@ public class ChangeSynonymToTaxonUiAction extends UndoableAction { Taxon newTaxon = (Taxon) event.getNewValue(); // Close editor for existing taxon - IEditorPart oldEditor; - try { - oldEditor = UiUtil.getEditorByTaxon(taxon); - UiUtil.closeEditor(oldEditor, true); - } catch (PartInitException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + EditorController.close(taxon, true); + // Remove old taxon from tree CdmSessionDataRepository.getDefault().removeTaxon(taxon); diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/ChangeTaxonToSynonymAction.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/ChangeTaxonToSynonymAction.java index 7940a81ff..1bd8628fc 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/ChangeTaxonToSynonymAction.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/ChangeTaxonToSynonymAction.java @@ -10,26 +10,16 @@ package eu.etaxonomy.taxeditor.actions.ui; import org.apache.log4j.Logger; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.operations.IUndoableOperation; import org.eclipse.jface.action.Action; -import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.PartInitException; -import eu.etaxonomy.cdm.model.description.TaxonDescription; -import eu.etaxonomy.cdm.model.name.TaxonNameBase; -import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType; import eu.etaxonomy.cdm.model.taxon.Taxon; -import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; import eu.etaxonomy.taxeditor.ITaxEditorConstants; import eu.etaxonomy.taxeditor.TaxEditorPlugin; -import eu.etaxonomy.taxeditor.UiUtil; -import eu.etaxonomy.taxeditor.actions.cdm.SaveTaxonAction; -import eu.etaxonomy.taxeditor.editor.SelectTaxonDialog; -import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository; -import eu.etaxonomy.taxeditor.model.CdmUtil; -import eu.etaxonomy.taxeditor.navigation.RecentNamesView; +import eu.etaxonomy.taxeditor.controller.GlobalController; +import eu.etaxonomy.taxeditor.operations.ChangeTaxonToSynonymOperation; /** * @author p.ciardelli @@ -44,99 +34,22 @@ public class ChangeTaxonToSynonymAction extends Action { private ImageDescriptor image = TaxEditorPlugin.getDefault() .getImageRegistry().getDescriptor(ITaxEditorConstants.TAXON_TO_SYNONYM_ICON); - private Taxon oldTaxon; + private Taxon taxon; private ChangeTaxonToSynonymAction() { super(text); setImageDescriptor(image); } - public ChangeTaxonToSynonymAction(Taxon oldTaxon) { + public ChangeTaxonToSynonymAction(Taxon taxon) { this(); - this.oldTaxon = oldTaxon; + this.taxon = taxon; } public void run() { + IUndoableOperation operation = new ChangeTaxonToSynonymOperation(getText(), + GlobalController.getWorkbenchUndoContext(), taxon); - IEditorPart oldEditor = null; - - try { - // Prompt user "Would you like to save?" before showing dialog - // "Cancel" cancels action - "No" does not - oldEditor = UiUtil.getEditorByTaxon(oldTaxon); - if (oldEditor.isDirty()) { - if (!MessageDialog.openConfirm(UiUtil.getShell(), "Save before proceeding", - "All changes must be saved before proceeding with this action.\n\n" + - "Press \"OK\" to save and continue, or \"Cancel\" to cancel this action.")) { - return; - } - oldEditor.doSave(null); - } -// if (UiUtil.getActivePage().saveEditor(oldEditor, true) == false) { -// return; -// } - } catch (PartInitException e1) { - e1.printStackTrace(); - } - - // Get destination taxon from dialog - Shell shell = UiUtil.getShell(); - SelectTaxonDialog dialog = new SelectTaxonDialog(shell, SelectTaxonDialog.TAXON_TO_SYNONYM); - Taxon destinationTaxon = dialog.open(oldTaxon); - - // Abort action if user cancelled dialog without choosing a taxon - if (destinationTaxon == null) { - return; - } - - // Move oldTaxon in CDM - TaxonNameBase synonymName = oldTaxon.getName(); - SynonymRelationshipType synonymType; - if (CdmUtil.isNameHomotypic(synonymName, destinationTaxon)) { -// makeTaxonSynonym -// oldTaxon.makeSynonym(); -// destinationTaxon.addHomotypicSynonymName(synonymName); - synonymType = SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF(); - } else { -// destinationTaxon.addHeterotypicSynonymName(synonymName); - synonymType = SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF(); - } - CdmUtil.makeTaxonSynonym(oldTaxon, destinationTaxon, synonymType, - null, null); - - // TODO move any children, descriptions, synonyms - for (TaxonDescription description: oldTaxon.getDescriptions()) { - destinationTaxon.addDescription(description); - oldTaxon.removeDescription(description); - } - - for (TaxonRelationship fromRelation : oldTaxon.getRelationsFromThisTaxon()) { - fromRelation.setFromTaxon(destinationTaxon); - } - - for (TaxonRelationship toRelation : oldTaxon.getRelationsToThisTaxon()) { - toRelation.setToTaxon(destinationTaxon); - } - -// if (!TaxEditorPlugin.getDefault().getObservableRecentNamesList(). -// contains(oldTaxon)) { -// TaxEditorPlugin.getDefault().getObservableRecentNamesList(). -// remove(oldTaxon); -// RecentNamesView.removeRecentName(oldTaxon); -// } - - CdmSessionDataRepository.getDefault().removeTaxon(oldTaxon); - - // Close open editor for oldTaxon without forcing save. - // User has already saved or declined to do so above. - try { - UiUtil.closeEditor(oldEditor, false); - } catch (PartInitException e) { - e.printStackTrace(); - } - - // Open editor for new oldTaxon - new SaveTaxonAction(destinationTaxon).run(); - new OpenTaxonEditorAction(destinationTaxon).run(); + GlobalController.executeOperation(operation); } } \ No newline at end of file diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/DeleteMisappliedNameCompositeAction.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/DeleteMisappliedNameCompositeAction.java index 5ba19336c..a41669081 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/DeleteMisappliedNameCompositeAction.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/DeleteMisappliedNameCompositeAction.java @@ -27,8 +27,8 @@ import org.eclipse.jface.util.PropertyChangeEvent; import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.taxeditor.ITaxEditorConstants; import eu.etaxonomy.taxeditor.TaxEditorPlugin; -import eu.etaxonomy.taxeditor.UiUtil; import eu.etaxonomy.taxeditor.actions.cdm.DeleteMisappliedNameFromTaxonAction; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.editor.name.NameComposite; /** @@ -72,8 +72,8 @@ public class DeleteMisappliedNameCompositeAction extends Action { } public void run() { - IOperationHistory operationHistory = UiUtil.getOperationHistory(); - IUndoContext undoContext = UiUtil.getWorkbenchUndoContext(); + IOperationHistory operationHistory = GlobalController.getOperationHistory(); + IUndoContext undoContext = GlobalController.getWorkbenchUndoContext(); operation.addContext(undoContext); try { operationHistory.execute(operation, null, null); diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/DeleteSynonymCompositeAction.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/DeleteSynonymCompositeAction.java index 3b86e3ee5..ae7bea49a 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/DeleteSynonymCompositeAction.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/DeleteSynonymCompositeAction.java @@ -28,14 +28,18 @@ import eu.etaxonomy.cdm.model.taxon.Synonym; import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.taxeditor.ITaxEditorConstants; import eu.etaxonomy.taxeditor.TaxEditorPlugin; -import eu.etaxonomy.taxeditor.UiUtil; import eu.etaxonomy.taxeditor.actions.cdm.DeleteSynonymFromTaxonAction; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.editor.name.NameComposite; /** * @author p.ciardelli * @created 04.06.2008 * @version 1.0 + * + * @deprecated + * + * TODO delete this deprecated class */ public class DeleteSynonymCompositeAction extends Action { private static final Logger logger = Logger @@ -73,8 +77,8 @@ public class DeleteSynonymCompositeAction extends Action { } public void run() { - IOperationHistory operationHistory = UiUtil.getOperationHistory(); - IUndoContext undoContext = UiUtil.getWorkbenchUndoContext(); + IOperationHistory operationHistory = GlobalController.getOperationHistory(); + IUndoContext undoContext = GlobalController.getWorkbenchUndoContext(); operation.addContext(undoContext); try { operationHistory.execute(operation, null, null); diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/MoveTaxonDialogAction.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/MoveTaxonDialogAction.java index 2b58358a4..445535b7e 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/MoveTaxonDialogAction.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/MoveTaxonDialogAction.java @@ -10,6 +10,8 @@ package eu.etaxonomy.taxeditor.actions.ui; import org.apache.log4j.Logger; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.operations.IUndoableOperation; import org.eclipse.jface.action.Action; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.widgets.Shell; @@ -20,10 +22,12 @@ import org.eclipse.ui.PartInitException; import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.taxeditor.ITaxEditorConstants; import eu.etaxonomy.taxeditor.TaxEditorPlugin; -import eu.etaxonomy.taxeditor.UiUtil; import eu.etaxonomy.taxeditor.actions.cdm.MoveTaxonAction; +import eu.etaxonomy.taxeditor.controller.EditorController; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.editor.SelectTaxonDialog; import eu.etaxonomy.taxeditor.model.NameEditorInput; +import eu.etaxonomy.taxeditor.operations.MoveTaxonOperation; /** * @author p.ciardelli @@ -57,9 +61,8 @@ public class MoveTaxonDialogAction extends Action { try { // Prompt user "Would you like to save?" before showing dialog // "Cancel" cancels action - "No" does not - IEditorInput editorInput = new NameEditorInput(taxon); - editor = UiUtil.getEditorByInput(editorInput); - if (UiUtil.getActivePage().saveEditor(editor, true) == false) { + editor = EditorController.getEditorByTaxon(taxon); + if (GlobalController.getActivePage().saveEditor(editor, true) == false) { return; } } catch (PartInitException e1) { @@ -67,7 +70,7 @@ public class MoveTaxonDialogAction extends Action { } // Get destination taxon from dialog - Shell shell = UiUtil.getShell(); + Shell shell = GlobalController.getShell(); SelectTaxonDialog dialog = new SelectTaxonDialog(shell, SelectTaxonDialog.TAXON_TO_NEW_PARENT); Taxon destinationTaxon = dialog.open(taxon); @@ -77,8 +80,10 @@ public class MoveTaxonDialogAction extends Action { } // Move taxon in CDM -// Taxon oldParent = taxon.getTaxonomicParent(); - new MoveTaxonAction(taxon, destinationTaxon).run(); + IUndoableOperation operation = new MoveTaxonOperation(this.getText(), + GlobalController.getWorkbenchUndoContext(), taxon, destinationTaxon); + + GlobalController.executeOperation(operation); // For some reason, old parent is not getting the hint that one of its children is gone // new SaveTaxonAction(oldParent).run(); diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/OpenNameRelationWizardAction.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/OpenNameRelationWizardAction.java index e57506105..cd20d1376 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/OpenNameRelationWizardAction.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/OpenNameRelationWizardAction.java @@ -19,7 +19,7 @@ import org.eclipse.jface.wizard.WizardDialog; import eu.etaxonomy.cdm.model.name.NameRelationship; import eu.etaxonomy.cdm.model.name.TaxonNameBase; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.propertysheet.namerelationswizard.NameRelationWizard; import eu.etaxonomy.taxeditor.propertysheet.namerelationswizard.NameRelationWizardModel; @@ -73,7 +73,7 @@ public class OpenNameRelationWizardAction extends Action { Wizard wizard = new NameRelationWizard(relationModel); - WizardDialog dialog = new WizardDialog(UiUtil.getShell(), wizard); + WizardDialog dialog = new WizardDialog(GlobalController.getShell(), wizard); dialog.create(); dialog.open(); } diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/OpenNameRelationsListWizardAction.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/OpenNameRelationsListWizardAction.java index 7f04fb74f..cc9e114a1 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/OpenNameRelationsListWizardAction.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/OpenNameRelationsListWizardAction.java @@ -18,7 +18,7 @@ import org.eclipse.jface.wizard.WizardDialog; import eu.etaxonomy.cdm.model.name.TaxonNameBase; import eu.etaxonomy.taxeditor.ITaxEditorConstants; import eu.etaxonomy.taxeditor.TaxEditorPlugin; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.propertysheet.namerelationswizard.NameRelationsListWizard; /** @@ -57,7 +57,7 @@ public class OpenNameRelationsListWizardAction extends Action { Wizard wizard = new NameRelationsListWizard(name); // Instantiates the wizard container with the wizard and opens it - WizardDialog dialog = new WizardDialog(UiUtil.getShell(), wizard); + WizardDialog dialog = new WizardDialog(GlobalController.getShell(), wizard); dialog.create(); dialog.open(); } diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/OpenNewChildNameEditorAction.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/OpenNewChildNameEditorAction.java index 55523882d..96346fe92 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/OpenNewChildNameEditorAction.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/OpenNewChildNameEditorAction.java @@ -12,17 +12,13 @@ package eu.etaxonomy.taxeditor.actions.ui; import org.apache.log4j.Logger; import org.eclipse.jface.action.Action; import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.ui.PartInitException; -import eu.etaxonomy.cdm.model.name.BotanicalName; import eu.etaxonomy.cdm.model.name.NonViralName; -import eu.etaxonomy.cdm.model.name.Rank; -import eu.etaxonomy.cdm.model.name.ZoologicalName; import eu.etaxonomy.cdm.model.reference.ReferenceBase; import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.taxeditor.ITaxEditorConstants; import eu.etaxonomy.taxeditor.TaxEditorPlugin; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.EditorController; import eu.etaxonomy.taxeditor.preference.PreferencesUtil; /** @@ -65,11 +61,8 @@ public class OpenNewChildNameEditorAction extends Action { parentTaxon.addTaxonomicChild(taxon, null, null); // Open editor for new taxon - try { - UiUtil.openTaxonEditor(taxon); - } catch (PartInitException e) { - e.printStackTrace(); - } + EditorController.open(taxon); + //new OpenTaxonEditorAction(taxon).run(); } diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/OpenTaxonEditorAction.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/OpenTaxonEditorAction.java index d0d194339..972ae0d22 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/OpenTaxonEditorAction.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/OpenTaxonEditorAction.java @@ -14,21 +14,11 @@ import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; -import org.eclipse.ui.PartInitException; -import eu.etaxonomy.cdm.model.name.TaxonNameBase; import eu.etaxonomy.cdm.model.taxon.Taxon; -import eu.etaxonomy.taxeditor.UiUtil; -import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository; -import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor; -import eu.etaxonomy.taxeditor.editor.name.CdmParserController; -import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository; -import eu.etaxonomy.taxeditor.model.NameEditorInput; -import eu.etaxonomy.taxeditor.navigation.RecentNamesView; -import eu.etaxonomy.taxeditor.navigation.TaxonomicTreeViewer; +import eu.etaxonomy.taxeditor.controller.EditorController; /** * Opens a taxon editor for an existing or new taxon. @@ -70,11 +60,7 @@ public class OpenTaxonEditorAction extends Action implements IWorkbenchWindowAct @Override public void run() { - try { - UiUtil.openTaxonEditor(taxon); - } catch (PartInitException e) { - e.printStackTrace(); - } + EditorController.open(taxon); // For clients who re-use the same instance of this class, // taxon is re-initalized to ensure a new Taxon is opened every time diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/description/AddDescriptionElementCompositeAction.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/description/AddDescriptionElementCompositeAction.java index a14843378..a6d3fd1df 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/description/AddDescriptionElementCompositeAction.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/description/AddDescriptionElementCompositeAction.java @@ -31,7 +31,7 @@ import eu.etaxonomy.cdm.model.description.Feature; import eu.etaxonomy.cdm.model.description.TaxonDescription; import eu.etaxonomy.cdm.model.description.TextData; import eu.etaxonomy.cdm.model.description.TextFormat; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.editor.description.DescriptionElementComposite; import eu.etaxonomy.taxeditor.editor.description.FeatureGroupComposite; @@ -97,8 +97,8 @@ public class AddDescriptionElementCompositeAction extends Action { } public void run() { - IOperationHistory operationHistory = UiUtil.getOperationHistory(); - IUndoContext undoContext = UiUtil.getWorkbenchUndoContext(); + IOperationHistory operationHistory = GlobalController.getOperationHistory(); + IUndoContext undoContext = GlobalController.getWorkbenchUndoContext(); operation.addContext(undoContext); try { operationHistory.execute(operation, null, null); diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/description/DeleteElementCompositeAction.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/description/DeleteElementCompositeAction.java index 9aecf8e55..f6f0be097 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/description/DeleteElementCompositeAction.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/description/DeleteElementCompositeAction.java @@ -28,7 +28,7 @@ import eu.etaxonomy.cdm.model.description.DescriptionElementBase; import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.taxeditor.ITaxEditorConstants; import eu.etaxonomy.taxeditor.TaxEditorPlugin; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.GlobalController; /** * @author p.ciardelli @@ -83,8 +83,8 @@ public class DeleteElementCompositeAction extends Action { } public void run() { - IOperationHistory operationHistory = UiUtil.getOperationHistory(); - IUndoContext undoContext = UiUtil.getWorkbenchUndoContext(); + IOperationHistory operationHistory = GlobalController.getOperationHistory(); + IUndoContext undoContext = GlobalController.getWorkbenchUndoContext(); operation.addContext(undoContext); try { operationHistory.execute(operation, null, null); diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/controller/EditorController.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/controller/EditorController.java new file mode 100644 index 000000000..1d8009011 --- /dev/null +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/controller/EditorController.java @@ -0,0 +1,291 @@ +/** +* Copyright (C) 2007 EDIT +* European Distributed Institute of Taxonomy +* http://www.e-taxonomy.eu +* +* The contents of this file are subject to the Mozilla Public License Version 1.1 +* See LICENSE.TXT at the top of this package for the full license terms. +*/ + +package eu.etaxonomy.taxeditor.controller; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.apache.log4j.Logger; +import org.eclipse.core.commands.operations.IOperationHistory; +import org.eclipse.core.commands.operations.IUndoContext; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorReference; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; + +import eu.etaxonomy.cdm.model.name.TaxonNameBase; +import eu.etaxonomy.cdm.model.taxon.Taxon; +import eu.etaxonomy.taxeditor.datasource.CdmTransactionController; +import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor; +import eu.etaxonomy.taxeditor.editor.name.CdmParserController; +import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor; +import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository; +import eu.etaxonomy.taxeditor.model.NameEditorInput; +import eu.etaxonomy.taxeditor.navigation.RecentNamesView; +import eu.etaxonomy.taxeditor.navigation.TaxonomicTreeViewer; + +/** + * @author n.hoffmann + * @created 20.01.2009 + * @version 1.0 + */ +public class EditorController { + private static final Logger logger = Logger.getLogger(EditorController.class); + + + private static Map taxonNameEditors; + + + private static boolean isSaving = false; + + private static IWorkbenchPage getActivePage(){ + return GlobalController.getActivePage(); + } + + /** + * @param input + * @return + * @throws PartInitException + */ + private static IEditorPart getEditorByInput(IEditorInput input) + throws PartInitException { + for (IEditorReference reference : getActivePage().getEditorReferences()) { + if (reference.getEditorInput().equals(input)) { + IEditorPart editor = reference.getEditor(false); + return editor; + } + } + return null; + } + + public static boolean closeAll() { + for (IEditorPart editor : getOpenEditors()) { + if (!getActivePage().closeEditor(editor, true)) { + return false; + } + } + return true; + } + + public static IEditorPart getEditorByTaxon(Taxon taxon) + throws PartInitException { + IEditorInput input = new NameEditorInput(taxon); + return getEditorByInput(input); + } + + /** + * @param input + * @param editorId + * @return + * @throws PartInitException + */ + private static IEditorPart open(IEditorInput input, String editorId) + throws PartInitException { + return getActivePage().openEditor(input, editorId); + } + + /** + * Open an emtpy taxon editor + * + * @return + * @throws PartInitException + */ + public static IEditorPart open() + throws PartInitException{ + return open(null); + } + + /** + * Open a taxon editor for the given taxon + * + * @param taxon + * @return + * @throws PartInitException + */ + public static IEditorPart open(Taxon taxon){ + if(taxon == null){ + TaxonNameBase name = CdmParserController.parseFullReference("", null, null); + name.setFullTitleCache("", false); + name.setTitleCache("", false); + taxon = Taxon.NewInstance(name, + CdmSessionDataRepository.getDefault().getDefaultSec()); + }else{ + // If this taxon is not visible in the tree, open node + TaxonomicTreeViewer treeViewer = TreeController.getTreeViewer(); + if (treeViewer != null) { + treeViewer.revealTaxon(taxon); + } + + // Add to recent names list + RecentNamesView.addRecentName(taxon); + } + + IEditorInput input = new NameEditorInput(taxon); + + try { + return open(input, MultiPageTaxonEditor.ID); + } catch (PartInitException e) { + logger.error("Error opening editor.", e); + } + return null; + } + + /** + * Redraws an open editor if it exists for the given taxon + * + * @param taxon + * @return + */ + public static boolean redraw(Taxon taxon){ + + TaxonNameEditor editor = EditorController.getEditor(taxon); + + if(editor == null || editor.redraw()){ + + // Mark editor as changed and unsaved + editor.setDirty(); + + return true; + } + return false; + } + + /** + * @param taxon + * @param save + */ + public static void close(Taxon taxon, boolean save) { + IEditorPart editor; + try { + editor = getEditorByTaxon(taxon); + close(editor, save); + } catch (PartInitException e) { + logger.error("Error closing taxon editor", e); + } + + } + + /** + * @param editor + * @param save + * @throws PartInitException + */ + private static void close(IEditorPart editor, boolean save) + throws PartInitException { + if (editor != null) { + getActivePage().closeEditor(editor, save); + } + } + + public static void save(Taxon taxon, boolean confirm) { + IEditorPart editor = null; + try { + editor = getEditorByTaxon(taxon); + } catch (PartInitException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if (editor != null) { + GlobalController.getActivePage().saveEditor(editor, confirm); + } + } + + public static void saveAll(){ + setSaving(true); + + // Get all open windows + for (IEditorPart taxonEditor : getOpenEditors()) { + + // Save the dirty ones + if (taxonEditor.isDirty()) { + + + IEditorInput input = taxonEditor.getEditorInput(); + if (input.getAdapter(Taxon.class) != null) { + Taxon taxon = (Taxon) input.getAdapter(Taxon.class); + CdmSessionDataRepository.getDefault().saveTaxon(taxon); + if (taxonEditor instanceof MultiPageTaxonEditor) { + ((MultiPageTaxonEditor) taxonEditor).setDirtyExtern(false); + } + } + } + } + + // Commit the transaction + CdmTransactionController.commitTransaction(); + + // Force library objects to be associated with new transaction + CdmSessionDataRepository.getDefault().clearNonTaxonData(); + + // Start a new transaction + CdmTransactionController.startTransaction(); + + // Put all open taxa in the new transaction + CdmTransactionController.addSessionTaxaToTransaction(); + + setSaving(false); + // TODO: delete undoHistory + } + + public static void setSaving(boolean isSaving) { + EditorController.isSaving = isSaving; + } + + public static boolean isSaving() { + return isSaving; + } + + public static void addEditor( + Taxon taxon, TaxonNameEditor taxonNameEditor) { + if (taxonNameEditors == null) { + taxonNameEditors = new HashMap(); + } + taxonNameEditors.put(taxon, taxonNameEditor); + } + + public static TaxonNameEditor getEditor(Taxon taxon) { + if (taxonNameEditors == null) { + return null; + } + return taxonNameEditors.get(taxon); + } + + /** + * Returns a set of all currently open + * MultiPageTaxonEditors. + * + * @return + */ + public static Set getOpenEditors() { + + Set taxonEditors = new HashSet(); + + for (IEditorReference reference : getActivePage().getEditorReferences()) { + IEditorPart editor = reference.getEditor(false); + if (editor instanceof MultiPageTaxonEditor) { + taxonEditors.add(editor); + } + } + return taxonEditors; + } + + public static IUndoContext getUndoContext(Taxon taxon) { + // TODO make this taxon name editor specific + // return getTaxonNameEditor(taxon).getUndoContext(); + return IOperationHistory.GLOBAL_UNDO_CONTEXT; + } + + + + +} diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/controller/GlobalController.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/controller/GlobalController.java new file mode 100644 index 000000000..e6d9b6fbb --- /dev/null +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/controller/GlobalController.java @@ -0,0 +1,161 @@ +/** + * Copyright (C) 2007 EDIT + * European Distributed Institute of Taxonomy + * http://www.e-taxonomy.eu + * + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * See LICENSE.TXT at the top of this package for the full license terms. + */ + +package eu.etaxonomy.taxeditor.controller; + +import java.util.Set; +import java.util.SortedSet; + +import org.apache.log4j.Logger; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.operations.IOperationHistory; +import org.eclipse.core.commands.operations.IUndoContext; +import org.eclipse.core.commands.operations.IUndoableOperation; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.action.IStatusLineManager; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.operations.IWorkbenchOperationSupport; + +import eu.etaxonomy.cdm.model.description.Feature; +import eu.etaxonomy.cdm.model.name.NameRelationshipType; +import eu.etaxonomy.cdm.model.name.Rank; +import eu.etaxonomy.taxeditor.TaxEditorPlugin; +import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository; + +/** + * A collection of useful methods related to the UI. + * + * @author p.ciardelli + * @created 27.05.2008 + * @version 1.0 + */ +public class GlobalController { + private static final Logger logger = Logger.getLogger(GlobalController.class); + + private static Set preferredFeatureSet; + private static Set preferredRankSet; + + /** + * @return + */ + public static IWorkbenchPage getActivePage() { + return TaxEditorPlugin.getDefault().getWorkbench() + .getActiveWorkbenchWindow().getActivePage(); + } + + /** + * @return + */ + public static Shell getShell() { + return TaxEditorPlugin.getDefault().getWorkbench() + .getActiveWorkbenchWindow().getShell(); + } + + public static IViewPart getViewById(String id) { + return TaxEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow(). + getActivePage().findView(id); + } + + + public static IWorkbenchOperationSupport getOperationSupport() { + return TaxEditorPlugin.getDefault().getWorkbench(). + getOperationSupport(); + } + + public static IOperationHistory getOperationHistory() { +// if (operationHistory == null) { +//// operationHistory = getOperationSupport().getOperationHistory(); +// operationHistory = OperationHistoryFactory.getOperationHistory(); +// } +// return operationHistory; + return getOperationSupport().getOperationHistory(); + } + + public static IUndoContext getWorkbenchUndoContext() { + // TODO make this more specific than GLOBAL_UNDO_CONTEXT +// return getOperationSupport().getUndoContext(); + return IOperationHistory.GLOBAL_UNDO_CONTEXT; + } + + public static void setStatusMessage(String msg) { + PropertySheetController.getPropertySheet().getViewSite().getActionBars().getStatusLineManager().setMessage(msg); + } + + /** + * Get the name out of the session's name relations vocabulary, not directly + * from the object. + * + * @param type + * @return + */ + public static String getNameRelationLabelType(NameRelationshipType type) { + SortedSet vocab = + CdmSessionDataRepository.getDefault().getNameRelationshipTypes(); + for (NameRelationshipType type1 : vocab) { + if (type1.equals(type)) { + return type1.getLabel(); + } + } + return ""; + } + + private static IStatusLineManager statusLineManager; + + public static void setStatusLineManager(IStatusLineManager manager) { + statusLineManager = manager; + } + + public static void setStatusLine(String message) { + statusLineManager.setMessage(message); + } + + public static IProgressMonitor getStatusLineProgressMonitor() { + statusLineManager.setCancelEnabled(false); + return statusLineManager.getProgressMonitor(); + } + + public static Set getPreferredFeatures() { + return preferredFeatureSet; + } + + public static void setPreferredFeatures(Set preferredFeatureSet) { + GlobalController.preferredFeatureSet = preferredFeatureSet; + } + + public static Set getPreferredRanks() { + return preferredRankSet; + } + + public static void setPreferredRanks(Set preferredRankSet) { + GlobalController.preferredRankSet = preferredRankSet; + } + + public static void addPreferredRank(Rank rank) { + preferredRankSet.add(rank); + } + + public static void addPreferredFeature(Feature feature) { + GlobalController.preferredFeatureSet.add(feature); + } + + public static void executeOperation(IUndoableOperation operation){ + try { + IStatus status = getOperationHistory().execute(operation, getStatusLineProgressMonitor(), null); + String statusString = status.equals(Status.OK_STATUS) ? "completed" : "cancelled"; + setStatusLine(operation.getLabel() + " " + statusString + "."); + } catch (ExecutionException e) { + logger.error("Error executing operation: " + operation.getLabel(), e); + } + } + +} \ No newline at end of file diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/controller/PropertySheetController.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/controller/PropertySheetController.java new file mode 100644 index 000000000..9b54ed374 --- /dev/null +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/controller/PropertySheetController.java @@ -0,0 +1,180 @@ +/** +* Copyright (C) 2007 EDIT +* European Distributed Institute of Taxonomy +* http://www.e-taxonomy.eu +* +* The contents of this file are subject to the Mozilla Public License Version 1.1 +* See LICENSE.TXT at the top of this package for the full license terms. +*/ + +package eu.etaxonomy.taxeditor.controller; + +import org.apache.log4j.Logger; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IPageLayout; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IViewReference; +import org.eclipse.ui.views.properties.PropertySheet; +import org.eclipse.ui.views.properties.PropertySheetPage; + +import eu.etaxonomy.taxeditor.TaxEditorPlugin; +import eu.etaxonomy.taxeditor.propertysheet.CustomSortPropertySheetEntry; + +/** + * @author n.hoffmann + * @created 20.01.2009 + * @version 1.0 + */ +public class PropertySheetController { + private static final Logger logger = Logger + .getLogger(PropertySheetController.class); + + public static IViewPart getPropertySheet() { + for (IViewReference reference : GlobalController.getActivePage().getViewReferences()) { + if (reference.getId().equals(IPageLayout.ID_PROP_SHEET)) { + logger.warn(reference.getView(false).getSite().getPart().getTitle()); + return reference.getView(false); + } + } + return null; + } + + /** + * By default, property sheet has buttons in the toolbar for + * "Show advanced properties" and "Show categories". + *

+ * This is confusing for the user, hence a method to remove them + * until such time as advanced properties or categories are implemented. + */ + public static void hidePropertySheetToolbar() { + PropertySheet propertySheet = (PropertySheet) getPropertySheet(); + IActionBars actionBars = propertySheet.getViewSite().getActionBars(); + actionBars.getToolBarManager().removeAll(); + actionBars.getMenuManager().removeAll(); + } + + /** + * The property sheet listener ensures only property sheets + * with data cause the Property Sheet to be updated. + */ + public static void addPropertySheetInputListener() { + IViewPart propertySheet = getPropertySheet(); + // propertySheet.get + PropertySheet ps = (PropertySheet) propertySheet; + // ps.addPartPropertyListener(listener) + // ps.addPropertyListener(l) + } + + public static void setPropertySheetTree(Tree tree) { + TaxEditorPlugin.getDefault().setPropertySheetTree(tree); + } + + public static Tree getPropertySheetTree() { + return TaxEditorPlugin.getDefault().getPropertySheetTree(); + } + + public static void setPropertySheetPage(PropertySheetPage page) { + TaxEditorPlugin.getDefault().setPropertySheetPage(page); + } + + public static PropertySheetPage getPropertySheetPage() { + return TaxEditorPlugin.getDefault().getPropertySheetPage(); + } + + /** + * UiUtil.paintPropertySheetRow(P_DATEPUBLISHED, new Color(Display.getDefault(), WarningAnnotation.WARNING_RGB), true); + * UiUtil.unpaintPropertySheetRow(P_DATEPUBLISHED); + * + * @param id + * @param color + * @param doPaintChildren + */ + public static void paintPropertySheetRow(String id, Color color, boolean doPaintChildren) { + + // Catch null property sheet name + if (id == null) { + return; + } + + // Catch uninit'ed property sheet tree + if (getPropertySheetTree() == null) { + return; + } + + paintPropertySheetRow(id, color, doPaintChildren, getPropertySheetTree()); + } + + private static void paintPropertySheetRow(String id, Color color, boolean doPaintChildren, Object treeOrItem) { + + // Init items w zero-length array + TreeItem[] items = new TreeItem[]{}; + + // Get child items depending to class + if (treeOrItem instanceof Tree) { + items = ((Tree) treeOrItem).getItems(); + } + if (treeOrItem instanceof TreeItem) { + items = ((TreeItem) treeOrItem).getItems(); + } + + // If array hasn't been populated by the above, return + if (items.length == 0) { + return; + } + + // Prop. sheet id's take the form "01:xxxx" for sorting - truncate + id = CustomSortPropertySheetEntry.truncateDisplayName(id); + + // Iterate through child items + for (TreeItem item : items) { + + // Item found, paint it + if (id.equals(item.getText())) { + paintItem(item, color, doPaintChildren); + return; + } + + // Recursively search for item to paint in child items + if (item.getItemCount() > 0) { + paintPropertySheetRow(id, color, doPaintChildren, item); + } + } + } + + public static void unpaintPropertySheetRow(String id) { + + // Catch uninit'ed property sheet tree + if (getPropertySheetTree() == null) { + return; + } + + // Get tree's background color to "unpaint" + Color color = getPropertySheetTree().getBackground(); + + paintPropertySheetRow(id, color, true); + } + + /** + * Note: children are only painted if submenu has already been created, i.e. opened once. + * + * @param item + * @param color + * @param doPaintChildren + */ + public static void paintItem(TreeItem item, Color color, boolean doPaintChildren) { + + // Paint the item + item.setBackground(color); + + // Recursively paint child items if requested + if (doPaintChildren) { + for (TreeItem childItem : item.getItems()) { + paintItem(childItem, color, doPaintChildren); + } + } + } + +} diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/controller/SearchController.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/controller/SearchController.java new file mode 100644 index 000000000..0a61131b4 --- /dev/null +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/controller/SearchController.java @@ -0,0 +1,42 @@ +/** +* Copyright (C) 2007 EDIT +* European Distributed Institute of Taxonomy +* http://www.e-taxonomy.eu +* +* The contents of this file are subject to the Mozilla Public License Version 1.1 +* See LICENSE.TXT at the top of this package for the full license terms. +*/ + +package eu.etaxonomy.taxeditor.controller; + +import org.apache.log4j.Logger; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; + +import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.navigation.SearchResult; +import eu.etaxonomy.taxeditor.navigation.SearchResultView; + +/** + * @author n.hoffmann + * @created 20.01.2009 + * @version 1.0 + */ +public class SearchController { + private static final Logger logger = Logger + .getLogger(SearchController.class); + private static String srv = ""; + + public static void openSearchResultsView(SearchResult searchResult) { + srv += "1"; + logger.warn("opening search results window " + srv); + try { + IViewPart resultsView = UiUtil.getActivePage().showView(SearchResultView.ID, + srv, IWorkbenchPage.VIEW_VISIBLE); + ((SearchResultView) resultsView).setResult(searchResult); + } catch (PartInitException e) { + logger.error("Error opening search result.", e); + } + } +} diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/controller/TreeController.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/controller/TreeController.java new file mode 100644 index 000000000..a8d420824 --- /dev/null +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/controller/TreeController.java @@ -0,0 +1,71 @@ +/** +* Copyright (C) 2007 EDIT +* European Distributed Institute of Taxonomy +* http://www.e-taxonomy.eu +* +* The contents of this file are subject to the Mozilla Public License Version 1.1 +* See LICENSE.TXT at the top of this package for the full license terms. +*/ + +package eu.etaxonomy.taxeditor.controller; + +import org.apache.log4j.Logger; +import org.eclipse.ui.IViewPart; + +import eu.etaxonomy.taxeditor.navigation.TaxonomicTreeView; +import eu.etaxonomy.taxeditor.navigation.TaxonomicTreeViewer; + +/** + * @author n.hoffmann + * @created 20.01.2009 + * @version 1.0 + */ +public class TreeController { + private static final Logger logger = Logger.getLogger(TreeController.class); + private static IViewPart treeView; + + /** + * Returns the TaxonomicTreeViewer used for navigation. Not to + * be confused with the window that contains it, TaxonomicTreeView. + * + * @return + */ + public static TaxonomicTreeViewer getTreeViewer() { + TaxonomicTreeView view = getTreeView(); + if (view == null) { + return null; + } + return view.getTreeViewer(); + } + + /** + * @see eu.etaxonomy.taxeditor.navigation.TaxonomicTreeView#createTreeViewer() + * + * @return + */ + public static TaxonomicTreeViewer createTreeViewer() { + TaxonomicTreeView view = getTreeView(); + if (view == null) { + return null; + } + return view.createTreeViewer(); + } + + /** + * Returns the TaxonomicTreeView containing the + * TaxonomicTreeViewer used for navigation. + * + * @return + */ + public static TaxonomicTreeView getTreeView() { + if (treeView == null) { + treeView = GlobalController.getViewById(TaxonomicTreeView.ID); + if (!(treeView instanceof TaxonomicTreeView)) { + treeView = null; + } + } + return (TaxonomicTreeView) treeView; + } + + +} diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/CdmDataSourceDialog.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/CdmDataSourceDialog.java index 675a73807..ecfe98a68 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/CdmDataSourceDialog.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/CdmDataSourceDialog.java @@ -47,7 +47,7 @@ import eu.etaxonomy.cdm.database.CdmDataSource; import eu.etaxonomy.cdm.database.CdmPersistentDataSource; import eu.etaxonomy.cdm.database.DatabaseTypeEnum; import eu.etaxonomy.cdm.database.ICdmDataSource; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.GlobalController; /** * List of database types comes from {@link eu.etaxonomy.cdm.database.DatabaseTypeEnum}. * @@ -234,7 +234,7 @@ public class CdmDataSourceDialog extends Dialog { createMySqlForm(dataSource); } else { // TODO Intrusive - change to text - MessageDialog.openInformation(UiUtil.getShell(), "Database not yet implemented", + MessageDialog.openInformation(GlobalController.getShell(), "Database not yet implemented", "Creation of datasources using a(n) '" + type.getName() + "' database not yet implemented."); } } @@ -438,9 +438,9 @@ public class CdmDataSourceDialog extends Dialog { usernameText.getText(), passwordText.getText()); if (dataSource.testConnection()) { - MessageDialog.openConfirm(UiUtil.getShell(), "Test successful", "Test successful"); + MessageDialog.openConfirm(GlobalController.getShell(), "Test successful", "Test successful"); } else { - MessageDialog.openWarning(UiUtil.getShell(), "Test unsuccessful", "Test unsuccessful"); + MessageDialog.openWarning(GlobalController.getShell(), "Test unsuccessful", "Test unsuccessful"); } } diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/CdmDataSourceRepository.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/CdmDataSourceRepository.java index db5c0cd32..ebd31ac2b 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/CdmDataSourceRepository.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/CdmDataSourceRepository.java @@ -25,7 +25,9 @@ import eu.etaxonomy.cdm.database.DatabaseTypeEnum; import eu.etaxonomy.cdm.database.ICdmDataSource; import eu.etaxonomy.cdm.model.common.init.TermNotFoundException; import eu.etaxonomy.taxeditor.TaxEditorPlugin; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.EditorController; +import eu.etaxonomy.taxeditor.controller.TreeController; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository; import eu.etaxonomy.taxeditor.model.CdmUtil; @@ -134,7 +136,7 @@ public class CdmDataSourceRepository implements ICdmDataSourceRepository { private boolean changeDataSource(final ICdmDataSource dataSource) { // Close all open editors before showing progress monitor - if (!UiUtil.closeOpenTaxonEditors()) { + if (!EditorController.closeAll()) { // User has canceled operation return false; @@ -175,7 +177,7 @@ public class CdmDataSourceRepository implements ICdmDataSourceRepository { // Get session root taxa // TODO get listener in tree content provider to take care of this - UiUtil.getTreeViewer().setInput( + TreeController.getTreeViewer().setInput( CdmSessionDataRepository.getDefault().getRootTaxa()); monitor.worked(11); @@ -184,7 +186,7 @@ public class CdmDataSourceRepository implements ICdmDataSourceRepository { } }; - new ProgressMonitorDialog(UiUtil.getShell()).run(false, true, op); + new ProgressMonitorDialog(GlobalController.getShell()).run(false, true, op); } catch (InvocationTargetException e) { e.printStackTrace(); return false; diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/AbstractTaxonEditor.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/AbstractTaxonEditor.java index 384f68533..4327d4406 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/AbstractTaxonEditor.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/AbstractTaxonEditor.java @@ -44,7 +44,8 @@ import org.eclipse.ui.views.properties.IPropertySource; import org.eclipse.ui.views.properties.PropertySheetPage; import eu.etaxonomy.cdm.model.taxon.Taxon; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.PropertySheetController; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.propertysheet.CustomSortPropertySheetEntry; /** @@ -237,7 +238,7 @@ public abstract class AbstractTaxonEditor extends EditorPart implements // Save the property sheet tree for easy access as needed if (!control.isDisposed()) { if (control instanceof Tree) { - UiUtil.setPropertySheetTree((Tree) control); + PropertySheetController.setPropertySheetTree((Tree) control); } } return control; @@ -245,7 +246,7 @@ public abstract class AbstractTaxonEditor extends EditorPart implements }; // Try out PartListener to intercept selections - IWorkbenchPage activePage = UiUtil.getActivePage(); + IWorkbenchPage activePage = GlobalController.getActivePage(); // IWorkbenchPart active = activePage.getActivePart(); IPartListener2 partListener = new IPartListener2() { @@ -299,7 +300,7 @@ public abstract class AbstractTaxonEditor extends EditorPart implements }; activePage.addPartListener(partListener); - UiUtil.setPropertySheetPage(page); + PropertySheetController.setPropertySheetPage(page); CustomSortPropertySheetEntry entry = new CustomSortPropertySheetEntry(); page.setRootEntry(entry); diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/FreeTextElementFactory.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/FreeTextElementFactory.java index c0c8cdabe..c888b9a6a 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/FreeTextElementFactory.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/FreeTextElementFactory.java @@ -20,7 +20,7 @@ import org.eclipse.ui.forms.IManagedForm; import eu.etaxonomy.cdm.model.name.HomotypicalGroup; import eu.etaxonomy.cdm.model.taxon.Synonym; import eu.etaxonomy.cdm.model.taxon.Taxon; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.EditorController; import eu.etaxonomy.taxeditor.editor.name.AcceptedNameComposite; import eu.etaxonomy.taxeditor.editor.name.HomotypicalGroupComposite; import eu.etaxonomy.taxeditor.editor.name.MisappliedGroupComposite; @@ -85,7 +85,7 @@ public class FreeTextElementFactory implements IFreeTextElementFactory { // If the group doesn't yet have a composite, create one and add it to the repository Composite groupComposite = - UiUtil.getTaxonNameEditor(taxon).getHomotypicGroup(group); + EditorController.getEditor(taxon).getHomotypicGroup(group); if (groupComposite == null) { groupComposite = createHomotypicalGroup(taxon, group); } @@ -107,7 +107,7 @@ public class FreeTextElementFactory implements IFreeTextElementFactory { // If there is no composite for misapplied names, // create one and add it to the repository Composite groupComposite = - UiUtil.getTaxonNameEditor(taxon).getMisappliedGroup(); + EditorController.getEditor(taxon).getMisappliedGroup(); if (groupComposite == null) { groupComposite = createMisappliedGroup(taxon); } diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/name/MisappliedNameComposite.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/name/MisappliedNameComposite.java index 2caf83275..71c81a7f8 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/name/MisappliedNameComposite.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/name/MisappliedNameComposite.java @@ -10,11 +10,8 @@ package eu.etaxonomy.taxeditor.editor.name; import org.apache.log4j.Logger; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.commands.operations.IOperationHistory; import org.eclipse.core.commands.operations.IUndoContext; import org.eclipse.core.commands.operations.IUndoableOperation; -import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.action.Action; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.graphics.Font; @@ -26,7 +23,8 @@ import eu.etaxonomy.cdm.model.name.HomotypicalGroup; import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.taxeditor.ITaxEditorConstants; import eu.etaxonomy.taxeditor.TaxEditorPlugin; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.EditorController; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.editor.ContextMenu; import eu.etaxonomy.taxeditor.operations.name.ChangeMisappliedNameToSynonymOperation; import eu.etaxonomy.taxeditor.operations.name.RemoveMisappliedNameOperation; @@ -68,8 +66,7 @@ public class MisappliedNameComposite extends NameComposite { ContextMenu contextMenu = createContextMenu(); - final IOperationHistory operationHistory = UiUtil.getOperationHistory(); - final IUndoContext undoContext = UiUtil.getTaxonNameEditorUndoContext(taxon); + final IUndoContext undoContext = EditorController.getUndoContext(taxon); // Remove misapplied name from taxon String text = "Remove misapplied name from taxon"; //$NON-NLS-1$ @@ -80,12 +77,8 @@ public class MisappliedNameComposite extends NameComposite { public void run() { IUndoableOperation operation = new RemoveMisappliedNameOperation (this.getText(), undoContext, taxon, misappliedName); - try { - IStatus status = operationHistory.execute(operation, null, null); - } catch (ExecutionException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + + GlobalController.executeOperation(operation); } }); } @@ -105,17 +98,11 @@ public class MisappliedNameComposite extends NameComposite { HomotypicalGroup homotypicalGroup = ((HomotypicalGroupComposite)parent).getGroup(); - IOperationHistory operationHistory = UiUtil.getOperationHistory(); - IUndoContext undoContext = UiUtil.getTaxonNameEditorUndoContext(taxon); + IUndoContext undoContext = EditorController.getUndoContext(taxon); IUndoableOperation operation = new ChangeMisappliedNameToSynonymOperation ("change misapplication to synonym", undoContext, taxon, misappliedName, homotypicalGroup); - try { - IStatus status = operationHistory.execute(operation, null, null); - } catch (ExecutionException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + GlobalController.executeOperation(operation); } return true; diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/name/NameComposite.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/name/NameComposite.java index b7a3def26..2d6ede29d 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/name/NameComposite.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/name/NameComposite.java @@ -38,7 +38,8 @@ import eu.etaxonomy.cdm.model.reference.StrictReferenceBase; import eu.etaxonomy.cdm.model.taxon.TaxonBase; import eu.etaxonomy.taxeditor.ITaxEditorConstants; import eu.etaxonomy.taxeditor.TaxEditorPlugin; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.EditorController; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.editor.EditorGroupedComposite; import eu.etaxonomy.taxeditor.editor.LineBreakListener; import eu.etaxonomy.taxeditor.editor.ParseListener; @@ -184,7 +185,7 @@ public abstract class NameComposite extends EditorGroupedComposite { return; } - if (UiUtil.getIsSaving()) { + if (EditorController.isSaving()) { return; } @@ -284,17 +285,11 @@ public abstract class NameComposite extends EditorGroupedComposite { public void handleSplitText(String text) { // Create a synonym in a new homotypic group using text as name - IOperationHistory operationHistory = UiUtil.getOperationHistory(); - IUndoContext undoContext = UiUtil.getTaxonNameEditorUndoContext(taxon); + IUndoContext undoContext = EditorController.getUndoContext(taxon); IUndoableOperation operation = new CreateSynonymInNewGroupOperation ("new heterotypic synonym", undoContext, taxon, text); //$NON-NLS-1$ - try { - IStatus status = operationHistory.execute(operation, null, null); - } catch (ExecutionException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + GlobalController.executeOperation(operation); // getTextViewer().removeLineBreakListener(this); } diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/name/SynonymComposite.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/name/SynonymComposite.java index fc7dbb1a4..e7ee5a673 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/name/SynonymComposite.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/name/SynonymComposite.java @@ -10,11 +10,8 @@ package eu.etaxonomy.taxeditor.editor.name; import org.apache.log4j.Logger; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.commands.operations.IOperationHistory; import org.eclipse.core.commands.operations.IUndoContext; import org.eclipse.core.commands.operations.IUndoableOperation; -import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.action.Action; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.graphics.Font; @@ -27,7 +24,8 @@ import eu.etaxonomy.cdm.model.taxon.Synonym; import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.taxeditor.ITaxEditorConstants; import eu.etaxonomy.taxeditor.TaxEditorPlugin; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.EditorController; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.editor.ContextMenu; import eu.etaxonomy.taxeditor.model.CdmUtil; import eu.etaxonomy.taxeditor.operations.name.ChangeHomotypicGroupOperation; @@ -44,11 +42,14 @@ import eu.etaxonomy.taxeditor.operations.name.UnmakeSynonymGroupBasionymOperatio * @version 1.0 */ public class SynonymComposite extends NameComposite { + @SuppressWarnings("unused") private static final Logger logger = Logger .getLogger(SynonymComposite.class); private Synonym synonym; + private IUndoContext undoContext; + public SynonymComposite(Composite parent, IManagedForm form, Taxon taxon, Synonym synonym) { super(parent, form, null, synonym); @@ -56,6 +57,8 @@ public class SynonymComposite extends NameComposite { this.taxon = taxon; this.synonym = synonym; + this.undoContext = EditorController.getUndoContext(taxon); + setDraggable(true); setFont(getViewerFont()); setIndent(SYNONYM_INDENT); @@ -95,17 +98,10 @@ public class SynonymComposite extends NameComposite { // Has this been moved to the misapplied names group? if (parent instanceof MisappliedGroupComposite) { - IOperationHistory operationHistory = UiUtil.getOperationHistory(); - IUndoContext undoContext = UiUtil.getTaxonNameEditorUndoContext(taxon); IUndoableOperation operation = new ChangeSynonymToMisappliedNameOperation ("change to misapplication", undoContext, taxon, synonym); //$NON-NLS-1$ - try { - IStatus status = operationHistory.execute(operation, null, null); - } catch (ExecutionException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + GlobalController.executeOperation(operation); } // Has this been moved to a HomotypicalGroup? @@ -119,17 +115,10 @@ public class SynonymComposite extends NameComposite { return true; } - IOperationHistory operationHistory = UiUtil.getOperationHistory(); - IUndoContext undoContext = UiUtil.getTaxonNameEditorUndoContext(taxon); IUndoableOperation operation = new ChangeHomotypicGroupOperation ("change type", undoContext, taxon, synonym, homotypicalGroup); //$NON-NLS-1$ - try { - IStatus status = operationHistory.execute(operation, null, null); - } catch (ExecutionException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + GlobalController.executeOperation(operation); } return true; @@ -144,9 +133,6 @@ public class SynonymComposite extends NameComposite { ContextMenu contextMenu = createContextMenu(); - final IOperationHistory operationHistory = UiUtil.getOperationHistory(); - final IUndoContext undoContext = UiUtil.getTaxonNameEditorUndoContext(taxon); - // Change composite to a misapplied name String text = "Change synonym to misapplied name"; //$NON-NLS-1$ ImageDescriptor image = TaxEditorPlugin.getDefault() @@ -156,12 +142,8 @@ public class SynonymComposite extends NameComposite { public void run() { IUndoableOperation operation = new ChangeSynonymToMisappliedNameOperation (this.getText(), undoContext, taxon, synonym); - try { - IStatus status = operationHistory.execute(operation, null, null); - } catch (ExecutionException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + + GlobalController.executeOperation(operation); } }); @@ -174,12 +156,8 @@ public class SynonymComposite extends NameComposite { public void run() { IUndoableOperation operation = new RemoveSynonymOperation (this.getText(), undoContext, taxon, synonym); - try { - IStatus status = operationHistory.execute(operation, null, null); - } catch (ExecutionException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + + GlobalController.executeOperation(operation); } }); @@ -196,12 +174,8 @@ public class SynonymComposite extends NameComposite { public void run() { IUndoableOperation operation = new MakeSynonymGroupBasionymOperation (this.getText(), undoContext, taxon, synonym); - try { - IStatus status = operationHistory.execute(operation, null, null); - } catch (ExecutionException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + + GlobalController.executeOperation(operation); } }; contextMenu.addAction(makeBasionymAction); @@ -216,12 +190,8 @@ public class SynonymComposite extends NameComposite { public void run() { IUndoableOperation operation = new UnmakeSynonymGroupBasionymOperation (this.getText(), undoContext, taxon, synonym); - try { - IStatus status = operationHistory.execute(operation, null, null); - } catch (ExecutionException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + + GlobalController.executeOperation(operation); } }; contextMenu.addAction(unmakeBasionymAction); @@ -248,12 +218,8 @@ public class SynonymComposite extends NameComposite { public void run() { IUndoableOperation operation = new MakeSynonymAcceptedOperation (this.getText(), undoContext, taxon, synonym); - try { - IStatus status = operationHistory.execute(operation, null, null); - } catch (ExecutionException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + + GlobalController.executeOperation(operation); } }; contextMenu.addAction(swapAction); @@ -270,12 +236,8 @@ public class SynonymComposite extends NameComposite { public void run() { IUndoableOperation operation = new ChangeSynonymToTaxonOperation (this.getText(), undoContext, taxon, synonym); - try { - IStatus status = operationHistory.execute(operation, null, null); - } catch (ExecutionException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + + GlobalController.executeOperation(operation); } }); } diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/name/TaxonNameEditor.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/name/TaxonNameEditor.java index dcb23361c..84d0b2037 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/name/TaxonNameEditor.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/name/TaxonNameEditor.java @@ -14,12 +14,9 @@ import java.beans.PropertyChangeListener; import java.util.HashSet; import org.apache.log4j.Logger; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.commands.operations.IOperationHistory; import org.eclipse.core.commands.operations.IUndoContext; import org.eclipse.core.commands.operations.IUndoableOperation; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.dialogs.IMessageProvider; import org.eclipse.swt.dnd.DND; import org.eclipse.swt.dnd.DropTarget; @@ -39,8 +36,9 @@ import eu.etaxonomy.cdm.model.taxon.Synonym; import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.cdm.model.taxon.TaxonBase; import eu.etaxonomy.taxeditor.ITaxEditorConstants; -import eu.etaxonomy.taxeditor.UiUtil; import eu.etaxonomy.taxeditor.actions.WidgetTransfer; +import eu.etaxonomy.taxeditor.controller.EditorController; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.editor.AbstractTaxonEditor; import eu.etaxonomy.taxeditor.editor.EditorGroupedComposite; import eu.etaxonomy.taxeditor.editor.FreeTextElementFactory; @@ -83,7 +81,7 @@ public class TaxonNameEditor extends AbstractTaxonEditor Taxon taxon = getTaxon(); - UiUtil.addTaxonNameEditor(taxon, this); + EditorController.addEditor(taxon, this); // Register listeners for any change in accepted name or set of relations taxon.getName().addPropertyChangeListener(taxonChangeListener); @@ -179,8 +177,7 @@ public class TaxonNameEditor extends AbstractTaxonEditor public void drop(DropTargetEvent event) { - IOperationHistory operationHistory = UiUtil.getOperationHistory(); - IUndoContext undoContext = UiUtil.getTaxonNameEditorUndoContext(getTaxon()); + IUndoContext undoContext = EditorController.getUndoContext(getTaxon()); IUndoableOperation operation = null; // Synonym being dropped @@ -203,13 +200,7 @@ public class TaxonNameEditor extends AbstractTaxonEditor if (operation == null) { logger.warn("User unsuccessfully tried to drop " + event.data.getClass()); } else { - try { -// WidgetTransfer.getInstance().setWidget(null); - IStatus status = operationHistory.execute(operation, null, null); - } catch (ExecutionException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + GlobalController.executeOperation(operation); } } }); diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/CdmSessionDataRepository.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/CdmSessionDataRepository.java index e3e925f32..a017df122 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/CdmSessionDataRepository.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/CdmSessionDataRepository.java @@ -73,7 +73,7 @@ public class CdmSessionDataRepository implements ICdmSessionDataRepository { private SortedSet ranks; - private TermVocabulary nomStatii; + private TermVocabulary nomStatus; private SortedSet nameRelationshipTypes; @@ -109,7 +109,7 @@ public class CdmSessionDataRepository implements ICdmSessionDataRepository { public void clearNonTaxonData() { features = null; ranks = null; - nomStatii = null; + nomStatus = null; // Parser is also transaction-, and therefore session-, dependent CdmParserController.clearNonViralNameParser(); @@ -368,12 +368,12 @@ public class CdmSessionDataRepository implements ICdmSessionDataRepository { } @Override - public TermVocabulary getNomStatii() { - if (nomStatii == null) { - nomStatii = getApplicationController().getNameService() + public TermVocabulary getNomStatus() { + if (nomStatus == null) { + nomStatus = getApplicationController().getNameService() .getStatusTypeVocabulary(); } - return nomStatii; + return nomStatus; } @Override diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/CdmUtil.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/CdmUtil.java index ff93ff080..32d2a98e8 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/CdmUtil.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/CdmUtil.java @@ -34,7 +34,7 @@ import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType; import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.cdm.model.taxon.TaxonBase; import eu.etaxonomy.taxeditor.TaxEditorPlugin; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.navigation.SearchResult; /** @@ -363,7 +363,7 @@ public class CdmUtil { try { resultsList = getReferenceService().getReferencesByTitle(reference); } catch (RuntimeException e) { - MessageDialog.openError(UiUtil.getShell(), "Search reference error", + MessageDialog.openError(GlobalController.getShell(), "Search reference error", "Reference search returned an error. This could be a Hibernate concurrency problem. " + "Please try saving your work, then searching again."); e.printStackTrace(); diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/ICdmSessionDataRepository.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/ICdmSessionDataRepository.java index f96c2a916..d34517494 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/ICdmSessionDataRepository.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/ICdmSessionDataRepository.java @@ -130,7 +130,7 @@ public interface ICdmSessionDataRepository { public SortedSet getRanks(); - public TermVocabulary getNomStatii(); + public TermVocabulary getNomStatus(); public SortedSet getNameRelationshipTypes(); } diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/SearchView.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/SearchView.java index d06e99121..d046d8e5f 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/SearchView.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/SearchView.java @@ -9,9 +9,6 @@ package eu.etaxonomy.taxeditor.navigation; -import java.util.List; -import java.util.Set; - import org.apache.log4j.Logger; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; @@ -34,8 +31,7 @@ import org.eclipse.ui.part.ViewPart; import com.swtdesigner.SWTResourceManager; -import eu.etaxonomy.cdm.model.name.TaxonNameBase; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.SearchController; import eu.etaxonomy.taxeditor.model.CdmUtil; /** @@ -148,7 +144,7 @@ public class SearchView extends ViewPart { // If there are results, open a view in the center pane if (searchResult.size() > 0) { - UiUtil.openSearchResultsView(searchResult); + SearchController.openSearchResultsView(searchResult); } else { // Display "no results found" message diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/TaxonomicTreeView.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/TaxonomicTreeView.java index c3cfc39bf..e7aeeeedd 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/TaxonomicTreeView.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/TaxonomicTreeView.java @@ -41,8 +41,8 @@ import eu.etaxonomy.cdm.database.DatabaseTypeEnum; import eu.etaxonomy.cdm.database.ICdmDataSource; import eu.etaxonomy.taxeditor.ITaxEditorConstants; import eu.etaxonomy.taxeditor.TaxEditorPlugin; -import eu.etaxonomy.taxeditor.UiUtil; import eu.etaxonomy.taxeditor.actions.ui.OpenTaxonEditorAction; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.datasource.CdmDataSourceDialog; import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository; import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository; @@ -167,7 +167,7 @@ public class TaxonomicTreeView extends ViewPart { newDataSourceMenuItem.setText("Edit data sources ..."); newDataSourceMenuItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { - Dialog dialog = new CdmDataSourceDialog(UiUtil.getShell()); + Dialog dialog = new CdmDataSourceDialog(GlobalController.getShell()); dialog.open(); // Refresh menu to reflect any changes in data diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/TaxonomicTreeViewer.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/TaxonomicTreeViewer.java index b3092d5d2..590c95466 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/TaxonomicTreeViewer.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/TaxonomicTreeViewer.java @@ -12,12 +12,9 @@ package eu.etaxonomy.taxeditor.navigation; import java.util.Set; import org.apache.log4j.Logger; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.commands.operations.IOperationHistory; import org.eclipse.core.commands.operations.IUndoContext; import org.eclipse.core.commands.operations.IUndoableOperation; import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; @@ -61,22 +58,19 @@ import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeItem; -import org.eclipse.ui.PartInitException; import eu.etaxonomy.cdm.model.name.NonViralName; import eu.etaxonomy.cdm.model.name.TaxonNameBase; import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.cdm.model.taxon.TaxonBase; import eu.etaxonomy.taxeditor.ITaxEditorConstants; -import eu.etaxonomy.taxeditor.TaxEditorPlugin; -import eu.etaxonomy.taxeditor.UiUtil; import eu.etaxonomy.taxeditor.actions.TaxonTransfer; import eu.etaxonomy.taxeditor.actions.cdm.DeleteTaxonAction; -import eu.etaxonomy.taxeditor.actions.cdm.MoveTaxonAction; -import eu.etaxonomy.taxeditor.actions.cdm.SaveTaxonAction; import eu.etaxonomy.taxeditor.actions.ui.AddQuickNameAction; import eu.etaxonomy.taxeditor.actions.ui.OpenNewChildNameEditorAction; import eu.etaxonomy.taxeditor.actions.ui.OpenTaxonEditorAction; +import eu.etaxonomy.taxeditor.controller.EditorController; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.editor.ContextMenu; import eu.etaxonomy.taxeditor.editor.name.CdmParserController; import eu.etaxonomy.taxeditor.editor.name.IterableSynonymyList; @@ -85,7 +79,6 @@ import eu.etaxonomy.taxeditor.model.CdmUtil; import eu.etaxonomy.taxeditor.model.ICdmTaxonSetListener; import eu.etaxonomy.taxeditor.model.TaxonomicTreeContentProvider; import eu.etaxonomy.taxeditor.operations.MoveTaxonOperation; -import eu.etaxonomy.taxeditor.operations.name.RemoveSynonymOperation; /** * Taxon tree viewer which responds to events within individual taxa. @@ -106,7 +99,6 @@ public class TaxonomicTreeViewer extends TreeViewer { private boolean quickAddMode; - private IOperationHistory operationHistory; private IUndoContext undoContext; private boolean initialized = false; @@ -122,8 +114,7 @@ public class TaxonomicTreeViewer extends TreeViewer { // SW.VIRTUAL causes nodes to be loaded on-demand, improving performance super(parent, SWT.VIRTUAL); - operationHistory = UiUtil.getOperationHistory(); - undoContext = UiUtil.getWorkbenchUndoContext(); + undoContext = GlobalController.getWorkbenchUndoContext(); tree = this.getTree(); tree.setLinesVisible(false); @@ -200,7 +191,7 @@ public class TaxonomicTreeViewer extends TreeViewer { // Make sure parentTaxon is not a child if (CdmUtil.isTaxonChildOfTaxon(parentTaxon, taxon)) { - MessageDialog.openError(UiUtil.getShell(), "Can't move taxon.", + MessageDialog.openError(GlobalController.getShell(), "Can't move taxon.", "'" + CdmUtil.getDisplayName(taxon) + "' sits above " + "'" + CdmUtil.getDisplayName(parentTaxon) + "' " + "in the taxonomic hierarchy."); @@ -218,11 +209,8 @@ public class TaxonomicTreeViewer extends TreeViewer { IUndoableOperation operation = new MoveTaxonOperation (text, undoContext, taxon, parentTaxon); - try { - IStatus status = operationHistory.execute(operation, null, null); - } catch (ExecutionException e) { - logger.error("Error moving taxon", e); - } + + GlobalController.executeOperation(operation); } }); } @@ -322,17 +310,11 @@ public class TaxonomicTreeViewer extends TreeViewer { this.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { - Taxon taxon = null; if (event.getSelection() instanceof StructuredSelection) { Object element = ((StructuredSelection) event .getSelection()).getFirstElement(); if (element instanceof Taxon) { -// new OpenTaxonEditorAction((Taxon) element).run(); - try { - UiUtil.openTaxonEditor((Taxon) element); - } catch (PartInitException e) { - logger.error("Error opening taxon editor", e); - } + EditorController.open((Taxon) element); } } } diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/AbstractEditorOperation.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/AbstractEditorOperation.java index f577a6d66..7b2f6e734 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/AbstractEditorOperation.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/AbstractEditorOperation.java @@ -16,7 +16,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import eu.etaxonomy.cdm.model.taxon.Taxon; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.EditorController; /** * @author p.ciardelli @@ -47,6 +47,6 @@ public abstract class AbstractEditorOperation extends AbstractOperation { * @return */ protected IStatus redrawOpenEditor() { - return UiUtil.redrawEditor(taxon) ? Status.OK_STATUS : Status.CANCEL_STATUS; + return EditorController.redraw(taxon) ? Status.OK_STATUS : Status.CANCEL_STATUS; } } diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/ChangeTaxonToSynonymOperation.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/ChangeTaxonToSynonymOperation.java new file mode 100644 index 000000000..4e46c5782 --- /dev/null +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/ChangeTaxonToSynonymOperation.java @@ -0,0 +1,142 @@ +/** +* Copyright (C) 2007 EDIT +* European Distributed Institute of Taxonomy +* http://www.e-taxonomy.eu +* +* The contents of this file are subject to the Mozilla Public License Version 1.1 +* See LICENSE.TXT at the top of this package for the full license terms. +*/ + +package eu.etaxonomy.taxeditor.operations; + +import org.apache.log4j.Logger; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.operations.IUndoContext; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.PartInitException; + +import sun.reflect.generics.reflectiveObjects.NotImplementedException; +import eu.etaxonomy.cdm.model.description.TaxonDescription; +import eu.etaxonomy.cdm.model.name.TaxonNameBase; +import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType; +import eu.etaxonomy.cdm.model.taxon.Taxon; +import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; +import eu.etaxonomy.taxeditor.controller.EditorController; +import eu.etaxonomy.taxeditor.controller.GlobalController; +import eu.etaxonomy.taxeditor.editor.SelectTaxonDialog; +import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository; +import eu.etaxonomy.taxeditor.model.CdmUtil; + +/** + * @author n.hoffmann + * @created 20.01.2009 + * @version 1.0 + */ +public class ChangeTaxonToSynonymOperation extends AbstractEditorOperation{ + + private static final Logger logger = Logger + .getLogger(ChangeTaxonToSynonymOperation.class); + + private Taxon destinationTaxon; + + public ChangeTaxonToSynonymOperation(String label, + IUndoContext undoContext, Taxon taxon) { + super(label, undoContext, taxon); + } + + @Override + public IStatus execute(IProgressMonitor monitor, IAdaptable info) + throws ExecutionException { + + IEditorPart editor = null; + + try { + // Prompt user "Would you like to save?" before showing dialog + // "Cancel" cancels action - "No" does not + editor = EditorController.getEditorByTaxon(taxon); + if (editor.isDirty()) { + if (!MessageDialog.openConfirm(GlobalController.getShell(), "Save before proceeding", + "All changes must be saved before proceeding with this action.\n\n" + + "Press \"OK\" to save and continue, or \"Cancel\" to cancel this action.")) { + return Status.CANCEL_STATUS; + } + editor.doSave(null); + } +// if (UiUtil.getActivePage().saveEditor(oldEditor, true) == false) { +// return; +// } + } catch (PartInitException e1) { + e1.printStackTrace(); + } + + // Get destination taxon from dialog + Shell shell = GlobalController.getShell(); + SelectTaxonDialog dialog = new SelectTaxonDialog(shell, SelectTaxonDialog.TAXON_TO_SYNONYM); + destinationTaxon = dialog.open(taxon); + + // Abort action if user cancelled dialog without choosing a taxon + if (destinationTaxon == null) { + return Status.CANCEL_STATUS; + } + + + return makeTaxonSynonym(taxon, destinationTaxon) ? Status.OK_STATUS : Status.CANCEL_STATUS; + } + + private boolean makeTaxonSynonym(Taxon taxon, Taxon destinationTaxon){ + // Move taxon in CDM to new destinationTaxon + TaxonNameBase synonymName = taxon.getName(); + SynonymRelationshipType synonymType; + if (CdmUtil.isNameHomotypic(synonymName, destinationTaxon)) { + synonymType = SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF(); + } else { + synonymType = SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF(); + } + CdmUtil.makeTaxonSynonym(taxon, destinationTaxon, synonymType, + null, null); + + // TODO move any children, descriptions, synonyms + for (TaxonDescription description: taxon.getDescriptions()) { + destinationTaxon.addDescription(description); + taxon.removeDescription(description); + } + + for (TaxonRelationship fromRelation : taxon.getRelationsFromThisTaxon()) { + fromRelation.setFromTaxon(destinationTaxon); + } + + for (TaxonRelationship toRelation : taxon.getRelationsToThisTaxon()) { + toRelation.setToTaxon(destinationTaxon); + } + + CdmSessionDataRepository.getDefault().removeTaxon(taxon); + + // Close open editor for oldTaxon without forcing save. + // User has already saved or declined to do so above. + EditorController.close(taxon, false); + CdmSessionDataRepository.getDefault().saveTaxon(destinationTaxon); + // Open editor for destinationTaxon + EditorController.open(destinationTaxon); + + return true; + } + + @Override + public IStatus redo(IProgressMonitor monitor, IAdaptable info) + throws ExecutionException { + return makeTaxonSynonym(taxon, destinationTaxon) ? Status.OK_STATUS : Status.CANCEL_STATUS; + } + + @Override + public IStatus undo(IProgressMonitor monitor, IAdaptable info) + throws ExecutionException { + // TODO implement undo + throw new NotImplementedException(); + } +} diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/DeleteTaxonOperation.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/DeleteTaxonOperation.java index 8cd2daf90..a1e6a6c93 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/DeleteTaxonOperation.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/DeleteTaxonOperation.java @@ -20,7 +20,8 @@ import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.ui.PartInitException; import eu.etaxonomy.cdm.model.taxon.Taxon; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.EditorController; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository; /** @@ -66,7 +67,7 @@ public class DeleteTaxonOperation extends AbstractEditorOperation { String taxonName = taxon.getName().getTitleCache(); // Prompt user for confirmation - if(! MessageDialog.openConfirm(UiUtil.getShell(), "Confirm Deletion", "Are you sure you want to delete taxon '" + taxonName + "'?")){ + if(! MessageDialog.openConfirm(GlobalController.getShell(), "Confirm Deletion", "Are you sure you want to delete taxon '" + taxonName + "'?")){ monitor.done(); return Status.CANCEL_STATUS; } @@ -75,13 +76,13 @@ public class DeleteTaxonOperation extends AbstractEditorOperation { monitor.beginTask("Deleting taxon '" + taxonName + "'.", 10); // Call save all - UiUtil.saveAll(); + EditorController.saveAll(); monitor.worked(2); // If the taxon has children, cancel operation // TODO add option to continue, and delete children if (taxon.hasTaxonomicChildren()) { - MessageDialog.openInformation(UiUtil.getShell(), "Cannot delete taxon", + MessageDialog.openInformation(GlobalController.getShell(), "Cannot delete taxon", "'" + taxonName + "' has taxonomic children. " + "These must be manually deleted before their parent."); monitor.done(); @@ -91,26 +92,22 @@ public class DeleteTaxonOperation extends AbstractEditorOperation { // Close taxon's editor, if any is active - try { - UiUtil.closeEditor(taxon, true); - } catch (PartInitException e) { - e.printStackTrace(); - } + EditorController.close(taxon, true); monitor.worked(1); // Delete taxon from CDM layer - CdmSessionDataRepository.getDefault().removeTaxon(taxon); + CdmSessionDataRepository.getDefault().deleteTaxon(taxon); monitor.worked(4); // Call save all - UiUtil.saveAll(); + EditorController.saveAll(); monitor.worked(2); // Close the progress monitor monitor.done(); // Announce taxon was deleted on status line - UiUtil.setStatusLine("Deleted taxon '" + taxonName + "'."); + GlobalController.setStatusLine("Deleted taxon '" + taxonName + "'."); return Status.OK_STATUS; } diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/name/ChangeSynonymToTaxonOperation.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/name/ChangeSynonymToTaxonOperation.java index b6080cf9f..5079a6300 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/name/ChangeSynonymToTaxonOperation.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/name/ChangeSynonymToTaxonOperation.java @@ -19,7 +19,7 @@ import org.eclipse.ui.PartInitException; import eu.etaxonomy.cdm.model.taxon.Synonym; import eu.etaxonomy.cdm.model.taxon.Taxon; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.EditorController; import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository; import eu.etaxonomy.taxeditor.operations.AbstractEditorOperation; @@ -58,11 +58,8 @@ public class ChangeSynonymToTaxonOperation extends AbstractEditorOperation { CdmSessionDataRepository.getDefault().addTaxon(newTaxon); // Open editor for new taxon - try { - UiUtil.openTaxonEditor(newTaxon); - } catch (PartInitException e) { - e.printStackTrace(); - } + EditorController.open(newTaxon); + return redrawOpenEditor(); } diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/name/MakeSynonymAcceptedOperation.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/name/MakeSynonymAcceptedOperation.java index a870e3d9b..dc0793742 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/name/MakeSynonymAcceptedOperation.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/name/MakeSynonymAcceptedOperation.java @@ -25,8 +25,9 @@ import eu.etaxonomy.cdm.model.name.TaxonNameBase; import eu.etaxonomy.cdm.model.taxon.Synonym; import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.taxeditor.TaxEditorPlugin; -import eu.etaxonomy.taxeditor.UiUtil; import eu.etaxonomy.taxeditor.actions.ui.OpenTaxonEditorAction; +import eu.etaxonomy.taxeditor.controller.EditorController; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository; import eu.etaxonomy.taxeditor.navigation.RecentNamesView; import eu.etaxonomy.taxeditor.operations.AbstractEditorOperation; @@ -58,19 +59,19 @@ public class MakeSynonymAcceptedOperation extends AbstractEditorOperation { // If taxon editor is dirty force user to save before proceeding, then close editor try { - IEditorPart oldEditor = UiUtil.getEditorByTaxon(taxon); + IEditorPart oldEditor = EditorController.getEditorByTaxon(taxon); if (oldEditor.isDirty()) { - if (!MessageDialog.openConfirm(UiUtil.getShell(), "Save before proceeding", + if (!MessageDialog.openConfirm(GlobalController.getShell(), "Save before proceeding", "All changes must be saved before proceeding with this action.\n\n" + "Press \"OK\" to save and continue, or \"Cancel\" to cancel this action.")) { return Status.CANCEL_STATUS; } oldEditor.doSave(null); - UiUtil.closeEditor(oldEditor, true); + EditorController.close(taxon, true); } } catch (PartInitException e) { - e.printStackTrace(); - MessageDialog.openError(UiUtil.getShell(), "Error", "Error saving and closing taxon"); + logger.error("Error while trying to save and close old editor.", e); + MessageDialog.openError(GlobalController.getShell(), "Error", "Error saving and closing taxon"); return Status.CANCEL_STATUS; } @@ -91,11 +92,8 @@ public class MakeSynonymAcceptedOperation extends AbstractEditorOperation { CdmSessionDataRepository.getDefault().addTaxon(newAcceptedTaxon); // Open editor for new accepted taxon - try { - UiUtil.openTaxonEditor(newAcceptedTaxon); - } catch (PartInitException e) { - e.printStackTrace(); - } + EditorController.open(newAcceptedTaxon); + // Remove old taxon from recent names list RecentNamesView.addRecentName(taxon); diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/name/RemoveSynonymOperation.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/name/RemoveSynonymOperation.java index f2d5b44f0..3e15169b4 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/name/RemoveSynonymOperation.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/name/RemoveSynonymOperation.java @@ -23,7 +23,7 @@ import org.eclipse.core.runtime.Status; import eu.etaxonomy.cdm.model.taxon.Synonym; import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType; import eu.etaxonomy.cdm.model.taxon.Taxon; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor; import eu.etaxonomy.taxeditor.operations.AbstractEditorOperation; diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java index 3a6191518..b0241f822 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java @@ -24,7 +24,7 @@ import eu.etaxonomy.cdm.model.name.Rank; import eu.etaxonomy.cdm.model.name.ZoologicalName; import eu.etaxonomy.taxeditor.ITaxEditorConstants; import eu.etaxonomy.taxeditor.TaxEditorPlugin; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository; /** @@ -87,20 +87,20 @@ public class PreferencesUtil { public static Set getPreferredFeatures() { // Initialize preferredFeatureSet as necessary - if (UiUtil.preferredFeatureSet == null) { + if (GlobalController.getPreferredFeatures() == null) { - UiUtil.preferredFeatureSet = new HashSet(); + GlobalController.setPreferredFeatures(new HashSet()); for (Feature feature : CdmSessionDataRepository.getDefault().getFeatures()) { // If the feature is set to show, add it to preferredFeatureSet if (PreferencesUtil.getFeaturePreference(feature)) { - UiUtil.preferredFeatureSet.add(feature); + GlobalController.addPreferredFeature(feature); } } } - return UiUtil.preferredFeatureSet; + return GlobalController.getPreferredFeatures(); } /** @@ -132,7 +132,7 @@ public class PreferencesUtil { * @param show */ public static void setFeaturePreference(Feature feature, boolean show) { - UiUtil.preferredFeatureSet = null; + GlobalController.setPreferredFeatures(null); PreferencesUtil.getPrefStore().setValue(PreferencesUtil.getPreferenceKey(feature), show); } @@ -163,10 +163,10 @@ public class PreferencesUtil { */ public static Set getPreferredRanks() { - // Initialize preferredFeatureSet as necessary - if (UiUtil.preferredRankSet == null) { + // Initialize preferredRankSet as necessary + if (GlobalController.getPreferredRanks() == null) { - UiUtil.preferredRankSet = new HashSet(); + GlobalController.setPreferredRanks(new HashSet()); SortedSet ranks = CdmSessionDataRepository.getDefault().getRanks(); if (ranks != null) { @@ -175,13 +175,13 @@ public class PreferencesUtil { // If the feature is set to show, add it to preferredFeatureSet if (PreferencesUtil.getRankPreference(rank)) { - UiUtil.preferredRankSet.add(rank); + GlobalController.addPreferredRank(rank); } } } // else { TODO: error message } - return UiUtil.preferredRankSet; + return GlobalController.getPreferredRanks(); } /** @@ -213,7 +213,7 @@ public class PreferencesUtil { * @param show */ public static void setRankPreference(Rank rank, boolean show) { - UiUtil.preferredRankSet = null; + GlobalController.setPreferredRanks(null); getPrefStore().setValue(PreferencesUtil.getPreferenceKey(rank), show); } diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/NameRelationsPropertySource.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/NameRelationsPropertySource.java index c241e9ce2..77c0a3c9e 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/NameRelationsPropertySource.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/NameRelationsPropertySource.java @@ -16,7 +16,7 @@ import eu.etaxonomy.cdm.model.name.NameRelationship; import eu.etaxonomy.cdm.model.name.NameRelationshipType; import eu.etaxonomy.cdm.model.name.TaxonNameBase; import eu.etaxonomy.cdm.model.name.ZoologicalName; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.propertysheet.CollectionPropertySource; public class NameRelationsPropertySource extends CollectionPropertySource { @@ -53,7 +53,7 @@ public class NameRelationsPropertySource extends CollectionPropertySource { NameRelationshipType type = nameRelation.getType(); // or the label? LABEL - String label = UiUtil.getNameRelationLabelType(type); + String label = GlobalController.getNameRelationLabelType(type); if (isZoological && nameRelation.getType().equals(NameRelationshipType.BASIONYM())) { label = "original combination"; diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/NomStatusPropertySource.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/NomStatusPropertySource.java index cd7c09ac2..d1ad8595d 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/NomStatusPropertySource.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/NomStatusPropertySource.java @@ -43,7 +43,7 @@ public class NomStatusPropertySource extends CollectionPropertySource { // Get terms from nom status vocabulary List nomStatusTypesList = new ArrayList(); nomStatusTypesList.addAll( - CdmSessionDataRepository.getDefault().getNomStatii().getTerms()); + CdmSessionDataRepository.getDefault().getNomStatus().getTerms()); // Populate nom status type menu labels List nomStatusTypesMenuList = new ArrayList(); diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/NonViralNamePropertySource.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/NonViralNamePropertySource.java index e29c09c02..7400d3949 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/NonViralNamePropertySource.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/NonViralNamePropertySource.java @@ -141,7 +141,7 @@ public class NonViralNamePropertySource implements IPropertySource { // Get terms from nom status vocabulary List nomStatusTypesList = new ArrayList(); TermVocabulary statusVocab = - CdmSessionDataRepository.getDefault().getNomStatii(); + CdmSessionDataRepository.getDefault().getNomStatus(); // If there is no status vocabulary, init type and status w empty arrays and return if (statusVocab == null) { diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/TaxonBasePropertySource.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/TaxonBasePropertySource.java index 51cd84d8f..dfe4907a7 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/TaxonBasePropertySource.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/TaxonBasePropertySource.java @@ -25,6 +25,7 @@ import eu.etaxonomy.cdm.model.name.TaxonNameBase; import eu.etaxonomy.cdm.model.name.ZoologicalName; import eu.etaxonomy.cdm.model.reference.ReferenceBase; import eu.etaxonomy.cdm.model.taxon.TaxonBase; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.propertysheet.reference.IReferenceSearch; import eu.etaxonomy.taxeditor.propertysheet.reference.ReferencePropertySource; import eu.etaxonomy.taxeditor.propertysheet.reference.ReferenceSearchDescriptor; diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/namerelationswizard/ListNameRelationsWizardPage.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/namerelationswizard/ListNameRelationsWizardPage.java index 088535233..d0c5928c7 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/namerelationswizard/ListNameRelationsWizardPage.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/namerelationswizard/ListNameRelationsWizardPage.java @@ -37,9 +37,9 @@ import eu.etaxonomy.cdm.model.name.TaxonNameBase; import eu.etaxonomy.cdm.model.name.ZoologicalName; import eu.etaxonomy.taxeditor.ITaxEditorConstants; import eu.etaxonomy.taxeditor.TaxEditorPlugin; -import eu.etaxonomy.taxeditor.UiUtil; import eu.etaxonomy.taxeditor.actions.cdm.DeleteNameRelationAction; import eu.etaxonomy.taxeditor.actions.ui.OpenNameRelationWizardAction; +import eu.etaxonomy.taxeditor.controller.GlobalController; import eu.etaxonomy.taxeditor.model.CdmUtil; /** @@ -223,7 +223,7 @@ public class ListNameRelationsWizardPage extends WizardPage { type = "original combination"; } else { // type = nameRelationship.getType().getLabel(); - type = UiUtil.getNameRelationLabelType(nameRelationship.getType()); + type = GlobalController.getNameRelationLabelType(nameRelationship.getType()); } } if (nameRelationship.getToName() == null) { diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/reference/SingleRefTypePropertySource.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/reference/SingleRefTypePropertySource.java index cf64b469b..f9a95907b 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/reference/SingleRefTypePropertySource.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/reference/SingleRefTypePropertySource.java @@ -19,7 +19,7 @@ import eu.etaxonomy.cdm.model.reference.Journal; import eu.etaxonomy.cdm.model.reference.ReferenceBase; import eu.etaxonomy.taxeditor.ITaxEditorConstants; import eu.etaxonomy.taxeditor.TaxEditorPlugin; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.GlobalController; /** * This subclass is for cases where only one subclass of ReferenceBase