Java Code Examples for org.eclipse.jdt.internal.ui.JavaPlugin#getActivePage()

The following examples show how to use org.eclipse.jdt.internal.ui.JavaPlugin#getActivePage() . 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: GWTProjectPropertyPage.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public static void reopenWithGWTJavaEditor(IEditorReference[] openEditors) {
  IWorkbenchPage page = JavaPlugin.getActivePage();

  for (IEditorReference editorRef : openEditors) {
    try {
      IEditorPart editor = editorRef.getEditor(false);
      IEditorInput input = editorRef.getEditorInput();

      // Close the editor, prompting the user to save if document is dirty
      if (page.closeEditor(editor, true)) {
        // Re-open the .java file in the GWT Java Editor
        IEditorPart gwtEditor = page.openEditor(input, GWTJavaEditor.EDITOR_ID);

        // Save the file from the new editor if the Java editor's
        // auto-format-on-save action screwed up the JSNI formatting
        gwtEditor.doSave(null);
      }
    } catch (PartInitException e) {
      GWTPluginLog.logError(e, "Could not open GWT Java editor on {0}", editorRef.getTitleToolTip());
    }
  }
}
 
Example 2
Source File: EditorUtility.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Tests if a CU is currently shown in an editor
 *
 * @param inputElement the input element
 * @return the IEditorPart if shown, null if element is not open in an editor
 */
public static IEditorPart isOpenInEditor(Object inputElement) {
	IEditorPart editor= findEditor(inputElement, false);
	if (editor != null)
		return editor;

	IEditorInput input= getEditorInput(inputElement);

	if (input != null) {
		IWorkbenchPage p= JavaPlugin.getActivePage();
		if (p != null) {
			return p.findEditor(input);
		}
	}

	return null;
}
 
Example 3
Source File: NewElementWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected void openResource(final IFile resource) {
	final IWorkbenchPage activePage= JavaPlugin.getActivePage();
	if (activePage != null) {
		final Display display= getShell().getDisplay();
		if (display != null) {
			display.asyncExec(new Runnable() {
				public void run() {
					try {
						IDE.openEditor(activePage, resource, true);
					} catch (PartInitException e) {
						JavaPlugin.log(e);
					}
				}
			});
		}
	}
}
 
Example 4
Source File: EditorUtility.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static IEditorPart openInEditor(IFile file, boolean activate) throws PartInitException {
	if (file == null)
		throwPartInitException(JavaEditorMessages.EditorUtility_file_must_not_be_null);

	IWorkbenchPage p= JavaPlugin.getActivePage();
	if (p == null)
		throwPartInitException(JavaEditorMessages.EditorUtility_no_active_WorkbenchPage);

	IEditorPart editorPart= IDE.openEditor(p, file, activate);
	initializeHighlightRange(editorPart);
	return editorPart;
}
 
Example 5
Source File: NewJavaWorkingSetWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private PackageExplorerPart getActivePackageExplorer() {
	IWorkbenchPage page= JavaPlugin.getActivePage();
	if (page != null) {
		IWorkbenchPart activePart= page.getActivePart();
		if (activePart instanceof PackageExplorerPart) {
			return (PackageExplorerPart) activePart;
		}
	}
	return null;
}
 
Example 6
Source File: FilteredTypesSelectionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void fillViewMenu(IMenuManager menuManager) {
	super.fillViewMenu(menuManager);

	if (! BUG_184693) {
		fShowContainerForDuplicatesAction= new ShowContainerForDuplicatesAction();
		menuManager.add(fShowContainerForDuplicatesAction);
	}
	if (fAllowScopeSwitching) {
		fFilterActionGroup= new WorkingSetFilterActionGroup(getShell(), JavaPlugin.getActivePage(), new IPropertyChangeListener() {
			public void propertyChange(PropertyChangeEvent event) {
				IWorkingSet ws= (IWorkingSet) event.getNewValue();
				if (ws == null || (ws.isAggregateWorkingSet() && ws.isEmpty())) {
					setSearchScope(SearchEngine.createWorkspaceScope());
					setSubtitle(null);
				} else {
					setSearchScope(JavaSearchScopeFactory.getInstance().createJavaSearchScope(ws, true));
					setSubtitle(ws.getLabel());
				}

				applyFilter();
			}
		});
		fFilterActionGroup.fillViewMenu(menuManager);
	}

	menuManager.add(new Separator());
	menuManager.add(new TypeFiltersPreferencesAction());
}
 
