2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.editor
.view
.checklist
.e4
;
13 import java
.util
.ArrayList
;
14 import java
.util
.Arrays
;
15 import java
.util
.Collections
;
16 import java
.util
.HashMap
;
17 import java
.util
.List
;
19 import java
.util
.SortedSet
;
20 import java
.util
.UUID
;
22 import javax
.annotation
.PostConstruct
;
23 import javax
.annotation
.PreDestroy
;
24 import javax
.inject
.Inject
;
26 import org
.apache
.log4j
.Logger
;
27 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
28 import org
.eclipse
.e4
.ui
.di
.Focus
;
29 import org
.eclipse
.e4
.ui
.di
.Persist
;
30 import org
.eclipse
.e4
.ui
.model
.application
.ui
.MDirtyable
;
31 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
32 import org
.eclipse
.e4
.ui
.workbench
.modeling
.ESelectionService
;
33 import org
.eclipse
.jface
.viewers
.ColumnViewerEditorActivationStrategy
;
34 import org
.eclipse
.jface
.viewers
.FocusCellOwnerDrawHighlighter
;
35 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
36 import org
.eclipse
.jface
.viewers
.StructuredViewer
;
37 import org
.eclipse
.jface
.viewers
.TableViewer
;
38 import org
.eclipse
.jface
.viewers
.TableViewerColumn
;
39 import org
.eclipse
.jface
.viewers
.TableViewerEditor
;
40 import org
.eclipse
.jface
.viewers
.TableViewerFocusCellManager
;
41 import org
.eclipse
.jface
.wizard
.WizardDialog
;
42 import org
.eclipse
.swt
.SWT
;
43 import org
.eclipse
.swt
.events
.ModifyListener
;
44 import org
.eclipse
.swt
.events
.SelectionAdapter
;
45 import org
.eclipse
.swt
.events
.SelectionEvent
;
46 import org
.eclipse
.swt
.layout
.GridData
;
47 import org
.eclipse
.swt
.layout
.GridLayout
;
48 import org
.eclipse
.swt
.widgets
.Button
;
49 import org
.eclipse
.swt
.widgets
.Composite
;
50 import org
.eclipse
.swt
.widgets
.Display
;
51 import org
.eclipse
.swt
.widgets
.Label
;
52 import org
.eclipse
.swt
.widgets
.Table
;
53 import org
.eclipse
.swt
.widgets
.TableColumn
;
54 import org
.eclipse
.swt
.widgets
.Text
;
55 import org
.eclipse
.swt
.widgets
.ToolBar
;
56 import org
.eclipse
.swt
.widgets
.ToolItem
;
57 import org
.eclipse
.ui
.progress
.IWorkbenchSiteProgressService
;
59 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
60 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
61 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
62 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
63 import eu
.etaxonomy
.cdm
.model
.common
.Representation
;
64 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
65 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
66 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
67 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
68 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
69 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
70 import eu
.etaxonomy
.taxeditor
.editor
.IDistributionEditor
;
71 import eu
.etaxonomy
.taxeditor
.editor
.internal
.TaxeditorEditorPlugin
;
72 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
73 import eu
.etaxonomy
.taxeditor
.editor
.view
.checklist
.ChecklistContentProvider
;
74 import eu
.etaxonomy
.taxeditor
.editor
.view
.checklist
.ChecklistEditorComparator
;
75 import eu
.etaxonomy
.taxeditor
.editor
.view
.checklist
.ChecklistEditorInput
;
76 import eu
.etaxonomy
.taxeditor
.editor
.view
.checklist
.ChecklistLabelProvider
;
77 import eu
.etaxonomy
.taxeditor
.editor
.view
.checklist
.filter
.ChecklistEditorFilter
;
78 import eu
.etaxonomy
.taxeditor
.editor
.view
.checklist
.listener
.ChecklistFocusListener
;
79 import eu
.etaxonomy
.taxeditor
.editor
.view
.checklist
.listener
.ChecklistModifyListener
;
80 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
81 import eu
.etaxonomy
.taxeditor
.model
.IDirtyMarkable
;
82 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
83 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
84 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
85 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
86 import eu
.etaxonomy
.taxeditor
.preference
.wizard
.AvailableDistributionWizard
;
87 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
88 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
89 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.ReferenceSelectionDialog
;
90 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
91 import eu
.etaxonomy
.taxeditor
.ui
.selection
.EntitySelectionElement
;
92 import eu
.etaxonomy
.taxeditor
.workbench
.part
.IE4SavablePart
;
99 public class ChecklistEditorE4
implements IConversationEnabled
,
100 IDirtyMarkable
, IPartContentHasDetails
, IE4SavablePart
, IDistributionEditor
, IPartContentHasSupplementalData
{
102 private static final String DISTRIBUTION_EDITOR
= "Distribution Editor";
103 private static final String LOADING_TAXA
= Messages
.ChecklistEditor_LOAD_TAXA
;
104 private static final String UNKNOWN
= Messages
.ChecklistEditor_UNKNOWN
;
105 private static final String ELEMENT_COUNT
= Messages
.ChecklistEditor_ELEMENT_COUNT
;
106 public static final String TYPE_FILTER_TEXT
= "type filter text"; //$NON-NLS-1$
108 private static final Logger logger
= Logger
.getLogger(ChecklistEditorE4
.class);
112 * <code>ID="eu.etaxonomy.taxeditor.store.datasource"{trunked}</code>
114 public static String ID
= "eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditor"; //$NON-NLS-1$
116 private TableViewer viewer
;
118 private ITaxonNodeService taxonNodeService
;
120 private ChecklistEditorComparator comparator
;
122 private ChecklistEditorInput checklistEditorInput
;
124 private ConversationHolder conversation
;
126 private Integer countNodes
;
128 private List
<TaxonNode
> selectedTaxonNodes
;
131 private MPart thisPart
;
134 private MDirtyable dirty
;
137 private ESelectionService selService
;
139 private ISelectionChangedListener selectionChangedListener
;
141 private ChecklistEditorFilter filter
;
143 private Label statusLabel
;
144 private Label statusLabelSourceReference
;
146 private ChecklistLabelProvider labelProvider
;
148 private Map
<UUID
, Integer
> areaPosition
= new HashMap();
150 private ToolItem toolItem
;
151 private ToolItem toolItem2
;
152 private ChecklistDropdownSelectionListenerE4 dropListener
;
153 private Text searchText
;
154 private EntitySelectionElement
<Reference
> defaultReferenceSelection
;
156 private Reference defaultSource
= null;
158 public Reference
getDefaultSource() {
159 return defaultSource
;
161 public Map
<UUID
, Integer
> getAreaPosition() {
165 * @return the selectedTaxonNodes
167 public List
<TaxonNode
> getSelectedTaxonNodes() {
168 return selectedTaxonNodes
;
172 * @param selectedTaxonNodes
173 * the selectedTaxonNodes to set
175 public void setSelectedTaxonNodes(List
<TaxonNode
> selectedTaxonNodes
) {
176 this.selectedTaxonNodes
= selectedTaxonNodes
;
180 public ChecklistEditorE4() {
185 public void createPartControl(Composite parent
) {
186 if (!CdmStore
.isActive()){
189 taxonNodeService
= CdmStore
.getService(ITaxonNodeService
.class);
190 filter
= new ChecklistEditorFilter();
191 createTopComposite(parent
);
192 // createToolbar(parent);
193 viewer
= new TableViewer(parent
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.FULL_SELECTION
);
195 //the focuzsCellManager should return the distribution!!!
196 TableViewerFocusCellManager focusCellManager
= new TableViewerFocusCellManager(viewer
, new FocusCellOwnerDrawHighlighter (viewer
));
197 TableViewerEditor
.create(viewer
, focusCellManager
, new ColumnViewerEditorActivationStrategy(viewer
), TableViewerEditor
.DEFAULT
);
199 labelProvider
= new ChecklistLabelProvider(this);
201 viewer
.addFilter(filter
);
204 viewer
.setContentProvider(new ChecklistContentProvider());
205 viewer
.setLabelProvider(this.labelProvider
);
207 comparator
= new ChecklistEditorComparator();
208 viewer
.setComparator(comparator
);
209 final ModifyListener modifyListener
= new ChecklistModifyListener(viewer
, filter
, searchText
);
211 searchText
.addFocusListener(new ChecklistFocusListener(searchText
, modifyListener
));
212 searchText
.addModifyListener(modifyListener
);
213 createGridDataForViewerLayout();
214 createStatusBar(parent
);
221 private void createTopComposite(Composite parent
) {
222 GridLayout gridLayout
= new GridLayout(3, false);
223 gridLayout
.marginWidth
= 0;
224 gridLayout
.marginHeight
= 0;
225 parent
.setLayout(gridLayout
);
227 searchText
= createSearchBar(parent
);
237 private void createSetDefaultReferenceButton(Composite parent
) {
238 CdmFormFactory cdmFormFactory
= new CdmFormFactory(Display
.getCurrent());
239 defaultReferenceSelection
= cdmFormFactory
.createSelectionElement(Reference
.class,
240 null, "Default Source Reference", null,
241 EntitySelectionElement
.DELETABLE
, SWT
.NULL
);
249 private void createGridDataForViewerLayout() {
250 GridData gridData
= new GridData();
251 gridData
.verticalAlignment
= GridData
.FILL
;
252 gridData
.horizontalSpan
= 3;
253 gridData
.grabExcessHorizontalSpace
= true;
254 gridData
.grabExcessVerticalSpace
= true;
255 gridData
.horizontalAlignment
= GridData
.FILL
;
256 viewer
.getControl().setLayoutData(gridData
);
263 private Text
createSearchBar(Composite parent
) {
265 final Text searchText
= new Text(parent
, SWT
.BORDER
| SWT
.SEARCH
| SWT
.ICON_SEARCH
| SWT
.CANCEL
);
266 GridData gridData
= new GridData(GridData
.GRAB_HORIZONTAL
| GridData
.HORIZONTAL_ALIGN_FILL
);
268 searchText
.setLayoutData(gridData
);
269 searchText
.setForeground(EditorUtil
.getColor(Resources
.SEARCH_VIEW_FOREGROUND
));
270 searchText
.setText(TYPE_FILTER_TEXT
);
271 searchText
.setToolTipText(Messages
.ChecklistEditor_SEARCH_TOOLTIP
);
273 Button button1
= new Button(parent
, SWT
.PUSH
);
274 GridData gridData2
= new GridData();
275 gridData2
.horizontalSpan
= 1;
276 gridData2
.horizontalAlignment
= SWT
.RIGHT
;
277 button1
.setLayoutData(gridData2
);
280 button1
.setText(Messages
.ChecklistEditor_DIST_STATUS
);
281 button1
.setToolTipText(Messages
.ChecklistEditor_DIST_STATUS_TOOLTIP
);
282 button1
.addSelectionListener(new SelectionAdapter() {
284 public void widgetSelected(SelectionEvent event
) {
285 AvailableDistributionWizard availableDistributionWizard
= new AvailableDistributionWizard();
286 WizardDialog dialog
= new WizardDialog(StoreUtil
.getShell(),
287 availableDistributionWizard
);
289 int open
= dialog
.open();
296 Button button2
= new Button(parent
, SWT
.PUSH
);
297 GridData gridData3
= new GridData();
298 gridData2
.horizontalSpan
= 1;
299 button2
.setLayoutData(gridData3
);
302 button2
.setText(Messages
.ChecklistEditor_DEFAULT_SOURCE
);
303 button2
.setToolTipText(Messages
.ChecklistEditor_DEFAULT_SOURCE_TOOLTIP
);
304 button2
.addSelectionListener(new SelectionAdapter() {
307 public void widgetSelected(SelectionEvent event
) {
308 defaultSource
= ReferenceSelectionDialog
.select(AbstractUtility
.getShell(), null);
310 String defaultSourceStr
= (defaultSource
== null) ?
"" : "Default Source Reference: " + defaultSource
.getTitleCache();
311 if (defaultSourceStr
.length()> 100){
312 defaultSourceStr
= defaultSourceStr
.substring(0, 98) + "...";
314 statusLabelSourceReference
.setText(defaultSourceStr
);
316 button2
.setBackground(EditorUtil
.getColor(Resources
.COLOR_CONTROL_SELECTED
));
328 private void createToolbar(Composite parent
) {
329 ToolBar toolBar
= new ToolBar(parent
, SWT
.BORDER
);
330 // toolItem = new ToolItem(toolBar, SWT.DROP_DOWN | SWT.BORDER);
332 toolItem
= new ToolItem(toolBar
, SWT
.PUSH
| SWT
.BORDER
);
335 toolItem
.setText(Messages
.ChecklistEditor_DIST_STATUS
);
336 toolItem
.setToolTipText(Messages
.ChecklistEditor_DIST_STATUS_TOOLTIP
);
337 //createToolbarItems();
338 // toolItem.addSelectionListener(dropListener);
339 toolItem
.addSelectionListener(new SelectionAdapter() {
341 public void widgetSelected(SelectionEvent event
) {
342 AvailableDistributionWizard availableDistributionWizard
= new AvailableDistributionWizard();
343 WizardDialog dialog
= new WizardDialog(StoreUtil
.getShell(),
344 availableDistributionWizard
);
346 int open
= dialog
.open();
352 toolItem2
= new ToolItem(toolBar
, SWT
.PUSH
| SWT
.BORDER
);
355 toolItem2
.setText(Messages
.ChecklistEditor_DEFAULT_SOURCE
);
356 toolItem2
.setToolTipText(Messages
.ChecklistEditor_DEFAULT_SOURCE_TOOLTIP
);
357 //createToolbarItems();
358 // toolItem.addSelectionListener(dropListener);
359 toolItem2
.addSelectionListener(new SelectionAdapter() {
361 public void widgetSelected(SelectionEvent event
) {
362 defaultSource
= ReferenceSelectionDialog
.select(AbstractUtility
.getShell(), null);
372 private void createStatusBar(Composite composite
) {
373 GridData gridData
= new GridData();
374 gridData
.horizontalSpan
= 1;
375 gridData
.grabExcessHorizontalSpace
= true;
376 gridData
.horizontalAlignment
= GridData
.FILL
;
378 statusLabel
= new Label(composite
, SWT
.LEFT
);
379 statusLabel
.setText(ELEMENT_COUNT
+ (countNodes
!= null ? countNodes
: UNKNOWN
));
380 statusLabel
.setLayoutData(gridData
);
382 statusLabelSourceReference
= new Label(composite
, SWT
.RIGHT
);
383 // GridData sourceGrid = new GridData();
384 // sourceGrid.horizontalAlignment = GridData.HORIZONTAL_ALIGN_END;
385 // //sourceGrid.grabExcessHorizontalSpace = false;
386 // sourceGrid.horizontalSpan = 1;
387 statusLabelSourceReference
.setLayoutData(gridData
);
389 if (defaultSource
!= null){
390 statusLabelSourceReference
.setText("Default Source Reference: " + defaultSource
.getAbbrevTitle() != null? defaultSource
.getAbbrevTitle() : defaultSource
.getAbbrevTitleCache());
395 private void createTable() {
396 Table table
= viewer
.getTable();//new Table(parent, viewer.getTable().getStyle());
397 List
<String
> titles
= new ArrayList
<String
>();
398 List
<Integer
> bounds
= new ArrayList
<Integer
>();
399 if (PreferencesUtil
.isShowRankInChecklistEditor()){
400 Collections
.addAll(titles
, Messages
.ChecklistEditor_TAXON
, Messages
.ChecklistEditor_RANK
);
401 Collections
.addAll(bounds
, 300, 200);
403 Collections
.addAll(titles
, Messages
.ChecklistEditor_TAXON
);
404 Collections
.addAll(bounds
, 300);
408 // Map<Integer, Boolean> restoreValuesForColumnWidth =
409 restoreValuesForColumnWidth(titles
, bounds
);
410 createInitalDistributionColumns(table
, titles
, bounds
);
411 table
.setSortDirection(SWT
.DOWN
);
412 table
.setHeaderVisible(true);
413 table
.setLinesVisible(true);
416 * This method creates initially the distribution columns for a table. It should only be called for creation.<br>
419 *<b>Notice:</b> If you want to add additional columns later please use <b>addTableViewerColumn()</b>
424 * @param restoreValuesForColumnWidth
426 private void createInitalDistributionColumns(Table table
,
427 List
<String
> titles
, List
<Integer
> bounds
) {
428 for (int columnIndex
= 0; columnIndex
< titles
.size(); columnIndex
++) {
429 TableViewerColumn column
= new TableViewerColumn(viewer
, SWT
.NONE
);
430 column
.getColumn().setText(titles
.get(columnIndex
));
431 column
.getColumn().setWidth(bounds
.get(columnIndex
));
432 column
.getColumn().setResizable(true);
433 column
.getColumn().setMoveable(true);
434 column
.getColumn().addSelectionListener(getSelectionAdapter(column
.getColumn(), columnIndex
));
435 if (columnIndex
== 0) {
436 table
.setSortColumn(column
.getColumn());
438 if (columnIndex
== 1 && PreferencesUtil
.isShowRankInChecklistEditor()) {
439 /** uncommented it for now because no rank editing is wanted **/
442 if ((columnIndex
== 1 && !PreferencesUtil
.isShowRankInChecklistEditor()) || columnIndex
>= 2 ) {
443 column
.getColumn().setWidth(50);
444 column
.setEditingSupport(new DistributionEditingSupportE4(viewer
, this, columnIndex
));
451 * This methods loads the last opened distribution columns for the table viewer from the prefrence store.<br>
453 * <b>Notice:</b> It adds also the TitleCache to the titles list for the header of each column.<p>
457 * @return Map<Integer, Boolean>
459 private void restoreValuesForColumnWidth(List
<String
> titles
,
460 List
<Integer
> bounds
) {
461 // Map<Integer, Boolean> restoreColumnWidth = new HashMap<Integer, Boolean>();
462 if (labelProvider
.getNamedAreas(true) != null) {
464 if (PreferencesUtil
.isShowRankInChecklistEditor()){
469 for (DefinedTermBase
<DefinedTermBase
> term
: getLabelProvider().getNamedAreas(false)) {
471 // restoreColumnWidth.put(columnIndex, PreferencesUtil.getPreferenceStore().getBoolean(term.getUuid().toString()));
472 areaPosition
.put(term
.getUuid(), columnIndex
);
473 Representation rep
= term
.getPreferredRepresentation(CdmStore
.getDefaultLanguage());
474 String label
= rep
.getLabel();
476 term
.getTitleCache();
478 if (PreferencesUtil
.isShowIdInVocabularyInChecklistEditor()){
479 if (term
.getIdInVocabulary() != null){
480 titles
.add(term
.getIdInVocabulary());
484 }else if (PreferencesUtil
.isShowSymbol1InChecklistEditor()){
485 if (term
.getSymbol() != null){
486 titles
.add(term
.getSymbol());
490 }else if (PreferencesUtil
.isShowSymbol2InChecklistEditor()){
491 if (term
.getSymbol2() != null){
492 titles
.add(term
.getSymbol2());
508 * This method adds new DistributionColumns to an existing table.
515 private TableViewerColumn
addTableViewerColumn(String title
, int bound
, final int colNumber
, DefinedTermBase term
) {
517 final TableViewerColumn viewerColumn
= new TableViewerColumn(viewer
, SWT
.FULL_SELECTION
);
518 final TableColumn column
= viewerColumn
.getColumn();
519 column
.setText(title
);
520 String
[] UuidAndLable
= new String
[2];
521 UuidAndLable
[0] = term
.getUuid().toString();
522 UuidAndLable
[1] = title
;
523 column
.setData(UuidAndLable
);
524 column
.setWidth(200);
526 viewerColumn
.setEditingSupport(new DistributionEditingSupportE4(viewer
, this, colNumber
));
527 column
.setResizable(true);
528 column
.setMoveable(true);
536 * pull data from database and set input for view
539 private void loadDataInput() {
540 Classification classification
= checklistEditorInput
.getClassification();
541 TaxonNode taxonNode
= checklistEditorInput
.getTaxonNode();
542 if (classification
!= null && taxonNode
== null) {
543 countNodes
= taxonNodeService
.countAllNodesForClassification(classification
);
544 // statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
545 // This should not kill the view nor the editor if something goes
547 // TODO: don't load the whole taxonNode Object but rather a small
548 // and simple Solution
549 // FIXME: May be don't open classification which are greater than
551 selectedTaxonNodes
= taxonNodeService
.listAllNodesForClassification(classification
, 0, countNodes
);
552 countNodes
= selectedTaxonNodes
.size();
553 statusLabel
.setText(ELEMENT_COUNT
+ (countNodes
!= null ? countNodes
: UNKNOWN
));
554 viewer
.setInput(checklistEditorInput
.getTaxa());
555 // Job checkListJob = new ChecklistJob(LOADING_TAXA, selectedTaxonNodes);
556 // checkListJob.schedule(Job.LONG);
559 if (taxonNode
!= null) {
560 boolean includeUnpublished
= true;
561 selectedTaxonNodes
= taxonNodeService
.loadChildNodesOfTaxonNode(taxonNode
, NODE_INIT_STRATEGY
, true, includeUnpublished
, null);
562 countNodes
= selectedTaxonNodes
.size();
563 viewer
.setInput(checklistEditorInput
.getTaxa());
564 statusLabel
.setText(ELEMENT_COUNT
+ (countNodes
!= null ? countNodes
: UNKNOWN
));
571 public void dispose() {
572 if(conversation
!=null){
573 conversation
.unregisterForDataStoreChanges(this);
574 conversation
.close();
577 if(checklistEditorInput
!=null){
578 checklistEditorInput
.dispose();
580 dirty
.setDirty(false);
586 public void setFocus() {
587 if(viewer
!=null && viewer
.getControl()!=null && !viewer
.getControl().isDisposed()) {
588 viewer
.getControl().setFocus();
596 // * @see org.eclipse.ui.part.WorkbenchPart#showBusy(boolean)
598 // /** {@inheritDoc} */
600 // public void showBusy(boolean busy) {
601 // super.showBusy(busy);
602 // // viewer.getTable().setEnabled(!busy);
604 // partNameCache = getPartName();
605 // setPartName(String.format(Messages.ChecklistEditor_LOAD_CNT_TAXA, countNodes));
607 // if (partNameCache != null) {
608 // setPartName(partNameCache);
615 * Getter for the field <code>viewer</code>.
618 * @return a {@link org.eclipse.jface.viewers.StructuredViewer} object.
620 public StructuredViewer
getViewer() {
624 public void refresh() {
629 * This method should only be called for adding new Distribution columns and reloading the table.<br>
630 * It will hide the old distribution column and load the newly added columns.<br>
632 * <b>Notice:</b> for data update please use <b>refresh()</b>
635 @SuppressWarnings({ "unchecked", "rawtypes" })
636 public void reload(){
637 //create new Items for Dropdown menue
638 Table table
= viewer
.getTable();
639 table
.setRedraw(false);
640 SortedSet
<DefinedTermBase
> newTerms
= labelProvider
.getNamedAreas(true);
643 //check which terms are deleted and which are new.
644 TableColumn
[] columns
= viewer
.getTable().getColumns() ;
647 for (TableColumn column
: columns
){
648 if ((!PreferencesUtil
.isShowRankInChecklistEditor() && index
> 0) || (index
> 1)) {
654 areaPosition
.clear();
656 if (PreferencesUtil
.isShowRankInChecklistEditor()){
661 for (DefinedTermBase term
:newTerms
){
662 areaPosition
.put(term
.getUuid(), Integer
.valueOf(columnIndex
));
666 for (DefinedTermBase term
: newTerms
){
667 Representation rep
= term
.getPreferredRepresentation(CdmStore
.getDefaultLanguage());
669 String termLable
= rep
.getAbbreviatedLabel();
670 if (termLable
== null){
671 termLable
= rep
.getLabel();
673 if (PreferencesUtil
.isShowIdInVocabularyInChecklistEditor()){
674 if (term
.getIdInVocabulary() != null){
675 termLable
= term
.getIdInVocabulary();
678 TableViewerColumn column
= addTableViewerColumn(termLable
, 200, areaPosition
.get(term
.getUuid()), term
);
683 viewer
.setLabelProvider(labelProvider
);
684 table
.setRedraw(true);
691 private void updateColumnIndex() {
693 if (PreferencesUtil
.isShowRankInChecklistEditor()){
698 for (UUID uuid
:areaPosition
.keySet()){
699 areaPosition
.put(uuid
, columnIndex
);
710 * Getter for the field <code>service</code>.
713 * @return the service
715 public IWorkbenchSiteProgressService
getService() {
716 return TaxeditorEditorPlugin
.getDefault().getWorkbench().getService(IWorkbenchSiteProgressService
.class);
719 private SelectionAdapter
getSelectionAdapter(final TableColumn column
, final int index
) {
720 SelectionAdapter selectionAdapter
= new SelectionAdapter() {
722 public void widgetSelected(SelectionEvent e
) {
723 comparator
.setColumn(index
);
724 int dir
= viewer
.getTable().getSortDirection();
725 if (viewer
.getTable().getSortColumn() == column
) {
726 dir
= dir
== SWT
.UP ? SWT
.DOWN
: SWT
.UP
;
730 viewer
.getTable().setSortDirection(dir
);
731 viewer
.getTable().setSortColumn(column
);
735 return selectionAdapter
;
738 public void doSave(IProgressMonitor monitor
) {
740 // monitor.beginTask(Messages.ChecklistEditor_SAVE_EDITOR, 1);
741 // if (!conversation.isBound()) {
742 // conversation.bind();
745 this.checklistEditorInput
.merge();
747 //conversation.commit(true);
749 // monitor.worked(1);
756 public void init(ChecklistEditorInput input
) {
757 checklistEditorInput
= input
;
758 thisPart
.setLabel(DISTRIBUTION_EDITOR
+": " + checklistEditorInput
.getName());
759 conversation
= checklistEditorInput
.getConversation();
760 conversation
.registerForDataStoreChanges(this);
762 //propagate selection
763 selectionChangedListener
= (event
-> selService
.setSelection(
764 DistributionEditorHelper
.getDistributionForColumn(event
, areaPosition
)));
766 viewer
.addSelectionChangedListener(selectionChangedListener
);
771 private static final List
<String
> NODE_INIT_STRATEGY
= Arrays
.asList(new String
[] { "descriptions", //$NON-NLS-1$
772 "descriptions.*", "description.state", "feature", "feature.*", "childNodes", "childNodes.taxon", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
773 "childNodes.taxon.name", "taxonNodes", "taxonNodes.*", "taxonNodes.taxon.*", "taxon.*", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
774 "taxon.descriptions", "taxon.sec", "taxon.name.*", "terms", "name.*", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
775 "name.rank.representations", "name.status.type.representations", "stateData.$" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
781 * eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(
785 public void changed(Object element
) {
786 if (element
!= null) {
787 viewer
.update(element
, null);
789 if (element
instanceof Taxon
){
790 checklistEditorInput
.addTaxonToSave((Taxon
)element
);
797 * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty()
800 public void forceDirty() {
804 public void setDirty(boolean dirty
) {
805 this.dirty
.setDirty(dirty
);
811 * @see org.eclipse.ui.forms.editor.FormEditor#isDirty()
814 public boolean isDirty() {
815 return dirty
.isDirty();
820 * @return the labelProvider
822 public ChecklistLabelProvider
getLabelProvider() {
823 return labelProvider
;
827 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
830 public void update(CdmDataChangeMap arg0
) {
831 // TODO Auto-generated method stub
836 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
839 public ConversationHolder
getConversationHolder() {
844 * @see eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart#save(org.eclipse.core.runtime.IProgressMonitor)
848 public void save(IProgressMonitor monitor
) {