KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Arrays JavaDoc;
25
26 import org.apache.directory.ldapstudio.valueeditors.IValueEditor;
27 import org.apache.directory.ldapstudio.valueeditors.ValueEditorManager;
28 import org.eclipse.jface.resource.ImageDescriptor;
29 import org.eclipse.jface.viewers.TreeViewer;
30
31
32 /**
33  * The OpenEditorAction is used to edit a value with a specific value editor.
34  *
35  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
36  * @version $Rev$, $Date$
37  */

38 public class OpenEditorAction extends AbstractOpenEditorAction
39 {
40
41     /** The specific value editor. */
42     private IValueEditor valueEditor;
43
44
45     /**
46      * Creates a new instance of OpenEditorAction.
47      *
48      * @param viewer the viewer
49      * @param actionGroup the action group
50      * @param valueEditorManager the value editor manager
51      * @param valueEditor the specific value editor
52      */

53     public OpenEditorAction( TreeViewer viewer, EntryEditorWidgetActionGroup actionGroup,
54         ValueEditorManager valueEditorManager, IValueEditor valueEditor )
55     {
56         super( viewer, actionGroup, valueEditorManager );
57         super.cellEditor = valueEditor.getCellEditor();
58         this.valueEditor = valueEditor;
59     }
60
61
62     /**
63      * Gets the value editor.
64      *
65      * @return the value editor
66      */

67     public IValueEditor getValueEditor()
68     {
69         return valueEditor;
70     }
71
72
73     /**
74      * {@inheritDoc}
75      */

76     public void run()
77     {
78         // ensure that the specific value editor is activated
79
valueEditorManager.setUserSelectedValueEditor( valueEditor );
80
81         super.run();
82     }
83
84
85     /**
86      * {@inheritDoc}
87      */

88     public void dispose()
89     {
90         this.valueEditor = null;
91         super.dispose();
92     }
93
94
95     /**
96      * {@inheritDoc}
97      */

98     @Override JavaDoc
99     public String JavaDoc getCommandId()
100     {
101         return null;
102     }
103
104
105     /**
106      * {@inheritDoc}
107      */

108     @Override JavaDoc
109     public ImageDescriptor getImageDescriptor()
110     {
111         return valueEditor.getValueEditorImageDescriptor();
112     }
113
114
115     /**
116      * {@inheritDoc}
117      */

118     @Override JavaDoc
119     public String JavaDoc getText()
120     {
121         return valueEditor.getValueEditorName();
122     }
123
124
125     /**
126      * {@inheritDoc}
127      */

128     @Override JavaDoc
129     public boolean isEnabled()
130     {
131         if ( getSelectedValues().length == 1
132             && getSelectedAttributes().length == 0
133             && viewer.getCellModifier().canModify( getSelectedValues()[0],
134                 EntryEditorWidgetTableMetadata.VALUE_COLUMN_NAME ) )
135         {
136             IValueEditor[] alternativeVps = valueEditorManager.getAlternativeValueEditors( getSelectedValues()[0] );
137             return Arrays.asList( alternativeVps ).contains( valueEditor )
138                 && valueEditor.getRawValue( getSelectedValues()[0] ) != null;
139         }
140         else
141         {
142             return false;
143         }
144     }
145
146 }
147
Popular Tags