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 | |
---|
42 | package org.modelica.mdt.ui; |
---|
43 | |
---|
44 | import org.eclipse.jface.resource.ImageDescriptor; |
---|
45 | import org.eclipse.ui.ISharedImages; |
---|
46 | import org.eclipse.ui.PlatformUI; |
---|
47 | import org.eclipse.ui.model.IWorkbenchAdapter; |
---|
48 | import org.eclipse.ui.model.WorkbenchAdapter; |
---|
49 | import org.modelica.mdt.core.IModelicaClass; |
---|
50 | import org.modelica.mdt.core.IModelicaElement; |
---|
51 | import org.modelica.mdt.core.IModelicaFile; |
---|
52 | import org.modelica.mdt.core.IModelicaFolder; |
---|
53 | import org.modelica.mdt.core.IModelicaProject; |
---|
54 | import org.modelica.mdt.core.IModelicaSourceFile; |
---|
55 | import org.modelica.mdt.ui.text.ModelicaLabelBuilder; |
---|
56 | |
---|
57 | /** |
---|
58 | * This class mapps modelica objects (Modelica packages, classes, etc) to icons |
---|
59 | * and labels via IWorkbenchAdapter interface. This icon and lables are used in |
---|
60 | * for example Modelica Projects view. |
---|
61 | * |
---|
62 | * @author Elmir Jagudin |
---|
63 | */ |
---|
64 | |
---|
65 | public class ModelicaElementAdapter extends WorkbenchAdapter |
---|
66 | { |
---|
67 | |
---|
68 | @Override |
---|
69 | public String getLabel(Object object) |
---|
70 | { |
---|
71 | if (object instanceof IModelicaClass) |
---|
72 | { |
---|
73 | IModelicaClass cls = ((IModelicaClass)object); |
---|
74 | try |
---|
75 | { |
---|
76 | return ModelicaLabelBuilder.constructSignature(cls); |
---|
77 | } |
---|
78 | catch(Exception e){ |
---|
79 | /* ignore */ |
---|
80 | } |
---|
81 | } |
---|
82 | return ((IModelicaElement)object).getElementName(); |
---|
83 | } |
---|
84 | |
---|
85 | @Override |
---|
86 | public ImageDescriptor getImageDescriptor(Object object) |
---|
87 | { |
---|
88 | if (object instanceof IModelicaProject) |
---|
89 | { |
---|
90 | /* |
---|
91 | * Aren't patterns beautiful ? |
---|
92 | */ |
---|
93 | IModelicaProject mproj = (IModelicaProject) object; |
---|
94 | IWorkbenchAdapter wadap = (IWorkbenchAdapter) mproj.getWrappedProject().getAdapter(IWorkbenchAdapter.class); |
---|
95 | return wadap.getImageDescriptor(mproj.getWrappedProject()); |
---|
96 | |
---|
97 | } |
---|
98 | /* |
---|
99 | * this check uggly must be done couse |
---|
100 | * IModelicaFile is superclass of IModelicaSourceFile |
---|
101 | */ |
---|
102 | else if ((object instanceof IModelicaFile) && !(object instanceof IModelicaSourceFile)) |
---|
103 | { |
---|
104 | /* |
---|
105 | * pattern beauty continued... |
---|
106 | */ |
---|
107 | IModelicaFile mfile = (IModelicaFile) object; |
---|
108 | IWorkbenchAdapter wadap = (IWorkbenchAdapter) mfile.getResource().getAdapter(IWorkbenchAdapter.class); |
---|
109 | return wadap.getImageDescriptor(mfile.getResource()); |
---|
110 | |
---|
111 | } |
---|
112 | else if (object instanceof IModelicaFolder) |
---|
113 | { |
---|
114 | return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER); |
---|
115 | } |
---|
116 | else if (object instanceof IModelicaElement) |
---|
117 | { |
---|
118 | String key = ModelicaImages.getModelicaElementKey((IModelicaElement)object); |
---|
119 | if (key != null) |
---|
120 | { |
---|
121 | return ModelicaImages.getImageDescriptor(key); |
---|
122 | } |
---|
123 | } |
---|
124 | |
---|
125 | return super.getImageDescriptor(object); |
---|
126 | } |
---|
127 | |
---|
128 | } |
---|