@Override
public void mouseUp(MouseEvent event) {
- Table table = (Table) event.widget;
- // Determine where the mouse was clicked
- Point point = new Point(event.x, event.y);
-
- int selectedColumn = getSelectedColumn(table, point);
-
- if (selectedColumn == 3) {
- PolytomousKeyNode node = (PolytomousKeyNode) getTableItem(
- table, point).getData();
- Object linkData = getItemLinkData(node);
- if (linkData instanceof PolytomousKeyNode) {
- viewer.setSelection(new StructuredSelection(linkData), true);
- } else if (linkData instanceof Taxon) {
- try {
- EditorUtil.openTaxonBase(((Taxon) linkData).getUuid());
- } catch (PartInitException e) {
- EditorUtil.error(getClass(), e);
- }
- }
- }
-
+ if(event.button == 1 && event.count == 2) {
+ Table table = (Table) event.widget;
+ // Determine where the mouse was clicked
+ Point point = new Point(event.x, event.y);
+
+ int selectedColumn = getSelectedColumn(table, point);
+ PolytomousKeyNode node = (PolytomousKeyNode) getTableItem(
+ table, point).getData();
+
+ if (selectedColumn == 3) {
+ PolytomousKeyNode linkData = getItemLinkData(node);
+ if (linkData != null) {
+ viewer.setSelection(new StructuredSelection(linkData), true);
+ }
+ }
+ if (selectedColumn == 4) {
+ Taxon taxon = getItemTaxon(node);
+ if (taxon != null) {
+ try {
+ EditorUtil.openTaxonBase((taxon).getUuid());
+ } catch (PartInitException e) {
+ EditorUtil.error(getClass(), e);
+ }
+ }
+ }
+ }
}
private int getSelectedColumn(Table table, Point point) {
/**
* @return
*/
- private Object getItemLinkData(PolytomousKeyNode node) {
- return node.getChildren().isEmpty() ? node.getTaxon() : node
+ private PolytomousKeyNode getItemLinkData(PolytomousKeyNode node) {
+ return node.getChildren().isEmpty() ? null : node
.getChildAt(0);
}
+
+ /**
+ * @return
+ */
+ private Taxon getItemTaxon(PolytomousKeyNode node) {
+ return node.getTaxon();
+ }
}
public static final String ID = "eu.etaxonomy.taxeditor.editor.key.polytomous.list";
viewer.setInput(key);
}
+ public int getTableItemCount() {
+ if (viewer != null && viewer.getTable() != null) {
+ return viewer.getTable().getItemCount();
+ }
+
+ return 0;
+ }
+
+ public PolytomousKey getViewerInputKey() {
+ return (PolytomousKey) viewer.getInput();
+ }
private void createMenu() {
// register context menu
MenuManager menuManager = new MenuManager();
// This will create the columns for the table
private void createColumns(TableViewer viewer) {
Table table = viewer.getTable();
- String[] titles = { "Node Number", "Question", "Statement", "Link" };
- int[] bounds = { 50, 200, 200, 100 };
+ String[] titles = { "Node Number", "Question", "Statement", "Link", "Taxon" };
+ int[] bounds = { 50, 200, 200, 100, 200 };
for (int i = 0; i < titles.length; i++) {
TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
*/
@Override
public void changed(Object element) {
- viewer.update(element, null);
+ if(element != null) {
+ viewer.update(element, null);
+ }
if (element instanceof PolytomousKeyNode) {
List<PolytomousKeyNode> children = ((PolytomousKeyNode) element)
columnIndex);
cell.setText(text);
- if (columnIndex == 3) {
+ if (columnIndex == 3 || columnIndex == 4) {
StyledString styledString = new StyledString(text, getStyler());
StyleRange[] styleRanges;
styleRanges = styledString.getStyleRanges();
return getItemStatement(node);
case 3:
return getItemLink(node);
+ case 4:
+ return getItemTaxon(node);
}
return EMPTY;
}
}
private String getItemLink(PolytomousKeyNode node) {
- String taxonString = node.getTaxon() != null ? node.getTaxon()
- .getName().getTitleCache() : EMPTY;
+ String linkString = node.getChildren().isEmpty() ? EMPTY : node.getNodeNumber().toString();
- return node.getChildren().isEmpty() ? taxonString : node
- .getNodeNumber().toString();
+ return linkString;
+ }
+
+ private String getItemTaxon(PolytomousKeyNode node) {
+ String taxonString = node.getTaxon() != null ? node.getTaxon().getName().getTitleCache() : EMPTY;
+
+ return taxonString;
}
private PolytomousKeyNode getParent(PolytomousKeyNode node) {
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.core.commands.operations.IUndoContext;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.handlers.HandlerUtil;
+import eu.etaxonomy.cdm.model.description.PolytomousKey;
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
import eu.etaxonomy.taxeditor.editor.EditorUtil;
import eu.etaxonomy.taxeditor.editor.key.KeyEditor;
import eu.etaxonomy.taxeditor.editor.key.polytomous.IPolytomousKeyEditorPage;
+import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyListEditor;
import eu.etaxonomy.taxeditor.editor.key.polytomous.operation.CreateNodeOperation;
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
- IEditorPart editor = HandlerUtil.getActiveEditor(event);
+ IEditorPart editor = HandlerUtil.getActiveEditor(event);
- if (editor instanceof KeyEditor) {
- IPolytomousKeyEditorPage editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
- .getActiveEditor();
+ if (editor instanceof KeyEditor) {
+ IPolytomousKeyEditorPage editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
+ .getActiveEditor();
- IStructuredSelection selection = (IStructuredSelection) HandlerUtil
- .getCurrentSelection(event);
+ if (editorPage instanceof PolytomousKeyListEditor) {
+ PolytomousKeyListEditor klEditor = (PolytomousKeyListEditor) editorPage;
+ if(klEditor.getTableItemCount() == 0) {
+ PolytomousKey pk = (PolytomousKey)klEditor.getViewerInputKey();
+ try {
+ String label = event.getCommand().getName();
+ IUndoContext undoContext = EditorUtil.getUndoContext();
- if (selection.getFirstElement() instanceof PolytomousKeyNode) {
- try {
- String label = event.getCommand().getName();
- IUndoContext undoContext = EditorUtil.getUndoContext();
- PolytomousKeyNode keyNode = (PolytomousKeyNode) selection
- .getFirstElement();
+ AbstractPostOperation operation = new CreateNodeOperation(
+ label, undoContext, pk.getRoot(), editorPage);
+ EditorUtil.executeOperation(operation);
+ } catch (NotDefinedException e) {
+ EditorUtil.warn(getClass(), "Command name not set.");
+ }
+ } else {
- AbstractPostOperation operation = new CreateNodeOperation(
- label, undoContext, keyNode, editorPage);
- EditorUtil.executeOperation(operation);
- } catch (NotDefinedException e) {
- EditorUtil.warn(getClass(), "Command name not set.");
- }
+ IStructuredSelection selection = (IStructuredSelection) HandlerUtil
+ .getCurrentSelection(event);
- }
- }
+ if (selection.getFirstElement() instanceof PolytomousKeyNode) {
+ try {
+ String label = event.getCommand().getName();
+ IUndoContext undoContext = EditorUtil.getUndoContext();
+
+ PolytomousKeyNode keyNode = (PolytomousKeyNode) selection
+ .getFirstElement();
+
+ AbstractPostOperation operation = new CreateNodeOperation(
+ label, undoContext, keyNode, editorPage);
+ EditorUtil.executeOperation(operation);
+ } catch (NotDefinedException e) {
+ EditorUtil.warn(getClass(), "Command name not set.");
+ }
+ } else {
+ MessageDialog.openInformation(
+ EditorUtil.getShell(),
+ "No Key Node Selected",
+ "Please right-click on a specific key node to create a new child key node.");
+ }
+ }
+ }
+ }
return null;
}
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.core.commands.operations.IUndoContext;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.handlers.HandlerUtil;
} catch (NotDefinedException e) {
EditorUtil.warn(getClass(), "Command name not set.");
}
-
- }
+ } else {
+ MessageDialog.openInformation(
+ EditorUtil.getShell(),
+ "No Key Node Selected",
+ "Please right-click on a specific key node to delete a key node.");
+ }
}
return null;