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
    	checklistEditorInput.bind();
471
    }
472

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

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

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

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

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

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

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

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

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

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

    
609
            this.checklistEditorInput.merge();
610

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

    
618
    }
619

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

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

    
630
        viewer.addSelectionChangedListener(selectionChangedListener);
631

    
632

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

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

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

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

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

    
680

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

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

    
695
    }
696

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

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

    
714

    
715
}
(2-2/4)