Project

General

Profile

Download (29.9 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.IMemento;
55
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
56

    
57
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
58
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
59
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
60
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
61
import eu.etaxonomy.cdm.model.taxon.Classification;
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.IContextListener;
76
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
77
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
78
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
79
import eu.etaxonomy.taxeditor.model.MessagingUtils;
80
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
81
import eu.etaxonomy.taxeditor.preference.Resources;
82
import eu.etaxonomy.taxeditor.store.CdmStore;
83
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
84

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

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

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

    
101

    
102
//    private class ChecklistJob extends Job {
103
//
104
//        private List<TaxonNode> taxonNodes;
105
//
106
//        /**
107
//         * @param name
108
//         */
109
//        public ChecklistJob(String title, List<TaxonNode> listTaxonNodes) {
110
//            super(title);
111
//            this.taxonNodes = listTaxonNodes;
112
//
113
//
114
//        }
115
//
116
//        /*
117
//         * (non-Javadoc)
118
//         *
119
//         * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.
120
//         * IProgressMonitor)
121
//         */
122
//        @Override
123
//        public IStatus run(final IProgressMonitor monitor) {
124
//            try {
125
//                logger.debug("Begin of eclipse core runtime Job to Retrieve datasources"); //$NON-NLS-1$
126
//                monitor.beginTask(Messages.ChecklistEditor_RETRIEVE_NODES, taxonNodes.size() + 1);
127
//
128
//                final List<Taxon> taxonList = new ArrayList<Taxon>();
129
//
130
//                for (TaxonNode taxonNode : taxonNodes) {
131
//                    HibernateProxyHelper hh = new HibernateProxyHelper();
132
//                    Taxon taxon = hh.deproxy(taxonNode.getTaxon(), Taxon.class);
133
//                    taxonList.add(taxon);
134
//                }
135
//                // set View input
136
//                Display.getDefault().asyncExec(new Runnable() {
137
//
138
//                    @Override
139
//                    public void run() {
140
//                    	viewer.setInput(taxonList);
141
//                    }
142
//                });
143
//                monitor.worked(1);
144
//
145
//            } finally {
146
//                monitor.done();
147
//                taxonNodes = null;
148
//            }
149
//            return Status.OK_STATUS;
150
//        }
151
//    }
152

    
153
    /**
154
     * Constant
155
     * <code>ID="eu.etaxonomy.taxeditor.store.datasource"{trunked}</code>
156
     */
157
    public static String ID = "eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditor"; //$NON-NLS-1$
158

    
159
    private TableViewer viewer;
160

    
161
    private String partNameCache;
162

    
163
    //FIXME E4 migrate/delete ater full migration
164

    
165
    private IWorkbenchSiteProgressService service;
166

    
167
    private ITaxonNodeService taxonNodeService;
168

    
169
    private ChecklistEditorComparator comparator;
170

    
171
    private ChecklistEditorInput checklistEditorInput;
172

    
173
    private ConversationHolder conversation;
174

    
175
    private Integer countNodes;
176

    
177
    private List<TaxonNode> selectedTaxonNodes;
178

    
179
    @Inject
180
    private MPart thisPart;
181

    
182
    @Inject
183
    private MDirtyable dirty;
184

    
185
    @Inject
186
    private ESelectionService selService;
187

    
188
    private ISelectionChangedListener selectionChangedListener;
189

    
190
    private ChecklistEditorFilter filter;
191

    
192
    private Menu headerMenu;
193

    
194
    private Label statusLabel;
195

    
196
   // private final ICdmEntitySession cdmEntitySession;
197

    
198
    private ChecklistLabelProvider labelProvider;
199

    
200
    private SortedSet<DefinedTermBase> terms = null;
201
	private ToolItem toolItem;
202
	private ChecklistDropdownSelectionListenerE4 dropListener;
203
	private Text searchText;
204

    
205

    
206
    /**
207
     * @return the selectedTaxonNodes
208
     */
209
    public List<TaxonNode> getSelectedTaxonNodes() {
210
        return selectedTaxonNodes;
211
    }
212

    
213
    /**
214
     * @param selectedTaxonNodes
215
     *            the selectedTaxonNodes to set
216
     */
217
    public void setSelectedTaxonNodes(List<TaxonNode> selectedTaxonNodes) {
218
        this.selectedTaxonNodes = selectedTaxonNodes;
219
    }
220

    
221
    @Inject
222
    public ChecklistEditorE4() {
223
    }
224

    
225
    /** {@inheritDoc} */
226
    @PostConstruct
227
    public void createPartControl(Composite parent) {
228
    	if (!CdmStore.isActive()){
229
            return;
230
        }
231
        taxonNodeService = CdmStore.getService(ITaxonNodeService.class);
232
        filter = new ChecklistEditorFilter();
233
        createTopComposite(parent);
234
        viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
235

    
236
        //the focuzsCellManager should return the distribution!!!
237
        TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(viewer, new FocusCellOwnerDrawHighlighter (viewer));
238
        TableViewerEditor.create(viewer, focusCellManager, new ColumnViewerEditorActivationStrategy(viewer), TableViewerEditor.KEYBOARD_ACTIVATION);
239

    
240

    
241
//        viewer.addSelectionChangedListener(new ISelectionChangedListener() {
242
//        	  @Override
243
//        	  public void selectionChanged(SelectionChangedEvent event) {
244
//        	    IStructuredSelection selection = viewer.getStructuredSelection();
245
//        	    Object firstElement = selection.getFirstElement();
246
//        	    // do something with it
247
//        	  }
248
//
249
//
250
//        	});
251

    
252

    
253

    
254
        labelProvider = new ChecklistLabelProvider(this.viewer);
255

    
256
        terms = labelProvider.getNamedAreas();
257
        if (terms == null){
258
			MessagingUtils.informationDialog(Messages.ChecklistEditor_NO_AREAS, Messages.ChecklistEditor_NO_AREAS_MESSAGE);
259
			this.dispose();
260
			return;
261
		}
262

    
263

    
264
        viewer.addFilter(filter);
265
        createTable();
266

    
267
        viewer.setContentProvider(new ChecklistContentProvider());
268
        viewer.setLabelProvider(this.labelProvider);
269
        comparator = new ChecklistEditorComparator();
270
        viewer.setComparator(comparator);
271
        final ModifyListener modifyListener = new ChecklistModifyListener(viewer, filter, searchText);
272

    
273
        searchText.addFocusListener(new ChecklistFocusListener(searchText, modifyListener));
274
        searchText.addModifyListener(modifyListener);
275
        createGridDataForViewerLayout();
276
        createStatusBar(parent);
277
        createToolbar(parent);
278
    }
279

    
280
    /**
281
     * @param parent
282
     */
283
    private void createTopComposite(Composite parent) {
284
        GridLayout gridLayout = new GridLayout(3, false);
285
        gridLayout.marginWidth = 0;
286
        gridLayout.marginHeight = 0;
287
        parent.setLayout(gridLayout);
288

    
289
       searchText = createSearchBar(parent);
290

    
291

    
292
       // getSite().setSelectionProvider(viewer);
293

    
294

    
295

    
296

    
297

    
298
    }
299

    
300
	private void createGridDataForViewerLayout() {
301
		GridData gridData = new GridData();
302
		gridData.verticalAlignment = GridData.FILL;
303
        gridData.horizontalSpan = 3;
304
        gridData.grabExcessHorizontalSpace = true;
305
        gridData.grabExcessVerticalSpace = true;
306
        gridData.horizontalAlignment = GridData.FILL;
307
        viewer.getControl().setLayoutData(gridData);
308
	}
309

    
310
    /**
311
     * @param parent
312
     * @return
313
     */
314
    private Text createSearchBar(Composite parent) {
315
        Label searchLabel = new Label(parent, SWT.NONE);
316
        searchLabel.setText(Messages.ChecklistEditor_SEARCH);
317
        final Text searchText = new Text(parent, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH | SWT.CANCEL);
318
        searchText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
319
        searchText.setForeground(EditorUtil.getColor(Resources.SEARCH_VIEW_FOREGROUND));
320
        searchText.setText(TYPE_FILTER_TEXT);
321
        return searchText;
322
    }
323

    
324
    /**
325
     * @param parent
326
     */
327
    private void createToolbar(Composite parent) {
328
        ToolBar toolBar = new ToolBar(parent, SWT.NONE);
329
        toolItem = new ToolItem(toolBar, SWT.DROP_DOWN | SWT.BORDER);
330
        toolItem.setText(Messages.ChecklistEditor_DIST_STATUS);
331
        toolItem.setToolTipText(Messages.ChecklistEditor_DIST_STATUS_TOOLTIP);
332
        createToolbarItems();
333
        toolItem.addSelectionListener(dropListener);
334
        toolBar.pack();
335
    }
336

    
337
	private void createToolbarItems() {
338
		dropListener = new ChecklistDropdownSelectionListenerE4(toolItem, this, terms);
339

    
340
        for (DefinedTermBase<DefinedTermBase> term : terms) {
341
            if(term!=null){
342
                dropListener.add(term);
343
            }
344
        }
345
	}
346

    
347
    private void createStatusBar(Composite composite) {
348
        GridData gridData = new GridData();
349
        gridData.horizontalSpan = 3;
350
        gridData.grabExcessHorizontalSpace = true;
351
        gridData.horizontalAlignment = GridData.FILL;
352

    
353
        statusLabel = new Label(composite, SWT.LEFT);
354
        statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
355
        statusLabel.setLayoutData(gridData);
356
    }
357

    
358
    private void createTable() {
359
        Table table = viewer.getTable();//new Table(parent, viewer.getTable().getStyle());
360
        List<String> titles = new ArrayList<String>();
361
        List<Integer> bounds = new ArrayList<Integer>();
362
        if (PreferencesUtil.isShowRankInChecklistEditor()){
363
            Collections.addAll(titles, Messages.ChecklistEditor_TAXON,  Messages.ChecklistEditor_RANK);
364
            Collections.addAll(bounds, 300, 200);
365
        } else{
366
            Collections.addAll(titles, Messages.ChecklistEditor_TAXON);
367
            Collections.addAll(bounds, 300);
368
        }
369

    
370

    
371
        Map<Integer, Boolean> restoreValuesForColumnWidth = restoreValuesForColumnWidth(titles, bounds);
372
        createInitalDistributionColumns(table, titles, bounds, restoreValuesForColumnWidth);
373
        table.setSortDirection(SWT.DOWN);
374
        table.setHeaderVisible(true);
375
        table.setLinesVisible(true);
376
	}
377
    /**
378
     * This method creates initially the distribution columns for a table. It should only be called for creation.<br>
379
     *<p>
380
     *
381
     *<b>Notice:</b> If you want to add additional columns later please use <b>addTableViewerColumn()</b>
382
     *
383
     * @param table
384
     * @param titles
385
     * @param bounds
386
     * @param restoreValuesForColumnWidth
387
     */
388
	private void createInitalDistributionColumns(Table table,
389
			List<String> titles, List<Integer> bounds, Map<Integer, Boolean> restoreValuesForColumnWidth) {
390
		for (int columnIndex = 0; columnIndex < titles.size(); columnIndex++) {
391
            TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
392
            column.getColumn().setText(titles.get(columnIndex));
393
            column.getColumn().setWidth(bounds.get(columnIndex));
394
            column.getColumn().setResizable(true);
395
            column.getColumn().setMoveable(true);
396
            column.getColumn().addSelectionListener(getSelectionAdapter(column.getColumn(), columnIndex));
397
            if (columnIndex == 0) {
398
                table.setSortColumn(column.getColumn());
399
            }
400
            if (columnIndex == 1 && PreferencesUtil.isShowRankInChecklistEditor()) {
401
            	/** uncommented it for now because no rank editing is wanted **/
402
//                column.setEditingSupport(new RankEditingSupport(viewer, this));
403
            }
404
            if ((columnIndex == 1 && !PreferencesUtil.isShowRankInChecklistEditor()) || columnIndex >= 2 ) {
405
                //read PrefrenceStore to setWidth according to last saved state
406
                if(restoreValuesForColumnWidth.get(columnIndex)){
407
                    column.getColumn().setWidth(50);
408
                }else{
409
                    column.getColumn().setWidth(50);
410
                }
411
                column.setEditingSupport(new DistributionEditingSupportE4(viewer, this, columnIndex));
412

    
413
            }
414
        }
415
	}
416

    
417
    /**
418
     * This methods loads the last opened distribution columns for the table viewer from the prefrence store.<br>
419
     *<p>
420
     * <b>Notice:</b> It adds also the TitleCache to the titles list for the header of each column.<p>
421
     *
422
     * @param titles
423
     * @param bounds
424
     * @return Map<Integer, Boolean>
425
     */
426
	private Map<Integer, Boolean> restoreValuesForColumnWidth(List<String> titles,
427
			List<Integer> bounds) {
428
		Map<Integer, Boolean> restoreColumnWidth = new HashMap<Integer, Boolean>();
429
		if (terms != null) {
430
		    int columnIndex;
431
		    if (PreferencesUtil.isShowRankInChecklistEditor()){
432
		        columnIndex = 2;
433
		    } else{
434
		        columnIndex = 1;
435
		    }
436
            for (DefinedTermBase<DefinedTermBase> term : terms) {
437
                if(term != null){
438
                    restoreColumnWidth.put(columnIndex, PreferencesUtil.getPreferenceStore().getBoolean(term.getUuid().toString()));
439
                    if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
440
                        if (term.getIdInVocabulary() != null){
441
                            titles.add(term.getIdInVocabulary());
442
                        } else{
443
                            titles.add(term.getTitleCache());
444
                        }
445
                    }else{
446
                        titles.add(term.getTitleCache());
447
                    }
448
                    bounds.add(200);
449
                    columnIndex++;
450
                }
451
            }
452
        }
453
		return restoreColumnWidth;
454
	}
