Project

General

Profile

Download (29.1 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

    
27
import org.eclipse.e4.ui.di.Focus;
28
import org.eclipse.e4.ui.di.Persist;
29
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
30
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
31
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
32
import org.eclipse.jface.viewers.ISelectionChangedListener;
33

    
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.swt.SWT;
38
import org.eclipse.swt.events.ModifyListener;
39
import org.eclipse.swt.events.SelectionAdapter;
40
import org.eclipse.swt.events.SelectionEvent;
41
import org.eclipse.swt.layout.GridData;
42
import org.eclipse.swt.layout.GridLayout;
43
import org.eclipse.swt.widgets.Composite;
44

    
45
import org.eclipse.swt.widgets.Label;
46
import org.eclipse.swt.widgets.Menu;
47
import org.eclipse.swt.widgets.MenuItem;
48
import org.eclipse.swt.widgets.Table;
49
import org.eclipse.swt.widgets.TableColumn;
50
import org.eclipse.swt.widgets.Text;
51
import org.eclipse.swt.widgets.ToolBar;
52
import org.eclipse.swt.widgets.ToolItem;
53
import org.eclipse.ui.IEditorInput;
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

    
61
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
62
import eu.etaxonomy.cdm.model.taxon.Classification;
63

    
64
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
65
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
66
import eu.etaxonomy.taxeditor.editor.EditorUtil;
67
import eu.etaxonomy.taxeditor.editor.SimpleSelectionProvider;
68
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
69
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
70
import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistContentProvider;
71
import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditorComparator;
72
import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditorInput;
73
import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistLabelProvider;
74
import eu.etaxonomy.taxeditor.editor.view.checklist.filter.ChecklistEditorFilter;
75
import eu.etaxonomy.taxeditor.editor.view.checklist.listener.ChecklistFocusListener;
76
import eu.etaxonomy.taxeditor.editor.view.checklist.listener.ChecklistModifyListener;
77
import eu.etaxonomy.taxeditor.model.IContextListener;
78
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
79
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
80
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
81
import eu.etaxonomy.taxeditor.model.MessagingUtils;
82
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
83
import eu.etaxonomy.taxeditor.preference.Resources;
84
import eu.etaxonomy.taxeditor.store.CdmStore;
85

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

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

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

    
102

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

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

    
160
    private TableViewer viewer;
161

    
162
    private String partNameCache;
163

    
164
    //FIXME E4 migrate/delete ater full migration
165
    
166
    private IWorkbenchSiteProgressService service;
167

    
168
    private ITaxonNodeService taxonNodeService;
169

    
170
    private ChecklistEditorComparator comparator;
171

    
172
    private ChecklistEditorInput checklistEditorInput;
173

    
174
    private ConversationHolder conversation;
175

    
176
    private Integer countNodes;
177

    
178
    private List<TaxonNode> selectedTaxonNodes;
179

    
180
    @Inject
181
    private MPart thisPart;
182
    
183
    @Inject
184
    private MDirtyable dirty;
185
    
186
    @Inject
187
    private ESelectionService selService;
188

    
189
    private ISelectionChangedListener selectionChangedListener;
190

    
191
    private ChecklistEditorFilter filter;
192

    
193
    private Menu headerMenu;
194

    
195
    private Label statusLabel;
196

    
197
   // private final ICdmEntitySession cdmEntitySession;
198

    
199
    private ChecklistLabelProvider labelProvider;
200

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

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

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

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

    
224
    /** {@inheritDoc} */
225
    @PostConstruct
226
    public void createPartControl(Composite parent) {
227
    	if (!CdmStore.isActive()){
228
            return;
229
        }
230
        taxonNodeService = CdmStore.getService(ITaxonNodeService.class);
231
        viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
232
      
233
//        viewer.addSelectionChangedListener(new ISelectionChangedListener() {
234
//        	  @Override
235
//        	  public void selectionChanged(SelectionChangedEvent event) {
236
//        	    IStructuredSelection selection = viewer.getStructuredSelection();
237
//        	    Object firstElement = selection.getFirstElement();
238
//        	    // do something with it
239
//        	  }
240
//
241
//			
242
//        	}); 
243
      
244

    
245
        
246
        labelProvider = new ChecklistLabelProvider(this.viewer);
247

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

    
258
    /**
259
     * @param parent
260
     */
261
    private void createTopComposite(Composite parent) {
262
        GridLayout gridLayout = new GridLayout(3, false);
263
        gridLayout.marginWidth = 0;
264
        gridLayout.marginHeight = 0;
265
        parent.setLayout(gridLayout);
266

    
267
        final Text searchText = createSearchBar(parent);
268
        createToolbar(parent);
269

    
270
       // getSite().setSelectionProvider(viewer);
271

    
272
        final ModifyListener modifyListener = new ChecklistModifyListener(viewer, filter, searchText);
273

    
274
        searchText.addFocusListener(new ChecklistFocusListener(searchText, modifyListener));
275
        searchText.addModifyListener(modifyListener);
276
        createGridDataForViewerLayout();
277

    
278
        viewer.addFilter(filter);
279
        createTable();
280

    
281
        viewer.setContentProvider(new ChecklistContentProvider());
282
        viewer.setLabelProvider(this.labelProvider);
283
        comparator = new ChecklistEditorComparator();
284
        viewer.setComparator(comparator);
285

    
286
        createStatusBar(parent);
287
    }
288

    
289
	private void createGridDataForViewerLayout() {
290
		GridData gridData = new GridData();
291
		gridData.verticalAlignment = GridData.FILL;
292
        gridData.horizontalSpan = 3;
293
        gridData.grabExcessHorizontalSpace = true;
294
        gridData.grabExcessVerticalSpace = true;
295
        gridData.horizontalAlignment = GridData.FILL;
296
        viewer.getControl().setLayoutData(gridData);
297
	}
298

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

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

    
326
	private void createToolbarItems() {
327
		dropListener = new ChecklistDropdownSelectionListenerE4(toolItem, this, terms);
328

    
329
        for (DefinedTermBase<DefinedTermBase> term : terms) {
330
            if(term!=null){
331
                dropListener.add(term);
332
            }
333
        }
334
	}
335

    
336
    private void createStatusBar(Composite composite) {
337
        GridData gridData = new GridData();
338
        gridData.horizontalSpan = 3;
339
        gridData.grabExcessHorizontalSpace = true;
340
        gridData.horizontalAlignment = GridData.FILL;
341

    
342
        statusLabel = new Label(composite, SWT.LEFT);
343
        statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
344
        statusLabel.setLayoutData(gridData);
345
    }
346

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

    
359

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

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

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

    
463

    
464

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

    
501
    /** {@inheritDoc} */
502
    @PreDestroy
503
    public void dispose() {
504
//    	if(checklistEditorInput!=null){
505
//    		this.checklistEditorInput.getConversation().unregisterForDataStoreChanges(this.checklistEditorInput);
506
//    	}
507

    
508
    	if(conversation!=null){
509
    		conversation.unregisterForDataStoreChanges(this);
510
    		conversation.unbind();
511
    	}
512
        //conversation.close();
513
		conversation = null;
514
    }
515

    
516
    /** {@inheritDoc} */
517
    @Focus
518
    public void setFocus() {
519
    	if(viewer!=null && viewer.getControl()!=null && !viewer.getControl().isDisposed())
520
        viewer.getControl().setFocus();
521
    }
522

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

    
544
    /**
545
     * <p>
546
     * Getter for the field <code>viewer</code>.
547
     * </p>
548
     *
549
     * @return a {@link org.eclipse.jface.viewers.StructuredViewer} object.
550
     */
551
    public StructuredViewer getViewer() {
552
        return viewer;
553
    }
554

    
555
    public void refresh() {
556
        viewer.refresh();
557
    }
558

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

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

    
594
	private void acitivateNewColumnInDropDownMenu(DefinedTermBase term) {
595
		Menu menu = dropListener.getMenu();
596
		MenuItem[] items = menu.getItems();
597
		for(MenuItem item: items){
598
			if(item.getText().equalsIgnoreCase(term.getTitleCache())){
599
				item.setSelection(true);
600
				PreferencesUtil.getPreferenceStore().setValue(term.getUuid().toString(), true);
601
			}
602
		}
603
	}
604

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

    
622
    /**
623
     * <p>
624
     * Getter for the field <code>service</code>.
625
     * </p>
626
     *
627
     * @return the service
628
     */
629
    public IWorkbenchSiteProgressService getService() {
630
        return TaxeditorEditorPlugin.getDefault().getWorkbench().getService(IWorkbenchSiteProgressService.class);
631
    }
632

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

    
652
    @Persist
653
    public void doSave(IProgressMonitor monitor) {
654
        try {
655
            monitor.beginTask(Messages.ChecklistEditor_SAVE_EDITOR, 1);
656
            if (!conversation.isBound()) {
657
                conversation.bind();
658
            }
659
           this.checklistEditorInput.merge();
660
            //this.checklistEditorInput.merge();
661
            conversation.commit(true);
662
            setDirty(false);
663
            monitor.worked(1);
664
        } finally {
665
            monitor.done();
666
        }
667

    
668
    }
669

    
670
    public void init(IEditorInput input) {
671
        if (input instanceof ChecklistEditorInput) {
672
            checklistEditorInput = (ChecklistEditorInput) input;
673
            thisPart.setLabel(DISTRIBUTION_EDITOR+": " + checklistEditorInput.getName());
674
            conversation = checklistEditorInput.getConversation();
675
            conversation.registerForDataStoreChanges(this);
676
        }
677
        //propagate selection
678
        selectionChangedListener = (event -> selService.setSelection(event));
679
        viewer.addSelectionChangedListener(selectionChangedListener);
680
        
681

    
682
        loadDataInput();
683
    }
684

    
685

    
686
    /*
687
     * (non-Javadoc)
688
     *
689
     * @see
690
     * eu.etaxonomy.taxeditor.model.IContextListener#contextAboutToStop(org.
691
     * eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
692
     */
693

    
694
    @Override
695
    public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
696

    
697
    }
698

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

    
720
    /*
721
     * (non-Javadoc)
722
     *
723
     * @see
724
     * eu.etaxonomy.taxeditor.model.IContextListener#contextStart(org.eclipse
725
     * .ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
726
     */
727
    @Override
728
    public void contextStart(IMemento memento, IProgressMonitor monitor) {
729

    
730
    }
731

    
732
    /*
733
     * (non-Javadoc)
734
     *
735
     * @see
736
     * eu.etaxonomy.taxeditor.model.IContextListener#contextRefresh(org.eclipse
737
     * .core.runtime.IProgressMonitor)
738
     */
739
    @Override
740
    public void contextRefresh(IProgressMonitor monitor) {
741
    }
742

    
743
    /*
744
     * (non-Javadoc)
745
     *
746
     * @see
747
     * eu.etaxonomy.taxeditor.model.IContextListener#workbenchShutdown(org.eclipse
748
     * .ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
749
     */
750
    @Override
751
    public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
752
        conversation.clear();
753
        conversation.close();
754
        conversation = null;
755
    }
