Project

General

Profile

« Previous | Next » 

Revision efbcc6bb

Added by Patrick Plitzner almost 7 years ago

ref #6774 session handling and minor refactoring

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/CharacterEditor.java
42 42
import org.eclipse.swt.widgets.Button;
43 43
import org.eclipse.swt.widgets.Composite;
44 44
import org.eclipse.swt.widgets.Display;
45
import org.eclipse.swt.widgets.Label;
46 45
import org.eclipse.swt.widgets.Shell;
47 46
import org.eclipse.ui.forms.widgets.FormToolkit;
48 47

  
......
86 85
    private ConversationHolder conversation;
87 86

  
88 87
    private ICdmEntitySession cdmEntitySession;
88
    private Composite composite;
89 89

  
90 90
    public CharacterEditor() {
91 91
    }
......
113 113
        formToolkit.adapt(sashForm);
114 114
        formToolkit.paintBordersFor(sashForm);
115 115

  
116
        Composite composite = new Composite(sashForm, SWT.NONE);
116
        composite = new Composite(sashForm, SWT.NONE);
117 117
        formToolkit.adapt(composite);
118 118
        formToolkit.paintBordersFor(composite);
119 119
        composite.setLayout(new GridLayout(1, false));
120 120

  
121
        Label lblNewLabel = new Label(composite, SWT.NONE);
122
        lblNewLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
123
        formToolkit.adapt(lblNewLabel, true, true);
124
        lblNewLabel.setText("Structures");
125

  
126 121
        treeViewerStructures = addFeatureTreeEditor(composite);
127 122
        initFeatureTreeComposite(treeViewerStructures, null, null);
128 123

  
......
131 126
        formToolkit.paintBordersFor(composite_1);
132 127
        composite_1.setLayout(new GridLayout(1, false));
133 128

  
134
        Label lblNewLabel_1 = new Label(composite_1, SWT.NONE);
135
        lblNewLabel_1.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
136
        formToolkit.adapt(lblNewLabel_1, true, true);
137
        lblNewLabel_1.setText("Properties");
138

  
139 129
        treeViewerProperties = addFeatureTreeEditor(composite_1);
140 130
        initFeatureTreeComposite(treeViewerProperties, null, null);
141 131
        //TODO: fix drag and drop
......
167 157
    private FeatureTreeEditorComposite addFeatureTreeEditor(Composite composite_3) {
168 158
        FeatureTreeEditorComposite featureTreeEditorComposite = new FeatureTreeEditorComposite(composite_3, SWT.BORDER);
169 159
        featureTreeEditorComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
170
        featureTreeEditorComposite.getButton_add().setVisible(false);
171
        featureTreeEditorComposite.getButton_remove().setVisible(false);
172
        featureTreeEditorComposite.getBtnExportTree().setVisible(false);
160
        featureTreeEditorComposite.getComposite_buttons().setVisible(false);
173 161
        return featureTreeEditorComposite;
174 162
    }
175 163

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureTreeEditor.java
77 77
    private FeatureTreeEditorComposite composite;
78 78

  
79 79
    @Inject
