Project

General

Profile

« Previous | Next » 

Revision a4a18917

Added by Patrick Plitzner almost 7 years ago

ref #6774 Add "Export" button to FeatureTreeEditorComposite

View differences:

eu.etaxonomy.taxeditor.cdmlib/META-INF/MANIFEST.MF
70 70
 eu.etaxonomy.cdm.io.csv.caryophyllales.out,
71 71
 eu.etaxonomy.cdm.io.csv.redlist.demo,
72 72
 eu.etaxonomy.cdm.io.csv.redlist.out,
73
 eu.etaxonomy.cdm.io.descriptive.owl.out,
73 74
 eu.etaxonomy.cdm.io.distribution.excelupdate,
74 75
 eu.etaxonomy.cdm.io.dwca,
75 76
 eu.etaxonomy.cdm.io.dwca.in,
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/CharacterEditor.java
137 137
        lblNewLabel_1.setText("Properties");
138 138

  
139 139
        treeViewerProperties = addFeatureTreeEditor(composite_1);
140
        initFeatureTreeComposite(treeViewerProperties, new CharacterDragListener(treeViewerStructures.getViewer(), treeViewerProperties.getViewer()), null);
140
        initFeatureTreeComposite(treeViewerProperties, null, null);
141
        //TODO: fix drag and drop
142
//        initFeatureTreeComposite(treeViewerProperties, new CharacterDragListener(treeViewerStructures.getViewer(), treeViewerProperties.getViewer()), null);
141 143

  
142 144
        Composite composite_2 = new Composite(sashForm, SWT.NONE);
143 145
        formToolkit.adapt(composite_2);
......
167 169
        featureTreeEditorComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
168 170
        featureTreeEditorComposite.getButton_add().setVisible(false);
169 171
        featureTreeEditorComposite.getButton_remove().setVisible(false);
172
        featureTreeEditorComposite.getBtnExportTree().setVisible(false);
170 173
        return featureTreeEditorComposite;
171 174
    }
172 175

  
......
175 178
        featureTreeEditorComposite.init(featureNodeDragListener, featureNodeDropAdapter, this,
176 179
                new FeatureTreeChooserListener(featureTreeEditorComposite), new SelectionAdapter() {
177 180
                }, new SelectionAdapter() {
181
                }, new SelectionAdapter() {
178 182
                });
179 183
    }
180 184

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureTreeEditor.java
43 43
import eu.etaxonomy.cdm.api.service.IFeatureNodeService;
44 44
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
45 45
import eu.etaxonomy.cdm.api.service.config.FeatureNodeDeletionConfigurator;
46
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
47 46
import eu.etaxonomy.cdm.model.description.Feature;
48 47
import eu.etaxonomy.cdm.model.description.FeatureNode;
49 48
import eu.etaxonomy.cdm.model.description.FeatureTree;
......
75 74

  
76 75
    private Shell shell;
77 76

  
78
    private FeatureTree featureTree;
79

  
80 77
    private FeatureTreeEditorComposite composite;
81 78

  
82 79
    @Inject
......
91 88
    }
92 89

  
93 90
	/** {@inheritDoc} */
94
	@PostConstruct
95
	public void createControl(Composite parent, @Named(IServiceConstants.ACTIVE_SHELL)Shell shell) {
96
	    composite = new FeatureTreeEditorComposite(parent, SWT.NULL);
97
		composite.init(new FeatureNodeDragListener(composite.getViewer()), new FeatureNodeDropAdapter(this, composite.getViewer()), this, new SelectionAdapter() {
98
            @Override
99
            public void widgetSelected(SelectionEvent e) {
100
                FeatureTree tree = FeatureTreeSelectionDialog.select(shell, conversation, null);
101
                if(tree!=null){
102
                    setSelectedTree(tree);
103
                }
104
            }
105
        }, new AddButtonListener(), new RemoveSelectionListener());
91
    @PostConstruct
92
    public void createControl(Composite parent, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell) {
93
        composite = new FeatureTreeEditorComposite(parent, SWT.NULL);
94
        composite.init(new FeatureNodeDragListener(composite.getViewer()),
95
                new FeatureNodeDropAdapter(this, composite.getViewer()), this, new SelectionAdapter() {
96
                    @Override
97
                    public void widgetSelected(SelectionEvent e) {
98
                        FeatureTree tree = FeatureTreeSelectionDialog.select(shell, conversation, null);
99
                        if (tree != null) {
100
                            composite.setSelectedTree(tree, FeatureTreeEditor.this);
101
                        }
102
                    }
103
                }, new AddButtonListener(), new RemoveSelectionListener(), new FeatureTreeExportListener(shell, composite));
106 104
        composite.getText_title().setEnabled(false);
107
	}
105
    }
108 106

  
109 107
	public void setDirty(boolean isDirty){
110 108
	    this.dirty.setDirty(isDirty);
......
114 112
	    return dirty.isDirty();
115 113
	}
116 114

  
117
    public void setSelectedTree(FeatureTree featureTree) {
118
		this.featureTree = HibernateProxyHelper.deproxy(featureTree, FeatureTree.class);
119
		this.featureTree.setRoot(HibernateProxyHelper.deproxy(featureTree.getRoot(), FeatureNode.class));
120
		composite.getViewer().setInput(featureTree);
121

  
122
		composite.getText_title().setEnabled(true);
123
		composite.getText_title().removeModifyListener(this);
124
		composite.getText_title().setText(featureTree.getTitleCache());
125
		composite.getText_title().addModifyListener(this);
126
	}
127

  
128 115
    public FeatureTree getSelectedFeatureTree(){
129
        return this.featureTree;
116
        return composite.getFeatureTree();
130 117
    }
