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

Last change on this file since 88 was 88, checked in by boris, 19 years ago
  • you can now click in the plus thingie on the packages and see classes also
File size: 4.2 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;
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.core.IModelicaProject;
51import org.modelica.mdt.core.IModelicaRoot;
52import org.modelica.mdt.core.IParent;
53
54/**
55 * @author Elmir Jagudin
56 *
57 */
58public class ModelicaElementContentProvider implements ITreeContentProvider
59{
60
61    public Object[] getElements(Object inputElement)
62    {
63        try
64        {
65            if (inputElement instanceof IModelicaRoot)
66            {
67                return ((IModelicaRoot)inputElement).getProjects();
68            }
69           
70        }
71        catch (CoreException e)
72        {
73            MdtPlugin.log(e);
74        }
75        return new Object[] {};
76    }
77   
78    public void dispose()
79    {
80        System.out.println("disposed " + ModelicaElementContentProvider.class);
81    }
82
83    public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
84    {
85        System.out.println("input changed " + ModelicaElementContentProvider.class);
86    }
87
88    public Object[] getChildren(Object parent)
89    {
90        if (parent instanceof IContainer)
91        {
92            try
93            {
94                return ((IContainer)parent).members();
95            }
96            catch (CoreException e)
97            {
98                MdtPlugin.log(e);
99            }
100        }
101        else if (parent instanceof IModelicaProject)
102        {
103            IModelicaProject mp = (IModelicaProject)parent; 
104            return MdtPlugin.concatenate(mp.getPackages(), mp.getClasses());
105        }
106        else if (parent instanceof IParent)
107        {
108            System.out.println("get children of " + parent);
109            Object[] ch = ((IParent)parent).getChildren();
110            for (Object ob : ch)
111            {
112                System.out.println("got " + ob.getClass());
113            }
114           
115            return ch;
116            //return ((IParent)parent).getChildren();
117        }
118        return null;
119    }
120
121    public Object getParent(Object element)
122    {
123        System.out.println("get parent " + ModelicaElementContentProvider.class);
124        return null;
125    }
126
127    public boolean hasChildren(Object element)
128    {
129        if (element instanceof IProject)
130        {
131            return ((IProject)element).isOpen();
132        }
133        else if (element instanceof IFolder)
134        {
135            return true;
136        }
137        else if (element instanceof IModelicaProject)
138        {
139            return ((IModelicaProject)element).getProject().isOpen();
140        }
141        else if (element instanceof IParent)
142        {
143            return true;
144        }
145        return false;
146    }
147}
Note: See TracBrowser for help on using the repository browser.