further migration issues for distribution editor
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / checklist / e4 / ChecklistEditorE4.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9
10 package eu.etaxonomy.taxeditor.editor.view.checklist.e4;
11
12 import java.util.ArrayList;
13 import java.util.Arrays;
14 import java.util.Collections;
15 import java.util.HashMap;
16 import java.util.List;
17 import java.util.Map;
18 import java.util.SortedSet;
19
20 import javax.annotation.PostConstruct;
21 import javax.annotation.PreDestroy;
22 import javax.inject.Inject;
23
24 import org.apache.log4j.Logger;
25 import org.eclipse.core.runtime.IProgressMonitor;
26 import org.eclipse.core.runtime.IStatus;
27 import org.eclipse.core.runtime.Status;
28 import org.eclipse.core.runtime.jobs.Job;
29 import org.eclipse.e4.ui.di.Focus;
30 import org.eclipse.e4.ui.di.Persist;
31 import org.eclipse.e4.ui.model.application.ui.MDirtyable;
32 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
33 import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
34 import org.eclipse.jface.viewers.ISelectionChangedListener;
35 import org.eclipse.jface.viewers.IStructuredSelection;
36 import org.eclipse.jface.viewers.SelectionChangedEvent;
37 import org.eclipse.jface.viewers.StructuredViewer;
38 import org.eclipse.jface.viewers.TableViewer;
39 import org.eclipse.jface.viewers.TableViewerColumn;
40 import org.eclipse.swt.SWT;
41 import org.eclipse.swt.events.ModifyListener;
42 import org.eclipse.swt.events.SelectionAdapter;
43 import org.eclipse.swt.events.SelectionEvent;
44 import org.eclipse.swt.layout.GridData;
45 import org.eclipse.swt.layout.GridLayout;
46 import org.eclipse.swt.widgets.Composite;
47 import org.eclipse.swt.widgets.Display;
48 import org.eclipse.swt.widgets.Label;
49 import org.eclipse.swt.widgets.Menu;
50 import org.eclipse.swt.widgets.MenuItem;
51 import org.eclipse.swt.widgets.Table;
52 import org.eclipse.swt.widgets.TableColumn;
53 import org.eclipse.swt.widgets.Text;
54 import org.eclipse.swt.widgets.ToolBar;
55 import org.eclipse.swt.widgets.ToolItem;
56 import org.eclipse.ui.IEditorInput;
57 import org.eclipse.ui.IMemento;
58 import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
59
60 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
61 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
62 import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
63 import eu.etaxonomy.cdm.api.service.ITaxonService;
64 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
65 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
66 import eu.etaxonomy.cdm.model.taxon.Classification;
67 import eu.etaxonomy.cdm.model.taxon.Taxon;
68 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
69 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
70 import eu.etaxonomy.taxeditor.editor.EditorUtil;
71 import eu.etaxonomy.taxeditor.editor.SimpleSelectionProvider;
72 import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
73 import eu.etaxonomy.taxeditor.editor.l10n.Messages;
74 import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistContentProvider;
75 import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditorComparator;
76 import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditorInput;
77 import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistLabelProvider;
78 import eu.etaxonomy.taxeditor.editor.view.checklist.filter.ChecklistEditorFilter;
79 import eu.etaxonomy.taxeditor.editor.view.checklist.listener.ChecklistFocusListener;
80 import eu.etaxonomy.taxeditor.editor.view.checklist.listener.ChecklistModifyListener;
81 import eu.etaxonomy.taxeditor.model.IContextListener;
82 import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
83 import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
84 import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
85 import eu.etaxonomy.taxeditor.model.MessagingUtils;
86 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
87 import eu.etaxonomy.taxeditor.preference.Resources;
88 import eu.etaxonomy.taxeditor.store.CdmStore;
89
90 /**
91 *
92 * @author k.luther
93 *
94 */
95 public class ChecklistEditorE4 implements IPartContentHasFactualData, IConversationEnabled,
96 IContextListener, IDirtyMarkable, IPartContentHasDetails{
97
98 private static final String DISTRIBUTION_EDITOR = "Distribution Editor";
99 private static final String LOADING_TAXA = Messages.ChecklistEditor_LOAD_TAXA;
100 private static final String UNKNOWN = Messages.ChecklistEditor_UNKNOWN;
101 private static final String ELEMENT_COUNT = Messages.ChecklistEditor_ELEMENT_COUNT;
102 public static final String TYPE_FILTER_TEXT = "type filter text"; //$NON-NLS-1$
103
104 private static final Logger logger = Logger.getLogger(ChecklistEditorE4.class);
105
106
107 // private class ChecklistJob extends Job {
108 //
109 // private List<TaxonNode> taxonNodes;
110 //
111 // /**
112 // * @param name
113 // */
114 // public ChecklistJob(String title, List<TaxonNode> listTaxonNodes) {
115 // super(title);
116 // this.taxonNodes = listTaxonNodes;
117 //
118 //
119 // }
120 //
121 // /*
122 // * (non-Javadoc)
123 // *
124 // * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.
125 // * IProgressMonitor)
126 // */
127 // @Override
128 // public IStatus run(final IProgressMonitor monitor) {
129 // try {
130 // logger.debug("Begin of eclipse core runtime Job to Retrieve datasources"); //$NON-NLS-1$
131 // monitor.beginTask(Messages.ChecklistEditor_RETRIEVE_NODES, taxonNodes.size() + 1);
132 //
133 // final List<Taxon> taxonList = new ArrayList<Taxon>();
134 //
135 // for (TaxonNode taxonNode : taxonNodes) {
136 // HibernateProxyHelper hh = new HibernateProxyHelper();
137 // Taxon taxon = hh.deproxy(taxonNode.getTaxon(), Taxon.class);
138 // taxonList.add(taxon);
139 // }
140 // // set View input
141 // Display.getDefault().asyncExec(new Runnable() {
142 //
143 // @Override
144 // public void run() {
145 // viewer.setInput(taxonList);
146 // }
147 // });
148 // monitor.worked(1);
149 //
150 // } finally {
151 // monitor.done();
152 // taxonNodes = null;
153 // }
154 // return Status.OK_STATUS;
155 // }
156 // }
157
158 /**
159 * Constant
160 * <code>ID="eu.etaxonomy.taxeditor.store.datasource"{trunked}</code>
161 */
162 public static String ID = "eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditor"; //$NON-NLS-1$
163
164 private TableViewer viewer;
165
166 private String partNameCache;
167
168 //FIXME E4 migrate/delete ater full migration
169
170 private IWorkbenchSiteProgressService service;
171
172 private ITaxonNodeService taxonNodeService;
173
174 private ChecklistEditorComparator comparator;
175
176 private ChecklistEditorInput checklistEditorInput;
177
178 private SimpleSelectionProvider simpleSelectionProvider;
179
180 private ConversationHolder conversation;
181
182 private Integer countNodes;
183
184 private List<TaxonNode> selectedTaxonNodes;
185
186 @Inject
187 private MPart thisPart;
188
189 @Inject
190 private MDirtyable dirty;
191
192 @Inject
193 private ESelectionService selService;
194
195 private ISelectionChangedListener selectionChangedListener;
196
197 private ChecklistEditorFilter filter;
198
199 private Menu headerMenu;
200
201 private Label statusLabel;
202
203 // private final ICdmEntitySession cdmEntitySession;
204
205 private ChecklistLabelProvider labelProvider;
206
207 private SortedSet<DefinedTermBase> terms = null;
208 private ToolItem toolItem;
209 private ChecklistDropdownSelectionListenerE4 dropListener;
210
211 /**
212 * @return the selectedTaxonNodes
213 */
214 public List<TaxonNode> getSelectedTaxonNodes() {
215 return selectedTaxonNodes;
216 }
217
218 /**
219 * @param selectedTaxonNodes
220 * the selectedTaxonNodes to set
221 */
222 public void setSelectedTaxonNodes(List<TaxonNode> selectedTaxonNodes) {
223 this.selectedTaxonNodes = selectedTaxonNodes;
224 }
225
226 @Inject
227 public ChecklistEditorE4() {
228 }
229
230 /** {@inheritDoc} */
231 @PostConstruct
232 public void createPartControl(Composite parent) {
233 if (!CdmStore.isActive()){
234 return;
235 }
236 taxonNodeService = CdmStore.getService(ITaxonNodeService.class);
237 viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
238
239 // viewer.addSelectionChangedListener(new ISelectionChangedListener() {
240 // @Override
241 // public void selectionChanged(SelectionChangedEvent event) {
242 // IStructuredSelection selection = viewer.getStructuredSelection();
243 // Object firstElement = selection.getFirstElement();
244 // // do something with it
245 // }
246 //
247 //
248 // });
249
250
251
252 labelProvider = new ChecklistLabelProvider(this.viewer);
253
254 terms = labelProvider.getNamedAreas();
255 if (terms == null){
256 MessagingUtils.informationDialog(Messages.ChecklistEditor_NO_AREAS, Messages.ChecklistEditor_NO_AREAS_MESSAGE);
257 this.dispose();
258 return;
259 }
260 filter = new ChecklistEditorFilter();
261 createTopComposite(parent);
262 }
263
264 /**
265 * @param parent
266 */
267 private void createTopComposite(Composite parent) {
268 GridLayout gridLayout = new GridLayout(3, false);
269 gridLayout.marginWidth = 0;
270 gridLayout.marginHeight = 0;
271 parent.setLayout(gridLayout);
272
273 final Text searchText = createSearchBar(parent);
274 createToolbar(parent);
275
276 // getSite().setSelectionProvider(viewer);
277
278 final ModifyListener modifyListener = new ChecklistModifyListener(viewer, filter, searchText);
279
280 searchText.addFocusListener(new ChecklistFocusListener(searchText, modifyListener));
281 searchText.addModifyListener(modifyListener);
282 createGridDataForViewerLayout();
283
284 viewer.addFilter(filter);
285 createTable();
286
287 viewer.setContentProvider(new ChecklistContentProvider());
288 viewer.setLabelProvider(this.labelProvider);
289 comparator = new ChecklistEditorComparator();
290 viewer.setComparator(comparator);
291
292 createStatusBar(parent);
293 }
294
295 private void createGridDataForViewerLayout() {
296 GridData gridData = new GridData();
297 gridData.verticalAlignment = GridData.FILL;
298 gridData.horizontalSpan = 3;
299 gridData.grabExcessHorizontalSpace = true;
300 gridData.grabExcessVerticalSpace = true;
301 gridData.horizontalAlignment = GridData.FILL;
302 viewer.getControl().setLayoutData(gridData);
303 }
304
305 /**
306 * @param parent
307 * @return
308 */
309 private Text createSearchBar(Composite parent) {
310 Label searchLabel = new Label(parent, SWT.NONE);
311 searchLabel.setText(Messages.ChecklistEditor_SEARCH);
312 final Text searchText = new Text(parent, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH | SWT.CANCEL);
313 searchText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
314 searchText.setForeground(EditorUtil.getColor(Resources.SEARCH_VIEW_FOREGROUND));
315 searchText.setText(TYPE_FILTER_TEXT);
316 return searchText;
317 }
318
319 /**
320 * @param parent
321 */
322 private void createToolbar(Composite parent) {
323 ToolBar toolBar = new ToolBar(parent, SWT.NONE);
324 toolItem = new ToolItem(toolBar, SWT.DROP_DOWN | SWT.BORDER);
325 toolItem.setText(Messages.ChecklistEditor_DIST_STATUS);
326 toolItem.setToolTipText(Messages.ChecklistEditor_DIST_STATUS_TOOLTIP);
327 createToolbarItems();
328 toolItem.addSelectionListener(dropListener);
329 toolBar.pack();
330 }
331
332 private void createToolbarItems() {
333 dropListener = new ChecklistDropdownSelectionListenerE4(toolItem, this, terms);
334
335 for (DefinedTermBase<DefinedTermBase> term : terms) {
336 if(term!=null){
337 dropListener.add(term);
338 }
339 }
340 }
341
342 private void createStatusBar(Composite composite) {
343 GridData gridData = new GridData();
344 gridData.horizontalSpan = 3;
345 gridData.grabExcessHorizontalSpace = true;
346 gridData.horizontalAlignment = GridData.FILL;
347
348 statusLabel = new Label(composite, SWT.LEFT);
349 statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
350 statusLabel.setLayoutData(gridData);
351 }
352
353 private void createTable() {
354 Table table = viewer.getTable();//new Table(parent, viewer.getTable().getStyle());
355 List<String> titles = new ArrayList<String>();
356 List<Integer> bounds = new ArrayList<Integer>();
357 if (PreferencesUtil.isShowRankInChecklistEditor()){
358 Collections.addAll(titles, Messages.ChecklistEditor_TAXON, Messages.ChecklistEditor_RANK);
359 Collections.addAll(bounds, 300, 200);
360 } else{
361 Collections.addAll(titles, Messages.ChecklistEditor_TAXON);
362 Collections.addAll(bounds, 300);
363 }
364
365
366 Map<Integer, Boolean> restoreValuesForColumnWidth = restoreValuesForColumnWidth(titles, bounds);
367 createInitalDistributionColumns(table, titles, bounds, restoreValuesForColumnWidth);
368 table.setSortDirection(SWT.DOWN);
369 table.setHeaderVisible(true);
370 table.setLinesVisible(true);
371 }
372 /**
373 * This method creates initially the distribution columns for a table. It should only be called for creation.<br>
374 *<p>
375 *
376 *<b>Notice:</b> If you want to add additional columns later please use <b>addTableViewerColumn()</b>
377 *
378 * @param table
379 * @param titles
380 * @param bounds
381 * @param restoreValuesForColumnWidth
382 */
383 private void createInitalDistributionColumns(Table table,
384 List<String> titles, List<Integer> bounds, Map<Integer, Boolean> restoreValuesForColumnWidth) {
385 for (int columnIndex = 0; columnIndex < titles.size(); columnIndex++) {
386 TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
387 column.getColumn().setText(titles.get(columnIndex));
388 column.getColumn().setWidth(bounds.get(columnIndex));
389 column.getColumn().setResizable(true);
390 column.getColumn().setMoveable(true);
391 column.getColumn().addSelectionListener(getSelectionAdapter(column.getColumn(), columnIndex));
392 if (columnIndex == 0) {
393 table.setSortColumn(column.getColumn());
394 }
395 if (columnIndex == 1 && PreferencesUtil.isShowRankInChecklistEditor()) {
396 /** uncommented it for now because no rank editing is wanted **/
397 // column.setEditingSupport(new RankEditingSupport(viewer, this));
398 }
399 if ((columnIndex == 1 && !PreferencesUtil.isShowRankInChecklistEditor()) || columnIndex >= 2 ) {
400 //read PrefrenceStore to setWidth according to last saved state
401 if(restoreValuesForColumnWidth.get(columnIndex)){
402 column.getColumn().setWidth(50);
403 }else{
404 column.getColumn().setWidth(50);
405 }
406 column.setEditingSupport(new DistributionEditingSupportE4(viewer, this, columnIndex));
407 }
408 }
409 }
410
411 /**
412 * This methods loads the last opened distribution columns for the table viewer from the prefrence store.<br>
413 *<p>
414 * <b>Notice:</b> It adds also the TitleCache to the titles list for the header of each column.<p>
415 *
416 * @param titles
417 * @param bounds
418 * @return Map<Integer, Boolean>
419 */
420 private Map<Integer, Boolean> restoreValuesForColumnWidth(List<String> titles,
421 List<Integer> bounds) {
422 Map<Integer, Boolean> restoreColumnWidth = new HashMap<Integer, Boolean>();
423 if (terms != null) {
424 int columnIndex;
425 if (PreferencesUtil.isShowRankInChecklistEditor()){
426 columnIndex = 2;
427 } else{
428 columnIndex = 1;
429 }
430 for (DefinedTermBase<DefinedTermBase> term : terms) {
431 if(term != null){
432 restoreColumnWidth.put(columnIndex, PreferencesUtil.getPreferenceStore().getBoolean(term.getUuid().toString()));
433 if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
434 if (term.getIdInVocabulary() != null){
435 titles.add(term.getIdInVocabulary());
436 } else{
437 titles.add(term.getTitleCache());
438 }
439 }else{
440 titles.add(term.getTitleCache());
441 }
442 bounds.add(200);
443 columnIndex++;
444 }
445 }
446 }
447 return restoreColumnWidth;
448 }
449
450 /**
451 * This method adds new DistributionColumns to an existing table.
452 *
453 * @param title
454 * @param bound
455 * @param colNumber
456 * @return
457 */
458 private TableViewerColumn addTableViewerColumn(String title, int bound, final int colNumber) {
459 final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
460 final TableColumn column = viewerColumn.getColumn();
461 column.setText(title);
462 column.setWidth(200);
463 viewerColumn.setEditingSupport(new DistributionEditingSupportE4(viewer, this, colNumber));
464 column.setResizable(true);
465 column.setMoveable(true);
466 return viewerColumn;
467 }
468
469
470
471 /**
472 *
473 * pull data from database and set input for view
474 *
475 */
476 private void loadDataInput() {
477 Classification classification = checklistEditorInput.getClassification();
478 TaxonNode taxonNode = checklistEditorInput.getTaxonNode();
479 if (classification != null && taxonNode == null) {
480 countNodes = taxonNodeService.countAllNodesForClassification(classification);
481 // statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
482 // This should not kill the view nor the editor if something goes
483 // wrong
484 // TODO: don't load the whole taxonNode Object but rather a small
485 // and simple Solution
486 // FIXME: May be don't open classification which are greater than
487 // 3000 Taxa
488 selectedTaxonNodes = taxonNodeService.listAllNodesForClassification(classification, 0, countNodes);
489 countNodes = selectedTaxonNodes.size();
490 statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
491 viewer.setInput(checklistEditorInput.getTaxa());
492 // Job checkListJob = new ChecklistJob(LOADING_TAXA, selectedTaxonNodes);
493 // checkListJob.schedule(Job.LONG);
494
495 }
496 if (taxonNode != null) {
497 selectedTaxonNodes = taxonNodeService.loadChildNodesOfTaxonNode(taxonNode, NODE_INIT_STRATEGY, true, null);
498 countNodes = selectedTaxonNodes.size();
499 viewer.setInput(checklistEditorInput.getTaxa());
500 statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
501 // Job checkListJob = new ChecklistJob(LOADING_TAXA, selectedTaxonNodes);
502 // checkListJob.schedule(Job.LONG);
503 // getService().schedule(new ChecklistJob(LOADING_TAXA, selectedTaxonNodes), Job.LONG);
504 }
505 }
506
507 /** {@inheritDoc} */
508 @PreDestroy
509 public void dispose() {
510 // if(checklistEditorInput!=null){
511 // this.checklistEditorInput.getConversation().unregisterForDataStoreChanges(this.checklistEditorInput);
512 // }
513
514 if(conversation!=null){
515 conversation.unregisterForDataStoreChanges(this);
516 conversation.unbind();
517 }
518 //conversation.close();
519 conversation = null;
520 }
521
522 /** {@inheritDoc} */
523 @Focus
524 public void setFocus() {
525 if(viewer!=null && viewer.getControl()!=null && !viewer.getControl().isDisposed())
526 viewer.getControl().setFocus();
527 }
528
529 //FIXME E4 migrate
530 // /*
531 // * (non-Javadoc)
532 // *
533 // * @see org.eclipse.ui.part.WorkbenchPart#showBusy(boolean)
534 // */
535 // /** {@inheritDoc} */
536 // @Override
537 // public void showBusy(boolean busy) {
538 // super.showBusy(busy);
539 // // viewer.getTable().setEnabled(!busy);
540 // if (busy) {
541 // partNameCache = getPartName();
542 // setPartName(String.format(Messages.ChecklistEditor_LOAD_CNT_TAXA, countNodes));
543 // } else {
544 // if (partNameCache != null) {
545 // setPartName(partNameCache);
546 // }
547 // }
548 // }
549
550 /**
551 * <p>
552 * Getter for the field <code>viewer</code>.
553 * </p>
554 *
555 * @return a {@link org.eclipse.jface.viewers.StructuredViewer} object.
556 */
557 public StructuredViewer getViewer() {
558 return viewer;
559 }
560
561 public void refresh() {
562 viewer.refresh();
563 }
564
565 /**
566 * This method should only be called for adding new Distribution columns and reloading the table.<br>
567 * It will hide the old distribution column and load the newly added columns.<br>
568 * <p>
569 * <b>Notice:</b> for data update please use <b>refresh()</b>
570 *
571 */
572 @SuppressWarnings({ "unchecked", "rawtypes" })
573 public void reload(){
574 //create new Items for Dropdown menue
575 Table table = viewer.getTable();
576 table.setRedraw(false);
577 SortedSet<DefinedTermBase> oldTerms = terms;
578
579 // if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
580 //
581 // } else{
582 // terms = (SortedSet<DefinedTermBase>) labelProvider.getTermsOrderedByLabels(labelProvider.getNamedAreas(), CdmStore.getDefaultLanguage());
583 // }
584 SortedSet<DefinedTermBase> newTerms = labelProvider.getNamedAreas();
585 toolItem.removeSelectionListener(dropListener);
586 hideDistributionColumns(oldTerms);
587 createToolbarItems();
588 toolItem.addSelectionListener(dropListener);
589 for(DefinedTermBase term:newTerms){
590 int count = viewer.getTable().getColumnCount();
591 addTableViewerColumn(term.getTitleCache(), 200, count);
592 acitivateNewColumnInDropDownMenu(term);
593 }
594 viewer.setLabelProvider(labelProvider);
595 // getService().schedule(new ChecklistJob(LOADING_TAXA, selectedTaxonNodes), Job.LONG);
596 table.setRedraw(true);
597 viewer.refresh();
598 }
599
600 private void acitivateNewColumnInDropDownMenu(DefinedTermBase term) {
601 Menu menu = dropListener.getMenu();
602 MenuItem[] items = menu.getItems();
603 for(MenuItem item: items){
604 if(item.getText().equalsIgnoreCase(term.getTitleCache())){
605 item.setSelection(true);
606 PreferencesUtil.getPreferenceStore().setValue(term.getUuid().toString(), true);
607 }
608 }
609 }
610
611 private void hideDistributionColumns(SortedSet<DefinedTermBase> oldTerms) {
612 TableColumn[] columns = viewer.getTable().getColumns();
613 for(int i=4; i<columns.length; i++){
614 //remove all columns
615 columns[i].dispose();
616 Menu menu = dropListener.getMenu();
617 int itemCount = menu.getItemCount();
618 MenuItem item = menu.getItem(i-3);
619 item.setSelection(false);
620 }
621 if(oldTerms != null){
622 for(DefinedTermBase term : oldTerms){
623 PreferencesUtil.getPreferenceStore().setValue(term.getUuid().toString(), false);
624 }
625 }
626 }
627
628 /**
629 * <p>
630 * Getter for the field <code>service</code>.
631 * </p>
632 *
633 * @return the service
634 */
635 public IWorkbenchSiteProgressService getService() {
636 return TaxeditorEditorPlugin.getDefault().getWorkbench().getService(IWorkbenchSiteProgressService.class);
637 }
638
639 private SelectionAdapter getSelectionAdapter(final TableColumn column, final int index) {
640 SelectionAdapter selectionAdapter = new SelectionAdapter() {
641 @Override
642 public void widgetSelected(SelectionEvent e) {
643 comparator.setColumn(index);
644 int dir = viewer.getTable().getSortDirection();
645 if (viewer.getTable().getSortColumn() == column) {
646 dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
647 } else {
648 dir = SWT.DOWN;
649 }
650 viewer.getTable().setSortDirection(dir);
651 viewer.getTable().setSortColumn(column);
652 viewer.refresh();
653 }
654 };
655 return selectionAdapter;
656 }
657
658 @Persist
659 public void doSave(IProgressMonitor monitor) {
660 try {
661 monitor.beginTask(Messages.ChecklistEditor_SAVE_EDITOR, 1);
662 if (!conversation.isBound()) {
663 conversation.bind();
664 }
665 this.checklistEditorInput.merge();
666 //this.checklistEditorInput.merge();
667 conversation.commit(true);
668 setDirty(false);
669 monitor.worked(1);
670 } finally {
671 monitor.done();
672 }
673
674 }
675
676 public void init(IEditorInput input) {
677 if (input instanceof ChecklistEditorInput) {
678 checklistEditorInput = (ChecklistEditorInput) input;
679 thisPart.setLabel(DISTRIBUTION_EDITOR+": " + checklistEditorInput.getName());
680 conversation = checklistEditorInput.getConversation();
681 conversation.registerForDataStoreChanges(this);
682 }
683 simpleSelectionProvider = new SimpleSelectionProvider();
684
685 //propagate selection
686 selectionChangedListener = (event -> selService.setSelection(event));
687 viewer.addSelectionChangedListener(selectionChangedListener);
688
689
690 loadDataInput();
691 }
692
693
694 /*
695 * (non-Javadoc)
696 *
697 * @see
698 * eu.etaxonomy.taxeditor.model.IContextListener#contextAboutToStop(org.
699 * eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
700 */
701
702 @Override
703 public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
704
705 }
706
707 /*
708 * (non-Javadoc)
709 *
710 * @see
711 * eu.etaxonomy.taxeditor.model.IContextListener#contextStop(org.eclipse
712 * .ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
713 */
714 @Override
715 public void contextStop(IMemento memento, IProgressMonitor monitor) {
716 // IStructuredSelection sel = (IStructuredSelection) this.viewer.getSelection();
717 // if (sel.isEmpty()) {
718 // return;
719 // }
720 // memento = memento.createChild("tree-selections");
721 // Iterator iter = sel.iterator();
722 // while (iter.hasNext()) {
723 // String nodeName = (String) iter.next();
724 // memento.createChild("selected-nodes", nodeName);
725 // }
726 }
727
728 /*
729 * (non-Javadoc)
730 *
731 * @see
732 * eu.etaxonomy.taxeditor.model.IContextListener#contextStart(org.eclipse
733 * .ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
734 */
735 @Override
736 public void contextStart(IMemento memento, IProgressMonitor monitor) {
737
738 }
739
740 /*
741 * (non-Javadoc)
742 *
743 * @see
744 * eu.etaxonomy.taxeditor.model.IContextListener#contextRefresh(org.eclipse
745 * .core.runtime.IProgressMonitor)
746 */
747 @Override
748 public void contextRefresh(IProgressMonitor monitor) {
749 }
750
751 /*
752 * (non-Javadoc)
753 *
754 * @see
755 * eu.etaxonomy.taxeditor.model.IContextListener#workbenchShutdown(org.eclipse
756 * .ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
757 */
758 @Override
759 public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
760 conversation.clear();
761 conversation.close();
762 conversation = null;
763 }
764
765 private static final List<String> NODE_INIT_STRATEGY = Arrays.asList(new String[] { "descriptions", //$NON-NLS-1$
766 "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$
767 "childNodes.taxon.name", "taxonNodes", "taxonNodes.*", "taxonNodes.taxon.*", "taxon.*", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
768 "taxon.descriptions", "taxon.sec", "taxon.name.*", "terms", "name.*", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
769 "name.rank.representations", "name.status.type.representations", "stateData.$" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
770
771 /*
772 * (non-Javadoc)
773 *
774 * @see
775 * eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(
776 * java.lang.Object)
777 */
778 @Override
779 public void changed(Object element) {
780 if (element != null) {
781 viewer.update(element, null);
782 setDirty(true);
783 }
784 }
785
786 /* (non-Javadoc)
787 * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty()
788 */
789 @Override
790 public void forceDirty() {
791 changed(null);
792 }
793
794 public void setDirty(boolean dirty) {
795 this.dirty.setDirty(dirty);
796 }
797
798 /*
799 * (non-Javadoc)
800 *
801 * @see org.eclipse.ui.forms.editor.FormEditor#isDirty()
802 */
803 public boolean isDirty() {
804 return dirty.isDirty();
805 }
806
807 /* (non-Javadoc)
808 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
809 */
810
811
812 // /* (non-Javadoc)
813 // * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
814 // */
815 // @Override
816 // public <T extends CdmBase> Collection<T> getRootEntities() {
817 // // TODO Auto-generated method stub
818 // return null;
819 // }
820 //
821 // /* (non-Javadoc)
822 // * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
823 // */
824 // @Override
825 // public Map<Object, List<String>> getPropertyPathsMap() {
826 // // TODO Auto-generated method stub
827 // return null;
828 // }
829
830 /**
831 * @return the labelProvider
832 */
833 public ChecklistLabelProvider getLabelProvider() {
834 return labelProvider;
835 }
836
837 /* (non-Javadoc)
838 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
839 */
840 @Override
841 public void update(CdmDataChangeMap arg0) {
842 // TODO Auto-generated method stub
843
844 }
845
846 /* (non-Javadoc)
847 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
848 */
849 @Override
850 public ConversationHolder getConversationHolder() {
851
852 return conversation;
853 }
854
855
856 }