Project

General

Profile

Revision 1ba96658

ID1ba966581ceca19aa0665fcb9d6096c27f4aa3c1
Parent be9600f6
Child d8379b7b

Added by Patrick Plitzner over 1 year ago

ref #6913 Remove checklist editor

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/ChecklistEditor.java
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;
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 org.apache.log4j.Logger;
21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.IStatus;
23
import org.eclipse.core.runtime.Status;
24
import org.eclipse.core.runtime.jobs.Job;
25
import org.eclipse.jface.viewers.ISelection;
26
import org.eclipse.jface.viewers.StructuredViewer;
27
import org.eclipse.jface.viewers.TableViewer;
28
import org.eclipse.jface.viewers.TableViewerColumn;
29
import org.eclipse.swt.SWT;
30
import org.eclipse.swt.events.ModifyListener;
31
import org.eclipse.swt.events.SelectionAdapter;
32
import org.eclipse.swt.events.SelectionEvent;
33
import org.eclipse.swt.layout.GridData;
34
import org.eclipse.swt.layout.GridLayout;
35
import org.eclipse.swt.widgets.Composite;
36
import org.eclipse.swt.widgets.Display;
37
import org.eclipse.swt.widgets.Label;
38
import org.eclipse.swt.widgets.Menu;
39
import org.eclipse.swt.widgets.MenuItem;
40
import org.eclipse.swt.widgets.Table;
41
import org.eclipse.swt.widgets.TableColumn;
42
import org.eclipse.swt.widgets.Text;
43
import org.eclipse.swt.widgets.ToolBar;
44
import org.eclipse.swt.widgets.ToolItem;
45
import org.eclipse.ui.IEditorInput;
46
import org.eclipse.ui.IEditorSite;
47
import org.eclipse.ui.IMemento;
48
import org.eclipse.ui.ISelectionListener;
49
import org.eclipse.ui.ISelectionService;
50
import org.eclipse.ui.IWorkbenchPart;
51
import org.eclipse.ui.PartInitException;
52
import org.eclipse.ui.part.EditorPart;
53
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
54

  
55
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
56
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
57
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
58
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
59
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
60
import eu.etaxonomy.cdm.model.taxon.Classification;
61
import eu.etaxonomy.cdm.model.taxon.Taxon;
62
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
63
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
64
import eu.etaxonomy.taxeditor.editor.EditorUtil;
65
import eu.etaxonomy.taxeditor.editor.SimpleSelectionProvider;
66
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
67
import eu.etaxonomy.taxeditor.editor.view.checklist.edit.DistributionEditingSupport;
68
import eu.etaxonomy.taxeditor.editor.view.checklist.filter.ChecklistEditorFilter;
69
import eu.etaxonomy.taxeditor.editor.view.checklist.listener.ChecklistDropdownSelectionListener;
70
import eu.etaxonomy.taxeditor.editor.view.checklist.listener.ChecklistFocusListener;
71
import eu.etaxonomy.taxeditor.editor.view.checklist.listener.ChecklistModifyListener;
72
import eu.etaxonomy.taxeditor.model.IContextListener;
73
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
74
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
75
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
76
import eu.etaxonomy.taxeditor.model.MessagingUtils;
77
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
78
import eu.etaxonomy.taxeditor.preference.Resources;
79
import eu.etaxonomy.taxeditor.store.CdmStore;
80

  
81
/**
82
 * <p>
83
 * ChecklistViewPart class.
84
 * </p>
85
 *
86
 * @author a.oppermann
87
 * @created 30.04.2014
88
 * @version 1.0
89
 */
