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

Last change on this file since 92 was 92, checked in by boris, 19 years ago
  • modelica file and modelica folder wrappers added
  • interface for quering subpackages/classes/folders etc changed to use List instead of arrays
File size: 3.7 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 org.eclipse.core.resources.IContainer;
45import org.eclipse.core.resources.IFolder;
46import org.eclipse.core.resources.IProject;
47import org.eclipse.core.runtime.CoreException;
48import org.eclipse.jface.viewers.ITreeContentProvider;
49import org.eclipse.jface.viewers.Viewer;
50import org.modelica.mdt.MdtPlugin;
51import org.modelica.mdt.core.IModelicaProject;
52import org.modelica.mdt.core.IModelicaRoot;
53import org.modelica.mdt.core.IParent;
54
55/**
56 * @author Elmir Jagudin
57 *
58 */
59public class ModelicaElementContentProvider implements ITreeContentProvider
60{
61
62    public Object[] getElements(Object inputElement)
63    {
64        try
65        {
66            if (inputElement instanceof IModelicaRoot)
67            {
68                return ((IModelicaRoot)inputElement).getProjects();
69            }
70           
71        }
72        catch (CoreException e)
73        {
74            MdtPlugin.log(e);
75        }
76        return new Object[] {};
77    }
78   
79    public void dispose()
80    {
81    }
82
83    public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
84    {
85    }
86
87    public Object[] getChildren(Object parent)
88    {
89        if (parent instanceof IContainer)
90        {
91            try
92            {
93                return ((IContainer)parent).members();
94            }
95            catch (CoreException e)
96            {
97                MdtPlugin.log(e);
98            }
99        }
100        else if (parent instanceof IModelicaProject)
101        {
102            return ((IModelicaProject)parent).getRootFolder().getChildren().toArray(); 
103        }
104        else if (parent instanceof IParent)
105        {
106            return ((IParent)parent).getChildren().toArray();
107        }
108        return null;
109    }
110
111    public Object getParent(Object element)
112    {
113        return null;
114    }
115
116    public boolean hasChildren(Object element)
117    {
118        if (element instanceof IProject)
119        {
120            return ((IProject)element).isOpen();
121        }
122        else if (element instanceof IFolder)
123        {
124            return true;
125        }
126        else if (element instanceof IModelicaProject)
127        {
128            return ((IModelicaProject)element).getProject().isOpen();
129        }
130        else if (element instanceof IParent)
131        {
132            return true;
133        }
134        return false;
135    }
136}
Note: See TracBrowser for help on using the repository browser.