Revision ff742a38
Added by Patrick Plitzner over 6 years ago
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java | ||
---|---|---|
23 | 23 |
import org.eclipse.e4.ui.workbench.modeling.ESelectionService; |
24 | 24 |
import org.eclipse.jface.dialogs.MessageDialog; |
25 | 25 |
import org.eclipse.jface.viewers.ArrayContentProvider; |
26 |
import org.eclipse.jface.viewers.CellEditor; |
|
27 |
import org.eclipse.jface.viewers.ICellModifier; |
|
26 | 28 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
29 |
import org.eclipse.jface.viewers.ITableLabelProvider; |
|
27 | 30 |
import org.eclipse.jface.viewers.TableViewer; |
31 |
import org.eclipse.jface.viewers.TableViewerColumn; |
|
32 |
import org.eclipse.jface.viewers.TextCellEditor; |
|
28 | 33 |
import org.eclipse.swt.SWT; |
29 | 34 |
import org.eclipse.swt.layout.FillLayout; |
30 | 35 |
import org.eclipse.swt.layout.GridData; |
31 | 36 |
import org.eclipse.swt.layout.GridLayout; |
32 | 37 |
import org.eclipse.swt.widgets.Composite; |
38 |
import org.eclipse.swt.widgets.Table; |
|
33 | 39 |
|
34 | 40 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
35 | 41 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; |
... | ... | |
93 | 99 |
performSearch(new BulkEditorQuery(bulkEditorInput.getEntityUuid().toString(), null)); |
94 | 100 |
} |
95 | 101 |
thisPart.setLabel(input.getName()); |
102 |
|
|
103 |
//create columns |
|
104 |
Table table = viewer.getTable(); |
|
105 |
String[] titles = {input.getName(), "Type"}; |
|
106 |
int[] bounds = {500, 100}; |
|
107 |
|
|
108 |
CellEditor[] editors = new CellEditor[titles.length]; |
|
109 |
for (int i = 0; i < titles.length; i++) { |
|
110 |
TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE); |
|
111 |
editors[i] = new TextCellEditor(table); |
|
112 |
column.getColumn().setText(titles[i]); |
|
113 |
column.getColumn().setWidth(bounds[i]); |
|
114 |
column.getColumn().setResizable(true); |
|
115 |
column.getColumn().setMoveable(true); |
|
116 |
} |
|
117 |
table.setHeaderVisible(true); |
|
118 |
table.setLinesVisible(true); |
|
119 |
viewer.setCellEditors(editors); |
|
120 |
viewer.setColumnProperties(titles); |
|
121 |
|
|
122 |
//content and label provider (NOTE: has to be set AFTER creating cell editors |
|
123 |
viewer.setContentProvider(new ArrayContentProvider()); |
|
124 |
BulkEditorLabelProvider labelProvider = new BulkEditorLabelProvider(this); |
|
125 |
viewer.setLabelProvider(labelProvider); |
|
126 |
|
|
127 |
|
|
128 |
//allow text selection |
|
129 |
viewer.setCellModifier(new ICellModifier() { |
|
130 |
@Override |
|
131 |
public void modify(Object element, String property, Object value) { |
|
132 |
} |
|
133 |
@Override |
|
134 |
public Object getValue(Object element, String property) { |
|
135 |
ITableLabelProvider tableLabelProvider = null; |
|
136 |
if(viewer.getLabelProvider() instanceof ITableLabelProvider){ |
|
137 |
tableLabelProvider = (ITableLabelProvider) viewer.getLabelProvider(); |
|
138 |
} |
|
139 |
Object[] columnProperties = viewer.getColumnProperties(); |
|
140 |
for (int i=0;i<columnProperties.length;i++) { |
|
141 |
if(columnProperties[i].equals(property) && tableLabelProvider!=null){ |
|
142 |
return tableLabelProvider.getColumnText(element, i); |
|
143 |
} |
|
144 |
} |
|
145 |
return ""; |
|
146 |
} |
|
147 |
@Override |
|
148 |
public boolean canModify(Object element, String property) { |
|
149 |
return true; |
|
150 |
} |
|
151 |
}); |
|
96 | 152 |
} |
97 | 153 |
|
98 | 154 |
/** {@inheritDoc} */ |
... | ... | |
118 | 174 |
Composite bottomComposite = new Composite(parent, SWT.NONE); |
119 | 175 |
bottomComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
120 | 176 |
bottomComposite.setLayout(new FillLayout()); |
121 |
viewer = new TableViewer(bottomComposite); |
|
122 |
viewer.setContentProvider(new ArrayContentProvider()); |
|
123 |
viewer.setLabelProvider(new BulkEditorLabelProvider(this)); |
|
177 |
viewer = new TableViewer(bottomComposite, SWT.MULTI | SWT.H_SCROLL |
|
178 |
| SWT.V_SCROLL | SWT.FULL_SELECTION); |
|
124 | 179 |
|
180 |
// createColumns(viewer); |
|
125 | 181 |
|
126 | 182 |
//propagate selection |
127 | 183 |
selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event))); |
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorLabelProvider.java | ||
---|---|---|
15 | 15 |
import org.eclipse.core.runtime.FileLocator; |
16 | 16 |
import org.eclipse.core.runtime.IPath; |
17 | 17 |
import org.eclipse.core.runtime.Path; |
18 |
import org.eclipse.jface.viewers.ITableLabelProvider; |
|
18 | 19 |
import org.eclipse.jface.viewers.LabelProvider; |
19 |
import org.eclipse.jface.viewers.StyledString; |
|
20 | 20 |
import org.eclipse.swt.graphics.Image; |
21 | 21 |
|
22 | 22 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
... | ... | |
29 | 29 |
* @date 11.09.2017 |
30 | 30 |
* |
31 | 31 |
*/ |
32 |
public class BulkEditorLabelProvider extends LabelProvider { |
|
32 |
public class BulkEditorLabelProvider extends LabelProvider implements ITableLabelProvider{
|
|
33 | 33 |
|
34 | 34 |
private BulkEditorE4 editor; |
35 | 35 |
|
... | ... | |
38 | 38 |
this.editor = editor; |
39 | 39 |
} |
40 | 40 |
|
41 |
/** |
|
42 |
* {@inheritDoc} |
|
43 |
*/ |
|
41 |
/** {@inheritDoc} */ |
|
44 | 42 |
@Override |
45 |
public Image getImage(Object element) { |
|
46 |
AbstractBulkEditorInput input = editor.getEditorInput(); |
|
43 |
public Image getColumnImage(Object element, int columnIndex) { |
|
44 |
if (columnIndex == 0) { |
|
45 |
AbstractBulkEditorInput input = editor.getEditorInput(); |
|
47 | 46 |
|
48 |
try { |
|
49 |
if(input.getMergeCandidates().contains(element)){ |
|
50 |
IPath path = new Path("icons/merge_candidate.gif"); //$NON-NLS-1$ |
|
51 |
URL url = FileLocator.find(TaxeditorBulkeditorPlugin.getDefault().getBundle(), path, null); |
|
52 |
return ImageResources.getImage(url.toURI()); |
|
47 |
try { |
|
48 |
if(input.getMergeCandidates().contains(element)){ |
|
49 |
IPath path = new Path("icons/merge_candidate.gif"); //$NON-NLS-1$ |
|
50 |
URL url = FileLocator.find(TaxeditorBulkeditorPlugin.getDefault().getBundle(), path, null); |
|
51 |
return ImageResources.getImage(url.toURI()); |
|
52 |
} |
|
53 |
else if(input.getMergeTarget()!=null && input.getMergeTarget().equals(element)){ |
|
54 |
IPath path = new Path("icons/merge_target.gif"); //$NON-NLS-1$ |
|
55 |
URL url = FileLocator.find(TaxeditorBulkeditorPlugin.getDefault().getBundle(), path, null); |
|
56 |
return ImageResources.getImage(url.toURI()); |
|
57 |
} |
|
58 |
} catch (URISyntaxException e) { |
|
59 |
return null; |
|
53 | 60 |
} |
54 |
else if(input.getMergeTarget()!=null && input.getMergeTarget().equals(element)){ |
|
55 |
IPath path = new Path("icons/merge_target.gif"); //$NON-NLS-1$ |
|
56 |
URL url = FileLocator.find(TaxeditorBulkeditorPlugin.getDefault().getBundle(), path, null); |
|
57 |
return ImageResources.getImage(url.toURI()); |
|
58 |
} |
|
59 |
} catch (URISyntaxException e) { |
|
60 |
return null; |
|
61 | 61 |
} |
62 | 62 |
return null; |
63 | 63 |
} |
64 | 64 |
|
65 |
/** |
|
66 |
* {@inheritDoc} |
|
67 |
*/ |
|
65 |
/** {@inheritDoc} */ |
|
68 | 66 |
@Override |
69 |
public String getText(Object element) { |
|
70 |
if(element instanceof CdmBase){ |
|
71 |
String text = editor.getEditorInput().getText((CdmBase) element); |
|
67 |
public String getColumnText(Object element, int columnIndex) { |
|
68 |
String text = null; |
|
69 |
|
|
70 |
if (columnIndex == 0) { |
|
71 |
if(element instanceof CdmBase){ |
|
72 |
text = editor.getEditorInput().getText((CdmBase) element); |
|
73 |
} |
|
74 |
}else if (columnIndex == 1) { |
|
72 | 75 |
if(editor.getEditorInput().getTypeText(element)!=null){ |
73 |
text += " ["+editor.getEditorInput().getTypeText(element)+"]";
|
|
76 |
text = editor.getEditorInput().getTypeText(element);
|
|
74 | 77 |
} |
75 |
return text; |
|
76 | 78 |
} |
77 |
return super.getText(element);
|
|
79 |
return text;
|
|
78 | 80 |
} |
79 | 81 |
|
82 |
|
|
80 | 83 |
} |
Also available in: Unified diff
ref #6932 Allow text selection in bulk editor