90
public class ChecklistEditor extends EditorPart implements ISelectionListener, IPartContentHasFactualData, IConversationEnabled,
91
        IContextListener, IDirtyMarkable, IPartContentHasDetails{
92

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

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

  
100

  
101
    private class ChecklistJob extends Job {
102

  
103
        private List<TaxonNode> taxonNodes;
104

  
105
        /**
106
         * @param name
107
         */
108
        public ChecklistJob(String title, List<TaxonNode> listTaxonNodes) {
109
            super(title);
110
            this.taxonNodes = listTaxonNodes;
111

  
112

  
113
        }
114

  
115
        /*
116
         * (non-Javadoc)
117
         *
118
         * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.
119
         * IProgressMonitor)
120
         */
121
        @Override
122
        public IStatus run(final IProgressMonitor monitor) {
123
            try {
124
                logger.debug("Begin of eclipse core runtime Job to Retrieve datasources"); //$NON-NLS-1$
125
                monitor.beginTask(Messages.ChecklistEditor_RETRIEVE_NODES, taxonNodes.size() + 1);
126

  
127
                final List<Taxon> taxonList = new ArrayList<Taxon>();
128

  
129
                for (TaxonNode taxonNode : taxonNodes) {
130
                    HibernateProxyHelper hh = new HibernateProxyHelper();
131
                    Taxon taxon = hh.deproxy(taxonNode.getTaxon(), Taxon.class);
132
                    taxonList.add(taxon);
133
                }
134
                // set View input
135
                Display.getDefault().asyncExec(new Runnable() {
136

  
137
                    @Override
138
                    public void run() {
139
                    	viewer.setInput(taxonList);
140
                    }
141
                });
142
                monitor.worked(1);
143

  
144
            } finally {
145
                monitor.done();
146
                taxonNodes = null;
147
            }
148
            return Status.OK_STATUS;
149
        }
150
    }
151

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

  
158
    private TableViewer viewer;
159

  
160
    private String partNameCache;
161

  
162
    private IWorkbenchSiteProgressService service;
163

  
164
    private ITaxonNodeService taxonNodeService;
165

  
166
    private ChecklistEditorComparator comparator;
167

  
168
    private ChecklistEditorInput checklistEditorInput;
169

  
170
    private SimpleSelectionProvider simpleSelectionProvider;
171

  
172
    private ISelectionService selectionService;
173

  
174
    private ConversationHolder conversation;
175

  
176
    private Integer countNodes;
177

  
178
    private List<TaxonNode> selectedTaxonNodes;
179

  
180
    private boolean dirty;
181

  
182
    private ChecklistEditorFilter filter;
183

  
184
    private Menu headerMenu;
185

  
186
    private Label statusLabel;
187

  
188
//    private ICdmEntitySession cdmEntitySession;
189

  
190
    private ChecklistLabelProvider labelProvider;
191

  
192
    private SortedSet<DefinedTermBase> terms = null;
193
	private ToolItem toolItem;
194
	private ChecklistDropdownSelectionListener dropListener;
195

  
196
    /**
197
     * @return the selectedTaxonNodes
198
     */
199
    public List<TaxonNode> getSelectedTaxonNodes() {
200
        return selectedTaxonNodes;
201
    }
202

  
203
    /**
204
     * @param selectedTaxonNodes
205
     *            the selectedTaxonNodes to set
206
     */
207
    public void setSelectedTaxonNodes(List<TaxonNode> selectedTaxonNodes) {
208
        this.selectedTaxonNodes = selectedTaxonNodes;
209
    }
210

  
211
    /**
212
     * <p>
213
     * Constructor for CdmDataSourceViewPart.
214
     * </p>
215
     */
216
    public ChecklistEditor() {
217
        //cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
218

  
219
    }
220

  
221
    /** {@inheritDoc} */
222
    @Override
223
    public void createPartControl(Composite parent) {
224
        service = getSite().getAdapter(IWorkbenchSiteProgressService.class);
225
        taxonNodeService = CdmStore.getService(ITaxonNodeService.class);
226
        selectionService = getSite().getWorkbenchWindow().getSelectionService();
227
        selectionService.addSelectionListener(this);
228
        viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
229

  
230
//        viewer.addSelectionChangedListener(new ISelectionChangedListener() {
231
//        	  @Override
232
//        	  public void selectionChanged(SelectionChangedEvent event) {
233
//        	    IStructuredSelection selection = viewer.getStructuredSelection();
234
//        	    Object firstElement = selection.getFirstElement();
235
//        	    // do something with it
236
//        	  }
237
//
238
//
239
//        	});
240
        labelProvider = new ChecklistLabelProvider(this.viewer);
241

  
242
        terms = labelProvider.getNamedAreas(false);
243
        if (terms == null){
244
			MessagingUtils.informationDialog(Messages.ChecklistEditor_NO_AREAS, Messages.ChecklistEditor_NO_AREAS_MESSAGE);
245
			this.dispose();
246
			return;
247
		}
248
        filter = new ChecklistEditorFilter();
249
        createTopComposite(parent);
250
        loadDataInput();
251
    }
252

  
253
    /**
254
     * @param parent
255
     */
256
    private void createTopComposite(Composite parent) {
257
        GridLayout gridLayout = new GridLayout(3, false);
258
        gridLayout.marginWidth = 0;
259
        gridLayout.marginHeight = 0;
260
        parent.setLayout(gridLayout);
261

  
262
        final Text searchText = createSearchBar(parent);
263
        createToolbar(parent);
264

  
265
       // getSite().setSelectionProvider(viewer);
266

  
267
        final ModifyListener modifyListener = new ChecklistModifyListener(viewer, filter, searchText);
268

  
269
        searchText.addFocusListener(new ChecklistFocusListener(searchText, modifyListener));
270
        searchText.addModifyListener(modifyListener);
271
        createGridDataForViewerLayout();
272

  
273
        viewer.addFilter(filter);
274
        createTable();
275

  
276
        viewer.setContentProvider(new ChecklistContentProvider());
277
        viewer.setLabelProvider(this.labelProvider);
278
        comparator = new ChecklistEditorComparator();
279
        viewer.setComparator(comparator);
280

  
281
        createStatusBar(parent);
282
    }
283

  
284
	private void createGridDataForViewerLayout() {
285
		GridData gridData = new GridData();
286
		gridData.verticalAlignment = GridData.FILL;
287
        gridData.horizontalSpan = 3;
288
        gridData.grabExcessHorizontalSpace = true;
289
        gridData.grabExcessVerticalSpace = true;
290
        gridData.horizontalAlignment = GridData.FILL;
291
        viewer.getControl().setLayoutData(gridData);
292
	}
293

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

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

  
321
	private void createToolbarItems() {
322
		dropListener = new ChecklistDropdownSelectionListener(toolItem, this, terms);
323

  
324
        for (DefinedTermBase<DefinedTermBase> term : terms) {
325
            if(term!=null){
326
                dropListener.add(term);
327
            }
328
        }
329
	}
330

  
331
    private void createStatusBar(Composite composite) {
332
        GridData gridData = new GridData();
333
        gridData.horizontalSpan = 3;
334
        gridData.grabExcessHorizontalSpace = true;
335
        gridData.horizontalAlignment = GridData.FILL;
336

  
337
        statusLabel = new Label(composite, SWT.LEFT);
338
        statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
339
        statusLabel.setLayoutData(gridData);
340
    }
341

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

  
354

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

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

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

  
458

  
459

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

  
490
    /** {@inheritDoc} */
491
    @Override
492
    public void dispose() {
493
//    	this.checklistEditorInput.dispose();
494
    	super.dispose();
495

  
496
        conversation.unregisterForDataStoreChanges(this);
497
        conversation.unbind();
498

  
499
        //conversation.close();
500
		conversation = null;
501
    }
502

  
503
    /** {@inheritDoc} */
504
    @Override
505
    public void setFocus() {
506

  
507
        viewer.getControl().setFocus();
508
    }
509

  
510
    /*
511
     * (non-Javadoc)
512
     *
513
     * @see org.eclipse.ui.part.WorkbenchPart#showBusy(boolean)
514
     */
515
    /** {@inheritDoc} */
516
    @Override
517
    public void showBusy(boolean busy) {
518
        super.showBusy(busy);
519
        // viewer.getTable().setEnabled(!busy);
520
        if (busy) {
521
            partNameCache = getPartName();
522
            setPartName(String.format(Messages.ChecklistEditor_LOAD_CNT_TAXA, countNodes));
523
        } else {
524
            if (partNameCache != null) {
525
                setPartName(partNameCache);
526
            }
527
        }
528
    }
529

  
530
    /**
531
     * <p>
532
     * Getter for the field <code>viewer</code>.
533
     * </p>
534
     *
535
     * @return a {@link org.eclipse.jface.viewers.StructuredViewer} object.
536
     */
537
    public StructuredViewer getViewer() {
538
        return viewer;
539
    }
540

  
541
    public void refresh() {
542
        viewer.refresh();
543
    }
544

  
545
    /**
546
     * This method should only be called for adding new Distribution columns and reloading the table.<br>
547
     * It will hide the old distribution column and load the newly added columns.<br>
548
     * <p>
549
     * <b>Notice:</b> for data update please use <b>refresh()</b>
550
     *
551
     */
552
    @SuppressWarnings({ "unchecked", "rawtypes" })
553
	public void reload(){
554
    	//create new Items for Dropdown menue
555
    	Table table = viewer.getTable();
556
    	table.setRedraw(false);
557
    	SortedSet<DefinedTermBase> oldTerms = terms;
558

  
559
//    	if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
560
//
561
//    	} else{
562
//    	    terms = (SortedSet<DefinedTermBase>) labelProvider.getTermsOrderedByLabels(labelProvider.getNamedAreas(), CdmStore.getDefaultLanguage());
563
//    	}
564
    	SortedSet<DefinedTermBase> newTerms = labelProvider.getNamedAreas(true);
565
    	toolItem.removeSelectionListener(dropListener);
566
    	hideDistributionColumns(oldTerms);
567
    	createToolbarItems();
568
    	toolItem.addSelectionListener(dropListener);
569
    	for(DefinedTermBase term:newTerms){
570
    		int count = viewer.getTable().getColumnCount();
571
    		addTableViewerColumn(term.getTitleCache(), 200, count);
572
    		acitivateNewColumnInDropDownMenu(term);
573
    	}
574
        viewer.setLabelProvider(labelProvider);
575
        getService().schedule(new ChecklistJob(LOADING_TAXA, selectedTaxonNodes), Job.LONG);
576
        table.setRedraw(true);
577
    	viewer.refresh();
578
    }
579

  
580
	private void acitivateNewColumnInDropDownMenu(DefinedTermBase term) {
581
		Menu menu = dropListener.getMenu();
582
		MenuItem[] items = menu.getItems();
583
		for(MenuItem item: items){
584
			if(item.getText().equalsIgnoreCase(term.getTitleCache())){
585
				item.setSelection(true);
586
				PreferencesUtil.getPreferenceStore().setValue(term.getUuid().toString(), true);
587
			}
588
		}
589
	}
590

  
591
	private void hideDistributionColumns(SortedSet<DefinedTermBase> oldTerms) {
592
		TableColumn[] columns = viewer.getTable().getColumns();
593
    	for(int i=4; i<columns.length; i++){
594
    		//remove all columns
595
    		columns[i].dispose();
596
    		Menu menu = dropListener.getMenu();
597
    		int itemCount = menu.getItemCount();
598
    		MenuItem item = menu.getItem(i-3);
599
    		item.setSelection(false);
600
    	}
601
    	if(oldTerms != null){
602
    		for(DefinedTermBase term : oldTerms){
603
    			PreferencesUtil.getPreferenceStore().setValue(term.getUuid().toString(), false);
604
    		}
605
    	}
606
	}
607

  
608
    /**
609
     * <p>
610
     * Getter for the field <code>service</code>.
611
     * </p>
612
     *
613
     * @return the service
614
     */
615
    public IWorkbenchSiteProgressService getService() {
616
        return service;
617
    }
618

  
619
    private SelectionAdapter getSelectionAdapter(final TableColumn column, final int index) {
620
        SelectionAdapter selectionAdapter = new SelectionAdapter() {
621
            @Override
622
            public void widgetSelected(SelectionEvent e) {
623
                comparator.setColumn(index);
624
                int dir = viewer.getTable().getSortDirection();
625
                if (viewer.getTable().getSortColumn() == column) {
626
                    dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
627
                } else {
628
                    dir = SWT.DOWN;
629
                }
630
                viewer.getTable().setSortDirection(dir);
631
                viewer.getTable().setSortColumn(column);
632
                viewer.refresh();
633
            }
634
        };
635
        return selectionAdapter;
636
    }
637

  
638
    @Override
639
    public void doSave(IProgressMonitor monitor) {
640
        try {
641
            monitor.beginTask(Messages.ChecklistEditor_SAVE_EDITOR, 1);
642
            if (!conversation.isBound()) {
643
                conversation.bind();
644
            }
645
            CdmStore.getService(ITaxonNodeService.class).merge(selectedTaxonNodes, true);
646
            //this.checklistEditorInput.merge();
647
            conversation.commit(true);
648
            setDirty(false);
649
            monitor.worked(1);
650
        } finally {
651
            monitor.done();
652
        }
653

  
654
    }
655

  
656
    @Override
657
    public void doSaveAs() {
658
    }
659

  
660
    @Override
661
    public void init(IEditorSite site, IEditorInput input) throws PartInitException {
662
        setSite(site);
663
        setInput(input);
664
        if (input instanceof ChecklistEditorInput) {
665
            checklistEditorInput = (ChecklistEditorInput) input;
666
            setPartName(getPartName() + ": " + checklistEditorInput.getName()); //$NON-NLS-1$
667
            conversation = checklistEditorInput.getConversation();
668
            conversation.registerForDataStoreChanges(this);
669
        }
670
        simpleSelectionProvider = new SimpleSelectionProvider();
671
        getSite().setSelectionProvider(simpleSelectionProvider);
672

  
673
    }
674

  
675
    @Override
676
    public boolean isSaveAsAllowed() {
677
        return false;
678
    }
679

  
680
    /*
681
     * (non-Javadoc)
682
     *
683
     * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.
684
     * IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
685
     */
686
    @Override
687
    public void selectionChanged(IWorkbenchPart part, ISelection selection) {
688
//    	System.out.println(selection.getClass().getSimpleName());
689
//    	viewer.setSelection(selection, true);
690
    }
691

  
692

  
693

  
694

  
695

  
696
    /*
697
     * (non-Javadoc)
698
     *
699
     * @see
700
     * eu.etaxonomy.taxeditor.model.IContextListener#contextAboutToStop(org.
701
     * eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
702
     */
703

  
704
    @Override
705
    public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
706

  
707
    }
