@Override public boolean performFinish() { // Open editor on new file. IWorkbenchWindow dw = getWorkbench().getActiveWorkbenchWindow(); IFile file = mainPage.createNewFile(); if (file == null) { return false; } Node node = MarketplaceFactory.eINSTANCE.createNode(); try { file.setContents(new ByteArrayInputStream(MarketplaceSerializer.serialize(node).getBytes()), true, true, new NullProgressMonitor()); } catch (CoreException | IOException e1) { } selectAndReveal(file); try { if (dw != null) { IWorkbenchPage page = dw.getActivePage(); if (page != null) { IDE.openEditor(page, file, true); } } } catch (PartInitException e) { DialogUtil.openError(dw.getShell(), ResourceMessages.FileResource_errorMessage, e.getMessage(), e); } return true; }
/** * Prompts the user for whether to switch perspectives. * * @param window * The workbench window in which to switch perspectives; must not * be <code>null</code> * @param finalPersp * The perspective to switch to; must not be <code>null</code>. * * @return <code>true</code> if it's OK to switch, <code>false</code> * otherwise */ private static boolean confirmPerspectiveSwitch(IWorkbenchWindow window, IPerspectiveDescriptor finalPersp) { IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore(); String pspm = store.getString(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE); if (!IDEInternalPreferences.PSPM_PROMPT.equals(pspm)) { // Return whether or not we should always switch return IDEInternalPreferences.PSPM_ALWAYS.equals(pspm); } String desc = finalPersp.getDescription(); String message; if (desc == null || desc.length() == 0) message = NLS.bind(ResourceMessages.NewProject_perspSwitchMessage, finalPersp.getLabel()); else message = NLS.bind(ResourceMessages.NewProject_perspSwitchMessageWithDesc, new String[] { finalPersp.getLabel(), desc }); MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(window.getShell(), ResourceMessages.NewProject_perspSwitchTitle, message, null /* use the default message for the toggle */, false /* toggle is initially unchecked */, store, IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE); int result = dialog.getReturnCode(); // If we are not going to prompt anymore propogate the choice. if (dialog.getToggleState()) { String preferenceValue; if (result == IDialogConstants.YES_ID) { // Doesn't matter if it is replace or new window // as we are going to use the open perspective setting preferenceValue = IWorkbenchPreferenceConstants.OPEN_PERSPECTIVE_REPLACE; } else { preferenceValue = IWorkbenchPreferenceConstants.NO_NEW_PERSPECTIVE; } // update PROJECT_OPEN_NEW_PERSPECTIVE to correspond PrefUtil.getAPIPreferenceStore().setValue(IDE.Preferences.PROJECT_OPEN_NEW_PERSPECTIVE, preferenceValue); } return result == IDialogConstants.YES_ID; }
public void addPages() { mainPage = new WizardNewFilePage(MAIN_PAGE_NAME, getSelection()); mainPage.setTitle(ResourceMessages.FileResource_pageTitle); mainPage.setDescription(ResourceMessages.FileResource_description); templateSelectionPage = new TemplateSelectionPage(TEMPLATE_PAGE_NAME); addPage(mainPage); addPage(templateSelectionPage); }
public boolean performFinish() { IFile file = mainPage.createNewFile(); if (file == null) { return false; } selectAndReveal(file); // Open editor on new file. IWorkbenchWindow dw = getWorkbench().getActiveWorkbenchWindow(); try { if (dw != null) { IWorkbenchPage page = dw.getActivePage(); if (page != null) { IDE.openEditor(page, file, true); } } } catch (PartInitException e) { DialogUtil.openError(dw.getShell(), ResourceMessages.FileResource_errorMessage, e.getMessage(), e); } return true; }
@Override public void addPages() { mainPage = new WizardNewTemplateFilePage(MAIN_PAGE_NAME, getSelection(), template); mainPage.setTitle(ResourceMessages.FileResource_pageTitle); mainPage.setDescription(ResourceMessages.FileResource_description); addPage(mainPage); }
@Override public boolean performFinish() { IFile file = mainPage.createNewFile(); if (file == null) { return false; } selectAndReveal(file); // opens editor on the new file IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow(); try { if (window != null) { IWorkbenchPage page = window.getActivePage(); if (page != null) { IDE.openEditor(page, file, true); } } } catch (PartInitException e) { DialogUtil.openError(window.getShell(), ResourceMessages.FileResource_errorMessage, e.getMessage(), e); } return true; }
@Override public void init(IWorkbench workbench, IStructuredSelection currentSelection) { super.init(workbench, currentSelection); setNeedsProgressMonitor(true); setWindowTitle(ResourceMessages.NewProject_windowTitle); }