KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > widgets > entryeditor > OpenDefaultEditorAction


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.widgets.entryeditor;
22
23
24 import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
25 import org.apache.directory.ldapstudio.browser.common.actions.BrowserAction;
26 import org.apache.directory.ldapstudio.browser.common.actions.RenameAction;
27 import org.apache.directory.ldapstudio.browser.common.actions.proxy.EntryEditorActionProxy;
28 import org.eclipse.jface.resource.ImageDescriptor;
29 import org.eclipse.jface.viewers.TreeViewer;
30
31
32 /**
33  *
34  * The OpenBestEditorAction is used to edit a value with the default value editor.
35  * This is either the best value editor or in case of an RDN attribute the rename
36  * action is invoked.
37  *
38  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
39  * @version $Rev$, $Date$
40  */

41 public class OpenDefaultEditorAction extends BrowserAction
42 {
43
44     /** The best value editor proxy. */
45     private EntryEditorActionProxy bestValueEditorProxy;
46
47     /** The rename proxy. */
48     private EntryEditorActionProxy renameProxy;
49     
50
51     /**
52      * Creates a new instance of OpenDefaultEditorAction.
53      *
54      * @param viewer the viewer
55      * @param bestValueEditorProxy the best value editor proxy
56      * @param enableRenameAction true to enable rename action
57      */

58     public OpenDefaultEditorAction( TreeViewer viewer, EntryEditorActionProxy bestValueEditorProxy, boolean enableRenameAction )
59     {
60         this.bestValueEditorProxy = bestValueEditorProxy;
61         this.renameProxy = enableRenameAction ? new EntryEditorActionProxy( viewer, new RenameAction() ) : null;
62     }
63
64
65     /**
66      * {@inheritDoc}
67      */

68     public void dispose()
69     {
70         bestValueEditorProxy = null;
71         renameProxy = null;
72
73         super.dispose();
74     }
75     
76     
77     /**
78      * {@inheritDoc}
79      */

80     @Override JavaDoc
81     public String JavaDoc getCommandId()
82     {
83         return BrowserCommonConstants.ACTION_ID_EDIT_VALUE;
84     }
85     
86     
87     /**
88      * {@inheritDoc}
89      */

90     @Override JavaDoc
91     public ImageDescriptor getImageDescriptor()
92     {
93         if ( bestValueEditorProxy != null )
94         {
95             return bestValueEditorProxy.getImageDescriptor();
96         }
97         else if ( renameProxy != null )
98         {
99             return renameProxy.getImageDescriptor();
100         }
101         else
102         {
103             return null;
104         }
105     }
106     
107     
108     /**
109      * {@inheritDoc}
110      */

111     @Override JavaDoc
112     public String JavaDoc getText()
113     {
114         return "Edit Value";
115     }
116     
117     
118     /**
119      * {@inheritDoc}
120      */

121     @Override JavaDoc
122     public boolean isEnabled()
123     {
124 // // update proxy selections
125
// if ( bestValueEditorProxy != null )
126
// {
127
// if ( this.currentSelectionChangedEvent != null )
128
// {
129
// this.valueEditorProxy.selectionChanged( currentSelectionChangedEvent );
130
// }
131
// this.valueEditorProxy.updateEnabledState();
132
// }
133
// if ( this.renameProxy != null )
134
// {
135
// if ( this.currentSelectionChangedEvent != null )
136
// {
137
// this.renameProxy.selectionChanged( currentSelectionChangedEvent );
138
// }
139
// this.renameProxy.updateAction();
140
// }
141

142       if ( bestValueEditorProxy != null && renameProxy != null )
143       {
144           return bestValueEditorProxy.isEnabled() || renameProxy.isEnabled();
145       }
146       else if ( renameProxy != null )
147       {
148           return renameProxy.isEnabled();
149       }
150       else if ( bestValueEditorProxy != null )
151       {
152           return bestValueEditorProxy.isEnabled();
153       }
154       else
155       {
156           return false;
157       }
158     }
159     
160     
161     /**
162      * {@inheritDoc}
163      */

164     @Override JavaDoc
165     public void run()
166     {
167       if ( bestValueEditorProxy != null && bestValueEditorProxy.isEnabled() )
168       {
169           bestValueEditorProxy.run();
170       }
171       else if ( renameProxy != null && renameProxy.isEnabled() )
172       {
173           renameProxy.run();
174       }
175         
176     }
177
178 }
179
Popular Tags