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 | package org.modelica.mdt.ui; |
---|
42 | |
---|
43 | import org.eclipse.jface.resource.ImageDescriptor; |
---|
44 | import org.eclipse.ui.ISharedImages; |
---|
45 | import org.eclipse.ui.PlatformUI; |
---|
46 | import org.eclipse.ui.model.IWorkbenchAdapter; |
---|
47 | import org.eclipse.ui.model.WorkbenchAdapter; |
---|
48 | import org.modelica.mdt.core.IModelicaClass; |
---|
49 | import org.modelica.mdt.core.IModelicaElement; |
---|
50 | import org.modelica.mdt.core.IModelicaFile; |
---|
51 | import org.modelica.mdt.core.IModelicaFolder; |
---|
52 | import org.modelica.mdt.core.IModelicaPackage; |
---|
53 | import org.modelica.mdt.core.IModelicaProject; |
---|
54 | import org.modelica.mdt.core.ISystemLibrary; |
---|
55 | import 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 | |
---|
65 | public 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 | } |
---|