455

    
456
    /**
457
     * This method adds new DistributionColumns to an existing table.
458
     *
459
     * @param title
460
     * @param bound
461
     * @param colNumber
462
     * @return
463
     */
464
    private TableViewerColumn addTableViewerColumn(String title, int bound, final int colNumber) {
465
        final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
466
        final TableColumn column = viewerColumn.getColumn();
467
        column.setText(title);
468
        column.setWidth(200);
469
        viewerColumn.setEditingSupport(new DistributionEditingSupportE4(viewer, this, colNumber));
470
        column.setResizable(true);
471
        column.setMoveable(true);
472
        return viewerColumn;
473
      }
474

    
475

    
476

    
477
    /**
478
     *
479
     * pull data from database and set input for view
480
     *
481
     */
482
    private void loadDataInput() {
483
        Classification classification = checklistEditorInput.getClassification();
484
        TaxonNode taxonNode = checklistEditorInput.getTaxonNode();
485
        if (classification != null && taxonNode == null) {
486
            countNodes = taxonNodeService.countAllNodesForClassification(classification);
487
//            statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
488
            // This should not kill the view nor the editor if something goes
489
            // wrong
490
            // TODO: don't load the whole taxonNode Object but rather a small
491
            // and simple Solution
492
            // FIXME: May be don't open classification which are greater than
493
            // 3000 Taxa
494
            selectedTaxonNodes = taxonNodeService.listAllNodesForClassification(classification, 0, countNodes);
495
            countNodes = selectedTaxonNodes.size();
496
            statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
497
            viewer.setInput(checklistEditorInput.getTaxa());
498
//            Job checkListJob = new ChecklistJob(LOADING_TAXA, selectedTaxonNodes);
499
//            checkListJob.schedule(Job.LONG);
500

    
501
        }
502
        if (taxonNode != null) {
503
            selectedTaxonNodes = taxonNodeService.loadChildNodesOfTaxonNode(taxonNode, NODE_INIT_STRATEGY, true, null);
504
            countNodes = selectedTaxonNodes.size();
505
            viewer.setInput(checklistEditorInput.getTaxa());
506
            statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
507
//            Job checkListJob = new ChecklistJob(LOADING_TAXA, selectedTaxonNodes);
508
//            checkListJob.schedule(Job.LONG);
509
//          getService().schedule(new ChecklistJob(LOADING_TAXA, selectedTaxonNodes), Job.LONG);
510
        }
511
    }
