1 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 44 public class EditAttributeDescriptionAction extends BrowserAction 45 { 46 47 48 private EntryEditorActionProxy deleteActionProxy; 49 50 51 56 public EditAttributeDescriptionAction( Viewer viewer ) 57 { 58 deleteActionProxy = new EntryEditorActionProxy( viewer, new DeleteAction() ); 59 } 60 61 62 65 @Override 66 public String getCommandId() 67 { 68 return BrowserCommonConstants.ACTION_ID_EDIT_ATTRIBUTE_DESCRIPTION; 69 } 70 71 72 75 @Override 76 public ImageDescriptor getImageDescriptor() 77 { 78 return null; 79 } 80 81 82 85 @Override 86 public String getText() 87 { 88 return "Edit Attribute Description"; 89 } 90 91 92 95 @Override 96 public boolean isEnabled() 97 { 98 return deleteActionProxy.getAction().isEnabled(); 99 } 100 101 102 105 @Override 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 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 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 |