Java Code Examples for org.eclipse.ui.PlatformUI

The following are top voted examples for showing how to use org.eclipse.ui.PlatformUI. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: gw4e.project   File: GraphWalkerContextManager.java   View source code 6 votes vote down vote up
public static IJavaProject chooseGW4EProject(IJavaProject javaProject) {
	Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
	IJavaProject[] projects = getGW4EProjects();
	ILabelProvider labelProvider = new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT);
	ElementListSelectionDialog dialog = new ElementListSelectionDialog(shell, labelProvider);
	dialog.setTitle(MessageUtil.getString("projectdialog_title"));
	dialog.setMessage(MessageUtil.getString("projectdialog_message"));
	dialog.setElements(projects);

	if (javaProject != null) {
		dialog.setInitialSelections(new Object[] { javaProject });
	}
	if (dialog.open() == Window.OK) {
		return (IJavaProject) dialog.getFirstResult();
	}
	return null;
}
 
Example 2
Project: n4js   File: UIUtils.java   View source code 6 votes vote down vote up
/**
 * Returns the initial location to use for the shell. The default implementation centers the shell horizontally (1/2
 * of the difference to the left and 1/2 to the right) and vertically (1/3 above and 2/3 below) relative to the
 * active workbench windows shell, or display bounds if there is no parent shell.
 *
 * @param shell
 *            the shell which initial location has to be calculated.
 * @param initialSize
 *            the initial size of the shell, as returned by <code>getInitialSize</code>.
 * @return the initial location of the shell
 */
public static Point getInitialLocation(final Shell shell, final Point initialSize) {
	final Composite parent = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

	Monitor monitor = shell.getDisplay().getPrimaryMonitor();
	if (parent != null) {
		monitor = parent.getMonitor();
	}

	final Rectangle monitorBounds = monitor.getClientArea();
	Point centerPoint;
	if (parent != null) {
		centerPoint = Geometry.centerPoint(parent.getBounds());
	} else {
		centerPoint = Geometry.centerPoint(monitorBounds);
	}

	return new Point(centerPoint.x - (initialSize.x / 2), Math.max(
			monitorBounds.y, Math.min(centerPoint.y
					- (initialSize.y * 2 / 3), monitorBounds.y
							+ monitorBounds.height - initialSize.y)));
}
 
Example 3
Project: Open_Source_ECOA_Toolset_AS5   File: TypesWizardCommand.java   View source code 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	IWizardDescriptor descriptor = PlatformUI.getWorkbench().getNewWizardRegistry().findWizard(ID);
	if (descriptor == null) {
		descriptor = PlatformUI.getWorkbench().getImportWizardRegistry().findWizard(ID);
	}
	if (descriptor == null) {
		descriptor = PlatformUI.getWorkbench().getExportWizardRegistry().findWizard(ID);
	}
	try {
		if (descriptor != null) {
			IWizard wizard = descriptor.createWizard();
			WizardDialog wd = new WizardDialog(Display.getDefault().getActiveShell(), wizard);
			wd.setTitle(wizard.getWindowTitle());
			wd.open();
		}
	} catch (CoreException e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 4
Project: Equella   File: NewPluginWizard.java   View source code 6 votes vote down vote up
@Override
public boolean performFinish()
{
	boolean res = super.performFinish();
	if( res )
	{
		final IJavaElement newElement = getCreatedElement();

		IWorkingSet[] workingSets = fFirstPage.getWorkingSets();
		if( workingSets.length > 0 )
		{
			PlatformUI.getWorkbench().getWorkingSetManager().addToWorkingSets(newElement, workingSets);
		}
		BasicNewResourceWizard.selectAndReveal(fSecondPage.getJavaProject().getProject(), getWorkbench()
			.getActiveWorkbenchWindow());
	}
	return res;
}
 
Example 5
Project: pandionj   File: NewJavaFileCommand.java   View source code 6 votes vote down vote up
@Override
public boolean isEnabled() {
	ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
	if(selection instanceof IStructuredSelection) {
		IStructuredSelection s = (IStructuredSelection) selection;
		if(s.size() == 1) {
			Object e = s.getFirstElement();
			try {
				return e instanceof IProject && ((IProject) e).hasNature("org.eclipse.jdt.internal.core.JavaProject");
			} catch (CoreException e1) {
				return false;
			}
		}
	}
	return false;
}
 
Example 6
Project: SurveyDSL   File: GenerateATLHandler.java   View source code 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	TreeSelection selection = (TreeSelection) HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
	Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
	Object firstElement = selection.getFirstElement();
	
	if (firstElement instanceof IAdaptable)
       {
           IFile file = (IFile)((IAdaptable)firstElement).getAdapter(IFile.class);
           IPath path = file.getLocation();
           
           try {
           	//TODO fix
			SurveyGenerator.generateAll(path.toOSString(), path.toOSString());
			MessageDialog.openInformation(shell, "Success", "Code was generated successfully");
		} catch (Exception e) {
			//MessageDialog.openError(shell, "Error", e.getMessage());
			e.printStackTrace();
		}
       }
	return null;
}
 