512

    
513
    /** {@inheritDoc} */
514
    @PreDestroy
515
    public void dispose() {
516
//    	if(checklistEditorInput!=null){
517
//    		this.checklistEditorInput.getConversation().unregisterForDataStoreChanges(this.checklistEditorInput);
518
//    	}
519

    
520
    	if(conversation!=null){
521
    		conversation.unregisterForDataStoreChanges(this);
522
    		conversation.unbind();
523
    		conversation.close();
524
    	}
525
    	conversation = null;
526
    	if(checklistEditorInput!=null){
527
    	    checklistEditorInput.dispose();
528
    	}
529
    }
530

    
531
    /** {@inheritDoc} */
532
    @Focus
533
    public void setFocus() {
534
    	if(viewer!=null && viewer.getControl()!=null && !viewer.getControl().isDisposed()) {
535
            viewer.getControl().setFocus();
536
        }
537
    }
538

    
539
    //FIXME E4 migrate
540
//    /*
541
//     * (non-Javadoc)
542
//     *
543
//     * @see org.eclipse.ui.part.WorkbenchPart#showBusy(boolean)
544
//     */
545
//    /** {@inheritDoc} */
546
//    @Override
547
//    public void showBusy(boolean busy) {
548
//        super.showBusy(busy);
549
//        // viewer.getTable().setEnabled(!busy);
550
//        if (busy) {
551
//            partNameCache = getPartName();
552
//            setPartName(String.format(Messages.ChecklistEditor_LOAD_CNT_TAXA, countNodes));
553
//        } else {
554
//            if (partNameCache != null) {
555
//                setPartName(partNameCache);
556
//            }
557
//        }
558
//    }
559

    
560
    /**
561
     * <p>
562
     * Getter for the field <code>viewer</code>.
563
     * </p>
564
     *
565
     * @return a {@link org.eclipse.jface.viewers.StructuredViewer} object.
566
     */
