Revision 340162f2
Added by Niels Hoffmann almost 13 years ago
eu.etaxonomy.taxeditor.editor/plugin.xml | ||
---|---|---|
525 | 525 |
style="push"> |
526 | 526 |
</command> |
527 | 527 |
</menuContribution> |
528 |
<menuContribution |
|
529 |
locationURI="popup:eu.etaxonomy.taxeditor.editor.key.polytomous.list"> |
|
530 |
<command |
|
531 |
commandId="eu.etaxonomy.taxeditor.key.polytomous.command.new" |
|
532 |
label="New" |
|
533 |
style="push"> |
|
534 |
</command> |
|
535 |
<command |
|
536 |
commandId="org.eclipse.ui.edit.delete" |
|
537 |
label="Delete" |
|
538 |
style="push"> |
|
539 |
</command> |
|
540 |
</menuContribution> |
|
528 | 541 |
</extension> |
529 | 542 |
<extension |
530 | 543 |
point="org.eclipse.ui.handlers"> |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/AbstractIdentificationEditorInput.java | ||
---|---|---|
14 | 14 |
|
15 | 15 |
/** |
16 | 16 |
* @author n.hoffmann |
17 |
* |
|
17 |
*
|
|
18 | 18 |
*/ |
19 |
public abstract class AbstractIdentificationEditorInput<T extends IIdentificationKey> implements IEditorInput, IConversationEnabled { |
|
19 |
public abstract class AbstractIdentificationEditorInput<T extends IIdentificationKey> |
|
20 |
implements IEditorInput, IConversationEnabled { |
|
20 | 21 |
|
21 |
private ConversationHolder conversation; |
|
22 |
private final ConversationHolder conversation;
|
|
22 | 23 |
|
23 |
protected AbstractIdentificationEditorInput(ConversationHolder conversation){ |
|
24 |
protected AbstractIdentificationEditorInput(ConversationHolder conversation) {
|
|
24 | 25 |
this.conversation = conversation; |
25 | 26 |
} |
26 |
|
|
27 |
/* (non-Javadoc) |
|
27 |
|
|
28 |
/* |
|
29 |
* (non-Javadoc) |
|
30 |
* |
|
28 | 31 |
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) |
29 | 32 |
*/ |
30 | 33 |
@Override |
... | ... | |
33 | 36 |
return null; |
34 | 37 |
} |
35 | 38 |
|
36 |
/* (non-Javadoc) |
|
39 |
/* |
|
40 |
* (non-Javadoc) |
|
41 |
* |
|
37 | 42 |
* @see org.eclipse.ui.IEditorInput#exists() |
38 | 43 |
*/ |
39 | 44 |
@Override |
... | ... | |
41 | 46 |
return getKey() != null; |
42 | 47 |
} |
43 | 48 |
|
44 |
/* (non-Javadoc) |
|
49 |
/* |
|
50 |
* (non-Javadoc) |
|
51 |
* |
|
45 | 52 |
* @see org.eclipse.ui.IEditorInput#getImageDescriptor() |
46 | 53 |
*/ |
47 | 54 |
@Override |
... | ... | |
50 | 57 |
return null; |
51 | 58 |
} |
52 | 59 |
|
53 |
/* (non-Javadoc) |
|
60 |
/* |
|
61 |
* (non-Javadoc) |
|
62 |
* |
|
54 | 63 |
* @see org.eclipse.ui.IEditorInput#getPersistable() |
55 | 64 |
*/ |
56 | 65 |
@Override |
... | ... | |
59 | 68 |
return null; |
60 | 69 |
} |
61 | 70 |
|
62 |
/* (non-Javadoc) |
|
71 |
/* |
|
72 |
* (non-Javadoc) |
|
73 |
* |
|
63 | 74 |
* @see org.eclipse.ui.IEditorInput#getToolTipText() |
64 | 75 |
*/ |
65 | 76 |
@Override |
66 | 77 |
public String getToolTipText() { |
67 | 78 |
return getName(); |
68 | 79 |
} |
69 |
|
|
80 |
|
|
81 |
/* |
|
82 |
* (non-Javadoc) |
|
83 |
* |
|
84 |
* @see org.eclipse.ui.IEditorInput#getName() |
|
85 |
*/ |
|
86 |
@Override |
|
87 |
public String getName() { |
|
88 |
return getKey().toString(); |
|
89 |
} |
|
90 |
|
|
70 | 91 |
@Override |
71 | 92 |
public ConversationHolder getConversationHolder() { |
72 | 93 |
return conversation; |
73 | 94 |
} |
74 | 95 |
|
75 | 96 |
public abstract T getKey(); |
76 |
|
|
97 |
|
|
77 | 98 |
@Override |
78 |
public void update(CdmDataChangeMap changeEvents) {} |
|
79 |
|
|
99 |
public void update(CdmDataChangeMap changeEvents) { |
|
100 |
} |
|
101 |
|
|
80 | 102 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/KeyEditor.java | ||
---|---|---|
17 | 17 |
|
18 | 18 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
19 | 19 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; |
20 |
import eu.etaxonomy.cdm.model.description.PolytomousKey; |
|
20 | 21 |
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; |
21 | 22 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
22 | 23 |
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyGraphEditor; |
... | ... | |
36 | 37 |
|
37 | 38 |
private ConversationHolder conversation; |
38 | 39 |
|
39 |
private AbstractIdentificationEditorInput input; |
|
40 |
|
|
41 | 40 |
private boolean dirty; |
42 | 41 |
|
43 | 42 |
/* |
... | ... | |
171 | 170 |
*/ |
172 | 171 |
@Override |
173 | 172 |
protected void addPages() { |
174 |
input = (AbstractIdentificationEditorInput) getEditorInput(); |
|
173 |
AbstractIdentificationEditorInput input = (AbstractIdentificationEditorInput) getEditorInput();
|
|
175 | 174 |
conversation = input.getConversationHolder(); |
176 | 175 |
conversation.registerForDataStoreChanges(this); |
177 | 176 |
|
... | ... | |
184 | 183 |
EditorUtil.error(getClass(), e); |
185 | 184 |
} |
186 | 185 |
|
186 |
PolytomousKey key = (PolytomousKey) input.getKey(); |
|
187 |
|
|
188 |
setPartName(key.getTitleCache()); |
|
189 |
|
|
187 | 190 |
} |
188 | 191 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyListEditor.java | ||
---|---|---|
13 | 13 |
import java.util.List; |
14 | 14 |
|
15 | 15 |
import org.eclipse.core.runtime.IProgressMonitor; |
16 |
import org.eclipse.jface.action.GroupMarker; |
|
17 |
import org.eclipse.jface.action.MenuManager; |
|
16 | 18 |
import org.eclipse.jface.viewers.StructuredSelection; |
17 | 19 |
import org.eclipse.jface.viewers.TableViewer; |
18 | 20 |
import org.eclipse.jface.viewers.TableViewerColumn; |
... | ... | |
23 | 25 |
import org.eclipse.swt.graphics.Rectangle; |
24 | 26 |
import org.eclipse.swt.layout.FillLayout; |
25 | 27 |
import org.eclipse.swt.widgets.Composite; |
28 |
import org.eclipse.swt.widgets.Control; |
|
29 |
import org.eclipse.swt.widgets.Menu; |
|
26 | 30 |
import org.eclipse.swt.widgets.Table; |
27 | 31 |
import org.eclipse.swt.widgets.TableItem; |
28 | 32 |
import org.eclipse.ui.IEditorInput; |
29 | 33 |
import org.eclipse.ui.IEditorSite; |
34 |
import org.eclipse.ui.IWorkbenchActionConstants; |
|
30 | 35 |
import org.eclipse.ui.PartInitException; |
31 | 36 |
import org.eclipse.ui.part.EditorPart; |
32 | 37 |
|
... | ... | |
60 | 65 |
|
61 | 66 |
Table table = (Table) event.widget; |
62 | 67 |
// Determine where the mouse was clicked |
63 |
Point pt = new Point(event.x, event.y); |
|
68 |
Point point = new Point(event.x, event.y); |
|
69 |
|
|
70 |
int selectedColumn = getSelectedColumn(table, point); |
|
71 |
|
|
72 |
if (selectedColumn == 3) { |
|
73 |
PolytomousKeyNode node = (PolytomousKeyNode) getTableItem( |
|
74 |
table, point).getData(); |
|
75 |
Object linkData = getItemLinkData(node); |
|
76 |
if (linkData instanceof PolytomousKeyNode) { |
|
77 |
viewer.setSelection(new StructuredSelection(linkData), true); |
|
78 |
} else if (linkData instanceof Taxon) { |
|
79 |
try { |
|
80 |
EditorUtil.openTaxonBase(((Taxon) linkData).getUuid()); |
|
81 |
} catch (PartInitException e) { |
|
82 |
EditorUtil.error(getClass(), e); |
|
83 |
} |
|
84 |
} |
|
85 |
} |
|
64 | 86 |
|
65 |
final TableItem item = table.getItem(pt); |
|
87 |
} |
|
88 |
|
|
89 |
private int getSelectedColumn(Table table, Point point) { |
|
90 |
TableItem item = getTableItem(table, point); |
|
66 | 91 |
if (item != null) { |
67 |
// Determine which column was selected |
|
68 |
int column = -1; |
|
69 | 92 |
for (int i = 0, n = table.getColumnCount(); i < n; i++) { |
70 | 93 |
Rectangle rect = item.getBounds(i); |
71 |
if (rect.contains(pt)) { |
|
94 |
if (rect.contains(point)) {
|
|
72 | 95 |
// This is the selected column |
73 |
column = i; |
|
74 |
break; |
|
75 |
} |
|
76 |
} |
|
77 |
if (column == 3) { |
|
78 |
PolytomousKeyNode node = (PolytomousKeyNode) item.getData(); |
|
79 |
Object linkData = getItemLinkData(node); |
|
80 |
if (linkData instanceof PolytomousKeyNode) { |
|
81 |
viewer.setSelection(new StructuredSelection(linkData), |
|
82 |
true); |
|
83 |
} else if (linkData instanceof Taxon) { |
|
84 |
try { |
|
85 |
EditorUtil.openTaxonBase(((Taxon) linkData) |
|
86 |
.getUuid()); |
|
87 |
} catch (PartInitException e) { |
|
88 |
EditorUtil.error(getClass(), e); |
|
89 |
} |
|
96 |
return i; |
|
90 | 97 |
} |
91 | 98 |
} |
92 | 99 |
} |
100 |
return -1; |
|
101 |
} |
|
102 |
|
|
103 |
private TableItem getTableItem(Table table, Point point) { |
|
104 |
return table.getItem(point); |
|
93 | 105 |
} |
94 | 106 |
|
95 | 107 |
/** |
... | ... | |
209 | 221 |
viewer.setContentProvider(new PolytomousKeyListContentProvider()); |
210 | 222 |
viewer.setLabelProvider(new PolytomousKeyListLabelProvider()); |
211 | 223 |
|
212 |
// viewer.getControl().setLayoutData(CdmFormFactory.FILL());
|
|
224 |
createMenu();
|
|
213 | 225 |
|
214 | 226 |
PolytomousKey key = ((PolytomousKeyEditorInput) getEditorInput()) |
215 | 227 |
.getKey(); |
216 | 228 |
|
229 |
setPartName(key.getTitleCache()); |
|
230 |
|
|
217 | 231 |
viewer.setInput(key); |
218 | 232 |
} |
219 | 233 |
|
234 |
private void createMenu() { |
|
235 |
// register context menu |
|
236 |
MenuManager menuManager = new MenuManager(); |
|
237 |
menuManager |
|
238 |
.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); |
|
239 |
getSite().registerContextMenu(ID, menuManager, viewer); |
|
240 |
|
|
241 |
Control control = viewer.getControl(); |
|
242 |
Menu menu = menuManager.createContextMenu(control); |
|
243 |
control.setMenu(menu); |
|
244 |
} |
|
245 |
|
|
220 | 246 |
// This will create the columns for the table |
221 | 247 |
private void createColumns(TableViewer viewer) { |
222 | 248 |
Table table = viewer.getTable(); |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyListLabelProvider.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
package eu.etaxonomy.taxeditor.editor.key.polytomous; |
12 | 12 |
|
13 |
import org.eclipse.jface.viewers.ITableLabelProvider; |
|
14 | 13 |
import org.eclipse.jface.viewers.StyledCellLabelProvider; |
15 |
import org.eclipse.swt.graphics.Image; |
|
14 |
import org.eclipse.jface.viewers.StyledString; |
|
15 |
import org.eclipse.jface.viewers.StyledString.Styler; |
|
16 |
import org.eclipse.jface.viewers.ViewerCell; |
|
17 |
import org.eclipse.swt.SWT; |
|
18 |
import org.eclipse.swt.custom.StyleRange; |
|
19 |
import org.eclipse.swt.graphics.Color; |
|
20 |
import org.eclipse.swt.graphics.TextStyle; |
|
21 |
import org.eclipse.swt.widgets.Display; |
|
16 | 22 |
|
17 | 23 |
import eu.etaxonomy.cdm.common.CdmUtils; |
18 | 24 |
import eu.etaxonomy.cdm.model.description.KeyStatement; |
... | ... | |
24 | 30 |
* @created Apr 18, 2011 |
25 | 31 |
* @version 1.0 |
26 | 32 |
*/ |
27 |
public class PolytomousKeyListLabelProvider extends StyledCellLabelProvider |
|
28 |
implements ITableLabelProvider { |
|
33 |
public class PolytomousKeyListLabelProvider extends StyledCellLabelProvider { |
|
29 | 34 |
|
30 |
/* |
|
31 |
* (non-Javadoc) |
|
32 |
* |
|
33 |
* @see |
|
34 |
* org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang |
|
35 |
* .Object, int) |
|
36 |
*/ |
|
37 |
@Override |
|
38 |
public Image getColumnImage(Object element, int columnIndex) { |
|
39 |
return null; |
|
40 |
} |
|
35 |
private static Color colorLink = Display.getCurrent().getSystemColor( |
|
36 |
SWT.COLOR_BLUE); |
|
37 |
private Styler styler; |
|
38 |
|
|
39 |
private static final String EMPTY = ""; |
|
40 |
// TODO make this configurable via preferences |
|
41 |
private static final String INCREMENTOR_CHARACTER = "'"; |
|
41 | 42 |
|
42 | 43 |
/* |
43 | 44 |
* (non-Javadoc) |
44 | 45 |
* |
45 | 46 |
* @see |
46 |
* org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang
|
|
47 |
* .Object, int)
|
|
47 |
* org.eclipse.jface.viewers.StyledCellLabelProvider#update(org.eclipse.
|
|
48 |
* jface.viewers.ViewerCell)
|
|
48 | 49 |
*/ |
49 | 50 |
@Override |
50 |
public String getColumnText(Object element, int columnIndex) { |
|
51 |
public void update(ViewerCell cell) { |
|
52 |
Object element = cell.getElement(); |
|
53 |
int columnIndex = cell.getColumnIndex(); |
|
54 |
|
|
51 | 55 |
if (element instanceof PolytomousKeyNode) { |
52 | 56 |
|
53 |
PolytomousKeyNode node = (PolytomousKeyNode) element; |
|
54 |
|
|
55 |
switch (columnIndex) { |
|
56 |
case 0: |
|
57 |
return getItemNumber(node); |
|
58 |
case 1: |
|
59 |
return getItemQuestion(node); |
|
60 |
case 2: |
|
61 |
return getItemStatement(node); |
|
62 |
case 3: |
|
63 |
return getItemLink(node); |
|
57 |
String text = getTextForColumnIndex((PolytomousKeyNode) element, |
|
58 |
columnIndex); |
|
59 |
cell.setText(text); |
|
60 |
|
|
61 |
if (columnIndex == 3) { |
|
62 |
StyledString styledString = new StyledString(text, getStyler()); |
|
63 |
StyleRange[] styleRanges; |
|
64 |
styleRanges = styledString.getStyleRanges(); |
|
65 |
cell.setStyleRanges(styleRanges); |
|
64 | 66 |
} |
65 | 67 |
} |
66 |
return null; |
|
68 |
|
|
69 |
super.update(cell); |
|
70 |
} |
|
71 |
|
|
72 |
private String getTextForColumnIndex(PolytomousKeyNode node, int columnIndex) { |
|
73 |
switch (columnIndex) { |
|
74 |
case 0: |
|
75 |
return getItemNumber(node); |
|
76 |
case 1: |
|
77 |
return getItemQuestion(node); |
|
78 |
case 2: |
|
79 |
return getItemStatement(node); |
|
80 |
case 3: |
|
81 |
return getItemLink(node); |
|
82 |
} |
|
83 |
return EMPTY; |
|
84 |
} |
|
85 |
|
|
86 |
/** |
|
87 |
* @return |
|
88 |
*/ |
|
89 |
private Styler getStyler() { |
|
90 |
if (styler == null) { |
|
91 |
styler = new Styler() { |
|
92 |
@Override |
|
93 |
public void applyStyles(TextStyle textStyle) { |
|
94 |
textStyle.underline = true; |
|
95 |
textStyle.underlineColor = colorLink; |
|
96 |
textStyle.foreground = colorLink; |
|
97 |
textStyle.underlineStyle = SWT.UNDERLINE_SINGLE; |
|
98 |
} |
|
99 |
}; |
|
100 |
} |
|
101 |
return styler; |
|
67 | 102 |
} |
68 | 103 |
|
69 | 104 |
private String getItemNumber(PolytomousKeyNode node) { |
... | ... | |
72 | 107 |
} else { |
73 | 108 |
PolytomousKeyNode parent = getParent(node); |
74 | 109 |
String itemNumber = parent.getNodeNumber() != null ? parent |
75 |
.getNodeNumber().toString() : "NaN";
|
|
110 |
.getNodeNumber().toString() : EMPTY;
|
|
76 | 111 |
|
77 | 112 |
int index = parent.getChildren().indexOf(node); |
78 | 113 |
|
79 | 114 |
for (int i = 0; i < index; i++) { |
80 |
itemNumber += "'";
|
|
115 |
itemNumber += INCREMENTOR_CHARACTER;
|
|
81 | 116 |
} |
82 | 117 |
|
83 | 118 |
return itemNumber; |
... | ... | |
90 | 125 |
} else { |
91 | 126 |
KeyStatement question = getParent(node).getQuestion(); |
92 | 127 |
return question != null ? question.getLabelText(CdmStore |
93 |
.getDefaultLanguage()) : "";
|
|
128 |
.getDefaultLanguage()) : EMPTY;
|
|
94 | 129 |
} |
95 | 130 |
|
96 | 131 |
} |
... | ... | |
98 | 133 |
private String getItemStatement(PolytomousKeyNode node) { |
99 | 134 |
KeyStatement statement = node.getStatement(); |
100 | 135 |
return statement != null ? CdmUtils.Nz(statement.getLabelText(CdmStore |
101 |
.getDefaultLanguage())) : "No statement";
|
|
136 |
.getDefaultLanguage())) : EMPTY;
|
|
102 | 137 |
} |
103 | 138 |
|
104 | 139 |
private String getItemLink(PolytomousKeyNode node) { |
105 | 140 |
String taxonString = node.getTaxon() != null ? node.getTaxon() |
106 |
.getName().getTitleCache() : "Taxon empty";
|
|
141 |
.getName().getTitleCache() : EMPTY;
|
|
107 | 142 |
|
108 | 143 |
return node.getChildren().isEmpty() ? taxonString : node |
109 | 144 |
.getNodeNumber().toString(); |
Also available in: Unified diff
Link in PolytomousKeyListEditor is recognizable as such; Added a menu