Project

General

Profile

Download (25.4 KB) Statistics
| Branch: | Tag: | Revision:
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.e4.ui.di.Focus;
27
import org.eclipse.e4.ui.di.Persist;
28
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
29
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
30
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
31
import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
32
import org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter;
33
import org.eclipse.jface.viewers.ISelectionChangedListener;
34
import org.eclipse.jface.viewers.StructuredViewer;
35
import org.eclipse.jface.viewers.TableViewer;
36
import org.eclipse.jface.viewers.TableViewerColumn;
37
import org.eclipse.jface.viewers.TableViewerEditor;
38
import org.eclipse.jface.viewers.TableViewerFocusCellManager;
39
import org.eclipse.swt.SWT;
40
import org.eclipse.swt.events.ModifyListener;
41
import org.eclipse.swt.events.SelectionAdapter;
42
import org.eclipse.swt.events.SelectionEvent;
43
import org.eclipse.swt.layout.GridData;
44
import org.eclipse.swt.layout.GridLayout;
45
import org.eclipse.swt.widgets.Composite;
46
import org.eclipse.swt.widgets.Label;
47
import org.eclipse.swt.widgets.Menu;
48
import org.eclipse.swt.widgets.MenuItem;
49
import org.eclipse.swt.widgets.Table;
50
import org.eclipse.swt.widgets.TableColumn;
51
import org.eclipse.swt.widgets.Text;
52
import org.eclipse.swt.widgets.ToolBar;
53
import org.eclipse.swt.widgets.ToolItem;
54
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
55

    
56
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
57
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
58
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
59
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
60
import eu.etaxonomy.cdm.model.taxon.Classification;
61
import eu.etaxonomy.cdm.model.taxon.Taxon;
62
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
63
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
64
import eu.etaxonomy.taxeditor.editor.EditorUtil;
65
import eu.etaxonomy.taxeditor.editor.IDistributionEditor;
66
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
67
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
68
import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistContentProvider;
69
import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditorComparator;
70
import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditorInput;
71
import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistLabelProvider;
72
import eu.etaxonomy.taxeditor.editor.view.checklist.filter.ChecklistEditorFilter;
73
import eu.etaxonomy.taxeditor.editor.view.checklist.listener.ChecklistFocusListener;
74
import eu.etaxonomy.taxeditor.editor.view.checklist.listener.ChecklistModifyListener;
75
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
76
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
77
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
78
import eu.etaxonomy.taxeditor.model.MessagingUtils;
79
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
80
import eu.etaxonomy.taxeditor.preference.Resources;
81
import eu.etaxonomy.taxeditor.store.CdmStore;
82
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
83

    
84
/**
85
 *
86
 * @author k.luther
87
 *
88
 */