567
    public StructuredViewer getViewer() {
568
        return viewer;
569
    }
570

    
571
    public void refresh() {
572
        viewer.refresh();
573
    }
574

    
575
    /**
576
     * This method should only be called for adding new Distribution columns and reloading the table.<br>
577
     * It will hide the old distribution column and load the newly added columns.<br>
578
     * <p>
579
     * <b>Notice:</b> for data update please use <b>refresh()</b>
580
     *
581
     */
582
    @SuppressWarnings({ "unchecked", "rawtypes" })
583
	public void reload(){
584
    	//create new Items for Dropdown menue
585
    	Table table = viewer.getTable();
586
    	table.setRedraw(false);
587
    	SortedSet<DefinedTermBase> oldTerms = terms;
588

    
589
//    	if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
590
//
591
//    	} else{
592
//    	    terms = (SortedSet<DefinedTermBase>) labelProvider.getTermsOrderedByLabels(labelProvider.getNamedAreas(), CdmStore.getDefaultLanguage());
593
//    	}
594
    	SortedSet<DefinedTermBase> newTerms = labelProvider.getNamedAreas();
595
    	toolItem.removeSelectionListener(dropListener);
596
    	hideDistributionColumns(oldTerms);
597
    	createToolbarItems();
598
    	toolItem.addSelectionListener(dropListener);
599
    	for(DefinedTermBase term:newTerms){
600
    		int count = viewer.getTable().getColumnCount();
601
    		addTableViewerColumn(term.getTitleCache(), 200, count);
602
    		acitivateNewColumnInDropDownMenu(term);
603
    	}
604
        viewer.setLabelProvider(labelProvider);
605
//        getService().schedule(new ChecklistJob(LOADING_TAXA, selectedTaxonNodes), Job.LONG);
606
        table.setRedraw(true);
607
    	viewer.refresh();
608
    }
