source: trunk/org.modelica.mdt.ui/src/org/modelica/mdt/ui/ModelicaElementAdapter.java @ 384

Last change on this file since 384 was 384, checked in by boris, 19 years ago
  • added images to code completions
File size: 4.1 KB
Line 
1/*
2 * This file is part of Modelica Development Tooling.
3 *
4 * Copyright (c) 2005, Link�pings universitet, Department of
5 * Computer and Information Science, PELAB
6 *
7 * All rights reserved.
8 *
9 * (The new BSD license, see also
10 * http://www.opensource.org/licenses/bsd-license.php)
11 *
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions are
15 * met:
16 *
17 * * Redistributions of source code must retain the above copyright
18 *   notice, this list of conditions and the following disclaimer.
19 *
20 * * Redistributions in binary form must reproduce the above copyright
21 *   notice, this list of conditions and the following disclaimer in
22 *   the documentation and/or other materials provided with the
23 *   distribution.
24 *
25 * * Neither the name of Link�pings universitet nor the names of its
26 *   contributors may be used to endorse or promote products derived from
27 *   this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 */
41
42package org.modelica.mdt.ui;
43
44import org.eclipse.jface.resource.ImageDescriptor;
45import org.eclipse.ui.ISharedImages;
46import org.eclipse.ui.PlatformUI;
47import org.eclipse.ui.model.IWorkbenchAdapter;
48import org.eclipse.ui.model.WorkbenchAdapter;
49import org.modelica.mdt.core.IModelicaElement;
50import org.modelica.mdt.core.IModelicaFile;
51import org.modelica.mdt.core.IModelicaSourceFile;
52import org.modelica.mdt.core.IModelicaFolder;
53import org.modelica.mdt.core.IModelicaProject;
54
55/**
56 * This class mapps modelica objects (Modelica packages, classes, etc) to icons
57 * and labels via IWorkbenchAdapter interface. This icon and lables are used in
58 * for example Modelica Projects view.
59 *
60 * @author Elmir Jagudin
61 */
62
63public class ModelicaElementAdapter extends WorkbenchAdapter
64{
65
66    @Override
67    public String getLabel(Object object)
68    {
69        return ((IModelicaElement)object).getElementName();
70    }
71
72    @Override
73    public ImageDescriptor getImageDescriptor(Object object)
74    {
75        if (object instanceof IModelicaProject)
76        {
77            /*
78             * Isn't patterns beautifull ?
79             */
80            IModelicaProject mproj = (IModelicaProject) object;
81            IWorkbenchAdapter wadap = 
82                (IWorkbenchAdapter) mproj.getWrappedProject().getAdapter(IWorkbenchAdapter.class);
83            return wadap.getImageDescriptor(mproj.getWrappedProject());
84           
85        }
86        /*
87         * this check uggly must be done couse
88         * IModelciaFile is superclass of IModelicaSourceFile
89         */
90        else if ((object instanceof IModelicaFile) 
91                && !(object instanceof IModelicaSourceFile))
92        {
93            /*
94             * pattern beauty continued...
95             */
96            IModelicaFile mfile = (IModelicaFile) object;
97            IWorkbenchAdapter wadap = 
98                (IWorkbenchAdapter) mfile.getResource().getAdapter(IWorkbenchAdapter.class);
99            return wadap.getImageDescriptor(mfile.getResource());
100           
101        }
102        else if (object instanceof IModelicaFolder)
103        {
104            return PlatformUI.getWorkbench().getSharedImages().
105                    getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER);
106        }
107        else if (object instanceof IModelicaElement)
108        {
109            String key = 
110                ModelicaImages.getModelicaElementKey((IModelicaElement)object);
111            if (key != null)
112            {
113                return ModelicaImages.getImageDescriptor(key);
114            }
115        }
116       
117        return super.getImageDescriptor(object);
118    }
119
120}
Note: See TracBrowser for help on using the repository browser.