Example 7
Source File: JavaOutlineInformationControl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IProgressMonitor getProgressMonitor() {
	IWorkbenchPage wbPage= JavaPlugin.getActivePage();
	if (wbPage == null)
		return null;

	IEditorPart editor= wbPage.getActiveEditor();
	if (editor == null)
		return null;

	return editor.getEditorSite().getActionBars().getStatusLineManager().getProgressMonitor();
}
 
Example 8
Source File: ConfigureWorkingSetAssignementAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private PackageExplorerPart getActivePackageExplorer() {
	IWorkbenchPage page= JavaPlugin.getActivePage();
	if (page != null) {
		IWorkbenchPart activePart= page.getActivePart();
		if (activePart instanceof PackageExplorerPart) {
			return (PackageExplorerPart) activePart;
		}
	}
	return null;
}
 
Example 9
Source File: AbstractJavaCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IWorkbenchSite getSite() {
	IWorkbenchPage page= JavaPlugin.getActivePage();
	if (page != null) {
		IWorkbenchPart part= page.getActivePart();
		if (part != null)
			return part.getSite();
	}
	return null;
}
 
Example 10
Source File: JavaStringAutoIndentStrategy.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isSmartMode() {
	IWorkbenchPage page= JavaPlugin.getActivePage();
	if (page != null)  {
		IEditorPart part= page.getActiveEditor();
		if (part instanceof ITextEditorExtension3) {
			ITextEditorExtension3 extension= (ITextEditorExtension3) part;
			return extension.getInsertMode() == ITextEditorExtension3.SMART_INSERT;
		}
	}
	return false;
}
 
Example 11
Source File: EditorUtility.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the Java element edited in the current active editor.
 *
 * @return the Java element or <code>null</code> if the active editor doesn't edit a Java element
 */
public static IJavaElement getActiveEditorJavaInput() {
	IWorkbenchPage page= JavaPlugin.getActivePage();
	if (page != null) {
		IEditorPart part= page.getActiveEditor();
		if (part != null) {
			IEditorInput editorInput= part.getEditorInput();
			if (editorInput != null) {
				return JavaUI.getEditorInputJavaElement(editorInput);
			}
		}
	}
	return null;
}
 
Example 12
Source File: EditorUtility.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static IEditorPart openInEditor(IEditorInput input, String editorID, boolean activate) throws PartInitException {
	Assert.isNotNull(input);
	Assert.isNotNull(editorID);

	IWorkbenchPage p= JavaPlugin.getActivePage();
	if (p == null)
		throwPartInitException(JavaEditorMessages.EditorUtility_no_active_WorkbenchPage);

	IEditorPart editorPart= p.openEditor(input, editorID, activate);
	initializeHighlightRange(editorPart);
	return editorPart;
}
 
Example 13
Source File: GWTProjectPropertyPage.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public static IEditorReference[] getOpenJavaEditors(IProject project) {
  List<IEditorReference> projectOpenJavaEditors = new ArrayList<IEditorReference>();
  try {
    IWorkbenchPage page = JavaPlugin.getActivePage();
    if (page != null) {
      // Iterate through all the open editors
      IEditorReference[] openEditors = page.getEditorReferences();
      for (IEditorReference openEditor : openEditors) {
        IEditorPart editor = openEditor.getEditor(false);

        // Only look for Java Editor and subclasses
        if (editor instanceof CompilationUnitEditor) {
          IEditorInput input = openEditor.getEditorInput();
          IJavaProject inputProject = EditorUtility.getJavaProject(input);

          // See if the editor is editing a file in this project
          if (inputProject != null && inputProject.getProject().equals(project)) {
            projectOpenJavaEditors.add(openEditor);
          }
        }
      }
    }
  } catch (PartInitException e) {
    GWTPluginLog.logError(e);
  }

  return projectOpenJavaEditors.toArray(new IEditorReference[0]);
}
 
Example 14
Source File: JavaSearchPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IEditorPart getActiveEditor() {
	IWorkbenchPage activePage= JavaPlugin.getActivePage();
	if (activePage != null) {
		return activePage.getActiveEditor();
	}
	return null;
}
 
Example 15
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 16
Source File: PackageExplorerPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.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</code> is returned.
 * @return the package explorer from the active perspective
 */