Example 7
Project: gw4e.project   File: RunAsManualWizard.java   View source code 6 votes vote down vote up
public static void open(String modelPath, ModelData[] additionalModels, String generatorstopcondition,
		String startnode, boolean removeBlockedElements, boolean omitEgdeswithoutDescription) {
	try {
		Display.getDefault().asyncExec(() -> {
			RunAsManualWizard wizard = new RunAsManualWizard(modelPath, additionalModels, generatorstopcondition,
					startnode, removeBlockedElements, omitEgdeswithoutDescription);
			wizard.init(PlatformUI.getWorkbench(), (IStructuredSelection) null);
			Shell activeShell = Display.getDefault().getActiveShell();
			if (activeShell == null)
				return;
			WizardDialog dialog = new WizardDialog(activeShell, wizard);
			dialog.open();
		});
	} catch (Exception e) {
		ResourceManager.logException(e);
	}
}
 
Example 8
Project: pgcodekeeper   File: ProjectEditorDiffer.java   View source code 6 votes vote down vote up
public static void notifyDbChanged(DbInfo dbinfo) {
    String action = Activator.getDefault().getPreferenceStore().getString(PG_EDIT_PREF.EDITOR_UPDATE_ACTION);
    if (action.equals(PG_EDIT_PREF.NO_ACTION)) {
        return;
    }
    for (IWorkbenchWindow wnd : PlatformUI.getWorkbench().getWorkbenchWindows()) {
        for (IWorkbenchPage page : wnd.getPages()) {
            for (IEditorReference ref : page.getEditorReferences()) {
                IEditorPart ed = ref.getEditor(false);
                if (ed instanceof ProjectEditorDiffer) {
                    notifyDbChanged(dbinfo, (ProjectEditorDiffer) ed, action.equals(PG_EDIT_PREF.UPDATE));
                }
            }
        }
    }
}
 
Example 9
Project: Open_Source_ECOA_Toolset_AS5   File: CompDefEditor.java   View source code 6 votes vote down vote up
@Override
public void mouseUp(MouseEvent e) {
	if (e.getSource() instanceof Button) {
		Button sel = (Button) e.getSource();
		if (sel.getText().equalsIgnoreCase("Save")) {
			try {
				String tempText = util.processAdd(isEdit, editName, comp, type, editor.getDocumentProvider().getDocument(getEditorInput()).get());
				editor.getDocumentProvider().getDocument(getEditorInput()).set(tempText);
				createPage1();
				setActivePage(1);
			} catch (JAXBException ex) {
				ErrorDialog.openError(getSite().getShell(), "Error removing item", null, new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, 0, "Error removing item", null));
			}
		}
	}
}
 
Example 10
Project: gemoc-studio-modeldebugging   File: SelectDsaProposal.java   View source code 6 votes vote down vote up
@Override
public String getReplacementText() {
	SelectAnyIProjectDialog dialog = new SelectAnyIProjectDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
	if (dialog.open() == Dialog.OK) {
		Object[] selections = dialog.getResult();
		if(selections != null 
			&& selections.length != 0
			&& selections[0] instanceof IProject 
		){
			dsaProject = (IProject) selections[0];
			Set<String> aspects = SequentialSingleLanguageTemplate.getAspectClassesList(dsaProject);
			final StringBuilder insertion = new StringBuilder();
			for (String asp : aspects) {
				insertion.append("\twith " + asp + "\n");
			}
			insertion.replace(0, 1, "");//remove the first \t
			return insertion.toString();
		}
	}
	
	return "";
}
 