80
    public FeatureTreeEditor(@Named(IServiceConstants.ACTIVE_SHELL)Shell shell) {
81
        this.shell = shell;
82
        if(conversation==null){
83
            conversation = CdmStore.createConversation();
84
        }
85
        if (CdmStore.isActive()) {
86
            cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
87
        }
80
    public FeatureTreeEditor() {
88 81
    }
89 82

  
90 83
	/** {@inheritDoc} */
91 84
    @PostConstruct
92
    public void createControl(Composite parent, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell) {
85
    public void createControl(Composite parent) {
86
        if (CdmStore.isActive()){
87
            if(conversation == null){
88
                conversation = CdmStore.createConversation();
89
            }
90
            if(cdmEntitySession!=null){
91
                cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
92
            }
93
        }
94
        else{
95
            return;
96
        }
93 97
        composite = new FeatureTreeEditorComposite(parent, SWT.NULL);
94 98
        composite.init(new FeatureNodeDragListener(composite.getViewer()),
95 99
                new FeatureNodeDropAdapter(this, composite.getViewer()), this, new SelectionAdapter() {
......
129 133
		IStructuredSelection selection = (IStructuredSelection) event
130 134
				.getSelection();
131 135

  
132
		composite.getButton_add().setEnabled(selection.size() <= 1);
133
		composite.getButton_remove().setEnabled(selection.size() > 0);
136
		composite.getBtnAdd().setEnabled(selection.size() <= 1);
137
		composite.getBtnRemove().setEnabled(selection.size() > 0);
134 138
		//propagate selection
135 139
		selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event));
136 140
	}
137 141

  
138 142
	@Focus
139
	public void focus(){
140
	    composite.getViewer().getControl().setFocus();
143
	public void focus(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell){
144
	    this.shell = shell;
145
	    if(composite!=null){
146
	        composite.getViewer().getControl().setFocus();
147
	    }
141 148
        if(conversation!=null && !conversation.isBound()){
142 149
            conversation.bind();
143 150
        }
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureTreeEditorComposite.java
45 45
    private Text text_title;
46 46
    private Button btnOpenFeatureTree;
47 47
    private TreeViewer viewer;
48
    private Button button_add;
49
    private Button button_remove;
48
    private Button btnAdd;
49
    private Button btnRemove;
50 50
    private Button btnExportTree;
51 51

  
52
    private Composite composite_buttons;
53

  
52 54
    public FeatureTreeEditorComposite(Composite parent, int style) {
53 55
        super(parent, style);
54 56
        setLayout(new GridLayout(2, false));
......
78 80
        viewer.getControl().setLayoutData(
79 81
                new GridData(SWT.FILL, SWT.FILL, true, true));
80 82

  
81
        Composite composite_buttons = new Composite(this,
83
        composite_buttons = new Composite(this,
82 84
                SWT.NULL);
83 85
        composite_buttons.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false,
84 86
                false));
85 87
        composite_buttons.setLayout(new GridLayout());
86 88

  
87
        button_add = new Button(composite_buttons, SWT.PUSH);
88
        button_add.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
89
        button_add.setToolTipText(Messages.FeatureTreeEditorComposite_ADD_FEATURE);
90
        button_add.setImage(ImageResources.getImage(ImageResources.ADD_EDIT));
91
        button_remove = new Button(composite_buttons, SWT.PUSH);
92
        button_remove.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
93
        button_remove.setToolTipText(Messages.FeatureTreeEditorComposite_REMOVE_FEATURE);
94
        button_remove.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
89
        btnAdd = new Button(composite_buttons, SWT.PUSH);
90
        btnAdd.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
91
        btnAdd.setToolTipText(Messages.FeatureTreeEditorComposite_ADD_FEATURE);
92
        btnAdd.setImage(ImageResources.getImage(ImageResources.ADD_EDIT));
93
        btnRemove = new Button(composite_buttons, SWT.PUSH);
94
        btnRemove.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
95
        btnRemove.setToolTipText(Messages.FeatureTreeEditorComposite_REMOVE_FEATURE);
96
        btnRemove.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
95 97

  
96 98
        btnExportTree = new Button(composite_buttons, SWT.NONE);
97 99
        btnExportTree.setToolTipText("Export feature tree");
......
116 118

  
117 119
        viewer.addSelectionChangedListener(viewerSelectionChangedListener);
118 120

  
119
        button_add.addSelectionListener(addButtonSelectionListener);
120
        button_remove.addSelectionListener(removeButtonSelectionListener);
121
        btnAdd.addSelectionListener(addButtonSelectionListener);
122
        btnRemove.addSelectionListener(removeButtonSelectionListener);
121 123
        btnExportTree.addSelectionListener(exportButtonSelectionListener);
122 124

  
123 125
        btnOpenFeatureTree.addSelectionListener(openFeatureTreeSelectionListener);
......
171 173
    /**
172 174
     * @return the button_add
173 175
     */
174
    public Button getButton_add() {
175
        return button_add;
176
    public Button getBtnAdd() {
177
        return btnAdd;
176 178
    }
177 179

  
178 180
    /**
179 181
     * @return the button_remove
180 182
     */
181
    public Button getButton_remove() {
182
        return button_remove;
183
    public Button getBtnRemove() {
184
        return btnRemove;
185
    }
186
    
187
    /**
188
     * @return the composite_buttons
189
     */
190
    public Composite getComposite_buttons() {
191
        return composite_buttons;
183 192
    }
184 193

  
185 194
    /**

Also available in: Unified diff