org.eclipse.ui.part.ViewPart#org.eclipse.ui.IWorkbenchWindow源码实例Demo

下面列出了org.eclipse.ui.part.ViewPart#org.eclipse.ui.IWorkbenchWindow 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: tracecompass   文件: LamiChartViewerTest.java
/**
 * Reset the current perspective
 */
@After
public void resetPerspective() {
    SWTBotView viewBot = fViewBot;
    if (viewBot != null) {
        viewBot.close();
    }
    /*
     * UI Thread executes the reset perspective action, which opens a shell
     * to confirm the action. The current thread will click on the 'Yes'
     * button
     */
    Runnable runnable = () -> SWTBotUtils.anyButtonOf(fBot, "Yes", "Reset Perspective").click();
    UIThreadRunnable.asyncExec(() -> {
        IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getWorkbenchWindows()[0];
        ActionFactory.RESET_PERSPECTIVE.create(activeWorkbenchWindow).run();
    });
    runnable.run();
}
 
private static TypeHierarchyViewPart openInViewPart(IWorkbenchWindow window, IJavaElement[] input) {
	IWorkbenchPage page= window.getActivePage();
	try {
		TypeHierarchyViewPart result= (TypeHierarchyViewPart) page.findView(JavaUI.ID_TYPE_HIERARCHY);
		if (result != null) {
			result.clearNeededRefresh(); // avoid refresh of old hierarchy on 'becomes visible'
		}
		result= (TypeHierarchyViewPart) page.showView(JavaUI.ID_TYPE_HIERARCHY);
		result.setInputElements(input);
		return result;
	} catch (CoreException e) {
		ExceptionHandler.handle(e, window.getShell(),
			JavaUIMessages.OpenTypeHierarchyUtil_error_open_view, e.getMessage());
	}
	return null;
}
 
源代码3 项目: olca-app   文件: Navigator.java
/**
 * 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 {
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
		return null;
	}
	XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
	int[] selectedRows = xliffEditor.getSelectedRows();
	if (selectedRows.length < 1) {
		return null;
	}
	Arrays.sort(selectedRows);
	int firstSelectedRow = selectedRows[0];
	XLFHandler handler = xliffEditor.getXLFHandler();

	int row = handler.getPreviousUntranslatedSegmentIndex(firstSelectedRow);
	if (row != -1) {
		xliffEditor.jumpToRow(row);
	} else {
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
		MessageDialog.openWarning(window.getShell(), "", "不存在上一未翻译文本段。");
	}

	return null;
}
 
源代码5 项目: mat-calcite-plugin   文件: CalcitePane.java
private void makeActions() {
	executeQueryAction = new ExecuteQueryAction(this, null, false);
	explainQueryAction = new ExecuteQueryAction(this, null, true);
	commentLineAction = new CommentLineAction(queryString);
	IWorkbenchWindow window = this.getEditorSite().getWorkbenchWindow();
	ActionFactory.IWorkbenchAction globalAction = ActionFactory.COPY.create(window);
	this.copyQueryStringAction = new Action() {
		public void run() {
			CalcitePane.this.queryString.copy();
		}
	};
	this.copyQueryStringAction.setAccelerator(globalAction.getAccelerator());
	this.contentAssistAction = new Action() {
		@Override
		public void run() {
			queryViewer.doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS);
		}
	};
}
 
public Object execute(ExecutionEvent event) throws ExecutionException {
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
		return null;
	}
	XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
	int[] selectedRows = xliffEditor.getSelectedRows();
	if (selectedRows.length < 1) {
		return null;
	}
	Arrays.sort(selectedRows);
	int lastSelectedRow = selectedRows[selectedRows.length - 1];
	XLFHandler handler = xliffEditor.getXLFHandler();

	int row = handler.getNextUntranslatableSegmentIndex(lastSelectedRow);
	if (row != -1) {
		xliffEditor.jumpToRow(row);
	} else {
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
		MessageDialog.openWarning(window.getShell(), "", "不存在下一不可翻译文本段。");
	}

	return null;
}
 
源代码7 项目: saros   文件: ViewUtils.java
public static void openSarosView() {
  /*
   * TODO What to do if no WorkbenchWindows are are active?
   */
  final IWorkbench workbench = PlatformUI.getWorkbench();

  if (workbench == null) return;

  final IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();

  if (window == null) return;

  try {
    window.getActivePage().showView(SarosView.ID, null, IWorkbenchPage.VIEW_CREATE);
  } catch (PartInitException e) {
    log.error("could not open Saros view (id: " + SarosView.ID + ")", e); // $NON-NLS-1$
  }
}
 
