Java Code Examples for org.eclipse.ui.IWorkbenchPage#findView()

The following examples show how to use org.eclipse.ui.IWorkbenchPage#findView() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Navigator.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: OpenTypeHierarchyUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static TypeHierarchyViewPart openInPerspective(IWorkbenchWindow window, IJavaElement[] input) throws WorkbenchException, JavaModelException {
	IWorkbench workbench= JavaPlugin.getDefault().getWorkbench();
	IJavaElement perspectiveInput= input.length == 1 ? input[0] : null;

	if (perspectiveInput != null && input[0] instanceof IMember) {
		if (input[0].getElementType() != IJavaElement.TYPE) {
			perspectiveInput= ((IMember)input[0]).getDeclaringType();
		} else {
			perspectiveInput= input[0];
		}
	}
	IWorkbenchPage page= workbench.showPerspective(JavaUI.ID_HIERARCHYPERSPECTIVE, window, perspectiveInput);

	TypeHierarchyViewPart part= (TypeHierarchyViewPart) page.findView(JavaUI.ID_TYPE_HIERARCHY);
	if (part != null) {
		part.clearNeededRefresh(); // avoid refresh of old hierarchy on 'becomes visible'
	}
	part= (TypeHierarchyViewPart) page.showView(JavaUI.ID_TYPE_HIERARCHY);
	part.setInputElements(input);
	if (perspectiveInput != null) {
		if (page.getEditorReferences().length == 0) {
			JavaUI.openInEditor(input[0], false, false); // only open when the perspective has been created
		}
	}
	return part;
}
 
Example 3
Source File: TmfAnalysisViewOutput.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void setOutputProperty(@NonNull String key, String value, boolean immediate) {
    if (value == null) {
        fProperties.remove(key);
    } else {
        fProperties.put(key, value);
        /*
         * If the property is immediate, we forward it to the view if the
         * view is active
         */
        if (immediate) {
            final IWorkbench wb = PlatformUI.getWorkbench();
            final IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage();
            IViewPart view = activePage.findView(fViewId);
            if (view instanceof WorkbenchPart) {
                ((WorkbenchPart) view).setPartProperty(key, value);
            }
        }
    }
}
 
Example 4
Source File: TabbedPropertySynchronizerListener.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private TabbedPropertySheetPage activePropertyTab(final IWorkbenchPage activePage, final String viewId) {
    final IViewPart view = activePage.findView(viewId);
    final TabbedPropertySheetPage propertySheetPage = (TabbedPropertySheetPage) view.getAdapter(TabbedPropertySheetPage.class);
    if (propertySheetPage != null) {
        return propertySheetPage;
    }
    return null;
}
 
Example 5
Source File: SARLPackageExplorerPart.java    From sarl with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the package explorer part of the active perspective. If
 * there isn't any package explorer part {@code null} is returned.
 *
 * @return the package explorer from the active perspective
 */
public static SARLPackageExplorerPart getFromActivePerspective() {
	final IWorkbenchPage activePage = JavaPlugin.getActivePage();
	if (activePage == null) {
		return null;
	}
	final IViewPart view = activePage.findView(ID_PACKAGES);
	if (view instanceof PackageExplorerPart) {
		return (SARLPackageExplorerPart) view;
	}
	return null;
}
 
Example 6
Source File: TemplatePrintSettingsCommand.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException{
	TextTemplate template = getSelectedTextTemplate(event);
	if (template == null) {
		return null;
	}
	String cfgTemplate = template.getCfgTemplateBase();
	String cfgPrinter =
		CoreHub.localCfg.get(cfgTemplate
			+ TextTemplatePrintSettings.TXT_TEMPLATE_PRINTER_SUFFIX, null);
	String cfgTray =
		CoreHub.localCfg.get(cfgTemplate + TextTemplatePrintSettings.TXT_TEMPLATE_TRAY_SUFFIX,
			null);
	
	TextTemplatePrintSettingsDialog ttPrintSettingsDialog =
		new TextTemplatePrintSettingsDialog(UiDesk.getTopShell(), cfgPrinter, cfgTray);
	if (ttPrintSettingsDialog.open() == IDialogConstants.OK_ID) {
		template.setPrinter(ttPrintSettingsDialog.getPrinter());
		template.setTray(ttPrintSettingsDialog.getMediaTray());
	}
	IWorkbenchPage activePage =
		PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	TextTemplateView textTemplateView =
		(TextTemplateView) activePage.findView(TextTemplateView.ID);
	textTemplateView.update(template);
	return null;
}
 
Example 7
Source File: QAResultViewer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 双击定位
 */
