Java Examples for org.eclipse.ui.IWorkbenchPartSite
The following java examples will help you to understand the usage of org.eclipse.ui.IWorkbenchPartSite. These source code samples are taken from different open source projects.
Example 1
| Project: framesoc-master File: HandlerUtils.java View source code |
/**
* Utility to launch a command given the Workbench site and the
* command identifier.
*
* @param site Workbench site
* @param commandID command identifier
*/
public static void launchCommand(IWorkbenchPartSite site, String commandID) {
IHandlerService handlerService = (IHandlerService) site.getService(IHandlerService.class);
try {
handlerService.executeCommand(commandID, null);
} catch (ExecutionExceptionNotDefinedException | NotEnabledException | NotHandledException | e) {
e.printStackTrace();
}
}Example 2
| Project: marketcetera-master File: ContextMenuFactory.java View source code |
public void createContextMenu(String name, final Table table, IWorkbenchPartSite site, ISelectionProvider selectionProvider) {
Menu menu;
Menu existingMenu = table.getMenu();
MenuManager menuMgr = new MenuManager(name);
if (existingMenu != null) {
menu = existingMenu;
} else {
menu = menuMgr.createContextMenu(table);
menuMgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
}
table.setMenu(menu);
table.setData(MenuManager.class.toString(), menuMgr);
site.registerContextMenu(menuMgr, selectionProvider);
}Example 3
| Project: vrapper-master File: SplitEditorCommand.java View source code |
public void execute(EditorAdaptor editorAdaptor) throws CommandExecutionException {
UserInterfaceService userInterfaceService = editorAdaptor.getUserInterfaceService();
IWorkbenchPartSite editorSite = getEditorSite();
EModelService svc = (EModelService) editorSite.getService(EModelService.class);
EPartService psvc = (EPartService) editorSite.getService(EPartService.class);
MPart p = null;
if (filename == null) {
p = (MPart) editorSite.getService(MPart.class);
} else {
if (!filename.startsWith("/")) {
if (editorAdaptor.getConfiguration().get(Options.AUTO_CHDIR)) {
filename = editorAdaptor.getFileService().getCurrentFilePath() + "/" + filename;
} else {
filename = editorAdaptor.getRegisterManager().getCurrentWorkingDirectory() + "/" + filename;
}
}
p = openFileInEditor(filename);
}
MElementContainer<MUIElement> editorStack = p.getParent();
MWindow window = svc.getTopLevelWindowFor(editorStack);
if (mode == SplitMode.MOVE && editorStack.getChildren().size() < 2) {
userInterfaceService.setErrorMessage("Editor must have at least 2 tabs");
return;
}
//
// Find a parent sash container to insert a new stack.
//
MUIElement neighbour = p;
MElementContainer<? extends MUIElement> parent = neighbour.getParent();
while (parent != null && // Detached windows
!(parent instanceof MTrimmedWindow) && (!(parent instanceof MPartSashContainer) || // NOTE: MArea is an instance of MPartSashContainer
(parent instanceof MArea && containerMode == SplitContainer.TOP_LEVEL))) {
neighbour = parent;
parent = neighbour.getParent();
if (parent == null) {
// Check if there is a placeholder for the element.
MPlaceholder ph = svc.findPlaceholderFor(window, neighbour);
if (ph != null) {
neighbour = ph;
parent = neighbour.getParent();
}
}
}
@SuppressWarnings("unchecked") final MElementContainer<MUIElement> parentContainer = (MElementContainer<MUIElement>) parent;
final int neighbourIndex = parentContainer.getChildren().indexOf(neighbour);
//
// Move or clone the editor into a new Stack.
//
MPartStack newStack = MBasicFactory.INSTANCE.createPartStack();
// Copy tags from the original stack to make it more like the one
// create by Eclipse.
newStack.getTags().addAll(editorStack.getTags());
MPart newPart = null;
if (mode == SplitMode.CLONE) {
try {
newPart = cloneEditor();
newStack.getChildren().add(newPart);
// Temporary activate the cloned editor.
psvc.activate(p);
} catch (PartInitException e) {
userInterfaceService.setErrorMessage("Unable to split editor");
VrapperLog.error("Unable to split editor", e);
return;
}
} else {
editorStack.getChildren().remove(p);
// Activate one of the remaining tabs in the stack.
psvc.activate((MPart) editorStack.getSelectedElement());
newStack.getChildren().add(p);
newPart = p;
}
//
// Do we need a new sash or can we extend the existing one?
// NOTE: MArea always needs a sash.
//
final MPartSashContainer editorSash = parent instanceof MPartSashContainer ? (MPartSashContainer) parent : null;
boolean isHorizontal = direction != SplitDirection.HORIZONTALLY;
if (editorSash != null && isHorizontal == editorSash.isHorizontal() && !(editorSash instanceof MArea)) {
//
// We just need to add to the existing sash.
//
int totalVisWeight = 0;
int countVis = 0;
for (MUIElement child : parentContainer.getChildren()) {
if (child.isToBeRendered()) {
totalVisWeight += getElementWeight(child);
++countVis;
}
}
newStack.setContainerData(Integer.toString(totalVisWeight / countVis));
parentContainer.getChildren().add(neighbourIndex + 1, newStack);
} else {
//
// Create a new PartSashContainer with the designed split property to
// put in place of the neighbour.
//
MPartSashContainer splitSash = MBasicFactory.INSTANCE.createPartSashContainer();
splitSash.setHorizontal(isHorizontal);
parentContainer.getChildren().remove(neighbour);
splitSash.getChildren().add((MPartSashContainerElement) neighbour);
splitSash.getChildren().add(newStack);
//
// Set 50/50 split ratio.
//
splitSash.setContainerData(neighbour.getContainerData());
newStack.setContainerData("5000");
neighbour.setContainerData("5000");
// Add the new sash at the same location.
parentContainer.getChildren().add(neighbourIndex, (MUIElement) splitSash);
}
psvc.activate(newPart, true);
}Example 4
| Project: webtools.sourceediting-master File: XSDMultiPageEditorContributor.java View source code |
/*
* (non-JavaDoc) Method declared in
* AbstractMultiPageEditorActionBarContributor.
*/
public void setActivePage(IEditorPart part) {
if (activeEditorPart == part)
return;
activeEditorPart = part;
IActionBars actionBars = getActionBars();
boolean isSource = false;
if (activeEditorPart != null && activeEditorPart instanceof ITextEditor) {
isSource = true;
zoomInRetargetAction.setEnabled(false);
zoomOutRetargetAction.setEnabled(false);
captureScreenAction.setEnabled(false);
activateSourcePage(activeEditorPart, true);
} else {
activateSourcePage(xsdEditor, false);
if (part instanceof InternalXSDMultiPageEditor) {
xsdEditor = (InternalXSDMultiPageEditor) part;
}
if (xsdEditor != null) {
// cs: here's we ensure the UNDO and REDO actions are available when
// the design view is active
IWorkbenchPartSite site = xsdEditor.getSite();
if (site instanceof IEditorSite) {
ITextEditor textEditor = xsdEditor.getTextEditor();
IActionBars siteActionBars = ((IEditorSite) site).getActionBars();
siteActionBars.setGlobalActionHandler(ITextEditorActionConstants.UNDO, getAction(textEditor, ITextEditorActionConstants.UNDO));
siteActionBars.setGlobalActionHandler(ITextEditorActionConstants.REDO, getAction(textEditor, ITextEditorActionConstants.REDO));
siteActionBars.updateActionBars();
}
Object adapter = xsdEditor.getAdapter(ActionRegistry.class);
if (adapter instanceof ActionRegistry) {
ActionRegistry registry = (ActionRegistry) adapter;
actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), registry.getAction(DeleteAction.ID));
actionBars.setGlobalActionHandler(GEFActionConstants.ZOOM_IN, registry.getAction(GEFActionConstants.ZOOM_IN));
actionBars.setGlobalActionHandler(GEFActionConstants.ZOOM_OUT, registry.getAction(GEFActionConstants.ZOOM_OUT));
actionBars.setGlobalActionHandler(ActionFactory.PRINT.getId(), registry.getAction(ActionFactory.PRINT.getId()));
actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), registry.getAction(ActionFactory.SELECT_ALL.getId()));
zoomInRetargetAction.setEnabled(true);
zoomOutRetargetAction.setEnabled(true);
captureScreenAction.setEnabled(true);
}
}
}
if (actionBars != null) {
// update menu bar and tool bar
actionBars.updateActionBars();
}
if (zoomComboContributionItem != null) {
zoomComboContributionItem.setVisible(!isSource);
zoomComboContributionItem.update();
// Bug 254772 - parent contribution manager should not be null. We added this item already.
// Force the ToolBarManager to update/redraw the items
zoomComboContributionItem.getParent().update(true);
}
}Example 5
| Project: buckminster-master File: QueryWizard.java View source code |
public static void openWizard(IWorkbenchPart targetPart, IStructuredSelection selection) {
final QueryWizard wizard = new QueryWizard();
IWorkbenchPartSite site = targetPart.getSite();
wizard.init(site.getWorkbenchWindow().getWorkbench(), selection);
WizardDialog dialog = new WizardDialog(site.getShell(), wizard);
dialog.setPageSize(300, 480);
dialog.open();
}Example 6
| Project: dbeaver-master File: CompileHandler.java View source code |
@Override
public void updateElement(UIElement element, Map parameters) {
List<OracleSourceObject> objects = new ArrayList<>();
IWorkbenchPartSite partSite = UIUtils.getWorkbenchPartSite(element.getServiceLocator());
if (partSite != null) {
final ISelectionProvider selectionProvider = partSite.getSelectionProvider();
if (selectionProvider != null) {
ISelection selection = selectionProvider.getSelection();
if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
for (Iterator<?> iter = ((IStructuredSelection) selection).iterator(); iter.hasNext(); ) {
final Object item = iter.next();
final OracleSourceObject sourceObject = RuntimeUtils.getObjectAdapter(item, OracleSourceObject.class);
if (sourceObject != null) {
objects.add(sourceObject);
}
}
}
}
if (objects.isEmpty()) {
final IWorkbenchPart activePart = partSite.getPart();
final OracleSourceObject sourceObject = RuntimeUtils.getObjectAdapter(activePart, OracleSourceObject.class);
if (sourceObject != null) {
objects.add(sourceObject);
}
}
}
if (!objects.isEmpty()) {
if (objects.size() > 1) {
element.setText("Compile " + objects.size() + " objects");
} else {
final OracleSourceObject sourceObject = objects.get(0);
String objectType = TextUtils.formatWord(sourceObject.getSourceType().name());
element.setText("Compile " + objectType);
}
}
}Example 7
| Project: eclipse.platform.ui-master File: LeakTests.java View source code |
public void testBug255005SiteLeak() throws Exception {
ReferenceQueue queue = new ReferenceQueue();
IViewPart view = fActivePage.showView(MockViewPart.ID);
assertNotNull(view);
// create a job to schedule
Job doNothingJob = new //$NON-NLS-1$
Job(//$NON-NLS-1$
"Does Nothing") {
@Override
protected IStatus run(IProgressMonitor monitor) {
return Status.OK_STATUS;
}
};
// retrieve the progress service
IWorkbenchSiteProgressService service = view.getSite().getService(IWorkbenchSiteProgressService.class);
// schedule it
service.schedule(doNothingJob);
IWorkbenchPartSite site = view.getSite();
// create a reference for our site
Reference ref = createReference(queue, site);
// wait for the job to complete
doNothingJob.join();
try {
// hide the view
fActivePage.hideView(view);
// remove our references
service = null;
site = null;
view = null;
// check for leaks
checkRef(queue, ref);
} finally {
ref.clear();
}
}Example 8
| Project: erlide-master File: ErlangFileActionProvider.java View source code |
@Override
public void init(final ICommonActionExtensionSite aSite) {
final ICommonViewerSite viewSite = aSite.getViewSite();
if (viewSite instanceof ICommonViewerWorkbenchSite) {
final ICommonViewerWorkbenchSite workbenchSite = (ICommonViewerWorkbenchSite) viewSite;
final IWorkbenchPartSite site = workbenchSite.getSite();
openAction = new OpenErlangAction(aSite, workbenchSite.getSelectionProvider());
searchActionGroup = new ErlangSearchActionGroup(site);
final IContextService service = (IContextService) site.getService(IContextService.class);
service.activateContext("org.erlide.ui.erlangOutlineAndNavigatorScope");
}
}Example 9
| Project: erlide_eclipse-master File: ErlangFileActionProvider.java View source code |
@Override
public void init(final ICommonActionExtensionSite aSite) {
final ICommonViewerSite viewSite = aSite.getViewSite();
if (viewSite instanceof ICommonViewerWorkbenchSite) {
final ICommonViewerWorkbenchSite workbenchSite = (ICommonViewerWorkbenchSite) viewSite;
final IWorkbenchPartSite site = workbenchSite.getSite();
openAction = new OpenErlangAction(aSite, workbenchSite.getSelectionProvider());
searchActionGroup = new ErlangSearchActionGroup(site);
final IContextService service = (IContextService) site.getService(IContextService.class);
service.activateContext("org.erlide.ui.erlangOutlineAndNavigatorScope");
}
}Example 10
| Project: gda-dal-master File: PopupMenuUtil.java View source code |
/**
* Use this to install a pop-up for a view where the contribution are all taken
* from the extension mechanism.
*
* @param control component that will host the pop-up menu
* @param viewSite the view site that hosts the view
* @param selectionProvider the selection used to create the context menu
*/
public static void installPopupForView(Control control, IWorkbenchPartSite viewSite, ISelectionProvider selectionProvider) {
MenuManager menuMgr = new MenuManager();
menuMgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
Menu menu = menuMgr.createContextMenu(control);
control.setMenu(menu);
viewSite.registerContextMenu(menuMgr, selectionProvider);
viewSite.setSelectionProvider(selectionProvider);
}Example 11
| Project: org.eclipse.rap-master File: EntityAdapter.java View source code |
private static IEntityAdapter get(final Object element) {
IEntityAdapter result = null;
if (element instanceof IWorkbenchPartSite) {
result = ROOT_ADAPTER;
} else if (element instanceof IDataModel) {
result = DATA_MODEL_ADAPTER;
} else if (element instanceof IPrincipal) {
result = PRINCIPAL_ADAPTER;
} else if (element instanceof IEmployee) {
result = EMPLOYEE_ADAPTER;
} else if (element instanceof IProject) {
result = PROJECT_ADAPTER;
} else if (element instanceof IAssignment) {
result = ASSIGNMENT_ADAPTER;
} else if (element instanceof ITask) {
result = TASK_ADAPTER;
} else {
//TODO: [yao] NLS#
Object[] param = new Object[] { element.getClass().getName() };
String bound = NLS.bind(RMSMessages.get().EntityAdapter_ElementNotSupported, param);
throw new IllegalArgumentException(bound);
}
return result;
}Example 12
| Project: rap-master File: ViewIntroAdapterPart.java View source code |
/**
* Adds a listener that toggles standby state if the view pane is zoomed.
*/
private void addPaneListener() {
IWorkbenchPartSite site = getSite();
if (site instanceof PartSite) {
final WorkbenchPartReference ref = ((WorkbenchPartReference) ((PartSite) site).getPartReference());
ref.addInternalPropertyListener(new IPropertyListener() {
public void propertyChanged(Object source, int propId) {
if (handleZoomEvents) {
if (propId == WorkbenchPartReference.INTERNAL_PROPERTY_ZOOMED) {
setStandby(!ref.getPane().isZoomed());
}
}
}
});
}
}Example 13
| Project: yoursway-sunrise-master File: ContributedAction.java View source code |
private void updateSiteAssociations(IWorkbenchPartSite site, String commandId, String actionId, IConfigurationElement element) {
IWorkbenchLocationService wls = (IWorkbenchLocationService) site.getService(IWorkbenchLocationService.class);
IWorkbench workbench = wls.getWorkbench();
IWorkbenchWindow window = wls.getWorkbenchWindow();
IHandlerService serv = (IHandlerService) workbench.getService(IHandlerService.class);
appContext = new EvaluationContext(serv.getCurrentState(), Collections.EMPTY_LIST);
// set up the appContext as we would want it.
appContext.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, StructuredSelection.EMPTY);
appContext.addVariable(ISources.ACTIVE_PART_NAME, site.getPart());
appContext.addVariable(ISources.ACTIVE_PART_ID_NAME, site.getId());
appContext.addVariable(ISources.ACTIVE_SITE_NAME, site);
if (site instanceof IEditorSite) {
appContext.addVariable(ISources.ACTIVE_EDITOR_NAME, site.getPart());
appContext.addVariable(ISources.ACTIVE_EDITOR_ID_NAME, site.getId());
}
appContext.addVariable(ISources.ACTIVE_WORKBENCH_WINDOW_NAME, window);
appContext.addVariable(ISources.ACTIVE_WORKBENCH_WINDOW_SHELL_NAME, window.getShell());
HandlerService realService = (HandlerService) serv;
partHandler = realService.findHandler(commandId, appContext);
if (partHandler == null) {
localHandler = true;
// if we can't find the handler, then at least we can
// call the action delegate run method
partHandler = new ActionDelegateHandlerProxy(element, IWorkbenchRegistryConstants.ATT_CLASS, actionId, getParameterizedCommand(), site.getWorkbenchWindow(), null, null, null);
}
if (site instanceof MultiPageEditorSite) {
IHandlerService siteServ = (IHandlerService) site.getService(IHandlerService.class);
siteServ.activateHandler(commandId, partHandler);
}
if (getParameterizedCommand() != null) {
getParameterizedCommand().getCommand().removeCommandListener(getCommandListener());
}
site.getPage().addPartListener(getPartListener());
}Example 14
| Project: studio2-master File: MultiPageHTMLEditor.java View source code |
public void elementDeleted(Object element) {
if (element.equals(getEditorInput())) {
IWorkbenchPartSite site = MultiPageHTMLEditor.this.getSite();
if (site == null) {
return;
}
IWorkbenchWindow window = site.getWorkbenchWindow();
if (window == null) {
return;
}
IWorkbenchPage page = window.getActivePage();
if (page == null) {
return;
}
page.closeEditor(MultiPageHTMLEditor.this, true);
}
}Example 15
| Project: BHT-FPA-master File: StatusBarHelper.java View source code |
/**
* This method returns the {@link IStatusLineManager}. It may return
* <code>null</code>.
*
* @return {@link IStatusLineManager} or <code>null</code>
*/
public static synchronized IStatusLineManager getStatusLineManager() {
if (manager != null) {
return manager;
}
manager = new NullStatusLineManager();
IWorkbench wb = PlatformUI.getWorkbench();
if (wb == null) {
return manager;
}
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
if (win == null) {
return manager;
}
IWorkbenchPage page = win.getActivePage();
if (page == null) {
return manager;
}
IWorkbenchPart part = page.getActivePart();
if (part == null) {
return manager;
}
IWorkbenchPartSite site = part.getSite();
if (site == null || !(site instanceof IViewSite)) {
return manager;
}
IViewSite vSite = (IViewSite) site;
IActionBars actionBars = vSite.getActionBars();
if (actionBars == null) {
return manager;
}
manager = actionBars.getStatusLineManager();
return manager;
}Example 16
| Project: bpmn2-modeler-master File: ErrorUtils.java View source code |
@Override
public void run() {
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
if (win == null)
return;
IWorkbenchPage page = win.getActivePage();
if (page == null)
return;
IWorkbenchPart part = page.getActivePart();
if (part == null)
return;
IActionBars actionBars = null;
IWorkbenchPartSite site = part.getSite();
if (site instanceof IViewSite)
actionBars = ((IViewSite) site).getActionBars();
else if (site instanceof IEditorSite)
actionBars = ((IEditorSite) site).getActionBars();
if (actionBars == null)
return;
IStatusLineManager statusLineManager = actionBars.getStatusLineManager();
if (statusLineManager == null)
return;
statusLineManager.setErrorMessage(msg);
statusLineManager.markDirty();
statusLineManager.update(true);
}Example 17
| Project: cdt-master File: RulerColumnDescriptor.java View source code |
/**
* Returns <code>true</code> if this contribution matches the passed disassembly part , <code>false</code> if not.
*
* @param disassembly the disassembly part to check
* @return <code>true</code> if this contribution targets the passed disassembly part
*/
public boolean matchesPart(IWorkbenchPart disassembly) {
Assert.isLegal(disassembly != null);
RulerColumnTarget target = getTarget();
IWorkbenchPartSite site = disassembly.getSite();
if (site != null && target.matchesEditorId(site.getId()))
return true;
if (target.matchesClass(disassembly.getClass()))
return true;
IContentType contentType = getContentType(disassembly);
return contentType != null && target.matchesContentType(contentType);
}Example 18
| Project: drools-guvnor-plugin-master File: ViewUtils.java View source code |
public static void showGitRepositoriesView(Repository repository) {
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
if (win == null)
return;
IWorkbenchPage page = win.getActivePage();
if (page == null)
return;
try {
page.showView(GIT_REPO_VIEW_ID, null, IWorkbenchPage.VIEW_CREATE);
IViewPart part = page.showView(GIT_REPO_VIEW_ID, null, IWorkbenchPage.VIEW_ACTIVATE);
IWorkbenchPartSite site = part.getSite();
org.eclipse.egit.ui.internal.repository.tree.RepositoryNode rn = new org.eclipse.egit.ui.internal.repository.tree.RepositoryNode(null, repository);
TreePath tp = new TreePath(new Object[] { rn });
TreeSelection ts = new TreeSelection(tp);
site.getSelectionProvider().setSelection(ts);
return;
} catch (Exception e) {
}
}Example 19
| Project: droolsjbpm-tools-master File: ViewUtils.java View source code |
public static void showGitRepositoriesView(Repository repository) {
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
if (win == null)
return;
IWorkbenchPage page = win.getActivePage();
if (page == null)
return;
try {
page.showView(GIT_REPO_VIEW_ID, null, IWorkbenchPage.VIEW_CREATE);
IViewPart part = page.showView(GIT_REPO_VIEW_ID, null, IWorkbenchPage.VIEW_ACTIVATE);
IWorkbenchPartSite site = part.getSite();
org.eclipse.egit.ui.internal.repository.tree.RepositoryNode rn = new org.eclipse.egit.ui.internal.repository.tree.RepositoryNode(null, repository);
TreePath tp = new TreePath(new Object[] { rn });
TreeSelection ts = new TreeSelection(tp);
site.getSelectionProvider().setSelection(ts);
return;
} catch (Exception e) {
}
}Example 20
| Project: e4macs-master File: BaseYankHandler.java View source code |
/**
* In the console context, use paste as
* in some consoles (e.g. org.eclipse.debug.internal.ui.views.console.ProcessConsole), updateText
* will not simulate keyboard input
*
* @param event the ExecutionEvent
* @param widget The consoles StyledText widget
*/
protected void paste(ExecutionEvent event, StyledText widget) {
IWorkbenchPart apart = HandlerUtil.getActivePart(event);
if (apart != null) {
try {
IWorkbenchPartSite site = apart.getSite();
if (site != null) {
IHandlerService service = (IHandlerService) site.getService(IHandlerService.class);
if (service != null) {
service.executeCommand(IEmacsPlusCommandDefinitionIds.EMP_PASTE, null);
KillRing.getInstance().setYanked(true);
}
}
} catch (CommandException e) {
}
}
}Example 21
| Project: jbosstools-central-master File: NewProjectExamplesWizardHandler.java View source code |
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
IExtensionPoint extensionPoint = extensionRegistry.getExtensionPoint("org.eclipse.ui.newWizards");
IExtension[] extensions = extensionPoint.getExtensions();
for (IExtension extension : extensions) {
IConfigurationElement[] elements = extension.getConfigurationElements();
for (IConfigurationElement element : elements) {
String id = element.getAttribute("id");
if (JBossCentralActivator.NEW_PROJECT_EXAMPLES_WIZARD_ID.equals(id)) {
try {
Object object = element.createExecutableExtension("class");
if (object instanceof INewWizard) {
INewWizard wizard = (INewWizard) object;
IWorkbenchPartSite site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().getActivePart().getSite();
ISelection selection = site.getSelectionProvider().getSelection();
if (selection instanceof IStructuredSelection) {
wizard.init(PlatformUI.getWorkbench(), (IStructuredSelection) selection);
}
WizardDialog dialog = new WizardDialog(site.getShell(), wizard);
dialog.open();
}
} catch (CoreException e) {
JBossCentralActivator.log(e);
}
break;
}
}
}
return null;
}Example 22
| Project: jucy-master File: UCWorkbenchPart.java View source code |
public static void createContextPopups(IWorkbenchPartSite site, String id, ISelectionProvider sp, Control c) {
MenuManager menuManager = new MenuManager();
menuManager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
menuManager.add(new GroupMarker(USER_ADDITIONS_ID));
menuManager.add(new GroupMarker(POST_USER_ADDITIONS_ID));
site.registerContextMenu(id, menuManager, sp);
Menu menu = menuManager.createContextMenu(c);
c.setMenu(menu);
}Example 23
| Project: perconik-master File: ElementSelectionListener.java View source code |
Event build(final long time, final Action action, final IWorkbenchPart part) {
Event data = LocalEvent.of(time, action.getName());
data.put(key("part"), this.execute(asDisplayTask(new PartSerializer(), part)));
IWorkbenchPartSite site = part.getSite();
if (site != null) {
IWorkbenchPage page = site.getPage();
IWorkbenchWindow window = page.getWorkbenchWindow();
IWorkbench workbench = window.getWorkbench();
data.put(key("part", "page"), identifyObject(page));
data.put(key("part", "page", "window"), identifyObject(window));
data.put(key("part", "page", "window", "workbench"), identifyObject(workbench));
}
return data;
}Example 24
| Project: plugin.maven-drools-plugin-master File: ViewUtils.java View source code |
public static void showGitRepositoriesView(Repository repository) {
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
if (win == null)
return;
IWorkbenchPage page = win.getActivePage();
if (page == null)
return;
try {
page.showView(GIT_REPO_VIEW_ID, null, IWorkbenchPage.VIEW_CREATE);
IViewPart part = page.showView(GIT_REPO_VIEW_ID, null, IWorkbenchPage.VIEW_ACTIVATE);
IWorkbenchPartSite site = part.getSite();
org.eclipse.egit.ui.internal.repository.tree.RepositoryNode rn = new org.eclipse.egit.ui.internal.repository.tree.RepositoryNode(null, repository);
TreePath tp = new TreePath(new Object[] { rn });
TreeSelection ts = new TreeSelection(tp);
site.getSelectionProvider().setSelection(ts);
return;
} catch (Exception e) {
}
}Example 25
| Project: Reuseware-master File: ContentController.java View source code |
/**
* @param selected
* @param site
*/
public void select(FragmentDescription fDesc, IWorkbenchPartSite site) {
try {
IEditorPart activeEditor = site.getPage().getActiveEditor();
// refresh description
DescriptionManager.refresh(fDesc);
// is the currently opened editor showing a composition program?
if (activeEditor instanceof CompositionprogramDiagramEditor) {
CompositionprogramDiagramEditor cpEditor = (CompositionprogramDiagramEditor) activeEditor;
final CompositionProgram cp = (CompositionProgram) cpEditor.getDiagram().getElement();
TransactionalEditingDomain domain = cpEditor.getEditingDomain();
if (fDesc.getSubject() != null) {
final Fragment fragment = fDesc.getSubject();
// add described fragment to the composition programm
domain.getCommandStack().execute(new RecordingCommand(domain) {
protected void doExecute() {
FragmentInstance fInstance = CompositionProgramUtil.createFragmentInstance(fragment, cp);
CompositionProgramUtil.linkImplicitInterface(cp, fInstance);
}
});
}
} else {
MessageDialog.openError(site.getShell(), "No Composition Program Selected", "Open a composition program.");
}
} catch (Exception e) {
e.printStackTrace();
}
}Example 26
| Project: starschema-talend-plugins-master File: JobHierarchyViewer.java View source code |
/**
* Attaches a contextmenu listener to the tree
*
* @param menuListener the menu listener
* @param popupId the popup id
* @param viewSite the view site
*/
public void initContextMenu(IMenuListener menuListener, IWorkbenchPartSite viewSite) {
//$NON-NLS-1$
String popupId = "JobHierarchyViewer_ContextMenu";
MenuManager menuMgr = new MenuManager();
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(menuListener);
Menu menu = menuMgr.createContextMenu(getTree());
getTree().setMenu(menu);
viewSite.registerContextMenu(popupId, menuMgr, this);
}Example 27
| Project: tcf-master File: RegisterVectorDisplayMenu.java View source code |
private TCFNode getRootNode(IWorkbenchPart part) {
IWorkbenchPartSite site = part.getSite();
if (site == null || IDebugUIConstants.ID_DEBUG_VIEW.equals(site.getId())) {
return null;
}
if (part instanceof IDebugView) {
Object input = ((IDebugView) part).getViewer().getInput();
if (input instanceof TCFNode)
return (TCFNode) input;
}
return null;
}Example 28
| Project: ui-bindings-master File: BindingContextSelectionProviderTest.java View source code |
/**
* Tests that a new {@link org.eclipse.jface.viewers.ISelectionProvider} is installed.
*/
@Test
public void testIsSelectionProvider() {
final IWorkbenchPartSite site = myView.getSite();
assertEquals(null, site.getSelectionProvider());
final IBindingContextSelectionProvider provider = IBindingContextSelectionProvider.Factory.adapt(myForm.getContext(), site);
assertEquals(provider, site.getSelectionProvider());
}Example 29
| Project: as-spacebar-master File: MetaspaceNavigator.java View source code |
@Override
protected void handleDoubleClick(DoubleClickEvent event) {
Object element = ((IStructuredSelection) event.getSelection()).getFirstElement();
if (element instanceof Metaspace) {
Metaspace metaspace = (Metaspace) element;
if (!metaspace.isConnected()) {
new ConnectJob(metaspace).schedule();
}
} else {
if (element instanceof Space) {
Space space = (Space) element;
SpaceEditorExport export = Preferences.getSpaceEditorExport(Preferences.getString(Preferences.SPACE_EDITOR_BROWSE_TIME_SCOPE));
SpaceEditorInput input = new SpaceEditorInput(space, export);
IWorkbenchPartSite site = getSite();
final IWorkbenchPage page = site.getWorkbenchWindow().getActivePage();
getCommonViewer().addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
page.activate(MetaspaceNavigator.this);
}
});
try {
page.openEditor(input, input.getEditorId());
} catch (PartInitException e) {
SpaceBarPlugin.errorDialog(site.getShell(), "Could not open editor", e);
}
return;
}
}
super.handleDoubleClick(event);
}Example 30
| Project: bpel-master File: BPELMultiPageEditorActionBarContributor.java View source code |
/*
* (non-JavaDoc) Method declared in
* AbstractMultiPageEditorActionBarContributor.
*/
@Override
public void setActivePage(IEditorPart part) {
if (activeEditorPart == part)
return;
activeEditorPart = part;
IActionBars actionBars = getActionBars();
if (activeEditorPart != null && activeEditorPart instanceof ITextEditor) {
IActionBars siteActionBars = ((IEditorSite) activeEditorPart.getEditorSite()).getActionBars();
siteActionBars.setGlobalActionHandler(ITextEditorActionConstants.UNDO, getAction((ITextEditor) activeEditorPart, ITextEditorActionConstants.UNDO));
siteActionBars.setGlobalActionHandler(ITextEditorActionConstants.REDO, getAction((ITextEditor) activeEditorPart, ITextEditorActionConstants.REDO));
siteActionBars.updateActionBars();
} else {
if (part instanceof BPELEditor) {
bpelEditor = (BPELEditor) part;
}
if (bpelEditor != null) {
Object adapter = bpelEditor.getAdapter(ActionRegistry.class);
if (adapter instanceof ActionRegistry) {
ActionRegistry registry = (ActionRegistry) adapter;
// COPY
IAction action = registry.getAction(BPELCopyAction.ID);
actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), action);
// CUT
action = registry.getAction(BPELCutAction.ID);
actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(), action);
// PASTE
action = registry.getAction(BPELPasteAction.ID);
actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), action);
// DELETE
action = registry.getAction(BPELDeleteAction.ID);
actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), action);
}
IWorkbenchPartSite site = bpelEditor.getSite();
if (site instanceof IEditorSite) {
ITextEditor textEditor = bpelEditor.getMultipageEditor().getTextEditor();
IActionBars siteActionBars = ((IEditorSite) site).getActionBars();
siteActionBars.setGlobalActionHandler(ITextEditorActionConstants.UNDO, getAction(textEditor, ITextEditorActionConstants.UNDO));
siteActionBars.setGlobalActionHandler(ITextEditorActionConstants.REDO, getAction(textEditor, ITextEditorActionConstants.REDO));
siteActionBars.updateActionBars();
}
}
}
if (actionBars != null) {
// update menu bar and tool bar
actionBars.updateActionBars();
}
}Example 31
| Project: cdt-tests-runner-master File: ResumeAtLineActionDelegate.java View source code |
public void run() {
boolean enabled = false;
if (fPartTarget != null && fTargetElement != null) {
IWorkbenchPartSite site = fActivePart.getSite();
if (site != null) {
ISelectionProvider selectionProvider = site.getSelectionProvider();
if (selectionProvider != null) {
ISelection selection = selectionProvider.getSelection();
enabled = fTargetElement.isSuspended() && fPartTarget.canResumeAtLine(fActivePart, selection, fTargetElement);
}
}
}
fAction.setEnabled(enabled);
}Example 32
| Project: ceylon-ide-eclipse-master File: RenameLinkedMode.java View source code |
@Override
public void done() {
if (isEnabled()) {
IProject project = editor.getParseController().getProject();
if (CeylonNature.isEnabled(project)) {
try {
hideEditorActivity();
setName(getNewNameFromNamePosition());
revertChanges();
if (isShowPreview()) {
openPreview();
} else {
IWorkbenchPartSite site = editor.getSite();
new RefactoringExecutionHelper(refactoring, RefactoringStatus.WARNING, getSaveMode(), site.getShell(), site.getWorkbenchWindow()).perform(false, true);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
unhideEditorActivity();
}
}
super.done();
} else {
super.cancel();
}
}Example 33
| Project: CodingSpectator-master File: JavaReconciler.java View source code |
/*
* @see org.eclipse.jface.text.reconciler.IReconciler#install(org.eclipse.jface.text.ITextViewer)
*/
@Override
public void install(ITextViewer textViewer) {
super.install(textViewer);
fPartListener = new PartListener();
IWorkbenchPartSite site = fTextEditor.getSite();
IWorkbenchWindow window = site.getWorkbenchWindow();
window.getPartService().addPartListener(fPartListener);
fActivationListener = new ActivationListener(textViewer.getTextWidget());
Shell shell = window.getShell();
shell.addShellListener(fActivationListener);
fJavaElementChangedListener = new ElementChangedListener();
JavaCore.addElementChangedListener(fJavaElementChangedListener);
fResourceChangeListener = new ResourceChangeListener();
IWorkspace workspace = JavaPlugin.getWorkspace();
workspace.addResourceChangeListener(fResourceChangeListener);
fPropertyChangeListener = new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
if (SpellingService.PREFERENCE_SPELLING_ENABLED.equals(event.getProperty()) || SpellingService.PREFERENCE_SPELLING_ENGINE.equals(event.getProperty()))
forceReconciling();
}
};
JavaPlugin.getDefault().getCombinedPreferenceStore().addPropertyChangeListener(fPropertyChangeListener);
fReconciledElement = EditorUtility.getEditorInputJavaElement(fTextEditor, false);
}Example 34
| Project: Curators-Workbench-master File: SetDivTypeHandler.java View source code |
@Override
public void updateElement(UIElement element, Map parameters) {
String state = (String) parameters.get("org.eclipse.ui.commands.radioStateParameter");
IWorkbenchPartSite site = (IWorkbenchPartSite) parameters.get("org.eclipse.ui.part.IWorkbenchPartSite");
if (site.getId().equals("cdr-workbench.projectview")) {
IStructuredSelection s = (IStructuredSelection) site.getSelectionProvider().getSelection();
if (s.getFirstElement() instanceof DivType) {
DivType div = (DivType) s.getFirstElement();
element.setChecked(div.getTYPE() != null && div.getTYPE().equals(state));
}
}
}Example 35
| Project: dltk.core-master File: ScriptReconciler.java View source code |
@Override
public void install(ITextViewer textViewer) {
super.install(textViewer);
fPartListener = new PartListener();
IWorkbenchPartSite site = fTextEditor.getSite();
IWorkbenchWindow window = site.getWorkbenchWindow();
window.getPartService().addPartListener(fPartListener);
fActivationListener = new ActivationListener(textViewer.getTextWidget());
Shell shell = window.getShell();
shell.addShellListener(fActivationListener);
fScriptElementChangedListener = new ElementChangedListener();
DLTKCore.addElementChangedListener(fScriptElementChangedListener);
fResourceChangeListener = new ResourceChangeListener();
ResourcesPlugin.getWorkspace().addResourceChangeListener(fResourceChangeListener);
final IPreferenceStore store = getCombinedPreferenceStore();
if (store != null) {
fPropertyChangeListener = event -> {
if (SpellingService.PREFERENCE_SPELLING_ENABLED.equals(event.getProperty()) || SpellingService.PREFERENCE_SPELLING_ENGINE.equals(event.getProperty()))
forceReconciling();
};
store.addPropertyChangeListener(fPropertyChangeListener);
}
fReconciledElement = EditorUtility.getEditorInputModelElement(fTextEditor, false);
}Example 36
| Project: eclipse-cocoa-set-represented-filename-master File: CocoaCode.java View source code |
/**
* Set the represented filename for the Cocoa NSWindow associated with the
* active editor to the filename in that editor, or set it to empty string
* if no file is associated.
*
* @param site the workbench part's site.
*/
public void setRepresentedFilename(IWorkbenchPartSite site) {
Shell shell = site.getShell();
if (shell != null) {
NSView view = shell.view;
if (view != null) {
NSWindow w = view.window();
if (w != null) {
// Create the Objective C selector for the method to set the filename,
// and get the filename.
long sel = OS.sel_registerName("setRepresentedFilename:");
NSString fileStr = getFilename(site);
// Set the represented filename.
OS.objc_msgSend(w.id, sel, fileStr.id);
}
}
}
}Example 37
| Project: eclipse.jdt.ui-master File: CodeFormatterTest.java View source code |
private static String format(ICompilationUnit cu, int offset, int length, String actionId) throws PartInitException, JavaModelException {
JavaEditor editorPart = (JavaEditor) EditorUtility.openInEditor(cu);
try {
IWorkbenchPartSite editorSite = editorPart.getSite();
ISelection selection = new TextSelection(offset, length);
editorSite.getSelectionProvider().setSelection(selection);
IAction formatAction = editorPart.getAction(actionId);
formatAction.run();
return cu.getBuffer().getContents();
} finally {
editorPart.close(false);
}
}Example 38
| Project: eclipse.platform.text-master File: RulerColumnDescriptor.java View source code |
/**
* Returns <code>true</code> if this contribution matches the passed editor, <code>false</code> if not.
*
* @param editor the editor to check
* @return <code>true</code> if this contribution targets the passed editor
*/
public boolean matchesEditor(ITextEditor editor) {
Assert.isLegal(editor != null);
RulerColumnTarget target = getTarget();
IWorkbenchPartSite site = editor.getSite();
if (site != null && target.matchesEditorId(site.getId()))
return true;
if (target.matchesClass(editor.getClass()))
return true;
IContentType contentType = getContentType(editor);
return contentType != null && target.matchesContentType(contentType);
}Example 39
| Project: eclipse3-master File: XMLTableTreeActionBarContributor.java View source code |
public void setActiveEditor(IEditorPart targetEditor) {
editorPart = targetEditor;
// IStructuredModel model = getModelForEditorPart(targetEditor);
/*
* reloadGrammarAction.setModel(model);
* toggleAction.setModelQuery(ModelQueryUtil.getModelQuery(model));
*
* XMLTableTreeViewer tableTreeViewer = getTableTreeViewerForEditorPart(editorPart); if
* (tableTreeViewer != null) { expandAction.setViewer(tableTreeViewer);
* collapseAction.setViewer(tableTreeViewer);
*
* xmlMenuExpandAction.setViewer(tableTreeViewer);
* xmlMenuCollapseAction.setViewer(tableTreeViewer); }
*/
ITextEditor textEditor = null;
if (editorPart instanceof XMLMultiPageEditorPart) {
IWorkbenchPartSite site = editorPart.getSite();
if (site instanceof IEditorSite) {
textEditor = ((XMLMultiPageEditorPart) editorPart).getTextEditor();
}
}
actionBars.setGlobalActionHandler(ITextEditorActionConstants.UNDO, getAction(textEditor, ITextEditorActionConstants.UNDO));
actionBars.setGlobalActionHandler(ITextEditorActionConstants.REDO, getAction(textEditor, ITextEditorActionConstants.REDO));
// TODO... uncomment this and investigate NPE
//
// add the cut/copy/paste for text fields
// ActionHandlerPlugin.connectPart(editorPart);
}Example 40
| Project: EclipseTrader-master File: MarketsViewTest.java View source code |
/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
shell = new Shell(Display.getDefault());
ISelectionProvider selectionProvider = EasyMock.createNiceMock(ISelectionProvider.class);
site = EasyMock.createNiceMock(IWorkbenchPartSite.class);
EasyMock.expect(site.getSelectionProvider()).andStubReturn(selectionProvider);
site.registerContextMenu(EasyMock.isA(MenuManager.class), EasyMock.isA(ISelectionProvider.class));
EasyMock.replay(site);
service = new MarketService();
service.addMarket(market = new Market("New York", new ArrayList<MarketTime>()));
}Example 41
| Project: ecommons-ltk-master File: PasteElementsHandler.java View source code |
/**
* {@inheritDoc}
*/
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final ISelection selection = WorkbenchUIUtil.getCurrentSelection(event.getApplicationContext());
if (selection == null) {
return null;
}
final ISourceUnit su = fEditor.getSourceUnit();
if (su == null) {
return null;
}
RefactoringDestination destination = null;
if (selection instanceof IStructuredSelection) {
final IProgressMonitor monitor = new NullProgressMonitor();
final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
final ISourceUnitModelInfo modelInfo = su.getModelInfo(null, IModelManager.MODEL_FILE, monitor);
if (modelInfo == null) {
return null;
}
if (structuredSelection.isEmpty()) {
destination = new RefactoringDestination(modelInfo.getSourceElement());
} else if (structuredSelection.size() == 1) {
final Object object = structuredSelection.getFirstElement();
destination = new RefactoringDestination(object);
}
}
if (destination == null || !destination.isOK()) {
return null;
}
final RefactoringAdapter adapter = fRefactoring.createAdapter(destination);
if (adapter == null) {
return null;
}
final String code = getCodeFromClipboard(event);
if (code == null || code.length() == 0) {
return null;
}
final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
final IWorkbenchPartSite site = activePart.getSite();
final Shell shell = site.getShell();
final IProgressService progressService = (IProgressService) site.getService(IProgressService.class);
try {
final Position position = startInsertRefactoring(code, destination, su, adapter, shell, progressService);
if (position != null && !position.isDeleted()) {
fEditor.selectAndReveal(position.getOffset(), 0);
}
} catch (final InvocationTargetException e) {
StatusManager.getManager().handle(new Status(IStatus.ERROR, adapter.getPluginIdentifier(), -1, Messages.PastingElements_error_message, e.getCause()), StatusManager.LOG | StatusManager.SHOW);
} catch (final InterruptedException e) {
}
return null;
}Example 42
| Project: emul-master File: FSTreeControl.java View source code |
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
*/
@Override
public void selectionChanged(SelectionChangedEvent event) {
IWorkbenchPart parent = getParentPart();
if (parent != null) {
IWorkbenchPartSite site = parent.getSite();
if (site != null) {
ISelectionProvider selectionProvider = site.getSelectionProvider();
if (selectionProvider instanceof MultiPageSelectionProvider) {
// Propagate the selection event to update the selection context.
((MultiPageSelectionProvider) selectionProvider).fireSelectionChanged(event);
}
}
}
}Example 43
| Project: gda-common-rcp-master File: CommandServiceFacade.java View source code |
/**
* Run a preconfigured command.
* @param site
* @param runScanCommandId
* @return null is command cannot be found. The command will return null if
* Eclipse command could not be found. Otherwise the return value of the command handler.
* @throws NotHandledException
* @throws NotEnabledException
* @throws NotDefinedException
* @throws ExecutionException
*/
public static Object runCommand(final IWorkbenchPartSite site, final String runScanCommandId) throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException {
final ICommandService service = (ICommandService) site.getService(ICommandService.class);
final Command run = service.getCommand(runScanCommandId);
if (run != null) {
final Map<String, String> params = new HashMap<String, String>(1);
return run.executeWithChecks(new ExecutionEvent(run, params, site, null));
}
return null;
}Example 44
| Project: gmp.graphiti-master File: ElementDeleteListener.java View source code |
@Override
public void notifyChanged(Notification msg) {
if (T.racer().debug()) {
final String editorName = diagramBehavior.getDiagramContainer().getTitle();
T.racer().debug(//$NON-NLS-1$
"Delete listener called of editor " + editorName + //$NON-NLS-1$
" with events " + //$NON-NLS-1$
msg.toString());
}
final IDiagramEditorInput in = diagramBehavior.getDiagramContainer().getDiagramEditorInput();
if (in != null) {
final IWorkbenchPartSite site = diagramBehavior.getDiagramContainer().getWorkbenchPart().getSite();
if (site == null) {
return;
}
final Shell shell = site.getShell();
// Do the real work, e.g. object retrieval from input and
// closing, asynchronous to not block this listener longer than necessary,
// which may provoke deadlocks.
shell.getDisplay().asyncExec(new Runnable() {
public void run() {
if (diagramBehavior == null) {
// disposed
return;
}
if (shell.isDisposed()) {
// disposed
return;
}
Diagram diagram = null;
try {
diagram = (Diagram) diagramBehavior.getAdapter(Diagram.class);
} catch (final Exception e) {
}
if (diagram == null || EcoreUtil.getRootContainer(diagram) == null) {
// diagram is gone so try to close
if (T.racer().debug()) {
final String editorName = diagramBehavior.getDiagramContainer().getTitle();
T.racer().debug(//$NON-NLS-1$
"Closing editor " + //$NON-NLS-1$
editorName);
}
diagramBehavior.getDiagramContainer().close();
}
}
});
}
}Example 45
| Project: gwtp-eclipse-plugin-master File: CodeFormattingUtil.java View source code |
public void organizeImports(ICompilationUnit unit) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
IWorkbenchPartSite workBenchSite = window.getPartService().getActivePart().getSite();
if (workBenchSite == null) {
return;
}
OrganizeImportsAction organizeImportsAction = new OrganizeImportsAction(workBenchSite);
organizeImportsAction.run(unit);
}Example 46
| Project: HBuilder-opensource-master File: PyMergeViewer.java View source code |
/**
* Overridden to handle backspace (will only be called on Eclipse 3.5)
*/
@Override
protected SourceViewer createSourceViewer(Composite parent, int textOrientation) {
final SourceViewer viewer = super.createSourceViewer(parent, textOrientation);
viewer.appendVerifyKeyListener(PyPeerLinker.createVerifyKeyListener(viewer));
viewer.appendVerifyKeyListener(PyBackspace.createVerifyKeyListener(viewer, null));
IWorkbenchPart workbenchPart = getCompareConfiguration().getContainer().getWorkbenchPart();
//Note that any site should be OK as it's just to know if a keybinding is active.
IWorkbenchPartSite site = null;
if (workbenchPart != null) {
site = workbenchPart.getSite();
} else {
IWorkbenchWindow window = PyAction.getActiveWorkbenchWindow();
if (window != null) {
IWorkbenchPage activePage = window.getActivePage();
if (activePage != null) {
IWorkbenchPart activePart = activePage.getActivePart();
if (activePart != null) {
site = activePart.getSite();
}
}
}
}
VerifyKeyListener createVerifyKeyListener = FirstCharAction.createVerifyKeyListener(viewer, site, true);
if (createVerifyKeyListener != null) {
viewer.appendVerifyKeyListener(createVerifyKeyListener);
}
return viewer;
}Example 47
| Project: mylyn.context-master File: ApplyPatchAction.java View source code |
protected IStatus execute(IProgressMonitor monitor) {
String attachmentFilename = AttachmentUtil.getAttachmentFilename(attachment);
File file = null;
try {
//$NON-NLS-1$ //$NON-NLS-2$
file = File.createTempFile("patch-", ".txt");
} catch (IOException e) {
return new Status(IStatus.ERROR, FocusedTeamUiPlugin.ID_PLUGIN, Messages.ApplyPatchAction_failedToDownloadPatch, e);
}
file.deleteOnExit();
boolean ok = false;
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
AttachmentUtil.downloadAttachment(attachment, fos, monitor);
ok = true;
} catch (IOException e) {
return new Status(IStatus.ERROR, FocusedTeamUiPlugin.ID_PLUGIN, Messages.ApplyPatchAction_failedToDownloadPatch, e);
} catch (CoreException e) {
int s = IStatus.ERROR;
if (e.getStatus() != null && e.getStatus().getCode() == IStatus.CANCEL) {
throw new OperationCanceledException();
}
return new Status(s, FocusedTeamUiPlugin.ID_PLUGIN, Messages.ApplyPatchAction_failedToDownloadPatch, e);
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
if (ok) {
file.delete();
return new Status(IStatus.ERROR, FocusedTeamUiPlugin.ID_PLUGIN, Messages.ApplyPatchAction_failedToDownloadPatch, e);
}
}
}
if (!ok) {
file.delete();
}
}
IWorkbenchPartSite site = wbPart.getSite();
if (site == null) {
return new Status(IStatus.WARNING, FocusedTeamUiPlugin.ID_PLUGIN, Messages.ApplyPatchAction_cannotApplyPatch);
}
final Display disp = site.getWorkbenchWindow().getWorkbench().getDisplay();
if (disp.isDisposed()) {
return new Status(IStatus.WARNING, FocusedTeamUiPlugin.ID_PLUGIN, Messages.ApplyPatchAction_cannotApplyPatch);
}
final AttachmentFileStorage fileStorage = new AttachmentFileStorage(file, attachmentFilename);
disp.asyncExec(new Runnable() {
public void run() {
ApplyPatchOperation op = new ApplyPatchOperation(wbPart, fileStorage, null, new CompareConfiguration());
BusyIndicator.showWhile(disp, op);
}
});
return Status.OK_STATUS;
}Example 48
| Project: ocl-master File: ShowValidityViewHandler.java View source code |
public Object execute(ExecutionEvent event) throws ExecutionException {
Object applicationContext = event.getApplicationContext();
Object editorPart = HandlerUtil.getVariable(applicationContext, ISources.ACTIVE_EDITOR_NAME);
Object shell = HandlerUtil.getVariable(applicationContext, ISources.ACTIVE_SHELL_NAME);
if (!(shell instanceof Shell) || !(editorPart instanceof EditorPart)) {
return null;
}
EditorPart editorPartInstance = (EditorPart) editorPart;
IWorkbenchPartSite site = editorPartInstance.getSite();
updateValidityView(site, true, true);
return null;
}Example 49
| Project: org.eclipse.bpel-master File: BPELMultiPageEditorActionBarContributor.java View source code |
/*
* (non-JavaDoc) Method declared in
* AbstractMultiPageEditorActionBarContributor.
*/
@Override
public void setActivePage(IEditorPart part) {
if (activeEditorPart == part)
return;
activeEditorPart = part;
IActionBars actionBars = getActionBars();
if (activeEditorPart != null && activeEditorPart instanceof ITextEditor) {
IActionBars siteActionBars = ((IEditorSite) activeEditorPart.getEditorSite()).getActionBars();
siteActionBars.setGlobalActionHandler(ITextEditorActionConstants.UNDO, getAction((ITextEditor) activeEditorPart, ITextEditorActionConstants.UNDO));
siteActionBars.setGlobalActionHandler(ITextEditorActionConstants.REDO, getAction((ITextEditor) activeEditorPart, ITextEditorActionConstants.REDO));
siteActionBars.updateActionBars();
} else {
if (part instanceof BPELEditor) {
bpelEditor = (BPELEditor) part;
}
if (bpelEditor != null) {
Object adapter = bpelEditor.getAdapter(ActionRegistry.class);
if (adapter instanceof ActionRegistry) {
ActionRegistry registry = (ActionRegistry) adapter;
// COPY
IAction action = registry.getAction(BPELCopyAction.ID);
actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), action);
// CUT
action = registry.getAction(BPELCutAction.ID);
actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(), action);
// PASTE
action = registry.getAction(BPELPasteAction.ID);
actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), action);
// DELETE
action = registry.getAction(BPELDeleteAction.ID);
actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), action);
}
IWorkbenchPartSite site = bpelEditor.getSite();
if (site instanceof IEditorSite) {
ITextEditor textEditor = bpelEditor.getMultipageEditor().getTextEditor();
IActionBars siteActionBars = ((IEditorSite) site).getActionBars();
siteActionBars.setGlobalActionHandler(ITextEditorActionConstants.UNDO, getAction(textEditor, ITextEditorActionConstants.UNDO));
siteActionBars.setGlobalActionHandler(ITextEditorActionConstants.REDO, getAction(textEditor, ITextEditorActionConstants.REDO));
siteActionBars.updateActionBars();
}
}
}
if (actionBars != null) {
// update menu bar and tool bar
actionBars.updateActionBars();
}
}Example 50
| Project: org.eclipse.dltk.core-master File: SemanticHighlightingReconciler.java View source code |
/**
* Update the presentation.
*
* @param textPresentation
* the text presentation
* @param addedPositions
* the added positions
* @param removedPositions
* the removed positions
*/
private void updatePresentation(TextPresentation textPresentation, HighlightedPosition[] addedPositions, HighlightedPosition[] removedPositions) {
Runnable runnable = fJobPresenter.createUpdateRunnable(textPresentation, addedPositions, removedPositions);
if (runnable == null)
return;
ScriptEditor editor = fEditor;
if (editor == null)
return;
IWorkbenchPartSite site = editor.getSite();
if (site == null)
return;
Shell shell = site.getShell();
if (shell == null || shell.isDisposed())
return;
Display display = shell.getDisplay();
if (display == null || display.isDisposed())
return;
display.asyncExec(runnable);
}Example 51
| Project: PTP-master File: ResumeAtLineActionDelegate.java View source code |
protected void update() {
if (fAction == null) {
return;
}
boolean enabled = false;
if (fPartTarget != null && fTargetElement != null) {
IWorkbenchPartSite site = fActivePart.getSite();
if (site != null) {
ISelectionProvider selectionProvider = site.getSelectionProvider();
if (selectionProvider != null) {
ISelection selection = selectionProvider.getSelection();
enabled = fTargetElement.isSuspended() && fPartTarget.canResumeAtLine(fActivePart, selection, fTargetElement);
}
}
}
fAction.setEnabled(enabled);
}Example 52
| Project: Pydev-master File: BaseDebugView.java View source code |
@Override
public void createPartControl(Composite parent) {
IViewSite viewSite = getViewSite();
if (viewSite != null) {
configureToolBar(viewSite);
}
parent.setLayout(new GridLayout(1, true));
viewer = new TreeViewer(parent);
provider = createContentProvider();
viewer.setContentProvider(provider);
viewer.setLabelProvider(new PyDebugModelPresentation(false));
GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getTree());
MenuManager menuManager = new MenuManager();
Menu menu = menuManager.createContextMenu(viewer.getTree());
viewer.getTree().setMenu(menu);
IWorkbenchPartSite site = getSite();
site.registerContextMenu(menuManager, viewer);
site.setSelectionProvider(viewer);
this.parent = parent;
listener = createListener();
if (listener != null) {
DebugPlugin plugin = DebugPlugin.getDefault();
ILaunchManager launchManager = plugin.getLaunchManager();
launchManager.addLaunchListener(listener);
plugin.addDebugEventListener(listener);
}
}Example 53
| Project: ArchStudio5-master File: SWTWidgetUtils.java View source code |
private static void _setupContextMenu(String name, Control c, Object site, IMenuFiller filler) {
MenuManager menuMgr = new MenuManager(name);
menuMgr.setRemoveAllWhenShown(true);
final IMenuFiller ffiller = filler;
menuMgr.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager m) {
ffiller.fillMenu(m);
}
});
Menu contextMenu = menuMgr.createContextMenu(c);
c.setMenu(contextMenu);
if (site != null) {
if (site instanceof IPageSite) {
((IPageSite) site).registerContextMenu(name, menuMgr, ((IPageSite) site).getSelectionProvider());
} else if (site instanceof IWorkbenchPartSite) {
((IWorkbenchPartSite) site).registerContextMenu(name, menuMgr, ((IWorkbenchPartSite) site).getSelectionProvider());
}
}
}Example 54
| Project: CAL-Eclipse-Plug-in-master File: RenameViewAction.java View source code |
/* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
public void run(IAction action) {
try {
final IWorkbenchPartSite site = activePart.getSite();
final ISelection selection = site.getSelectionProvider().getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object selectedObject = structuredSelection.getFirstElement();
Name oldName = null;
String initValue = null;
SourceIdentifier.Category category;
if (selectedObject instanceof ScopedEntity) {
ScopedEntity scopedEntity = (ScopedEntity) selectedObject;
oldName = scopedEntity.getName();
initValue = scopedEntity.getName().getUnqualifiedName();
}
CALModelManager cmm = CALModelManager.getCALModelManager();
if (selectedObject instanceof Function) {
category = SourceIdentifier.Category.TOP_LEVEL_FUNCTION_OR_CLASS_METHOD;
} else if (selectedObject instanceof TypeClass) {
category = SourceIdentifier.Category.TYPE_CLASS;
} else if (selectedObject instanceof TypeConstructor) {
category = SourceIdentifier.Category.TYPE_CONSTRUCTOR;
} else if (selectedObject instanceof DataConstructor) {
category = SourceIdentifier.Category.DATA_CONSTRUCTOR;
} else if (selectedObject instanceof ModuleName) {
ModuleName moduleName = (ModuleName) selectedObject;
oldName = moduleName;
category = SourceIdentifier.Category.MODULE_NAME;
initValue = moduleName.toSourceText();
} else if (selectedObject instanceof IFile) {
ModuleName moduleName = cmm.getModuleName((IFile) selectedObject);
oldName = moduleName;
category = SourceIdentifier.Category.MODULE_NAME;
initValue = moduleName.toSourceText();
} else {
oldName = null;
category = null;
assert false;
return;
}
CompilerMessageLogger messageLogger = new MessageLogger();
RenameAction.performRename(site.getShell(), cmm, messageLogger, oldName, initValue, category);
CoreUtility.showErrors(ActionMessages.RenameAction_windowTitle, ActionMessages.RenameAction_failed, messageLogger);
}
} catch (Exception e) {
CALEclipseUIPlugin.log(new Status(IStatus.ERROR, CALEclipseUIPlugin.PLUGIN_ID, IStatus.OK, "", e));
}
}Example 55
| Project: damp.ekeko.snippets-master File: OperatorOperandsViewer.java View source code |
public void updateWorkbenchStatusErrorLine(String message) {
IWorkbenchPartSite site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite();
//TODO: figure out nicer way to get to the site of the view in which this viewer is embedded
IActionBars actionBars;
if (site instanceof IViewSite) {
IViewSite viewSite = (IViewSite) site;
actionBars = viewSite.getActionBars();
} else {
IEditorSite editorSite = (IEditorSite) site;
actionBars = editorSite.getActionBars();
}
IStatusLineManager statusLineManager = actionBars.getStatusLineManager();
statusLineManager.setErrorMessage(message);
}Example 56
| Project: Diver-master File: RevealInThreadContribution.java View source code |
/**
* @return
*/
private ITraceModel getActiveSelection() {
IWorkbenchPartSite site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite();
ISelection selection = site.getSelectionProvider().getSelection();
if (selection instanceof IStructuredSelection) {
return getTraceModelForSelection((IStructuredSelection) selection);
}
return null;
}Example 57
| Project: ecf-master File: EditorCompoundContributionItem.java View source code |
protected ITextSelection getSelection() {
final IEditorPart ep = getEditorPart();
if (ep == null)
return null;
final IWorkbenchPartSite ws = ep.getEditorSite();
if (ws == null)
return null;
final ISelectionProvider sp = ws.getSelectionProvider();
if (sp == null)
return null;
final ISelection sel = sp.getSelection();
if (sel == null || !(sel instanceof ITextSelection))
return null;
return (ITextSelection) sel;
}Example 58
| Project: ecf-nonepl-master File: EditorCompoundContributionItem.java View source code |
protected ITextSelection getSelection() {
final IEditorPart ep = getEditorPart();
if (ep == null)
return null;
final IWorkbenchPartSite ws = ep.getEditorSite();
if (ws == null)
return null;
final ISelectionProvider sp = ws.getSelectionProvider();
if (sp == null)
return null;
final ISelection sel = sp.getSelection();
if (sel == null || !(sel instanceof ITextSelection))
return null;
return (ITextSelection) sel;
}Example 59
| Project: eclipse-gov.redhawk.core-master File: PortHelper.java View source code |
public static boolean executeCommand(final IWorkbenchPartSite site, final String commandId, final Map<String, String> paramMap, final String varName, final Object variable) throws CommandException {
final IHandlerService handlerService = (IHandlerService) site.getService(IHandlerService.class);
final ICommandService commandService = (ICommandService) site.getService(ICommandService.class);
if ((handlerService == null) || (commandService == null)) {
return false;
}
final ParameterizedCommand pcmd;
final ExecutionEvent evt;
final Command cmd = commandService.getCommand(commandId);
if (cmd == null) {
return false;
}
if (paramMap != null) {
pcmd = ParameterizedCommand.generateCommand(cmd, paramMap);
evt = handlerService.createExecutionEvent(pcmd, null);
} else {
pcmd = null;
evt = handlerService.createExecutionEvent(cmd, null);
}
if (varName != null) {
((IEvaluationContext) evt.getApplicationContext()).addVariable(varName, variable);
}
if (pcmd != null) {
pcmd.executeWithChecks(evt.getTrigger(), evt.getApplicationContext());
} else {
cmd.executeWithChecks(evt);
}
return true;
}Example 60
| Project: eclipse.jdt.debug-master File: ExceptionInspector.java View source code |
/**
* @see org.eclipse.debug.ui.contexts.IDebugContextListener#debugContextChanged(org.eclipse.debug.ui.contexts.DebugContextEvent)
*/
@Override
public void debugContextChanged(DebugContextEvent event) {
if ((event.getFlags() & DebugContextEvent.ACTIVATED) > 0) {
IWorkbenchPart part = event.getDebugContextProvider().getPart();
if (part != null) {
IWorkbenchPartSite site = part.getSite();
if (site != null && IDebugUIConstants.ID_DEBUG_VIEW.equals(site.getId())) {
IWorkbenchPage page = site.getWorkbenchWindow().getActivePage();
if (page != null && page.isPartVisible(part)) {
ISelection selection = event.getContext();
if (selection instanceof IStructuredSelection) {
IStructuredSelection ss = (IStructuredSelection) selection;
if (ss.size() == 1) {
Object firstElement = ss.getFirstElement();
if (firstElement instanceof IAdaptable) {
IJavaStackFrame frame = ((IAdaptable) firstElement).getAdapter(IJavaStackFrame.class);
if (frame != null) {
IJavaThread thread = (IJavaThread) frame.getThread();
try {
if (frame.equals(thread.getTopStackFrame())) {
IBreakpoint[] breakpoints = thread.getBreakpoints();
if (breakpoints.length == 1) {
if (breakpoints[0] instanceof IJavaExceptionBreakpoint) {
IJavaExceptionBreakpoint exception = (IJavaExceptionBreakpoint) breakpoints[0];
IJavaObject lastException = ((JavaExceptionBreakpoint) exception).getLastException();
if (lastException != null) {
IExpression exp = new JavaInspectExpression(exception.getExceptionTypeName(), lastException);
Tree tree = (Tree) ((IDebugView) part).getViewer().getControl();
TreeItem[] selection2 = tree.getSelection();
Rectangle bounds = selection2[0].getBounds();
Point point = tree.toDisplay(bounds.x, bounds.y + bounds.height);
InspectPopupDialog dialog = new InspectPopupDialog(part.getSite().getShell(), point, PopupInspectAction.ACTION_DEFININITION_ID, exp);
dialog.open();
}
}
}
}
} catch (DebugException e) {
}
}
}
}
}
}
}
}
}
}Example 61
| Project: eu.geclipse.core-master File: JobDetailsView.java View source code |
/**
* Refresh view - may be called from any thread
*
*/
private void scheduleRefresh() {
IWorkbenchPartSite site = this.getSite();
if (site != null) {
Shell shell = site.getShell();
if (shell != null) {
Display display = shell.getDisplay();
if (display != null && !display.isDisposed()) {
display.asyncExec(new Runnable() {
public void run() {
refresh();
}
});
}
}
}
}Example 62
| Project: gmf-runtime-master File: TextAlignmentTests.java View source code |
public void closeWelcome() {
IWorkbench workbench = PlatformUI.getWorkbench();
if (workbench != null) {
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
if (workbenchWindow != null) {
IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
if (workbenchPage != null) {
IWorkbenchPart workbenchPart = workbenchPage.getActivePart();
if (workbenchPart != null) {
IWorkbenchPartSite workbenchPartSite = workbenchPart.getSite();
if (workbenchPartSite != null) {
if (workbenchPartSite.getId().equals("org.eclipse.ui.internal.introview")) {
IViewPart welcomeView = (IViewPart) workbenchPart;
workbenchPage.hideView(welcomeView);
}
}
}
}
}
}
}Example 63
| Project: jactr-eclipse-master File: FormattingTextOperationAction.java View source code |
/**
* The <code>TextOperationAction</code> implementation of this
* <code>IAction</code> method runs the operation with the current operation
* code.
*/
@Override
public void run() {
if (fOperationCode == -1 || fOperationTarget == null)
return;
ITextEditor editor = getTextEditor();
if (editor == null)
return;
if (!fRunsOnReadOnly && !validateEditorInputState())
return;
Display display = null;
IWorkbenchPartSite site = editor.getSite();
Shell shell = site.getShell();
if (shell != null && !shell.isDisposed())
display = shell.getDisplay();
BusyIndicator.showWhile(display, new Runnable() {
public void run() {
fOperationTarget.doOperation(fOperationCode);
if (fOperationTarget.canDoOperation(ISourceViewer.FORMAT))
fOperationTarget.doOperation(ISourceViewer.FORMAT);
}
});
}Example 64
| Project: jubula.core-master File: CommandHelper.java View source code |
/**
* Execute the given commmandId using the given part site for handler
* service retrievement
*
* @param commandID
* the command to execute
* @param site
* the site to get the handler service from; may be <code>null</code>
* @return The return value from the execution; may be null.
*/
public static Object executeCommand(String commandID, IWorkbenchPartSite site) {
IHandlerService handlerService;
if (site != null) {
handlerService = site.getService(IHandlerService.class);
} else {
handlerService = getHandlerService();
}
try {
return handlerService.executeCommand(commandID, null);
} catch (CommandException e) {
log.warn(Messages.ErrorOccurredWhileExecutingCommand + StringConstants.COLON + StringConstants.SPACE + commandID);
}
return null;
}Example 65
| Project: liferay-ide-master File: FormatResourceAction.java View source code |
/*
* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
public void run(IAction action) {
IWorkbenchPartSite site = _part.getSite();
provider = site.getSelectionProvider();
if (_selected == null) {
MessageDialog.openInformation(new Shell(), "VelocityPlugin", "Unable to open file");
// VelocityPlugin.log("Unable to open file");
return;
}
if (_selected instanceof IStructuredSelection) {
//
try {
Object[] items = ((IStructuredSelection) _selected).toArray();
Set files = new HashSet(items.length, 1.0F);
try {
for (int i = 0; i < items.length; i++) {
if (items[i] instanceof IResource) {
IResource resource = (IResource) items[i];
switch(resource.getType()) {
case IResource.FOLDER:
case IResource.PROJECT:
IContainer folder = (IContainer) items[i];
getChildren(folder, files);
break;
case IResource.FILE:
files.add((IFile) items[i]);
// ((IFile) items[i]).getProject()
break;
default:
/**
* @todo use logger to print warning about
* invalid type
*/
break;
}
}
}
} catch (CoreException ex) {
ex.printStackTrace();
}
for (Iterator iter = files.iterator(); iter.hasNext(); ) {
IFile directory = (IFile) iter.next();
formatFile(directory);
}
} catch (Exception e) {
VelocityPlugin.log(e);
}
} else {
MessageDialog.openInformation(new Shell(), "VelocityPlugin", "Unable to open file");
// VelocityPlugin.log("Unable to open shell");
return;
}
}Example 66
| Project: m2eclipse-hudson-master File: StatusLineCLabelContribution.java View source code |
/*
* From org.eclipse.equinox.internal.p2.ui.sdk.scheduler.AutomaticUpdater
*/
IStatusLineManager getStatusLineManager() {
if (statusLineManager != null)
return statusLineManager;
IWorkbenchWindow activeWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (activeWindow == null)
return null;
try {
//$NON-NLS-1$
Method method = activeWindow.getClass().getDeclaredMethod("getStatusLineManager", new Class[0]);
try {
Object statusLine = method.invoke(activeWindow, new Object[0]);
if (statusLine instanceof IStatusLineManager) {
statusLineManager = (IStatusLineManager) statusLine;
return statusLineManager;
}
} catch (InvocationTargetException e) {
log.error("Could not find getStatusLineManagerMethod", e);
} catch (IllegalAccessException e) {
log.error("Could not find getStatusLineManagerMethod", e);
}
} catch (NoSuchMethodException e) {
log.error("Could not find getStatusLineManagerMethod", e);
}
IWorkbenchPartSite site = activeWindow.getActivePage().getActivePart().getSite();
if (site instanceof IViewSite) {
statusLineManager = ((IViewSite) site).getActionBars().getStatusLineManager();
} else if (site instanceof IEditorSite) {
statusLineManager = ((IEditorSite) site).getActionBars().getStatusLineManager();
}
return statusLineManager;
}Example 67
| Project: modellipse-master File: PapyrusModelActionProvider.java View source code |
private void makeActions() {
final IWorkbenchPartSite provider = workbenchSite.getSite();
final ActionHelper helper = new ActionHelper();
openAction = new Action() {
@Override
public void run() {
if (getIFile() != null) {
try {
IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), getIFile(), true);
} catch (WorkbenchException e) {
}
}
}
public IFile getIFile() {
return helper.getIFile(getContext());
}
@Override
public boolean isEnabled() {
return getIFile() != null;
}
@Override
public String getText() {
return IDEWorkbenchMessages.OpenFileAction_text;
}
};
deleteAction = new DeleteResourceAction(provider) {
@Override
public boolean isEnabled() {
return getSelectedResources() != null && getSelectedResources().size() > 0 && OneFileUtils.isDi((IResource) getSelectedResources().get(0));
}
@Override
public IStructuredSelection getStructuredSelection() {
return helper.getOneStructuredSelection(getContext());
}
@Override
protected List getSelectedResources() {
return helper.getOneSelectedResources(getContext());
}
};
moveAction = new MoveResourceAction(provider) {
@Override
public IStructuredSelection getStructuredSelection() {
return helper.getStructuredSelection(getContext());
}
@Override
protected List getSelectedResources() {
return helper.getSelectedResources(getContext());
}
};
copyAction = new CopyResourceAction(provider) {
@Override
public IStructuredSelection getStructuredSelection() {
return helper.getStructuredSelection(getContext());
}
@Override
protected List getSelectedResources() {
return helper.getSelectedResources(getContext());
}
};
renameAction = new RenameResourceAction(provider) {
@Override
public IStructuredSelection getStructuredSelection() {
IStructuredSelection selec = helper.getOneStructuredSelection(getContext());
return selec != null ? selec : super.getStructuredSelection();
}
@Override
protected List getSelectedResources() {
return helper.getOneSelectedResources(getContext());
}
};
refreshAction = new RefreshAction(provider) {
@Override
public void run() {
super.run();
}
};
makeAction(openAction, ICommonActionConstants.OPEN, ISharedImages.IMG_TOOL_COPY, ISharedImages.IMG_TOOL_COPY_DISABLED);
makeAction(deleteAction, IWorkbenchCommandConstants.EDIT_DELETE, ISharedImages.IMG_TOOL_DELETE, ISharedImages.IMG_TOOL_DELETE_DISABLED);
makeAction(moveAction, ActionFactory.MOVE.getId(), null, null);
makeAction(copyAction, IWorkbenchCommandConstants.EDIT_CUT, ISharedImages.IMG_TOOL_CUT, ISharedImages.IMG_TOOL_CUT_DISABLED);
makeAction(copyAction, IWorkbenchCommandConstants.EDIT_COPY, ISharedImages.IMG_TOOL_COPY, ISharedImages.IMG_TOOL_COPY_DISABLED);
makeAction(refreshAction, ActionFactory.REFRESH.getCommandId(), null, null);
}Example 68
| Project: org.eclipse.wst.sse.sieditor-master File: SIEditorService.java View source code |
private void setReadOnlyStatusMessage(IEditorPart editorPart) {
if (editorPart != null) {
IEditorInput editorInput = editorPart.getEditorInput();
if (editorModeMap.containsKey(editorInput)) {
IWorkbenchPartSite site = editorPart.getSite();
if (site instanceof IEditorSite) {
IActionBars actionBars = ((IEditorSite) site).getActionBars();
if (actionBars == null)
return;
IStatusLineManager statusLineManager = actionBars.getStatusLineManager();
if (statusLineManager == null)
return;
statusLineManager.setMessage(Messages.SIEditorService_status_line_read_only);
}
}
}
}Example 69
| Project: pmd-eclipse-plugin-master File: CPDCheckProjectAction.java View source code |
/*
* @see org.eclipse.ui.IActionDelegate#run(IAction)
*/
public void run(final IAction action) {
// NOPMD:UnusedFormalParameter
final IWorkbenchPartSite site = targetPartSite();
final ISelection sel = site.getSelectionProvider().getSelection();
final Shell shell = site.getShell();
final String[] languages = LanguageFactory.supportedLanguages;
final String[] formats = { SIMPLE_KEY, XML_KEY, CSV_KEY };
final CPDCheckDialog dialog = new CPDCheckDialog(shell, languages, formats);
if (dialog.open() == Dialog.OK && sel instanceof IStructuredSelection) {
final StructuredSelection ss = (StructuredSelection) sel;
final Iterator<?> i = ss.iterator();
while (i.hasNext()) {
final Object obj = i.next();
if (obj instanceof IAdaptable) {
final IAdaptable adaptable = (IAdaptable) obj;
final IProject project = (IProject) adaptable.getAdapter(IProject.class);
if (project == null) {
log.warn("The selected object cannot adapt to a project");
log.debug(" -> selected object : " + obj);
} else {
this.detectCutAndPaste(project, dialog);
}
} else {
log.warn("The selected object is not adaptable");
log.debug(" -> selected object : " + obj);
}
}
}
}Example 70
| Project: sling-master File: StatusLineUtils.java View source code |
private static IStatusLineManager getStatusLineManager() {
IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (activeWorkbenchWindow == null) {
return null;
}
IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
if (activePage == null) {
return null;
}
IEditorPart activeEditor = activePage.getActiveEditor();
if (activeEditor != null) {
return activeEditor.getEditorSite().getActionBars().getStatusLineManager();
}
IViewReference[] viewRefs = activePage.getViewReferences();
if (viewRefs != null) {
for (IViewReference aViewRef : viewRefs) {
IViewPart view = aViewRef.getView(false);
if (view != null) {
return view.getViewSite().getActionBars().getStatusLineManager();
}
}
}
IEditorReference[] editorRefs = activePage.getEditorReferences();
if (editorRefs != null) {
for (IEditorReference anEditorRef : editorRefs) {
IEditorPart editor = anEditorRef.getEditor(false);
if (editor != null) {
return editor.getEditorSite().getActionBars().getStatusLineManager();
}
}
}
IWorkbenchPart activePart = activePage.getActivePart();
if (activePart == null) {
return null;
}
IWorkbenchPartSite site = activePart.getSite();
if (site instanceof IEditorSite) {
IEditorSite editorSite = (IEditorSite) site;
return editorSite.getActionBars().getStatusLineManager();
} else if (site instanceof IViewSite) {
IViewSite viewSite = (IViewSite) site;
return viewSite.getActionBars().getStatusLineManager();
} else {
return null;
}
}Example 71
| Project: statet-master File: RElementNameVariableResolver.java View source code |
@Override
public String resolveValue(final IDynamicVariable variable, final String argument) throws CoreException {
final IWorkbenchPart part = UIAccess.getActiveWorkbenchPart(false);
if (part != null) {
final IWorkbenchPartSite site = part.getSite();
final ISelectionProvider selectionProvider = site.getSelectionProvider();
if (selectionProvider != null) {
final ISelection selection = selectionProvider.getSelection();
if (selection instanceof IStructuredSelection) {
final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
if (selection.isEmpty()) {
throw new CoreException(new Status(IStatus.ERROR, RUI.PLUGIN_ID, NLS.bind(Messages.Variable_error_EmptySelection_message, R_OBJECT_NAME_NAME)));
}
if (structuredSelection.size() == 1) {
final Object element = structuredSelection.getFirstElement();
if (element instanceof IRElement) {
final IElementName elementName;
if (selection instanceof IElementNameProvider) {
elementName = ((IElementNameProvider) selection).getElementName((selection instanceof ITreeSelection) ? ((ITreeSelection) selection).getPaths()[0] : element);
} else {
elementName = ((IRElement) element).getElementName();
}
return checkName(elementName);
}
}
final IModelElement[] elements = LTKSelectionUtil.getSelectedElements((IStructuredSelection) selection);
if (elements != null && elements.length == 1 && elements[0].getModelTypeId() == RModel.TYPE_ID) {
return checkName(elements[0].getElementName());
}
throw new CoreException(new Status(IStatus.ERROR, RUI.PLUGIN_ID, NLS.bind(Messages.Variable_error_NoSingleRElement_message, R_OBJECT_NAME_NAME)));
}
}
final ISourceEditor editor = (ISourceEditor) part.getAdapter(ISourceEditor.class);
if (editor instanceof IRSourceEditor) {
try {
final IRSourceEditor rEditor = (IRSourceEditor) editor;
final Point range = rEditor.getViewer().getSelectedRange();
final String contentType = TextUtils.getContentType(rEditor.getViewer().getDocument(), rEditor.getDocumentContentInfo(), range.x, (range.y == 0));
final RAssistInvocationContext context = new RAssistInvocationContext(rEditor, new Region(range.x, range.y), contentType, null, null);
return checkName(context.getNameSelection());
} catch (final BadPartitioningExceptionBadLocationException | e) {
}
}
}
throw new CoreException(new Status(IStatus.ERROR, RUI.PLUGIN_ID, NLS.bind(Messages.Variable_error_NoSingleRElement_message, R_OBJECT_NAME_NAME)));
}Example 72
| Project: Symfony-2-Eclipse-Plugin-master File: XmlHyperlinkDetector.java View source code |
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
IDocument document = textViewer.getDocument();
int offset = region.getOffset();
ITextFileBuffer textFileBuffer = FileBuffersPlugin.getDefault().getFileBufferManager().getTextFileBuffer(document);
if (textFileBuffer == null || textFileBuffer.getFileStore() == null) {
return null;
}
try {
if (PHP_SOURCE.equals(textFileBuffer.getContentType().getId())) {
// PHP Editor is resolved as XML due WTP extension
return null;
}
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(textFileBuffer.getFileStore().toURI(), IWorkspaceRoot.INCLUDE_HIDDEN);
if (files == null || files.length != 1 || files[0].getProject() == null || !files[0].getProject().hasNature(PHPNature.ID)) {
return null;
}
IDLTKSearchScope scope = SearchEngine.createSearchScope(DLTKCore.create(files[0].getProject()));
IRegion wordRegion = findWord(document, offset);
if (wordRegion == null)
return null;
String path = document.get(wordRegion.getOffset(), wordRegion.getLength());
PHPModelAccess model = PHPModelAccess.getDefault();
if (path == null || path.length() == 0) {
return null;
}
IType[] types = model.findTypes(path, MatchRule.EXACT, 0, 0, scope, new NullProgressMonitor());
IWorkbenchPartSite site = Workbench.getInstance().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getSite();
if (types.length > 10) {
Logger.debugMSG("Found more than ten (" + types.length + ") types during xml hyperlink detection...");
return null;
}
if (types != null && types.length > 0) {
IHyperlink[] links = new IHyperlink[types.length];
for (int i = 0; i < types.length; i++) {
links[i] = new ModelElementHyperlink(wordRegion, types[i], new OpenAction(site));
}
return links;
}
} catch (Exception e) {
Logger.logException(e);
}
return null;
}Example 73
| Project: textuml-master File: SourceEditor.java View source code |
public void format() {
Display display = null;
IWorkbenchPartSite site = getSite();
Shell shell = site.getShell();
if (shell != null && !shell.isDisposed())
display = shell.getDisplay();
BusyIndicator.showWhile(display, new Runnable() {
public void run() {
doFormat();
}
});
}Example 74
| Project: tmdm-studio-se-master File: RenameViewAction.java View source code |
private RenameViewDialog getRenameDialog(String oldName) {
RenameViewDialog dialog = null;
IWorkbenchPartSite site = commonViewer.getCommonNavigator().getSite();
if (RepositoryTransformUtil.getInstance().getViewType(oldName) == TYPE_WEBFILTER) {
dialog = new RenameViewDialog(getShell(), Messages.RenameObjectAction_rename, Messages.Common_rename, oldName.substring(PREFIX_VIEW_UPPER.length()), getInputValidator(), site);
} else {
dialog = new RenameViewDialog2(getShell(), Messages.RenameObjectAction_rename, Messages.Common_rename, oldName, getInputValidator(), site);
}
return dialog;
}Example 75
| Project: BPMN2-Editor-for-Eclipse-master File: BPMN2Editor.java View source code |
public void showErrorMessage(String msg) {
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = win.getActivePage();
IWorkbenchPart part = page.getActivePart();
IWorkbenchPartSite site = part.getSite();
IViewSite vSite = (IViewSite) site;
IActionBars actionBars = vSite.getActionBars();
if (actionBars == null)
return;
IStatusLineManager statusLineManager = actionBars.getStatusLineManager();
if (statusLineManager == null)
return;
statusLineManager.setErrorMessage(msg);
statusLineManager.markDirty();
statusLineManager.update(true);
}Example 76
| Project: Eclipse-EGit-master File: GitVariableResolver.java View source code |
private IResource getSelectedResource() {
IResource resource = null;
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow window = null;
if (workbench != null)
window = workbench.getActiveWorkbenchWindow();
if (window != null) {
IWorkbenchPage page = window.getActivePage();
if (page != null) {
IWorkbenchPart part = page.getActivePart();
if (part instanceof IEditorPart) {
IEditorPart epart = (IEditorPart) part;
resource = AdapterUtils.adaptToAnyResource(epart.getEditorInput());
} else if (part != null) {
IWorkbenchPartSite site = part.getSite();
if (site != null) {
ISelectionProvider provider = site.getSelectionProvider();
if (provider != null) {
ISelection selection = provider.getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection ss = (IStructuredSelection) selection;
if (!ss.isEmpty()) {
Iterator iterator = ss.iterator();
while (iterator.hasNext() && resource == null) {
Object next = iterator.next();
resource = AdapterUtils.adaptToAnyResource(next);
}
}
}
}
}
}
}
}
return resource;
}Example 77
| Project: eclipse.platform.debug-master File: DetailPaneProxy.java View source code |
/**
* Finds or creates an initialized detail pane with the given ID. Asks the detail
* pane to create the control and display the selection.
*
* @param paneID the ID of the pane to display in
* @param selection the selection to display
*/
private void setupPane(String paneID, IStructuredSelection selection) {
try {
fParentContainer.getParentComposite().setRedraw(false);
if (fCurrentPane != null) {
fCurrentPane.dispose();
}
if (fCurrentControl != null && !fCurrentControl.isDisposed()) {
fCurrentControl.dispose();
}
fCurrentPane = null;
fCurrentPane = DetailPaneManager.getDefault().getDetailPaneFromID(paneID);
if (fCurrentPane != null) {
final IWorkbenchPartSite workbenchPartSite = fParentContainer.getWorkbenchPartSite();
fCurrentPane.init(workbenchPartSite);
IDetailPane3 saveable = getSaveable();
if (saveable != null) {
for (IPropertyListener iPropertyListener : fListeners) {
saveable.addPropertyListener(iPropertyListener);
}
}
fCurrentControl = fCurrentPane.createControl(fParentContainer.getParentComposite());
if (fCurrentControl != null) {
fParentContainer.getParentComposite().layout(true);
fCurrentPane.display(selection);
if (fParentContainer instanceof IDetailPaneContainer2) {
fCurrentControl.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
updateSelectionProvider(true);
}
@Override
public void focusLost(FocusEvent e) {
updateSelectionProvider(false);
}
});
}
} else {
createErrorLabel(DetailMessages.DetailPaneProxy_0);
DebugUIPlugin.log(new CoreException(new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), MessageFormat.format(DetailMessages.DetailPaneProxy_2, new Object[] { fCurrentPane.getID() }))));
}
} else {
createErrorLabel(DetailMessages.DetailPaneProxy_0);
DebugUIPlugin.log(new CoreException(new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), MessageFormat.format(DetailMessages.DetailPaneProxy_3, new Object[] { paneID }))));
}
} finally {
fParentContainer.getParentComposite().setRedraw(true);
}
}Example 78
| Project: eclipse.platform.swt-master File: LauncherView.java View source code |
/**
* Runs the specified launch item.
*
* @param itemDescriptor the launch item to execute
*/
private void launchItem(ItemDescriptor itemDescriptor) {
/* Case 1: The launch item is a view */
String pluginViewId = itemDescriptor.getView();
if (pluginViewId != null) {
final IWorkbenchPart workbenchPart = this;
final IWorkbenchPartSite workbenchPartSite = workbenchPart.getSite();
final IWorkbenchPage workbenchPage = workbenchPartSite.getPage();
try {
workbenchPage.showView(pluginViewId);
} catch (PartInitException e) {
LauncherPlugin.logError(LauncherPlugin.getResourceString("run.error.Invocation"), e);
}
return;
}
/* Case 2: The launch item is a standalone program */
if (workbenchShell == null)
return;
try {
Object instance = itemDescriptor.createItemInstance();
if (instance != null) {
Display display = workbenchShell.getDisplay();
Method openMethod = instance.getClass().getDeclaredMethod("open", new Class[] { Display.class });
openMethod.invoke(instance, display);
}
} catch (NoSuchMethodException e) {
LauncherPlugin.logError(LauncherPlugin.getResourceString("run.error.DoesNotImplementMethod"), null);
} catch (Exception e) {
LauncherPlugin.logError(LauncherPlugin.getResourceString("run.error.CouldNotInstantiateClass"), e);
}
}Example 79
| Project: EGit-master File: GitVariableResolver.java View source code |
private IResource getSelectedResource() {
IResource resource = null;
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow window = null;
if (workbench != null)
window = workbench.getActiveWorkbenchWindow();
if (window != null) {
IWorkbenchPage page = window.getActivePage();
if (page != null) {
IWorkbenchPart part = page.getActivePart();
if (part instanceof IEditorPart) {
IEditorPart epart = (IEditorPart) part;
resource = AdapterUtils.adaptToAnyResource(epart.getEditorInput());
} else if (part != null) {
IWorkbenchPartSite site = part.getSite();
if (site != null) {
ISelectionProvider provider = site.getSelectionProvider();
if (provider != null) {
ISelection selection = provider.getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection ss = (IStructuredSelection) selection;
if (!ss.isEmpty()) {
Iterator iterator = ss.iterator();
while (iterator.hasNext() && resource == null) {
Object next = iterator.next();
resource = AdapterUtils.adaptToAnyResource(next);
}
}
}
}
}
}
}
}
return resource;
}Example 80
| Project: elexis-3-core-master File: MedicationViewerHelper.java View source code |
// public static TableViewerColumn createSuppliedUntilColumn(TableViewer viewer, TableColumnLayout layout, int columnIndex) {
// supplied until
// TableViewerColumn tableViewerColumnSuppliedUntil =
// new TableViewerColumn(medicationTableViewer, SWT.CENTER);
// TableColumn tblclmnSufficient = tableViewerColumnSuppliedUntil.getColumn();
// tcl_compositeMedicationTable.setColumnData(tblclmnSufficient,
// new ColumnPixelData(45, true, true));
// tblclmnSufficient.setText(Messages.TherapieplanComposite_tblclmnSupplied_text);
// tblclmnSufficient.addSelectionListener(getSelectionAdapter(tblclmnSufficient, columnIndex));
// tableViewerColumnSuppliedUntil.setLabelProvider(new MedicationCellLabelProvider() {
//
// @Override
// public String getText(Object element){
// // SLLOW
// MedicationTableViewerItem pres = (MedicationTableViewerItem) element;
// if (!pres.isFixedMediation() || pres.isReserveMedication())
// return "";
//
// TimeTool tt = pres.getSuppliedUntilDate();
// if (tt != null && tt.isAfterOrEqual(new TimeTool())) {
// return "OK";
// }
//
// return "?";
// }
// });
// }
public static void addContextMenu(TableViewer viewer, MedicationComposite medicationComposite, IWorkbenchPartSite site) {
// register context menu for table viewer
MenuManager menuManager = new MenuManager();
Menu menu = menuManager.createContextMenu(viewer.getTable());
viewer.getTable().setMenu(menu);
if (site != null) {
site.registerContextMenu("ch.elexis.core.ui.medication.tables", menuManager, viewer);
}
}Example 81
| Project: EPF-Composer-master File: UIActionDispatcher.java View source code |
public void doubleClick(DoubleClickEvent e) {
ISelection selection = e.getSelection();
if (selection != null) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPartSite site = window.getActivePage().getActivePart().getSite();
IStructuredSelection sel = (IStructuredSelection) selection;
Object[] selObjs = sel.toArray();
Object selectedObject = null;
if ((selObjs != null) && (selObjs.length > 0)) {
// Open the Authoring persepective.
UIActionDispatcher.openAuthoringPerspective();
// Locate the selected Method element.
Object obj = TngUtil.unwrap(selObjs[0]);
ConfigurationView view = ConfigurationView.getView();
if ((view != null) && site.equals(view.getSite())) {
// view.
if (obj instanceof VariabilityElement) {
VariabilityElement element = (VariabilityElement) obj;
ContributionSelection contribSelection = new ContributionSelection();
selectedObject = contribSelection.getSelectedContributor(element);
} else if (obj instanceof Milestone) {
selectedObject = TngUtil.getOwningProcess((BreakdownElement) obj);
}
} else {
selectedObject = obj;
}
if (selectedObject != null) {
EditorChooser.getInstance().openEditor(selectedObject);
}
}
}
}Example 82
| Project: FreeQDA-master File: StyledEditor.java View source code |
@Override
public void createPartControl(Composite parent) {
FillLayout layout = new FillLayout();
parent.setLayout(layout);
styledText = new TaggableStyledText(parent, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.H_SCROLL | SWT.V_SCROLL);
styledText.setData(editorInput.getTextNode());
styledText.setText(editorInput.getTextNode().getNEWText());
styledText.setStyleRanges(editorInput.getTextNode().getNEWStyleRanges());
styledText.registerComponentDirtyNotificationListener(this);
styledText.addExtendedModifyListener(new ExtendedModifyListener() {
@Override
public void modifyText(ExtendedModifyEvent event) {
if (!isDirty)
setDirty(true);
}
});
/*
* Reset the dirty flag because the registration of tags changed it.
*/
setDirty(false);
IWorkbenchPartSite site = this.getSite();
IPartService partService = (IPartService) site.getService(IPartService.class);
partService.addPartListener(new IPartListener() {
@Override
public void partOpened(IWorkbenchPart part) {
DOCUMENT_REGISTRY.registerDocumentSelectionManipulateTagsListener(editorInput.getTextNode(), getActiveStyledText());
}
@Override
public void partDeactivated(IWorkbenchPart part) {
/* ignore */
}
@Override
public void partClosed(IWorkbenchPart part) {
// IWorkbenchPart thisPart = (IWorkbenchPart) StyledEditor.this;
DOCUMENT_REGISTRY.removeDocumentSelectionManipulateTagsListener(editorInput.getTextNode(), styledText);
getActiveTextNode().reset();
DOCUMENT_REGISTRY.resetDocumentData(getActiveTextNode());
DOCUMENT_REGISTRY.updateCodeStats();
TAG_MANAGER.updateCodeStats();
}
@Override
public void partBroughtToTop(IWorkbenchPart part) {
/* ignore */
}
@Override
public void partActivated(IWorkbenchPart part) {
/* ignore */
}
});
}Example 83
| Project: komma-master File: AbstractEditingDomainView.java View source code |
@Override
@SuppressWarnings("rawtypes")
public Object getAdapter(Class adapter) {
if (IWorkbenchPartSite.class.equals(adapter) || IViewSite.class.equals(adapter)) {
return getViewSite();
}
if (IToolBarManager.class.equals(adapter)) {
return getViewSite().getActionBars().getToolBarManager();
}
if (IEditingDomainProvider.class.equals(adapter)) {
return editingDomainProvider;
} else if (IViewerMenuSupport.class.equals(adapter)) {
if (part instanceof IViewerMenuSupport) {
return (IViewerMenuSupport) part;
} else if (part != null) {
return part.getAdapter(IViewerMenuSupport.class);
}
}
return delegatedGetAdapter(adapter);
}Example 84
| Project: linuxtools-master File: BrowserView.java View source code |
protected void registerContextMenu(String menuName) {
Control control = this.viewer.getControl();
MenuManager manager = new MenuManager(menuName);
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
Menu menu = manager.createContextMenu(control);
viewer.getControl().setMenu(menu);
IWorkbenchPartSite partSite = getSite();
partSite.registerContextMenu(manager, viewer);
partSite.setSelectionProvider(viewer);
}Example 85
| Project: mylyn.builds-master File: BuildHistoryPage.java View source code |
private void schedule(final Job job) {
final IWorkbenchPartSite site = getWorkbenchSite();
if (site != null) {
IWorkbenchSiteProgressService progress = site.getAdapter(IWorkbenchSiteProgressService.class);
if (progress != null) {
progress.schedule(job, 0, true);
return;
}
}
// fall-back
job.schedule();
}Example 86
| Project: mylyn.tasks-master File: BugzillaAttachmentUpdateAction.java View source code |
public void run(IAction action) {
IStructuredSelection selection = null;
if (currentSelection instanceof IStructuredSelection) {
selection = (IStructuredSelection) currentSelection;
}
if (selection == null || selection.isEmpty() || selection.size() != 1) {
return;
}
ITaskAttachment attachment = (ITaskAttachment) selection.getFirstElement();
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
IEditorPart activeEditor = page.getActiveEditor();
IWorkbenchPartSite site = activeEditor.getSite();
Shell shell = site.getShell();
if (activeEditor instanceof TaskEditor) {
final TaskEditor taskEditor = (TaskEditor) activeEditor;
//$NON-NLS-1$
IFormPage taskEditorPage = taskEditor.findPage("id");
if (taskEditorPage instanceof BugzillaTaskEditorPage) {
BugzillaTaskEditorPage bugzillaTaskEditorPage = (BugzillaTaskEditorPage) taskEditorPage;
ITask attachmentTask = attachment.getTask();
ITask nTask = new TaskTask(attachmentTask.getConnectorKind(), attachmentTask.getRepositoryUrl(), //$NON-NLS-1$
attachmentTask.getTaskId() + //$NON-NLS-1$
"attachment");
TaskData editTaskData = new TaskData(attachment.getTaskAttribute().getTaskData().getAttributeMapper(), attachment.getTaskAttribute().getTaskData().getConnectorKind(), attachment.getTaskAttribute().getTaskData().getRepositoryUrl(), attachment.getTaskAttribute().getTaskData().getTaskId());
editTaskData.setVersion(attachment.getTaskAttribute().getTaskData().getVersion());
TaskAttribute target0 = editTaskData.getRoot();
TaskAttribute temp = attachment.getTaskAttribute();
target0.setValues(temp.getValues());
for (TaskAttribute child : temp.getAttributes().values()) {
target0.deepAddCopy(child);
}
TaskAttribute comment = //$NON-NLS-1$
target0.createAttribute(//$NON-NLS-1$
"comment");
TaskAttributeMetaData commentMeta = comment.getMetaData();
commentMeta.setType(TaskAttribute.TYPE_LONG_RICH_TEXT);
commentMeta.setLabel(Messages.BugzillaAttachmentUpdateAction_Comment);
ITaskDataWorkingCopy workingCopy = TasksUi.getTaskDataManager().createWorkingCopy(nTask, editTaskData);
TaskRepository repository = TasksUiPlugin.getRepositoryManager().getRepository(attachment.getTaskAttribute().getTaskData().getRepositoryUrl());
final String repositoryLabel = repository.getRepositoryLabel();
final TaskDataModel model = new TaskDataModel(repository, nTask, workingCopy);
AttributeEditorFactory factory = new AttributeEditorFactory(model, repository, bugzillaTaskEditorPage.getEditorSite()) {
@Override
public AbstractAttributeEditor createEditor(String type, final TaskAttribute taskAttribute) {
AbstractAttributeEditor editor;
if (IBugzillaConstants.EDITOR_TYPE_FLAG.equals(type)) {
editor = new FlagAttributeEditor(model, taskAttribute);
} else {
editor = super.createEditor(type, taskAttribute);
if (TaskAttribute.TYPE_BOOLEAN.equals(type)) {
editor.setDecorationEnabled(false);
}
}
return editor;
}
};
TaskAttribute target = workingCopy.getLocalData().getRoot();
target.setValue(target0.getValue());
final BugzillaAttachmentWizard attachmentWizard = new BugzillaAttachmentWizard(shell, factory, target, taskEditor, attachment, repository.getRepositoryLabel());
final NewAttachmentWizardDialog dialog = new NewAttachmentWizardDialog(shell, attachmentWizard, false) {
@Override
protected IDialogSettings getDialogBoundsSettings() {
IDialogSettings settings = BugzillaUiPlugin.getDefault().getDialogSettings();
IDialogSettings section = settings.getSection(BugzillaUiPlugin.ATTACHMENT_WIZARD_SETTINGS_SECTION + repositoryLabel);
if (section == null) {
section = settings.addNewSection(BugzillaUiPlugin.ATTACHMENT_WIZARD_SETTINGS_SECTION + repositoryLabel);
}
return section;
}
};
model.addModelListener(new TaskDataModelListener() {
@Override
public void attributeChanged(TaskDataModelEvent event) {
attachmentWizard.setChanged(true);
dialog.updateButtons();
}
});
dialog.setBlockOnOpen(false);
dialog.create();
dialog.open();
}
}
}Example 87
| Project: neoclipse-master File: Activator.java View source code |
@Override
public void run() {
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = win.getActivePage();
IWorkbenchPart part = page.getActivePart();
IWorkbenchPartSite site = part.getSite();
IViewSite vSite = (IViewSite) site;
IActionBars actionBars = vSite.getActionBars();
if (actionBars == null) {
return;
}
IStatusLineManager statusLineManager = actionBars.getStatusLineManager();
if (statusLineManager == null) {
return;
}
statusLineManager.setMessage(message);
}Example 88
| Project: neoclipseWithCypherGenerator-master File: Activator.java View source code |
@Override
public void run() {
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = win.getActivePage();
IWorkbenchPart part = page.getActivePart();
IWorkbenchPartSite site = part.getSite();
IViewSite vSite = (IViewSite) site;
IActionBars actionBars = vSite.getActionBars();
if (actionBars == null) {
return;
}
IStatusLineManager statusLineManager = actionBars.getStatusLineManager();
if (statusLineManager == null) {
return;
}
statusLineManager.setMessage(message);
}Example 89
| Project: org.eclipse.mylyn.tasks-master File: BugzillaAttachmentUpdateAction.java View source code |
public void run(IAction action) {
IStructuredSelection selection = null;
if (currentSelection instanceof IStructuredSelection) {
selection = (IStructuredSelection) currentSelection;
}
if (selection == null || selection.isEmpty() || selection.size() != 1) {
return;
}
ITaskAttachment attachment = (ITaskAttachment) selection.getFirstElement();
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
IEditorPart activeEditor = page.getActiveEditor();
IWorkbenchPartSite site = activeEditor.getSite();
Shell shell = site.getShell();
if (activeEditor instanceof TaskEditor) {
final TaskEditor taskEditor = (TaskEditor) activeEditor;
//$NON-NLS-1$
IFormPage taskEditorPage = taskEditor.findPage("id");
if (taskEditorPage instanceof BugzillaTaskEditorPage) {
BugzillaTaskEditorPage bugzillaTaskEditorPage = (BugzillaTaskEditorPage) taskEditorPage;
ITask attachmentTask = attachment.getTask();
ITask nTask = new TaskTask(attachmentTask.getConnectorKind(), attachmentTask.getRepositoryUrl(), //$NON-NLS-1$
attachmentTask.getTaskId() + //$NON-NLS-1$
"attachment");
TaskData editTaskData = new TaskData(attachment.getTaskAttribute().getTaskData().getAttributeMapper(), attachment.getTaskAttribute().getTaskData().getConnectorKind(), attachment.getTaskAttribute().getTaskData().getRepositoryUrl(), attachment.getTaskAttribute().getTaskData().getTaskId());
editTaskData.setVersion(attachment.getTaskAttribute().getTaskData().getVersion());
TaskAttribute target0 = editTaskData.getRoot();
TaskAttribute temp = attachment.getTaskAttribute();
target0.setValues(temp.getValues());
for (TaskAttribute child : temp.getAttributes().values()) {
target0.deepAddCopy(child);
}
TaskAttribute comment = //$NON-NLS-1$
target0.createAttribute(//$NON-NLS-1$
"comment");
TaskAttributeMetaData commentMeta = comment.getMetaData();
commentMeta.setType(TaskAttribute.TYPE_LONG_RICH_TEXT);
commentMeta.setLabel(Messages.BugzillaAttachmentUpdateAction_Comment);
ITaskDataWorkingCopy workingCopy = TasksUi.getTaskDataManager().createWorkingCopy(nTask, editTaskData);
TaskRepository repository = TasksUiPlugin.getRepositoryManager().getRepository(attachment.getTaskAttribute().getTaskData().getRepositoryUrl());
final String repositoryLabel = repository.getRepositoryLabel();
final TaskDataModel model = new TaskDataModel(repository, nTask, workingCopy);
AttributeEditorFactory factory = new AttributeEditorFactory(model, repository, bugzillaTaskEditorPage.getEditorSite()) {
@Override
public AbstractAttributeEditor createEditor(String type, final TaskAttribute taskAttribute) {
AbstractAttributeEditor editor;
if (IBugzillaConstants.EDITOR_TYPE_FLAG.equals(type)) {
editor = new FlagAttributeEditor(model, taskAttribute);
} else {
editor = super.createEditor(type, taskAttribute);
if (TaskAttribute.TYPE_BOOLEAN.equals(type)) {
editor.setDecorationEnabled(false);
}
}
return editor;
}
};
TaskAttribute target = workingCopy.getLocalData().getRoot();
target.setValue(target0.getValue());
final BugzillaAttachmentWizard attachmentWizard = new BugzillaAttachmentWizard(shell, factory, target, taskEditor, attachment, repository.getRepositoryLabel());
final NewAttachmentWizardDialog dialog = new NewAttachmentWizardDialog(shell, attachmentWizard, false) {
@Override
protected IDialogSettings getDialogBoundsSettings() {
IDialogSettings settings = BugzillaUiPlugin.getDefault().getDialogSettings();
IDialogSettings section = settings.getSection(BugzillaUiPlugin.ATTACHMENT_WIZARD_SETTINGS_SECTION + repositoryLabel);
if (section == null) {
section = settings.addNewSection(BugzillaUiPlugin.ATTACHMENT_WIZARD_SETTINGS_SECTION + repositoryLabel);
}
return section;
}
};
model.addModelListener(new TaskDataModelListener() {
@Override
public void attributeChanged(TaskDataModelEvent event) {
attachmentWizard.setChanged(true);
dialog.updateButtons();
}
});
dialog.setBlockOnOpen(false);
dialog.create();
dialog.open();
}
}
}Example 90
| Project: rmf-master File: ProrCellEditor.java View source code |
/**
* Updates the error message in the status line, if the status line can be
* found (otherwise does nothing). If message is null, the error message is
* reset.
*/
protected void setStatusBar(String message) {
IWorkbenchPartSite site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite();
IStatusLineManager mgr = null;
if (site instanceof IEditorSite) {
mgr = ((IEditorSite) site).getActionBars().getStatusLineManager();
} else if (site instanceof IViewSite) {
mgr = ((IViewSite) site).getActionBars().getStatusLineManager();
}
if (mgr != null) {
mgr.setErrorMessage(message);
}
}Example 91
| Project: statecharts-master File: AbstractEditorPropertySection.java View source code |
protected void initContextMenu(Control control) {
MenuManager menuManager = new FilteringMenuManager();
Menu contextMenu = menuManager.createContextMenu(control);
control.setMenu(contextMenu);
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPartSite site = window.getActivePage().getActiveEditor().getSite();
site.registerContextMenu(CONTEXTMENUID, menuManager, site.getSelectionProvider());
}Example 92
| Project: textmapper-master File: SemanticHighlightingReconciler.java View source code |
/**
* Update the presentation.
*/
private void updatePresentation(TextPresentation textPresentation, List<HighlightedPosition> addedPositions, List<HighlightedPosition> removedPositions) {
Runnable runnable = fJobPresenter.createUpdateRunnable(textPresentation, addedPositions, removedPositions);
if (runnable == null) {
return;
}
StructuredTextEditor editor = fEditor;
if (editor == null) {
return;
}
IWorkbenchPartSite site = editor.getSite();
if (site == null) {
return;
}
Shell shell = site.getShell();
if (shell == null || shell.isDisposed()) {
return;
}
Display display = shell.getDisplay();
if (display == null || display.isDisposed()) {
return;
}
display.asyncExec(runnable);
}Example 93
| Project: webtools.jsf-master File: DesignPageActionContributor.java View source code |
/**
* @param enabled
*/
public void setViewerSpecificContributionsEnabled(boolean enabled) {
HTMLEditor htmlEditor = null;
if (_editorPart instanceof HTMLEditor) {
htmlEditor = (HTMLEditor) _editorPart;
} else if (_editorPart instanceof SimpleGraphicalEditor) {
htmlEditor = ((SimpleGraphicalEditor) _editorPart).getHTMLEditor();
}
if (htmlEditor == null)
return;
SimpleGraphicalEditor graphicalEditor = (SimpleGraphicalEditor) htmlEditor.getDesignViewer();
IWorkbenchPartSite site = htmlEditor.getSite();
if (site instanceof IEditorSite) {
IActionBars actionBars = ((IEditorSite) site).getActionBars();
if (enabled) {
// // we always let the text editor to handle UNDO and REDO
// actionBars.setGlobalActionHandler(ITextEditorActionConstants.UNDO,
// textEditor
// .getAction(ITextEditorActionConstants.UNDO));
// actionBars.setGlobalActionHandler(ITextEditorActionConstants.REDO,
// textEditor
// .getAction(ITextEditorActionConstants.REDO));
// lium: the above behavior changed, since we now use
// DesignerUndoRedoAction.
// see comments in DesignerUndoRedoAction
actionBars.setGlobalActionHandler(ITextEditorActionConstants.UNDO, graphicalEditor.getAction(IWorkbenchCommandConstants.EDIT_UNDO));
actionBars.setGlobalActionHandler(ITextEditorActionConstants.REDO, graphicalEditor.getAction(IWorkbenchCommandConstants.EDIT_REDO));
// cut/copy/paste is delegated to design actions
actionBars.setGlobalActionHandler(ITextEditorActionConstants.DELETE, graphicalEditor.getAction(IWorkbenchCommandConstants.EDIT_DELETE));
actionBars.setGlobalActionHandler(ITextEditorActionConstants.CUT, graphicalEditor.getAction(IWorkbenchCommandConstants.EDIT_CUT));
actionBars.setGlobalActionHandler(ITextEditorActionConstants.COPY, graphicalEditor.getAction(IWorkbenchCommandConstants.EDIT_COPY));
actionBars.setGlobalActionHandler(ITextEditorActionConstants.PASTE, graphicalEditor.getAction(IWorkbenchCommandConstants.EDIT_PASTE));
} else {
actionBars.setGlobalActionHandler(ITextEditorActionConstants.UNDO, null);
actionBars.setGlobalActionHandler(ITextEditorActionConstants.REDO, null);
actionBars.setGlobalActionHandler(ITextEditorActionConstants.DELETE, null);
actionBars.setGlobalActionHandler(ITextEditorActionConstants.CUT, null);
actionBars.setGlobalActionHandler(ITextEditorActionConstants.COPY, null);
actionBars.setGlobalActionHandler(ITextEditorActionConstants.PASTE, null);
}
}
}Example 94
| Project: xmind-master File: CommandLabelUpdater.java View source code |
private IActionBars findActionBars(IWorkbenchWindow window) {
if (window == null)
return null;
IWorkbenchPage page = window.getActivePage();
if (page == null)
return null;
IWorkbenchPart activePart = page.getActivePart();
if (activePart == null)
return null;
IWorkbenchPartSite site = activePart.getSite();
if (site instanceof IEditorSite)
return ((IEditorSite) site).getActionBars();
if (site instanceof IViewSite)
return ((IViewSite) site).getActionBars();
return null;
}Example 95
| Project: android-platform_sdk-master File: UiPackageAttributeNode.java View source code |
/**
* Handles response to the Label hyper link being activated.
*/
private void doLabelClick() {
// get the current package name
String package_name = getTextWidget().getText().trim();
if (package_name.length() == 0) {
createNewPackage();
} else {
// Try to select the package in the Package Explorer for the current
// project and the current editor's site.
IProject project = getProject();
if (project == null) {
//$NON-NLS-1$
AdtPlugin.log(IStatus.ERROR, "Failed to get project for UiPackageAttribute");
return;
}
IWorkbenchPartSite site = getUiParent().getEditor().getSite();
if (site == null) {
//$NON-NLS-1$
AdtPlugin.log(IStatus.ERROR, "Failed to get editor site for UiPackageAttribute");
return;
}
for (IPackageFragmentRoot root : getPackageFragmentRoots(project)) {
IPackageFragment fragment = root.getPackageFragment(package_name);
if (fragment != null && fragment.exists()) {
ShowInPackageViewAction action = new ShowInPackageViewAction(site);
action.run(fragment);
// so we just assume it worked.
return;
}
}
}
}Example 96
| Project: com.ifedorenko.m2e.mavendev-master File: BuildProgressView.java View source code |
@Override
protected void setSite(IWorkbenchPartSite site) {
super.setSite(site);
refreshJob = new UIJob(site.getShell().getDisplay(), "Maven Build Progress View Refresh Job") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
return BuildProgressView.this.runInUIThread(monitor);
}
};
refreshJob.setUser(false);
enqueueRefresh(this);
}Example 97
| Project: eclipse-integration-gradle-master File: GradleTasksView.java View source code |
@Override
public void dispose() {
try {
IWorkbenchPartSite site = getSite();
if (site != null) {
if (selectionListener != null) {
site.getWorkbenchWindow().getSelectionService().removeSelectionListener(selectionListener);
}
}
} finally {
selectionListener = null;
}
}Example 98
| Project: Eclipse-Postfix-Code-Completion-master File: JavaReconciler.java View source code |
/*
* @see org.eclipse.jface.text.reconciler.IReconciler#install(org.eclipse.jface.text.ITextViewer)
*/
@Override
public void install(ITextViewer textViewer) {
super.install(textViewer);
fPartListener = new PartListener();
IWorkbenchPartSite site = fTextEditor.getSite();
IWorkbenchWindow window = site.getWorkbenchWindow();
window.getPartService().addPartListener(fPartListener);
fActivationListener = new ActivationListener(textViewer.getTextWidget());
Shell shell = window.getShell();
shell.addShellListener(fActivationListener);
fJavaElementChangedListener = new ElementChangedListener();
JavaCore.addElementChangedListener(fJavaElementChangedListener);
fResourceChangeListener = new ResourceChangeListener();
IWorkspace workspace = JavaPlugin.getWorkspace();
workspace.addResourceChangeListener(fResourceChangeListener);
fPropertyChangeListener = new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
if (SpellingService.PREFERENCE_SPELLING_ENABLED.equals(event.getProperty()) || SpellingService.PREFERENCE_SPELLING_ENGINE.equals(event.getProperty()))
forceReconciling();
}
};
JavaPlugin.getDefault().getCombinedPreferenceStore().addPropertyChangeListener(fPropertyChangeListener);
fReconciledElement = EditorUtility.getEditorInputJavaElement(fTextEditor, false);
}Example 99
| Project: edt-master File: ProblemReconciler.java View source code |
public void install(ITextViewer textViewer) {
fViewer = textViewer;
synchronized (this) {
if (fThread != null)
return;
fThread = new BackgroundThread(getClass().getName());
}
fPartListener = new PartListener();
IWorkbenchPartSite site = fEditor.getSite();
IWorkbenchWindow window = site.getWorkbenchWindow();
window.getPartService().addPartListener(fPartListener);
fModelListener = new Listener();
fViewer.addTextInputListener(fModelListener);
fResourceChangeListener = new ResourceChangeListener();
IWorkspace workspace = EDTUIPlugin.getWorkspace();
workspace.addResourceChangeListener(fResourceChangeListener);
fPropertyListener = new EGLPropertyChangeListener();
EDTUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(fPropertyListener);
}Example 100
| Project: gef-gwt-master File: RetargetAction.java View source code |
/**
* Disposes of the action and any resources held.
*/
public void dispose() {
if (handler != null) {
handler.removePropertyChangeListener(propertyChangeListener);
handler = null;
}
IWorkbenchPart part = getActivePart();
if (part != null) {
IWorkbenchPartSite site = part.getSite();
SubActionBars bars = (SubActionBars) ((PartSite) site).getActionBars();
bars.removePropertyChangeListener(propertyChangeListener);
}
}Example 101
| Project: hale-master File: WindowSelectionSelector.java View source code |
/**
* Show the given selection.
*
* @param is the selection to show
* @param image an image to show for the selection, may be <code>null</code>
*/
public void showSelection(InstanceSelection is, final Image image) {
if (current != null && !current.isDisposed()) {
current.selectionChanged(new // dummy part
IWorkbenchPart() {
@SuppressWarnings("unchecked")
@Override
public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
// dummy
return null;
}
@Override
public void setFocus() {
// dummy
}
@Override
public void removePropertyListener(IPropertyListener listener) {
// dummy
}
@Override
public String getTitleToolTip() {
// dummy
return null;
}
@Override
public Image getTitleImage() {
return image;
}
@Override
public String getTitle() {
// dummy
return null;
}
@Override
public IWorkbenchPartSite getSite() {
// dummy
return null;
}
@Override
public void dispose() {
// dummy
}
@Override
public void createPartControl(Composite parent) {
// dummy
}
@Override
public void addPropertyListener(IPropertyListener listener) {
// dummy
}
}, is);
}
}