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

Last change on this file since 120 was 120, checked in by boris, 19 years ago
  • implemented the backend part for tree view browsing of file system based modelica packages
  • regressions test added for testing hierarchy of file system based packages
  • some API changes
  • general cleanups
File size: 4.8 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.omcproxy.InitializationException;
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 = null;
95           
96           
97            try {
98                switch (((IModelicaClass)object).getType())
99                {
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                    imgTag = "";
123                }
124            } catch (InitializationException e) {
125                // TODO Proper error handling here!
126                e.printStackTrace();
127            }
128            return ModelicaImages.getImageDescriptor(imgTag);
129        }
130        else if (object instanceof IModelicaFile)
131        {
132            return ModelicaImages.getImageDescriptor(ModelicaImages.IMG_OBJS_MO_FILE);
133        }
134        else if (object instanceof IModelicaFolder)
135        {
136            return PlatformUI.getWorkbench().getSharedImages().
137            getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER);
138        }
139        else if (object instanceof ISystemLibrary)
140        {
141            return ModelicaImages.getImageDescriptor(ModelicaImages.IMG_OBJS_LIBRARY);
142        }
143       
144        return super.getImageDescriptor(object);
145    }
146
147}
Note: See TracBrowser for help on using the repository browser.