89
public class ChecklistEditorE4 implements IPartContentHasFactualData, IConversationEnabled,
90
       IDirtyMarkable, IPartContentHasDetails, IE4SavablePart, IDistributionEditor{
91

    
92
    private static final String DISTRIBUTION_EDITOR = "Distribution Editor";
93
	private static final String LOADING_TAXA = Messages.ChecklistEditor_LOAD_TAXA;
94
    private static final String UNKNOWN = Messages.ChecklistEditor_UNKNOWN;
95
    private static final String ELEMENT_COUNT = Messages.ChecklistEditor_ELEMENT_COUNT;
96
    public static final String TYPE_FILTER_TEXT = "type filter text"; //$NON-NLS-1$
97

    
98
    private static final Logger logger = Logger.getLogger(ChecklistEditorE4.class);
99

    
100
    /**
101
     * Constant
102
     * <code>ID="eu.etaxonomy.taxeditor.store.datasource"{trunked}</code>
103
     */
104
    public static String ID = "eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditor"; //$NON-NLS-1$
105

    
106
    private TableViewer viewer;
107

    
108
    private ITaxonNodeService taxonNodeService;
109

    
110
    private ChecklistEditorComparator comparator;
111

    
112
    private ChecklistEditorInput checklistEditorInput;
113

    
114
    private ConversationHolder conversation;
115

    
116
    private Integer countNodes;
117

    
118
    private List<TaxonNode> selectedTaxonNodes;
119

    
120
    @Inject
121
    private MPart thisPart;
122

    
123
    @Inject
124
    private MDirtyable dirty;
125

    
126
    @Inject
127
    private ESelectionService selService;
128

    
129
    private ISelectionChangedListener selectionChangedListener;
130

    
131
    private ChecklistEditorFilter filter;
132

    
133
    private Label statusLabel;
134

    
135
    private ChecklistLabelProvider labelProvider;
136

    
137
    private SortedSet<DefinedTermBase> terms = null;
138
	private ToolItem toolItem;
139
	private ChecklistDropdownSelectionListenerE4 dropListener;
140
	private Text searchText;
141

    
142

    
143
    /**
144
     * @return the selectedTaxonNodes
145
     */
146
    public List<TaxonNode> getSelectedTaxonNodes() {
147
        return selectedTaxonNodes;
148
    }
149

    
150
    /**
151
     * @param selectedTaxonNodes
152
     *            the selectedTaxonNodes to set
153
     */
154
    public void setSelectedTaxonNodes(List<TaxonNode> selectedTaxonNodes) {
155
        this.selectedTaxonNodes = selectedTaxonNodes;
156
    }
157

    
158
    @Inject
159
    public ChecklistEditorE4() {
160
    }
161

    
162
    /** {@inheritDoc} */
163
    @PostConstruct
164
    public void createPartControl(Composite parent) {
165
    	if (!CdmStore.isActive()){
166
            return;
167
        }
168
        taxonNodeService = CdmStore.getService(ITaxonNodeService.class);
169
        filter = new ChecklistEditorFilter();
170
        createTopComposite(parent);
171
        viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
172

    
173
        //the focuzsCellManager should return the distribution!!!
174
        TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(viewer, new FocusCellOwnerDrawHighlighter (viewer));
175
        TableViewerEditor.create(viewer, focusCellManager, new ColumnViewerEditorActivationStrategy(viewer), TableViewerEditor.KEYBOARD_ACTIVATION);
176

    
177

    
178
//        viewer.addSelectionChangedListener(new ISelectionChangedListener() {
179
//        	  @Override
180
//        	  public void selectionChanged(SelectionChangedEvent event) {
181
//        	    IStructuredSelection selection = viewer.getStructuredSelection();
182
//        	    Object firstElement = selection.getFirstElement();
183
//        	    // do something with it
184
//        	  }
185
//
186
//
187
//        	});
188

    
189

    
190

    
191
        labelProvider = new ChecklistLabelProvider(this.viewer);
192

    
193
        terms = labelProvider.getNamedAreas();
194
        if (terms == null){
195
			MessagingUtils.informationDialog(Messages.ChecklistEditor_NO_AREAS, Messages.ChecklistEditor_NO_AREAS_MESSAGE);
196
			this.dispose();
197
			return;
198
		}
199

    
200

    
201
        viewer.addFilter(filter);
202
        createTable();
203

    
204
        viewer.setContentProvider(new ChecklistContentProvider());
205
        viewer.setLabelProvider(this.labelProvider);
206
        comparator = new ChecklistEditorComparator();
207
        viewer.setComparator(comparator);
208
        final ModifyListener modifyListener = new ChecklistModifyListener(viewer, filter, searchText);
209

    
210
        searchText.addFocusListener(new ChecklistFocusListener(searchText, modifyListener));
211
        searchText.addModifyListener(modifyListener);
212
        createGridDataForViewerLayout();
213
        createStatusBar(parent);
214
        createToolbar(parent);
215
    }
216

    
217
    /**
218
     * @param parent
219
     */
220
    private void createTopComposite(Composite parent) {
221
        GridLayout gridLayout = new GridLayout(3, false);
222
        gridLayout.marginWidth = 0;
223
        gridLayout.marginHeight = 0;
224
        parent.setLayout(gridLayout);
225

    
226
       searchText = createSearchBar(parent);
227

    
228

    
229
       // getSite().setSelectionProvider(viewer);
230

    
231

    
232

    
233

    
234

    
235
    }
236

    
237
	private void createGridDataForViewerLayout() {
238
		GridData gridData = new GridData();
239
		gridData.verticalAlignment = GridData.FILL;
240
        gridData.horizontalSpan = 3;
241
        gridData.grabExcessHorizontalSpace = true;
242
        gridData.grabExcessVerticalSpace = true;
243
        gridData.horizontalAlignment = GridData.FILL;
244
        viewer.getControl().setLayoutData(gridData);
245
	}
246

    
247
    /**
248
     * @param parent
249
     * @return
250
     */
251
    private Text createSearchBar(Composite parent) {
252
        Label searchLabel = new Label(parent, SWT.NONE);
253
        searchLabel.setText(Messages.ChecklistEditor_SEARCH);
254
        final Text searchText = new Text(parent, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH | SWT.CANCEL);
255
        searchText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
256
        searchText.setForeground(EditorUtil.getColor(Resources.SEARCH_VIEW_FOREGROUND));
257
        searchText.setText(TYPE_FILTER_TEXT);
258
        return searchText;
259
    }
260

    
261
    /**
262
     * @param parent
263
     */
264
    private void createToolbar(Composite parent) {
265
        ToolBar toolBar = new ToolBar(parent, SWT.NONE);
266
        toolItem = new ToolItem(toolBar, SWT.DROP_DOWN | SWT.BORDER);
267
        toolItem.setText(Messages.ChecklistEditor_DIST_STATUS);
268
        toolItem.setToolTipText(Messages.ChecklistEditor_DIST_STATUS_TOOLTIP);
269
        createToolbarItems();
270
        toolItem.addSelectionListener(dropListener);
271
        toolBar.pack();
272
    }
273

    
274
	private void createToolbarItems() {
275
		dropListener = new ChecklistDropdownSelectionListenerE4(toolItem, this, terms);
276

    
277
        for (DefinedTermBase<DefinedTermBase> term : terms) {
278
            if(term!=null){
279
                dropListener.add(term);
280
            }
281
        }
282
	}
283

    
284
    private void createStatusBar(Composite composite) {
285
        GridData gridData = new GridData();
286
        gridData.horizontalSpan = 3;
287
        gridData.grabExcessHorizontalSpace = true;
288
        gridData.horizontalAlignment = GridData.FILL;
289

    
290
        statusLabel = new Label(composite, SWT.LEFT);
291
        statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
292
        statusLabel.setLayoutData(gridData);
293
    }
294

    
295
    private void createTable() {
296
        Table table = viewer.getTable();//new Table(parent, viewer.getTable().getStyle());
297
        List<String> titles = new ArrayList<String>();
298
        List<Integer> bounds = new ArrayList<Integer>();
299
        if (PreferencesUtil.isShowRankInChecklistEditor()){
300
            Collections.addAll(titles, Messages.ChecklistEditor_TAXON,  Messages.ChecklistEditor_RANK);
301
            Collections.addAll(bounds, 300, 200);
302
        } else{
303
            Collections.addAll(titles, Messages.ChecklistEditor_TAXON);
304
            Collections.addAll(bounds, 300);
305
        }
306

    
307

    
308
        Map<Integer, Boolean> restoreValuesForColumnWidth = restoreValuesForColumnWidth(titles, bounds);
309
        createInitalDistributionColumns(table, titles, bounds, restoreValuesForColumnWidth);
310
        table.setSortDirection(SWT.DOWN);
311
        table.setHeaderVisible(true);
312
        table.setLinesVisible(true);
313
	}
314
    /**
315
     * This method creates initially the distribution columns for a table. It should only be called for creation.<br>
316
     *<p>
317
     *
318
     *<b>Notice:</b> If you want to add additional columns later please use <b>addTableViewerColumn()</b>
319
     *
320
     * @param table
321
     * @param titles
322
     * @param bounds
323
     * @param restoreValuesForColumnWidth
324
     */
325
	private void createInitalDistributionColumns(Table table,
326
			List<String> titles, List<Integer> bounds, Map<Integer, Boolean> restoreValuesForColumnWidth) {
327
		for (int columnIndex = 0; columnIndex < titles.size(); columnIndex++) {
328
            TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
329
            column.getColumn().setText(titles.get(columnIndex));
330
            column.getColumn().setWidth(bounds.get(columnIndex));
331
            column.getColumn().setResizable(true);
332
            column.getColumn().setMoveable(true);
333
            column.getColumn().addSelectionListener(getSelectionAdapter(column.getColumn(), columnIndex));
334
            if (columnIndex == 0) {
335
                table.setSortColumn(column.getColumn());
336
            }
337
            if (columnIndex == 1 && PreferencesUtil.isShowRankInChecklistEditor()) {
338
            	/** uncommented it for now because no rank editing is wanted **/
339
//                column.setEditingSupport(new RankEditingSupport(viewer, this));
340
            }
341
            if ((columnIndex == 1 && !PreferencesUtil.isShowRankInChecklistEditor()) || columnIndex >= 2 ) {
342
                //read PrefrenceStore to setWidth according to last saved state
343
                if(restoreValuesForColumnWidth.get(columnIndex)){
344
                    column.getColumn().setWidth(50);
345
                }else{
346
                    column.getColumn().setWidth(50);
347
                }
348
                column.setEditingSupport(new DistributionEditingSupportE4(viewer, this, columnIndex));
349

    
350
            }
351
        }
352
	}
353

    
354
    /**
355
     * This methods loads the last opened distribution columns for the table viewer from the prefrence store.<br>
356
     *<p>
357
     * <b>Notice:</b> It adds also the TitleCache to the titles list for the header of each column.<p>
358
     *
359
     * @param titles
360
     * @param bounds
361
     * @return Map<Integer, Boolean>
362
     */
363
	private Map<Integer, Boolean> restoreValuesForColumnWidth(List<String> titles,
364
			List<Integer> bounds) {
365
		Map<Integer, Boolean> restoreColumnWidth = new HashMap<Integer, Boolean>();
366
		if (terms != null) {
367
		    int columnIndex;
368
		    if (PreferencesUtil.isShowRankInChecklistEditor()){
369
		        columnIndex = 2;
370
		    } else{
371
		        columnIndex = 1;
372
		    }
373
            for (DefinedTermBase<DefinedTermBase> term : terms) {
374
                if(term != null){
375
                    restoreColumnWidth.put(columnIndex, PreferencesUtil.getPreferenceStore().getBoolean(term.getUuid().toString()));
376
                    if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
377
                        if (term.getIdInVocabulary() != null){
378
                            titles.add(term.getIdInVocabulary());
379
                        } else{
380
                            titles.add(term.getTitleCache());
381
                        }
382
                    }else{
383
                        titles.add(term.getTitleCache());
384
                    }
385
                    bounds.add(200);
386
                    columnIndex++;
387
                }
388
            }
389
        }
390
		return restoreColumnWidth;
391
	}
