Project

General

Profile

Revision 6df52dba

ID6df52dba735b4b44f8f78335644dfc8480292b8c
Parent 68e4a9c8
Child b57b8fd1

Added by Patrick Plitzner almost 2 years ago

fix #7998 Store newly created Characters in selected vocabulary

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/character/CharacterDropAdapter.java
19 19
import eu.etaxonomy.cdm.model.description.FeatureTree;
20 20
import eu.etaxonomy.taxeditor.featuretree.CharacterTransfer;
21 21
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeDropAdapter;
22
import eu.etaxonomy.taxeditor.featuretree.e4.IFeatureTreeEditor;
23 22
import eu.etaxonomy.taxeditor.store.CdmStore;
24 23
import eu.etaxonomy.taxeditor.store.StoreUtil;
25 24

  
......
31 30
 */
32 31
public class CharacterDropAdapter extends FeatureTreeDropAdapter {
33 32

  
34
	protected CharacterDropAdapter(IFeatureTreeEditor editor, Viewer viewer, UISynchronize sync) {
35
	    super(editor, viewer, sync);
33
	private CharacterEditor characterEditor;
34

  
35
    protected CharacterDropAdapter(CharacterEditor characterEditor, Viewer viewer, UISynchronize sync) {
36
	    super(characterEditor, viewer, sync);
37
	    this.characterEditor = characterEditor;
36 38
	}
37 39

  
38 40
	@Override
......
48 50
	    if(StoreUtil.promptCheckIsDirty(editor)){
49 51
	        return false;
50 52
	    }
53
	    if(!characterEditor.isVocabularySet()){
54
	        return false;
55
	    }
51 56
	    FeatureNode target = (FeatureNode) getCurrentTarget();
52 57
	    if(data instanceof Object[]){
53 58
	        Object[] transferObjects = (Object[])data;
......
59 64
                        //drop on feature tree
60 65
                        target = ((FeatureTree)getViewer().getInput()).getRoot();
61 66
                    }
67
	                characterEditor.getVocabulary().addTerm(character);
62 68
                    CdmStore.getService(IFeatureNodeService.class).createChildFeatureNode(target, character);
63 69
	            }
64 70
	        }
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/character/CharacterEditor.java
48 48
import org.eclipse.swt.widgets.Button;
49 49
import org.eclipse.swt.widgets.Composite;
50 50
import org.eclipse.swt.widgets.Display;
51
import org.eclipse.swt.widgets.Label;
51 52
import org.eclipse.swt.widgets.Text;
52 53
import org.eclipse.ui.forms.widgets.FormToolkit;
53 54

  
......
57 58
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
58 59
import eu.etaxonomy.cdm.api.service.ITermService;
59 60
import eu.etaxonomy.cdm.model.common.Representation;
61
import eu.etaxonomy.cdm.model.common.TermVocabulary;
60 62
import eu.etaxonomy.cdm.model.description.Character;
61 63
import eu.etaxonomy.cdm.model.description.FeatureNode;
62 64
import eu.etaxonomy.cdm.model.description.FeatureTree;
......
72 74
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
73 75
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
74 76
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
77
import eu.etaxonomy.taxeditor.model.ImageResources;
75 78
import eu.etaxonomy.taxeditor.model.MessagingUtils;
76 79
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
77 80
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
78 81
import eu.etaxonomy.taxeditor.store.CdmStore;
79 82
import eu.etaxonomy.taxeditor.ui.dialog.selection.FeatureTreeSelectionDialog;
83
import eu.etaxonomy.taxeditor.ui.dialog.selection.TermVocabularySelectionDialog;
80 84
import eu.etaxonomy.taxeditor.workbench.part.IE4ViewerPart;
81 85

  
82 86
/**
......
92 96
    private FeatureTreeEditorComposite propertiesTreeEditorComposite;
93 97
    private FeatureTreeEditorComposite structuresTreeEditorComposite;
94 98
    private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
95
    private Button btnAddCharacter;
96 99

  
97 100
    @Inject
98 101
    private ESelectionService selService;
......
108 111
    private ICdmEntitySession cdmEntitySession;
109 112
    private Composite composite;
110 113

  
114
    private TermVocabulary vocabulary;
115

  
111 116
    public CharacterEditor() {
112 117
    }
113 118

  
......
129 134
        }
130 135
        parent.setLayout(new GridLayout(1, false));
131 136

  
137
        Composite vocChooserComposite = new Composite(parent, SWT.NONE);
138
        vocChooserComposite.setLayout(new GridLayout(3, false));
139
        vocChooserComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false, 2, 1));
140
        Label lblVocImport = new Label(vocChooserComposite, SWT.NONE);
141
        lblVocImport.setText("Character vocabulary");
142
        Text txtVocabulary = new Text(vocChooserComposite, SWT.NONE);
143
        Button btnChooseVoc = new Button(vocChooserComposite, SWT.PUSH);
144
        btnChooseVoc.setImage(ImageResources.getImage(ImageResources.BROWSE_ICON));
145
        btnChooseVoc.addSelectionListener(new SelectionAdapter() {
146

  
147
            @Override
148
            public void widgetSelected(SelectionEvent e) {
149
                vocabulary = TermVocabularySelectionDialog.select("Select vocabulary for characters", btnChooseVoc.getShell(), null);
150
                txtVocabulary.setText(vocabulary.getLabel());
151
            }
152
        });
153

  
132 154
        SashForm sashForm = new SashForm(parent, SWT.NONE);
133 155
        sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
134 156
        formToolkit.adapt(sashForm);
......
174 196
        gl_composite_3.marginWidth = 0;
175 197
        composite_3.setLayout(gl_composite_3);
176 198

  
177
        btnAddCharacter = new Button(composite_3, SWT.NONE);
199
        Button btnAddCharacter = new Button(composite_3, SWT.NONE);
178 200
        btnAddCharacter.setText(">>"); //$NON-NLS-1$
179 201
        formToolkit.adapt(btnAddCharacter, true, true);
202
        btnAddCharacter.addSelectionListener(new SelectionAdapter() {
203
            @Override
204
            public void widgetSelected(SelectionEvent e) {
205
                if(!isVocabularySet()){
206
                    return;
207
                }
208
                ISelection structureTreeSelection = structuresTreeEditorComposite.getViewer().getSelection();
209
                ISelection propertyTreeSelection = propertiesTreeEditorComposite.getViewer().getSelection();
210
                if(structureTreeSelection==null || propertyTreeSelection==null || characterTreeEditorComposite.getFeatureTree()==null){
211
                    MessagingUtils.warningDialog(Messages.CharacterEditor_CANNOT_PERFORM_TITLE, CharacterEditor.this,
212
                            Messages.CharacterEditor_CANNOT_PERFORM_MESSAGE);
213
                    return;
214
                }
215
                Collection<Character> characters = createCharacters((TreeSelection)structureTreeSelection, (TreeSelection)propertyTreeSelection);
216
                for (Character character : characters) {
217
                    //add new Character to feature tree
218
                    FeatureNode parent = ((FeatureTree) characterTreeEditorComposite.getViewer().getInput()).getRoot();
219
                    vocabulary.addTerm(character);
220
                    CdmStore.getService(IFeatureNodeService.class).createChildFeatureNode(parent, character);
221
                }
222
                characterTreeEditorComposite.getViewer().refresh();
223
            }
224
        });
180 225

  
181 226
        characterTreeEditorComposite = addFeatureTreeEditor(composite_3);
182 227
        initFeatureTreeComposite(characterTreeEditorComposite, new FeatureNodeDragListener(characterTreeEditorComposite.getViewer()),
......
188 233

  
189 234
        characterTreeEditorComposite.getLabel_title().setText(Messages.CharacterEditor_CHARACTERS);
190 235

  
191
        //add context menu to character viewer//create context menu
236
        //add context menu to character viewer
192 237
        menuService.registerContextMenu(characterTreeEditorComposite.getViewer().getControl(),
193 238
                AppModelId.POPUPMENU_EU_ETAXONOMY_TAXEDITOR_EDITOR_POPUPMENU_CHARACTEREDITOR);
194 239

  
195
        init();
196 240
    }
197 241

  
198 242
    private FeatureTreeEditorComposite addFeatureTreeEditor(Composite composite_3) {
......
231 275
        }
232 276
    }
233 277

  
234
    private void init(){
235
        btnAddCharacter.addSelectionListener(new SelectionAdapter() {
236
            @Override
237
            public void widgetSelected(SelectionEvent e) {
238
                ISelection structureTreeSelection = structuresTreeEditorComposite.getViewer().getSelection();
239
                ISelection propertyTreeSelection = propertiesTreeEditorComposite.getViewer().getSelection();
240
                if(structureTreeSelection==null || propertyTreeSelection==null || characterTreeEditorComposite.getFeatureTree()==null){
241
                    MessagingUtils.warningDialog(Messages.CharacterEditor_CANNOT_PERFORM_TITLE, CharacterEditor.this,
242
                            Messages.CharacterEditor_CANNOT_PERFORM_MESSAGE);
243
                    return;
244
                }
245
                Collection<Character> characters = createCharacters((TreeSelection)structureTreeSelection, (TreeSelection)propertyTreeSelection);
246
                for (Character character : characters) {
247
                    //add new Character to feature tree
248
                    FeatureNode parent = ((FeatureTree) characterTreeEditorComposite.getViewer().getInput()).getRoot();
249
                    CdmStore.getService(IFeatureNodeService.class).createChildFeatureNode(parent, character);
250
                }
251
                characterTreeEditorComposite.getViewer().refresh();
252
            }
253
        });
254
    }
255

  
256 278
    public static Collection<Character> createCharacters(TreeSelection structureTreeSelection, TreeSelection propertyTreeSelection){
257 279
        Set<Character> characters = new HashSet<>();
258 280
        //get selected structures and properties
......
321 343
        dirty.setDirty(false);
322 344
    }
323 345

  
346
    public boolean isVocabularySet() {
347
        if(vocabulary==null){
348
            MessagingUtils.warningDialog("Character creation not possible", this.getClass(), "Please select a vocabulary for the characters.");
349
        }
350
        return vocabulary!=null;
351
    }
352

  
353
    public TermVocabulary getVocabulary() {
354
        return vocabulary;
355
    }
356

  
324 357
    @Override
325 358
    public Map<Object, List<String>> getPropertyPathsMap() {
326 359
        List<String> propertyPaths = Arrays.asList(new String[] {

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)