609

    
610
	private void acitivateNewColumnInDropDownMenu(DefinedTermBase term) {
611
		Menu menu = dropListener.getMenu();
612
		MenuItem[] items = menu.getItems();
613
		for(MenuItem item: items){
614
			if(item.getText().equalsIgnoreCase(term.getTitleCache())){
615
				item.setSelection(true);
616
				PreferencesUtil.getPreferenceStore().setValue(term.getUuid().toString(), true);
617
			}
618
		}
619
	}
620

    
621
	private void hideDistributionColumns(SortedSet<DefinedTermBase> oldTerms) {
622
		TableColumn[] columns = viewer.getTable().getColumns();
623
    	for(int i=4; i<columns.length; i++){
624
    		//remove all columns
625
    		columns[i].dispose();
626
    		Menu menu = dropListener.getMenu();
627
    		int itemCount = menu.getItemCount();
628
    		MenuItem item = menu.getItem(i-3);
629
    		item.setSelection(false);
630
    	}
631
    	if(oldTerms != null){
632
    		for(DefinedTermBase term : oldTerms){
633
    			PreferencesUtil.getPreferenceStore().setValue(term.getUuid().toString(), false);
634
    		}
635
    	}
636
	}
637

    
638
    /**
639
     * <p>
640
     * Getter for the field <code>service</code>.
641
     * </p>
642
     *
643
     * @return the service
644
     */