Example 11
Project: gemoc-studio-modeldebugging   File: AbstractDebugAsAction.java   View source code 6 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.sirius.tools.api.ui.IExternalJavaAction#execute(java.util.Collection, java.util.Map)
 */
public void execute(Collection<? extends EObject> selections, Map<String, Object> parameters) {
	final ILaunchConfigurationType launchConfigType = DebugPlugin.getDefault().getLaunchManager()
			.getLaunchConfigurationType(getLaunchConfigurationTypeID());
	Set<String> modes = new HashSet<String>();
	modes.add("debug");
	try {
		ILaunchDelegate[] delegates = launchConfigType.getDelegates(modes);
		if (delegates.length != 0
				&& delegates[0].getDelegate() instanceof AbstractDSLLaunchConfigurationDelegateUI) {
			AbstractDSLLaunchConfigurationDelegateUI delegate = (AbstractDSLLaunchConfigurationDelegateUI)delegates[0]
					.getDelegate();
			delegate.launch(delegate.getLaunchableResource(PlatformUI.getWorkbench()
					.getActiveWorkbenchWindow().getActivePage().getActiveEditor()),
					getFirstInstruction(selections), "debug");
		}
	} catch (CoreException e) {
		DebugSiriusIdeUiPlugin.getPlugin().getLog().log(
				new Status(IStatus.ERROR, DebugSiriusIdeUiPlugin.ID, e.getLocalizedMessage(), e));
	}
}
 
Example 12
Project: scanning   File: XcenView.java   View source code 6 votes vote down vote up
private void showQueue() throws Exception {

		IViewReference[] refs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();

		boolean foundStatus = false;
		for (IViewReference vr : refs) {
			if (StatusQueueView.ID.equals(vr.getId())) foundStatus = true;
		}
		if (!foundStatus) {
			String secondId = XcenServices.getQueueViewSecondaryId();
			IViewPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(StatusQueueView.ID+":"+secondId, null, IWorkbenchPage.VIEW_VISIBLE);
			if (part !=null && part instanceof StatusQueueView) {
				StatusQueueView view = (StatusQueueView)part;
				PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().bringToTop(view);
				view.refresh();
			}
		}
	}
 
Example 13
Project: convertigo-eclipse   File: ObjectExplorerWizardPage.java   View source code 6 votes vote down vote up
@Override
public void performHelp() {
	String href = null;
	BeanInfo bi = getCurrentSelectedBeanInfo();
	if (bi != null) {
		String displayName = bi.getBeanDescriptor().getDisplayName();
		if ((displayName != null) && !displayName.equals(""))
			href = getBeanHelpHref(displayName);
	}
	
	if ((href == null) || href.equals(""))
		href = "convertigoObjects.html";
	
	String helpPageUri = "/com.twinsoft.convertigo.studio.help/help/helpRefManual/"+ href;
	PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpPageUri);
}
 
Example 14
Project: Hydrograph   File: Utils.java   View source code 6 votes vote down vote up
/**
 * 
 * loading the properties files
 */
public void loadProperties() {
	IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	if (page.getActiveEditor().getEditorInput() instanceof IFileEditorInput) {
		IFileEditorInput input = (IFileEditorInput) page.getActiveEditor().getEditorInput();
		List<File> paramNameList = null;
		IFile file = input.getFile();
		IProject activeProject = file.getProject();
		final File globalparamFilesPath = new File(activeProject.getLocation().toString() + "/" + "globalparam");
		final File localParamFilePath = new File(activeProject.getLocation().toString() + "/" + Constants.PARAM_FOLDER);
		File[] files = (File[]) ArrayUtils.addAll(listFilesForFolder(globalparamFilesPath),
				getJobsPropertyFile(localParamFilePath,file));
		if (files != null) {
			paramNameList = Arrays.asList(files);
			getParamMap(paramNameList, null);
		}
	}
}
 
