下面列出了怎么用org.eclipse.ui.IWorkbench的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void run() {
IWorkbench workbench= JavaPlugin.getDefault().getWorkbench();
IWorkbenchWindow window= workbench.getActiveWorkbenchWindow();
IWorkbenchPage page= window.getActivePage();
IAdaptable input;
if (page != null)
input= page.getInput();
else
input= ResourcesPlugin.getWorkspace().getRoot();
try {
workbench.showPerspective(JavaUI.ID_PERSPECTIVE, window, input);
} catch (WorkbenchException e) {
ExceptionHandler.handle(e, window.getShell(),
ActionMessages.OpenJavaPerspectiveAction_dialog_title,
ActionMessages.OpenJavaPerspectiveAction_error_open_failed);
}
}
public boolean isEnabled() {
if (!handler.isEnabled()) {
return false;
}
// disable the command when editor is readonly.
IWorkbench workbench = PlatformUI.getWorkbench();
if (workbench == null) {
return false;
}
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
if (window == null) {
return false;
}
IWorkbenchPage activePage = window.getActivePage();
if (activePage == null) {
return false;
}
IEditorPart activeEditor = activePage.getActiveEditor();
if (activeEditor != null && activeEditor instanceof LocalWSDLEditor) {
LocalWSDLEditor wsdlEditor = (LocalWSDLEditor) activeEditor;
return !wsdlEditor.isEditorInputReadOnly();
}
return false;
}
public void earlyStartup() {
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
public void run() {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
if (window != null) {
IWorkbenchPage page = window.getActivePage();
if (page != null) {
IEditorPart part = page.getActiveEditor();
if (part != null) {
addListener(part);
}
}
window.getPartService().addPartListener(new PartListener());
}
workbench.addWindowListener(new WindowListener());
}
});
}
/**
* Opens the new window containing the new perspective
*
* @param perspectiveId
* new perspective
* @param input
* IAdaptable, or null if no input
* @return IWorkbenchWindow instance
*
*/
public static IWorkbenchWindow openPerspectiveInNewWindow(String perspectiveId, IAdaptable input) {
IWorkbench workbench = Activator.getDefault().getWorkbench();
IWorkbenchWindow window = null;
try {
// avoids flicking, from implementation above
window = workbench.openWorkbenchWindow(perspectiveId, input);
// show intro
if (InitialPerspective.ID.equals(perspectiveId) && workbench.getIntroManager().hasIntro()) {
// IIntroPart intro =
workbench.getIntroManager().showIntro(window, true);
}
} catch (WorkbenchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return window;
}
@Override
public void init(IWorkbench targetWorkbench, IStructuredSelection currentSelection) {
this.selection = currentSelection;
List<?> selectedResources = IDE.computeSelectedResources(currentSelection);
if (!selectedResources.isEmpty()) {
this.selection = new StructuredSelection(selectedResources);
}
setWindowTitle("AsciiDoc Specification Export");
setNeedsProgressMonitor(true);
configAdocPage = new SpecConfigAdocPage("Configuration Page");
processAdocPage = new SpecProcessPage("Process Page");
comparePage = new SpecComparePage("Compare Page", "Adoc");
summaryPage = new SpecExportCodeSummaryPage("Summary Page");
processOutputPage = new SpecProcessPage("Process Page");
taskGenAdoc = new TaskGenerateAdoc(jsDoc2SpecProcessor, resourceSetProvider, n4JSCore, selection,
configAdocPage, processAdocPage);
taskWriteFiles = new TaskWriteFiles(processOutputPage, taskGenAdoc);
addVisibilityListeners();
}
/**
* Returns the editor with the specified input. Returns null if there is no
* opened editor with that input. If restore is requested, the method finds and
* returns the editor even if it is not restored yet after a restart.
*
* @param input
* the editor input
* @param restore
* true if the editor should be restored
* @return an editor with input equals to <code>input</code>
*/
private static IEditorPart findEditor(IEditorInput input, boolean restore) {
final IWorkbench wb = PlatformUI.getWorkbench();
final IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage();
for (IEditorReference editorReference : activePage.getEditorReferences()) {
try {
IEditorInput editorInput = editorReference.getEditorInput();
if (editorInput.equals(input)) {
return editorReference.getEditor(restore);
}
} catch (PartInitException e) {
// do nothing
}
}
return null;
}
/**
* Returns the instance of the navigation view or NULL if there is# no such
* instance available.
*/
public static Navigator getInstance() {
IWorkbench workbench = PlatformUI.getWorkbench();
if (workbench == null)
return null;
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
if (window == null)
return null;
IWorkbenchPage page = window.getActivePage();
if (page == null)
return null;
IViewPart part = page.findView(ID);
if (part instanceof Navigator)
return (Navigator) part;
return null;
}
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbench workbench = PlatformUI.getWorkbench();
IBindingService bindingService = (IBindingService) workbench.getService(IBindingService.class);
BindingService service = (BindingService) bindingService;
ArrayList<Binding> lstBinding = new ArrayList<Binding>(Arrays.asList(bindingService.getBindings()));
List<String> lstRemove = Constants.lstRemove;
Iterator<Binding> it = lstBinding.iterator();
while (it.hasNext()) {
Binding binding = it.next();
ParameterizedCommand pCommand = binding.getParameterizedCommand();
if (pCommand == null || lstRemove.contains(pCommand.getCommand().getId())) {
it.remove();
}
}
service.getKeyboard().openKeyAssistShell(lstBinding);
return null;
}
private static void executeCommand(IWorkbench workbench, String commandName, Map<String, Object> params) {
if (workbench == null) {
workbench = PlatformUI.getWorkbench();
}
// get command
ICommandService commandService = (ICommandService)workbench.getService(ICommandService.class);
Command command = commandService != null ? commandService.getCommand(commandName) : null;
// get handler service
//IBindingService bindingService = (IBindingService)workbench.getService(IBindingService.class);
//TriggerSequence[] triggerSequenceArray = bindingService.getActiveBindingsFor("de.anbos.eclipse.easyshell.plugin.commands.open");
IHandlerService handlerService = (IHandlerService)workbench.getService(IHandlerService.class);
if (command != null && handlerService != null) {
ParameterizedCommand paramCommand = ParameterizedCommand.generateCommand(command, params);
try {
handlerService.executeCommand(paramCommand, null);
} catch (Exception e) {
Activator.logError(Activator.getResourceString("easyshell.message.error.handlerservice.execution"), paramCommand.toString(), e, true);
}
}
}
/**
* Opens the internal help in the Studio's internal browser.
*
* @param url
* @return A boolean value indicating a successful operations or not.
*/
public static boolean openHelpInBrowser(String url)
{
IWorkbench workbench = PlatformUI.getWorkbench();
if (workbench != null)
{
IWorkbenchHelpSystem helpSystem = workbench.getHelpSystem();
URL resolvedURL = helpSystem.resolve(url, true);
if (resolvedURL != null)
{
return openInBroswer(resolvedURL, true, IWorkbenchBrowserSupport.AS_EDITOR
| IWorkbenchBrowserSupport.STATUS);
}
else
{
IdeLog.logError(UIPlugin.getDefault(), "Unable to resolve the Help URL for " + url); //$NON-NLS-1$
return false;
}
}
return false;
}
@Override
public void earlyStartup() {
final IWorkbench workbench = PlatformUI.getWorkbench();
GcpStatusMonitoringService service = workbench.getService(GcpStatusMonitoringService.class);
if (service != null) {
service.addStatusChangeListener(
result -> {
ICommandService commandService = workbench.getService(ICommandService.class);
if (commandService != null) {
commandService.refreshElements(
"com.google.cloud.tools.eclipse.ui.status.showGcpStatus", null);
}
});
}
}
public void init(IWorkbench workbench){
getPreferenceStore().setValue(Preferences.USR_DEFCASELABEL, Fall.getDefaultCaseLabel());
getPreferenceStore().setValue(Preferences.USR_DEFCASEREASON, Fall.getDefaultCaseReason());
getPreferenceStore().setValue(Preferences.USR_DEFLAW, Fall.getDefaultCaseLaw());
// read the sorting for this user form prefs, convert to LinkedList for editing
String topItemsSortingStr = CoreHub.userCfg.get(Preferences.USR_TOPITEMSSORTING, "");
String[] topItemsSorting = topItemsSortingStr.split(PREFSDELIMITER_REGEX);
topItemsLinkedList = new LinkedList<String>(Arrays.asList(topItemsSorting));
}
private void removePartListener()
{
IWorkbench workbench = null;
try
{
workbench = PlatformUI.getWorkbench();
}
catch (Exception e)
{
// ignore, may be running headless, like in tests
}
if (workbench != null)
{
IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
IPartService partService;
for (IWorkbenchWindow window : windows)
{
partService = window.getPartService();
if (partService != null)
{
partService.removePartListener(fPartListener);
}
window.removePerspectiveListener(fPerspectiveListener);
}
PlatformUI.getWorkbench().removeWindowListener(fWindowListener);
}
}
@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
setWindowTitle(M.ILCDNetworkExport);
setDefaultPageImageDescriptor(RcpActivator.imageDescriptorFromPlugin(
RcpActivator.PLUGIN_ID, "/icons/network_wiz.png"));
setNeedsProgressMonitor(true);
selectionPage = new ExportWizardPage();
}
@Before
public void setUp() {
evaluationService = mock( IEvaluationService.class );
workbench = mock( IWorkbench.class );
when( workbench.getService( IEvaluationService.class ) ).thenReturn( evaluationService );
preferences = new WorkspaceScopePreferences( new PreferenceStore() );
action = new CloseJUnitStatusAction( workbench, preferences );
}
/**
* This just records the information.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void init ( IWorkbench workbench, IStructuredSelection selection )
{
this.workbench = workbench;
this.selection = selection;
setWindowTitle ( SecurityEditorPlugin.INSTANCE.getString ( "_UI_Wizard_label" ) ); //$NON-NLS-1$
setDefaultPageImageDescriptor ( ExtendedImageRegistry.INSTANCE.getImageDescriptor ( SecurityEditorPlugin.INSTANCE.getImage ( "full/wizban/NewSecurity" ) ) ); //$NON-NLS-1$
}
/**
* @return IWorkbenchPage
*/
public static IWorkbenchPage getDefaultPage() {
final IWorkbench bench = PlatformUI.getWorkbench();
if (bench==null) return null;
final IWorkbenchWindow[] windows = bench.getWorkbenchWindows();
if (windows==null) return null;
return windows[0].getActivePage();
}
@Before
public final void checkNotRunninginUiThread () {
final IWorkbench workbench = PlatformUI.getWorkbench();
if (workbench.getDisplay().getThread() == Thread.currentThread()) {
Assert.fail("This test MUST NOT RUN in SWT's UI thread. Please check the 'Run in UI thread' option of your launch config or build configuration!");
}
}
@Override
public void stop() {
if (!PlatformUI.isWorkbenchRunning())
return;
final IWorkbench workbench = PlatformUI.getWorkbench();
final Display display = workbench.getDisplay();
display.syncExec(new Runnable() {
@Override
public void run() {
if (!display.isDisposed())
workbench.close();
}
});
}
/**
* This just records the information.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void init(IWorkbench workbench, IStructuredSelection selection) {
this.workbench = workbench;
this.selection = selection;
setWindowTitle(BeansEditorPlugin.INSTANCE.getString("_UI_Wizard_label"));
setDefaultPageImageDescriptor(ExtendedImageRegistry.INSTANCE.getImageDescriptor(BeansEditorPlugin.INSTANCE.getImage("full/wizban/NewBeans")));
}
/**
* This just records the information.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void init ( IWorkbench workbench, IStructuredSelection selection )
{
this.workbench = workbench;
this.selection = selection;
setWindowTitle ( GlobalizeEditorPlugin.INSTANCE.getString ( "_UI_Wizard_label" ) ); //$NON-NLS-1$
setDefaultPageImageDescriptor ( ExtendedImageRegistry.INSTANCE.getImageDescriptor ( GlobalizeEditorPlugin.INSTANCE.getImage ( "full/wizban/NewGlobalize" ) ) ); //$NON-NLS-1$
}
@Override
public void stop() {
final IWorkbench workbench = PlatformUI.getWorkbench();
if ( workbench == null ) { return; }
final Display display = workbench.getDisplay();
display.syncExec(() -> {
if ( !display.isDisposed() ) {
workbench.close();
}
});
}
/**
* Creates a run in debug mode for the debug editor
*/
public void launchEditorInDebug() {
final IWorkbench workBench = PydevPlugin.getDefault().getWorkbench();
Display display = workBench.getDisplay();
// Make sure to run the UI thread.
display.syncExec(new Runnable() {
@Override
public void run() {
JythonLaunchShortcut launchShortcut = new JythonLaunchShortcut();
launchShortcut.launch(debugEditor, "debug");
}
});
}
public void dispose()
{
IWorkbench workbench = null;
try
{
workbench = PlatformUI.getWorkbench();
}
catch (Exception e)
{
// ignore
}
if (workbench != null)
{
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
if (window != null)
{
IWorkbenchPage page = window.getActivePage();
if (page != null)
{
page.removePartListener(this);
}
}
}
if (baseNames != null)
{
baseNames.clear();
baseNames = null;
}
}
/**
* Open the specified file in the editor.
*
* @param workbench the active workbench
* @param file the file to open
*/
public static IEditorPart openInEditor(IWorkbench workbench, IFile file) {
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
if (window != null && file != null) {
IWorkbenchPage page = window.getActivePage();
try {
return IDE.openEditor(page, file, true);
} catch (PartInitException ex) {
// ignore; we don't have to open the file
}
}
return null;
}
@Override
public void init(IWorkbench workbench){
setPreferenceStore(new SettingsPreferenceStore(CoreHub.globalCfg));
setMessage("Globale Befunde Einstellungen");
// initialize the model
if (FindingsServiceComponent.getService() != null) {
FindingsServiceComponent.getService().findById("", IObservation.class);
} else {
getLogger().warn("FindingsService is null - not found.");
setErrorMessage("Befunde Service konnte nicht geladen werden.");
}
}
@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
fSelection = selection;
setWindowTitle(Messages.ImportTraceWizard_DialogTitle);
setDefaultPageImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, ICON_PATH));
setNeedsProgressMonitor(true);
}
@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
setWindowTitle(Messages.DotnetExportWizard_exportProject);
Iterator<Object> selectionIterator = selection.iterator();
IFile projectFile = null;
while (selectionIterator.hasNext() && projectFile == null) {
IResource resource = (IResource) selectionIterator.next();
projectFile = getProjectFile(resource.getProject());
}
wizardPage = new DotnetExportWizardPage(projectFile);
}
/**
* Convenience method for getting the current shell.
*
* @return the shell
*/
public Shell getShell() {
if (shell != null) {
return shell;
} else {
IWorkbench workbench = SVNUIPlugin.getPlugin().getWorkbench();
if (workbench == null) return null;
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
if (window == null) return null;
return window.getShell();
}
}
@SuppressWarnings("restriction")
public void filterDupliteBind(){
IWorkbench workbench = PlatformUI.getWorkbench();
IBindingService bindingService = (IBindingService) workbench.getService(IBindingService.class);
BindingService service =(BindingService)bindingService;
BindingManager bindingManager = service.getBindingManager();
//service.getBindingManager().
Binding[] bindings = bindingManager.getBindings();
List<Binding> bindTemp = new ArrayList<Binding>();
List<String> ids = new ArrayList<String>();
for(Binding bind : bindings){
if(null ==bind){
continue;
}
ParameterizedCommand command = bind.getParameterizedCommand();
if(null == command){
continue;
}
String id = command.getId();
if(!ids.contains(id)){
ids.add(id);
bindTemp.add(bind);
}
}
bindingManager.setBindings(bindTemp.toArray(new Binding[ids.size()]));
}