708

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

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

  
740
    }
741

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

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

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

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

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

  
800
    public void setDirty(boolean dirty) {
801
        this.dirty = dirty;
802
        firePropertyChange(PROP_DIRTY);
803
    }
804

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

  
815
    /* (non-Javadoc)
816
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
817
     */
818

  
819

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

  
838
    /**
839
     * @return the labelProvider
840
     */
841
    public ChecklistLabelProvider getLabelProvider() {
842
        return labelProvider;
843
    }
844

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

  
852
    }
853

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

  
860
        return conversation;
861
    }
862

  
863

  
864
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/edit/DistributionEditingSupport.java
1
package eu.etaxonomy.taxeditor.editor.view.checklist.edit;
2

  
3
import java.util.Arrays;
4
import java.util.List;
5
import java.util.Set;
6
import java.util.SortedSet;
7

  
8
import org.apache.commons.lang.StringUtils;
9
import org.apache.log4j.Logger;
10
import org.eclipse.jface.viewers.ArrayContentProvider;
11
import org.eclipse.jface.viewers.CellEditor;
12
import org.eclipse.jface.viewers.ComboBoxViewerCellEditor;
13
import org.eclipse.jface.viewers.EditingSupport;
14
import org.eclipse.jface.viewers.LabelProvider;
15
import org.eclipse.jface.viewers.TableViewer;
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.widgets.Composite;
18
import org.eclipse.swt.widgets.TableColumn;
19

  
20
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
21
import eu.etaxonomy.cdm.model.common.TermType;
22
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
23
import eu.etaxonomy.cdm.model.description.Distribution;
24
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
25
import eu.etaxonomy.cdm.model.description.TaxonDescription;
26
import eu.etaxonomy.cdm.model.location.NamedArea;
27
import eu.etaxonomy.cdm.model.taxon.Taxon;
28
import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditor;
29
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
30
import eu.etaxonomy.taxeditor.store.CdmStore;
31

  
32
public final class DistributionEditingSupport extends EditingSupport {
33

  
34
    private ComboBoxViewerCellEditor cellEditor = null;
35
    private final TableViewer viewer;
36
    private final ChecklistEditor editor;
37
    private final int columnIndex;
38

  
39
    private static final Logger logger = Logger.getLogger(DistributionEditingSupport.class);
40

  
41
    public DistributionEditingSupport(TableViewer viewer, ChecklistEditor checklistEditor, int columnIndex) {
42
        super(viewer);
43
        this.viewer = viewer;
44
        this.columnIndex = columnIndex;
45

  
46
        editor = checklistEditor;
47
        cellEditor = new ComboBoxViewerCellEditor((Composite) viewer.getControl(), SWT.READ_ONLY);
48
        cellEditor.setLabelProvider(new LabelProvider(){
49
        	 @Override
50
        	   public String getText(Object element) {
51
        	     if (element instanceof PresenceAbsenceTerm) {
52
        	    	 PresenceAbsenceTerm  status = (PresenceAbsenceTerm)element;
53
        	    	 String result = null;
54
        	    	 if (PreferencesUtil.isShowSymbolInChecklistEditor() && !StringUtils.isBlank(status.getSymbol())){
55
        	    		 result = status.getTitleCache() + "("+ status.getSymbol()+")";
56
        	    	 }else{
57
        	    		 result = status.getTitleCache();
58
        	    	 }
59
        	    	 return result;
60
        	     }
61
        	     return null;
62
        	   }
63
        });
64
        cellEditor.setContentProvider(new ArrayContentProvider());
65
        // TODO set input
66
//        List<PresenceAbsenceTermBase> input = CdmStore.getTermManager()
67
//                .getPreferredTerms(PresenceAbsenceTermBase.class);
68
        List<DefinedTermBase<?>> input = CdmStore.getTermManager().getPreferredTerms(TermType.PresenceAbsenceTerm);
69
        cellEditor.setInput(input);
70
    }
71

  
72
    @Override
73
    protected CellEditor getCellEditor(Object element) {
74
        return cellEditor;
75
    }
76

  
77
    @Override
78
    protected boolean canEdit(Object element) {
79
        return true;
80
    }
81

  
82
    @Override
83
    protected Object getValue(Object element) {
84
        if (element instanceof Taxon) {
85
            Taxon taxon = (Taxon) element;
86
            String result = null;
87
            Distribution distributionForColumn = getDistributionForColumn(taxon);
88

  
89
            if (distributionForColumn != null) {
90
                PresenceAbsenceTerm status = distributionForColumn.getStatus();
91
                if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
92
                    if (status.getIdInVocabulary() != null){
93
                        result =  status.getIdInVocabulary();
94
                    } else{
95
                        result = status.getTitleCache();
96
                    }
97
                } else{
98
                    result = status.getTitleCache();
99
                }
100
                if (PreferencesUtil.isShowSymbolInChecklistEditor() && status.getSymbol() != null){
101
                	result.concat(" ("+ status.getSymbol() + ")");
102
                }
103
            }
104

  
105
            return result;
106
        }
107
        return null;
108
    }