Example 15
Project: convertigo-eclipse   File: ProjectTreeObject.java   View source code 6 votes vote down vote up
public void closeConnectorEditors(Connector connector) {
	IWorkbenchPage activePage = PlatformUI
									.getWorkbench()
									.getActiveWorkbenchWindow()
									.getActivePage();
	if (activePage != null) {
		if (connector != null) {
			IEditorReference[] editorRefs = activePage.getEditorReferences();
			for (int i=0;i<editorRefs.length;i++) {
				IEditorReference editorRef = (IEditorReference)editorRefs[i];
				try {
					IEditorInput editorInput = editorRef.getEditorInput();
					if ((editorInput != null) && (editorInput instanceof ConnectorEditorInput)) {
						if (((ConnectorEditorInput)editorInput).is(connector)) {
							activePage.closeEditor(editorRef.getEditor(false),true);
							break;
						}
					}
				}
				catch(PartInitException e) {
					ConvertigoPlugin.logException(e, "Error while retrieving the connector editor '" + editorRef.getName() + "'");
				}
			}
		}
	}
}
 
Example 16
Project: pgcodekeeper   File: NavigatorOutlineActionProvider.java   View source code 6 votes vote down vote up
@Override
public void run() {
    if (isEnabled()) {
        try {
            ITextEditor editor = (ITextEditor) IDE.openEditor(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
                    segment.getParentFile(), EDITOR.SQL, true);
            editor.setHighlightRange(segment.offset, segment.length, true);
            editor.selectAndReveal(segment.offset, segment.length);
        } catch (PartInitException e) {
            Log.log(e);
            ExceptionNotifier.notifyDefault(Messages.PgNavigatorActionProvider_failed_to_open_editor, e);
        }
    }
}
 