392

    
393
    /**
394
     * This method adds new DistributionColumns to an existing table.
395
     *
396
     * @param title
397
     * @param bound
398
     * @param colNumber
399
     * @return
400
     */
401
    private TableViewerColumn addTableViewerColumn(String title, int bound, final int colNumber) {
402
        final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
403
        final TableColumn column = viewerColumn.getColumn();
404
        column.setText(title);
405
        column.setWidth(200);
406
        viewerColumn.setEditingSupport(new DistributionEditingSupportE4(viewer, this, colNumber));
407
        column.setResizable(true);
408
        column.setMoveable(true);
409
        return viewerColumn;
410
      }
411

    
412

    
413

    
414
    /**
415
     *
416
     * pull data from database and set input for view
417
     *
418
     */
419
    private void loadDataInput() {
420
        Classification classification = checklistEditorInput.getClassification();
421
        TaxonNode taxonNode = checklistEditorInput.getTaxonNode();
422
        if (classification != null && taxonNode == null) {
423
            countNodes = taxonNodeService.countAllNodesForClassification(classification);
424
//            statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
425
            // This should not kill the view nor the editor if something goes
426
            // wrong
427
            // TODO: don't load the whole taxonNode Object but rather a small
428
            // and simple Solution
429
            // FIXME: May be don't open classification which are greater than
430
            // 3000 Taxa
431
            selectedTaxonNodes = taxonNodeService.listAllNodesForClassification(classification, 0, countNodes);
432
            countNodes = selectedTaxonNodes.size();
433
            statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
434
            viewer.setInput(checklistEditorInput.getTaxa());
435
//            Job checkListJob = new ChecklistJob(LOADING_TAXA, selectedTaxonNodes);
436
//            checkListJob.schedule(Job.LONG);
437

    
438
        }
439
        if (taxonNode != null) {
440
            selectedTaxonNodes = taxonNodeService.loadChildNodesOfTaxonNode(taxonNode, NODE_INIT_STRATEGY, true, null);
441
            countNodes = selectedTaxonNodes.size();
442
            viewer.setInput(checklistEditorInput.getTaxa());
443
            statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
444
//            Job checkListJob = new ChecklistJob(LOADING_TAXA, selectedTaxonNodes);
445
//            checkListJob.schedule(Job.LONG);
446
//          getService().schedule(new ChecklistJob(LOADING_TAXA, selectedTaxonNodes), Job.LONG);
447
        }
448
    }