private void locationRow(){
	int[] selectRow = table.getRowSelection();
	
	if (selectRow.length <= 0) {
		return;
	}
	// 获取第一行选择的值
	QAResultBean bean = dataList.get(selectRow[0] - 1);
	
	if (nattable == null) {
		IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		IViewPart view = workbenchPage.findView(TmxEditorViewer.ID);
		if (view == null) {
			return;
		}
		TmxEditorViewer tmxEditorViewer = (TmxEditorViewer) view;
		editor = tmxEditorViewer.getTmxEditor();
		if (editor == null) {
			return;
		}
		nattable = editor.getTmxEditorImpWithNattable();
	}
	
	if (nattable != null && !nattable.isDispose()) {
		// 获取第一行选择的值
		// UNDO 这里应该通过 tuid 进行定位
		editor.resetFilterBeforLocation(qaControl.getOriginalSrcLang(), qaControl.getOriginalTgtLang());
		nattable.selectCell(nattable.getTgtColumnIndex(), Integer.parseInt(bean.getLineNumber()) - 1);
	}
}
 
Example 8
Source File: ToggleOutlineHandler.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException
{
	boolean toShow = !HandlerUtil.toggleCommandState(event.getCommand());
	IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	if (page != null)
	{
		if (toShow)
		{
			try
			{
				page.showView(OUTLINE_VIEW_ID);
			}
			catch (PartInitException e)
			{
				IdeLog.logError(CommonEditorPlugin.getDefault(), Messages.ToggleOutlineHandler_ERR_OpeningOutline,
						e);
			}
		}
		else
		{
			IViewPart viewPart = page.findView(OUTLINE_VIEW_ID);
			if (viewPart != null)
			{
				page.hideView(viewPart);
			}
		}
	}
	return null;
}
 
Example 9
Source File: ExportProjectWizard.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addPages() {
	// TODO Auto-generated method stub
	super.addPages();
	IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	IViewPart viewPart = workbenchPage.findView("net.heartsome.cat.common.ui.navigator.view");
	if (viewPart != null) {
		this.selection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
	}
	page = new ExportProjectWizardPage("", selection);
	addPage(page);
}
 
Example 10
Source File: OpenUrlHandler.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException{
	IWorkbenchPage activePage =
			PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	BrowserView view =
			(BrowserView) activePage.findView(BrowserView.ID);
	
	view.navigateTo();	
	return null;
}
 
Example 11
Source File: BatchValidationHandler.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected void refreshViewerPropertyPart() {
    if (PlatformUI.isWorkbenchRunning() && PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null) {
        final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        if (activePage != null) {
            final IViewPart part = activePage.findView("org.bonitasoft.studio.validation.view");
            if (part instanceof ValidationViewPart) {
                ((ValidationViewPart) part).refreshViewer();
            }
        }
    }
}
 
Example 12
Source File: RefreshHandler.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
private GamaNavigator getNavigator() {
	if (navigator == null) {
		final IWorkbenchPage page = WorkbenchHelper.getPage();
		if (page != null) {
			navigator = (GamaNavigator) page.findView(IGui.NAVIGATOR_VIEW_ID);
		}
	}
	return navigator;
}
 
Example 13
Source File: WebAppLaunchViewActivator.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@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;
}
 
Example 14
Source File: CreateMandantTemplateCommand.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private void refreshTextTemplateView(TextTemplate template){
	IWorkbenchPage activePage =
		PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	TextTemplateView textTemplateView =
		(TextTemplateView) activePage.findView(TextTemplateView.ID);
	textTemplateView.update(template);
}
 
Example 15
Source File: UIInterpreterHelper.java    From typescript.java with MIT License 5 votes vote down vote up
/**
 * Select the given element in the view of the given id
 * 
 * @param element
 */
public static void selectReveal(Object element, String viewId) {
	IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	// Select in the Project Explorer the generated files.
	IViewPart view = page.findView(viewId);
	if (view instanceof ISetSelectionTarget) {
		((ISetSelectionTarget) view).selectReveal(new StructuredSelection(element));
	}
}
 
Example 16
Source File: SWTUtils.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
/** @swt Needs to be called from the SWT-UI thread, otherwise <code>null</code> is returned. */
public static IViewPart findView(String id) {
  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;

  return page.findView(id);
}
 
Example 17
Source File: AbstractPluginTest.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    // Start with a clean FindBugs state
    clearBugsState();
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    activePage.closeAllEditors(false);
    IViewPart view = activePage.findView("org.eclipse.ui.internal.introview");
    if (view != null) {
        activePage.hideView(view);
    }
    getPreferenceStore().setValue(FindBugsConstants.ASK_ABOUT_PERSPECTIVE_SWITCH, false);
    waitForJobs();
    processUiEvents();
}
 
