KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > actions > UpAction


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.browser.common.actions;
22
23
24 import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
25 import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
26 import org.apache.directory.ldapstudio.browser.common.widgets.browser.BrowserEntryPage;
27 import org.apache.directory.ldapstudio.browser.common.widgets.browser.BrowserSearchResultPage;
28 import org.apache.directory.ldapstudio.browser.core.model.IBookmark;
29 import org.apache.directory.ldapstudio.browser.core.model.IEntry;
30 import org.apache.directory.ldapstudio.browser.core.model.ISearch;
31 import org.apache.directory.ldapstudio.browser.core.model.ISearchResult;
32 import org.eclipse.jface.resource.ImageDescriptor;
33 import org.eclipse.jface.viewers.ITreeContentProvider;
34 import org.eclipse.jface.viewers.StructuredSelection;
35 import org.eclipse.jface.viewers.TreeViewer;
36
37
38 /**
39  * This class implements the Up Action.
40  *
41  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
42  * @version $Rev$, $Date$
43  */

44 public class UpAction extends BrowserAction
45 {
46     protected TreeViewer viewer;
47
48
49     /**
50      * Creates a new instance of UpAction.
51      *
52      * @param viewer
53      * the attached TreeViewer
54      */

55     public UpAction( TreeViewer viewer )
56     {
57         super();
58         this.viewer = viewer;
59     }
60
61
62     /**
63      * {@inheritDoc}
64      */

65     public String JavaDoc getText()
66     {
67         return "Up";
68     }
69
70
71     /**
72      * {@inheritDoc}
73      */

74     public ImageDescriptor getImageDescriptor()
75     {
76         return BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_PARENT );
77     }
78
79
80     /**
81      * {@inheritDoc}
82      */

83     public String JavaDoc getCommandId()
84     {
85         return "org.apache.directory.ldapstudio.browser.action.openSearchResult";
86     }
87
88
89     /**
90      * {@inheritDoc}
91      */

92     public void run()
93     {
94         IEntry[] entries = getSelectedEntries();
95         ISearch[] searches = getSelectedSearches();
96         ISearchResult[] searchResults = getSelectedSearchResults();
97         IBookmark[] bookmarks = getSelectedBookmarks();
98         BrowserEntryPage[] browserEntryPages = getSelectedBrowserEntryPages();
99         BrowserSearchResultPage[] browserSearchResultPages = getSelectedBrowserSearchResultPages();
100
101         Object JavaDoc selection = null;
102
103         if ( entries.length > 0 )
104         {
105             selection = entries[0];
106         }
107         else if ( searches.length > 0 )
108         {
109             selection = searches[0];
110         }
111         else if ( searchResults.length > 0 )
112         {
113             selection = searchResults[0];
114         }
115         else if ( bookmarks.length > 0 )
116         {
117             selection = bookmarks[0];
118         }
119         else if ( browserEntryPages.length > 0 )
120         {
121             selection = browserEntryPages[0];
122         }
123         else if ( browserSearchResultPages.length > 0 )
124         {
125             selection = browserSearchResultPages[0];
126         }
127
128         if ( selection != null )
129         {
130             ITreeContentProvider contentProvider = ( ITreeContentProvider ) viewer.getContentProvider();
131             Object JavaDoc newSelection = contentProvider.getParent( selection );
132             viewer.reveal( newSelection );
133             viewer.setSelection( new StructuredSelection( newSelection ), true );
134         }
135     }
136
137
138     /**
139      * {@inheritDoc}
140      */

141     public boolean isEnabled()
142     {
143         IEntry[] entries = getSelectedEntries();
144         ISearch[] searches = getSelectedSearches();
145         ISearchResult[] searchResults = getSelectedSearchResults();
146         IBookmark[] bookmarks = getSelectedBookmarks();
147         BrowserEntryPage[] browserEntryPages = getSelectedBrowserEntryPages();
148         BrowserSearchResultPage[] browserSearchResultPages = getSelectedBrowserSearchResultPages();
149
150         return entries.length > 0 || searches.length > 0 || searchResults.length > 0 || bookmarks.length > 0
151             || browserEntryPages.length > 0 || browserSearchResultPages.length > 0;
152     }
153 }
154
Popular Tags