Project

General

Profile

« Previous | Next » 

Revision 6803fca4

Added by Patrick Plitzner about 2 years ago

fix #8755 Show all structure/property trees in CharacterEditor

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/character/CharacterEditor.java
36 36
import org.eclipse.jface.viewers.SelectionChangedEvent;
37 37
import org.eclipse.jface.viewers.StructuredSelection;
38 38
import org.eclipse.jface.viewers.TreeSelection;
39
import org.eclipse.jface.viewers.TreeViewer;
39 40
import org.eclipse.swt.SWT;
40 41
import org.eclipse.swt.custom.SashForm;
42
import org.eclipse.swt.dnd.DND;
41 43
import org.eclipse.swt.dnd.Transfer;
42 44
import org.eclipse.swt.events.ModifyEvent;
43 45
import org.eclipse.swt.events.ModifyListener;
......
59 61
import eu.etaxonomy.cdm.api.service.IVocabularyService;
60 62
import eu.etaxonomy.cdm.model.description.Character;
61 63
import eu.etaxonomy.cdm.model.description.Feature;
64
import eu.etaxonomy.cdm.model.term.DefinedTerm;
62 65
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
63
import eu.etaxonomy.cdm.model.term.Representation;
64 66
import eu.etaxonomy.cdm.model.term.TermNode;
65 67
import eu.etaxonomy.cdm.model.term.TermTree;
66 68
import eu.etaxonomy.cdm.model.term.TermType;
......
68 70
import eu.etaxonomy.cdm.model.term.VocabularyEnum;
69 71
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
70 72
import eu.etaxonomy.taxeditor.editor.AppModelId;
73
import eu.etaxonomy.taxeditor.editor.definedterm.FeatureTreeViewerComparator;
71 74
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
72 75
import eu.etaxonomy.taxeditor.featuretree.CharacterTransfer;
73 76
import eu.etaxonomy.taxeditor.featuretree.FeatureNodeTransfer;
77
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeContentProvider;
78
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeLabelProvider;
79
import eu.etaxonomy.taxeditor.featuretree.e4.AbstractTermTreeEditor;
74 80
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureNodeDragListener;
75 81
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeDropAdapter;
76 82
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditorComposite;
......
80 86
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
81 87
import eu.etaxonomy.taxeditor.model.ImageResources;
82 88
import eu.etaxonomy.taxeditor.model.MessagingUtils;
83
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
84 89
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
85 90
import eu.etaxonomy.taxeditor.store.CdmStore;
86 91
import eu.etaxonomy.taxeditor.ui.dialog.selection.FeatureTreeSelectionDialog;
......
97 102
        ModifyListener, IE4ViewerPart, IPartContentHasDetails, IPartContentHasSupplementalData, IDirtyMarkable {
98 103

  
99 104
    private FeatureTreeEditorComposite<Character> characterTreeEditorComposite;
100
    private FeatureTreeEditorComposite<DefinedTermBase> propertiesTreeEditorComposite;
101
    private FeatureTreeEditorComposite<DefinedTermBase> structuresTreeEditorComposite;
102 105
    private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
103 106

  
104 107
    @Inject
......
113 116
    private ConversationHolder conversation;
114 117

  
115 118
    private ICdmEntitySession cdmEntitySession;
116
    private Composite composite;
117 119

  
118 120
    private TermVocabulary vocabulary;
119 121

  
......
170 172
        formToolkit.adapt(sashForm);
171 173
        formToolkit.paintBordersFor(sashForm);
172 174

  
173
        composite = new Composite(sashForm, SWT.NONE);
175
        Composite composite = new Composite(sashForm, SWT.NONE);
174 176
        formToolkit.adapt(composite);
175 177
        formToolkit.paintBordersFor(composite);
176 178
        GridLayout gl_composite = new GridLayout(1, false);
177 179
        gl_composite.marginWidth = 0;
178 180
        composite.setLayout(gl_composite);
179 181

  
180
        structuresTreeEditorComposite = addFeatureTreeEditor(composite);
181

  
182
        initFeatureTreeComposite(TermType.Structure, structuresTreeEditorComposite,
183
                new FeatureNodeDragListener(structuresTreeEditorComposite.getViewer()), null, null, null, null);
184

  
185
        structuresTreeEditorComposite.getLabel_title().setText(Messages.CharacterEditor_STRUCTURES);
182
        TreeViewer structureViewer = createTreeViewer(composite, TermType.Structure);
186 183

  
187 184
        Composite composite_1 = new Composite(sashForm, SWT.NONE);
188 185
        formToolkit.adapt(composite_1);
......
191 188
        gl_composite_1.marginWidth = 0;
192 189
        composite_1.setLayout(gl_composite_1);
193 190

  
194
        propertiesTreeEditorComposite = addFeatureTreeEditor(composite_1);
195
        initFeatureTreeComposite(TermType.Property, propertiesTreeEditorComposite,
196
                new CharacterDragListener(structuresTreeEditorComposite.getViewer(), propertiesTreeEditorComposite.getViewer()),
197
                null,
198
                new Transfer[] {CharacterTransfer.getInstance()},
199
                null,
200
                null
191
        TreeViewer propertyViewer = createTreeViewer(composite_1, TermType.Property);
201 192

  
202
        );
203
        propertiesTreeEditorComposite.getLabel_title().setText(Messages.CharacterEditor_PROPERTIES);
193
        int ops = DND.DROP_COPY | DND.DROP_MOVE;
194
        Transfer[] transfers = new Transfer[] {CharacterTransfer.getInstance()};
195
        propertyViewer.addDragSupport(ops, transfers, new CharacterDragListener(structureViewer, propertyViewer));
204 196

  
205 197
        Composite composite_3 = new Composite(sashForm, SWT.NONE);
206 198
        formToolkit.adapt(composite_3);
......
218 210
                if(!isVocabularySet()){
219 211
                    return;
220 212
                }
221
                ISelection structureTreeSelection = structuresTreeEditorComposite.getViewer().getSelection();
222
                ISelection propertyTreeSelection = propertiesTreeEditorComposite.getViewer().getSelection();
213
                ISelection structureTreeSelection = structureViewer.getSelection();
214
                ISelection propertyTreeSelection = propertyViewer.getSelection();
223 215
                if(structureTreeSelection==null || propertyTreeSelection==null || characterTreeEditorComposite.getFeatureTree()==null){
224 216
                    MessagingUtils.warningDialog(Messages.CharacterEditor_CANNOT_PERFORM_TITLE, CharacterEditor.this,
225 217
                            Messages.CharacterEditor_CANNOT_PERFORM_MESSAGE);
......
251 243

  
252 244
    }
253 245

  
246
    private TreeViewer createTreeViewer(Composite parent, TermType termType) {
247
        Composite composite = new Composite(parent, SWT.NONE);
248
        composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
249
        composite.setLayout(new GridLayout(1, false));
250
        Label label = new Label(composite, SWT.NONE);
251
        label.setText(termType.getMessage());
252
        TreeViewer viewer = new TreeViewer(composite);
253
        viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
254
        viewer.setContentProvider(new FeatureTreeContentProvider());
255
        viewer.setLabelProvider(new FeatureTreeLabelProvider());
256
        viewer.setComparator(new FeatureTreeViewerComparator());
257
        viewer.addSelectionChangedListener(this);
258
        viewer.setInput(CdmStore.getService(ITermTreeService.class).list(termType, null, null, null, AbstractTermTreeEditor.TREE_PROPERTY_PATH));
259
        return viewer;
260
    }
261

  
254 262
    private <T extends DefinedTermBase> FeatureTreeEditorComposite<T> addFeatureTreeEditor(Composite composite_3) {
255 263
        FeatureTreeEditorComposite<T> featureTreeEditorComposite = new FeatureTreeEditorComposite<>(composite_3, SWT.NONE);
256 264
        featureTreeEditorComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
......
291 299
    public static Collection<Character> createCharacters(TreeSelection structureTreeSelection, TreeSelection propertyTreeSelection){
292 300
        Set<Character> characters = new HashSet<>();
293 301
        //get selected structures and properties
294
        Iterator<TermNode<DefinedTermBase>> structureIterator = structureTreeSelection.iterator();
302
        Iterator<TermNode<DefinedTerm>> structureIterator = structureTreeSelection.iterator();
295 303

  
296 304
        //create all combinations of structures and properties
297 305
        while(structureIterator.hasNext()){
298
            TermNode<DefinedTermBase> structureNode = structureIterator.next();
299
            Iterator<TermNode<DefinedTermBase>> propertiesIterator = propertyTreeSelection.iterator();
306
            TermNode<DefinedTerm> structureNode = structureIterator.next();
307
            Iterator<TermNode<DefinedTerm>> propertiesIterator = propertyTreeSelection.iterator();
300 308
            while(propertiesIterator.hasNext()){
301
                TermNode<DefinedTermBase> propertyNode = propertiesIterator.next();
302
                Representation structureRepresentation = structureNode.getTerm().getRepresentation(PreferencesUtil.getGlobalLanguage());
303
                Representation propertyRepresentation = propertyNode.getTerm().getRepresentation(PreferencesUtil.getGlobalLanguage());
304
                String label = null;
305
                String abbrevLabel = null;
306
                if(structureRepresentation.getLabel()!=null && propertyRepresentation.getLabel()!=null){
307
                    label = structureRepresentation.getLabel()+" "+propertyRepresentation.getLabel();
308
                }
309
                if(structureRepresentation.getAbbreviatedLabel()!=null && propertyRepresentation.getAbbreviatedLabel()!=null){
310
                    abbrevLabel = structureRepresentation.getAbbreviatedLabel()+" "+propertyRepresentation.getAbbreviatedLabel();
311
                }
312
                //create new Character
313
                Character character = Character.NewInstance(structureNode, propertyNode, null, label, abbrevLabel);
309
                TermNode<DefinedTerm> propertyNode = propertiesIterator.next();
310
                Character character = CharacterTransfer.createCharacter(structureNode, propertyNode);
314 311
                characters.add(character);
315 312
            }
316 313
        }
......
439 436

  
440 437
    @Override
441 438
    public void refresh(){
442
        structuresTreeEditorComposite.getViewer().refresh();
443
        propertiesTreeEditorComposite.getViewer().refresh();
444 439
        characterTreeEditorComposite.getViewer().setInput(characterTreeEditorComposite.getViewer().getInput());
445 440
    }
446 441

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/CharacterTransfer.java
23 23
import org.eclipse.swt.dnd.TransferData;
24 24

  
25 25
import eu.etaxonomy.cdm.api.service.IFeatureNodeService;
26
import eu.etaxonomy.cdm.model.common.Language;
26 27
import eu.etaxonomy.cdm.model.description.Character;
27 28
import eu.etaxonomy.cdm.model.term.DefinedTerm;
28 29
import eu.etaxonomy.cdm.model.term.Representation;
......
103 104
                        IFeatureNodeService featureNodeService = CdmStore.getService(IFeatureNodeService.class);
104 105
                        TermNode<DefinedTerm> structure = featureNodeService.load(UUID.fromString(split[0]));
105 106
                        TermNode<DefinedTerm> property = featureNodeService.load(UUID.fromString(split[1]));
106
                        Representation structureRepresentation = structure.getTerm().getRepresentation(PreferencesUtil.getGlobalLanguage());
107
                        Representation propertyRepresentation = property.getTerm().getRepresentation(PreferencesUtil.getGlobalLanguage());
108
                        String label = null;
109
                        String abbrevLabel = null;
110
                        if(structureRepresentation.getLabel()!=null && propertyRepresentation.getLabel()!=null){
111
                            label = structureRepresentation.getLabel()+" "+propertyRepresentation.getLabel();
112
                        }
113
                        if(structureRepresentation.getAbbreviatedLabel()!=null && propertyRepresentation.getAbbreviatedLabel()!=null){
114
                            abbrevLabel = structureRepresentation.getAbbreviatedLabel()+" "+propertyRepresentation.getAbbreviatedLabel();
115
                        }
116
                        characters.add(Character.NewInstance(structure, property, null, label, abbrevLabel));
107
                        characters.add(createCharacter(structure, property));
117 108
                    }
118 109
                }catch(EOFException e){
119 110
                    return characters.toArray();
......
125 116
        return null;
126 117
    }
127 118

  
119
    public static Character createCharacter(TermNode<DefinedTerm> structureNode,
120
            TermNode<DefinedTerm> propertyNode) {
121
        Representation structureRepresentation = structureNode.getTerm().getRepresentation(PreferencesUtil.getGlobalLanguage());
122
        if(structureRepresentation==null){
123
            structureRepresentation = structureNode.getTerm().getRepresentation(Language.DEFAULT());
124
        }
125
        Representation propertyRepresentation = propertyNode.getTerm().getRepresentation(PreferencesUtil.getGlobalLanguage());
126
        if(propertyRepresentation==null){
127
            propertyRepresentation = propertyNode.getTerm().getRepresentation(Language.DEFAULT());
128
        }
129
        String label = null;
130
        String abbrevLabel = null;
131
        if(structureRepresentation!=null && propertyRepresentation!=null){
132
            if(structureRepresentation.getLabel()!=null && propertyRepresentation.getLabel()!=null){
133
                label = structureRepresentation.getLabel()+" "+propertyRepresentation.getLabel();
134
            }
135
            if(structureRepresentation.getAbbreviatedLabel()!=null && propertyRepresentation.getAbbreviatedLabel()!=null){
136
                abbrevLabel = structureRepresentation.getAbbreviatedLabel()+" "+propertyRepresentation.getAbbreviatedLabel();
137
            }
138
        }
139
        if(label!=null){
140
            //default label
141
            label = structureNode.getTerm().getLabel()+" "+propertyNode.getTerm().getLabel();
142
        }
143
        //create new Character
144
        Character character = Character.NewInstance(structureNode, propertyNode, null, label, abbrevLabel);
145
        return character;
146
    }
147

  
128 148
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/AbstractTermTreeEditor.java
79 79
        IE4ViewerPart, IPartContentHasDetails, IPartContentHasSupplementalData,
80 80
        IContextListener, IConversationEnabled, IDirtyMarkable {
81 81

  
82
    protected static final List<String> TREE_PROPERTY_PATH = Arrays.asList(new String[] {
82
    public static final List<String> TREE_PROPERTY_PATH = Arrays.asList(new String[] {
83 83
            "root", //$NON-NLS-1$
84 84
            "root.children", //$NON-NLS-1$
85 85
            "root.children.inapplicableIf", //$NON-NLS-1$

Also available in: Unified diff