~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/uml2sd/load/LoadersManager.java

  • Committer: Package Import Robot
  • Author(s): tony mancill
  • Date: 2013-05-13 21:43:22 UTC
  • mfrom: (1.2.1) (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20130513214322-6frgd9du1n0w2uo7
Tags: 1.2.1-1
* Team upload.
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**********************************************************************
2
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
3
3
 * Copyright (c) 2011, 2012 Ericsson.
4
 
 * 
 
4
 *
5
5
 * All rights reserved.   This program and the accompanying materials
6
6
 * are made available under the terms of the Eclipse Public License v1.0
7
7
 * which accompanies this distribution, and is available at
8
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 
 * 
10
 
 * Contributors: 
 
9
 *
 
10
 * Contributors:
11
11
 * IBM - Initial API and implementation
12
12
 * Bernd Hufmann - Updated for TMF
13
13
 **********************************************************************/
32
32
 
33
33
/**
34
34
 * Manager class for the UML2SD extension point.
35
 
 * 
 
35
 *
36
36
 * @version 1.0
37
37
 * @author sveyrier
38
38
 * @author Bernd Hufmann
68
68
     * Map for caching information (view ID to list of configuration elements)
69
69
     */
70
70
    protected Map<String, ArrayList<IConfigurationElement>> fViewLoadersList = new HashMap<String, ArrayList<IConfigurationElement>>();
71
 
    
 
71
 
72
72
    // ------------------------------------------------------------------------
73
73
    // Constructor
74
74
    // ------------------------------------------------------------------------
83
83
    // ------------------------------------------------------------------------
84
84
    /**
85
85
     * A static method to get the manager instance.
86
 
     * 
 
86
     *
87
87
     * @return the manager instance
88
88
     */
89
89
    public synchronized static LoadersManager getInstance() {
92
92
        }
93
93
        return fLoadersManager;
94
94
    }
95
 
    
 
95
 
96
96
    /**
97
97
     * Creates a loader instance and associate it to the view. It requires
98
98
     * that the loader-view-association was created by an eclipse extension.
99
 
     * 
 
99
     *
100
100
     * @param className The name of the class to create an instance from
101
101
     * @param view The UML2 Sequence Diagram view instance
102
102
     * @return The created loader
123
123
                return loader;
124
124
            }
125
125
        }
126
 
        return null; 
 
126
        return null;
127
127
    }
128
128
 
129
129
    /**
130
130
     * Sets the loader to null for this view, a kind of clean-up while disposing.
131
 
     * 
 
131
     *
132
132
     * @param viewId the id of the view
133
133
     */