449

    
450

    
451
    @PreDestroy
452
    public void dispose() {
453
    	if(conversation!=null){
454
    		conversation.unregisterForDataStoreChanges(this);
455
    		conversation.close();
456
    	}
457
    	conversation = null;
458
    	if(checklistEditorInput!=null){
459
    	    checklistEditorInput.dispose();
460
    	}
461

    
462
    }
463

    
464
    /** {@inheritDoc} */
465
    @Focus
466
    public void setFocus() {
467
    	if(viewer!=null && viewer.getControl()!=null && !viewer.getControl().isDisposed()) {
468
            viewer.getControl().setFocus();
469
        }
470
    }
471

    
472
    //FIXME E4 migrate
473
//    /*
474
//     * (non-Javadoc)
475
//     *
476
//     * @see org.eclipse.ui.part.WorkbenchPart#showBusy(boolean)
477
//     */
478
//    /** {@inheritDoc} */
479
//    @Override
480
//    public void showBusy(boolean busy) {
481
//        super.showBusy(busy);
482
//        // viewer.getTable().setEnabled(!busy);
483
//        if (busy) {
484
//            partNameCache = getPartName();
485
//            setPartName(String.format(Messages.ChecklistEditor_LOAD_CNT_TAXA, countNodes));
486
//        } else {
487
//            if (partNameCache != null) {
488
//                setPartName(partNameCache);
489
//            }
490
//        }
491
//    }
492

    
493
    /**
494
     * <p>
495
     * Getter for the field <code>viewer</code>.
496
     * </p>
497
     *
498
     * @return a {@link org.eclipse.jface.viewers.StructuredViewer} object.
499
     */