Example 17
Project: Hydrograph   File: ComponentDeleteCommand.java   View source code 6 votes vote down vote up
private void removeWatch(Port sourcePort, Component sourceComponent){
	ELTGraphicalEditor editor=(ELTGraphicalEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
	GraphicalViewer	graphicalViewer =(GraphicalViewer) ((GraphicalEditor)editor).getAdapter(GraphicalViewer.class);
	for (Object objectEditPart : graphicalViewer.getEditPartRegistry().values()) 
	{
		EditPart editPart = (EditPart) objectEditPart;
		if(editPart instanceof ComponentEditPart) 
		{
			Component comp = ((ComponentEditPart)editPart).getCastedModel();
			if(comp.equals(sourceComponent)){
				List<PortEditPart> portEditParts = editPart.getChildren();
				for(AbstractGraphicalEditPart part:portEditParts)
				{
					if(part instanceof PortEditPart){
						if(((PortEditPart)part).getCastedModel().getTerminal().equals(sourcePort.getTerminal())){
							((PortEditPart)part).getPortFigure().removeWatcherColor();
							((PortEditPart)part).getPortFigure().setWatched(false);
						} 
					}
				}
			}
		} 
	}
}
 
Example 18
Project: Hydrograph   File: Provider.java   View source code 6 votes vote down vote up
private Integer getPortNo(JobDetails jobDetails) {
	String localPortNo = PlatformUI.getPreferenceStore().getString(PreferenceConstants.LOCAL_PORT_NO);
	if(StringUtils.isBlank(localPortNo)){
		localPortNo =PreferenceConstants.DEFAULT_PORT_NO;
	}
	
	
	String remotePortNo = PlatformUI.getPreferenceStore().getString(PreferenceConstants.REMOTE_PORT_NO);
	if(StringUtils.isBlank(remotePortNo)){
		remotePortNo = PreferenceConstants.DEFAULT_PORT_NO;
	}
	if(jobDetails.isRemote() && StringUtils.isNotBlank(remotePortNo)){
		return	Integer.parseInt(remotePortNo);
	}else
		return Integer.parseInt(localPortNo);
}
 
Example 19
Project: neoscada   File: Application.java   View source code 6 votes vote down vote up
@Override
public Object start ( final IApplicationContext context ) throws Exception
{
    Display display = PlatformUI.createDisplay ();
    try
    {
        int returnCode = PlatformUI.createAndRunWorkbench ( display, new ApplicationWorkbenchAdvisor () );
        if ( returnCode == PlatformUI.RETURN_RESTART )
        {
            return IApplication.EXIT_RESTART;
        }
        else
        {
            return IApplication.EXIT_OK;
        }
    }
    finally
    {
        display.dispose ();
    }

}
 
Example 20
Project: convertigo-eclipse   File: StatementTreeObject.java   View source code 6 votes vote down vote up
private void openJscriptStatementEditor(IProject project) {
	Statement statement = this.getObject();

	IFile file = project.getFile("/_private/" + statement.getQName() + " " + statement.getName());

	IWorkbenchPage activePage = PlatformUI
									.getWorkbench()
									.getActiveWorkbenchWindow()
									.getActivePage();
	if (activePage != null) {
		try {
			activePage.openEditor(new JscriptStatementEditorInput(file, statement),
									"com.twinsoft.convertigo.eclipse.editors.jscript.JscriptStatementEditor");
		}
		catch(PartInitException e) {
			ConvertigoPlugin.logException(e, "Error while loading the statement editor '" + statement.getName() + "'");
		} 
	}
}
 
Example 21
Project: solidity-ide   File: KickStartNewProjectAction.java   View source code 6 votes vote down vote up
@Override
public void run(IIntroSite site, Properties params) {
	WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
		@Override
		protected void execute(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
			IProject project = createProject(monitor);
			createExample(project);
		}
	};
	try {
		PlatformUI.getWorkbench().getProgressService().run(true, true, op);
		final IIntroManager introManager = PlatformUI.getWorkbench().getIntroManager();
		IIntroPart part = introManager.getIntro();
		introManager.closeIntro(part);
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		IDE.openEditor(page, ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("hello-world/greeter.sol")));
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 22
Project: Hydrograph   File: ELTGraphicalEditor.java   View source code 6 votes vote down vote up
@Override
public void setInput(IEditorInput input) {
	if(input instanceof FileStoreEditorInput){
		MessageBox messageBox=new MessageBox(Display.getCurrent().getActiveShell(),SWT.ICON_WARNING);
		messageBox.setText(Messages.WARNING);
		messageBox.setMessage(Messages.JOB_OPENED_FROM_OUTSIDE_WORKSPACE_WARNING);
		messageBox.open();
	}	
	try {
		GenrateContainerData genrateContainerData = new GenrateContainerData();
		genrateContainerData.setEditorInput(input, this);
		if(StringUtils.equals(this.getJobName()+Messages.JOBEXTENSION, input.getName()) || StringUtils.equals(this.getJobName(), Messages.ELT_GRAPHICAL_EDITOR)){
			container = genrateContainerData.getContainerData();
		}else{
			this.setPartName(input.getName());
		}
		super.setInput(input);
	} catch (CoreException | IOException ce) {
		logger.error("Exception while setting input", ce);
		PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().dispose();
		MessageDialog.openError(new Shell(), "Error", "Exception occured while opening the graph -\n"+ce.getMessage());
	}
}
 
Example 23
Project: gw4e.project   File: ConsolePreferencePage.java   View source code 6 votes vote down vote up
private SWTBotShell showPreferenceDialogMAC() {
	final IWorkbench workbench = PlatformUI.getWorkbench();
	workbench.getDisplay().asyncExec(new Runnable() {
		public void run() {
			IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
			if (window != null) {
				Menu appMenu = workbench.getDisplay().getSystemMenu();
				for (MenuItem item : appMenu.getItems()) {
					if (item.getText().startsWith("Preferences")) {
						Event event = new Event();
						event.time = (int) System.currentTimeMillis();
						event.widget = item;
						event.display = workbench.getDisplay();
						item.setSelection(true);
						item.notifyListeners(SWT.Selection, event);
						break;
					}
				}
			}
		}
	});
	return  getPreferenceDialog() ;
}
 
Example 24
Project: convertigo-eclipse   File: MobileApplicationComponentTreeObject.java   View source code 6 votes vote down vote up
@Override
public void closeAllEditors(boolean save) {
	super.closeAllEditors(save);// will close any child component editor
	
	ApplicationComponent application = (ApplicationComponent) getObject();
	synchronized (application) {
		IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		if (activePage != null) {
			IEditorReference[] editorRefs = activePage.getEditorReferences();
			for (int i = 0; i < editorRefs.length; i++) {
				IEditorReference editorRef = (IEditorReference) editorRefs[i];
				try {
					IEditorInput editorInput = editorRef.getEditorInput();
					if (editorInput != null && editorInput instanceof ApplicationComponentEditorInput) {
						if (((ApplicationComponentEditorInput) editorInput).is(application)) {
							activePage.closeEditor(editorRef.getEditor(false),false);
						}
					}
				} catch(Exception e) {
					
				}
			}
		}
	}
}
 
Example 25
Project: gemoc-studio   File: OpenEditor.java   View source code 6 votes vote down vote up
public static void openFile(File file) {
	if (file.exists() && file.isFile()) {
		IFileStore fileStore = EFS.getLocalFileSystem().getStore(
				file.toURI());
		IWorkbenchPage page = PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow().getActivePage();

		try {
			IDE.openEditorOnFileStore(page, fileStore);
		} catch (PartInitException e) {
			// Put your exception handler here if you wish to
		}
	} else {
		// Do something if the file does not exist
	}
}
 
Example 26
Project: Hydrograph   File: CustomizeNewClassWizardPage.java   View source code 6 votes vote down vote up
@Override
protected void createContainerControls(Composite parent, int nColumns) {

	super.createContainerControls(parent, nColumns);
	Text text = (Text) parent.getChildren()[1];
	text.setEditable(false);
	IEditorInput editorInput = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
			.getActiveEditor().getEditorInput();
	if (editorInput instanceof IFileEditorInput) {
		IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput;
		IProject project = fileEditorInput.getFile().getProject();
		if (project != null) {
			IFolder srcFolder = project.getFolder("src/main/java");
			if (srcFolder != null && srcFolder.exists()) {
				text.setText(project.getName() + "/" + srcFolder.getProjectRelativePath().toString());
			}
		}
		Button button = (Button) parent.getChildren()[2];
		button.setEnabled(false);
	}
}
 
Example 27
Project: n4js   File: AbstractBuilderTest.java   View source code 5 votes vote down vote up
/***/
@SuppressWarnings("restriction")
protected IWorkbenchPage getActivePage() {
	IWorkbenchPage page = null;
	if (org.eclipse.ui.internal.Workbench.getInstance() != null) {
		IWorkbench wb = PlatformUI.getWorkbench();
		IWorkbenchWindow window = wb.getActiveWorkbenchWindow();
		// Could be null if using Timeout test rule and does not run on main thread.
		if (null != window) {
			page = window.getActivePage();
		}
	}
	return page;
}
 
Example 28
Project: pgcodekeeper   File: UsageReporter.java   View source code 5 votes vote down vote up
/**
 * Asks the user is he allows us to report usage. Opens a dialog for this sake.
 */
private void askUser() {

    Display.getDefault().syncExec(() -> {
        Shell shell = PlatformUI.getWorkbench().getModalDialogShellProvider().getShell();
        boolean isEnabled =  MessageDialog.openQuestion(shell,
                Messages.UsageReport_DialogTitle, Messages.UsageReport_DialogMessage);
        mainPrefs.setValue(USAGE_REPORT_PREF.USAGEREPORT_ENABLED_ID, isEnabled);
        mainPrefs.setValue(USAGE_REPORT_PREF.ASK_USER_USAGEREPORT_ID, false);
    });
}
 
Example 29
Project: Hydrograph   File: JobHandler.java   View source code 5 votes vote down vote up
private boolean jobIsSaved(){
	ELTGraphicalEditor editor = SubJobUtility.getCurrentEditor();
	if(editor.isDirty())
	{
		if(!StringUtils.equals(Activator.getDefault().getPreferenceStore().getString(JobRunPreference.SAVE_JOB_BEFORE_RUN_PREFRENCE), MessageDialogWithToggle.ALWAYS)){
		SaveJobFileBeforeRunDialog messageBox = new SaveJobFileBeforeRunDialog(Display.getCurrent().getActiveShell(),"'"+editor.getEditorInput().getName()+"' "+Messages.CONFIRM_TO_SAVE_JOB_BEFORE_RUN );
	    int rc = messageBox.open();
	    if(rc!=IDialogConstants.OK_ID){
	    	return false;
	    	}
	    }
	PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().doSave(null);	    
	}
	return true;
}
 
Example 30
Project: Open_Source_ECOA_Toolset_AS5   File: AppAbstractEditPart.java   View source code 5 votes vote down vote up
@Override
public void performRequest(Request req) {
	if (req.getType().equals(RequestConstants.REQ_OPEN)) {
		try {
			IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
			page.showView(IPageLayout.ID_PROP_SHEET);
		} catch (PartInitException e) {
			e.printStackTrace();
		}
	}
}
 
Example 31
Project: Tarski   File: AlloyParserForMetamodel.java   View source code 5 votes vote down vote up
private MarkerTypeElement convertToMarkerType(final Sig rootSig) {
  if (rootSig instanceof PrimSig) {
    final PrimSig primSig = (PrimSig) rootSig;
    MarkerTypeElement rootType;
    if (primSig.isAbstract != null) {
      rootType = new MarkerTypeElement(
          primSig.toString().substring(primSig.toString().indexOf("/") + 1) + " {abs}");
    } else {
      rootType = new MarkerTypeElement(
          primSig.toString().substring(primSig.toString().indexOf("/") + 1));
    }
    try {
      if (primSig.children().isEmpty()) {
        return rootType;
      } else {
        for (int i = 0; i < primSig.children().size(); i++) {
          rootType.getChildren().add(this.convertToMarkerType(primSig.children().get(i)));
        }
        return rootType;
      }
    } catch (final Err e) {
      final MessageDialog dialog =
          new MessageDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
              "Alloy Error Information", null, e.getMessage(), MessageDialog.INFORMATION,
              new String[] {"OK"}, 0);
      dialog.open();
    }
  } else if (rootSig instanceof SubsetSig) {
    final SubsetSig subsetSig = (SubsetSig) rootSig;
    String parentName = subsetSig.type().toString();
    parentName = parentName.substring(parentName.indexOf("/") + 1, parentName.length() - 1);
    final MarkerTypeElement parentMarkerType =
        this.getMarkTypeElementByName(parentName, this.types);
    parentMarkerType.getChildren().add(new MarkerTypeElement(
        subsetSig.toString().substring(subsetSig.toString().indexOf("/") + 1)));
  }
  return null;
}
 