源代码8 项目: tlaplus   文件: ParseSpecHandler.java
/**
 * @deprecated
 */
protected void saveDirtyEditors()
{
    Display display = UIHelper.getCurrentDisplay(); 
    display.syncExec(new Runnable() {
        public void run()
        {
            IWorkbenchWindow[] windows = Activator.getDefault().getWorkbench().getWorkbenchWindows();
            for (int i = 0; i < windows.length; i++)
            {
                IWorkbenchPage[] pages = windows[i].getPages();
                for (int j = 0; j < pages.length; j++)
                    pages[j].saveAllEditors(false);
            }
        }
    });
}
 
public Object execute(ExecutionEvent event) throws ExecutionException {
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
		return null;
	}
	XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
	int[] selectedRows = xliffEditor.getSelectedRows();
	if (selectedRows.length < 1) {
		return null;
	}
	Arrays.sort(selectedRows);
	int firstSelectedRow = selectedRows[0];
	XLFHandler handler = xliffEditor.getXLFHandler();

	int row = handler.getPreviousUntranslatableSegmentIndex(firstSelectedRow);
	if (row != -1) {
		xliffEditor.jumpToRow(row);
	} else {
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
		MessageDialog.openWarning(window.getShell(), "", "不存在上一不可翻译文本段。");
	}

	return null;
}
 
源代码10 项目: yang-design-studio   文件: YangSyntax.java
public MessageConsoleStream getMessageStream() {
	MessageConsole myConsole = findConsole("Yang Console"); //calls function to find/create the Yang console
	if (myConsole != null) {

		IWorkbench wb = PlatformUI.getWorkbench();
		IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
		IWorkbenchPage page = win.getActivePage();
		String id = IConsoleConstants.ID_CONSOLE_VIEW;
		IConsoleView view;
		try {

			view = (IConsoleView) page.showView(id);
			view.display(myConsole);

			return myConsole.newMessageStream();
		} catch (PartInitException e) {
			e.printStackTrace();
		}
	}
	return null;
}
 
源代码11 项目: tracecompass   文件: TmfAlignmentSynchronizer.java
/**
 * Get the narrowest view that corresponds to the given alignment information.
 */
private static TmfView getNarrowestView(TmfTimeViewAlignmentInfo alignmentInfo) {
    IWorkbenchWindow workbenchWindow = getWorkbenchWindow(alignmentInfo.getShell());
    if (workbenchWindow == null || workbenchWindow.getActivePage() == null) {
        // Only time aligned views that are part of a workbench window are supported
        return null;
    }
    IWorkbenchPage page = workbenchWindow.getActivePage();

    int narrowestWidth = Integer.MAX_VALUE;
    TmfView narrowestView = null;
    for (IViewReference ref : page.getViewReferences()) {
        IViewPart view = ref.getView(false);
        if (isTimeAlignedView(view)) {
            TmfView tmfView = (TmfView) view;
            if (isCandidateForNarrowestView(tmfView, alignmentInfo, narrowestWidth)) {
                narrowestWidth = ((ITmfTimeAligned) tmfView).getAvailableWidth(getClampedTimeAxisOffset(alignmentInfo));
                narrowestWidth = getClampedTimeAxisWidth(alignmentInfo, narrowestWidth);
                narrowestView = tmfView;
            }
        }
    }

    return narrowestView;
}
 
源代码12 项目: tracecompass   文件: PasteHandler.java
@Override
public boolean isEnabled() {
    // Check if we are closing down
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }

    // Get the selection
    IWorkbenchPage page = window.getActivePage();
    IWorkbenchPart part = page.getActivePart();
    if (!(part instanceof FilterView)) {
        return false;
    }
    FilterView v = (FilterView) part;
    ITmfFilterTreeNode sel = v.getSelection();
    if (sel == null) {
        sel = v.getFilterRoot();
    }
    ITmfFilterTreeNode objectToPaste = FilterEditUtils.getTransferredTreeNode();
    return (v.isTreeInFocus() && objectToPaste != null &&
            (sel.getValidChildren().contains(objectToPaste.getNodeName())
                    || TmfFilterNode.NODE_NAME.equals(objectToPaste.getNodeName())));
}
 