public static PackageExplorerPart getFromActivePerspective() {
	IWorkbenchPage activePage= JavaPlugin.getActivePage();
	if (activePage == null)
		return null;
	IViewPart view= activePage.findView(VIEW_ID);
	if (view instanceof PackageExplorerPart)
		return (PackageExplorerPart)view;
	return null;
}
 
Example 17
Source File: CUCorrectionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void apply(IDocument document) {
	try {
		ICompilationUnit unit= getCompilationUnit();
		IEditorPart part= null;
		if (unit.getResource().exists()) {
			boolean canEdit= performValidateEdit(unit);
			if (!canEdit) {
				return;
			}
			part= EditorUtility.isOpenInEditor(unit);
			if (part == null) {
				part= JavaUI.openInEditor(unit);
				if (part != null) {
					fSwitchedEditor= true;
					document= JavaUI.getDocumentProvider().getDocument(part.getEditorInput());
				}
			}
			IWorkbenchPage page= JavaPlugin.getActivePage();
			if (page != null && part != null) {
				page.bringToTop(part);
			}
			if (part != null) {
				part.setFocus();
			}
		}
		performChange(part, document);
	} catch (CoreException e) {
		ExceptionHandler.handle(e, CorrectionMessages.CUCorrectionProposal_error_title, CorrectionMessages.CUCorrectionProposal_error_message);
	}
}
 
Example 18
Source File: DeleteAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Hides all the working sets in the list from the Package Explorer.
 * 
 * @param selection the selection of working sets 
 * @since 3.8
 */
private void hideWorkingSets(List<IWorkingSet> selection) {
	IWorkbenchPage page= JavaPlugin.getActivePage();
	if (page != null) {
		IWorkbenchPart activePart= page.getActivePart();
		if (activePart instanceof PackageExplorerPart) {
			PackageExplorerPart packagePart= (PackageExplorerPart) activePart;
			WorkingSetModel model= packagePart.getWorkingSetModel();
			List<IWorkingSet> activeWorkingSets= new ArrayList<IWorkingSet>(Arrays.asList(model.getActiveWorkingSets()));
			activeWorkingSets.removeAll(selection);
			model.setActiveWorkingSets(activeWorkingSets.toArray(new IWorkingSet[activeWorkingSets.size()]));
		}
	}
}
 
Example 19
Source File: JavaSearchPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void initSelections() {
	ISelection sel= getContainer().getSelection();

	IWorkbenchPage activePage= JavaPlugin.getActivePage();
	if (activePage != null) {
		IWorkbenchPart activePart= activePage.getActivePart();
		if (activePart instanceof JavaEditor) {
			JavaEditor javaEditor= (JavaEditor) activePart;
			if (javaEditor.isBreadcrumbActive()) {
				sel= javaEditor.getBreadcrumb().getSelectionProvider().getSelection();
			}
		}
	}

	SearchPatternData initData= null;

	if (sel instanceof IStructuredSelection) {
		initData= tryStructuredSelection((IStructuredSelection) sel);
	} else if (sel instanceof ITextSelection) {
		IEditorPart activeEditor= getActiveEditor();
		if (activeEditor instanceof JavaEditor) {
			try {
				IJavaElement[] elements= SelectionConverter.codeResolve((JavaEditor) activeEditor);
				if (elements != null && elements.length > 0) {
					initData= determineInitValuesFrom(elements[0]);
				}
			} catch (JavaModelException e) {
				// ignore
			}
		}
		if (initData == null) {
			initData= trySimpleTextSelection((ITextSelection) sel);
		}
	}
	if (initData == null) {
		initData= getDefaultInitValues();
	}

	fInitialData= initData;
	fJavaElement= initData.getJavaElement();
	fCaseSensitive.setSelection(initData.isCaseSensitive());
	fCaseSensitive.setEnabled(fJavaElement == null);

	setSearchFor(initData.getSearchFor());
	setLimitTo(initData.getSearchFor(), initData.getLimitTo());
	setIncludeMask(initData.getIncludeMask());
	setMatchLocations(initData.getMatchLocations());

	fPattern.setText(initData.getPattern());
}
 
Example 20
Source File: PackageExplorerPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void partInputChanged(IWorkbenchPartReference partRef) {
	IWorkbenchPage activePage= JavaPlugin.getActivePage();
	if (partRef instanceof IEditorReference && activePage != null && activePage.getActivePartReference() == partRef) {
		editorActivated(((IEditorReference) partRef).getEditor(true));
	}
}