Example 32
Project: scanning   File: Util.java   View source code 5 votes vote down vote up
/**
 * @return IWorkbenchPage
 */
public static IWorkbenchPage getDefaultPage() {
	final IWorkbench bench = PlatformUI.getWorkbench();
	if (bench==null) return null;
	final IWorkbenchWindow[] windows = bench.getWorkbenchWindows();
	if (windows==null) return null;

	return windows[0].getActivePage();
}
 
Example 33
Project: codelens-eclipse   File: EditorTracker.java   View source code 5 votes vote down vote up
private void init() {
	if (PlatformUI.isWorkbenchRunning()) {
		IWorkbench workbench = CodeLensEditorPlugin.getDefault().getWorkbench();
		if (workbench != null) {
			IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
			for (IWorkbenchWindow window : windows) {
				windowOpened(window);
			}
			CodeLensEditorPlugin.getDefault().getWorkbench().addWindowListener(this);
		}
	}
}
 
Example 34
Project: gw4e.project   File: FilterTests.java   View source code 5 votes vote down vote up
private void resetWorkbench() {
	try {
		IViewReference[] views = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
		for (IViewReference iViewReference : views) {
			 if ( iViewReference.getTitle().equals( "Welcome" ) ) {
				 	iViewReference.getPage().hideView(iViewReference);
					break;
			}
		}
		
		IWorkbench workbench = PlatformUI.getWorkbench();
		IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
		IWorkbenchPage page = workbenchWindow.getActivePage();
		Shell activeShell = Display.getCurrent().getActiveShell();
		if ( activeShell != null && activeShell != workbenchWindow.getShell() ) {
			activeShell.close();
		}
		page.closeAllEditors( false );
		page.resetPerspective();
		String defaultPerspectiveId = workbench.getPerspectiveRegistry().getDefaultPerspective();
		workbench.showPerspective( defaultPerspectiveId, workbenchWindow );
		page.resetPerspective();
	}
	catch ( WorkbenchException e ) {
		throw new RuntimeException( e );
	}

}
 
