source: trunk/org.modelica.mdt/src/org/modelica/mdt/ui/ModelicaElementContentProvider.java @ 118

Last change on this file since 118 was 118, checked in by remar, 19 years ago
  • moved org.modelica.mdt.internal.corba to org.modelica.mdt.internal.omcproxy
  • made OMCProxy into a nicer interface to OMC
  • added lotsa try/catch around places to allow running. Should be dialogs/error log instead
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 */
41
42package org.modelica.mdt.ui;
43
44import java.util.List;
45
46import org.eclipse.core.resources.IContainer;
47import org.eclipse.core.resources.IFolder;
48import org.eclipse.core.resources.IProject;
49import org.eclipse.core.runtime.CoreException;
50import org.eclipse.jface.viewers.ITreeContentProvider;
51import org.eclipse.jface.viewers.Viewer;
52import org.modelica.mdt.MdtPlugin;
53import org.modelica.mdt.core.IModelicaProject;
54import org.modelica.mdt.core.IModelicaRoot;
55import org.modelica.mdt.core.IParent;
56import org.modelica.mdt.internal.core.SystemLibrary;
57import org.modelica.mdt.internal.omcproxy.InitializationException;
58
59/**
60 * @author Elmir Jagudin
61 *
62 */
63public class ModelicaElementContentProvider implements ITreeContentProvider
64{
65
66    public Object[] getElements(Object inputElement)
67    {
68        try
69        {
70            if (inputElement instanceof IModelicaRoot)
71            {
72                return ((IModelicaRoot)inputElement).getProjects();
73            }
74           
75        }
76        catch (CoreException e)
77        {
78            MdtPlugin.log(e);
79        }
80        return new Object[] {};
81    }
82   
83    public void dispose()
84    {
85    }
86
87    public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
88    {
89    }
90
91    public Object[] getChildren(Object parent)
92    {
93        if (parent instanceof IContainer)
94        {
95            try
96            {
97                return ((IContainer)parent).members();
98            }
99            catch (CoreException e)
100            {
101                MdtPlugin.log(e);
102            }
103        }
104        else if (parent instanceof IModelicaProject)
105        {
106            List<?> list = null;
107            try
108            {
109                list = ((IModelicaProject)parent).getRootFolder().getChildren();
110            }
111            catch (InitializationException e)
112            {
113                // TODO Auto-generated catch block
114                e.printStackTrace();
115            }
116
117            Object[] children = new Object[list.size()+1];
118            /*
119             * add as last element system library
120             */
121            list.toArray(children);
122            children[children.length-1] = new SystemLibrary();
123            return children; 
124        }
125        else if (parent instanceof IParent)
126        {
127            try
128            {
129                return ((IParent)parent).getChildren().toArray();
130            }
131            catch (InitializationException e)
132            {
133                // TODO Auto-generated catch block
134                e.printStackTrace();
135            }
136        }
137        return null;
138    }
139
140    public Object getParent(Object element)
141    {
142        return null;
143    }
144
145    public boolean hasChildren(Object element)
146    {
147        if (element instanceof IProject)
148        {
149            return ((IProject)element).isOpen();
150        }
151        else if (element instanceof IFolder)
152        {
153            return true;
154        }
155        else if (element instanceof IModelicaProject)
156        {
157            return ((IModelicaProject)element).getProject().isOpen();
158        }
159        else if (element instanceof IParent)
160        {
161            try 
162            {
163                return ((IParent)element).hasChildren();
164            } 
165            catch (CoreException e) 
166            {
167                // TODO Auto-generated catch block
168                e.printStackTrace();
169            } catch (InitializationException e)
170            {
171                // TODO Auto-generated catch block
172                e.printStackTrace();
173            }
174        }
175        return false;
176    }
177}
Note: See TracBrowser for help on using the repository browser.