500
    public StructuredViewer getViewer() {
501
        return viewer;
502
    }
503

    
504
    public void refresh() {
505
        viewer.refresh();
506
    }
507

    
508
    /**
509
     * This method should only be called for adding new Distribution columns and reloading the table.<br>
510
     * It will hide the old distribution column and load the newly added columns.<br>
511
     * <p>
512
     * <b>Notice:</b> for data update please use <b>refresh()</b>
513
     *
514
     */
515
    @SuppressWarnings({ "unchecked", "rawtypes" })
516
	public void reload(){
517
    	//create new Items for Dropdown menue
518
    	Table table = viewer.getTable();
519
    	table.setRedraw(false);
520
    	SortedSet<DefinedTermBase> oldTerms = terms;
521

    
522
//    	if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
523
//
524
//    	} else{
525
//    	    terms = (SortedSet<DefinedTermBase>) labelProvider.getTermsOrderedByLabels(labelProvider.getNamedAreas(), CdmStore.getDefaultLanguage());
526
//    	}
527
    	SortedSet<DefinedTermBase> newTerms = labelProvider.getNamedAreas();
528
    	toolItem.removeSelectionListener(dropListener);
529
    	hideDistributionColumns(oldTerms);
530
    	createToolbarItems();
531
    	toolItem.addSelectionListener(dropListener);
532
    	for(DefinedTermBase term:newTerms){
533
    		int count = viewer.getTable().getColumnCount();
534
    		addTableViewerColumn(term.getTitleCache(), 200, count);
535
    		acitivateNewColumnInDropDownMenu(term);
536
    	}
537
        viewer.setLabelProvider(labelProvider);
538
//        getService().schedule(new ChecklistJob(LOADING_TAXA, selectedTaxonNodes), Job.LONG);
539
        table.setRedraw(true);
540
    	viewer.refresh();
541
    }
542

    
543
	private void acitivateNewColumnInDropDownMenu(DefinedTermBase term) {
544
		Menu menu = dropListener.getMenu();
545
		MenuItem[] items = menu.getItems();
546
		for(MenuItem item: items){
547
			if(item.getText().equalsIgnoreCase(term.getTitleCache())){
548
				item.setSelection(true);
549
				PreferencesUtil.getPreferenceStore().setValue(term.getUuid().toString(), true);
550
			}
551
		}
552
	}
553

    
554
	private void hideDistributionColumns(SortedSet<DefinedTermBase> oldTerms) {
555
		TableColumn[] columns = viewer.getTable().getColumns();
556
    	for(int i=4; i<columns.length; i++){
557
    		//remove all columns
558
    		columns[i].dispose();
559
    		Menu menu = dropListener.getMenu();
560
    		int itemCount = menu.getItemCount();
561
    		MenuItem item = menu.getItem(i-3);
562
    		item.setSelection(false);
563
    	}
564
    	if(oldTerms != null){
565
    		for(DefinedTermBase term : oldTerms){
566
    			PreferencesUtil.getPreferenceStore().setValue(term.getUuid().toString(), false);
567
    		}
568
    	}
569
	}
570

    
571
    /**
572
     * <p>
573
     * Getter for the field <code>service</code>.
574
     * </p>
575
     *
576
     * @return the service
577
     */
