Project

General

Profile

Download (4.54 KB) Statistics
| Branch: | Tag: | Revision:
1 c10e4c27 n.hoffmann
/**
2 ee1ed5a9 Patric Plitzner
 *
3 c10e4c27 n.hoffmann
 */
4 f211dd28 n.hoffmann
package eu.etaxonomy.taxeditor.view;
5 c10e4c27 n.hoffmann
6 2832a925 Patric Plitzner
import org.eclipse.jface.viewers.ISelection;
7 12257a98 Patrick Plitzner
import org.eclipse.jface.viewers.IStructuredSelection;
8 c10e4c27 n.hoffmann
import org.eclipse.swt.widgets.Composite;
9 2832a925 Patric Plitzner
import org.eclipse.swt.widgets.Display;
10
import org.eclipse.ui.IWorkbenchPart;
11 c10e4c27 n.hoffmann
12 296bc5e0 Patric Plitzner
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
13 da07b5ae Patrick Plitzner
import eu.etaxonomy.taxeditor.workbench.part.ISelectionElementEditingPart;
14 c10e4c27 n.hoffmann
15
/**
16 9d33fde3 n.hoffmann
 * <p>
17
 * Abstract AbstractCdmEditorViewPart class.
18
 * </p>
19 ee1ed5a9 Patric Plitzner
 *
20 c10e4c27 n.hoffmann
 * @author n.hoffmann
21
 * @created Sep 21, 2010
22
 * @version 1.0
23
 */
24 da07b5ae Patrick Plitzner
public abstract class AbstractCdmEditorViewPart extends AbstractCdmViewPart implements ISelectionElementEditingPart {
25 c10e4c27 n.hoffmann
26 2832a925 Patric Plitzner
    private DelaySelection delaySelection = null;
27
    /**
28
     * This is the monitor for the DelaySelection runnable.
29
     * If it is <code>true</code> then it is currently delaying a selection.
30
     */
31 310e8ec9 Patric Plitzner
    private boolean isInDelay;
32 12257a98 Patrick Plitzner
33 da07b5ae Patrick Plitzner
    protected Object selectionProvidingPart;
34 2832a925 Patric Plitzner
35
36
    /**
37
     * This class invokes internal_selectionChanged() in a separate thread.
38
     * This allows an asynchronous and/or delayed handling of selection changes
39
     */
40
    private class DelaySelection implements Runnable{
41
        private IWorkbenchPart part;
42
        private ISelection selection;
43
44
        public DelaySelection(IWorkbenchPart part, ISelection selection) {
45
            super();
46
            this.part = part;
47
            this.selection = selection;
48
        }
49
50
        @Override
51
        public void run() {
52 310e8ec9 Patric Plitzner
            try{
53 7beb1c71 Patric Plitzner
                selectionChanged_internal(part, selection);
54 310e8ec9 Patric Plitzner
            }
55
            finally{
56
                isInDelay = false;
57
            }
58 2832a925 Patric Plitzner
        }
59
60
        public synchronized void setSelection(ISelection selection) {
61
            this.selection = selection;
62
        }
63
64
        public synchronized void setPart(IWorkbenchPart part) {
65
            this.part = part;
66
        }
67
68
    }
69
70
    /**
71
     * Handle selection change events here and <b>not</b> in
72
     * {@link AbstractCdmEditorViewPart#selectionChanged(IWorkbenchPart, ISelection)}
73
     * if you want asynchronous selection handling.
74
     * @param part The workbench part that has issued the selection change
75
     * @param selection the new selection
76
     */
77 7beb1c71 Patric Plitzner
    protected abstract void selectionChanged_internal(IWorkbenchPart part, ISelection selection);
78 2832a925 Patric Plitzner
79
    /** {@inheritDoc} */
80
    @Override
81
    public void selectionChanged(IWorkbenchPart part, ISelection selection) {
82 79724bfc k.luther
    	/*to avoid widget is disposed exceptions
83 221d1c69 k.luther
        if(getViewer().getControl().isDisposed()){
84
            return;
85 79724bfc k.luther
        }*/
86 221d1c69 k.luther
    	if(delaySelection==null){
87 2832a925 Patric Plitzner
            delaySelection = new DelaySelection(part, selection);
88
        }
89
        delaySelection.setPart(part);
90
        delaySelection.setSelection(selection);
91
        if(!isInDelay){
92
            isInDelay = true;
93
            Display.getCurrent().asyncExec(delaySelection);
94
        }
95 12257a98 Patrick Plitzner
    }
96
97
    /**
98
     * {@inheritDoc}
99
     */
100
    @Override
101
    public void showViewer(Object part, IStructuredSelection selection) {
102
        super.showViewer(part, selection);
103 da07b5ae Patrick Plitzner
        selectionProvidingPart = part;
104
    }
105
106
    @Override
107
    public Object getSelectionProvidingPart() {
108
        return selectionProvidingPart;
109 2832a925 Patric Plitzner
    }
110 f13a970a Patrick Plitzner
111
112 2832a925 Patric Plitzner
113
    /** {@inheritDoc} */
114
    @Override
115
    public void createPartControl(Composite parent) {
116
        super.createPartControl(parent);
117 310e8ec9 Patric Plitzner
        isInDelay = false;
118 2832a925 Patric Plitzner
    }
119
120 68061e15 Patrick Plitzner
//    /**
121
//     * <p>
122
//     * getEditor
123
//     * </p>
124
//     *
125
//     * @return the currently active editor
126
//     */
127
//    public IEditorPart getEditor() {
128
////        return AbstractUtility.getActiveEditor();
129
//    }
130 2832a925 Patric Plitzner
131 da07b5ae Patrick Plitzner
    /**
132
     * {@inheritDoc}
133
     */
134
    @Override
135
    public void showEmptyPage() {
136
        selectionProvidingPart = null;
137
        super.showEmptyPage();
138
    }
139
140 2832a925 Patric Plitzner
    /** {@inheritDoc} */
141
    @Override
142
    public void setFocus() {
143
        super.setFocus();
144
145 68061e15 Patrick Plitzner
//        if(getEditor() != null && ISecuredEditor.class.isAssignableFrom(getEditor().getClass())){
146
//            boolean doEnable = ((ISecuredEditor)getEditor()).permissionsSatisfied();
147
//            setEnabled(doEnable);
148
//        }
149 ee1ed5a9 Patric Plitzner
    }
150 9d33fde3 n.hoffmann
151 da07b5ae Patrick Plitzner
    /**
152
     * {@inheritDoc}
153
     */
154
    @Override
155
    public void dispose() {
156
        selectionProvidingPart = null;
157
        super.dispose();
158
    }
159
160 ee1ed5a9 Patric Plitzner
    /** {@inheritDoc} */
161
    @Override
162
    public void changed(Object object) {
163 f13a970a Patrick Plitzner
        if(part instanceof IDirtyMarkable){
164
            ((IDirtyMarkable) part).changed(object);
165
        }
166
        else {
167 68061e15 Patrick Plitzner
//            IEditorPart editor = getEditor();
168
//            if (editor != null && editor instanceof IDirtyMarkable) {
169
//                ((IDirtyMarkable) editor).changed(object);
170
//            }
171 ee1ed5a9 Patric Plitzner
        }
172
    }
173 c10e4c27 n.hoffmann
174
}