source: trunk/org.modelica.mdt.ui/src/org/modelica/mdt/ui/view/ModelicaProjectsViewDoubleClickAction.java

Last change on this file was 482, checked in by adrpo, 18 years ago

latest updates for 0.6.9

File size: 3.3 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.view;
43
44import org.eclipse.core.resources.IFolder;
45import org.eclipse.core.resources.IProject;
46import org.eclipse.jface.action.Action;
47import org.eclipse.jface.viewers.ISelection;
48import org.eclipse.jface.viewers.IStructuredSelection;
49import org.eclipse.jface.viewers.TreeViewer;
50import org.modelica.mdt.core.IModelicaFolder;
51import org.modelica.mdt.core.IModelicaClass;
52import org.modelica.mdt.core.IModelicaProject;
53import org.modelica.mdt.core.IStandardLibrary;
54
55/**
56 * Defines what happens when user double clicks on items in the
57 * projects view tree.
58 */
59
60public class ModelicaProjectsViewDoubleClickAction extends Action
61{
62    private TreeViewer viewer;
63   
64    ModelicaProjectsViewDoubleClickAction(TreeViewer viewer)
65    {
66        this.viewer = viewer;
67    }
68
69    @Override
70    public void run()
71    {
72        /* get the object that was double clicked */
73        ISelection selection = viewer.getSelection();
74        Object obj = ((IStructuredSelection)selection).getFirstElement();
75       
76        if (obj instanceof IModelicaProject ||
77            obj instanceof IModelicaFolder  ||
78            obj instanceof IModelicaClass   ||
79            obj instanceof IStandardLibrary ||
80            obj instanceof IProject         ||
81            obj instanceof IFolder          )
82                 
83        {
84            expandElement(obj);
85        }
86    }
87
88    /**
89     * expands element in the treeviewer, so that it's immediate children are
90     * visible
91     * @param element element to expand
92     */
93    private void expandElement(Object element) 
94    {
95        viewer.expandToLevel(element, 1);
96    }
97}
Note: See TracBrowser for help on using the repository browser.