134
134
    public void resetLoader(String viewId) {
135
 
        IUml2SDLoader loader = (IUml2SDLoader) fViewLoaderMap.get(viewId);
 
135
        IUml2SDLoader loader = fViewLoaderMap.get(viewId);
136
136
        if (loader != null) {
137
137
            loader.dispose();
138
138
        }
141
141
 
142
142
    /**
143
143
     * Returns the loader in use in given Sequence Diagram View
144
 
     * 
 
144
     *
145
145
     * @param viewId The Sequence Diagram viewId.
146
146
     * @return the current loader if any - null otherwise
147
147
     */
151
151
 
152
152
    /**
153
153
     * Returns the loader in use in this Sequence Diagram View
154
 
     * 
 
154
     *
155
155
     * @param viewId The Sequence Diagram viewId
156
156
     * @param view The Sequence Diagram view (if known). Use null to reference the primary SD View.
157
157
     * @return the current loader if any - null otherwise
168
168
        try {
169
169
            // Search the view corresponding to the viewId
170
170
            if (sdView == null) {
171
 
                IViewReference viewref = (IViewReference) persp.findViewReference(viewId);
 
171
                IViewReference viewref = persp.findViewReference(viewId);
172
172
                if (viewref != null) {
173
173
                    sdView = (SDView) viewref.getView(false);
174
174
                }
175
 
                
 
175
 
176
176
                if (sdView == null) {
177
177
                    // no corresponding view exists -> return null for the loader
178
178
                    return null;
195
195
 
196
196
    /**
197
197
     * Returns the loader class name that have been saved last time.
198
 
     * 
 
198
     *
199
199
     * @param viewId The view this loader belongs to
200
200
     * @return the class name of the saved loader
201
201
     */
206
206
 
207
207
    /**
208
208
     * Saves the last loader in order to reload it on next session.
 
209
     *
 
210
     * @param id
 
211
     *            Standalone ID of the loader
 
212
     * @param id2
 
213
     *            Suffix ID of the loader
209
214
     */
210
215
    public void saveLastLoader(String id, String id2) {
211
216
        IPreferenceStore p = Activator.getDefault().getPreferenceStore();
214
219
 
215
220
    /**
216
221
     * Changes the current unique loader to the given secondary viewId.
217
 
     * 
 
222
     *
218
223
     * @param loader The current loader
219
224
     * @param id the view secondary id or null
220
225
     */
232
237
                try {
233
238
                    // Search view corresponding to the viewId
234
239
                    SDView sdview = null;
235
 
                    IViewReference viewref = (IViewReference) persp.findViewReference(id);
 
240
                    IViewReference viewref = persp.findViewReference(id);
236
241
                    if (viewref != null) {
237
242
                        sdview = (SDView) viewref.getView(false);
238
243
                    }
258
263
            saveLastLoader(loader.getClass().getName(), id);
259
264
        }
260
265
    }
261
 
    
 
266
 
262
267
    /**
263
268
     * Creates the last loader and saves it. If not last is not available, it creates
264
269
     * and saves the default loader, else no loader is created.
265
 
     * 
 
270
     *
266
271
     * @param viewId The view ID.
267
272
     */
268
273
    private void createLastLoaderIfAny(String viewId) {
288
293
     * @return List of extension point configuration elements.
289
294
     */
290
295
    private List<IConfigurationElement> getLoaderConfigurationElements(String viewId) {
291
 
        List<IConfigurationElement> list = (List<IConfigurationElement>) fViewLoadersList.get(viewId);
 
296
        List<IConfigurationElement> list = fViewLoadersList.get(viewId);
292
297
        if (list != null) {
293
298
            return list;
294
299
        }
298
303
        if (iep == null) {
299
304
            return ret;
300
305
        }
301
 
        
 
306
 
302
307
        IExtension[] ie = iep.getExtensions();
303
308
        if (ie == null) {
304
309
            return ret;
317
322
    }
318
323
 
319
324
    /**
320
 
     * Returns the loader configuration element for given loader class name and for the given 
 
325
     * Returns the loader configuration element for given loader class name and for the given
321
326
     * list of configuration elements, if available else null.
322
 
     * 
 
327
     *
323
328
     * @param loaderClassName The loader class name.
324
329
     * @param loaderElements  The list of loader configuration elements
325
 
     * @return Extension point configuration element 
 
330
     * @return Extension point configuration element
326
331
     */
327
 
    private IConfigurationElement getLoaderConfigurationElement(String loaderClassName, List<IConfigurationElement> loaderElements) {
 
332
    private static IConfigurationElement getLoaderConfigurationElement(
 
333
            String loaderClassName, List<IConfigurationElement> loaderElements) {
328
334
        if (loaderClassName != null && loaderClassName.length() > 0) {
329
335
            // Find configuration element corresponding to the saved loader
330
336
            for (Iterator<IConfigurationElement> i = loaderElements.iterator(); i.hasNext();) {
331
 
                IConfigurationElement ce = (IConfigurationElement) i.next();
 
337
                IConfigurationElement ce = i.next();
332
338
                if (ce.getAttribute("class").equals(loaderClassName)) { //$NON-NLS-1$
333
339
                    return ce;
334
340
                }
338
344
    }
339
345
 
340
346
    /**
341
 
     * Returns the loader configuration element for the given list of configuration elements, if available else null. 
 
347
     * Returns the loader configuration element for the given list of configuration elements, if available else null.
342
348
     * Note that if multiple default loaders are defined it selects the first one
343
349
 
344
350
     * @param loaderElements The list of loader configuration elements
345
351
     * @return The default extension point configuration element.
346
352
     */
347
 
    private IConfigurationElement getDefaultLoader(List<IConfigurationElement> loaderElements) {
 
353
    private static IConfigurationElement getDefaultLoader(
 
354
            List<IConfigurationElement> loaderElements) {
348
355
        // Look for a default loader
349
356
        for (Iterator<IConfigurationElement> i = loaderElements.iterator(); i.hasNext();) {
350
 
            IConfigurationElement ce = (IConfigurationElement) i.next();
 
357
            IConfigurationElement ce = i.next();
351
358
            if (Boolean.valueOf(ce.getAttribute("default")).booleanValue()) { //$NON-NLS-1$
352
359
                return ce;
353
360
            }
358
365
    /**
359
366
     * Creates an instance of the loader class for a given extension point configuration element and
360
367
     * also sets it as current loader for the given view.
361
 
     * 
 
368
     *
362
369
     * @param viewId The view ID.
363
370
     * @param ce The extension point configuration element
364
371
     */