Example 18
Source File: NumberOrTagConsisQAHandler.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	boolean isMultiFile = false;
	IFile multiTempIFile = null;
	IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
	// 改为布局
	if (editorPart != null && editorPart instanceof XLIFFEditorImplWithNatTable) {
		String qaItem = event.getParameter("qaItemId");
		XLIFFEditorImplWithNatTable nattable = (XLIFFEditorImplWithNatTable) editorPart;
		ArrayList<IFile> selectIFiles = new ArrayList<IFile>();
		FileEditorInput input = (FileEditorInput) nattable.getEditorInput();

		// 首先判断是否是合并打开的文件
		if (nattable.isMultiFile()) {
			isMultiFile = true;
		}
		if (isMultiFile) {
			multiTempIFile = input.getFile();
			List<String> multiFilesList = new XLFHandler().getMultiFiles(multiTempIFile);
			for (String filePath : multiFilesList) {
				selectIFiles.add(ResourceUtils.fileToIFile(filePath));
			}
		} else {
			selectIFiles.add(input.getFile());
		}

		QAModel model = new QAModel();
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
		shell = window.getShell();
		// 先调用方法,查看品质检查结果视图是否处于显示状态,如果是显示的,就删除数据
		IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		IViewPart view = workbenchPage.findView(QAResultViewPart.ID);
		if (view != null) {
			// 运行时,将结果视图中列表的数据清除
			((QAResultViewPart) view).clearTableData();
		}

		QAResult qaResult = new QAResult();

		// 存储品质检查的检查项
		// model.setBatchQAItemIdList(getBatchQAItems());
		// 存储品质检查的检查时不包括的文本段
		model.setNotInclude(getNotIncludePara());

		// 给品质检查结果视图发出通告,本次检查对象为合并打开文件
		qaResult.firePropertyChange(isMultiFile, new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles,
				multiTempIFile));
		if (isMultiFile) {
			model.setMuliFiles(true);
			model.setMultiOper(new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles,multiTempIFile));
		} else {
			model.setMuliFiles(false);
		}

		boolean isNumberQA = false;
		if (QAConstant.QA_NUMBER.equals(qaItem)) {
			isNumberQA = true;
		} else if (QAConstant.QA_TAG.equals(qaItem)) {
			isNumberQA = false;
		}
		
		HsMultiActiveCellEditor.commit(true);
		beginQA(selectIFiles, model, isNumberQA, qaResult);
	}
	return null;
}
 
Example 19
Source File: ProjectModelOutputTest.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Test the outputAnalysis method for a view
 */
@Test
public void testOpenView() {
    TmfAnalysisElement analysis = getTestAnalysisUi();
    TmfCommonProjectElement traceElement = analysis.getParent().getParent();

    analysis.activateParentTrace();
    try {
        ProjectModelTestData.delayUntilTraceOpened(traceElement);
    } catch (WaitTimeoutException e) {
        fail("The analysis parent did not open in a reasonable time");
    }

    WaitUtils.waitUntil(new ConditionTraceChildrenElements(analysis, 1));
    List<TmfAnalysisOutputElement> outputList = analysis.getAvailableOutputs();
    assertFalse(outputList.isEmpty());

    final IWorkbench wb = PlatformUI.getWorkbench();
    final IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage();

    IViewPart view = activePage.findView(TestAnalysisUi.VIEW_ID);
    if (view != null) {
        activePage.hideView(view);
    }

    TmfAnalysisOutputElement outputElement = null;
    for (ITmfProjectModelElement element : outputList) {
        if (element instanceof TmfAnalysisOutputElement) {
            TmfAnalysisOutputElement el = (TmfAnalysisOutputElement) element;
            if (el.getName().equals("Test Analysis View")) {
                outputElement = el;
            }
        }
    }
    assertNotNull(outputElement);

    outputElement.outputAnalysis();
    WaitUtils.waitUntil(workbenchPage -> workbenchPage.findView(TestAnalysisUi.VIEW_ID) != null,
            activePage, "Test Analysis View did not open");
    traceElement.closeEditors();
}
 
Example 20
Source File: AbstractExportHandler.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
public boolean initExportConfig(ExecutionEvent event) throws ExecutionException {
	config = new ExportConfig();
	Shell shell = HandlerUtil.getActiveShell(event);
	String partId = HandlerUtil.getActivePartId(event);

	if (partId.equals("net.heartsome.cat.common.ui.navigator.view")) {// 导航视图处于激活状态
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		IViewPart viewPart = page.findView("net.heartsome.cat.common.ui.navigator.view");
		StructuredSelection selection = (StructuredSelection) viewPart.getSite().getSelectionProvider()
				.getSelection();
		if (selection != null && !selection.isEmpty()) {
			for (Object obj : selection.toList()) {
				if (obj instanceof IFile) {
					addXLFFile((IFile) obj);
				} else if (obj instanceof IFolder) {
					traversalFile((IFolder) obj);
				} else if (obj instanceof IProject) {
					IProject proj = (IProject) obj;
					traversalFile(proj.getFolder(XLF));
				}
			}
			if (config.getProjects() == null || config.getProjects().size() < 1) {
				MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"),
						Messages.getString("xlf2tmx.info.notfoundxlf"));
				return false;
			}
		}
	} else if (partId.equals("net.heartsome.cat.ts.ui.xliffeditor.nattable.editor")) {// nattable 处于激活状态
		IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
		IEditorInput editorInput = ((IEditorPart) part).getEditorInput();
		IFile iFile = (IFile) editorInput.getAdapter(IFile.class);
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
		IXliffEditor xliffEditor = (IXliffEditor) editor;

		if (xliffEditor.isMultiFile()) {
			MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"),
					Messages.getString("ExportDocxHandler.msg2"));
			return false;
		} else if (iFile.getFileExtension() != null && CommonFunction.validXlfExtension(iFile.getFileExtension())) {
			addXLFFile(iFile);
		}
	}

	return true;
}