源代码13 项目: gama   文件: GamlReferenceSearch.java
public static void install() {
	WorkbenchHelper.runInUI("Install GAML Search", 0, m -> {
		final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		if (window instanceof WorkbenchWindow) {
			final MTrimBar topTrim = ((WorkbenchWindow) window).getTopTrim();
			for (final MTrimElement element : topTrim.getChildren()) {
				if ("SearchField".equals(element.getElementId())) {
					final Composite parent = ((Control) element.getWidget()).getParent();
					final Control old = (Control) element.getWidget();
					WorkbenchHelper.runInUI("Disposing old search control", 500, m2 -> old.dispose());
					element.setWidget(GamlSearchField.installOn(parent));
					parent.layout(true, true);
					parent.update();
					break;
				}
			}
		}
	});
}
 
源代码14 项目: tmxeditor8   文件: ShowPreviousNoteHandler.java
public Object execute(ExecutionEvent event) throws ExecutionException {
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
		return null;
	}
	XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
	int[] selectedRows = xliffEditor.getSelectedRows();
	if (selectedRows.length < 1) {
		return null;
	}
	Arrays.sort(selectedRows);
	int firstSelectedRow = selectedRows[0];
	XLFHandler handler = xliffEditor.getXLFHandler();

	int row = handler.getPreviousNoteSegmentIndex(firstSelectedRow);
	if (row != -1) {
		xliffEditor.jumpToRow(row);
	} else {
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
		MessageDialog.openWarning(window.getShell(), "", "不存在上一个带批注的文本段。");
	}

	return null;
}
 
@Override
public void uninstall() {

	IWorkbenchPartSite site= fTextEditor.getSite();
	IWorkbenchWindow window= site.getWorkbenchWindow();
	window.getPartService().removePartListener(fPartListener);
	fPartListener= null;

	Shell shell= window.getShell();
	if (shell != null && !shell.isDisposed())
		shell.removeShellListener(fActivationListener);
	fActivationListener= null;

	JavaCore.removeElementChangedListener(fJavaElementChangedListener);
	fJavaElementChangedListener= null;

	IWorkspace workspace= JavaPlugin.getWorkspace();
	workspace.removeResourceChangeListener(fResourceChangeListener);
	fResourceChangeListener= null;

	JavaPlugin.getDefault().getCombinedPreferenceStore().removePropertyChangeListener(fPropertyChangeListener);
	fPropertyChangeListener= null;

	super.uninstall();
}
 
public Object execute(ExecutionEvent event) throws ExecutionException {
	isSelected = !isSelected;				
	try {
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		if (window != null) {
			IWorkbenchPage page = window.getActivePage();
			if (page != null) {
				IEditorPart editor = page.getActiveEditor();
				if (editor != null && editor instanceof IXliffEditor) {
					((IXliffEditor) editor).refreshWithNonprinttingCharacter(isSelected);
				}
			}
		}
	} catch (NullPointerException e) {
		e.printStackTrace();
	}
	
	return null;
}
 
源代码17 项目: tlaplus   文件: UIHelper.java
/**
 * Closes all windows with a perspective
 * 
 * @param perspectiveId
 *            a perspective Id pointing the perspective
 */
public static void closeWindow(String perspectiveId) {
	IWorkbench workbench = Activator.getDefault().getWorkbench();
	// hide intro
	if (InitialPerspective.ID.equals(perspectiveId)) {
		workbench.getIntroManager().closeIntro(workbench.getIntroManager().getIntro());
	}

	IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();

	// closing the perspective opened in a window
	for (int i = 0; i < windows.length; i++) {
		IWorkbenchPage page = windows[i].getActivePage();
		if (page != null && page.getPerspective() != null && perspectiveId.equals(page.getPerspective().getId())) {
			windows[i].close();
		}
	}
}
 
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
	boolean enabled = false;
	IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	if (window != null) {
		IWorkbenchPage page = window.getActivePage();
		if (page != null) {
			IEditorPart editor = page.getActiveEditor();
			if (editor != null && editor instanceof XLIFFEditorImplWithNatTable) {
				XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
				if (xliffEditor != null && xliffEditor.getTable() != null) {
					List<String> selectedRowIds = xliffEditor.getSelectedRowIds();
					enabled = (selectedRowIds != null && selectedRowIds.size() > 0);
				}
			}
		}
	}

	return enabled;
}
 
