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

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

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

    
219
    @Inject
220
    public ChecklistEditorE4() {
221
    }
222

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

    
232
        //the focuzsCellManager should return the distribution!!!
233
        TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(viewer, new FocusCellOwnerDrawHighlighter (viewer));
234
        TableViewerEditor.create(viewer, focusCellManager, new ColumnViewerEditorActivationStrategy(viewer), TableViewerEditor.KEYBOARD_ACTIVATION);
235

    
236

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

    
248

    
249

    
250
        labelProvider = new ChecklistLabelProvider(this.viewer);
251

    
252
        terms = labelProvider.getNamedAreas();
253
        if (terms == null){
254
			MessagingUtils.informationDialog(Messages.ChecklistEditor_NO_AREAS, Messages.ChecklistEditor_NO_AREAS_MESSAGE);
255
			this.dispose();
256
			return;
257
		}
258
        filter = new ChecklistEditorFilter();
259
        createTopComposite(parent);
260
    }
261

    
262
    /**
263
     * @param parent
264
     */
265
    private void createTopComposite(Composite parent) {
266
        GridLayout gridLayout = new GridLayout(3, false);
267
        gridLayout.marginWidth = 0;
268
        gridLayout.marginHeight = 0;
269
        parent.setLayout(gridLayout);
270

    
271
        final Text searchText = createSearchBar(parent);
272
        createToolbar(parent);
273

    
274
       // getSite().setSelectionProvider(viewer);
275

    
276
        final ModifyListener modifyListener = new ChecklistModifyListener(viewer, filter, searchText);
277

    
278
        searchText.addFocusListener(new ChecklistFocusListener(searchText, modifyListener));
279
        searchText.addModifyListener(modifyListener);
280
        createGridDataForViewerLayout();
281

    
282
        viewer.addFilter(filter);
283
        createTable();
284

    
285
        viewer.setContentProvider(new ChecklistContentProvider());
286
        viewer.setLabelProvider(this.labelProvider);
287
        comparator = new ChecklistEditorComparator();
288
        viewer.setComparator(comparator);
289

    
290
        createStatusBar(parent);
291
    }
292

    
293
	private void createGridDataForViewerLayout() {
294
		GridData gridData = new GridData();
295
		gridData.verticalAlignment = GridData.FILL;
296
        gridData.horizontalSpan = 3;
297
        gridData.grabExcessHorizontalSpace = true;
298
        gridData.grabExcessVerticalSpace = true;
299
        gridData.horizontalAlignment = GridData.FILL;
300
        viewer.getControl().setLayoutData(gridData);
301
	}
302

    
303
    /**
304
     * @param parent
305
     * @return
306
     */
307
    private Text createSearchBar(Composite parent) {
308
        Label searchLabel = new Label(parent, SWT.NONE);
309
        searchLabel.setText(Messages.ChecklistEditor_SEARCH);
310
        final Text searchText = new Text(parent, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH | SWT.CANCEL);
311
        searchText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
312
        searchText.setForeground(EditorUtil.getColor(Resources.SEARCH_VIEW_FOREGROUND));
313
        searchText.setText(TYPE_FILTER_TEXT);
314
        return searchText;
315
    }
316

    
317
    /**
318
     * @param parent
319
     */
320
    private void createToolbar(Composite parent) {
321
        ToolBar toolBar = new ToolBar(parent, SWT.NONE);
322
        toolItem = new ToolItem(toolBar, SWT.DROP_DOWN | SWT.BORDER);
323
        toolItem.setText(Messages.ChecklistEditor_DIST_STATUS);
324
        toolItem.setToolTipText(Messages.ChecklistEditor_DIST_STATUS_TOOLTIP);
325
        createToolbarItems();
326
        toolItem.addSelectionListener(dropListener);
327
        toolBar.pack();
328
    }
329

    
330
	private void createToolbarItems() {
331
		dropListener = new ChecklistDropdownSelectionListenerE4(toolItem, this, terms);
332

    
333
        for (DefinedTermBase<DefinedTermBase> term : terms) {
334
            if(term!=null){
335
                dropListener.add(term);
336
            }
337
        }
338
	}
339

    
340
    private void createStatusBar(Composite composite) {
341
        GridData gridData = new GridData();
342
        gridData.horizontalSpan = 3;
343
        gridData.grabExcessHorizontalSpace = true;
344
        gridData.horizontalAlignment = GridData.FILL;
345

    
346
        statusLabel = new Label(composite, SWT.LEFT);
347
        statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
348
        statusLabel.setLayoutData(gridData);
349
    }
