1 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 40 public class PropertiesAction extends BrowserAction 41 { 42 45 public PropertiesAction() 46 { 47 super(); 48 } 49 50 51 54 public String getText() 55 { 56 return "Properties"; 57 } 58 59 60 63 public ImageDescriptor getImageDescriptor() 64 { 65 return null; 66 } 67 68 69 72 public String getCommandId() 73 { 74 return IWorkbenchActionDefinitionIds.PROPERTIES; 75 } 76 77 78 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 95 public void run() 96 { 97 98 IAdaptable element = null; 99 String pageId = null; 100 String 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 |