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

Last change on this file since 283 was 283, checked in by boris, 19 years ago
  • redone how the top-level packages in the system library are enumerated and displayed in the gui
File size: 5.4 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.IModelicaClass;
50import org.modelica.mdt.core.IModelicaComponent;
51import org.modelica.mdt.core.IModelicaElement;
52import org.modelica.mdt.core.IModelicaFile;
53import org.modelica.mdt.core.IModelicaFolder;
54import org.modelica.mdt.core.IModelicaProject;
55import org.modelica.mdt.core.compiler.CompilerException;
56import org.modelica.mdt.internal.core.ErrorManager;
57
58/**
59 * This class mapps modelica objects (Modelica packages, classes, etc) to icons and labels
60 * via IWorkbenchAdapter interface. This icon and lables are used in for example Modelica
61 * Projects view.
62 *
63 * @author Elmir Jagudin
64 */
65
66public class ModelicaElementAdapter extends WorkbenchAdapter
67{
68
69    @Override
70    public String getLabel(Object object)
71    {
72        return ((IModelicaElement)object).getElementName();
73    }
74
75    @Override
76    public ImageDescriptor getImageDescriptor(Object object)
77    {
78        if (object instanceof IModelicaProject)
79        {
80            /*
81             * Isn't patterns beautifull ?
82             */
83            IModelicaProject mproj = (IModelicaProject) object;
84            IWorkbenchAdapter wadap = 
85                (IWorkbenchAdapter) mproj.getProject().getAdapter(IWorkbenchAdapter.class);
86            return wadap.getImageDescriptor(mproj.getProject());
87           
88        }
89        else if (object instanceof IModelicaClass)
90        {
91            String imgTag = null;
92
93            try
94            {
95                switch (((IModelicaClass)object).getRestrictionType())
96                {
97                case PACKAGE:
98                    imgTag = ModelicaImages.IMG_OBJS_PACKAGE;
99                    break;
100                case CLASS:
101                    imgTag = ModelicaImages.IMG_OBJS_CLASS;
102                    break;
103                case MODEL:
104                    imgTag = ModelicaImages.IMG_OBJS_MODEL;
105                    break;
106                case FUNCTION:
107                    imgTag = ModelicaImages.IMG_OBJS_FUNCTION;
108                    break;
109                case RECORD:
110                    imgTag = ModelicaImages.IMG_OBJS_RECORD;
111                    break;
112                case CONNECTOR:
113                    imgTag = ModelicaImages.IMG_OBJS_CONNECTOR;
114                    break;
115                case BLOCK:
116                    imgTag = ModelicaImages.IMG_OBJS_BLOCK;
117                    break;
118                case TYPE:
119                    imgTag = ModelicaImages.IMG_OBJS_TYPE;
120                    break;
121                default:
122                    ErrorManager.logBug(Plugin.getSymbolicName(),
123                            "IModelicaClass object of unexpected restriction " + 
124                            "type " + 
125                            ((IModelicaClass)object).getRestrictionType() +
126                            " encountered.");
127                    imgTag = "";
128                }
129            }
130            catch (CompilerException e)
131            {
132                ErrorManager.logError(e);
133                /*
134                 * hmm, let the class icon be default
135                 * 'i don't know your type' image
136                 */ 
137                imgTag = ModelicaImages.IMG_OBJS_CLASS;
138            }
139            return ModelicaImages.getImageDescriptor(imgTag);
140        }
141        else if (object instanceof IModelicaComponent)
142        {
143            switch (((IModelicaComponent)object).getVisbility())
144            {
145            case PUBLIC:
146                return ModelicaImages.getImageDescriptor
147                    (ModelicaImages.IMG_OBJS_PUBLIC_COMPONENT);
148            case PROTECTED:
149                return ModelicaImages.getImageDescriptor
150                    (ModelicaImages.IMG_OBJS_PROTECTED_COMPONENT);
151            }
152        }
153        else if (object instanceof IModelicaFile)
154        {
155            return ModelicaImages.getImageDescriptor(ModelicaImages.IMG_OBJS_MO_FILE);
156        }
157        else if (object instanceof IModelicaFolder)
158        {
159            return PlatformUI.getWorkbench().getSharedImages().
160            getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER);
161        }
162        else if (object instanceof SystemLibrary)
163        {
164            return ModelicaImages.getImageDescriptor(ModelicaImages.IMG_OBJS_LIBRARY);
165        }
166       
167       
168        return super.getImageDescriptor(object);
169    }
170
171}
Note: See TracBrowser for help on using the repository browser.