350

    
351
    private void createTable() {
352
        Table table = viewer.getTable();//new Table(parent, viewer.getTable().getStyle());
353
        List<String> titles = new ArrayList<String>();
354
        List<Integer> bounds = new ArrayList<Integer>();
355
        if (PreferencesUtil.isShowRankInChecklistEditor()){
356
            Collections.addAll(titles, Messages.ChecklistEditor_TAXON,  Messages.ChecklistEditor_RANK);
357
            Collections.addAll(bounds, 300, 200);
358
        } else{
359
            Collections.addAll(titles, Messages.ChecklistEditor_TAXON);
360
            Collections.addAll(bounds, 300);
361
        }
362

    
363

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

    
406
            }
407
        }
408
	}
409

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

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

    
468

    
469

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

    
494
        }
495
        if (taxonNode != null) {
496
            selectedTaxonNodes = taxonNodeService.loadChildNodesOfTaxonNode(taxonNode, NODE_INIT_STRATEGY, true, null);
497
            countNodes = selectedTaxonNodes.size();
498
            viewer.setInput(checklistEditorInput.getTaxa());
499
            statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
500
//            Job checkListJob = new ChecklistJob(LOADING_TAXA, selectedTaxonNodes);
501
//            checkListJob.schedule(Job.LONG);
502
//          getService().schedule(new ChecklistJob(LOADING_TAXA, selectedTaxonNodes), Job.LONG);
503
        }
504
    }
505

    
506
    /** {@inheritDoc} */
507
    @PreDestroy
508
    public void dispose() {
509
//    	if(checklistEditorInput!=null){
510
//    		this.checklistEditorInput.getConversation().unregisterForDataStoreChanges(this.checklistEditorInput);
511
//    	}
512

    
513
    	if(conversation!=null){
514
    		conversation.unregisterForDataStoreChanges(this);
515
    		conversation.unbind();
516
    	}
517
        //conversation.close();
518
		conversation = null;
519
    }
520

    
521
    /** {@inheritDoc} */
522
    @Focus
523
    public void setFocus() {
524
    	if(viewer!=null && viewer.getControl()!=null && !viewer.getControl().isDisposed()) {
525
            viewer.getControl().setFocus();
526
        }
527
    }
528

    
529
    //FIXME E4 migrate
530
//    /*
531
//     * (non-Javadoc)
532
//     *
533
//     * @see org.eclipse.ui.part.WorkbenchPart#showBusy(boolean)
534
//     */
535
//    /** {@inheritDoc} */
536
//    @Override
537
//    public void showBusy(boolean busy) {
538
//        super.showBusy(busy);
539
//        // viewer.getTable().setEnabled(!busy);
540
//        if (busy) {
541
//            partNameCache = getPartName();
542
//            setPartName(String.format(Messages.ChecklistEditor_LOAD_CNT_TAXA, countNodes));
543
//        } else {
544
//            if (partNameCache != null) {
545
//                setPartName(partNameCache);
546
//            }
547
//        }
548
//    }
549

    
550
    /**
551
     * <p>
552
     * Getter for the field <code>viewer</code>.
553
     * </p>
554
     *
555
     * @return a {@link org.eclipse.jface.viewers.StructuredViewer} object.
556
     */
557
    public StructuredViewer getViewer() {
558
        return viewer;
559
    }
560

    
561
    public void refresh() {
562
        viewer.refresh();
563
    }
564

    
565
    /**
566
     * This method should only be called for adding new Distribution columns and reloading the table.<br>
567
     * It will hide the old distribution column and load the newly added columns.<br>
568
     * <p>
569
     * <b>Notice:</b> for data update please use <b>refresh()</b>
570
     *
571
     */
572
    @SuppressWarnings({ "unchecked", "rawtypes" })
