Project

General

Profile

« Previous | Next » 

Revision c886671b

Added by Cherian Mathew over 11 years ago

Updated Polytomous Key List Editor Component

  • added extra column for taxa
  • 'New' and 'Delete' both lead to error popups when no node is selected
  • 'New' menu click creates an empty node linked to the root node, when no nodes are present.

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyListEditor.java
66 66
		@Override
67 67
		public void mouseUp(MouseEvent event) {
68 68

  
69
			Table table = (Table) event.widget;
70
			// Determine where the mouse was clicked
71
			Point point = new Point(event.x, event.y);
72

  
73
			int selectedColumn = getSelectedColumn(table, point);
74

  
75
			if (selectedColumn == 3) {
76
				PolytomousKeyNode node = (PolytomousKeyNode) getTableItem(
77
						table, point).getData();
78
				Object linkData = getItemLinkData(node);
79
				if (linkData instanceof PolytomousKeyNode) {
80
					viewer.setSelection(new StructuredSelection(linkData), true);
81
				} else if (linkData instanceof Taxon) {
82
					try {
83
						EditorUtil.openTaxonBase(((Taxon) linkData).getUuid());
84
					} catch (PartInitException e) {
85
						EditorUtil.error(getClass(), e);
86
					}
87
				}
88
			}
89

  
69
		    if(event.button == 1 && event.count == 2) {
70
		        Table table = (Table) event.widget;
71
		        // Determine where the mouse was clicked
72
		        Point point = new Point(event.x, event.y);
73

  
74
		        int selectedColumn = getSelectedColumn(table, point);
75
		        PolytomousKeyNode node = (PolytomousKeyNode) getTableItem(
76
                        table, point).getData();
77
                
78
		        if (selectedColumn == 3) {		
79
		            PolytomousKeyNode linkData = getItemLinkData(node);
80
		            if (linkData != null) {
81
		                viewer.setSelection(new StructuredSelection(linkData), true);
82
		            } 
83
		        }
84
		        if (selectedColumn == 4) {
85
		            Taxon taxon = getItemTaxon(node);
86
		            if (taxon != null) {
87
		                try {
88
		                    EditorUtil.openTaxonBase((taxon).getUuid());
89
		                } catch (PartInitException e) {
90
		                    EditorUtil.error(getClass(), e);
91
		                }
92
		            }
93
		        }
94
		    }
90 95
		}
91 96

  
92 97
		private int getSelectedColumn(Table table, Point point) {
......
110 115
		/**
111 116
		 * @return
112 117
		 */
113
		private Object getItemLinkData(PolytomousKeyNode node) {
114
			return node.getChildren().isEmpty() ? node.getTaxon() : node
118
		private PolytomousKeyNode getItemLinkData(PolytomousKeyNode node) {
119
			return node.getChildren().isEmpty() ? null : node
115 120
					.getChildAt(0);
116 121
		}
122
		
123
	      /**
124
         * @return
125
         */
126
        private Taxon getItemTaxon(PolytomousKeyNode node) {
127
            return node.getTaxon();
128
        }
117 129
	}
118 130

  
119 131
	public static final String ID = "eu.etaxonomy.taxeditor.editor.key.polytomous.list";
......
239 251
		viewer.setInput(key);
240 252
	}
241 253

  
254
	public int getTableItemCount() {
255
	    if (viewer != null && viewer.getTable() != null) {
256
	        return viewer.getTable().getItemCount();
257
	    }
258
	    
259
	    return 0;
260
	}
261
	
262
	public PolytomousKey getViewerInputKey() {
263
	    return (PolytomousKey) viewer.getInput();
264
	}
