KickJava   Java API By Example, From Geeks To Geeks.

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


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.DeleteAction;
27 import org.apache.directory.ldapstudio.browser.common.actions.proxy.EntryEditorActionProxy;
28 import org.apache.directory.ldapstudio.browser.common.wizards.AttributeWizard;
29 import org.apache.directory.ldapstudio.browser.core.jobs.RenameValuesJob;
30 import org.apache.directory.ldapstudio.browser.core.model.IValue;
31 import org.eclipse.jface.dialogs.Dialog;
32 import org.eclipse.jface.resource.ImageDescriptor;
33 import org.eclipse.jface.viewers.Viewer;
34 import org.eclipse.jface.wizard.WizardDialog;
35 import org.eclipse.swt.widgets.Display;
36
37
38 /**
39  * This Action is used to edit an attribute description within the entry edtitor.
40  *
41  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
42  * @version $Rev$, $Date$
43  */

44 public class EditAttributeDescriptionAction extends BrowserAction
45 {
46
47     /** To avoid duplicate implementations of the isEnabled() code we use a delete action */
48     private EntryEditorActionProxy deleteActionProxy;
49
50
51     /**
52      * Creates a new instance of EditAttributeDescriptionAction.
53      *
54      * @param viewer the viewer
55      */

56     public EditAttributeDescriptionAction( Viewer viewer )
57     {
58         deleteActionProxy = new EntryEditorActionProxy( viewer, new DeleteAction() );
59     }
60
61
62     /**
63      * {@inheritDoc}
64      */

65     @Override JavaDoc
66     public String JavaDoc getCommandId()
67     {
68         return BrowserCommonConstants.ACTION_ID_EDIT_ATTRIBUTE_DESCRIPTION;
69     }
70
71
72     /**
73      * {@inheritDoc}
74      */

75     @Override JavaDoc
76     public ImageDescriptor getImageDescriptor()
77     {
78         return null;
79     }
80
81
82     /**
83      * {@inheritDoc}
84      */

85     @Override JavaDoc
86     public String JavaDoc getText()
87     {
88         return "Edit Attribute Description";
89     }
90
91
92     /**
93      * {@inheritDoc}
94      */

95     @Override JavaDoc
96     public boolean isEnabled()
97     {
98         return deleteActionProxy.getAction().isEnabled();
99     }
100
101
102     /**
103      * {@inheritDoc}
104      */

105     @Override JavaDoc
106     public void run()
107     {
108         if ( getSelectedAttributes().length == 1 )
109         {
110             renameValues( getSelectedAttributes()[0].getValues() );
111         }
112         else if ( getSelectedValues().length > 0 )
113         {
114             renameValues( getSelectedValues() );
115         }
116     }
117
118
119     /**
120      * Rename the given values.
121      *
122      * @param values the values
123      */

124     private void renameValues( final IValue[] values )
125     {
126         AttributeWizard wizard = new AttributeWizard( "Edit Attribute Description", true, false, values[0]
127             .getAttribute().getDescription(), values[0].getAttribute().getEntry() );
128         WizardDialog dialog = new WizardDialog( Display.getDefault().getActiveShell(), wizard );
129         dialog.setBlockOnOpen( true );
130         dialog.create();
131         if ( dialog.open() == Dialog.OK )
132         {
133             String JavaDoc newAttributeName = wizard.getAttributeDescription();
134             if ( newAttributeName != null && !"".equals( newAttributeName )
135                 && !newAttributeName.equals( values[0].getAttribute().getDescription() ) )
136             {
137                 new RenameValuesJob( values[0].getAttribute().getEntry(), values, newAttributeName ).execute();
138             }
139         }
140     }
141
142 }
143
Popular Tags