From 01731ab54ac9753cba5fdc76f215cd50efe77c2e Mon Sep 17 00:00:00 2001 From: "n.hoffmann" Date: Thu, 21 Apr 2011 15:02:23 +0000 Subject: [PATCH] minor --- .../editor/name/TaxonNameEditor.java | 659 +++++++------ .../taxeditor/model/AbstractUtility.java | 894 +++++++++++------- 2 files changed, 924 insertions(+), 629 deletions(-) diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/TaxonNameEditor.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/TaxonNameEditor.java index fc11c4456..37b99454d 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/TaxonNameEditor.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/TaxonNameEditor.java @@ -1,11 +1,11 @@ /** -* 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. -*/ + * 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.editor.name; @@ -72,31 +72,35 @@ import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; import eu.etaxonomy.taxeditor.preference.Resources; /** - *

TaxonNameEditor class.

- * + *

+ * TaxonNameEditor class. + *

+ * * @author p.ciardelli * @author n.hoffmann * @created 15.05.2008 * @version 1.0 */ -public class TaxonNameEditor extends EditorPart implements IMultiPageTaxonEditorPage, IAdaptable, IConversationEnabled, IPostOperationEnabled, IPartContentHasDetails, IPartChangeListener - , ISelectionListener, IDropTargetable { - +public class TaxonNameEditor extends EditorPart implements + IMultiPageTaxonEditorPage, IAdaptable, IConversationEnabled, + IPostOperationEnabled, IPartContentHasDetails, IPartChangeListener, + ISelectionListener, IDropTargetable { + /** Constant ID="eu.etaxonomy.taxeditor.editor.taxon.name" */ public static final String ID = "eu.etaxonomy.taxeditor.editor.taxon.name"; - + private Taxon taxon; - + private ManagedForm managedForm; - private ScrolledForm scrolledForm; + private ScrolledForm scrolledForm; private Composite parent; private ISelectionProvider provider; - - private MultiPageTaxonEditor editor; - + + private final MultiPageTaxonEditor editor; + private TaxonBase selection; - - private ConversationHolder conversation; + + private final ConversationHolder conversation; private MenuManager menuManager; @@ -106,451 +110,516 @@ public class TaxonNameEditor extends EditorPart implements IMultiPageTaxonEditor private ConceptGroup conceptGroup; - private List heterotypicSynonymGroups = new ArrayList(); - + private final List heterotypicSynonymGroups = new ArrayList(); + private DropTarget target; - + private ISelectionService selectionService; private AcceptedGroup acceptedGroup; private TaxonBase objectAffectedByLastOperation; - + /** - *

Constructor for TaxonNameEditor.

- * - * @param editor a {@link eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor} object. + *

+ * Constructor for TaxonNameEditor. + *

+ * + * @param editor + * a {@link eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor} + * object. */ - public TaxonNameEditor(MultiPageTaxonEditor editor){ + public TaxonNameEditor(MultiPageTaxonEditor editor) { this.editor = editor; conversation = editor.getConversationHolder(); } - - /** - *

getUndoContext

- * - * @return a {@link org.eclipse.core.commands.operations.IUndoContext} object. + *

+ * getUndoContext + *

+ * + * @return a {@link org.eclipse.core.commands.operations.IUndoContext} + * object. */ public IUndoContext getUndoContext() { return editor.getUndoContext(); } - /* (non-Javadoc) - * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets + * .Composite) */ /** {@inheritDoc} */ + @Override public void createPartControl(Composite composite) { selectionService = getSite().getWorkbenchWindow().getSelectionService(); selectionService.addSelectionListener(this); - + createManagedForm(composite); - - TaxeditorPartService.getInstance().addListener(TaxeditorPartService.PART_ACTIVATED, this); + + TaxeditorPartService.getInstance().addListener( + TaxeditorPartService.PART_ACTIVATED, this); } - + /** - *

createManagedForm

- * - * @param composite a {@link org.eclipse.swt.widgets.Composite} object. + *

+ * createManagedForm + *

+ * + * @param composite + * a {@link org.eclipse.swt.widgets.Composite} object. */ protected void createManagedForm(Composite composite) { - + managedForm = new ManagedForm(composite) { - + + @Override public void dirtyStateChanged() { firePropertyChange(PROP_DIRTY); } + + @Override public boolean setInput(Object input) { if (input instanceof AbstractGroupedContainer) { selection = ((AbstractGroupedContainer) input).getData(); provider.setSelection(new StructuredSelection(selection)); } - return super.setInput(input); + return super.setInput(input); } }; - - + scrolledForm = managedForm.getForm(); parent = scrolledForm.getBody(); - + // register the context menu menuManager = new MenuManager(); ISelectionProvider selectionProvider = getSite().getSelectionProvider(); - getSite().registerContextMenu(TaxonNameEditor.ID, menuManager, selectionProvider); - + getSite().registerContextMenu(TaxonNameEditor.ID, menuManager, + selectionProvider); + parent.setData(taxon); - + TableWrapLayout layout = new TableWrapLayout(); layout.leftMargin = 0; layout.rightMargin = 0; layout.topMargin = 0; layout.bottomMargin = 0; - + layout.verticalSpacing = 0; layout.horizontalSpacing = 0; - - parent.setLayout(layout); - parent.setBackground(EditorUtil.getColor(Resources.COLOR_COMPOSITE_BACKGROUND)); - + + parent.setLayout(layout); + parent.setBackground(EditorUtil + .getColor(Resources.COLOR_COMPOSITE_BACKGROUND)); + createOrUpdateNameComposites(); - + createDragSupport(); - + setFocus(); } - + /** - *

createNameComposites

+ *

+ * createNameComposites + *

*/ - public void createOrUpdateNameComposites(){ - + public void createOrUpdateNameComposites() { + ContainerFactory.createOrUpdateAcceptedTaxonsHomotypicGroup(this); ContainerFactory.createOrUpdateHeterotypicSynonymyGroups(this); ContainerFactory.createOrUpdateMisapplicationsGroup(this); ContainerFactory.createOrUpdateConceptGroup(this); - + // Redraw composite managedForm.reflow(true); } - - - /** - *

Getter for the field taxon.

- * + *

+ * Getter for the field taxon. + *

+ * * @return a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object. */ public Taxon getTaxon() { return (Taxon) HibernateProxyHelper.deproxy(taxon); } - + /** - *

setDirty

+ *

+ * setDirty + *

*/ public void setDirty() { managedForm.dirtyStateChanged(); } - - + /* * (non-Javadoc) + * * @see org.eclipse.ui.part.WorkbenchPart#setFocus() */ /** {@inheritDoc} */ @Override - public void setFocus(){ - if(getSelectedContainer() == null){ - throw new IllegalStateException("There should always be a selected object."); + public void setFocus() { + if (getSelectedContainer() == null) { + throw new IllegalStateException( + "There should always be a selected object."); } getSelectedContainer().setSelected(); } - + /** {@inheritDoc} */ - public void setInput(IEditorInput input){ + @Override + public void setInput(IEditorInput input) { this.setInputWithNotify(input); } - + /* * (non-Javadoc) - * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder() + * + * @see + * eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder + * () */ /** - *

getConversationHolder

- * - * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object. + *

+ * getConversationHolder + *

+ * + * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} + * object. */ - public ConversationHolder getConversationHolder(){ + public ConversationHolder getConversationHolder() { return conversation; } - + /* * (non-Javadoc) - * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostCrudObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmCrudEvent) + * + * @see + * eu.etaxonomy.cdm.persistence.hibernate.ICdmPostCrudObserver#update(eu + * .etaxonomy.cdm.persistence.hibernate.CdmCrudEvent) */ /** {@inheritDoc} */ public void update(CdmDataChangeMap events) { - //redraw(); + // redraw(); } - + /** - * Redraws this editor - * return true on success - * + * Redraws this editor return true on success + * * @return a boolean. */ - public boolean redraw(){ + public boolean redraw() { return redraw(true); } - + /** * {@inheritDoc} - * + * * Redraws the editor controls */ public boolean redraw(boolean focus) { - + createOrUpdateNameComposites(); - - if(focus){ + + if (focus) { setFocus(); } - - return true; + + return true; } - /** - *

getMultiPageTaxonEditor

- * - * @return a {@link eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor} object. + *

+ * getMultiPageTaxonEditor + *

+ * + * @return a {@link eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor} + * object. */ public MultiPageTaxonEditor getMultiPageTaxonEditor() { return editor; } - /* * (non-Javadoc) - * @see eu.etaxonomy.taxeditor.store.operations.IPostOperationEnabled#postOperation() + * + * @see + * eu.etaxonomy.taxeditor.store.operations.IPostOperationEnabled#postOperation + * () */ /** {@inheritDoc} */ public boolean postOperation(CdmBase objectAffectedByOperation) { - + editor.changed(objectAffectedByOperation); - + redraw(false); - - if(objectAffectedByOperation instanceof TaxonBase){ + + if (objectAffectedByOperation instanceof TaxonBase) { objectAffectedByLastOperation = (TaxonBase) objectAffectedByOperation; } - + return true; } - + /** - *

Getter for the field managedForm.

- * + *

+ * Getter for the field managedForm. + *

+ * * @return the managedForm */ public ManagedForm getManagedForm() { return managedForm; } - + /** - *

getControl

- * + *

+ * getControl + *

+ * * @return a {@link org.eclipse.swt.widgets.Composite} object. */ public Composite getControl() { return this.getManagedForm().getForm().getBody(); } - /** - *

Getter for the field menu.

- * + *

+ * Getter for the field menu. + *

+ * * @return the menu */ public Menu getMenu() { - if(menu == null || menu.isDisposed()){ - // Creating the menu because it was either not initialised or disposed while refreshing the editor + if (menu == null || menu.isDisposed()) { + // Creating the menu because it was either not initialised or + // disposed while refreshing the editor menu = menuManager.createContextMenu(parent); } return menu; } /** - *

checkForEmptyNames

- * + *

+ * checkForEmptyNames + *

+ * * @return true if there are empty names */ public boolean checkForEmptyNames() { - for(AbstractGroupedContainer container : getGroupedContainers()){ - if(container.getName() == null || StringUtils.isEmpty(container.getName().getTitleCache())){ + for (AbstractGroupedContainer container : getGroupedContainers()) { + if (container.getName() == null + || StringUtils.isEmpty(container.getName().getTitleCache())) { return true; } } return false; } - - public Set getEmptyContainers(){ + public Set getEmptyContainers() { Set containersWithEmptyNames = new HashSet(); - - for(AbstractGroupedContainer container : getGroupedContainers()){ - if(container.getName() == null || StringUtils.isEmpty(container.getName().getTitleCache())){ + + for (AbstractGroupedContainer container : getGroupedContainers()) { + if (container.getName() == null + || StringUtils.isEmpty(container.getName().getTitleCache())) { containersWithEmptyNames.add(container); } } - + return containersWithEmptyNames; } - + /** {@inheritDoc} */ @Override public void doSave(IProgressMonitor monitor) { monitor.beginTask("Saving names", getGroupedContainers().size()); - try { + try { // check for empty names - for(AbstractGroupedContainer container : getGroupedContainers()){ - - monitor.subTask("Saving composite: " + container.getTaxonBase().getTitleCache()); + for (AbstractGroupedContainer container : getGroupedContainers()) { + + monitor.subTask("Saving composite: " + + container.getTaxonBase().getTitleCache()); container.persistName(); - + // In case the progress monitor was canceled throw an exception. if (monitor.isCanceled()) { - throw new OperationCanceledException(); - } - + throw new OperationCanceledException(); + } + // Otherwise declare this step as done. monitor.worked(1); } - } - finally { - - // Stop the progress monitor. - monitor.done(); - } - + } finally { + + // Stop the progress monitor. + monitor.done(); + } + } /** {@inheritDoc} */ @Override - public void doSaveAs() {} + public void doSaveAs() { + } /** {@inheritDoc} */ @Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { - + if (!(input instanceof IEditorInput)) - throw new PartInitException( - "Invalid Input: Must be IEditorInput"); - + throw new PartInitException("Invalid Input: Must be IEditorInput"); + if (input.getAdapter(Taxon.class) != null) { taxon = (Taxon) input.getAdapter(Taxon.class); } else { - throw new PartInitException( - "Invalid Input: Taxon cannot be null"); + throw new PartInitException("Invalid Input: Taxon cannot be null"); } setSite(site); setInput(input); - + provider = new SimpleSelectionProvider(); getSite().setSelectionProvider(provider); } - + /** * */ private void createDragSupport() { // Listen for names being dragged outside of existing homotypic groups - - // user wants to create a new group - Transfer[] types = new Transfer[] {CdmDataTransfer.getInstance()}; + // user wants to create a new group + Transfer[] types = new Transfer[] { CdmDataTransfer.getInstance() }; int operations = DND.DROP_MOVE; - if(target == null){ + if (target == null) { target = new DropTarget(parent, operations); target.setTransfer(types); target.addDropListener(new NameEditorDropTargetListener(this)); - } + } } /** - *

Getter for the field acceptedNameContainer.

- * - * @return a {@link eu.etaxonomy.taxeditor.editor.name.container.AcceptedNameContainer} object. + *

+ * Getter for the field acceptedNameContainer. + *

+ * + * @return a + * {@link eu.etaxonomy.taxeditor.editor.name.container.AcceptedNameContainer} + * object. */ public AcceptedNameContainer getAcceptedNameContainer() { return getAcceptedGroup().getAcceptedNameContainer(); } - + /** - *

getSynonymGroup

- * - * @param homotypicalGroup a {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup} object. - * @return a {@link eu.etaxonomy.taxeditor.editor.name.container.HomotypicalSynonymGroup} object. - */ - public HomotypicalSynonymGroup getHomotypicalGroupContainer(HomotypicalGroup homotypicalGroup) { - for(HomotypicalSynonymGroup group : getHeterotypicSynonymGroups()){ - if(group.getGroup().equals(homotypicalGroup)){ + *

+ * getSynonymGroup + *

+ * + * @param homotypicalGroup + * a {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup} object. + * @return a + * {@link eu.etaxonomy.taxeditor.editor.name.container.HomotypicalSynonymGroup} + * object. + */ + public HomotypicalSynonymGroup getHomotypicalGroupContainer( + HomotypicalGroup homotypicalGroup) { + for (HomotypicalSynonymGroup group : getHeterotypicSynonymGroups()) { + if (group.getGroup().equals(homotypicalGroup)) { return group; } } - + return null; } - + /** - *

Getter for the field conceptGroup.

- * - * @return a {@link eu.etaxonomy.taxeditor.editor.name.container.ConceptGroup} object. + *

+ * Getter for the field conceptGroup. + *

+ * + * @return a + * {@link eu.etaxonomy.taxeditor.editor.name.container.ConceptGroup} + * object. */ public ConceptGroup getConceptGroup() { return conceptGroup; } - + /** - *

getDirtyNames

- * + *

+ * getDirtyNames + *

+ * * @return a Set containing all composites that have been edited */ - public Set getDirtyNames(){ + public Set getDirtyNames() { Set dirtyNames = new HashSet(); - - for(AbstractGroupedContainer composite : getGroupedContainers()){ - if(composite.isDirty()){ + + for (AbstractGroupedContainer composite : getGroupedContainers()) { + if (composite.isDirty()) { dirtyNames.add(composite); } } - + return dirtyNames; } - + /** - *

getGroupedContainers

- * + *

+ * getGroupedContainers + *

+ * * @return a {@link java.util.List} object. */ - public List getGroupedContainers(){ + public List getGroupedContainers() { List groupedComposites = new ArrayList(); - - for(AbstractGroup group : getAllGroups()){ + + for (AbstractGroup group : getAllGroups()) { groupedComposites.addAll(group.getGroupedContainers()); } - + return groupedComposites; } - + /** - *

getAllGroups

- * + *

+ * getAllGroups + *

+ * * @return a {@link java.util.List} object. */ - public List getAllGroups(){ + public List getAllGroups() { List allGroups = new ArrayList(); - + allGroups.add(getAcceptedGroup()); - + allGroups.addAll(getHeterotypicSynonymGroups()); - - if(misappliedGroup != null){ + + if (misappliedGroup != null) { allGroups.add(misappliedGroup); } - - if(conceptGroup != null){ + + if (conceptGroup != null) { allGroups.add(conceptGroup); } - + return allGroups; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.ui.part.EditorPart#isDirty() */ /** {@inheritDoc} */ @@ -558,8 +627,10 @@ public class TaxonNameEditor extends EditorPart implements IMultiPageTaxonEditor public boolean isDirty() { return editor.isDirty(); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.eclipse.ui.part.WorkbenchPart#dispose() */ /** {@inheritDoc} */ @@ -568,7 +639,9 @@ public class TaxonNameEditor extends EditorPart implements IMultiPageTaxonEditor super.dispose(); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed() */ /** {@inheritDoc} */ @@ -576,74 +649,100 @@ public class TaxonNameEditor extends EditorPart implements IMultiPageTaxonEditor public boolean isSaveAsAllowed() { return false; } - + /* * (non-Javadoc) - * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) + * + * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui. + * IWorkbenchPart, org.eclipse.jface.viewers.ISelection) */ /** {@inheritDoc} */ public void selectionChanged(IWorkbenchPart part, ISelection selection) { - + } /** - *

getNameEditor

- * - * @return a {@link eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor} object. + *

+ * getNameEditor + *

+ * + * @return a {@link eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor} + * object. */ public TaxonNameEditor getEditor() { return this; } /** - *

Getter for the field selectedObject.

- * - * @return a {@link eu.etaxonomy.taxeditor.editor.name.container.AbstractGroupedContainer} object. + *

+ * Getter for the field selectedObject. + *

+ * + * @return a + * {@link eu.etaxonomy.taxeditor.editor.name.container.AbstractGroupedContainer} + * object. */ - public AbstractGroupedContainer getSelectedContainer(){ - + public AbstractGroupedContainer getSelectedContainer() { + TaxonBase selectedTaxonBase = null; - + TaxonEditorInput input = (TaxonEditorInput) editor.getEditorInput(); - if(input.getInitiallySelectedTaxonBase() != null){ + if (input.getInitiallySelectedTaxonBase() != null) { selectedTaxonBase = input.getInitiallySelectedTaxonBase(); - }else{ - if(selection != null){ + } else { + if (selection != null) { selectedTaxonBase = selection; } } - - return (selectedTaxonBase != null) ? getContainer(selectedTaxonBase) : getAcceptedNameContainer(); + + return (selectedTaxonBase != null) ? getContainer(selectedTaxonBase) + : getAcceptedNameContainer(); } - + /** - *

dragEntered

+ *

+ * dragEntered + *

*/ public void dragEntered() { // TODO change this - getControl().setBackground(EditorUtil.getColor(Resources.COLOR_DRAG_ENTER)); + getControl().setBackground( + EditorUtil.getColor(Resources.COLOR_DRAG_ENTER)); } /** - *

dragLeft

+ *

+ * dragLeft + *

*/ public void dragLeft() { - getControl().setBackground(EditorUtil.getColor(Resources.COLOR_COMPOSITE_BACKGROUND)); + getControl().setBackground( + EditorUtil.getColor(Resources.COLOR_COMPOSITE_BACKGROUND)); } /** - *

Setter for the field conceptGroup.

- * - * @param conceptGroup a {@link eu.etaxonomy.taxeditor.editor.name.container.ConceptGroup} object. + *

+ * Setter for the field conceptGroup. + *

+ * + * @param conceptGroup + * a + * {@link eu.etaxonomy.taxeditor.editor.name.container.ConceptGroup} + * object. */ public void setConceptGroup(ConceptGroup conceptGroup) { this.conceptGroup = conceptGroup; } /** - *

setMisapplicationsGroup

- * - * @param misappliedGroup a {@link eu.etaxonomy.taxeditor.editor.name.container.MisappliedGroup} object. + *

+ * setMisapplicationsGroup + *

+ * + * @param misappliedGroup + * a + * {@link eu.etaxonomy.taxeditor.editor.name.container.MisappliedGroup} + * object. */ public void setMisapplicationsGroup(MisappliedGroup misappliedGroup) { this.misappliedGroup = misappliedGroup; @@ -651,11 +750,15 @@ public class TaxonNameEditor extends EditorPart implements IMultiPageTaxonEditor /* * (non-Javadoc) - * @see eu.etaxonomy.taxeditor.editor.IMultiPageTaxonEditorPage#isRedrawing() + * + * @see + * eu.etaxonomy.taxeditor.editor.IMultiPageTaxonEditorPage#isRedrawing() */ /** - *

isRedrawing

- * + *

+ * isRedrawing + *

+ * * @return a boolean. */ public boolean isRedrawing() { @@ -663,8 +766,10 @@ public class TaxonNameEditor extends EditorPart implements IMultiPageTaxonEditor } /** - *

getToolkit

- * + *

+ * getToolkit + *

+ * * @return a {@link org.eclipse.ui.forms.widgets.FormToolkit} object. */ public FormToolkit getToolkit() { @@ -672,48 +777,59 @@ public class TaxonNameEditor extends EditorPart implements IMultiPageTaxonEditor } /** - *

getHeterotypicSynonymGroups

- * + *

+ * getHeterotypicSynonymGroups + *

+ * * @return a {@link java.util.List} object. */ - public List getHeterotypicSynonymGroups(){ + public List getHeterotypicSynonymGroups() { return heterotypicSynonymGroups; } - /** - *

addHeterotypicSynonymGroup

- * - * @param group a {@link eu.etaxonomy.taxeditor.editor.name.container.HomotypicalSynonymGroup} object. + *

+ * addHeterotypicSynonymGroup + *

+ * + * @param group + * a + * {@link eu.etaxonomy.taxeditor.editor.name.container.HomotypicalSynonymGroup} + * object. */ public void addHeterotypicSynonymGroup(HomotypicalSynonymGroup group) { heterotypicSynonymGroups.add(group); } - + /** - *

getHomotypicSynonymGroup

- * - * @return a {@link eu.etaxonomy.taxeditor.editor.name.container.HomotypicalSynonymGroup} object. + *

+ * getHomotypicSynonymGroup + *

+ * + * @return a + * {@link eu.etaxonomy.taxeditor.editor.name.container.HomotypicalSynonymGroup} + * object. */ public AcceptedGroup getAcceptedGroup() { return acceptedGroup; } - - /** * * @param acceptedGroup */ - public void setAcceptedGroup( - AcceptedGroup acceptedGroup) { + public void setAcceptedGroup(AcceptedGroup acceptedGroup) { this.acceptedGroup = acceptedGroup; } /** - *

Getter for the field misappliedGroup.

- * - * @return a {@link eu.etaxonomy.taxeditor.editor.name.container.MisappliedGroup} object. + *

+ * Getter for the field misappliedGroup. + *

+ * + * @return a + * {@link eu.etaxonomy.taxeditor.editor.name.container.MisappliedGroup} + * object. */ public MisappliedGroup getMisappliedGroup() { return misappliedGroup; @@ -721,18 +837,22 @@ public class TaxonNameEditor extends EditorPart implements IMultiPageTaxonEditor // TODO not very useful at the moment /** - *

isActive

- * + *

+ * isActive + *

+ * * @return a boolean. */ - public boolean isActive(){ + public boolean isActive() { IWorkbenchPart activePart = EditorUtil.getActivePart(); return editor.equals(activePart); } /** - *

onComplete

- * + *

+ * onComplete + *

+ * * @return a boolean. */ public boolean onComplete() { @@ -740,22 +860,18 @@ public class TaxonNameEditor extends EditorPart implements IMultiPageTaxonEditor return true; } - - /** {@inheritDoc} */ public void partChanged(Integer eventType, IWorkbenchPartReference partRef) { - if(! partRef.getPart(false).equals(editor)){ -// getSelectedObject().colorSelected(AbstractGroupedContainer.SELECTED_NO_FOCUS); + if (!partRef.getPart(false).equals(editor)) { + // getSelectedObject().colorSelected(AbstractGroupedContainer.SELECTED_NO_FOCUS); } } - - /** * @param retainedGroup */ public void removeGroup(AbstractGroup group) { - if(group != null){ + if (group != null) { group.dispose(); getHeterotypicSynonymGroups().remove(group); } @@ -767,8 +883,9 @@ public class TaxonNameEditor extends EditorPart implements IMultiPageTaxonEditor */ public AbstractGroupedContainer getContainer(TaxonBase taxonBase) { List groupedContainers = getGroupedContainers(); - for(AbstractGroupedContainer container : groupedContainers){ - if(container.getData().equals(taxonBase) && container.getNameViewer().getTextWidget() != null){ + for (AbstractGroupedContainer container : groupedContainers) { + if (container.getData().equals(taxonBase) + && container.getNameViewer().getTextWidget() != null) { return container; } } diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java index 36f2d5197..99ea66efd 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java @@ -1,12 +1,12 @@ // $Id$ /** -* 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. -*/ + * 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.model; @@ -57,311 +57,392 @@ import eu.etaxonomy.taxeditor.view.detail.DetailsViewPart; import eu.etaxonomy.taxeditor.view.supplementaldata.SupplementalDataViewPart; /** - *

Abstract AbstractUtility class.

- * + *

+ * Abstract AbstractUtility class. + *

+ * * @author n.hoffmann * @created 11.05.2009 * @version 1.0 */ public abstract class AbstractUtility { - + /** Constant statusLineManager */ protected static IStatusLineManager statusLineManager; - - + /** - *

closeAll

- * + *

+ * closeAll + *

+ * * @return a boolean. */ public static boolean closeAll() { return getActivePage().closeAllEditors(true); } - + /** * Close the given editor. - * - * @param editor The MultipageTaxonEditor to close. + * + * @param editor + * The MultipageTaxonEditor to close. * @return true on success */ public static boolean close(EditorPart editor) { return getActivePage().closeEditor(editor, true); } - + /** - *

getShell

- * + *

+ * getShell + *

+ * * @return a {@link org.eclipse.swt.widgets.Shell} object. */ public static Shell getShell() { - + return TaxeditorStorePlugin.getDefault().getWorkbench() .getActiveWorkbenchWindow().getShell(); } - + /** - *

getActivePage

- * + *

+ * getActivePage + *

+ * * @return a {@link org.eclipse.ui.IWorkbenchPage} object. */ - public static IWorkbenchPage getActivePage(){ - + public static IWorkbenchPage getActivePage() { + return TaxeditorStorePlugin.getDefault().getWorkbench() - .getActiveWorkbenchWindow().getActivePage(); + .getActiveWorkbenchWindow().getActivePage(); } - + /** - *

getActivePart

- * + *

+ * getActivePart + *

+ * * @return a {@link org.eclipse.ui.IWorkbenchPart} object. */ - public static IWorkbenchPart getActivePart(){ + public static IWorkbenchPart getActivePart() { return getActivePage() != null ? getActivePage().getActivePart() : null; } - - public static IWorkbench getWorkbench(){ + + public static IWorkbench getWorkbench() { return TaxeditorStorePlugin.getDefault().getWorkbench(); } - + /** - *

getWorkbenchWindow

- * + *

+ * getWorkbenchWindow + *

+ * * @return a {@link org.eclipse.jface.window.ApplicationWindow} object. */ - public static ApplicationWindow getWorkbenchWindow(){ - if(getWorkbench().getWorkbenchWindowCount() > 1){ + public static ApplicationWindow getWorkbenchWindow() { + if (getWorkbench().getWorkbenchWindowCount() > 1) { throw new IllegalStateException("More than one workbench window"); } return (ApplicationWindow) getWorkbench().getWorkbenchWindows()[0]; } - + /** - *

showView

- * - * @param id a {@link java.lang.String} object. + *

+ * showView + *

+ * + * @param id + * a {@link java.lang.String} object. * @return a {@link org.eclipse.ui.IViewPart} object. */ - public static IViewPart showView(String id){ + public static IViewPart showView(String id) { try { - return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(id, null, IWorkbenchPage.VIEW_VISIBLE); + return PlatformUI.getWorkbench().getActiveWorkbenchWindow() + .getActivePage() + .showView(id, null, IWorkbenchPage.VIEW_VISIBLE); } catch (PartInitException e) { error(AbstractUtility.class, "Could not open view: " + id, e); throw new RuntimeException(e); } } - + /** - *

hideView

- * - * @param view a {@link org.eclipse.ui.IViewPart} object. + *

+ * hideView + *

+ * + * @param view + * a {@link org.eclipse.ui.IViewPart} object. */ - public static void hideView(IViewPart view){ - PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(view); + public static void hideView(IViewPart view) { + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() + .hideView(view); } - - + /** - *

getView

- * - * @param id a {@link java.lang.String} object. - * @param restore a boolean. + *

+ * getView + *

+ * + * @param id + * a {@link java.lang.String} object. + * @param restore + * a boolean. * @return a {@link org.eclipse.ui.IViewPart} object. */ - public static IViewPart getView(String id, boolean restore){ - IViewReference[] references = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences(); - for (IViewReference reference : references){ - if(reference.getId().equals(id)){ + public static IViewPart getView(String id, boolean restore) { + IViewReference[] references = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow().getActivePage().getViewReferences(); + for (IViewReference reference : references) { + if (reference.getId().equals(id)) { return reference.getView(restore); } } return null; } - + /** - *

getService

- * - * @param api a {@link java.lang.Class} object. + *

+ * getService + *

+ * + * @param api + * a {@link java.lang.Class} object. * @return a {@link java.lang.Object} object. */ - public static Object getService(Class api){ + public static Object getService(Class api) { return TaxeditorStorePlugin.getDefault().getWorkbench().getService(api); } - + /** - *

getCurrentTheme

- * + *

+ * getCurrentTheme + *

+ * * @return a {@link org.eclipse.ui.themes.ITheme} object. */ - public static ITheme getCurrentTheme(){ - IThemeManager themeManager = TaxeditorStorePlugin.getDefault().getWorkbench().getThemeManager(); + public static ITheme getCurrentTheme() { + IThemeManager themeManager = TaxeditorStorePlugin.getDefault() + .getWorkbench().getThemeManager(); return themeManager.getCurrentTheme(); } - + /** - * Fonts registered to the plugin may be obtained with the Eclipse themeing functionality. - * Thus fonts are chooseable by the user via Preferences->General->Appearance->Colors and Fonts - * + * Fonts registered to the plugin may be obtained with the Eclipse themeing + * functionality. Thus fonts are chooseable by the user via + * Preferences->General->Appearance->Colors and Fonts + * * @return the FontRegistry for the current theme */ - public static FontRegistry getFontRegistry(){ + public static FontRegistry getFontRegistry() { return getCurrentTheme().getFontRegistry(); } - + /** - *

getFont

- * - * @param symbolicName a {@link java.lang.String} object. + *

+ * getFont + *

+ * + * @param symbolicName + * a {@link java.lang.String} object. * @return a {@link org.eclipse.swt.graphics.Font} object. */ - public static Font getFont(String symbolicName){ + public static Font getFont(String symbolicName) { return getFontRegistry().get(symbolicName); } - + /** - * Color registered to the plugin may be obtained with the Eclipse themeing functionality. - * Thus colors are editable by the user via Preferences->General->Appearance->Colors and Fonts - * + * Color registered to the plugin may be obtained with the Eclipse themeing + * functionality. Thus colors are editable by the user via + * Preferences->General->Appearance->Colors and Fonts + * * @return the ColorRegistry for the current theme */ - public static ColorRegistry getColorRegistry(){ + public static ColorRegistry getColorRegistry() { return getCurrentTheme().getColorRegistry(); } - + /** - *

getColor

- * - * @param symbolicName a {@link java.lang.String} object. + *

+ * getColor + *

+ * + * @param symbolicName + * a {@link java.lang.String} object. * @return a {@link org.eclipse.swt.graphics.Color} object. */ - public static Color getColor(String symbolicName){ + public static Color getColor(String symbolicName) { return getColorRegistry().get(symbolicName); } - + /** - * Open a message box that informs the user about unimplemented functionality. - * This method is for developer convenience. - * - * @param source a {@link java.lang.Object} object. + * Open a message box that informs the user about unimplemented + * functionality. This method is for developer convenience. + * + * @param source + * a {@link java.lang.Object} object. */ - public static void notImplementedMessage(Object source){ - warningDialog("Not yet implemented", source, "This functionality is not yet implemented."); + public static void notImplementedMessage(Object source) { + warningDialog("Not yet implemented", source, + "This functionality is not yet implemented."); } - + /** - *

informationDialog

- * - * @param title a {@link java.lang.String} object. - * @param message a {@link java.lang.String} object. - */ - public static void informationDialog(final String title, final String message){ - Display.getDefault().asyncExec(new Runnable(){ + *

+ * informationDialog + *

+ * + * @param title + * a {@link java.lang.String} object. + * @param message + * a {@link java.lang.String} object. + */ + public static void informationDialog(final String title, + final String message) { + Display.getDefault().asyncExec(new Runnable() { public void run() { MessageDialog.openInformation(getShell(), title, message); } }); } - + /** - *

warningDialog

- * - * @param title The dialogs title - * @param source The object where the warning was generated (used by log4j) - * @param message An informative String to be presented to the user - */ - public static void warningDialog(final String title, final Object source, final String message){ - Display.getDefault().asyncExec(new Runnable(){ + *

+ * warningDialog + *

+ * + * @param title + * The dialogs title + * @param source + * The object where the warning was generated (used by log4j) + * @param message + * An informative String to be presented to the user + */ + public static void warningDialog(final String title, final Object source, + final String message) { + Display.getDefault().asyncExec(new Runnable() { public void run() { MessageDialog.openWarning(getShell(), title, message); - Class clazz = source != null ? source.getClass() : AbstractUtility.class; + Class clazz = source != null ? source + .getClass() : AbstractUtility.class; warn(clazz, message); } }); } - + /** - *

errorDialog

- * - * @param title The dialogs title - * @param source The object where the warning was generated (used by log4j) - * @param message An informative String to be presented to the user - * @param title The dialogs title - * @param t a Throwable if one exists or null - */ - public static void errorDialog(final String title, final Object source, final String message, final Throwable t){ - Display.getDefault().asyncExec(new Runnable(){ + *

+ * errorDialog + *

+ * + * @param title + * The dialogs title + * @param source + * The object where the warning was generated (used by log4j) + * @param message + * An informative String to be presented to the user + * @param title + * The dialogs title + * @param t + * a Throwable if one exists or null + */ + public static void errorDialog(final String title, final Object source, + final String message, final Throwable t) { + Display.getDefault().asyncExec(new Runnable() { public void run() { MessageDialog.openError(getShell(), title, message); - Class clazz = source != null ? source.getClass() : this.getClass(); + Class clazz = source != null ? source + .getClass() : this.getClass(); error(clazz, message, t); } }); } - + /** - *

errorDialog

- * - * @param title a {@link java.lang.String} object. - * @param source a {@link java.lang.Object} object. - * @param status a {@link org.eclipse.core.runtime.IStatus} object. + *

+ * errorDialog + *

+ * + * @param title + * a {@link java.lang.String} object. + * @param source + * a {@link java.lang.Object} object. + * @param status + * a {@link org.eclipse.core.runtime.IStatus} object. */ - public static void errorDialog(final String title, final Object source, final IStatus status){ - Display.getDefault().asyncExec(new Runnable(){ + public static void errorDialog(final String title, final Object source, + final IStatus status) { + Display.getDefault().asyncExec(new Runnable() { public void run() { MessageDialog.openError(getShell(), title, status.getMessage()); - Class clazz = source != null ? source.getClass() : this.getClass(); + Class clazz = source != null ? source + .getClass() : this.getClass(); error(clazz, status.getMessage(), status.getException()); } }); } /** - *

confirmDialog

- * - * @param title a {@link java.lang.String} object. - * @param message a {@link java.lang.String} object. + *

+ * confirmDialog + *

+ * + * @param title + * a {@link java.lang.String} object. + * @param message + * a {@link java.lang.String} object. * @return a boolean. */ public static boolean confirmDialog(String title, String message) { return MessageDialog.openQuestion(getShell(), title, message); } - + /** - *

executeOperation

- * - * @param operation a {@link eu.etaxonomy.taxeditor.operation.AbstractPostOperation} object. + *

+ * executeOperation + *

+ * + * @param operation + * a + * {@link eu.etaxonomy.taxeditor.operation.AbstractPostOperation} + * object. * @return a {@link org.eclipse.core.runtime.IStatus} object. */ - public static IStatus executeOperation(final AbstractPostOperation operation){ - if(getOperationHistory() == null){ - throw new IllegalArgumentException("There is no operation history for this context"); + public static IStatus executeOperation(final AbstractPostOperation operation) { + if (getOperationHistory() == null) { + throw new IllegalArgumentException( + "There is no operation history for this context"); } - - final IAdaptable uiInfoAdapter = WorkspaceUndoUtil.getUIInfoAdapter(getShell()); - - - + + final IAdaptable uiInfoAdapter = WorkspaceUndoUtil + .getUIInfoAdapter(getShell()); + IRunnableWithProgress runnable = new IRunnableWithProgress() { - - public void run(IProgressMonitor monitor) throws InvocationTargetException, - InterruptedException { + + public void run(IProgressMonitor monitor) + throws InvocationTargetException, InterruptedException { monitor.beginTask(operation.getLabel(), 100); IStatus status; try { - status = getOperationHistory().execute(operation, monitor, uiInfoAdapter); + operation.addContext(IOperationHistory.GLOBAL_UNDO_CONTEXT); + status = getOperationHistory().execute(operation, monitor, + uiInfoAdapter); } catch (ExecutionException e) { throw new RuntimeException(e); } monitor.done(); - String statusString = status.equals(Status.OK_STATUS) ? "completed" : "cancelled"; + String statusString = status.equals(Status.OK_STATUS) ? "completed" + : "cancelled"; setStatusLine(operation.getLabel() + " " + statusString + "."); - + } }; - + try { runInUI(runnable, null); } catch (InvocationTargetException e) { @@ -369,118 +450,147 @@ public abstract class AbstractUtility { } catch (InterruptedException e) { throw new RuntimeException(e); } - -// // Start the main progress monitor. -// IProgressMonitor newMonitor = startMainMonitor(getMonitor(),operation.getLabel(), 100); -// -// // Check whether operation was canceled and do some steps. -// workedChecked(newMonitor, 10); -// -// try { -// IStatus status = getOperationHistory().execute(operation, newMonitor, -// WorkspaceUndoUtil.getUIInfoAdapter(getShell())); -// -// // Check whether operation was canceled and do some steps. -// workedChecked(newMonitor, 30); -// -// String statusString = status.equals(Status.OK_STATUS) ? "completed" : "cancelled"; -// setStatusLine(operation.getLabel() + " " + statusString + "."); -// -// return status; -// } catch (ExecutionException e) { -// logger.error("Error executing operation: " + operation.getLabel(), e); -// errorDialog("Error executing operation: " + operation.getLabel(), "Please refer to the error log."); -// } -// finally { -// -// // Stop the progress monitor. -// newMonitor.done(); -// } - - IPostOperationEnabled postOperationEnabled = operation.getPostOperationEnabled(); - if(postOperationEnabled != null){ + + // // Start the main progress monitor. + // IProgressMonitor newMonitor = + // startMainMonitor(getMonitor(),operation.getLabel(), 100); + // + // // Check whether operation was canceled and do some steps. + // workedChecked(newMonitor, 10); + // + // try { + // IStatus status = getOperationHistory().execute(operation, newMonitor, + // WorkspaceUndoUtil.getUIInfoAdapter(getShell())); + // + // // Check whether operation was canceled and do some steps. + // workedChecked(newMonitor, 30); + // + // String statusString = status.equals(Status.OK_STATUS) ? "completed" : + // "cancelled"; + // setStatusLine(operation.getLabel() + " " + statusString + "."); + // + // return status; + // } catch (ExecutionException e) { + // logger.error("Error executing operation: " + operation.getLabel(), + // e); + // errorDialog("Error executing operation: " + operation.getLabel(), + // "Please refer to the error log."); + // } + // finally { + // + // // Stop the progress monitor. + // newMonitor.done(); + // } + + IPostOperationEnabled postOperationEnabled = operation + .getPostOperationEnabled(); + if (postOperationEnabled != null) { postOperationEnabled.onComplete(); } return Status.OK_STATUS; } - + /** - *

getOperationHistory

- * - * @return a {@link org.eclipse.core.commands.operations.IOperationHistory} object. + *

+ * getOperationHistory + *

+ * + * @return a {@link org.eclipse.core.commands.operations.IOperationHistory} + * object. */ - public static IOperationHistory getOperationHistory(){ - return TaxeditorStorePlugin.getDefault().getWorkbench(). - getOperationSupport().getOperationHistory(); + public static IOperationHistory getOperationHistory() { + return getWorkbench().getOperationSupport().getOperationHistory(); } - + /** - *

setStatusLine

- * - * @param message a {@link java.lang.String} object. + *

+ * setStatusLine + *

+ * + * @param message + * a {@link java.lang.String} object. */ public static void setStatusLine(final String message) { - Display.getDefault().asyncExec(new Runnable(){ + Display.getDefault().asyncExec(new Runnable() { public void run() { statusLineManager.setMessage(message); } - + }); - + } - + /** - *

getMonitor

- * + *

+ * getMonitor + *

+ * * @return a {@link org.eclipse.core.runtime.IProgressMonitor} object. */ public static IProgressMonitor getMonitor() { statusLineManager.setCancelEnabled(false); return statusLineManager.getProgressMonitor(); } - - /** - * Starts either the given {@link IProgressMonitor} if it's not null or a new {@link NullProgressMonitor}. - * - * @param progressMonitor The {@link IProgressMonitor} or null if no progress should be reported. - * @param taskName The name of the main task. - * @param steps The number of steps this task is subdivided into. - * @return The {@link IProgressMonitor}. - */ - public static IProgressMonitor startMainMonitor(IProgressMonitor progressMonitor, String taskName, int steps) { - IProgressMonitor newMonitor = progressMonitor; - if (newMonitor == null) { - newMonitor = new NullProgressMonitor(); - } - newMonitor.beginTask(taskName == null ? "" : taskName, steps); - newMonitor.subTask(" "); - return newMonitor; - } - - /** - * Creates a {@link SubProgressMonitor} if the given {@link IProgressMonitor} is not null and not a {@link NullProgressMonitor}. - * - * @param progressMonitor The parent {@link IProgressMonitor} of the {@link SubProgressMonitor} to be created. - * @param ticks The number of steps this subtask is subdivided into. Must be a positive number and must not be {@link IProgressMonitor#UNKNOWN}. - * @return The {@link IProgressMonitor}. - */ - public static IProgressMonitor getSubProgressMonitor(IProgressMonitor progressMonitor, int ticks) { - if (progressMonitor == null) { - return new NullProgressMonitor(); - } - if (progressMonitor instanceof NullProgressMonitor) { - return progressMonitor; - } - - return new SubProgressMonitor(progressMonitor, ticks); - } - - /** - * Checks whether the user canceled this operation. If not canceled, the given number of steps are declared as done. - * - * @param newMonitor a {@link org.eclipse.core.runtime.IProgressMonitor} object. - * @param steps a int. + + /** + * Starts either the given {@link IProgressMonitor} if it's not + * null or a new {@link NullProgressMonitor}. + * + * @param progressMonitor + * The {@link IProgressMonitor} or null if no + * progress should be reported. + * @param taskName + * The name of the main task. + * @param steps + * The number of steps this task is subdivided into. + * @return The {@link IProgressMonitor}. + */ + public static IProgressMonitor startMainMonitor( + IProgressMonitor progressMonitor, String taskName, int steps) { + IProgressMonitor newMonitor = progressMonitor; + if (newMonitor == null) { + newMonitor = new NullProgressMonitor(); + } + newMonitor.beginTask(taskName == null ? "" : taskName, steps); + newMonitor.subTask(" "); + return newMonitor; + } + + /** + * Creates a {@link SubProgressMonitor} if the given + * {@link IProgressMonitor} is not null and not a + * {@link NullProgressMonitor}. + * + * @param progressMonitor + * The parent {@link IProgressMonitor} of the + * {@link SubProgressMonitor} to be created. + * @param ticks + * The number of steps this subtask is subdivided into. Must be a + * positive number and must not be + * {@link IProgressMonitor#UNKNOWN}. + * @return The {@link IProgressMonitor}. + */ + public static IProgressMonitor getSubProgressMonitor( + IProgressMonitor progressMonitor, int ticks) { + if (progressMonitor == null) { + return new NullProgressMonitor(); + } + if (progressMonitor instanceof NullProgressMonitor) { + return progressMonitor; + } + + return new SubProgressMonitor(progressMonitor, ticks); + } + + /** + * Checks whether the user canceled this operation. If not canceled, the + * given number of steps are declared as done. + * + * @param newMonitor + * a {@link org.eclipse.core.runtime.IProgressMonitor} object. + * @param steps + * a int. */ public static void workedChecked(IProgressMonitor newMonitor, int steps) { // In case the progress monitor was canceled throw an exception. @@ -493,197 +603,265 @@ public abstract class AbstractUtility { /** * Present a progress dialog to the user. This dialog will block the UI - * - * @param runnable an implementation of {@link IRunnableWithProgress} - * @throws java.lang.InterruptedException if any. - * @throws java.lang.reflect.InvocationTargetException if any. - */ - public static void busyCursorWhile(IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException{ + * + * @param runnable + * an implementation of {@link IRunnableWithProgress} + * @throws java.lang.InterruptedException + * if any. + * @throws java.lang.reflect.InvocationTargetException + * if any. + */ + public static void busyCursorWhile(IRunnableWithProgress runnable) + throws InvocationTargetException, InterruptedException { getProgressService().busyCursorWhile(runnable); } - + /** - *

runInUI

- * + *

+ * runInUI + *

+ * * @see {@link IProgressService#runInUI(org.eclipse.jface.operation.IRunnableContext, IRunnableWithProgress, ISchedulingRule)} - * @param runnable a {@link org.eclipse.jface.operation.IRunnableWithProgress} object. - * @param rule a {@link org.eclipse.core.runtime.jobs.ISchedulingRule} object. - * @throws java.lang.reflect.InvocationTargetException if any. - * @throws java.lang.InterruptedException if any. - */ - public static void runInUI(IRunnableWithProgress runnable, ISchedulingRule rule) throws InvocationTargetException, InterruptedException{ - getProgressService().runInUI(getWorkbenchWindow(), runnable, rule); + * @param runnable + * a {@link org.eclipse.jface.operation.IRunnableWithProgress} + * object. + * @param rule + * a {@link org.eclipse.core.runtime.jobs.ISchedulingRule} + * object. + * @throws java.lang.reflect.InvocationTargetException + * if any. + * @throws java.lang.InterruptedException + * if any. + */ + public static void runInUI(IRunnableWithProgress runnable, + ISchedulingRule rule) throws InvocationTargetException, + InterruptedException { + getProgressService().runInUI(getWorkbenchWindow(), runnable, rule); } - + /** - *

run

- * - * @param fork a boolean. - * @param cancelable a boolean. - * @param runnable a {@link org.eclipse.jface.operation.IRunnableWithProgress} object. - * @throws java.lang.reflect.InvocationTargetException if any. - * @throws java.lang.InterruptedException if any. - */ - public static void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException{ + *

+ * run + *

+ * + * @param fork + * a boolean. + * @param cancelable + * a boolean. + * @param runnable + * a {@link org.eclipse.jface.operation.IRunnableWithProgress} + * object. + * @throws java.lang.reflect.InvocationTargetException + * if any. + * @throws java.lang.InterruptedException + * if any. + */ + public static void run(boolean fork, boolean cancelable, + IRunnableWithProgress runnable) throws InvocationTargetException, + InterruptedException { getProgressService().run(fork, cancelable, runnable); } - + /** - *

getProgressService

- * + *

+ * getProgressService + *

+ * * @return a {@link org.eclipse.ui.progress.IProgressService} object. */ - public static IProgressService getProgressService(){ + public static IProgressService getProgressService() { IWorkbench workbench = PlatformUI.getWorkbench(); return workbench.getProgressService(); } - + /** - *

getProgressService2

- * - * @return a {@link org.eclipse.ui.progress.IWorkbenchSiteProgressService} object. + *

+ * getProgressService2 + *

+ * + * @return a {@link org.eclipse.ui.progress.IWorkbenchSiteProgressService} + * object. */ - public static IWorkbenchSiteProgressService getProgressService2(){ + public static IWorkbenchSiteProgressService getProgressService2() { return (IWorkbenchSiteProgressService) getService(IWorkbenchSiteProgressService.class); } - + /** - *

info

- * - * @param message a {@link java.lang.String} object. + *

+ * info + *

+ * + * @param message + * a {@link java.lang.String} object. */ - public static void info(String message){ + public static void info(String message) { IStatus status = new Status(IStatus.INFO, getPluginId(), message); info(status); } - + /** - *

info

- * - * @param status a {@link org.eclipse.core.runtime.IStatus} object. + *

+ * info + *

+ * + * @param status + * a {@link org.eclipse.core.runtime.IStatus} object. */ - public static void info(IStatus status){ + public static void info(IStatus status) { log(status); } - + /** - *

warn

- * - * @param source a {@link java.lang.Class} object. - * @param message a {@link java.lang.String} object. + *

+ * warn + *

+ * + * @param source + * a {@link java.lang.Class} object. + * @param message + * a {@link java.lang.String} object. */ - public static void warn(Class source, String message){ + public static void warn(Class source, String message) { IStatus status = new Status(IStatus.WARNING, getPluginId(), message); getLog4JLogger(source).warn(message); log(status); } - + /** - *

error

- * - * @param source a {@link java.lang.Class} object. - * @param t a {@link java.lang.Throwable} object. + *

+ * error + *

+ * + * @param source + * a {@link java.lang.Class} object. + * @param t + * a {@link java.lang.Throwable} object. */ - public static void error(Class source, Throwable t){ + public static void error(Class source, Throwable t) { error(source.getClass(), t.getMessage(), t); } - + /** - *

error

- * - * @param source a {@link java.lang.Class} object. - * @param message a {@link java.lang.String} object. - * @param t a {@link java.lang.Throwable} object. - */ - public static void error(Class source, String message, Throwable t){ + *

+ * error + *

+ * + * @param source + * a {@link java.lang.Class} object. + * @param message + * a {@link java.lang.String} object. + * @param t + * a {@link java.lang.Throwable} object. + */ + public static void error(Class source, String message, Throwable t) { IStatus status = new Status(IStatus.ERROR, getPluginId(), message, t); error(source, status); } - + /** - *

error

- * - * @param source a {@link java.lang.Class} object. - * @param status a {@link org.eclipse.core.runtime.IStatus} object. + *

+ * error + *

+ * + * @param source + * a {@link java.lang.Class} object. + * @param status + * a {@link org.eclipse.core.runtime.IStatus} object. */ - public static void error(Class source, IStatus status){ - getLog4JLogger(source).error(status.getMessage(), status.getException()); + public static void error(Class source, IStatus status) { + getLog4JLogger(source) + .error(status.getMessage(), status.getException()); log(status); } - /** - *

getLog4JLogger

- * - * @param clazz a {@link java.lang.Class} object. + *

+ * getLog4JLogger + *

+ * + * @param clazz + * a {@link java.lang.Class} object. * @return a {@link org.apache.log4j.Logger} object. */ - public static Logger getLog4JLogger( - Class clazz) { + public static Logger getLog4JLogger(Class clazz) { return Logger.getLogger(clazz); } - + /** * @see {@link ILog#log(IStatus)} * * @param status */ - private static void log(IStatus status){ + private static void log(IStatus status) { TaxeditorStorePlugin.getDefault().getLog().log(status); } - + /** - *

getPluginId

- * + *

+ * getPluginId + *

+ * * @return a {@link java.lang.String} object. */ - protected static String getPluginId(){ + protected static String getPluginId() { return "eu.taxeditor"; } - + /** - *

getActiveEditor

- * + *

+ * getActiveEditor + *

+ * * @return a {@link org.eclipse.ui.IEditorPart} object. */ - public static IEditorPart getActiveEditor(){ - return getActivePage() != null ? getActivePage().getActiveEditor() : null; + public static IEditorPart getActiveEditor() { + return getActivePage() != null ? getActivePage().getActiveEditor() + : null; } - + /** - *

getDetailsView

- * - * @return a {@link eu.etaxonomy.taxeditor.view.detail.DetailsViewPart} object. + *

+ * getDetailsView + *

+ * + * @return a {@link eu.etaxonomy.taxeditor.view.detail.DetailsViewPart} + * object. */ - public static DetailsViewPart getDetailsView(){ - return (DetailsViewPart) getView(DetailsViewPart.ID, false); + public static DetailsViewPart getDetailsView() { + return (DetailsViewPart) getView(DetailsViewPart.ID, false); } - + /** - *

refreshDetailsViewer

+ *

+ * refreshDetailsViewer + *

*/ - public static void refreshDetailsViewer(){ - if(getDetailsView() != null){ + public static void refreshDetailsViewer() { + if (getDetailsView() != null) { ((AbstractCdmDataViewer) getDetailsView().getViewer()).refresh(); } } - + /** - *

reflowDetailsViewer

+ *

+ * reflowDetailsViewer + *

*/ - public static void reflowDetailsViewer(){ - if(getDetailsView() != null){ + public static void reflowDetailsViewer() { + if (getDetailsView() != null) { ((AbstractCdmDataViewer) getDetailsView().getViewer()).reflow(); } } - - public static SupplementalDataViewPart getSupplementalDataView(){ - return (SupplementalDataViewPart) getView(SupplementalDataViewPart.ID, false); + + public static SupplementalDataViewPart getSupplementalDataView() { + return (SupplementalDataViewPart) getView(SupplementalDataViewPart.ID, + false); } - - public static void reflowSupplementalViewer(){ - if(getSupplementalDataView() != null){ - ((AbstractCdmDataViewer) getSupplementalDataView().getViewer()).reflow(); + + public static void reflowSupplementalViewer() { + if (getSupplementalDataView() != null) { + ((AbstractCdmDataViewer) getSupplementalDataView().getViewer()) + .reflow(); } } } -- 2.34.1