131 118

  
132 119
	/** {@inheritDoc} */
133 120
	@Override
134 121
	public void modifyText(ModifyEvent e) {
135
		featureTree.setTitleCache(composite.getText_title().getText(), true);
122
	    composite.getFeatureTree().setTitleCache(composite.getText_title().getText(), true);
136 123
		setDirty(true);
137 124
	}
138 125

  
......
168 155
        // commit the conversation and start a new transaction immediately
169 156
        conversation.commit(true);
170 157

  
171
        CdmStore.getService(IFeatureTreeService.class).saveOrUpdate(featureTree);
158
        CdmStore.getService(IFeatureTreeService.class).saveOrUpdate(composite.getFeatureTree());
172 159

  
173 160
        this.setDirty(false);
174 161
	}
......
207 194
    @Override
208 195
    public List<FeatureTree> getRootEntities() {
209 196
        List<FeatureTree> root = new ArrayList<>();
210
        root.add(featureTree);
197
        root.add(composite.getFeatureTree());
211 198
        return root;
212 199
    }
213 200

  
......
215 202
		@Override
216 203
		public void widgetSelected(SelectionEvent e) {
217 204
			AvailableFeaturesWizard wizard = new AvailableFeaturesWizard(
218
					featureTree);
205
			        composite.getFeatureTree());
219 206
			WizardDialog dialog = new WizardDialog(shell, wizard);
220 207

  
221 208
			if (dialog.open() == IStatus.OK) {
......
247 234
			composite.getViewer().refresh();
248 235
		}
249 236
	}
237

  
250 238
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureTreeEditorComposite.java
47 47
    private TreeViewer viewer;
48 48
    private Button button_add;
49 49
    private Button button_remove;
50
    private Button btnExportTree;
50 51

  
51 52
    public FeatureTreeEditorComposite(Composite parent, int style) {
52 53
        super(parent, style);
......
91 92
        button_remove.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
92 93
        button_remove.setToolTipText(Messages.FeatureTreeEditorComposite_REMOVE_FEATURE);
93 94
        button_remove.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
95

  
96
        btnExportTree = new Button(composite_buttons, SWT.NONE);
97
        btnExportTree.setToolTipText("Export feature tree");
98
        btnExportTree.setImage(ImageResources.getImage(ImageResources.MOVE_ICON));
94 99
    }
95 100

  
96 101
    public void init(DragSourceListener dragSourceListener,
97 102
            DropTargetListener dropTargetListener, ISelectionChangedListener viewerSelectionChangedListener,
98
            SelectionListener openFeatureTreeSelectionListener, SelectionListener addButtonSelectionListener, SelectionListener removeButtonSelectionListener) {
103
            SelectionListener openFeatureTreeSelectionListener, SelectionListener addButtonSelectionListener, SelectionListener removeButtonSelectionListener, SelectionListener exportButtonSelectionListener) {
99 104
        viewer.setContentProvider(new FeatureTreeContentProvider());
100 105
        viewer.setLabelProvider(new FeatureTreeLabelProvider());
101 106

  
......
113 118

  
114 119
        button_add.addSelectionListener(addButtonSelectionListener);
115 120
        button_remove.addSelectionListener(removeButtonSelectionListener);
121
        btnExportTree.addSelectionListener(exportButtonSelectionListener);
116 122

  
117 123
        btnOpenFeatureTree.addSelectionListener(openFeatureTreeSelectionListener);
118 124
    }
......
176 182
        return button_remove;
177 183
    }
178 184

  
185
    /**
186
     * @return the btnExportTree
187
     */
188
    public Button getBtnExportTree() {
189
        return btnExportTree;
190
    }
191

  
179 192
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureTreeExportListener.java
1
/**
2
* Copyright (C) 2017 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.featuretree.e4;
10

  
11
import java.io.File;
12

  
13
import org.eclipse.core.runtime.jobs.Job;
14
import org.eclipse.swt.events.SelectionAdapter;
15
import org.eclipse.swt.events.SelectionEvent;
16
import org.eclipse.swt.widgets.DirectoryDialog;
17
import org.eclipse.swt.widgets.Shell;
18
import org.eclipse.ui.progress.IProgressConstants;
19

  
20
import eu.etaxonomy.cdm.io.descriptive.owl.out.OwlExportConfigurator;
21
import eu.etaxonomy.taxeditor.model.MessagingUtils;
22
import eu.etaxonomy.taxeditor.store.CdmStore;
23

  
24
/**
25
 * @author pplitzner
26
 * @since Jul 4, 2017
27
 *
28
 */
29
public class FeatureTreeExportListener extends SelectionAdapter{
30

  
31
    private Shell shell;
32
    private FeatureTreeEditorComposite composite;
33

  
34
    public FeatureTreeExportListener(Shell shell, FeatureTreeEditorComposite composite) {
35
        super();
36
        this.shell = shell;
37
        this.composite = composite;
38
    }
39

  
40
    @Override
41
    public void widgetSelected(SelectionEvent e) {
42
        if(composite.getFeatureTree()==null){
43
            MessagingUtils.informationDialog("Export not possible", "There is no feature tree selected.");
44
            return;
45
        }
46
        DirectoryDialog dialog = new DirectoryDialog(shell);
47
        String directoryString = dialog.open();
48
        if(directoryString!=null){
49
            // create job
50
            Job job = CdmStore.getExportManager().createIOServiceJob(OwlExportConfigurator.NewInstance(null, null, composite.getFeatureTree()), new File(directoryString+"/owl.owl"));
51
            // configure the job
52
            job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
53
            job.setUser(true);
54
            // schedule job
55
            job.schedule();
56
        }
57
    }
58
}

Also available in: Unified diff