1 20 21 package org.apache.directory.ldapstudio.browser.common.actions; 22 23 24 import java.util.ArrayList ; 25 import java.util.Arrays ; 26 import java.util.List ; 27 28 import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator; 29 import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants; 30 import org.apache.directory.ldapstudio.browser.core.jobs.InitializeAttributesJob; 31 import org.apache.directory.ldapstudio.browser.core.jobs.InitializeChildrenJob; 32 import org.apache.directory.ldapstudio.browser.core.jobs.SearchJob; 33 import org.apache.directory.ldapstudio.browser.core.model.IEntry; 34 import org.apache.directory.ldapstudio.browser.core.model.ISearch; 35 import org.eclipse.jface.resource.ImageDescriptor; 36 37 38 44 public class RefreshAction extends BrowserAction 45 { 46 49 public RefreshAction() 50 { 51 super(); 52 } 53 54 55 58 public String getText() 59 { 60 IEntry[] entries = getEntries(); 61 ISearch[] searches = getSearches(); 62 IEntry entryInput = getEntryInput(); 63 ISearch searchInput = getSearchInput(); 64 65 if ( entries.length > 0 && searches.length == 0 && entryInput == null && searchInput == null ) 66 { 67 return "Reload Attributes and Children"; 68 } 69 else if ( searches.length > 0 && entries.length == 0 && entryInput == null && searchInput == null ) 70 { 71 boolean searchAgain = true; 72 for ( int i = 0; i < searches.length; i++ ) 73 { 74 if ( searches[i].getSearchResults() == null ) 75 { 76 searchAgain = false; 77 break; 78 } 79 } 80 if ( searchAgain ) 81 { 82 return "Search Again"; 83 } 84 else 85 { 86 return searches.length == 1 ? "Perform Search" : "Perform Searches"; 87 } 88 } 89 else if ( entryInput != null && searches.length == 0 && entries.length == 0 && searchInput == null ) 90 { 91 return "Reload Attributes"; 92 } 93 else if ( searchInput != null && searches.length == 0 && entryInput == null ) 94 { 95 return searchInput.getSearchResults() == null ? "Perform Search" : "Search Again"; 96 } 97 else 98 { 99 return "Refresh"; 100 } 101 } 102 103 104 107 public ImageDescriptor getImageDescriptor() 108 { 109 return BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_REFRESH ); 110 } 111 112 113 116 public String getCommandId() 117 { 118 return "org.eclipse.ui.file.refresh"; 119 } 120 121 122 125 public void run() 126 { 127 IEntry[] entries = getEntries(); 128 ISearch[] searches = getSearches(); 129 IEntry entryInput = getEntryInput(); 130 ISearch searchInput = getSearchInput(); 131 boolean soa = BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean( 132 BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_OPERATIONAL_ATTRIBUTES ); 133 134 if ( entries.length > 0 ) 135 { 136 new InitializeAttributesJob( entries, soa ).execute(); 137 new InitializeChildrenJob( entries ).execute(); 138 } 139 if ( searches.length > 0 ) 140 { 141 new SearchJob( searches ).execute(); 142 } 143 144 if ( entryInput != null ) 145 { 146 new InitializeAttributesJob( new IEntry[] 147 { entryInput }, soa ).execute(); 148 } 149 if ( searchInput != null ) 150 { 151 new SearchJob( new ISearch[] 152 { searchInput } ).execute(); 153 } 154 } 155 156 157 160 public boolean isEnabled() 161 { 162 IEntry[] entries = getEntries(); 163 ISearch[] searches = getSearches(); 164 IEntry entryInput = getEntryInput(); 165 ISearch searchInput = getSearchInput(); 166 167 return entries.length > 0 || searches.length > 0 || entryInput != null || searchInput != null; 168 } 169 170 171 177 protected IEntry[] getEntries() 178 { 179 List <IEntry> entriesList = new ArrayList <IEntry>(); 180 entriesList.addAll( Arrays.asList( getSelectedEntries() ) ); 181 for ( int i = 0; i < getSelectedSearchResults().length; i++ ) 182 { 183 entriesList.add( getSelectedSearchResults()[i].getEntry() ); 184 } 185 for ( int i = 0; i < getSelectedBookmarks().length; i++ ) 186 { 187 entriesList.add( getSelectedBookmarks()[i].getEntry() ); 188 } 189 return ( IEntry[] ) entriesList.toArray( new IEntry[entriesList.size()] ); 190 } 191 192 193 199 protected ISearch[] getSearches() 200 { 201 return getSelectedSearches(); 202 } 203 204 205 211 private IEntry getEntryInput() 212 { 213 if ( getInput() != null && getInput() instanceof IEntry ) 214 { 215 return ( IEntry ) getInput(); 216 } 217 else 218 { 219 return null; 220 } 221 } 222 223 224 230 private ISearch getSearchInput() 231 { 232 if ( getInput() != null && getInput() instanceof ISearch ) 233 { 234 return ( ISearch ) getInput(); 235 } 236 else 237 { 238 return null; 239 } 240 } 241 } 242 | Popular Tags |