- used IPartContentHasXYZ interfaces for selectionChanged() in Supplemental- and DetailsViewPart
- formatted code
- fixed warnings
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* 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.
*/
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.taxeditor.editor.EditorUtil;
-import eu.etaxonomy.taxeditor.editor.OpenEditorConfiguration;
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
import eu.etaxonomy.taxeditor.model.AbstractUtility;
*/
public class NavigationUtil extends AbstractUtility{
private static IUndoContext defaultUndoContext;
-
+
/**
* <p>executeEditHandler</p>
*/
public static void executeEditHandler(){
String commandId = "eu.etaxonomy.taxeditor.navigation.command.editSelection";
-
- IHandlerService handlerService = (IHandlerService) NavigationUtil.getService(IHandlerService.class);
+
+ IHandlerService handlerService = (IHandlerService) AbstractUtility.getService(IHandlerService.class);
try {
handlerService.executeCommand(commandId, null);
} catch (ExecutionException e) {
- NavigationUtil.error(NavigationUtil.class, e);
+ AbstractUtility.error(NavigationUtil.class, e);
} catch (NotDefinedException e) {
- NavigationUtil.error(NavigationUtil.class, e);
+ AbstractUtility.error(NavigationUtil.class, e);
} catch (NotEnabledException e) {
- NavigationUtil.error(NavigationUtil.class, e);
+ AbstractUtility.error(NavigationUtil.class, e);
} catch (NotHandledException e) {
- NavigationUtil.error(NavigationUtil.class, e);
+ AbstractUtility.error(NavigationUtil.class, e);
}
}
-
+
/**
* <p>openEditor</p>
*
* @param selectedObject a {@link eu.etaxonomy.cdm.model.common.CdmBase} object.
*/
public static void openEditor(ICdmBase selectedObject){
- UUID entityUuid = selectedObject.getUuid();
- try {
+ UUID entityUuid = selectedObject.getUuid();
+ try {
if(selectedObject instanceof TaxonNode){
EditorUtil.openTaxonNode(entityUuid);
}else if(selectedObject instanceof TaxonBase){
warningDialog("Unsupported Type", NavigationUtil.class, "No editor exists for the current selection: " + selectedObject);
}
} catch (PartInitException e) {
- NavigationUtil.error(NavigationUtil.class, "Error opening the editor", e);
+ AbstractUtility.error(NavigationUtil.class, "Error opening the editor", e);
} catch (Exception e) {
- EditorUtil.warningDialog("Could not create Taxon", NavigationUtil.class, e.getMessage());
+ AbstractUtility.warningDialog("Could not create Taxon", NavigationUtil.class, e.getMessage());
}
}
-
+
public static void openEditor(Object selectedObject){
if (selectedObject instanceof UuidAndTitleCache){
Class type = ((UuidAndTitleCache) selectedObject).getType();
try {
EditorUtil.openTaxonBase(((UuidAndTitleCache) selectedObject).getUuid());
} catch (PartInitException e) {
- NavigationUtil.error(NavigationUtil.class, "Error opening the editor", e);
+ AbstractUtility.error(NavigationUtil.class, "Error opening the editor", e);
}
}
}else if(selectedObject instanceof ICdmBase){
- openEditor((ICdmBase) selectedObject);
+ openEditor((ICdmBase) selectedObject);
}else{
- NavigationUtil.error(NavigationUtil.class, new IllegalArgumentException("Selected object is not supported: " + selectedObject));
+ AbstractUtility.error(NavigationUtil.class, new IllegalArgumentException("Selected object is not supported: " + selectedObject));
}
}
-
+
/**
* <p>openEmpty</p>
*
try {
EditorUtil.openEmpty(parentNodeUuid);
} catch (PartInitException e) {
- NavigationUtil.error(NavigationUtil.class, "Error opening the editor", e);
+ AbstractUtility.error(NavigationUtil.class, "Error opening the editor", e);
}
}
-
+
/**
* <p>getShell</p>
*
return TaxeditorNavigationPlugin.getDefault().getWorkbench().
getActiveWorkbenchWindow();
}
-
+
/**
* <p>getWorkbenchUndoContext</p>
*
public static IUndoContext getUndoContext() {
// FIXME this has to be more specific. Every widget has to have its own undo context
// return IOperationHistory.GLOBAL_UNDO_CONTEXT;
-
- // Plug-ins that wish their operations to be undoable from workbench views
- // such as the Navigator or Package Explorer should assign the workbench
- // undo context to their operations.
+
+ // Plug-ins that wish their operations to be undoable from workbench views
+ // such as the Navigator or Package Explorer should assign the workbench
+ // undo context to their operations.
if (defaultUndoContext == null) {
defaultUndoContext = new UndoContext();
}
* @return a boolean.
*/
public static boolean isDirty(TaxonNode taxonNode){
-
+
for (IEditorReference reference : getActivePage().getEditorReferences()) {
-
+
try {
if (reference.getEditorInput() instanceof TaxonEditorInput) {
TaxonEditorInput editorInput = (TaxonEditorInput) reference.getEditorInput();
}
}
} catch (PartInitException e) {
- NavigationUtil.error(NavigationUtil.class, e.getMessage(), e);
+ AbstractUtility.error(NavigationUtil.class, e.getMessage(), e);
throw new RuntimeException(e);
}
-
+
}
return false;
}
public static void selectInNavigator(final Object element, final Object parentElement) {
Display.getDefault().asyncExec(new Runnable(){
- public void run() {
+ @Override
+ public void run() {
TaxonNavigator navigator = showNavigator();
if (navigator != null) {
if (parentElement != null) {
viewer.setExpandedState(parentElement, true);
}
- viewer.setSelection(new StructuredSelection((TaxonNode) element));
+ viewer.setSelection(new StructuredSelection(element));
}
}
}
-
+
});
}
public static void openSearch(Object selection) {
if(selection instanceof Taxon){
Taxon taxon = (Taxon) selection;
-
+
handleOpeningOfMultipleTaxonNodes(taxon.getTaxonNodes());
-
+
}else if(selection instanceof Synonym){
Synonym synonym = (Synonym) selection;
-
+
handleOpeningOfMultipleTaxa(synonym.getAcceptedTaxa());
-
+
}else{
warningDialog("Not implemented yet", NavigationUtil.class, "You chose to open a name that has no connection to a taxon. The Editor does not support editing of such a content type at the moment.");
}
-
+
}
private static void handleOpeningOfMultipleTaxa(Set<Taxon> acceptedTaxa) {
*/
private static void handleOpeningOfMultipleTaxonNodes(
Set<TaxonNode> taxonNodes) {
-
+
if(taxonNodes.size() == 1){
openEditor(taxonNodes.iterator().next());
}else if(taxonNodes.size() > 1){
// $Id$
/**
* Copyright (C) 2007 EDIT
- * European Distributed Institute of Taxonomy
+ * 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.
*/
import java.util.Set;
import java.util.UUID;
-import org.eclipse.core.commands.Command;
-import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IViewSite;
import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.commands.ICommandService;
-import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.navigator.CommonNavigator;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
/**
* Taxonomic tree implementation using Common Navigator Framework.
- *
+ *
* @author p.ciardelli
* @author n.hoffmann
* @created 02.06.2009
*/
public static final String ID = "eu.etaxonomy.taxeditor.navigation.navigator"; //$NON-NLS-1$
- /**
- * Constant
- * <code>OPEN_COMMAND_ID="eu.etaxonomy.taxeditor.navigation.comma"{trunked}</code>
- */
- public static final String OPEN_COMMAND_ID = "eu.etaxonomy.taxeditor.navigation.command.editSelection";
-
private static final String TREE_PATH = "treepath";
private static final String TREE_PATHS = "treepaths";
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.ui.navigator.CommonNavigator#getInitialInput()
*/
/** {@inheritDoc} */
*/
public void refresh() {
if(getConversationHolder() != null){
- getConversationHolder().bind();
+ getConversationHolder().bind();
}
getCommonViewer().refresh();
}
* <p>
* restore
* </p>
- *
+ *
* @param memento
* a {@link org.eclipse.ui.IMemento} object.
* @param monitor
List<CdmBase> pathList = new ArrayList<CdmBase>();
- if (string.length() == 0)
- return null;
+ if (string.length() == 0) {
+ return null;
+ }
for (String uuid : string.split(" ")) {
CdmBase cdmBaseObject = CdmStore.getService(
IClassificationService.class).load(
UUID.fromString(uuid));
- if (cdmBaseObject == null)
- return null;
+ if (cdmBaseObject == null) {
+ return null;
+ }
}
pathList.add(cdmBaseObject);
}
* <p>
* saveTreeState
* </p>
- *
+ *
* @param memento
* a {@link org.eclipse.ui.IMemento} object.
* @param progressMonitor
/*
* (non-Javadoc)
- *
+ *
* @see
* eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder
* ()
* <p>
* getConversationHolder
* </p>
- *
+ *
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
* object.
*/
/*
* (non-Javadoc)
- *
+ *
* @see
* eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update
* (eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.ui.part.WorkbenchPart#dispose()
*/
/** {@inheritDoc} */
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.ui.navigator.CommonNavigator#setFocus()
*/
/** {@inheritDoc} */
/*
* (non-Javadoc)
- *
+ *
* @see
* eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation
* (eu.etaxonomy.cdm.model.common.CdmBase)
* <p>
* save
* </p>
- *
+ *
* @param memento
* a {@link org.eclipse.ui.IMemento} object.
* @param monitor
/** {@inheritDoc} */
@Override
protected void handleDoubleClick(DoubleClickEvent anEvent) {
-
- ICommandService commandService = (ICommandService) getSite()
- .getService(ICommandService.class);
-
- Command command = commandService.getCommand(OPEN_COMMAND_ID);
- if (command.isEnabled()) {
- IHandlerService handlerService = (IHandlerService) getSite()
- .getService(IHandlerService.class);
- try {
- handlerService.executeCommand(OPEN_COMMAND_ID, null);
- } catch (NotDefinedException e) {
- throw new RuntimeException("Could not find open command: "
- + OPEN_COMMAND_ID);
- } catch (Exception e) {
- NavigationUtil
- .error(getClass(),
- "An exception occured while trying to open a selection",
- e);
- }
- }
+ NavigationUtil.executeEditHandler();
// If the double click is passed up to the super-class it will
// expand/collapse trees.
// We do not want that
* <p>
* onComplete
* </p>
- *
+ *
* @return a boolean.
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.ui.part.WorkbenchPart#showBusy(boolean)
*/
/** {@inheritDoc} */
if(o instanceof LoginManager){
refresh();
}
-
+
}
}
// $Id$
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* 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.
*/
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
/** {@inheritDoc} */
- public Object execute(ExecutionEvent event) throws ExecutionException {
-
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
ISelection selection = HandlerUtil.getCurrentSelection(event);
-
+
if(selection instanceof StructuredSelection){
final StructuredSelection structuredSelection = (StructuredSelection) selection;
-
+
if(structuredSelection.size() == 1 && structuredSelection.getFirstElement() instanceof Classification){
Classification classification = (Classification) structuredSelection.getFirstElement();
-
+
NewClassificationWizard classificationWizard = new NewClassificationWizard();
classificationWizard.init(null, null);
classificationWizard.setEntity(classification);
WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), classificationWizard);
dialog.open();
-
+
}
else{
Job job = new Job("Opening editor") {
-
+
@Override
protected IStatus run(IProgressMonitor monitor) {
for(final Object selectedObject : structuredSelection.toArray()){
-
+
Display.getDefault().asyncExec(new Runnable(){
-
- public void run() {
+
+ @Override
+ public void run() {
NavigationUtil.openEditor(selectedObject);
}
-
+
});
}
return Status.OK_STATUS;
}
};
-
+
job.schedule();
}
}
-
+
return null;
}
}
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* 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.
*/
import eu.etaxonomy.cdm.model.common.UuidAndTitleCache;
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
import eu.etaxonomy.taxeditor.model.ContextListenerAdapter;
import eu.etaxonomy.taxeditor.model.IContextListener;
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
* @version 1.0
*/
public class SearchResultView extends ViewPart implements IConversationEnabled{
-
+
private static Object[] EMPTY = new Object[0];
-
+
private class ContextListener extends ContextListenerAdapter{
/* (non-Javadoc)
* @see eu.etaxonomy.taxeditor.model.IContextListener#contextStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
@Override
public void contextStop(IMemento memento, IProgressMonitor monitor) {
monitor.subTask("Getting rid of search results");
- NavigationUtil.hideView(SearchResultView.this);
+ AbstractUtility.hideView(SearchResultView.this);
}
}
-
+
/** Constant <code>ID="eu.etaxonomy.taxeditor.navigation.searc"{trunked}</code> */
- public static final String ID =
+ public static final String ID =
"eu.etaxonomy.taxeditor.navigation.search.searchResultView"; //$NON-NLS-1$
private TableViewer resultViewer;
private Text status;
private SearchJob searchJob;
-
+
private IContextListener contextListener;
-
+
/* (non-Javadoc)
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
/** {@inheritDoc} */
@Override
public void createPartControl(Composite parent) {
-
+
conversation = CdmStore.createConversation();
contextListener = new ContextListener();
CdmStore.getContextManager().addContextListener(contextListener);
-
+
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
-
+
parent.setLayout(layout);
-
+
Composite infoComposite = createInfoComposite(parent);
infoComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
-
+
resultViewer = new TableViewer(parent, SWT.NONE);
resultViewer.setContentProvider(new ArrayContentProvider());
resultViewer.setLabelProvider(new SearchResultLabelProvider());
resultViewer.addDoubleClickListener(new IDoubleClickListener() {
- public void doubleClick(DoubleClickEvent event) {
+ @Override
+ public void doubleClick(DoubleClickEvent event) {
NavigationUtil.executeEditHandler();
}
});
-
+
resultViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-
+
getSite().setSelectionProvider(resultViewer);
-
+
// register context menu
MenuManager menuMgr = new MenuManager();
menuMgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
Control control = resultViewer.getControl();
Menu menu = menuMgr.createContextMenu(control);
- control.setMenu(menu);
+ control.setMenu(menu);
}
-
+
private Composite createInfoComposite(Composite parent){
Composite composite = new Composite(parent, SWT.NULL);
-
+
composite.setLayout(new GridLayout(2, false));
-
+
Label searchStringLabel = new Label(composite, SWT.NULL);
searchStringLabel.setText("Search String:");
-
+
searchString = new Text(composite, SWT.NULL);
searchString.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
searchString.setEditable(false);
// searchString.setText(" ");
-
+
Label configurationDescriptionLabel = new Label(composite, SWT.NULL);
configurationDescriptionLabel.setText("Search for:");
-
+
configurationLabel = new Text(composite, SWT.WRAP);
configurationLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
configurationLabel.setEditable(false);
-
+
Label statusLabel = new Label(composite, SWT.NULL);
statusLabel.setText("Status:");
-
+
status = new Text(composite, SWT.NULL);
status.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
status.setEditable(false);
-
+
return composite;
}
-
+
/**
* <p>performSearch</p>
*
*/
public void performSearch(IFindTaxaAndNamesConfigurator configurator){
setPartName("Search: '" + configurator.getTitleSearchString() + "'");
-
+
searchString.setText(configurator.getTitleSearchString());
-
+
List<String> includedEntities = new ArrayList<String>();
- if(configurator.isDoTaxa())
- includedEntities.add(SearchOption.TAXON.getLabel());
- if(configurator.isDoSynonyms())
- includedEntities.add(SearchOption.SYNONYM.getLabel());
- if(configurator.isDoNamesWithoutTaxa())
- includedEntities.add(SearchOption.NAME.getLabel());
+ if(configurator.isDoTaxa()) {
+ includedEntities.add(SearchOption.TAXON.getLabel());
+ }
+ if(configurator.isDoSynonyms()) {
+ includedEntities.add(SearchOption.SYNONYM.getLabel());
+ }
+ if(configurator.isDoNamesWithoutTaxa()) {
+ includedEntities.add(SearchOption.NAME.getLabel());
+ }
if(configurator.isDoTaxaByCommonNames()){
includedEntities.add(SearchOption.COMMON_NAME.getLabel());
}
-
+
String includedEntitiesString = "";
for (int i = 0; i < includedEntities.size(); i++){
includedEntitiesString += includedEntities.get(i);
includedEntitiesString += ", ";
}
}
-
+
configurationLabel.setText(includedEntitiesString);
-
+
status.setText("Searching...");
-
+
searchJob = new SearchJob(Display.getCurrent(), configurator);
searchJob.schedule();
-
+
}
-
+
/**
* <p>displaySearchResult</p>
*
*/
protected void displaySearchResult(List<UuidAndTitleCache<TaxonBase>> result) {
if(result.size() > 0){
- resultViewer.setInput(result);
+ resultViewer.setInput(result);
status.setText(result.size() + " entities found");
}else{
- resultViewer.setInput(EMPTY);
+ resultViewer.setInput(EMPTY);
status.setText("Search returned no results");
}
}
*
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
*/
- public ConversationHolder getConversationHolder() {
+ @Override
+ public ConversationHolder getConversationHolder() {
return this.conversation;
}
* @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
*/
/** {@inheritDoc} */
- public void update(CdmDataChangeMap changeEvents) {
+ @Override
+ public void update(CdmDataChangeMap changeEvents) {
// TODO Auto-generated method stub
-
+
}
-
+
/* (non-Javadoc)
* @see org.eclipse.ui.part.WorkbenchPart#dispose()
*/
public void dispose() {
super.dispose();
conversation.close();
- if(searchJob != null)
- searchJob.cancel();
+ if(searchJob != null) {
+ searchJob.cancel();
+ }
CdmStore.getContextManager().removeContextListener(contextListener);
}
-
+
/**
- *
+ *
* @author n.hoffmann
* @created Feb 2, 2010
* @version 1.0
*/
class SearchJob extends Job{
- private IFindTaxaAndNamesConfigurator configurator;
-
- private Display display;
-
+ private final IFindTaxaAndNamesConfigurator configurator;
+
+ private final Display display;
+
/**
* @param name
*/
protected IStatus run(IProgressMonitor monitor) {
monitor.beginTask("", 100);
monitor.worked(20);
-
+
final List<UuidAndTitleCache<TaxonBase>> searchResult = CdmStore.getSearchManager().findTaxaAndNames(configurator);
monitor.worked(40);
-
+
if(! monitor.isCanceled()){
display.asyncExec(new Runnable() {
- public void run() {
+ @Override
+ public void run() {
displaySearchResult(searchResult);
}
});
}else{
display.asyncExec(new Runnable() {
- public void run() {
+ @Override
+ public void run() {
status.setText("Cancelled");
}
});
monitor.done();
return Status.OK_STATUS;
}
-
- }
+
+ }
}