573
	public void reload(){
574
    	//create new Items for Dropdown menue
575
    	Table table = viewer.getTable();
576
    	table.setRedraw(false);
577
    	SortedSet<DefinedTermBase> oldTerms = terms;
578

    
579
//    	if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
580
//
581
//    	} else{
582
//    	    terms = (SortedSet<DefinedTermBase>) labelProvider.getTermsOrderedByLabels(labelProvider.getNamedAreas(), CdmStore.getDefaultLanguage());
583
//    	}
584
    	SortedSet<DefinedTermBase> newTerms = labelProvider.getNamedAreas();
585
    	toolItem.removeSelectionListener(dropListener);
586
    	hideDistributionColumns(oldTerms);
587
    	createToolbarItems();
588
    	toolItem.addSelectionListener(dropListener);
589
    	for(DefinedTermBase term:newTerms){
590
    		int count = viewer.getTable().getColumnCount();
591
    		addTableViewerColumn(term.getTitleCache(), 200, count);
592
    		acitivateNewColumnInDropDownMenu(term);
593
    	}
594
        viewer.setLabelProvider(labelProvider);
595
//        getService().schedule(new ChecklistJob(LOADING_TAXA, selectedTaxonNodes), Job.LONG);
596
        table.setRedraw(true);
597
    	viewer.refresh();
598
    }
599

    
600
	private void acitivateNewColumnInDropDownMenu(DefinedTermBase term) {
601
		Menu menu = dropListener.getMenu();
602
		MenuItem[] items = menu.getItems();
603
		for(MenuItem item: items){
604
			if(item.getText().equalsIgnoreCase(term.getTitleCache())){
605
				item.setSelection(true);
606
				PreferencesUtil.getPreferenceStore().setValue(term.getUuid().toString(), true);
607
			}
608
		}
609
	}
610

    
611
	private void hideDistributionColumns(SortedSet<DefinedTermBase> oldTerms) {
612
		TableColumn[] columns = viewer.getTable().getColumns();
613
    	for(int i=4; i<columns.length; i++){
614
    		//remove all columns
615
    		columns[i].dispose();
616
    		Menu menu = dropListener.getMenu();
617
    		int itemCount = menu.getItemCount();
618
    		MenuItem item = menu.getItem(i-3);
619
    		item.setSelection(false);
620
    	}
621
    	if(oldTerms != null){
622
    		for(DefinedTermBase term : oldTerms){
623
    			PreferencesUtil.getPreferenceStore().setValue(term.getUuid().toString(), false);
624
    		}
625
    	}
626
	}
627

    
628
    /**
629
     * <p>
630
     * Getter for the field <code>service</code>.
631
     * </p>
632
     *
633
     * @return the service
634
     */
635
    public IWorkbenchSiteProgressService getService() {
636
        return TaxeditorEditorPlugin.getDefault().getWorkbench().getService(IWorkbenchSiteProgressService.class);
637
    }
638

    
639
    private SelectionAdapter getSelectionAdapter(final TableColumn column, final int index) {
640
        SelectionAdapter selectionAdapter = new SelectionAdapter() {
641
            @Override
642
            public void widgetSelected(SelectionEvent e) {
643
                comparator.setColumn(index);
644
                int dir = viewer.getTable().getSortDirection();
645
                if (viewer.getTable().getSortColumn() == column) {
646
                    dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
647
                } else {
648
                    dir = SWT.DOWN;
649
                }
650
                viewer.getTable().setSortDirection(dir);
651
                viewer.getTable().setSortColumn(column);
652
                viewer.refresh();
653
            }
654
        };
655
        return selectionAdapter;
656
    }
657

    
658
    public void doSave(IProgressMonitor monitor) {
659
        try {
660
            monitor.beginTask(Messages.ChecklistEditor_SAVE_EDITOR, 1);
661
            if (!conversation.isBound()) {
662
                conversation.bind();
663
            }
664
           this.checklistEditorInput.merge();
665
            //this.checklistEditorInput.merge();
666
            conversation.commit(true);
667
            setDirty(false);
668
            monitor.worked(1);
669
        } finally {
670
            monitor.done();
671
        }
672

    
673
    }
674

    
675
    public void init(ChecklistEditorInput input) {
676
        checklistEditorInput = input;
677
        thisPart.setLabel(DISTRIBUTION_EDITOR+": " + checklistEditorInput.getName());
678
        conversation = checklistEditorInput.getConversation();
679
        conversation.registerForDataStoreChanges(this);
680

    
681
        //propagate selection
682
        selectionChangedListener = (event -> selService.setSelection(
683
               DistributionEditorHelper.getDistributionForColumn(event)));
684

    
685
        viewer.addSelectionChangedListener(selectionChangedListener);
686

    
687

    
688
        loadDataInput();
689
    }