645
    public IWorkbenchSiteProgressService getService() {
646
        return TaxeditorEditorPlugin.getDefault().getWorkbench().getService(IWorkbenchSiteProgressService.class);
647
    }
648

    
649
    private SelectionAdapter getSelectionAdapter(final TableColumn column, final int index) {
650
        SelectionAdapter selectionAdapter = new SelectionAdapter() {
651
            @Override
652
            public void widgetSelected(SelectionEvent e) {
653
                comparator.setColumn(index);
654
                int dir = viewer.getTable().getSortDirection();
655
                if (viewer.getTable().getSortColumn() == column) {
656
                    dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
657
                } else {
658
                    dir = SWT.DOWN;
659
                }
660
                viewer.getTable().setSortDirection(dir);
661
                viewer.getTable().setSortColumn(column);
662
                viewer.refresh();
663
            }
664
        };
665
        return selectionAdapter;
666
    }
667

    
668
    public void doSave(IProgressMonitor monitor) {
669
        try {
670
            monitor.beginTask(Messages.ChecklistEditor_SAVE_EDITOR, 1);
671
            if (!conversation.isBound()) {
672
                conversation.bind();
673
            }
674
           this.checklistEditorInput.merge();
675
            //this.checklistEditorInput.merge();
676
            conversation.commit(true);
677
            setDirty(false);
678
            monitor.worked(1);
679
        } finally {
680
            monitor.done();
681
        }
682

    
683
    }
684

    
685
    public void init(ChecklistEditorInput input) {
686
        checklistEditorInput = input;
687
        thisPart.setLabel(DISTRIBUTION_EDITOR+": " + checklistEditorInput.getName());
688
        conversation = checklistEditorInput.getConversation();
689
        conversation.registerForDataStoreChanges(this);
690

    
691
        //propagate selection
692
        selectionChangedListener = (event -> selService.setSelection(
693
               DistributionEditorHelper.getDistributionForColumn(event)));
694

    
695
        viewer.addSelectionChangedListener(selectionChangedListener);
696

    
697

    
698
        loadDataInput();
699
    }
700

    
701

    
702
    /*
703
     * (non-Javadoc)
704
     *
705
     * @see
706
     * eu.etaxonomy.taxeditor.model.IContextListener#contextAboutToStop(org.
707
     * eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
708
     */
709

    
710
    @Override
711
    public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
712

    
713
    }
714

    
715
    /*
716
     * (non-Javadoc)
717
     *
718
     * @see
719
     * eu.etaxonomy.taxeditor.model.IContextListener#contextStop(org.eclipse
720
     * .ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
721
     */
722
    @Override