Example 35
Project: vertigo-chroma-kspplugin   File: KspEditor.java   View source code 5 votes vote down vote up
@Override
public void createPartControl(Composite parent) {
	super.createPartControl(parent);

	/* Abonnement au changement du fichier. */
	ResourcesPlugin.getWorkspace().addResourceChangeListener(this);

	/* Abonnement au changement de part pour mémoriser l'éditeur courant. */
	IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	window.getPartService().addPartListener(new PartListener());
}
 
Example 36
Project: gemoc-studio   File: WizardFinder.java   View source code 5 votes vote down vote up
static public IWizardDescriptor findNewWizardDescriptor(String wizardId)
{
	return PlatformUI
			.getWorkbench()
			.getNewWizardRegistry()
			.findWizard(wizardId);
}
 
Example 37
Project: n4js   File: N4JSApplication.java   View source code 5 votes vote down vote up
@Override
public void stop() {
	final IWorkbench workbench = PlatformUI.getWorkbench();
	if (workbench == null)
		return;
	final Display display = workbench.getDisplay();
	display.syncExec(new Runnable() {
		@Override
		public void run() {
			if (!display.isDisposed())
				workbench.close();
		}
	});
}
 
Example 38
Project: Hydrograph   File: ProjectExplorerView.java   View source code 5 votes vote down vote up
public boolean isSaveAsAllowed() {
	IEditorPart editorPart = PlatformUI.getWorkbench()
			.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
	
	if (editorPart != null) {
		return editorPart.isSaveAsAllowed();
		}
	return false;
}
 
