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

Last change on this file since 107 was 96, checked in by boris, 19 years ago
  • system library element added to projects view tree
File size: 4.6 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 */
41package org.modelica.mdt.ui;
42
43import org.eclipse.jface.resource.ImageDescriptor;
44import org.eclipse.ui.ISharedImages;
45import org.eclipse.ui.PlatformUI;
46import org.eclipse.ui.model.IWorkbenchAdapter;
47import org.eclipse.ui.model.WorkbenchAdapter;
48import org.modelica.mdt.core.IModelicaClass;
49import org.modelica.mdt.core.IModelicaElement;
50import org.modelica.mdt.core.IModelicaFile;
51import org.modelica.mdt.core.IModelicaFolder;
52import org.modelica.mdt.core.IModelicaPackage;
53import org.modelica.mdt.core.IModelicaProject;
54import org.modelica.mdt.core.ISystemLibrary;
55import org.modelica.mdt.internal.core.ModelicaImages;
56
57/**
58 * @author Elmir Jagudin
59 *
60 * This class mapps modelica objects (Modelica packages, classes, etc) to icons and labels
61 * via IWorkbenchAdapter interface. This icon and lables are used in for example Modelica
62 * Projects view.
63 */
64
65public class ModelicaElementAdapter extends WorkbenchAdapter
66{
67
68    @Override
69    public String getLabel(Object object)
70    {
71        return ((IModelicaElement)object).getElementName();
72    }
73
74    @Override
75    public ImageDescriptor getImageDescriptor(Object object)
76    {
77        if (object instanceof IModelicaProject)
78        {
79            /*
80             * Isn't patterns beautifull ?
81             */
82            IModelicaProject mproj = (IModelicaProject) object;
83            IWorkbenchAdapter wadap = 
84                (IWorkbenchAdapter) mproj.getProject().getAdapter(IWorkbenchAdapter.class);
85            return wadap.getImageDescriptor(mproj.getProject());
86           
87        }
88        else if (object instanceof IModelicaPackage)
89        {
90            return ModelicaImages.getImageDescriptor(ModelicaImages.IMG_OBJS_PACKAGE);
91        }
92        else if (object instanceof IModelicaClass)
93        {
94            String imgTag;
95            switch (((IModelicaClass)object).getType())
96            {
97            case CLASS:
98                imgTag = ModelicaImages.IMG_OBJS_CLASS;
99                break;
100            case MODEL:
101                imgTag = ModelicaImages.IMG_OBJS_MODEL;
102                break;
103            case FUNCTION:
104                imgTag = ModelicaImages.IMG_OBJS_FUNCTION;
105                break;
106            case RECORD:
107                imgTag = ModelicaImages.IMG_OBJS_RECORD;
108                break;
109            case CONNECTOR:
110                imgTag = ModelicaImages.IMG_OBJS_CONNECTOR;
111                break;
112            case BLOCK:
113                imgTag = ModelicaImages.IMG_OBJS_BLOCK;
114                break;
115            case TYPE:
116                imgTag = ModelicaImages.IMG_OBJS_TYPE;
117                break;
118            default:
119                imgTag = "";
120            }
121            return ModelicaImages.getImageDescriptor(imgTag);
122        }
123        else if (object instanceof IModelicaFile)
124        {
125            return ModelicaImages.getImageDescriptor(ModelicaImages.IMG_OBJS_MO_FILE);
126        }
127        else if (object instanceof IModelicaFolder)
128        {
129            return PlatformUI.getWorkbench().getSharedImages().
130            getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER);
131        }
132        else if (object instanceof ISystemLibrary)
133        {
134            return ModelicaImages.getImageDescriptor(ModelicaImages.IMG_OBJS_LIBRARY);
135        }
136       
137        return super.getImageDescriptor(object);
138    }
139
140}
Note: See TracBrowser for help on using the repository browser.