756

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

    
763
    /*
764
     * (non-Javadoc)
765
     *
766
     * @see
767
     * eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(
768
     * java.lang.Object)
769
     */
770
    @Override
771
    public void changed(Object element) {
772
        if (element != null) {
773
            viewer.update(element, null);
774
            setDirty(true);
775
        }
776
    }
777

    
778
    /* (non-Javadoc)
779
     * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty()
780
     */
781
    @Override
782
    public void forceDirty() {
783
        changed(null);
784
    }
785

    
786
    public void setDirty(boolean dirty) {
787
        this.dirty.setDirty(dirty);
788
    }
789

    
790
    /*
791
     * (non-Javadoc)
792
     *
793
     * @see org.eclipse.ui.forms.editor.FormEditor#isDirty()
794
     */
795
    public boolean isDirty() {
796
        return dirty.isDirty();
797
    }
798

    
799
    /* (non-Javadoc)
800
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
801
     */
802

    
803

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

    
822
    /**
823
     * @return the labelProvider
824
     */
825
    public ChecklistLabelProvider getLabelProvider() {
826
        return labelProvider;
827
    }
828

    
829
    /* (non-Javadoc)
830
     * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
831
     */
832
    @Override
833
    public void update(CdmDataChangeMap arg0) {
834
        // TODO Auto-generated method stub
835

    
836
    }
837

    
838
    /* (non-Javadoc)
839
     * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
840
     */
841
    @Override
842
    public ConversationHolder getConversationHolder() {
843

    
844
        return conversation;
845
    }
846

    
847

    
848
}
(2-2/3)