109

  
110
    @Override
111
    protected void setValue(Object element, Object value) {
112
    	if (element instanceof Taxon && value instanceof PresenceAbsenceTerm) {
113
            Taxon taxon = (Taxon) element;
114
            PresenceAbsenceTerm occurenceStatus = (PresenceAbsenceTerm) value;
115
            Distribution distribution = getDistributionForColumn(taxon);
116
            if (distribution != null) {
117
                // change status for already exsiting distribution
118
                distribution.setStatus(occurenceStatus);
119
            } else {
120
                createDistributionForColumn(taxon, occurenceStatus);
121
            }
122
            // viewer.update(distribution, null);
123
//            viewer.update(element, null);
124
//            viewer.refresh();
125
//            editor.setDirty(true);
126
            editor.changed(element);
127
            viewer.refresh();
128
        }
129
    }
130

  
131
    private static final List<String> DESC_INIT_STRATEGY = Arrays.asList(new String[] { "descriptions", //$NON-NLS-1$
132
            "descriptions.*", "description.state" }); //$NON-NLS-1$ //$NON-NLS-2$
133

  
134
    /**
135
     *
136
     * @param taxon
137
     * @return
138
     */
139
    private Distribution getDistributionForColumn(Taxon taxon) {
140
//        List<TaxonDescription> listTaxonDescriptions = descriptionService.listTaxonDescriptions(taxon, null, null,
141
//                null, null, null, DESC_INIT_STRATEGY);
142
        Set<TaxonDescription> listTaxonDescriptions = taxon.getDescriptions();
143
        TableColumn column = viewer.getTable().getColumn(columnIndex);
144
        for (TaxonDescription td : listTaxonDescriptions) {
145
            for (DescriptionElementBase deb : td.getElements()) {
146
                if (deb instanceof Distribution) {
147
                    Distribution distribution = (Distribution) deb;
148
                    if (distribution.getArea() != null){
149
                        if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
150
                            if (column.getText().equalsIgnoreCase(distribution.getArea().getIdInVocabulary())) {
151
                                return distribution;
152
                            }
153
                        }else{
154
                            if (column.getText().equalsIgnoreCase(distribution.getArea().getTitleCache())) {
155
                                return distribution;
156
                            }
157
                        }
158
                    }
159
                }
160
            }
161
        }