源代码19 项目: eclipse-wakatime   文件: WakaTime.java
public static void promptForApiKey(IWorkbenchWindow window) {
    String apiKey = ConfigFile.get("settings", "api_key");
    InputDialog dialog = new InputDialog(window.getShell(),
        "WakaTime API Key", "Please enter your api key from http://wakatime.com/settings#apikey", apiKey, null);
    if (dialog.open() == IStatus.OK) {
      apiKey = dialog.getValue();
      ConfigFile.set("settings", "api_key", apiKey);
    }
}
 
源代码20 项目: birt   文件: SessionHandleAdapter.java
/**
 * @return Returns the active moudle in current session
 * 
 * @deprecated It's better to find module from relevant context instead
 *             here.
 */
public ModuleHandle getModule( )
{
	if ( model == null )
	{
		IWorkbenchWindow activeWindow = PlatformUI.getWorkbench( )
				.getActiveWorkbenchWindow( );
		model = moduleHandleMap.get( activeWindow );
	}
	return model;
}
 
源代码21 项目: tesb-studio-se   文件: LocalWSDLEditor.java
@Override
protected void createActions() {
    super.createActions();
    ActionRegistry registry = getActionRegistry();
    BaseSelectionAction action = new OpenInNewEditor(this) {

        @Override
        public void run() {

            if (getSelectedObjects().size() > 0) {
                Object o = getSelectedObjects().get(0);
                // should make this generic and be able to get the owner from a facade object
                if (o instanceof WSDLBaseAdapter) {
                    WSDLBaseAdapter baseAdapter = (WSDLBaseAdapter) o;
                    IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                    IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor();
                    Object object = editorPart.getAdapter(org.eclipse.wst.wsdl.Definition.class);
                    if (object instanceof org.eclipse.wst.wsdl.Definition) {
                        EObject eObject = (EObject) baseAdapter.getTarget();
                        OpenOnSelectionHelper openHelper = new OpenOnSelectionHelper(
                                (org.eclipse.wst.wsdl.Definition) object);
                        openHelper.openEditor(eObject);
                    }
                }
            }
        }
    };
    action.setSelectionProvider(getSelectionManager());
    registry.registerAction(action);
}
 
源代码22 项目: n4js   文件: EclipseUIUtils.java
/** Obtains active workbench window. Can be null. */
public static IWorkbenchWindow getWorkbenchWindow() {
	if (!UIUtils.runsInUIThread())
		LOGGER.warn("Eclipse UI utilities work correctly only when called from the UI thread.");

	IWorkbenchWindow window = null;
	if (Workbench.getInstance() != null) {
		IWorkbench wb = PlatformUI.getWorkbench();
		window = wb.getActiveWorkbenchWindow();
	}
	return window;
}
 
源代码23 项目: XPagesExtensionLibrary   文件: ExtLibPanelUtil.java
public static IWorkbenchPage getActiveWorkbenchPage(){
    IWorkbenchWindow window = getActiveWorkbenchWindow();
    if(null != window){
        IWorkbenchPage page = window.getActivePage();
        return page;
    }
    return null;
}
 
源代码24 项目: xds-ide   文件: SwtUtils.java
public static Shell getDefaultShell() {
	IWorkbenchWindow window = PlatformUI.getWorkbench()
			.getActiveWorkbenchWindow();
	if (window != null) {
		return window.getShell();
	}
	return null;
}
 
源代码25 项目: ice   文件: ForkStorkWizard.java
/**
 * The default constructor. This is not normally called by the platform but
 * via handlers.
 * 
 * @param window
 *            The workbench window.
 */
public ForkStorkWizard(IWorkbenchWindow window) {
	// Initialize the default information.
	this();
	// Store a reference to the workbench window.
	workbenchWindow = window;
	page = new ForkStorkWizardPage("Fork the Stork!");

}
 
