1 20 21 package org.apache.directory.ldapstudio.browser.ui.actions; 22 23 24 import java.util.LinkedHashSet ; 25 26 import org.apache.directory.ldapstudio.browser.common.actions.BrowserAction; 27 import org.apache.directory.ldapstudio.browser.common.dialogs.MoveEntriesDialog; 28 import org.apache.directory.ldapstudio.browser.core.internal.model.RootDSE; 29 import org.apache.directory.ldapstudio.browser.core.jobs.MoveEntriesJob; 30 import org.apache.directory.ldapstudio.browser.core.model.DN; 31 import org.apache.directory.ldapstudio.browser.core.model.IBookmark; 32 import org.apache.directory.ldapstudio.browser.core.model.IEntry; 33 import org.apache.directory.ldapstudio.browser.core.model.ISearch; 34 import org.eclipse.jface.dialogs.Dialog; 35 import org.eclipse.jface.resource.ImageDescriptor; 36 import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds; 37 38 39 45 public class MoveAction extends BrowserAction 46 { 47 50 public MoveAction() 51 { 52 super(); 53 } 54 55 56 59 public String getText() 60 { 61 62 IEntry[] entries = getEntries(); 63 ISearch[] searches = getSearches(); 64 IBookmark[] bookmarks = getBookmarks(); 65 66 if ( entries.length > 0 && searches.length == 0 && bookmarks.length == 0 ) 67 { 68 return entries.length == 1 ? "Move Entry..." : "Move Entries..."; 69 } 70 else 80 { 81 return "Move..."; 82 } 83 } 84 85 86 89 public ImageDescriptor getImageDescriptor() 90 { 91 return null; 92 } 93 94 95 98 public String getCommandId() 99 { 100 return IWorkbenchActionDefinitionIds.MOVE; 101 } 102 103 104 107 public void run() 108 { 109 110 IEntry[] entries = getEntries(); 111 ISearch[] searches = getSearches(); 112 IBookmark[] bookmarks = getBookmarks(); 113 114 if ( entries.length > 0 && searches.length == 0 && bookmarks.length == 0 ) 115 { 116 moveEntries( entries ); 117 } 118 else if ( searches.length > 0 && entries.length == 0 && bookmarks.length == 0 ) 119 { 120 } 122 else if ( bookmarks.length > 0 && entries.length == 0 && searches.length == 0 ) 123 { 124 } 126 } 127 128 129 132 public boolean isEnabled() 133 { 134 135 try 136 { 137 IEntry[] entries = getEntries(); 138 ISearch[] searches = getSearches(); 139 IBookmark[] bookmarks = getBookmarks(); 140 141 return entries.length > 0 && searches.length == 0 && bookmarks.length == 0; 142 143 } 144 catch ( Exception e ) 145 { 146 return false; 147 } 148 } 149 150 151 157 protected IEntry[] getEntries() 158 { 159 if ( getSelectedConnections().length + getSelectedBookmarks().length + getSelectedSearches().length 160 + getSelectedAttributes().length + getSelectedValues().length == 0 161 && getSelectedEntries().length + getSelectedSearchResults().length > 0 ) 162 { 163 LinkedHashSet <IEntry> entriesSet = new LinkedHashSet <IEntry>(); 164 for ( int i = 0; i < getSelectedEntries().length; i++ ) 165 { 166 entriesSet.add( getSelectedEntries()[i] ); 167 } 168 for ( int i = 0; i < this.getSelectedSearchResults().length; i++ ) 169 { 170 entriesSet.add( this.getSelectedSearchResults()[i].getEntry() ); 171 } 172 IEntry[] entries = ( IEntry[] ) entriesSet.toArray( new IEntry[entriesSet.size()] ); 173 for ( int i = 0; i < entries.length; i++ ) 174 { 175 if ( entries[i] == null || entries[i] instanceof RootDSE ) 176 { 177 return new IEntry[0]; 178 } 179 } 180 return entries; 181 } 182 else 183 { 184 return new IEntry[0]; 185 } 186 } 187 188 189 195 protected void moveEntries( final IEntry[] entries ) 196 { 197 MoveEntriesDialog moveDialog = new MoveEntriesDialog( getShell(), entries ); 198 if ( moveDialog.open() == Dialog.OK ) 199 { 200 DN newParentDn = moveDialog.getParentDn(); 201 if ( newParentDn != null ) 202 { 203 IEntry newParentEntry = entries[0].getConnection().getEntryFromCache( newParentDn ); 204 if ( newParentEntry != null ) 205 { 206 new MoveEntriesJob( entries, newParentEntry ).execute(); 207 } 208 } 209 } 210 } 211 212 213 219 protected ISearch[] getSearches() 220 { 221 if ( getSelectedSearches().length == 1 ) 222 { 223 return getSelectedSearches(); 224 } 225 else 226 { 227 return new ISearch[0]; 228 } 229 } 230 231 232 238 protected IBookmark[] getBookmarks() 239 { 240 if ( getSelectedBookmarks().length == 1 ) 241 { 242 return getSelectedBookmarks(); 243 } 244 else 245 { 246 return new IBookmark[0]; 247 } 248 } 249 } 250 | Popular Tags |