723
    public void contextStop(IMemento memento, IProgressMonitor monitor) {
724
//        IStructuredSelection sel = (IStructuredSelection) this.viewer.getSelection();
725
//        if (sel.isEmpty()) {
726
//            return;
727
//        }
728
//        memento = memento.createChild("tree-selections");
729
//        Iterator iter = sel.iterator();
730
//        while (iter.hasNext()) {
731
//            String nodeName = (String) iter.next();
732
//            memento.createChild("selected-nodes", nodeName);
733
//        }
734
    }
735

    
736
    /*
737
     * (non-Javadoc)
738
     *
739
     * @see
740
     * eu.etaxonomy.taxeditor.model.IContextListener#contextStart(org.eclipse
741
     * .ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
742
     */
743
    @Override
744
    public void contextStart(IMemento memento, IProgressMonitor monitor) {
745

    
746
    }
747

    
748
    /*
749
     * (non-Javadoc)
750
     *
751
     * @see
752
     * eu.etaxonomy.taxeditor.model.IContextListener#contextRefresh(org.eclipse
753
     * .core.runtime.IProgressMonitor)
754
     */
755
    @Override
756
    public void contextRefresh(IProgressMonitor monitor) {
757
    }
758

    
759
    /*
760
     * (non-Javadoc)
761
     *
762
     * @see
763
     * eu.etaxonomy.taxeditor.model.IContextListener#workbenchShutdown(org.eclipse
764
     * .ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
765
     */
766
    @Override
767
    public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
768
    }
769

    
770
    private static final List<String> NODE_INIT_STRATEGY = Arrays.asList(new String[] { "descriptions", //$NON-NLS-1$
771
            "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$
772
            "childNodes.taxon.name", "taxonNodes", "taxonNodes.*", "taxonNodes.taxon.*", "taxon.*", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
773
            "taxon.descriptions", "taxon.sec", "taxon.name.*", "terms", "name.*", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
774
            "name.rank.representations", "name.status.type.representations", "stateData.$" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
775

    
776
    /*
777
     * (non-Javadoc)
778
     *
779
     * @see
780
     * eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(
781
     * java.lang.Object)
782
     */
783
    @Override
784
    public void changed(Object element) {
785
        if (element != null) {
786
            viewer.update(element, null);
787
            setDirty(true);
788
        }
789
    }
790

    
791
    /* (non-Javadoc)
792
     * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty()
793
     */
794
    @Override
795
    public void forceDirty() {
796
        changed(null);
797
    }
798

    
799
    public void setDirty(boolean dirty) {
800
        this.dirty.setDirty(dirty);
801
    }
802

    
803
    /*
804
     * (non-Javadoc)
805
     *
806
     * @see org.eclipse.ui.forms.editor.FormEditor#isDirty()
807
     */
808
    public boolean isDirty() {
809
        return dirty.isDirty();
810
    }
811

    
812
    /* (non-Javadoc)
813
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
814
     */
815

    
816

    
817
//    /* (non-Javadoc)
818
//     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
819
//     */
820
//    @Override
821
//    public <T extends CdmBase> Collection<T> getRootEntities() {
822
//        // TODO Auto-generated method stub
823
//        return null;
824
//    }
825
//
826
//    /* (non-Javadoc)
827
//     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
828
//     */
829
//    @Override
830
//    public Map<Object, List<String>> getPropertyPathsMap() {
831
//        // TODO Auto-generated method stub
832
//        return null;
833
//    }
834

    
835
    /**
836
     * @return the labelProvider
837
     */
838
    public ChecklistLabelProvider getLabelProvider() {
839
        return labelProvider;
840
    }
841

    
842
    /* (non-Javadoc)
843
     * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
844
     */
845
    @Override
846
    public void update(CdmDataChangeMap arg0) {
847
        // TODO Auto-generated method stub
848

    
849
    }
850

    
851
    /* (non-Javadoc)
852
     * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
853
     */
854
    @Override
855
    public ConversationHolder getConversationHolder() {
856

    
857
        return conversation;
858
    }
859

    
860
    /* (non-Javadoc)
861
     * @see eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart#save(org.eclipse.core.runtime.IProgressMonitor)
862
     */
863
    @Override
864
    @Persist
865
    public void save(IProgressMonitor monitor) {
866
        doSave(monitor);
867

    
868
    }
869

    
870

    
871
}
(2-2/4)