690

    
691

    
692
    /*
693
     * (non-Javadoc)
694
     *
695
     * @see
696
     * eu.etaxonomy.taxeditor.model.IContextListener#contextAboutToStop(org.
697
     * eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
698
     */
699

    
700
    @Override
701
    public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
702

    
703
    }
704

    
705
    /*
706
     * (non-Javadoc)
707
     *
708
     * @see
709
     * eu.etaxonomy.taxeditor.model.IContextListener#contextStop(org.eclipse
710
     * .ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
711
     */
712
    @Override
713
    public void contextStop(IMemento memento, IProgressMonitor monitor) {
714
//        IStructuredSelection sel = (IStructuredSelection) this.viewer.getSelection();
715
//        if (sel.isEmpty()) {
716
//            return;
717
//        }
718
//        memento = memento.createChild("tree-selections");
719
//        Iterator iter = sel.iterator();
720
//        while (iter.hasNext()) {
721
//            String nodeName = (String) iter.next();
722
//            memento.createChild("selected-nodes", nodeName);
723
//        }
724
    }
725

    
726
    /*
727
     * (non-Javadoc)
728
     *
729
     * @see
730
     * eu.etaxonomy.taxeditor.model.IContextListener#contextStart(org.eclipse
731
     * .ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
732
     */
733
    @Override
734
    public void contextStart(IMemento memento, IProgressMonitor monitor) {
735

    
736
    }
737

    
738
    /*
739
     * (non-Javadoc)
740
     *
741
     * @see
742
     * eu.etaxonomy.taxeditor.model.IContextListener#contextRefresh(org.eclipse
743
     * .core.runtime.IProgressMonitor)
744
     */
745
    @Override
746
    public void contextRefresh(IProgressMonitor monitor) {
747
    }
748

    
749
    /*
750
     * (non-Javadoc)
751
     *
752
     * @see
753
     * eu.etaxonomy.taxeditor.model.IContextListener#workbenchShutdown(org.eclipse
754
     * .ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
755
     */
756
    @Override
757
    public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
758
        conversation.clear();
759
        conversation.close();
760
        conversation = null;
761
    }
762

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

    
769
    /*
770
     * (non-Javadoc)
771
     *
772
     * @see
773
     * eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(
774
     * java.lang.Object)
775
     */
776
    @Override
777
    public void changed(Object element) {
778
        if (element != null) {
779
            viewer.update(element, null);
780
            setDirty(true);
781
        }
782
    }
783

    
784
    /* (non-Javadoc)
785
     * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty()
786
     */
787
    @Override
788
    public void forceDirty() {
789
        changed(null);
790
    }
791

    
792
    public void setDirty(boolean dirty) {
793
        this.dirty.setDirty(dirty);
794
    }
795

    
796
    /*
797
     * (non-Javadoc)
798
     *
799
     * @see org.eclipse.ui.forms.editor.FormEditor#isDirty()
800
     */
801
    public boolean isDirty() {
802
        return dirty.isDirty();
803
    }
804

    
805
    /* (non-Javadoc)
806
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
807
     */
808

    
809

    
810
//    /* (non-Javadoc)
811
//     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
812
//     */
813
//    @Override
814
//    public <T extends CdmBase> Collection<T> getRootEntities() {
815
//        // TODO Auto-generated method stub
816
//        return null;
817
//    }
818
//
819
//    /* (non-Javadoc)
820
//     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
821
//     */
822
//    @Override
823
//    public Map<Object, List<String>> getPropertyPathsMap() {
824
//        // TODO Auto-generated method stub
825
//        return null;
826
//    }
827

    
828
    /**
829
     * @return the labelProvider
830
     */
831
    public ChecklistLabelProvider getLabelProvider() {
832
        return labelProvider;
833
    }
834

    
835
    /* (non-Javadoc)
836
     * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
837
     */
838
    @Override
839
    public void update(CdmDataChangeMap arg0) {
840
        // TODO Auto-generated method stub
841

    
842
    }
843

    
844
    /* (non-Javadoc)
845
     * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
846
     */
847
    @Override
848
    public ConversationHolder getConversationHolder() {
849

    
850
        return conversation;
851
    }
852

    
853
    /* (non-Javadoc)
854
     * @see eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart#save(org.eclipse.core.runtime.IProgressMonitor)
855
     */
856
    @Override
857
    @Persist
858
    public void save(IProgressMonitor monitor) {
859
        doSave(monitor);
860

    
861
    }
862

    
863

    
864
}
(2-2/4)