242 265
	private void createMenu() {
243 266
		// register context menu
244 267
		MenuManager menuManager = new MenuManager();
......
254 277
	// This will create the columns for the table
255 278
	private void createColumns(TableViewer viewer) {
256 279
		Table table = viewer.getTable();
257
		String[] titles = { "Node Number", "Question", "Statement", "Link" };
258
		int[] bounds = { 50, 200, 200, 100 };
280
		String[] titles = { "Node Number", "Question", "Statement", "Link", "Taxon" };
281
		int[] bounds = { 50, 200, 200, 100, 200 };
259 282

  
260 283
		for (int i = 0; i < titles.length; i++) {
261 284
			TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
......
288 311
	 */
289 312
	@Override
290 313
	public void changed(Object element) {
291
		viewer.update(element, null);
314
	    if(element != null) {
315
	        viewer.update(element, null);
316
	    }
292 317

  
293 318
		if (element instanceof PolytomousKeyNode) {
294 319
			List<PolytomousKeyNode> children = ((PolytomousKeyNode) element)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyListLabelProvider.java
58 58
					columnIndex);
59 59
			cell.setText(text);
60 60

  
61
			if (columnIndex == 3) {
61
			if (columnIndex == 3 || columnIndex == 4) {
62 62
				StyledString styledString = new StyledString(text, getStyler());
63 63
				StyleRange[] styleRanges;
64 64
				styleRanges = styledString.getStyleRanges();
......
79 79
			return getItemStatement(node);
80 80
		case 3:
81 81
			return getItemLink(node);
82
		case 4:
83
            return getItemTaxon(node);
82 84
		}
83 85
		return EMPTY;
84 86
	}
......
137 139
	}
138 140

  
139 141
	private String getItemLink(PolytomousKeyNode node) {
140
		String taxonString = node.getTaxon() != null ? node.getTaxon()
141
				.getName().getTitleCache() : EMPTY;
142
		String linkString = node.getChildren().isEmpty() ? EMPTY : node.getNodeNumber().toString();
142 143

  
143
		return node.getChildren().isEmpty() ? taxonString : node
144
				.getNodeNumber().toString();
144
		return linkString;
145
	}
146
	
147
	private String getItemTaxon(PolytomousKeyNode node) {
148
	    String taxonString = node.getTaxon() != null ? node.getTaxon().getName().getTitleCache() : EMPTY;
149

  
150
	    return taxonString;
145 151
	}
146 152

  
147 153
	private PolytomousKeyNode getParent(PolytomousKeyNode node) {
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/handler/CreateNodeHandler.java
8 8
import org.eclipse.core.commands.ExecutionException;
9 9
import org.eclipse.core.commands.common.NotDefinedException;
10 10
import org.eclipse.core.commands.operations.IUndoContext;
11
import org.eclipse.jface.dialogs.MessageDialog;
11 12
import org.eclipse.jface.viewers.IStructuredSelection;
12 13
import org.eclipse.ui.IEditorPart;
13 14
import org.eclipse.ui.handlers.HandlerUtil;
14 15

  
16
import eu.etaxonomy.cdm.model.description.PolytomousKey;
15 17
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
16 18
import eu.etaxonomy.taxeditor.editor.EditorUtil;
17 19
import eu.etaxonomy.taxeditor.editor.key.KeyEditor;
18 20
import eu.etaxonomy.taxeditor.editor.key.polytomous.IPolytomousKeyEditorPage;
21
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyListEditor;
19 22
import eu.etaxonomy.taxeditor.editor.key.polytomous.operation.CreateNodeOperation;
20 23
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
21 24

  
......
35 38
	@Override
36 39
	public Object execute(ExecutionEvent event) throws ExecutionException {
37 40

  
38
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
41
	    IEditorPart editor = HandlerUtil.getActiveEditor(event);
39 42

  
40
		if (editor instanceof KeyEditor) {
41
			IPolytomousKeyEditorPage editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
42
					.getActiveEditor();
43
	    if (editor instanceof KeyEditor) {
44
	        IPolytomousKeyEditorPage editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
45
	                .getActiveEditor();
43 46

  
44
			IStructuredSelection selection = (IStructuredSelection) HandlerUtil
45
					.getCurrentSelection(event);
47
	        if (editorPage instanceof PolytomousKeyListEditor) {
48
	            PolytomousKeyListEditor klEditor = (PolytomousKeyListEditor) editorPage;
49
	            if(klEditor.getTableItemCount() == 0) {
50
	                PolytomousKey pk = (PolytomousKey)klEditor.getViewerInputKey();
51
	                try {
52
	                    String label = event.getCommand().getName();
53
	                    IUndoContext undoContext = EditorUtil.getUndoContext();
46 54

  
47
			if (selection.getFirstElement() instanceof PolytomousKeyNode) {
48
				try {
49
					String label = event.getCommand().getName();
50
					IUndoContext undoContext = EditorUtil.getUndoContext();
51 55

  
52
					PolytomousKeyNode keyNode = (PolytomousKeyNode) selection
53
							.getFirstElement();
56
	                    AbstractPostOperation operation = new CreateNodeOperation(
57
	                            label, undoContext, pk.getRoot(), editorPage);
58
	                    EditorUtil.executeOperation(operation);
59
	                } catch (NotDefinedException e) {
60
	                    EditorUtil.warn(getClass(), "Command name not set.");
61
	                }
62
	            } else {
54 63

  
55
					AbstractPostOperation operation = new CreateNodeOperation(
56
							label, undoContext, keyNode, editorPage);
57
					EditorUtil.executeOperation(operation);
58
				} catch (NotDefinedException e) {
59
					EditorUtil.warn(getClass(), "Command name not set.");
60
				}
64
	                IStructuredSelection selection = (IStructuredSelection) HandlerUtil
65
	                        .getCurrentSelection(event);
61 66

  
62
			}
63
		}
67
	                if (selection.getFirstElement() instanceof PolytomousKeyNode) {
68
	                    try {
69
	                        String label = event.getCommand().getName();
70
	                        IUndoContext undoContext = EditorUtil.getUndoContext();
71

  
72
	                        PolytomousKeyNode keyNode = (PolytomousKeyNode) selection
73
	                                .getFirstElement();
74

  
75
	                        AbstractPostOperation operation = new CreateNodeOperation(
76
	                                label, undoContext, keyNode, editorPage);
77
	                        EditorUtil.executeOperation(operation);
78
	                    } catch (NotDefinedException e) {
79
	                        EditorUtil.warn(getClass(), "Command name not set.");
80
	                    }
81
	                } else {
82
	                    MessageDialog.openInformation(
83
	                            EditorUtil.getShell(),
84
	                            "No Key Node Selected",
85
	                            "Please right-click on a specific key node to create a new child key node.");
86
	                }
87
	            }
88
	        }
89
	    }
64 90

  
65 91
		return null;
66 92
	}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/handler/DeleteNodeHandler.java
15 15
import org.eclipse.core.commands.ExecutionException;
16 16
import org.eclipse.core.commands.common.NotDefinedException;
17 17
import org.eclipse.core.commands.operations.IUndoContext;
18
import org.eclipse.jface.dialogs.MessageDialog;
18 19
import org.eclipse.jface.viewers.IStructuredSelection;
19 20
import org.eclipse.ui.IEditorPart;
20 21
import org.eclipse.ui.handlers.HandlerUtil;
......
67 68
				} catch (NotDefinedException e) {
68 69
					EditorUtil.warn(getClass(), "Command name not set.");
69 70
				}
70

  
71
			}
71
			} else {
72
	                MessageDialog.openInformation(
73
	                        EditorUtil.getShell(),
74
	                        "No Key Node Selected",
75
	                        "Please right-click on a specific key node to delete a key node.");	            
76
			}			
72 77
		}
73 78

  
74 79
		return null;

Also available in: Unified diff