578
    public IWorkbenchSiteProgressService getService() {
579
        return TaxeditorEditorPlugin.getDefault().getWorkbench().getService(IWorkbenchSiteProgressService.class);
580
    }
581

    
582
    private SelectionAdapter getSelectionAdapter(final TableColumn column, final int index) {
583
        SelectionAdapter selectionAdapter = new SelectionAdapter() {
584
            @Override
585
            public void widgetSelected(SelectionEvent e) {
586
                comparator.setColumn(index);
587
                int dir = viewer.getTable().getSortDirection();
588
                if (viewer.getTable().getSortColumn() == column) {
589
                    dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
590
                } else {
591
                    dir = SWT.DOWN;
592
                }
593
                viewer.getTable().setSortDirection(dir);
594
                viewer.getTable().setSortColumn(column);
595
                viewer.refresh();
596
            }
597
        };
598
        return selectionAdapter;
599
    }
600

    
601
    public void doSave(IProgressMonitor monitor) {
602
        try {
603
            monitor.beginTask(Messages.ChecklistEditor_SAVE_EDITOR, 1);
604
            if (!conversation.isBound()) {
605
                conversation.bind();
606
            }
607

    
608
            this.checklistEditorInput.merge();
609

    
610
            conversation.commit(true);
611
            setDirty(false);
612
            monitor.worked(1);
613
        } finally {
614
            monitor.done();
615
        }
616

    
617
    }
618

    
619
    public void init(ChecklistEditorInput input) {
620
        checklistEditorInput = input;
621
        thisPart.setLabel(DISTRIBUTION_EDITOR+": " + checklistEditorInput.getName());
622
        conversation = checklistEditorInput.getConversation();
623
        conversation.registerForDataStoreChanges(this);
624

    
625
        //propagate selection
626
        selectionChangedListener = (event -> selService.setSelection(
627
               DistributionEditorHelper.getDistributionForColumn(event)));
628

    
629
        viewer.addSelectionChangedListener(selectionChangedListener);
630

    
631

    
632
        loadDataInput();
633
    }
634
    private static final List<String> NODE_INIT_STRATEGY = Arrays.asList(new String[] { "descriptions", //$NON-NLS-1$
635
            "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$
636
            "childNodes.taxon.name", "taxonNodes", "taxonNodes.*", "taxonNodes.taxon.*", "taxon.*", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
637
            "taxon.descriptions", "taxon.sec", "taxon.name.*", "terms", "name.*", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
638
            "name.rank.representations", "name.status.type.representations", "stateData.$" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
639

    
640
    /*
641
     * (non-Javadoc)
642
     *
643
     * @see
644
     * eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(
645
     * java.lang.Object)
646
     */
647
    @Override
648
    public void changed(Object element) {
649
        if (element != null) {
650
            viewer.update(element, null);
651
            if (element instanceof Taxon){
652
                checklistEditorInput.addTaxonToSave((Taxon)element);
653
            }
654
            setDirty(true);
655
        }
656
    }
657

    
658
    /* (non-Javadoc)
659
     * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty()
660
     */
661
    @Override
662
    public void forceDirty() {
663
        changed(null);
664
    }
665

    
666
    public void setDirty(boolean dirty) {
667
        this.dirty.setDirty(dirty);
668
    }
669

    
670
    /*
671
     * (non-Javadoc)
672
     *
673
     * @see org.eclipse.ui.forms.editor.FormEditor#isDirty()
674
     */
675
    public boolean isDirty() {
676
        return dirty.isDirty();
677
    }
678

    
679

    
680
    /**
681
     * @return the labelProvider
682
     */
683
    public ChecklistLabelProvider getLabelProvider() {
684
        return labelProvider;
685
    }
686

    
687
    /* (non-Javadoc)
688
     * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
689
     */
690
    @Override
691
    public void update(CdmDataChangeMap arg0) {
692
        // TODO Auto-generated method stub
693

    
694
    }
695

    
696
    /* (non-Javadoc)
697
     * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
698
     */
699
    @Override
700
    public ConversationHolder getConversationHolder() {
701
        return conversation;
702
    }
703

    
704
    /* (non-Javadoc)
705
     * @see eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart#save(org.eclipse.core.runtime.IProgressMonitor)
706
     */
707
    @Override
708
    @Persist
709
    public void save(IProgressMonitor monitor) {
710
        doSave(monitor);
711
    }
712

    
713

    
714
}
(2-2/4)