162
        return null;
163
    }
164

  
165
    private void createDistributionForColumn(Taxon taxon, PresenceAbsenceTerm occurenceStatus) {
166
        TableColumn column = viewer.getTable().getColumn(columnIndex);
167

  
168
        SortedSet<DefinedTermBase> namedAreas = this.editor.getLabelProvider().getNamedAreas(false);
169

  
170

  
171
        if (namedAreas != null) {
172
            for (DefinedTermBase term : namedAreas) {
173
                boolean sameArea = true;
174
                if (!PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
175
                    sameArea = column.getText().equalsIgnoreCase(term.getTitleCache());
176
                } else{
177
                	if (term.getIdInVocabulary() != null){
178
                		sameArea = column.getText().equalsIgnoreCase(term.getIdInVocabulary());
179
                	} else{
180
                		sameArea = column.getText().equalsIgnoreCase(term.getTitleCache());
181
                	}
182
                }
183
                if (sameArea) {
184
                    NamedArea area = (NamedArea) term;
185
                    Distribution distribution = Distribution.NewInstance(area, occurenceStatus);
186
                    Set<TaxonDescription> descriptions = taxon.getDescriptions();
187
                    if (!descriptions.isEmpty()) {
188
                        for (TaxonDescription desc : descriptions) {
189
                            // add to first taxon description
190
                            desc.addElement(distribution);
191
                            break;
192
                        }
193
                    } else {// there are no TaxonDescription yet.
194
                        TaxonDescription td = TaxonDescription.NewInstance(taxon);
195
                        td.addElement(distribution);
196
                        break;
197
                    }
198
                }
199
            }
200
        }
201

  
202
        return;
203
    }