Example 39
Project: OCCI-Studio   File: DesignerGeneratorAction.java   View source code 5 votes vote down vote up
private void generateDesignTestProject(IProject project, String extensionName, final IProgressMonitor monitor)
		throws CoreException, IOException, WorkbenchException {
	/*
	 * Create design test project
	 */
	IProject testProject = DesignerGeneratorUtils.genDesignTestProject(project, monitor);

	/*
	 * Create design representation
	 */
	final Resource resource = resourceSet.createResource(URI.createURI(
			"platform:/resource/" + testProject.getFullPath() + "/sample." + extensionName.toLowerCase()));
	resource.getContents().add(OCCIFactory.eINSTANCE.createConfiguration());
	resource.save(Collections.EMPTY_MAP);

	// switch perspective
	PlatformUI.getWorkbench().showPerspective("org.eclipse.sirius.ui.tools.perspective.modeling",
			PlatformUI.getWorkbench().getActiveWorkbenchWindow());

	final Session session = ModelingProject.asModelingProject(testProject).get().getSession();
	session.getTransactionalEditingDomain().getCommandStack()
			.execute(new RecordingCommand(session.getTransactionalEditingDomain()) {
				@Override
				protected void doExecute() {
					session.addSemanticResource(resource.getURI(), monitor);
				}
			});

	WizardUtils.enableViewpoint(session,
			"viewpoint:/" + project.getName() + '/' + ConverterUtils.toU1Case(extensionName) + "Configuration");
	String diagramInstanceName = "Sample " + extensionName;
	EObject root = WizardUtils.getRoot(session, resource.getURI());
	WizardUtils.openDiagram(monitor, testProject, "Configuration Diagram", diagramInstanceName, root);

	project.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, monitor);
}
 
Example 40
Project: pgcodekeeper   File: NewProjWizardAction.java   View source code 5 votes vote down vote up
public NewProjWizardAction(){
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
    ISelection selection = window.getSelectionService().getSelection();

    NewProjWizard wizard = new NewProjWizard();
    wizard.init(workbench, selection instanceof IStructuredSelection ?
            (IStructuredSelection) selection : null);
    new WizardDialog(window.getShell(), wizard).open();
}