Project

General

Profile

Revision 4f25e642

ID4f25e6422b5f543eda7bfe4f4dd4f7f869277c7a
Parent 7cc3798b
Child 9c8494ea

Added by Katja Luther over 2 years ago

ref #7063: add vocabulary selection for distribution editor and area selection in editor

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/ChecklistLabelProvider.java
27 27
import org.eclipse.swt.widgets.TableColumn;
28 28

  
29 29
import eu.etaxonomy.cdm.api.service.IDescriptionService;
30
import eu.etaxonomy.cdm.api.service.ITermService;
30
import eu.etaxonomy.cdm.api.service.IVocabularyService;
31 31
import eu.etaxonomy.cdm.common.CdmUtils;
32 32
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
33 33
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
......
170 170
    private SortedSet<DefinedTermBase> loadNamedAreas() {
171 171
        IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
172 172

  
173
        String values = preferenceStore.getString(PreferencesUtil.DISTRIBUTION_AREA_OCCURENCE_STATUS);
174

  
173
        String valuesAreas = preferenceStore.getString(PreferencesUtil.DISTRIBUTION_AREA_OCCURENCE_STATUS);
174
        String values = preferenceStore.getString(PreferencesUtil.DISTRIBUTION_VOCABULARIES);
175 175
        if (values != null && values != "") { //$NON-NLS-1$
176 176
            String[] split = values.split(","); //$NON-NLS-1$
177 177
            List<String> listValue = Arrays.asList(split);
......
183 183
                uuidList.add(uuid);
184 184

  
185 185
            }
186
            ITermService service = CdmStore.getService(ITermService.class);
187
            termlist = service.find(uuidList);
186
            IVocabularyService service =  CdmStore.getService(IVocabularyService.class);
187
            List<TermVocabulary> vocs = service.find(uuidList);
188
            split = valuesAreas.split(",");
189
            listValue = Arrays.asList(split);
190
            for (TermVocabulary voc: vocs){
191
                termlist.addAll(service.getTerms(voc, null, null, null, null).getRecords());
192
            }
193
            List<DefinedTermBase> filteredList = new ArrayList();
194
            for (DefinedTermBase area: termlist){
195
                if (listValue.contains(area.getUuid().toString())) {
196
                    filteredList.add(area);
197
                }
198

  
199
            }
200

  
188 201
            if (PreferencesUtil.isSortNamedAreaByOrderInVocabulary()){
189
                return getTermsOrderedByVocabularyOrder(termlist);
202
                return getTermsOrderedByVocabularyOrder(filteredList);
190 203
            } else if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
191
                return getTermsOrderedByIdInVocabulary(termlist);
204
                return getTermsOrderedByIdInVocabulary(filteredList);
192 205
            }else{
193
                return getTermsOrderedByLabels(termlist, CdmStore.getDefaultLanguage());
206
                return getTermsOrderedByLabels(filteredList, CdmStore.getDefaultLanguage());
194 207
            }
195 208
        }
196 209
        return null;
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/ChecklistDropdownSelectionListenerE4.java
42 42
        this.editor = editor;
43 43
        this.termSet = termSet;
44 44
        menu = new Menu(dropdown.getParent().getShell());
45

  
45 46
        initialMenuItem();
46 47
    }
47 48

  
48 49
    // SearchOption option
49 50
    public void add(DefinedTermBase<DefinedTermBase> term) {
50 51
        MenuItem menuItem = new MenuItem(menu, SWT.CHECK);
51
   
52

  
52 53
           menuItem.setText(term.getTitleCache());
53 54

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

  
71
                Integer position = editor.getAreaPosition().get(term.getUuid());
72
                TableColumn[] columns = viewer.getTable().getColumns();
73
                column = columns[position];
74

  
75
                if (column != null && column.getWidth() == 0) {
76
                    // save column status if shown or not
77
                    if (term != null) {
78
                        PreferencesUtil.getPreferenceStore().setValue(term.getUuid().toString(), true);
79
                    }
80
                    column.setWidth(50);
81
                } else if (column != null) {
82
                    if (term != null) {
83
                        PreferencesUtil.getPreferenceStore().setValue(term.getUuid().toString(), false);
84
                    }
85
                    column.setWidth(0);
102 86
                }
103
                
87
//                if (termSet != null) {
88
//                	TableColumn[] columns = viewer.getTable().getColumns();
89
//                	for (DefinedTermBase<DefinedTermBase> term : termSet) {
90
//                		if(selected.getText().equalsIgnoreCase(term.getTitleCache())){
91
//                		    selectedTerm = term;
92
//        					for(int i=0; i<columns.length; i++){
93
//        						column = null;
94
//                        		if(columns[i].getText().equalsIgnoreCase(term.getIdInVocabulary())){
95
//                        			column = columns[i];
96
//                        			logger.info("Column no " +i +" Column Header "+ column.getText() ); //$NON-NLS-1$ //$NON-NLS-2$
97
//                				}else if (columns[i].getText().equalsIgnoreCase(term.getTitleCache())){
98
//                					column = columns[i];
99
//                        			logger.info("Column no " +i +" Column Header "+ column.getText() ); //$NON-NLS-1$ //$NON-NLS-2$
100
//
101
//                        		}
102
//                        		if (column != null && column.getWidth() == 0) {
103
//                                    // save column status if shown or not
104
//                                    if (selectedTerm != null) {
105
//                                        PreferencesUtil.getPreferenceStore().setValue(selectedTerm.getUuid().toString(), true);
106
//                                    }
107
//                                    column.setWidth(50);
108
//                                } else if (column != null) {
109
//                                    if (selectedTerm != null) {
110
//                                        PreferencesUtil.getPreferenceStore().setValue(selectedTerm.getUuid().toString(), false);
111
//                                    }
112
//                                    column.setWidth(0);
113
//                                }
114
//                        	}
115
//        					break;
116
//        				}
117
//
118
//        			}
119
//
120
//                }
121

  
104 122
                editor.refresh();
105
                
123

  
106 124
            }
107 125
        });
108 126
    }
......
134 152
            Point pt = item.getParent().toDisplay(new Point(rect.x, rect.y));
135 153
            menu.setLocation(pt.x, pt.y + rect.height);
136 154
            menu.setVisible(true);
155

  
137 156
        } else {
138 157
            menu.setVisible(true);
139 158
        }
159

  
140 160
    }