源代码26 项目: eclipse-wakatime   文件: CustomExecutionListener.java
@Override
public void postExecuteSuccess(String commandId, Object returnValue) {
    if (commandId.equals("org.eclipse.ui.file.save")) {
        IWorkbench workbench = PlatformUI.getWorkbench();
        if (workbench == null) return;
        IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
        if (window == null) return;

        if (window.getPartService() == null) return;
        if (window.getPartService().getActivePart() == null) return;
        if (window.getPartService().getActivePart().getSite() == null) return;
        if (window.getPartService().getActivePart().getSite().getPage() == null) return;
        if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor() == null) return;
        if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor().getEditorInput() == null) return;

        // log file save event
        IEditorInput input = window.getPartService().getActivePart().getSite().getPage().getActiveEditor().getEditorInput();
        if (input instanceof IURIEditorInput) {
            URI uri = ((IURIEditorInput)input).getURI();
            if (uri != null && uri.getPath() != null) {
                String currentFile = uri.getPath();
                long currentTime = System.currentTimeMillis() / 1000;

                // always log writes
                WakaTime.sendHeartbeat(currentFile, WakaTime.getActiveProject(), true);
                WakaTime.getDefault().lastFile = currentFile;
                WakaTime.getDefault().lastTime = currentTime;
            }
        }
    }
}
 
源代码27 项目: Pydev   文件: UIUtils.java
public static IWorkbenchPage getActivePage() {
    IWorkbenchWindow workbench = getActiveWorkbenchWindow();
    if (workbench == null) {
        return null;
    }
    return workbench.getActivePage();
}
 
源代码28 项目: n4js   文件: N4JSGracefulActivator.java
/**
 * Returns the active workbench shell or <code>null</code> if none
 *
 * @return the active workbench shell or <code>null</code> if none
 */
public static Shell getActiveWorkbenchShell() {
	IWorkbenchWindow window = getInstance().getWorkbench().getActiveWorkbenchWindow();
	if (window != null) {
		return window.getShell();
	}
	return null;
}
 
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
  IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
  if (window != null) {
    IWorkbenchPage page = window.getActivePage();
    if (page != null) {
      IViewPart webAppView = page.findView(WebAppLaunchView.ID);
      if (webAppView == null) {
        try {
          webAppView = page.showView(WebAppLaunchView.ID);
        } catch (PartInitException e) {
          return StatusUtilities.newErrorStatus(e, Activator.PLUGIN_ID);
        }
      }

      if (webAppView != null) {
        synchronized(boldingLock) {
          if (bolding) {
            if (webAppView.getSite() != null) {
              IWorkbenchSiteProgressService service = 
                (IWorkbenchSiteProgressService) webAppView.getSite().getAdapter(
                  IWorkbenchSiteProgressService.class);
              if (service != null) {
                service.warnOfContentChange();
              }
            }
          } else {
            page.bringToTop(webAppView);
          }
        }
      }
    }
  }
  return Status.OK_STATUS;
}
 
/**
 * Refresh change editor part.
 *
 * @param partRef the IEditorPart which the user has switched.
 */
public void refreshChangeEditorPart(IEditorPart partRef) {        
    if (partRef.getEditorInput() instanceof IFileEditorInput){
        //could be FileStoreEditorInput
        //for files which are not part of the
        //current workspace
        activeEditorPart = partRef;
        IFile file = ((IFileEditorInput) partRef.getEditorInput()).getFile();
        IProject project = file.getProject();

        CodeCheckerProject ccProj = projects.get(project);
        String filename = "";
        if (ccProj != null)
            filename = ((FileEditorInput) partRef.getEditorInput()).getFile().getLocation().toFile().toPath()
                    .toString();

        IWorkbenchWindow activeWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (activeWindow == null) {
            Logger.log(IStatus.ERROR, NULL_WINDOW);
            return;
        }
        IWorkbenchPage[] pages = activeWindow.getPages();

        this.refreshProject(pages, project, true);
        this.refreshCurrent(pages, project, filename, true);
        this.refreshCustom(pages, project, "", true);
        this.activeProject = project;
    }
}