KickJava   Java API By Example, From Geeks To Geeks.

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


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.core.model.IAttribute;
25 import org.apache.directory.ldapstudio.browser.core.utils.Utils;
26
27 import org.eclipse.core.runtime.IAdaptable;
28 import org.eclipse.jface.preference.PreferenceDialog;
29 import org.eclipse.jface.resource.ImageDescriptor;
30 import org.eclipse.ui.dialogs.PreferencesUtil;
31 import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
32
33
34 /**
35  * This Action opens the Property Dialog for a given object.
36  *
37  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
38  * @version $Rev$, $Date$
39  */

40 public class PropertiesAction extends BrowserAction
41 {
42     /**
43      * Creates a new instance of PropertiesAction.
44      */

45     public PropertiesAction()
46     {
47         super();
48     }
49
50
51     /**
52      * {@inheritDoc}
53      */

54     public String JavaDoc getText()
55     {
56         return "Properties";
57     }
58
59
60     /**
61      * {@inheritDoc}
62      */

63     public ImageDescriptor getImageDescriptor()
64     {
65         return null;
66     }
67
68
69     /**
70      * {@inheritDoc}
71      */

72     public String JavaDoc getCommandId()
73     {
74         return IWorkbenchActionDefinitionIds.PROPERTIES;
75     }
76
77
78     /**
79      * {@inheritDoc}
80      */

81     public boolean isEnabled()
82     {
83
84         return getSelectedConnections().length == 1
85             || getSelectedEntries().length + getSelectedSearchResults().length + getSelectedBookmarks().length
86                 + getSelectedSearches().length == 1 || getSelectedAttributes().length + getSelectedValues().length == 1
87             || ( getSelectedAttributeHierarchies().length == 1 && getSelectedAttributeHierarchies()[0].size() == 1 );
88
89     }
90
91
92     /**
93      * {@inheritDoc}
94      */

95     public void run()
96     {
97
98         IAdaptable element = null;
99         String JavaDoc pageId = null;
100         String JavaDoc title = null;
101
102         if ( getSelectedValues().length == 1 )
103         {
104             element = ( IAdaptable ) getSelectedValues()[0];
105             pageId = "org.apache.directory.ldapstudio.browser.ui.dialogs.properties.ValuePropertyPage";
106             title = getSelectedValues()[0].toString();
107         }
108         else if ( getSelectedAttributes().length == 1 )
109         {
110             element = ( IAdaptable ) getSelectedAttributes()[0];
111             pageId = "org.apache.directory.ldapstudio.browser.ui.dialogs.properties.AttributePropertyPage";
112             title = getSelectedAttributes()[0].toString();
113         }
114         else if ( getSelectedAttributeHierarchies().length == 1 )
115         {
116             IAttribute att = getSelectedAttributeHierarchies()[0].getAttribute();
117             element = att;
118             pageId = "org.apache.directory.ldapstudio.browser.ui.dialogs.properties.AttributePropertyPage";
119             title = att.toString();
120         }
121         else if ( getSelectedSearches().length == 1 )
122         {
123             element = ( IAdaptable ) getSelectedSearches()[0];
124             pageId = "org.apache.directory.ldapstudio.browser.ui.dialogs.properties.SearchPropertyPage";
125             title = getSelectedSearches()[0].getName();
126         }
127         else if ( getSelectedBookmarks().length == 1 )
128         {
129             element = ( IAdaptable ) getSelectedBookmarks()[0];
130             pageId = "org.apache.directory.ldapstudio.browser.ui.dialogs.properties.BookmarkPropertyPage";
131             title = getSelectedBookmarks()[0].getName();
132         }
133         else if ( getSelectedEntries().length == 1 )
134         {
135             element = ( IAdaptable ) getSelectedEntries()[0];
136             pageId = "org.apache.directory.ldapstudio.browser.ui.dialogs.properties.EntryPropertyPage";
137             title = getSelectedEntries()[0].getDn().toString();
138         }
139         else if ( getSelectedSearchResults().length == 1 )
140         {
141             element = ( IAdaptable ) getSelectedSearchResults()[0];
142             pageId = "org.apache.directory.ldapstudio.browser.ui.dialogs.properties.EntryPropertyPage";
143             title = getSelectedSearchResults()[0].getDn().toString();
144         }
145         else if ( getSelectedConnections().length == 1 )
146         {
147             element = ( IAdaptable ) getSelectedConnections()[0];
148             pageId = "org.apache.directory.ldapstudio.browser.ui.dialogs.properties.ConnectionPropertyPage";
149             title = getSelectedConnections()[0].getName();
150         }
151
152         if ( element != null )
153         {
154             PreferenceDialog dialog = PreferencesUtil.createPropertyDialogOn( getShell(), element, pageId, null, null );
155             if ( dialog != null )
156                 title = Utils.shorten( title, 30 );
157             dialog.getShell().setText( "Properties for '" + title + "'" );
158             dialog.open();
159
160         }
161     }
162 }
163
Popular Tags