Project

General

Profile

« Previous | Next » 

Revision 243636c2

Added by Patrick Plitzner almost 9 years ago

Refactor ICdmViewer framework

Removed unnecessary ExecutionEvent

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java
13 13
import java.util.Map;
14 14
import java.util.Map.Entry;
15 15

  
16
import org.eclipse.core.commands.ExecutionEvent;
17 16
import org.eclipse.core.runtime.CoreException;
18 17
import org.eclipse.core.runtime.IConfigurationElement;
19 18
import org.eclipse.core.runtime.IExtensionRegistry;
......
40 39
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
41 40

  
42 41
/**
43
 * This class provides the possibility to choose from a list of possible viewers
44
 * which can be opened for a given input in a popup dialog.
42
 * This class opens a popup dialog and provides the possibility to choose from a
43
 * list of possible viewers which can be opened for a given input.
45 44
 *
46 45
 * @author pplitzner
47 46
 * @date Feb 23, 2015
......
51 50

  
52 51
    private Object input;
53 52
    private Map<Entry<Class<?>, String>, ICdmViewer> nameViewerMap;
54
    private ExecutionEvent executionEvent;
55 53

  
56 54
    public CdmViewerChooser(Shell parentShell) {
57 55
        this(parentShell, SWT.RESIZE | SWT.ON_TOP, true, false, false, false, false, "Open in ...",
......
65 63
                titleText, infoText);
66 64
    }
67 65

  
68
    /**
69
     * Opens a popup dialog with all possible viewers for the given input.
70
     * @param input the input for which the viewers are listed
71
     * @param event the {@link ExecutionEvent} if invoked via command/handler
72
     */
73
    public void chooseViewer(Object input, ExecutionEvent event){
74
        this.input = input;
75
        this.executionEvent = event;
76
        this.nameViewerMap = new HashMap<Entry<Class<?>, String>, ICdmViewer>();
66
    public static  Map<Entry<Class<?>, String>, ICdmViewer> getNameViewerMap(Object input){
67
        Map<Entry<Class<?>, String>, ICdmViewer> nameViewerMap = new HashMap<Entry<Class<?>, String>, ICdmViewer>();
77 68

  
78 69
        IExtensionRegistry reg = Platform.getExtensionRegistry();
79 70
        IConfigurationElement[] extensions = reg
......
95 86
                MessagingUtils.error(CdmViewerChooser.class, "Could not load cdmViewer extension", e);
96 87
            }
97 88
        }
89
        return nameViewerMap;
90
    }
91

  
92
    /**
93
     * Opens a popup dialog with all possible viewers for the given input.
94
     * @param input the input for which the viewers are listed
95
     */
96
    public void chooseViewer(Object input){
97
        this.input = input;
98
        this.nameViewerMap = getNameViewerMap(input);
99

  
98 100
        //if only one editor is available then open it
99 101
        if(nameViewerMap.size()==1){
100 102
            Entry<Class<?>, String> next = nameViewerMap.keySet().iterator().next();
101 103
            ICdmViewer cdmViewer = nameViewerMap.get(next);
102
            cdmViewer.show(input, next.getKey(), event);
104
            cdmViewer.show(input, next.getKey());
103 105
        }
104 106
        else{
105 107
            if(nameViewerMap.isEmpty()){
......
109 111
        }
110 112
    }
111 113

  
112
    /* (non-Javadoc)
113
     * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
114
     */
115 114
    @Override
116 115
    protected Control createDialogArea(Composite parent) {
117 116
        TableViewer viewer = new TableViewer(new Table(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION));
......
122 121
        return parent;
123 122
    }
124 123

  
125
    /* (non-Javadoc)
126
     * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
127
     */
128 124
    @Override
129 125
    public void selectionChanged(SelectionChangedEvent event) {
130 126
        ISelection selection = event.getSelection();
......
133 129
            if(nameViewerMap.containsKey(firstElement)){
134 130
                Entry<Class<?>, String> entry = (Entry<Class<?>, String>)firstElement;
135 131
                ICdmViewer cdmViewer = nameViewerMap.get(entry);
136
                cdmViewer.show(input, entry.getKey(), this.executionEvent);
132
                cdmViewer.show(input, entry.getKey());
137 133
                this.close();
138 134
            }
139 135
        }
140 136
    }
141 137

  
142
    /* (non-Javadoc)
143
     * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
144
     */
145 138
    @Override
146 139
    public String getText(Object element) {
147 140
        String text = null;
......
152 145
        return text;
153 146
    }
154 147

  
155
    /* (non-Javadoc)
156
     * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
157
     */
158 148
    @Override
159 149
    public void addListener(ILabelProviderListener listener) {
160 150
        // TODO Auto-generated method stub
161 151

  
162 152
    }
163 153

  
164
    /* (non-Javadoc)
165
     * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
166
     */
167 154
    @Override
168 155
    public void dispose() {
169 156
        // TODO Auto-generated method stub
170 157

  
171 158
    }
172 159

  
173
    /* (non-Javadoc)
174
     * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
175
     */
176 160
    @Override
177 161
    public boolean isLabelProperty(Object element, String property) {
178 162
        // TODO Auto-generated method stub
179 163
        return false;
180 164
    }
181 165

  
182
    /* (non-Javadoc)
183
     * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
184
     */
185 166
    @Override
186 167
    public void removeListener(ILabelProviderListener listener) {
187 168
        // TODO Auto-generated method stub
188 169

  
189 170
    }
190 171

  
191
    /* (non-Javadoc)
192
     * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
193
     */
194 172
    @Override
195 173
    public Image getImage(Object element) {
196 174
        // TODO Auto-generated method stub

Also available in: Unified diff