141 161

  
142 162
    public Menu getMenu(){
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/ChecklistEditorE4.java
17 17
import java.util.List;
18 18
import java.util.Map;
19 19
import java.util.SortedSet;
20
import java.util.UUID;
20 21

  
21 22
import javax.annotation.PostConstruct;
22 23
import javax.annotation.PreDestroy;
......
37 38
import org.eclipse.jface.viewers.TableViewerColumn;
38 39
import org.eclipse.jface.viewers.TableViewerEditor;
39 40
import org.eclipse.jface.viewers.TableViewerFocusCellManager;
41
import org.eclipse.jface.wizard.WizardDialog;
40 42
import org.eclipse.swt.SWT;
41 43
import org.eclipse.swt.events.ModifyListener;
42 44
import org.eclipse.swt.events.SelectionAdapter;
......
76 78
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
77 79
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
78 80
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
79
import eu.etaxonomy.taxeditor.model.MessagingUtils;
80 81
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
81 82
import eu.etaxonomy.taxeditor.preference.Resources;
83
import eu.etaxonomy.taxeditor.preference.wizard.AvailableDistributionWizard;
82 84
import eu.etaxonomy.taxeditor.store.CdmStore;
85
import eu.etaxonomy.taxeditor.store.StoreUtil;
83 86
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
84 87

  
85 88
/**
......
135 138

  
136 139
    private ChecklistLabelProvider labelProvider;
137 140
//TODO: maybe it is better to use a hashMap for better handling of adding and removing terms??
138
    private HashMap<String, DefinedTermBase> terms = null;
139
	private ToolItem toolItem;
141
    private Map<UUID, Integer> areaPosition= new HashMap();
142

  
143
    private ToolItem toolItem;
140 144
	private ChecklistDropdownSelectionListenerE4 dropListener;
141 145
	private Text searchText;
142 146

  
143

  
147
	public Map<UUID, Integer> getAreaPosition() {
148
        return areaPosition;
149
    }
144 150
    /**
145 151
     * @return the selectedTaxonNodes
146 152
     */
......
190 196

  
191 197

  
192 198
        labelProvider = new ChecklistLabelProvider(this.viewer);
193
        SortedSet<DefinedTermBase> termSet = labelProvider.getNamedAreas(false);
194
        terms = new HashMap();
195
        for (DefinedTermBase term : termSet){
196
                terms.put(term.getTitleCache(), term);
197
        }
198
        if (terms == null){
199
			MessagingUtils.informationDialog(Messages.ChecklistEditor_NO_AREAS, Messages.ChecklistEditor_NO_AREAS_MESSAGE);
200
			this.dispose();
201
			return;
202
		}
199
       // SortedSet<DefinedTermBase> termSet = labelProvider.getNamedAreas(true);
200
//        terms = new HashMap();
201
//        for (DefinedTermBase term : termSet){
202
//                terms.put(term.getUuid(), term);
203
//        }
204
//        if (terms == null){
205
//			MessagingUtils.informationDialog(Messages.ChecklistEditor_NO_AREAS, Messages.ChecklistEditor_NO_AREAS_MESSAGE);
206
//			this.dispose();
207
//			return;
208
//		}
203 209

  
204 210

  
205 211
        viewer.addFilter(filter);
......
267 273
     */
268 274
    private void createToolbar(Composite parent) {
269 275
        ToolBar toolBar = new ToolBar(parent, SWT.NONE);
270
        toolItem = new ToolItem(toolBar, SWT.DROP_DOWN | SWT.BORDER);
276
      //  toolItem = new ToolItem(toolBar, SWT.DROP_DOWN | SWT.BORDER);
277
        toolItem = new ToolItem(toolBar, SWT.BUTTON1);
278

  
271 279
        toolItem.setText(Messages.ChecklistEditor_DIST_STATUS);
272 280
        toolItem.setToolTipText(Messages.ChecklistEditor_DIST_STATUS_TOOLTIP);
273
        createToolbarItems();
274
        toolItem.addSelectionListener(dropListener);
281
        //createToolbarItems();
282
      //  toolItem.addSelectionListener(dropListener);
283
        toolItem.addSelectionListener(new SelectionAdapter() {
284
            @Override
285
            public void widgetSelected(SelectionEvent event) {
286
                AvailableDistributionWizard availableDistributionWizard = new AvailableDistributionWizard();
287
                WizardDialog dialog = new WizardDialog(StoreUtil.getShell(),
288
                        availableDistributionWizard);
289

  
290
                int open = dialog.open();
291
                if(open == 0){
292
                    reload();
293
                }
294
            }
295
        });
275 296
        toolBar.pack();
276 297
    }
277 298

  
......
368 389
	private Map<Integer, Boolean> restoreValuesForColumnWidth(List<String> titles,
369 390
			List<Integer> bounds) {
370 391
		Map<Integer, Boolean> restoreColumnWidth = new HashMap<Integer, Boolean>();
371
		if (labelProvider.getNamedAreas(false) != null) {
392
		if (labelProvider.getNamedAreas(true) != null) {
372 393
		    int columnIndex;
373 394
		    if (PreferencesUtil.isShowRankInChecklistEditor()){
374 395
		        columnIndex = 2;
......
378 399
            for (DefinedTermBase<DefinedTermBase> term : getLabelProvider().getNamedAreas(false)) {
379 400
                if(term != null){
380 401
                    restoreColumnWidth.put(columnIndex, PreferencesUtil.getPreferenceStore().getBoolean(term.getUuid().toString()));
402
                    areaPosition.put(term.getUuid(), columnIndex);
381 403
                    if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
382 404
                        if (term.getIdInVocabulary() != null){
383 405
                            titles.add(term.getIdInVocabulary());
......
403 425
     * @param colNumber
404 426
     * @return
405 427
     */
406
    private TableViewerColumn addTableViewerColumn(String title, int bound, final int colNumber) {
428
    private TableViewerColumn addTableViewerColumn(String title, int bound, final int colNumber, DefinedTermBase term) {
407 429

  
408 430
        final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
409 431
        final TableColumn column = viewerColumn.getColumn();
410 432
        column.setText(title);
433
        String[] UuidAndLable = new String[2];
434
        UuidAndLable[0] = term.getUuid().toString();
435
        UuidAndLable[1] = title;
436
        column.setData(UuidAndLable);
411 437
        column.setWidth(200);
412 438
        viewerColumn.setEditingSupport(new DistributionEditingSupportE4(viewer, this, colNumber));
413 439
        column.setResizable(true);
......
533 559
//    	}
534 560
    	SortedSet<DefinedTermBase> newTerms = labelProvider.getNamedAreas(true);
535 561
    	//terms = newTerms;
536
    	toolItem.removeSelectionListener(dropListener);
537
//    	hideDistributionColumns(oldTerms);
538
    	createToolbarItems();
539
    	toolItem.addSelectionListener(dropListener);
562
//    	toolItem.removeSelectionListener(dropListener);
563
////    	hideDistributionColumns(oldTerms);
564
//    	createToolbarItems();
565
//    	toolItem.addSelectionListener(dropListener);
540 566

  
541 567
    	//check which terms are deleted and which are new.
542 568
    	TableColumn[] columns = viewer.getTable().getColumns() ;
543 569
    	int index = 0;
544
    	for (TableColumn column: columns){
545
    	    if ((!PreferencesUtil.isShowRankInChecklistEditor() && index > 0) || (index > 1)) {
570

  
571
      for (TableColumn column: columns){
572
          if ((!PreferencesUtil.isShowRankInChecklistEditor() && index > 0) || (index > 1)) {
546 573
                column.dispose();
547 574
            }
548
    	    index++;
549
    	}
575
          index++;
576
      }
577
    	for (DefinedTermBase oldTerm:oldTerms){
578
            boolean delete = true;
579
            for (DefinedTermBase term: newTerms){
580
                   if(oldTerm.getUuid().equals(term.getUuid())){
581
                       delete = false;
582
                       break;
583
                   }
584

  
585
            }
586
            if (delete){
587
               // viewer.getTable().remove(areaPosition.get(oldTerm.getUuid()));
588
                areaPosition.remove(oldTerm.getUuid());
589

  
590
            }
591
        }
592
    	updateColumnIndex();
593

  
594

  
550 595

  
551 596
    	for (DefinedTermBase term:newTerms){
552 597
    	    boolean isNew = true;
553
    	    for (DefinedTermBase oldTerm: oldTerms){
554
    	           if(oldTerm.getTitleCache().equals(term.getTitleCache())){
555
    	               isNew = false;
556
    	               break;
557
    	           }
558 598

  
559
    	    }
560
    	    if (isNew){
561
    	        terms.put(term.getTitleCache(),term);
599
    	    Integer position = areaPosition.get(term.getUuid());
562 600

  
563
    	    }
564 601
    	    String termLable = term.getTitleCache();;
565 602
            if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
566 603
                if (term.getIdInVocabulary() != null){
567 604
                    termLable = term.getIdInVocabulary();
568 605
                }
569 606
            }
570
            int count = viewer.getTable().getColumnCount();
571
            TableViewerColumn column= addTableViewerColumn(termLable, 200, count);
572
            acitivateNewColumnInDropDownMenu(term);
573
    	}
574
    	for (DefinedTermBase oldTerm:oldTerms){
575
    	    boolean delete = true;
576
            for (DefinedTermBase term: newTerms){
577
                   if(oldTerm.getTitleCache().equals(term.getTitleCache())){
578
                       delete = false;
579
                       break;
580
                   }
581 607

  
608
            if (position == null){
609
                int count = viewer.getTable().getColumnCount();
610
                TableViewerColumn column= addTableViewerColumn(termLable, 200, count, term);
611
                areaPosition.put(term.getUuid(), Integer.valueOf(count));
612
            }else{
613
                TableViewerColumn column= addTableViewerColumn(termLable, 200, position, term);
582 614
            }
583
            if (delete){
584
                terms.remove(oldTerm);
585 615

  
586
            }
587
        }
616
           // acitivateNewColumnInDropDownMenu(term);
617
    	}
618

  
588 619

  
589 620

  
590 621
//    	for(DefinedTermBase term:terms.values()){
......
613 644
    	viewer.refresh();
614 645
    }
615 646

  
616
	private void acitivateNewColumnInDropDownMenu(DefinedTermBase term) {
647
	/**
648
     *
649
     */
650
    private void updateColumnIndex() {
651
        int columnIndex;
652
        if (PreferencesUtil.isShowRankInChecklistEditor()){
653
            columnIndex = 2;
654
        } else{
655
            columnIndex = 1;
656
        }
657
        for (UUID uuid:areaPosition.keySet()){
658
            areaPosition.put(uuid, columnIndex);
659
            columnIndex++;
660
        }
661

  
662
    }
663
    private void acitivateNewColumnInDropDownMenu(DefinedTermBase term) {
617 664
		Menu menu = dropListener.getMenu();
618 665
		MenuItem[] items = menu.getItems();
619 666
		for(MenuItem item: items){
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/VocabularyContentProvider.java
1
/**
2
* Copyright (C) 2009 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.definedterm;
10

  
11
import java.util.Collection;
12

  
13
import org.eclipse.jface.viewers.IStructuredContentProvider;
14
import org.eclipse.jface.viewers.Viewer;
15

  
16
import eu.etaxonomy.cdm.model.common.TermVocabulary;
17

  
18
/**
19
 * @author l.morris
20
 * @date 8 Dec 2011
21
 *
22
 */
23
public class VocabularyContentProvider implements IStructuredContentProvider {
24

  
25
	/* (non-Javadoc)
26
	 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
27
	 */
28
	@Override
29
	public void dispose() {
30
		// TODO Auto-generated method stub
31

  
32
	}
33

  
34
	/* (non-Javadoc)
35
	 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
36
	 */
37
	@Override
38
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
39
		// TODO Auto-generated method stub
40

  
41
	}
42

  
43
	/* (non-Javadoc)
44
	 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
45
	 */
46
	@Override
47
	public Object[] getElements(Object inputElement) {
48

  
49
		Collection<TermVocabulary> inputElements = (Collection<TermVocabulary>) inputElement;
50
		return inputElements.toArray();
51

  
52
	}
53

  
54
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/VocabularyLabelProvider.java
1
/**
2
 * Copyright (C) 2009 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.definedterm;
10

  
11
import java.util.ArrayList;
12

  
13
import org.eclipse.jface.viewers.StyledCellLabelProvider;
14
import org.eclipse.jface.viewers.StyledString;
15
import org.eclipse.jface.viewers.StyledString.Styler;
16
import org.eclipse.jface.viewers.ViewerCell;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.custom.StyleRange;
19
import org.eclipse.swt.graphics.Color;
20
import org.eclipse.swt.graphics.TextStyle;
21
import org.eclipse.swt.widgets.Display;
22

  
23
import eu.etaxonomy.cdm.common.CdmUtils;
24
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
25
import eu.etaxonomy.cdm.model.common.Language;
26
import eu.etaxonomy.cdm.model.common.Representation;
27
import eu.etaxonomy.cdm.model.common.TermVocabulary;
28
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
29

  
30
/**
31
 * @author l.morris
32
 * @date 9 Dec 2011
33
 *
34
 */
35
public class VocabularyLabelProvider extends StyledCellLabelProvider {
36

  
37
    private static Color vocColor = Display.getCurrent().getSystemColor(SWT.COLOR_BLUE);
38
    private static Color kindOfColor = Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY);
39
    private Styler vocStyler;
40
    private Styler kindOfStyler;
41

  
42
    public VocabularyLabelProvider() {
43
    }
44

  
45
    public VocabularyLabelProvider(Styler vocStyler){
46
        this.vocStyler = vocStyler;
47
    }
48

  
49
    @Override
50
    public void update(ViewerCell cell) {
51
        Object element = cell.getElement();
52

  
53
        String text = getText(element);
54
        cell.setText(text);
55

  
56
        Styler styler = null;
57
        if (element instanceof TermVocabulary && text != null) {
58
            styler = getVocabularyStyler();
59
        }
60

  
61
        if(styler!=null){
62
            StyledString styledString = new StyledString(text, styler);
63
            StyleRange[] styleRanges;
64
            styleRanges = styledString.getStyleRanges();
65
            cell.setStyleRanges(styleRanges);
66
        }
67
        super.update(cell);
68
    }
69

  
70
//    public StyledString getStyledText(Object element) {
71
//        if (element instanceof TermVocabulary) {
72
//            new StyledString(getText(element), getVocabularyStyler());
73
//        }
74
//        else if (element instanceof DefinedTermBase && ((DefinedTermBase) element).getKindOf()!=null) {
75
//            new StyledString(getText(element), getKindOfStyler());
76
//        }
77
//        return new StyledString(getText(element), StyledString.QUALIFIER_STYLER);
78
//    }
79

  
80
    public String getText(Object element) {
81
        String label = null;
82
    	if(element instanceof TermVocabulary){
83
    	    TermVocabulary termBase = (TermVocabulary)element;
84
    		Representation rep = termBase.getRepresentation(PreferencesUtil.getGlobalLanguage());
85
    		if (rep == null){
86
    			rep = termBase.getPreferredRepresentation(new ArrayList<Language>());
87
    		}
88
    		label = rep != null? rep.getLabel() : termBase.getTitleCache();
89
    		if (element instanceof DefinedTermBase && label!=null) {
90
    			DefinedTermBase<?> dtb = (DefinedTermBase<?>) element;
91
    			label = CdmUtils.concat(" : ", dtb.getIdInVocabulary(), label);
92
    		}
93
    	}
94
        // FIXME : must throw an exception here
95
    	if(label==null){
96
    	    label = element.toString();
97
    	}
98
        return label;
99
    }
100

  
101
    private Styler getVocabularyStyler() {
102
        if (vocStyler == null) {
103
            vocStyler = new Styler() {
104
                @Override
105
                public void applyStyles(TextStyle textStyle) {
106
                    textStyle.foreground = vocColor;
107
                }
108
            };
109
        }
110
        return vocStyler;
111
    }
112

  
113

  
114
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/e4/OpenDistributionEditorWizardHandlerE4.java
16 16
import org.eclipse.swt.widgets.Shell;
17 17

  
18 18
import eu.etaxonomy.taxeditor.preference.wizard.AvailableDistributionWizard;
19
import eu.etaxonomy.taxeditor.preference.wizard.AvailableVocabularyWizard;
19 20

  
20 21
/**
21 22
 *
......
29 30

  
30 31
        @Execute
31 32
        public void execute(@Named(IServiceConstants.ACTIVE_SHELL)Shell shell) {
33
            AvailableVocabularyWizard wizard = new AvailableVocabularyWizard();
32 34
            AvailableDistributionWizard availableDistributionWizard = new AvailableDistributionWizard();
33 35
            WizardDialog dialog = new WizardDialog(shell,
34
                    availableDistributionWizard);
36
                    wizard);
35 37

  
36 38
            dialog.open();
37 39
        }
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java
672 672
            reportSb.append(((ExportResult)remotingMonitor.getResult()).createReport());
673 673
        }else if (remotingMonitor.getResult() instanceof UpdateResult){
674 674
            if (((UpdateResult)remotingMonitor.getResult()).isOk()){
675
                reportSb.append("Update successfull. \n"+"Updated Objects: " + ((UpdateResult)remotingMonitor.getResult()).getUpdatedObjects().size());
675
                reportSb.append("Update successful. \n"+"Updated Objects: " + ((UpdateResult)remotingMonitor.getResult()).getUpdatedObjects().size());
676 676
            }
677 677
            if (!((UpdateResult)remotingMonitor.getResult()).getExceptions().isEmpty()){
678 678
                reportSb.append(((UpdateResult)remotingMonitor.getResult()).getExceptions().toString());
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AbstractAreaSelectionWizard.java
1
/**
2
* Copyright (C) 2018 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.preference.wizard;
10

  
11
import java.util.ArrayList;
12
import java.util.Arrays;
13
import java.util.List;
14
import java.util.UUID;
15

  
16
import org.eclipse.jface.viewers.CheckboxTableViewer;
17
import org.eclipse.jface.viewers.CheckboxTreeViewer;
18
import org.eclipse.jface.viewers.ColumnViewer;
19
import org.eclipse.jface.wizard.WizardPage;
20
import org.eclipse.swt.widgets.Composite;
21

  
22
import eu.etaxonomy.cdm.api.service.ITermService;
23
import eu.etaxonomy.cdm.api.service.IVocabularyService;
24
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
25
import eu.etaxonomy.cdm.model.common.TermType;
26
import eu.etaxonomy.cdm.model.common.TermVocabulary;
27
import eu.etaxonomy.taxeditor.store.CdmStore;
28

  
29
/**
30
 * @author k.luther
31
 * @since 04.06.2018
32
 *
33
 */
34
public abstract class AbstractAreaSelectionWizard extends WizardPage {
35

  
36
    private ColumnViewer viewer;
37
    private List<TermVocabulary<DefinedTermBase>> vocabularies = new ArrayList<>();
38

  
39
    /**
40
     * @param pageName
41
     */
42
    protected AbstractAreaSelectionWizard(String pageName) {
43
        super(pageName);
44
        // TODO check if configuration exists
45
        CdmStore.getCurrentSessionManager().bindNullSession();
46
    }
47

  
48
    /**
49
     * {@inheritDoc}
50
     */
51
    @Override
52
    public abstract void createControl(Composite parent) ;
53

  
54
    public ColumnViewer getViewer() {
55
        return viewer;
56
    }
57

  
58
    public void setViewer(ColumnViewer viewer) {
59
        this.viewer = viewer;
60
    }
61

  
62
    public List<TermVocabulary<DefinedTermBase>> getVocabularies() {
63
        return vocabularies;
64
    }
65

  
66
    public void addVocabularies(TermVocabulary<DefinedTermBase> vocabulary) {
67
        this.vocabularies.add(vocabulary);
68
    }
69

  
70
    protected void initialiseVocabularies() {
71
        if (getVocabularies() != null) {
72
            getVocabularies().clear();
73
        }
74
        List<TermVocabulary<DefinedTermBase>> vocs = CdmStore.getService(IVocabularyService.class).findByTermType(
75
                TermType.NamedArea, null);
76

  
77
        vocabularies = vocs;
78
    }
79

  
80
    /**
81
     * @param vocs
82
     */
83
    protected void setVocabularies(List<TermVocabulary> vocs) {
84
        for (TermVocabulary voc:vocs){
85
            vocabularies.add(voc);
86
        }
87

  
88

  
89
    }
90

  
91
    protected void rememberCheckedValues(String checkedValues, String grayedValues) {
92
        initialiseVocabularies();
93
        getViewer().setInput(getVocabularies());
94

  
95
        if (grayedValues != null && grayedValues != "") {
96
            String[] listGrayed = grayedValues.split(",");
97
            ArrayList listGrayedTerms = new ArrayList();
98
            getTermsFromStringValues(listGrayed, listGrayedTerms);
99
            for(Object element : listGrayedTerms){
100
                if(element != null){
101
                    if (getViewer() instanceof CheckboxTreeViewer) {
102
                        ((CheckboxTreeViewer)getViewer()).setGrayChecked(element, true);
103
                    }
104
                }
105
            }
106
        }
107
        if (checkedValues != null && checkedValues != "") {
108
            String[] listChecked = checkedValues.split(",");
109
            ArrayList<DefinedTermBase<?>> listCheckedTerms = new ArrayList<DefinedTermBase<?>>();
110
            getTermsFromStringValues(listChecked, listCheckedTerms);
111
            for(Object element : listCheckedTerms){
112
                if(element != null){
113
                    if (getViewer() instanceof CheckboxTreeViewer) {
114
                        ((CheckboxTreeViewer)getViewer()).setChecked(element, true);
115
                    }else if (getViewer() instanceof CheckboxTableViewer){
116
                        ((CheckboxTreeViewer)getViewer()).setChecked(element, true);
117
                    }
118
                }
119
            }
120
        }
121
    }
122

  
123
    /**
124
     * @param split
125
     * @param termlist
126
     */
127
    private void getTermsFromStringValues(String[] split, ArrayList termlist) {
128
        List<String> listValue = Arrays.asList(split);
129
        for (String s : listValue) {
130
            UUID uuid = UUID.fromString(s);
131
            ITermService termService = CdmStore.getService(ITermService.class);
132
            DefinedTermBase definedTermBase = termService.load(uuid);
133
            if(definedTermBase != null){
134
                termlist.add(definedTermBase);
135
            }else{
136
                IVocabularyService vocabularyService = CdmStore.getService(IVocabularyService.class);
137
                TermVocabulary termVocabulary = vocabularyService.load(uuid);
138
                termlist.add(termVocabulary);
139
            }
140
        }
141
    }
142

  
143
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableAreaVocabulariesPage.java
1
/**
2
* Copyright (C) 2018 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.preference.wizard;
10

  
11
import java.util.Collection;
12
import java.util.List;
13
import java.util.Map;
14

  
15
import org.eclipse.jface.preference.IPreferenceStore;
16
import org.eclipse.jface.viewers.CheckStateChangedEvent;
17
import org.eclipse.jface.viewers.CheckboxTableViewer;
18
import org.eclipse.jface.viewers.ICheckStateListener;
19
import org.eclipse.jface.viewers.StyledString.Styler;
20
import org.eclipse.jface.viewers.ViewerComparator;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.graphics.TextStyle;
23
import org.eclipse.swt.layout.GridData;
24
import org.eclipse.swt.layout.GridLayout;
25
import org.eclipse.swt.widgets.Composite;
26
import org.eclipse.swt.widgets.Display;
27

  
28
import eu.etaxonomy.cdm.model.common.CdmBase;
29
import eu.etaxonomy.taxeditor.editor.definedterm.VocabularyContentProvider;
30
import eu.etaxonomy.taxeditor.editor.definedterm.VocabularyLabelProvider;
31
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
32
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
33
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
34

  
35
/**
36
 * @author k.luther
37
 * @since 04.06.2018
38
 *
39
 */
40
public class AvailableAreaVocabulariesPage  extends AbstractAreaSelectionWizard implements ICdmEntitySessionEnabled{
41

  
42
    /**
43
     * @param pageName
44
     */
45
    public AvailableAreaVocabulariesPage(String pageName) {
46
        super(pageName);
47

  
48
    }
49

  
50
     /**
51
     * {@inheritDoc}
52
     */
53
    @Override
54
    public void createControl(Composite parent) {
55
        IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
56
       // String checkedValues = preferenceStore.getString(PreferencesUtil.DISTRIBUTION_AREA_OCCURENCE_STATUS);
57
       // String grayedValues = preferenceStore.getString(PreferencesUtil.DISTRIBUTION_AREA_OCCURENCE_STATUS_GRAYED);
58
        setTitle("Select vocabularies for Distribution Editor");
59
        setDescription("In order to be able to modify and see the distribution status of taxa,\n"
60
                + "you have to select the areas which you like to see.");
61
        Composite composite = new Composite(parent, SWT.NULL);
62
        composite.setLayout(new GridLayout());
63
        setViewer(CheckboxTableViewer.newCheckList(composite, SWT.NULL));
64
        ((CheckboxTableViewer)getViewer()).getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
65
//        viewer.setContentProvider(new TermContentProvider());
66
        Styler styler = new Styler() {
67
            @Override
68
            public void applyStyles(TextStyle textStyle) {
69
                textStyle.foreground = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
70
            }
71
        };
72
        getViewer().setContentProvider(new VocabularyContentProvider());
73
        getViewer().setLabelProvider(new VocabularyLabelProvider(styler));
74
        getViewer().setComparator(new ViewerComparator());
75
        ((CheckboxTableViewer)getViewer()).addCheckStateListener(new ICheckStateListener() {
76

  
77
            private boolean ignoreCheckEvent = false;
78

  
79
            @Override
80
            public void checkStateChanged(CheckStateChangedEvent event) {
81

  
82

  
83
                if (ignoreCheckEvent ) {
84
                    return;
85
                }
86

  
87
                ignoreCheckEvent = true;
88

  
89
                try {
90

  
91

  
92
                }
93
                finally {
94
                    ignoreCheckEvent = false;
95
                }
96

  
97
            }
98
        });
99
        rememberCheckedValues(null, null);
100
        setControl(composite);
101

  
102
    }
103

  
104
    /**
105
     * {@inheritDoc}
106
     */
107
    @Override
108
    public ICdmEntitySession getCdmEntitySession() {
109
        // TODO Auto-generated method stub
110
        return null;
111
    }
112

  
113
    /**
114
     * {@inheritDoc}
115
     */
116
    @Override
117
    public <T extends CdmBase> Collection<T> getRootEntities() {
118
        // TODO Auto-generated method stub
119
        return null;
120
    }
121

  
122
    /**
123
     * {@inheritDoc}
124
     */
125
    @Override
126
    public Map<Object, List<String>> getPropertyPathsMap() {
127
        // TODO Auto-generated method stub
128
        return null;
129
    }
130

  
131

  
132

  
133
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionPage.java
8 8
 */
9 9
package eu.etaxonomy.taxeditor.preference.wizard;
10 10

  
11
import java.util.ArrayList;
12 11
import java.util.Arrays;
13 12
import java.util.Collection;
14 13
import java.util.HashMap;
14
import java.util.HashSet;
15 15
import java.util.List;
16 16
import java.util.Map;
17 17
import java.util.Set;
......
24 24
import org.eclipse.jface.viewers.StyledString.Styler;
25 25
import org.eclipse.jface.viewers.TreePath;
26 26
import org.eclipse.jface.viewers.ViewerComparator;
27
import org.eclipse.jface.wizard.WizardPage;
28 27
import org.eclipse.swt.SWT;
29 28
import org.eclipse.swt.graphics.TextStyle;
30 29
import org.eclipse.swt.layout.GridData;
......
32 31
import org.eclipse.swt.widgets.Composite;
33 32
import org.eclipse.swt.widgets.Display;
34 33

  
35
import eu.etaxonomy.cdm.api.service.ITermService;
36 34
import eu.etaxonomy.cdm.api.service.IVocabularyService;
37 35
import eu.etaxonomy.cdm.model.common.CdmBase;
38
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
39
import eu.etaxonomy.cdm.model.common.TermType;
40 36
import eu.etaxonomy.cdm.model.common.TermVocabulary;
41 37
import eu.etaxonomy.taxeditor.editor.definedterm.TermContentProvider;
42 38
import eu.etaxonomy.taxeditor.editor.definedterm.TermLabelProvider;
......
50 46
 * @date 21.07.2014
51 47
 *
52 48
 */
53
public class AvailableDistributionPage extends WizardPage implements ICdmEntitySessionEnabled {
54

  
55
    private CheckboxTreeViewer viewer;
56

  
57
    private Set<TermVocabulary<DefinedTermBase>> vocabularies;
49
public class AvailableDistributionPage extends AbstractAreaSelectionWizard implements ICdmEntitySessionEnabled {
58 50

  
59 51
    /**
60 52
     * @param pageName
61 53
     */
62 54
    protected AvailableDistributionPage(String pageName) {
63 55
        super(pageName);
64
        // TODO check if configuration exists
65
        CdmStore.getCurrentSessionManager().bindNullSession();
56

  
66 57
    }
67 58

  
68 59
    /*
......
76 67
    @Override
77 68
    public void createControl(Composite parent) {
78 69
        IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
70

  
79 71
        String checkedValues = preferenceStore.getString(PreferencesUtil.DISTRIBUTION_AREA_OCCURENCE_STATUS);
80 72
        String grayedValues = preferenceStore.getString(PreferencesUtil.DISTRIBUTION_AREA_OCCURENCE_STATUS_GRAYED);
81 73
        setTitle("Select areas for Distribution Editor");
......
83 75
                + "you have to select the areas which you like to see.");
84 76
        Composite composite = new Composite(parent, SWT.NULL);
85 77
        composite.setLayout(new GridLayout());
86
        viewer = new CheckboxTreeViewer(composite, SWT.NULL);
87
        viewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
88
        viewer.setContentProvider(new TermContentProvider());
78
        setViewer(new CheckboxTreeViewer(composite, SWT.NULL));
79
        ((CheckboxTreeViewer)getViewer()).getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
80
        getViewer().setContentProvider(new TermContentProvider());
89 81
        Styler styler = new Styler() {
90 82
            @Override
91 83
            public void applyStyles(TextStyle textStyle) {
92 84
                textStyle.foreground = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
93 85
            }
94 86
        };
95
        viewer.setLabelProvider(new TermLabelProvider(styler));
96
        viewer.setComparator(new ViewerComparator());
97
        viewer.addCheckStateListener(new ICheckStateListener() {
87
        getViewer().setLabelProvider(new TermLabelProvider(styler));
88
        getViewer().setComparator(new ViewerComparator());
89
        ((CheckboxTreeViewer)getViewer()).addCheckStateListener(new ICheckStateListener() {
98 90

  
99 91
            private boolean ignoreCheckEvent = false;
100 92

  
......
127 119
    }
128 120

  
129 121

  
130
    protected List<TermVocabulary<DefinedTermBase>> initialiseVocabularies() {
131
        if (vocabularies != null) {
132
            vocabularies.clear();
133
        }
134
        List<TermVocabulary<DefinedTermBase>> vocs = CdmStore.getService(IVocabularyService.class).findByTermType(
135
                TermType.NamedArea, null);
136 122

  
137
        return vocs;
138
    }
139 123

  
140
    private void rememberCheckedValues(String checkedValues, String grayedValues) {
141
        viewer.setInput(initialiseVocabularies());
142 124

  
143
        if (grayedValues != null && grayedValues != "") {
144
            String[] listGrayed = grayedValues.split(",");
145
            ArrayList listGrayedTerms = new ArrayList();
146
            getTermsFromStringValues(listGrayed, listGrayedTerms);
147
            for(Object element : listGrayedTerms){
148
                if(element != null){
149
                    viewer.setGrayChecked(element, true);
150
                }
151
            }
152
        }
153
        if (checkedValues != null && checkedValues != "") {
154
            String[] listChecked = checkedValues.split(",");
155
            ArrayList<DefinedTermBase<?>> listCheckedTerms = new ArrayList<DefinedTermBase<?>>();
156
            getTermsFromStringValues(listChecked, listCheckedTerms);
157
            for(Object element : listCheckedTerms){
158
                if(element != null){
159
                    viewer.setChecked(element, true);
160
                }
161
            }
162
        }
163
    }
164

  
165
    /**
166
     * @param split
167
     * @param termlist
168
     */
169
    private void getTermsFromStringValues(String[] split, ArrayList termlist) {
170
        List<String> listValue = Arrays.asList(split);
171
        for (String s : listValue) {
172
            UUID uuid = UUID.fromString(s);
173
            ITermService termService = CdmStore.getService(ITermService.class);
174
            DefinedTermBase definedTermBase = termService.load(uuid);
175
            if(definedTermBase != null){
176
                termlist.add(definedTermBase);
177
            }else{
178
                IVocabularyService vocabularyService = CdmStore.getService(IVocabularyService.class);
179
                TermVocabulary termVocabulary = vocabularyService.load(uuid);
180
                termlist.add(termVocabulary);
181
            }
182
        }
183
    }
184 125

  
185 126
    private boolean checkNoneChecked() {
186 127

  
187
        if (viewer.getCheckedElements().length == 0) {
128
        if (((CheckboxTreeViewer)getViewer()).getCheckedElements().length == 0) {
188 129
            setMessage("Please check at least one item", WARNING);
189 130
            return true;
190 131
        } else {
......
193 134
        }
194 135
    }
195 136

  
196
    /**
197
     * @return the viewer
198
     */
199
    public CheckboxTreeViewer getViewer() {
200
        return viewer;
201
    }
202 137

  
203 138
    /**
204 139
     *
......
215 150
            boolean allChecked = true;
216 151
            boolean allUnchecked = true;
217 152
            for (final Object fieldElement : tcp.getChildren(treeElement)) {
218
                allChecked = allChecked && this.viewer.getChecked(fieldElement);
219
                allUnchecked = allUnchecked && !this.viewer.getChecked(fieldElement);
153
                allChecked = allChecked && ((CheckboxTreeViewer)getViewer()).getChecked(fieldElement);
154
                allUnchecked = allUnchecked && !((CheckboxTreeViewer)getViewer()).getChecked(fieldElement);
220 155
            }
221 156
            if (allUnchecked) {
222
                this.viewer.setChecked(treeElement, false);
223
                this.viewer.setGrayed(treeElement, false);
157
                ((CheckboxTreeViewer)getViewer()).setChecked(treeElement, false);
158
                ((CheckboxTreeViewer)getViewer()).setGrayed(treeElement, false);
224 159
            } else if (allChecked) {
225
                this.viewer.setChecked(treeElement, true);
226
                this.viewer.setGrayed(treeElement, false);
160
                ((CheckboxTreeViewer)getViewer()).setChecked(treeElement, true);
161
                ((CheckboxTreeViewer)getViewer()).setGrayed(treeElement, false);
227 162
            } else if (!allUnchecked && !allChecked) {
228
                this.viewer.setChecked(treeElement, true);
229
                this.viewer.setGrayed(treeElement, true);
163
                ((CheckboxTreeViewer)getViewer()).setChecked(treeElement, true);
164
                ((CheckboxTreeViewer)getViewer()).setGrayed(treeElement, true);
230 165
            }
231 166
        }
232 167
        checkParents(path.getParentPath());
......
268 203
       }
269 204
    //   final Object element = path.getLastSegment();
270 205
       if (element != null) {
271
           this.viewer.setChecked(element, checked);
272
           this.viewer.setGrayed(element, false);
206
           ((CheckboxTreeViewer)getViewer()).setChecked(element, checked);
207
           ((CheckboxTreeViewer)getViewer()).setGrayed(element, false);
273 208
           int length = tcp.getChildren(element).length;
274 209
           if(length>1){
275
               this.viewer.expandToLevel(element, CheckboxTreeViewer.ALL_LEVELS);
276
               this.viewer.setSubtreeChecked(element, checked);
210
               ((CheckboxTreeViewer)getViewer()).expandToLevel(element, CheckboxTreeViewer.ALL_LEVELS);
211
               ((CheckboxTreeViewer)getViewer()).setSubtreeChecked(element, checked);
277 212
           }
278 213
       }
279 214
   }
......
294 229
          boolean allChecked = true;
295 230
          boolean allUnchecked = true;
296 231
          for (final Object fieldElement : tcp.getChildren(parent)) {
297
              allChecked = allChecked && this.viewer.getChecked(fieldElement);
298
              allUnchecked = allUnchecked && !this.viewer.getChecked(fieldElement);
232
              allChecked = allChecked && ((CheckboxTreeViewer)getViewer()).getChecked(fieldElement);
233
              allUnchecked = allUnchecked && !((CheckboxTreeViewer)getViewer()).getChecked(fieldElement);
299 234
          }
300 235
          if (allUnchecked) {
301
              this.viewer.setChecked(parent, false);
302
              this.viewer.setGrayed(parent, false);
236
              ((CheckboxTreeViewer)getViewer()).setChecked(parent, false);
237
              ((CheckboxTreeViewer)getViewer()).setGrayed(parent, false);
303 238
          } else if (allChecked) {
304
              this.viewer.setChecked(parent, true);
305
              this.viewer.setGrayed(parent, false);
239
              ((CheckboxTreeViewer)getViewer()).setChecked(parent, true);
240
              ((CheckboxTreeViewer)getViewer()).setGrayed(parent, false);
306 241
          } else if (!allUnchecked && !allChecked) {
307
              this.viewer.setChecked(parent, true);
308
              this.viewer.setGrayed(parent, true);
242
              ((CheckboxTreeViewer)getViewer()).setChecked(parent, true);
243
              ((CheckboxTreeViewer)getViewer()).setGrayed(parent, true);
309 244
          }
310 245

  
311 246
        grayParents(tcp.getParent(parent));
......
346 281
        propertyPathsMap.put("terms", termsPropertyPaths);
347 282
        return propertyPathsMap;
348 283
    }
284
    @Override
285
    protected void initialiseVocabularies() {
286
        if (getVocabularies() != null) {
287
            getVocabularies().clear();
288
        }
289
        String vocString = PreferencesUtil.getPreferenceStore().getString(PreferencesUtil.DISTRIBUTION_VOCABULARIES);
290
        String[] arrayVocs = vocString.split(",");
291

  
292
        Set<UUID> uuidVocs = new HashSet();
293
        for (String voc: arrayVocs){
294
            uuidVocs.add(UUID.fromString(voc));
295
        }
296

  
297
        List<TermVocabulary> vocs = CdmStore.getService(IVocabularyService.class).find(uuidVocs);
298

  
299
        setVocabularies(vocs);
300
    }
301

  
302

  
349 303

  
350 304
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionWizard.java
15 15
import org.apache.commons.collections.CollectionUtils;
16 16
import org.apache.commons.lang.StringUtils;
17 17
import org.eclipse.jface.preference.IPreferenceStore;
18
import org.eclipse.jface.viewers.CheckboxTreeViewer;
18 19
import org.eclipse.jface.wizard.Wizard;
19 20

  
20 21
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
......
51 52
    public boolean performFinish() {
52 53
        // TODO: get Selection and save in EditorPreferences
53 54
        if (!checkNoneChecked()) {
54
            Object[] checkedElements = aPage.getViewer().getCheckedElements();
55
            Object[] grayedElements = aPage.getViewer().getGrayedElements();
55
            Object[] checkedElements = ((CheckboxTreeViewer)aPage.getViewer()).getCheckedElements();
56
            Object[] grayedElements = ((CheckboxTreeViewer)aPage.getViewer()).getGrayedElements();
56 57
            ArrayList checkedList = new ArrayList(Arrays.asList(checkedElements));
57 58
            ArrayList grayedList = new ArrayList(Arrays.asList(grayedElements));
58 59
            checkedList = (ArrayList) CollectionUtils.subtract(checkedList, grayedList);
......
99 100

  
100 101
    private boolean checkNoneChecked() {
101 102

  
102
        if (aPage.getViewer().getCheckedElements().length == 0) {
103
        if (((CheckboxTreeViewer)aPage.getViewer()).getCheckedElements().length == 0) {
103 104
            aPage.setMessage("Please check at least one item", aPage.WARNING);
104 105
            return true;
105 106
        } else {
......
115 116
        }
116 117
        return conversation;
117 118
    }
119
    
120
    
118 121

  
119 122
    /*
120 123
     * (non-Javadoc)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableVocabularyWizard.java
1
/**
2
* Copyright (C) 2018 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.preference.wizard;
10

  
11
import java.util.ArrayList;
12
import java.util.UUID;
13

  
14
import org.apache.commons.lang.StringUtils;
15
import org.eclipse.jface.preference.IPreferenceStore;
16
import org.eclipse.jface.viewers.CheckboxTableViewer;
17
import org.eclipse.jface.wizard.IWizardPage;
18
import org.eclipse.jface.wizard.Wizard;
19

  
20
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
21
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
22
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
23
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
24
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
25
import eu.etaxonomy.taxeditor.store.CdmStore;
26

  
27
/**
28
 * @author k.luther
29
 * @since 04.06.2018
30
 *
31
 */
32
public class AvailableVocabularyWizard extends Wizard implements IConversationEnabled {
33

  
34
    private ConversationHolder conversation;
35
    private final AvailableAreaVocabulariesPage aPage;
36

  
37
    public AvailableVocabularyWizard() {
38
        setWindowTitle("Vocabulary Selection Wizard");
39
        // TODO if preferenceStore has elements checked load elements in wizard
40
        aPage = new AvailableAreaVocabulariesPage("AvailableDistributionPage");
41
    }
42

  
43
    @Override
44
    public void addPages() {
45
        addPage(aPage);
46
    }
47

  
48

  
49

  
50

  
51
    /**
52
     * {@inheritDoc}
53
     */
54
    @Override
55
    public IWizardPage getPage(String pageName) {
56

  
57
        return aPage;
58
    }
59

  
60
    /**
61
     * {@inheritDoc}
62
     */
63
    @Override
64
    public int getPageCount() {
65
       return 1;
66
    }
67

  
68
    /**
69
     * {@inheritDoc}
70
     */
71
    @Override
72
    public IWizardPage[] getPages() {
73
        IWizardPage[] pages = new IWizardPage[1];
74
        pages [0] = aPage;
75
        return pages;
76
    }
77

  
78

  
79

  
80

  
81

  
82
    /**
83
     * {@inheritDoc}
84
     */
85
    @Override
86
    public String getWindowTitle() {
87

  
88
        return "Vocabulary Selection Wizard";
89
    }
90

  
91

  
92

  
93

  
94

  
95

  
96

  
97
    /**
98
     * {@inheritDoc}
99
     */
100
    @Override
101
    public boolean performCancel() {
102
        // TODO Auto-generated method stub
103
        return true;
104
    }
105

  
106
    /**
107
     * {@inheritDoc}
108
     */
109
    @Override
110
    public boolean performFinish() {
111
        Object[] checkedElements = ((CheckboxTableViewer)aPage.getViewer()).getCheckedElements();
112

  
113
        ArrayList<UUID> listUIIDChecked = new ArrayList<UUID>();
114
        for (Object o : checkedElements) {
115
               if(o instanceof OrderedTermVocabulary){
116
                    OrderedTermVocabulary otb = (OrderedTermVocabulary) o;
117
                    listUIIDChecked.add(otb.getUuid());
118
                }
119
            }
120
           String saveCheckedElements = StringUtils.join(listUIIDChecked, ",");
121
           IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
122
           PreferencesUtil.setPreferredVocabulariesForDistributionEditor(saveCheckedElements, false);
123
           preferenceStore.setValue(PreferencesUtil.DISTRIBUTION_VOCABULARIES, saveCheckedElements);
124
           return true;
125
    }
126

  
127

  
128

  
129

  
130
    /**
131
     * {@inheritDoc}
132
     */
133
    @Override
134
    public void update(CdmDataChangeMap changeEvents) {
135
        // TODO Auto-generated method stub
136

  
137
    }
138

  
139

  
140
    /**
141
     * {@inheritDoc}
142
     */
143
    @Override
144
    public ConversationHolder getConversationHolder() {
145
        if (conversation == null) {
146
            conversation = CdmStore.createConversation();
147
        }
148
        return conversation;
149
    }
150

  
151
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)