204
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/edit/RankEditingSupport.java
1
package eu.etaxonomy.taxeditor.editor.view.checklist.edit;
2

  
3
import java.util.List;
4

  
5
import org.apache.log4j.Logger;
6
import org.eclipse.jface.viewers.ArrayContentProvider;
7
import org.eclipse.jface.viewers.CellEditor;
8
import org.eclipse.jface.viewers.ComboBoxViewerCellEditor;
9
import org.eclipse.jface.viewers.EditingSupport;
10
import org.eclipse.jface.viewers.LabelProvider;
11
import org.eclipse.jface.viewers.TableViewer;
12
import org.eclipse.swt.SWT;
13
import org.eclipse.swt.widgets.Composite;
14

  
15
import eu.etaxonomy.cdm.model.name.Rank;
16
import eu.etaxonomy.cdm.model.taxon.Taxon;
17
import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditor;
18
import eu.etaxonomy.taxeditor.store.CdmStore;
19

  
20
public final class RankEditingSupport extends EditingSupport{
21

  
22
    private ComboBoxViewerCellEditor cellEditor = null;
23
    private final TableViewer viewer;
24
    private final ChecklistEditor editor;
25

  
26

  
27
    private static final Logger logger = Logger.getLogger(RankEditingSupport.class);
28

  
29
    public RankEditingSupport(TableViewer viewer, ChecklistEditor checklistEditor) {
30
        super(viewer);
31
        this.viewer = viewer;
32
        editor = checklistEditor;
33
        cellEditor = new ComboBoxViewerCellEditor((Composite) viewer.getControl(), SWT.READ_ONLY);
34
        cellEditor.setLabelProvider(new LabelProvider());
35
        cellEditor.setContentProvider(new ArrayContentProvider());
36
        //TODO set input
37
        List<Rank> input = CdmStore.getTermManager().getPreferredTerms(Rank.class);
38
        cellEditor.setInput(input);
39
    }
40

  
41
    @Override
42
    protected CellEditor getCellEditor(Object element) {
43
        return cellEditor;
44
    }
45

  
46
    @Override
47
    protected boolean canEdit(Object element) {
48
        return true;
49
    }
50

  
51
    @Override
52
    protected Object getValue(Object element) {
53
        if (element instanceof Taxon) {
54
            Taxon taxon = (Taxon)element;
55
            Rank rank = (taxon.getName().getRank() != null)?taxon.getName().getRank() : null;
56
            return rank;
57
        }
58
        return null;
59
    }
60

  
61
    @Override
62
    protected void setValue(Object element, Object value) {
63
        if (element instanceof Taxon && value instanceof Rank) {
64
            Taxon taxon = (Taxon)element;
65
            Rank rank = (Rank) value;
66
            taxon.getName().setRank(rank);
67
            viewer.update(element, null);
68
            viewer.refresh();
69
            editor.setDirty(true);
70
            editor.changed(element);
71
        }
72
    }
73

  
74
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/handler/CreateDescriptionHandler.java
1
/**
2
* Copyright (C) 2011 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
package eu.etaxonomy.taxeditor.editor.view.checklist.handler;
10

  
11
import org.eclipse.core.commands.AbstractHandler;
12
import org.eclipse.core.commands.ExecutionEvent;
13
import org.eclipse.core.commands.ExecutionException;
14
import org.eclipse.core.commands.common.NotDefinedException;
15
import org.eclipse.ui.IEditorInput;
16
import org.eclipse.ui.IEditorPart;
17
import org.eclipse.ui.IWorkbenchPart;
18
import org.eclipse.ui.forms.editor.FormEditor;
19
import org.eclipse.ui.handlers.HandlerUtil;
20

  
21
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
22
import eu.etaxonomy.cdm.model.taxon.Taxon;
23
import eu.etaxonomy.taxeditor.editor.EditorUtil;
24
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
25
import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4;
26
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateSpecimenDescriptionOperation;
27
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateTaxonDescriptionOperation;
28
import eu.etaxonomy.taxeditor.model.MessagingUtils;
29
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
30
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
31

  
32
/**
33
 * <p>AddDescriptionHandler class.</p>
34
 *
35
 * @author p.ciardelli
36
 * @created 11.08.2009
37
 * @version 1.0
38
 */
39
public class CreateDescriptionHandler extends AbstractHandler {
40

  
41
	/* (non-Javadoc)
42
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
43
	 */
44
	/** {@inheritDoc} */
45
	@Override
46
    public Object execute(ExecutionEvent event) throws ExecutionException {
47
		IWorkbenchPart part = HandlerUtil.getActivePart(event);
48
		IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
49

  
50
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
51
		if (editor instanceof FormEditor) {
52
			editor = ((FormEditor) editor).getActiveEditor();
53
		}
54
		IEditorInput input = editor.getEditorInput();
55
		AbstractPostOperation<?> operation;
56

  
57
		// taxon description
58
		if (input instanceof TaxonEditorInput) {
59
			Taxon taxon = ((TaxonEditorInput) input).getTaxon();
60
			try {
61
			    operation = createTaxonOperation(event.getCommand().getName(), taxon, postOperationEnabled);
62
			} catch (NotDefinedException e) {
63
				MessagingUtils.warn(getClass(), "Command name not set."); //$NON-NLS-1$
64
			}
65
		}
66
		// specimen description
67
		else if(part instanceof FactualDataPartE4){
68
		    Object viewerInput = ((FactualDataPartE4)part).getViewer().getInput();
69
		    if(viewerInput instanceof SpecimenOrObservationBase<?>){
70
		        try {
71
		            operation = new CreateSpecimenDescriptionOperation(event.getCommand().getName(), EditorUtil.getUndoContext(), (SpecimenOrObservationBase<?>) viewerInput, postOperationEnabled);
72
		        } catch (NotDefinedException e) {
73
		        	MessagingUtils.warn(getClass(), "Command name not set."); //$NON-NLS-1$
74
		        }
75
		    }
76
		}
77
		return null;
78
	}
79

  
80
	   /** {@inheritDoc} */
81
    protected CreateTaxonDescriptionOperation createTaxonOperation(String eventLabel, Taxon taxon, IPostOperationEnabled postOperationEnabled) {
82
        return new CreateTaxonDescriptionOperation(eventLabel, EditorUtil.getUndoContext(), taxon, postOperationEnabled);
83
    }
84

  
85
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/handler/OpenDistributionHandler.java
1
/**
2
 * Copyright (C) 2014 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
package eu.etaxonomy.taxeditor.editor.view.checklist.handler;
10

  
11
import java.util.Arrays;
12
import java.util.List;
13

  
14
import org.eclipse.core.commands.AbstractHandler;
15
import org.eclipse.core.commands.ExecutionEvent;
16
import org.eclipse.core.commands.ExecutionException;
17
import org.eclipse.jface.viewers.ISelection;
18
import org.eclipse.jface.viewers.IStructuredSelection;
19
import org.eclipse.jface.viewers.TableViewer;
20
import org.eclipse.swt.widgets.Table;
21
import org.eclipse.swt.widgets.TableColumn;
22
import org.eclipse.ui.handlers.HandlerUtil;
23

  
24
import eu.etaxonomy.cdm.model.taxon.Taxon;
25
import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditor;
26
import eu.etaxonomy.taxeditor.model.AbstractUtility;
27

  
28
/**
29
 * @author a.oppermann
30
 * @date 15.05.2014
31
 *
32
 */
33
public class OpenDistributionHandler extends AbstractHandler {
34

  
35
    @Override
36
    public Object execute(ExecutionEvent event) throws ExecutionException {
37

  
38
        ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
39
        ChecklistEditor editor = (ChecklistEditor) AbstractUtility.getActiveEditor();
40

  
41
        if (currentSelection instanceof IStructuredSelection) {
42

  
43
            Object selectedElement = ((IStructuredSelection) currentSelection).getFirstElement();
44
            if (selectedElement instanceof Taxon) {
45
                TableViewer viewer = (TableViewer)editor.getViewer();
46
                final Table table = viewer.getTable();
47

  
48
                TableColumn column2 = table.getColumn(4);
49
                column2.setWidth(100);
50
                viewer.refresh();
51

  
52
            }
53
        }
54
        return null;
55
    }
56
    private static final List<String> DESC_INIT_STRATEGY = Arrays.asList(new String[]{
57
            "descriptions", //$NON-NLS-1$
58
            "descriptions.*", //$NON-NLS-1$
59
            "description.state" //$NON-NLS-1$
60
    });
61

  
62

  
63

  
64
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/listener/ChecklistDropdownSelectionListener.java
1
package eu.etaxonomy.taxeditor.editor.view.checklist.listener;
2

  
3
import java.util.SortedSet;
4

  
5
import org.apache.log4j.Logger;
6
import org.eclipse.jface.viewers.TableViewer;
7
import org.eclipse.jface.wizard.WizardDialog;
8
import org.eclipse.swt.SWT;
9
import org.eclipse.swt.events.SelectionAdapter;
10
import org.eclipse.swt.events.SelectionEvent;
11
import org.eclipse.swt.graphics.Point;
12
import org.eclipse.swt.graphics.Rectangle;
13
import org.eclipse.swt.widgets.Menu;
14
import org.eclipse.swt.widgets.MenuItem;
15
import org.eclipse.swt.widgets.Table;
16
import org.eclipse.swt.widgets.TableColumn;
17
import org.eclipse.swt.widgets.ToolItem;
18

  
19
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
20
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
21
import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditor;
22
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
23
import eu.etaxonomy.taxeditor.preference.wizard.AvailableDistributionWizard;
24
import eu.etaxonomy.taxeditor.store.StoreUtil;
25

  
26
/**
27
 * Handles drop down menu selection. Available items are defined in the
28
 * enumeration SearchOption.
29
 *
30
 * @author n.hoffmann
31
 * @created Feb 2, 2010
32
 * @version 1.0
33
 */
34
public class ChecklistDropdownSelectionListener extends SelectionAdapter {
35

  
36
    private final Menu menu;
37
    private final ChecklistEditor editor;
38
    private final SortedSet<DefinedTermBase> termSet;
39
    private Logger logger = Logger.getLogger(ChecklistDropdownSelectionListener.class);
40
    
41
    public ChecklistDropdownSelectionListener(ToolItem dropdown, ChecklistEditor editor,
42
            SortedSet<DefinedTermBase> termSet) {
43
        this.editor = editor;
44
        this.termSet = termSet;
45
        menu = new Menu(dropdown.getParent().getShell());
46
        initialMenuItem();
47
    }
48

  
49
    // SearchOption option
50
    public void add(DefinedTermBase<DefinedTermBase> term) {
51
        MenuItem menuItem = new MenuItem(menu, SWT.CHECK);
52
        menuItem.setText(term.getTitleCache());
53
        if (PreferencesUtil.getPreferenceStore().getBoolean(term.getUuid().toString())) {
54
            menuItem.setSelection(true);
55
        } else {
56
            menuItem.setSelection(false);
57
        }
58
        menuItem.addSelectionListener(new SelectionAdapter() {
59
            @Override
60
            public void widgetSelected(SelectionEvent event) {
61
                MenuItem selected = (MenuItem) event.widget;
62

  
63
                TableViewer viewer = (TableViewer) editor.getViewer();
64
                final Table table = viewer.getTable();
65
                // TODO make it selectable according to selection event
66
                TableColumn column = null;
67
                DefinedTermBase<DefinedTermBase> selectedTerm = null;
68
                if (termSet != null) {
69
                	TableColumn[] columns = viewer.getTable().getColumns();
70
                	for(int i=0; i<columns.length; i++){
71
                		if(selected.getText().equalsIgnoreCase(columns[i].getText())){
72
                			column = columns[i];
73
                			logger.info("Column no " +i +" Column Header "+ column.getText() ); //$NON-NLS-1$ //$NON-NLS-2$
74
                			for (DefinedTermBase<DefinedTermBase> term : termSet) {
75
                				if(column.getText().equalsIgnoreCase(term.getTitleCache())){
76
                					selectedTerm = term;
77
                					break;
78
                				}
79
                			}
80
                		}
81
                	}
82
                }
83
                if (column != null && column.getWidth() == 0) {
84
                    // save column status if shown or not
85
                    if (selectedTerm != null) {
86
                        PreferencesUtil.getPreferenceStore().setValue(selectedTerm.getUuid().toString(), true);
87
                    }
88
                    column.setWidth(100);
89
                } else if (column != null) {
90
                    if (selectedTerm != null) {
91
                        PreferencesUtil.getPreferenceStore().setValue(selectedTerm.getUuid().toString(), false);
92
                    }
93
                    column.setWidth(0);
94
                }
95
            }
96
        });
97
    }
98

  
99
    private void initialMenuItem(){
100
        MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
101
        menuItem.setText(Messages.ChecklistDropdownSelectionListener_ADD_DISTRIBUTION);
102
        menuItem.addSelectionListener(new SelectionAdapter() {
103
            @Override
104
            public void widgetSelected(SelectionEvent event) {
105
                AvailableDistributionWizard availableDistributionWizard = new AvailableDistributionWizard();
106
                WizardDialog dialog = new WizardDialog(StoreUtil.getShell(),
107
                        availableDistributionWizard);
108

  
109
                int open = dialog.open();
110
                if(open == 0){
111
                	editor.reload();
112
                }
113
            }
114
        });
115
        new MenuItem(menu, SWT.SEPARATOR);
116
    }
117

  
118
    @Override
119
    public void widgetSelected(SelectionEvent event) {
120
        if (event.detail == SWT.ARROW) {
121
            ToolItem item = (ToolItem) event.widget;
122
            Rectangle rect = item.getBounds();
123
            Point pt = item.getParent().toDisplay(new Point(rect.x, rect.y));
124
            menu.setLocation(pt.x, pt.y + rect.height);
125
            menu.setVisible(true);
126
        } else {
127
            menu.setVisible(true);
128
        }
129
    }
130
    
131
    public Menu getMenu(){
132
    	return menu;
133
    }
134
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/listener/ChecklistFocusListener.java
6 6
import org.eclipse.swt.widgets.Text;
7 7

  
8 8
import eu.etaxonomy.taxeditor.editor.EditorUtil;
9
import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditor;
9
import eu.etaxonomy.taxeditor.editor.view.checklist.e4.ChecklistEditorE4;
10 10
import eu.etaxonomy.taxeditor.preference.Resources;
11 11

  
12 12
public class ChecklistFocusListener implements FocusListener{
......
22 22

  
23 23
    @Override
24 24
    public void focusGained(FocusEvent e) {
25
        if (ChecklistEditor.TYPE_FILTER_TEXT.equals(searchText.getText())) {
25
        if (ChecklistEditorE4.TYPE_FILTER_TEXT.equals(searchText.getText())) {
26 26
            searchText.setForeground(EditorUtil.getColor(Resources.SEARCH_VIEW_FOCUS));
27 27
            searchText.setText(""); //$NON-NLS-1$
28 28
        }
......
35 35
            searchText.removeModifyListener(modifyListener);
36 36

  
37 37
            searchText.setForeground(EditorUtil.getColor(Resources.SEARCH_VIEW_FOREGROUND));
38
            searchText.setText(ChecklistEditor.TYPE_FILTER_TEXT);
38
            searchText.setText(ChecklistEditorE4.TYPE_FILTER_TEXT);
39 39

  
40 40
            searchText.addModifyListener(modifyListener);
41 41
        }
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)