package eu.etaxonomy.taxeditor.editor.handler;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
if(currentSelection instanceof IStructuredSelection){
- Object selectedElement = ((IStructuredSelection) currentSelection).getFirstElement();
- if(selectedElement instanceof SpecimenOrObservationBase<?>){
-
- DerivateViewEditorInput input = new DerivateViewEditorInput(((SpecimenOrObservationBase<?>) selectedElement).getUuid());
- try {
- EditorUtil.open(input);
- } catch (PartInitException e) {
- MessagingUtils.error(OpenDerivateViewHandler.class, "Could not open DerivateView", e);
- } catch (NullPointerException npe){
- MessagingUtils.messageDialog("Failed to open Editor", OpenDerivateViewHandler.class, "Could not open DerivateView. The derivate hierarchy is corrupted!", npe);
+ Iterator<?> selectionIterator = ((IStructuredSelection) currentSelection).iterator();
+ Set<UUID> selectedElementUUIDs = new HashSet<UUID>();
+ while(selectionIterator.hasNext()){
+ Object object = selectionIterator.next();
+ if(object instanceof SpecimenOrObservationBase<?>){
+ selectedElementUUIDs.add(((SpecimenOrObservationBase<?>) object).getUuid());
}
}
+ DerivateViewEditorInput input = new DerivateViewEditorInput(selectedElementUUIDs);
+ try {
+ EditorUtil.open(input);
+ } catch (PartInitException e) {
+ MessagingUtils.error(OpenDerivateViewHandler.class, "Could not open DerivateView", e);
+ } catch (NullPointerException npe){
+ MessagingUtils.messageDialog("Failed to open Editor", OpenDerivateViewHandler.class, "Could not open DerivateView. The derivate hierarchy is corrupted!", npe);
+ }
}
return null;
}
package eu.etaxonomy.taxeditor.editor.view.derivate;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
+import java.util.UUID;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TreeNode;
@Override
public Object[] getElements(Object inputElement) {
- SpecimenOrObservationBase<?> rootElement = null;
+ List<TreeNode> rootElements = new ArrayList<TreeNode>();
if(inputElement instanceof DerivateViewEditorInput){
- rootElement = CdmStore.getService(IOccurrenceService.class).load(((DerivateViewEditorInput) inputElement).getRootElementUUID());
- }
-
- if(rootElement!=null){
- //show topmost element in the derivate hierarchy if no field unit was found
- TreeNode node = new TreeNode(rootElement);
- return Collections.singleton(node).toArray();
+ Set<UUID> rootUUIDs = ((DerivateViewEditorInput) inputElement).getRootUUIDs();
+ for (UUID uuid : rootUUIDs) {
+ SpecimenOrObservationBase<?> rootElement = CdmStore.getService(IOccurrenceService.class).load(uuid);
+ if(rootElement!=null){
+ rootElements.add(new TreeNode(rootElement));
+ }
+ }
}
- return null;
+ return rootElements.toArray();
}
@Override
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.Set;
+import java.util.UUID;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.MenuManager;
labelProvider.setMultiLinkSingleReads(multiLinkSingleReads);
IEditorInput editorInput = getEditorInput();
viewer.setInput(editorInput);
+ //set selection to selected derivate if only one was selected
if(editorInput instanceof DerivateViewEditorInput){
- SpecimenOrObservationBase<?> specimen = CdmStore.getService(IOccurrenceService.class).load(((DerivateViewEditorInput) editorInput).getDerivateUUID());
- SpecimenOrObservationBase<?> rootElement = CdmStore.getService(IOccurrenceService.class).load(((DerivateViewEditorInput) editorInput).getRootElementUUID());
- setPartName(labelProvider.getDerivateText(rootElement));
- viewer.setSelection(new StructuredSelection(new TreeNode(specimen)));
+ Set<UUID> derivateUUIDs = ((DerivateViewEditorInput) editorInput).getDerivateUUIDs();
+ if(derivateUUIDs.size()==1){
+ SpecimenOrObservationBase<?> specimen = CdmStore.getService(IOccurrenceService.class).load(derivateUUIDs.iterator().next());
+ viewer.setSelection(new StructuredSelection(new TreeNode(specimen)));
+ }
}
//add drag'n'drop support
*/
@Override
public String getTitleToolTip() {
+ if(getEditorInput() instanceof DerivateViewEditorInput){
+ DerivateViewEditorInput derivateViewEditorInput = (DerivateViewEditorInput) getEditorInput();
+ return derivateViewEditorInput.getName();
+ }
return "Derivate View";
}
setSite(site);
setInput(input);
if(input instanceof DerivateViewEditorInput){
- conversation = ((DerivateViewEditorInput) input).getConversationHolder();
+ DerivateViewEditorInput derivateViewEditorInput = (DerivateViewEditorInput) input;
+ conversation = derivateViewEditorInput.getConversationHolder();
+ setPartName(derivateViewEditorInput.getName());
}
}
public boolean postOperation(CdmBase objectAffectedByOperation) {
refreshTree();
if(objectAffectedByOperation!=null){
- DerivateViewEditorInput derivateViewEditorInput = (DerivateViewEditorInput) getEditorInput();
- if(objectAffectedByOperation.getUuid().equals(derivateViewEditorInput.getRootElementUUID())){
- // TODO close derivate view if root element is deleted
-// this.getViewer().setEditorSite().getPage().close();
- return true;
- }
- else if(objectAffectedByOperation.getUuid().equals(derivateViewEditorInput.getDerivateUUID())){
- derivateViewEditorInput.setRootAsDerivate();
- }
changed(objectAffectedByOperation);
return true;
}
*/
package eu.etaxonomy.taxeditor.editor.view.derivate;
+import java.util.HashSet;
+import java.util.Set;
import java.util.UUID;
import org.eclipse.jface.resource.ImageDescriptor;
import eu.etaxonomy.taxeditor.editor.EditorUtil;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
/**
* Editor input for the {@link DerivateView} which holds the currently selected derivate for which
public class DerivateViewEditorInput implements IEditorInput{
/**
- * The selected derivate {@link UUID}
+ * The selected derivate {@link UUID}s
*/
- private UUID derivateUUID;
+ private Set<UUID> derivateUUIDs;
/**
- * The {@link UUID} of the root of the hierarchy (may be the same object as the derivate)
+ * List of the {@link UUID}s of the root elements of the hierarchy (may be the same objects as the derivates)
*/
- private UUID rootUUID;
+ private Set<UUID> rootUUIDs;
private final ConversationHolder conversationHolder;
/**
- * Creates an editor input for the {@link DerivateView} with the currently selected derivate and the
- * corresponding {@link FieldUnit} (both may be the same object).
- * @param derivateUuid the {@link UUID} of the derivate for which the derivate hierarchy should be shown
- * @param rootUUID the root of the hierarchy
+ * Creates an editor input for the {@link DerivateView} with the currently selected derivates and the
+ * corresponding {@link FieldUnit}s (both may be the same object).
+ * @param derivateUuids the {@link UUID}s of the derivates for which the derivate hierarchy should be shown
+ * @param rootUUIDs the root of the hierarchy
*/
- public DerivateViewEditorInput(UUID derivateUuid) {
+ public DerivateViewEditorInput(Set<UUID> derivateUuids) {
super();
this.conversationHolder = CdmStore.createConversation();
- this.derivateUUID = derivateUuid;
- SpecimenOrObservationBase<?> derivate = CdmStore.getService(IOccurrenceService.class).load(derivateUuid);
- if(derivate instanceof FieldUnit){
- this.rootUUID = derivateUUID;
- }
- else if(derivate instanceof DerivedUnit){
- SpecimenOrObservationBase<?> topMostDerivate = EditorUtil.getTopMostDerivate(derivate);
- rootUUID = topMostDerivate==null?null:topMostDerivate.getUuid();
- if(rootUUID==null){
- rootUUID = derivateUUID;
+ this.derivateUUIDs = derivateUuids;
+ this.rootUUIDs = new HashSet<UUID>();
+ for (UUID uuid : derivateUuids) {
+ SpecimenOrObservationBase<?> derivate = CdmStore.getService(IOccurrenceService.class).load(uuid);
+ if(derivate instanceof FieldUnit){
+ rootUUIDs.add(uuid);
+ }
+ else if(derivate instanceof DerivedUnit){
+ SpecimenOrObservationBase<?> topMostDerivate = EditorUtil.getTopMostDerivate(derivate);
+ if(topMostDerivate!=null){
+ rootUUIDs.add(topMostDerivate.getUuid());
+ }
}
}
- if(rootUUID==null){
+ if(rootUUIDs.isEmpty()){
+ rootUUIDs = derivateUUIDs;
+ }
+ if(rootUUIDs.isEmpty()){
MessagingUtils.messageDialog("Failed initializing editor", DerivateViewEditorInput.class, "No root element found!");
}
}
*/
@Override
public String getName() {
- return derivateUUID.toString();
+ return getEditorName();
}
/* (non-Javadoc)
*/
@Override
public String getToolTipText() {
- return derivateUUID.toString();
+ return getEditorName();
+ }
+
+ private String getEditorName() {
+ String name = null;
+ //FIXME consider giving label provider a static method to get the derivate text. Pass the conversation as a method parameter.
+ DerivateLabelProvider labelProvider = new DerivateLabelProvider();
+ labelProvider.setConversation(conversationHolder);
+ for(UUID uuid:rootUUIDs){
+ SpecimenOrObservationBase specimen = CdmStore.getService(IOccurrenceService.class).load(uuid);
+ if(specimen!=null){
+ if(name==null){
+ name = labelProvider.getDerivateText(specimen);
+ }
+ else{
+ name += ", "+labelProvider.getDerivateText(specimen);
+ }
+ }
+ }
+ return name;
}
- public UUID getDerivateUUID() {
- return derivateUUID;
+ public Set<UUID> getRootUUIDs() {
+ return rootUUIDs;
}
- public UUID getRootElementUUID() {
- return rootUUID;
+ public Set<UUID> getDerivateUUIDs() {
+ return derivateUUIDs;
}
public void setRootAsDerivate(){
- this.derivateUUID = this.rootUUID;
+ this.derivateUUIDs = this.rootUUIDs;
}
public ConversationHolder getConversationHolder() {
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((rootUUID == null) ? 0 : rootUUID.hashCode());
+ result = prime * result + ((rootUUIDs == null) ? 0 : rootUUIDs.hashCode());
return result;
}
return false;
}
DerivateViewEditorInput other = (DerivateViewEditorInput) obj;
- if (rootUUID == null) {
- if (other.rootUUID != null) {
+ if (rootUUIDs == null) {
+ if (other.rootUUIDs != null) {
return false;
}
- } else if (!rootUUID.equals(other.rootUUID)) {
+ } else if (!rootUUIDs.equals(other.rootUUIDs)) {
return false;
}
return true;
}
+
}
</visibleWhen>
</command>
</menuContribution>
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:eu.etaxonomy.taxeditor.view.derivateSearch.DerivateSearchView">
+ <command
+ commandId="eu.etaxonomy.taxeditor.editor.handler.openDerivateView"
+ label="Open in Derivate Editor"
+ style="push">
+ </command>
+ </menuContribution>
</extension>
<extension
point="org.eclipse.ui.handlers">
</activeWhen>
</handler>
</extension>
- <extension
- point="org.eclipse.ui.commands">
- <command
- defaultHandler="eu.etaxonomy.taxeditor.view.datasource.handler.ChangeConnectionHandler"
- id="eu.etaxonomy.taxeditor.datasource.connect"
- name="Connect">
- </command>
- </extension>
<extension
name="Popup Menu Commands"
point="org.eclipse.ui.commands">
id="eu.etaxonomy.taxeditor.store.open.OpenDistributionEditorWizardHandler"
name="Open Distribution Editor Wizard">
</command>
+ <command
+ defaultHandler="eu.etaxonomy.taxeditor.view.datasource.handler.ChangeConnectionHandler"
+ id="eu.etaxonomy.taxeditor.datasource.connect"
+ name="Connect">
+ </command>
</extension>
<extension
point="org.eclipse.ui.importWizards">
new Label(this, SWT.NONE);
new Label(this, SWT.NONE);
- resultViewer = new TableViewer(this, SWT.BORDER | SWT.FULL_SELECTION);
+ resultViewer = new TableViewer(this, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
table = resultViewer.getTable();
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 6, 4));
package eu.etaxonomy.taxeditor.view.derivateSearch;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.action.MenuManager;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.part.ViewPart;
derivateSearchCompositeController = new DerivateSearchCompositeController(parent, this);
getSite().setSelectionProvider(derivateSearchCompositeController.getResultViewer());
derivateSearchCompositeController.setEnabled(CdmStore.isActive());
+
+ //create context menu
+ MenuManager menuManager = new MenuManager();
+ getSite().registerContextMenu(menuManager, derivateSearchCompositeController.getResultViewer());
+ Control control = derivateSearchCompositeController.getResultViewer().getControl();
+ Menu menu = menuManager.createContextMenu(control);
+ control.setMenu(menu);
}
/* (non-Javadoc)