1 20 21 package org.apache.directory.ldapstudio.browser.ui.actions; 22 23 24 import org.apache.directory.ldapstudio.browser.common.actions.BrowserAction; 25 import org.apache.directory.ldapstudio.browser.common.jobs.RunnableContextJobAdapter; 26 import org.apache.directory.ldapstudio.browser.core.jobs.ReadEntryJob; 27 import org.apache.directory.ldapstudio.browser.core.model.DN; 28 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 29 import org.apache.directory.ldapstudio.browser.core.model.IEntry; 30 import org.apache.directory.ldapstudio.browser.ui.views.browser.BrowserView; 31 32 import org.eclipse.ui.IViewPart; 33 import org.eclipse.ui.IWorkbenchPage; 34 import org.eclipse.ui.PartInitException; 35 import org.eclipse.ui.PlatformUI; 36 37 38 44 public abstract class LocateInDitAction extends BrowserAction 45 { 46 49 public final void run() 50 { 51 ConnectionAndDn connectionAndDn = getConnectionAndDn(); 52 if ( connectionAndDn != null ) 53 { 54 IConnection connection = connectionAndDn.connection; 55 DN dn = connectionAndDn.dn; 56 57 IEntry entry = connection.getEntryFromCache( dn ); 58 if ( entry == null ) 59 { 60 ReadEntryJob job = new ReadEntryJob( connection, dn ); 61 RunnableContextJobAdapter.execute( job ); 62 entry = job.getReadEntry(); 63 } 64 65 if ( entry != null ) 66 { 67 String targetId = BrowserView.getId(); 68 IViewPart targetView = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView( 69 targetId ); 70 if ( targetView == null ) 71 { 72 try 73 { 74 targetView = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView( 75 targetId, null, IWorkbenchPage.VIEW_ACTIVATE ); 76 } 77 catch ( PartInitException e ) 78 { 79 } 80 } 81 if ( targetView != null && targetView instanceof BrowserView ) 82 { 83 ( ( BrowserView ) targetView ).select( entry ); 84 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().activate( targetView ); 85 } 86 } 87 } 88 } 89 90 91 94 public String getCommandId() 95 { 96 return "org.apache.directory.ldapstudio.browser.action.locateInDit"; 97 } 98 99 100 103 public final boolean isEnabled() 104 { 105 return getConnectionAndDn() != null; 106 } 107 108 109 114 protected abstract ConnectionAndDn getConnectionAndDn(); 115 116 117 123 protected class ConnectionAndDn 124 { 125 126 private IConnection connection; 127 128 129 private DN dn; 130 131 132 138 protected ConnectionAndDn( IConnection connection, DN dn ) 139 { 140 this.connection = connection; 141 this.dn = dn; 142 } 143 } 144 } 145 | Popular Tags |