List of usage examples for org.eclipse.jface.dialogs MessageDialog openError
public static void openError(Shell parent, String title, String message)
From source file:com.aptana.ide.editor.text.preferences.TextEditorPreferencePage.java
License:Open Source License
/** * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) *//*from w w w . j a v a2 s.c o m*/ protected Control createContents(Composite parent) { this.noDefaultAndApplyButton(); changed = false; imagesToDispose = new ArrayList<Image>(); mappings = new ArrayList<FileEditorMapping>(); mappingsToGrammars = new HashMap<String, String>(); activeProviders = new HashMap<String, LanguageStructureProvider>(); displayArea = new Composite(parent, SWT.NONE); final Composite buffer = new Composite(displayArea, SWT.NONE); header = new PreferenceMastHead(buffer, Messages.TextEditorPreferencePage_Allows_Users_To_Create_Custom_Editors, 3, TextPlugin.getImageDescriptor("images/generic_file.png")); //$NON-NLS-1$ buffer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); buffer.setBackground(PreferenceMastHead.HEADER_BG_COLOR); GridLayout layout = new GridLayout(1, true); layout.marginHeight = 0; layout.marginWidth = 0; layout.marginBottom = 10; displayArea.setLayout(layout); buffer.setLayout(layout); buffer.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { GC gc = new GC(buffer); gc.setBackground(PreferenceMastHead.FOOTER_BG_COLOR); if (buffer.getSize().y - 4 >= 0) { gc.fillRectangle(0, buffer.getSize().y - 5, buffer.getSize().x, 5); } } }); displayArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); description = new Label(displayArea, SWT.WRAP | SWT.LEFT); description.setText(Messages.TextEditorPreferencePage_ASSOCIATED_FILE_EXTENSIONS); Composite middle = new Composite(displayArea, SWT.NONE); layout = new GridLayout(2, false); GridData middleData = new GridData(SWT.FILL, SWT.FILL, true, false); middleData.heightHint = 120; middle.setLayout(layout); middle.setLayoutData(middleData); typesTable = new Table(middle, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER); typesTable.setLayout(new GridLayout(1, true)); GridData data = new GridData(SWT.FILL, SWT.FILL, true, false); data.heightHint = 100; typesTable.setLayoutData(data); typesTable.addSelectionListener(tableSelectionListener); Composite buttons = new Composite(middle, SWT.NONE); layout = new GridLayout(1, true); buttons.setLayout(layout); buttons.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true)); add = new Button(buttons, SWT.PUSH); add.setText(StringUtils.ellipsify(Messages.TextEditorPreferencePage_ADD)); add.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); add.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { FileExtensionDialog dialog = new FileExtensionDialog(displayArea.getShell()); if (dialog.open() == Window.OK) { changed = true; String newName = dialog.getName(); String newExtension = dialog.getExtension(); // Find the index at which to insert the new entry. String newFilename = (newName + (newExtension == null || newExtension.length() == 0 ? "" : "." + newExtension)) //$NON-NLS-1$//$NON-NLS-2$ .toUpperCase(); IFileEditorMapping newMapping; TableItem[] items = typesTable.getItems(); boolean found = false; int i = 0; while (i < items.length && !found) { newMapping = (IFileEditorMapping) items[i].getData(); int result = newFilename.compareToIgnoreCase(newMapping.getLabel()); if (result == 0) { // Same resource type not allowed! MessageDialog.openInformation(getControl().getShell(), Messages.TextEditorPreferencePage_FILE_TYPE_EXISTS, Messages.TextEditorPreferencePage_FILE_TYPE_EXISTS_TITLE); return; } if (result < 0) { found = true; } else { i++; } } newMapping = getFileEditorMapping(newName, newExtension); addTypesTableItem(newMapping, i); typesTable.setFocus(); typesTable.setSelection(i); tableSelectionListener.widgetSelected(null); } } }); remove = new Button(buttons, SWT.PUSH); remove.setText(Messages.TextEditorPreferencePage_REMOVE_ASSOCIATION); remove.setEnabled(false); remove.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); remove.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { if (typesTable.getSelectionCount() == 1) { changed = true; TableItem item = typesTable.getSelection()[0]; FileEditorMapping data = (FileEditorMapping) item.getData(); mappings.remove(data); browseGrammar.setEnabled(false); grammarText.setText(""); //$NON-NLS-1$ remove.setEnabled(false); String label = item.getText(); String prefId = TextPlugin.getColorizerPreference(label); UnifiedEditorsPlugin.getDefault().getPreferenceStore().setValue(prefId, ""); //$NON-NLS-1$ LanguageStructureProvider provider = (LanguageStructureProvider) activeProviders.remove(prefId); if (provider != null) { LanguageRegistry.unregisterLanguageColorizer(provider.getLanguage()); TokenList tokenList = LanguageRegistry.getTokenList(provider.getLanguage()); if (tokenList != null) { LanguageRegistry.unregisterTokenList(tokenList); } UnifiedEditorsPlugin.getDefault().getPreferenceStore().firePropertyChangeEvent( "Colorization removed", "Colorization removed", "Colorization removed"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } colorizer.setProvider(null); item.dispose(); } } }); IEditorRegistry registry = EclipseUIUtils.getWorkbenchEditorRegistry(); // Look up generic text editor descriptor = (EditorDescriptor) registry.findEditor(GenericTextEditor.ID); IFileEditorMapping[] array = registry.getFileEditorMappings(); int count = 0; for (int i = 0; i < array.length; i++) { FileEditorMapping mapping = (FileEditorMapping) array[i]; mapping = (FileEditorMapping) mapping.clone(); // want a copy mappings.add(mapping); if (mapping.getDefaultEditor() != null && mapping.getDefaultEditor().getId().equals(GenericTextEditor.ID)) { String label = mapping.getLabel(); String extension = mapping.getExtension(); // This check allows us to internally contribute generic text editor association without making them // visible in the pref page (but configurable elsewhere) if (LanguageRegistry.getTokenListByExtension(extension) == null) { String grammarFile = store.getString(TextPlugin.getGrammarPreference(label)); if (!grammarFile.equals("")) //$NON-NLS-1$ { mappingsToGrammars.put(label, grammarFile); } addTypesTableItem(mapping, count); count++; } } } grammarGroup = new Group(displayArea, SWT.NONE); grammarGroup.setLayout(new GridLayout(2, false)); grammarGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); grammarGroup.setText(Messages.TextEditorPreferencePage_GRAMMAR_FILE); grammarText = new Text(grammarGroup, SWT.READ_ONLY | SWT.LEFT | SWT.SINGLE | SWT.BORDER); ModifyListener gListener = new ModifyListener() { public void modifyText(ModifyEvent e) { if (typesTable.getSelectionCount() == 1) { TableItem item = typesTable.getSelection()[0]; mappingsToGrammars.put(item.getText(), grammarText.getText()); changed = true; } } }; grammarText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); grammarText.addModifyListener(gListener); browseGrammar = new Button(grammarGroup, SWT.PUSH); browseGrammar.setText(StringUtils.ellipsify(Messages.TextEditorPreferencePage_BROWSE)); browseGrammar.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { FileDialog fileDialog = new FileDialog(displayArea.getShell()); fileDialog.setFilterExtensions(new String[] { "*.lxr" }); //$NON-NLS-1$ String fileName = fileDialog.open(); if (fileName != null) { try { AttributeSniffer sniffer = new AttributeSniffer("lexer", "language"); //$NON-NLS-1$ //$NON-NLS-2$ sniffer.read(fileName); String newLanguage = sniffer.getMatchedValue(); if (newLanguage != null) { if (!LanguageRegistry.hasTokenList(newLanguage)) { grammarText.setText(fileName); tableSelectionListener.widgetSelected(e); } else { UIJob errorJob = new UIJob( Messages.TextEditorPreferencePage_Error_Loading_Language) { public IStatus runInUIThread(IProgressMonitor monitor) { MessageDialog.openError(getShell(), Messages.TextEditorPreferencePage_Error_Adding_Language, Messages.TextEditorPreferencePage_Language_Already_Supported); return Status.OK_STATUS; } }; errorJob.schedule(); } } } catch (final Exception e1) { UIJob errorJob = new UIJob(Messages.TextEditorPreferencePage_Error_Loading_Lexer_File) { public IStatus runInUIThread(IProgressMonitor monitor) { MessageDialog.openError(getShell(), Messages.TextEditorPreferencePage_Error_Loading_Lexer_File, e1.getMessage()); return Status.OK_STATUS; } }; errorJob.schedule(); } } } }); browseGrammar.setEnabled(false); colorizerGroup = new Group(displayArea, SWT.NONE); colorizerGroup.setText(Messages.TextEditorPreferencePage_COLORIATION_FILE); colorizerGroup.setLayout(new GridLayout(1, false)); colorizerGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); applyChanges = new Button(colorizerGroup, SWT.PUSH); applyChanges.setText(Messages.TextEditorPreferencePage_Apply_Changes); applyChanges.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { if (typesTable.getSelectionCount() == 1) { TableItem item = typesTable.getSelection()[0]; String colorizerId = TextPlugin.getColorizerPreference(item.getText()); if (activeProviders.containsKey(colorizerId)) { LanguageStructureProvider provider = (LanguageStructureProvider) activeProviders .get(colorizerId); LanguageColorizer colorizer = LanguageRegistry.getLanguageColorizer(provider.getLanguage()); provider.buildLanguageColorizer(colorizer, colorizerId); } } } }); applyChanges.setEnabled(true); colorizer = new LanguageColorizationWidget(); data = new GridData(SWT.FILL, SWT.FILL, true, true); colorizer.createControl(colorizerGroup, data); colorizer.collapseAll(); return displayArea; }
From source file:com.aptana.ide.editors.junit.TestSelectionFormattingAction.java
License:Open Source License
/** * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) *///from w ww . j a v a 2 s .c o m public void run(IAction action) { try { IProject project = ProjectTestUtils.createProject("test format"); Path path = ProjectTestUtils.findFileInPlugin("com.aptana.ide.editors.junit", //$NON-NLS-1$ "format/dojo.js"); IFile file = ProjectTestUtils.addFileToProject(path, project); final JSEditor editor = (JSEditor) ProjectTestUtils.openInEditor(file, ProjectTestUtils.JS_EDITOR_ID); final StyledText text = editor.getViewer().getTextWidget(); final IDocument document = editor.getViewer().getDocument(); UIJob cpJob = new UIJob("Copy Pasting") { int currentIndex = 0; int currentLenght = 1; int errors = 0; public IStatus runInUIThread(IProgressMonitor monitor) { final String original = document.get(); CodeFormatAction action = new CodeFormatAction(); action.setActiveEditor(null, editor); try { String finalString = null; if (currentIndex < document.getLength()) { text.setSelection(currentIndex, currentLenght); action.run(); finalString = text.getText(); if (!finalString.equals(original)) { document.set(original); System.out.println("Selection Formatting Error:" + errors + " Position:" + currentIndex + " Length:" + currentLenght); errors++; } if (currentLenght < document.getLength()) { currentLenght++; } else { currentIndex++; currentLenght = 1; } } } catch (Exception e) { } this.schedule(100); return Status.OK_STATUS; } }; cpJob.schedule(); } catch (Exception e) { MessageDialog.openError(Display.getDefault().getActiveShell(), "Error formatting", e.getMessage()); } }
From source file:com.aptana.ide.editors.untitled.BaseTextEditor.java
License:Open Source License
private File doExternalSaveAs(IProgressMonitor progressMonitor) { Shell shell = getSite().getShell();/*from www . j a va 2 s . com*/ IDocumentProvider provider = getDocumentProvider(); IEditorInput input = getEditorInput(); FileDialog fileDialog = new FileDialog(shell, SWT.SAVE); String fileName = getDefaultSaveAsFile(); fileDialog.setFileName(getBaseFilename(fileName)); FileDialogFilterInfo filterInfo = getFileDialogFilterInformation(fileName); String[] fileExtensions = filterInfo.getFilterExtensions(); if (fileExtensions != null && fileExtensions.length > 0) { fileDialog.setFilterExtensions(fileExtensions); fileDialog.setFilterNames(filterInfo.getFilterNames()); } // [IM] This appears to have no effect on OSX. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=101948 if (directoryHint != null) { File f = new File(directoryHint); if (f.exists()) { fileDialog.setFilterPath(directoryHint); } } String text = fileDialog.open(); if (text == null) { if (progressMonitor != null) { progressMonitor.setCanceled(true); } return null; } File file = new File(text); final IEditorInput newInput = CoreUIUtils.createJavaFileEditorInput(file); boolean success = false; try { provider.aboutToChange(newInput); provider.saveDocument(progressMonitor, newInput, provider.getDocument(input), true); success = true; } catch (CoreException x) { IStatus status = x.getStatus(); if (status == null || status.getSeverity() != IStatus.CANCEL) { String title = Messages.BaseTextEditor_SaveFileError; String msg = StringUtils.format(Messages.BaseTextEditor_ErrorSaving, new Object[] { x.getMessage() }); if (status != null) { switch (status.getSeverity()) { case IStatus.INFO: MessageDialog.openInformation(shell, title, msg); break; case IStatus.WARNING: MessageDialog.openWarning(shell, title, msg); break; default: MessageDialog.openError(shell, title, msg); } } else { MessageDialog.openError(shell, title, msg); } } } finally { provider.changed(newInput); if (success) { setInput(newInput); } } if (progressMonitor != null) { progressMonitor.setCanceled(!success); } if (success) { return file; } else { return null; } }
From source file:com.aptana.ide.editors.views.profiles.ProfilesView.java
License:Open Source License
private void changeEnvironment() { UIJob job = new UIJob(Messages.ProfilesView_Refreshing_environment_job_title) { public IStatus runInUIThread(IProgressMonitor monitor) { bar.setSelection(4);/*from w w w . j ava 2s .c om*/ TableItem[] items = globalEnvironments.getItems(); List<String> environments = new ArrayList<String>(); List<String> disabledEnvironments = new ArrayList<String>(); for (int i = 0; i < items.length; i++) { if (items[i].getChecked()) { environments.add(items[i].getText().trim()); } else { disabledEnvironments.add(items[i].getText().trim()); } } JSLanguageEnvironment.setEnabledEnvironments(environments.toArray(new String[0])); JSLanguageEnvironment.setDisabledEnvironments(disabledEnvironments.toArray(new String[0])); try { JSLanguageEnvironment.resetEnvironment(); } catch (Exception e) { MessageDialog.openError(getDisplay().getActiveShell(), Messages.ProfilesView_ERR_Setting_global_refs, Messages.ProfilesView_ERR_MSG_error_occurred_setting_global_refs); IdeLog.logError(JSPlugin.getDefault(), Messages.ProfilesView_ERR_Setting_global_refs, e); } bar.setSelection(5); GridData data = (GridData) bar.getLayoutData(); data.exclude = true; bar.setVisible(false); accordion.getDrawerArea(globalDrawer).layout(true, true); globalEnvironments.setEnabled(true); return Status.OK_STATUS; } }; job.schedule(); }
From source file:com.aptana.ide.editors.wizards.SimpleNewFileWizard.java
License:Open Source License
/** * This method is called when 'Finish' button is pressed in * the wizard. We will create an operation and run it * using wizard as execution context./*from www . ja va 2 s. c om*/ * @return boolean */ public boolean performFinish() { final String containerName = page.getContainerName(); final String fileName = page.getFileName(); IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException { try { doFinish(containerName, fileName, monitor); } catch (CoreException e) { throw new InvocationTargetException(e); } finally { monitor.done(); } } }; try { getContainer().run(true, false, op); } catch (InterruptedException e) { return false; } catch (InvocationTargetException e) { Throwable realException = e.getTargetException(); MessageDialog.openError(getShell(), Messages.SimpleNewFileWizard_Error, realException.getMessage()); return false; } return true; }
From source file:com.aptana.ide.installer.actions.InstallFeatureAction.java
License:Open Source License
/** * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) *//*w w w . j av a 2 s .co m*/ public void run(IAction action) { if (selectedFeatures == null || selectedFeatures.length == 0) { Activator.launchWizard(false); } else { try { Activator.getDefault().getPluginManager().install(selectedFeatures, new NullProgressMonitor()); } catch (PluginManagerException e) { IdeLog.logError(Activator.getDefault(), e.getMessage(), e); MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.getString("InstallFeatureAction.ERR_TTL_Unable_install_plugin"), //$NON-NLS-1$ Messages.getString("InstallFeatureAction.ERR_MSG_Unable_install_plugin") //$NON-NLS-1$ + selectedFeatures[0].getName()); } } }
From source file:com.aptana.ide.installer.wizard.InstallerWizard.java
License:Open Source License
/** * @see org.eclipse.jface.wizard.Wizard#performFinish() *///from w ww .j a v a 2 s. com @Override public boolean performFinish() { // installs the selected plug-ins Plugin[] plugins = fPluginsPage.getSelectedPlugins(); try { Activator.getDefault().getPluginManager().install(plugins, new NullProgressMonitor()); } catch (PluginManagerException e) { IdeLog.logError(com.aptana.ide.installer.Activator.getDefault(), e.getMessage(), e); MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.InstallerWizard_ERR_TTL_Unable_install_plugin, NLS.bind(Messages.InstallerWizard_ERR_MSG_Unable_install_plugin, plugins[0].getName())); } return true; }
From source file:com.aptana.ide.intro.actions.CoreIntroAction.java
License:Open Source License
/** * @see org.eclipse.ui.intro.config.IIntroAction#run(org.eclipse.ui.intro.IIntroSite, java.util.Properties) *///from ww w. java 2 s.co m public final void run(IIntroSite site, Properties params) { try { runDelegate(site, params); } catch (Exception e) { if (params != null) { final String errorMessage = params.getProperty(ParameterConstants.ERROR_MESSAGE); if (errorMessage != null) { UIJob errorJob = new UIJob(Messages.CoreIntroAction_Job_ErrorRunAction) { public IStatus runInUIThread(IProgressMonitor monitor) { MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.CoreIntroAction_ERR_RunAction, errorMessage); return Status.OK_STATUS; } }; errorJob.schedule(); } } } }
From source file:com.aptana.ide.intro.browser.CoreBrowserEditor.java
License:Open Source License
/** * @see org.eclipse.ui.internal.browser.WebBrowserEditor#doSaveAs() *///from w w w . j a v a2s. co m public void doSaveAs() { if (browserInput != null) { String fileName = browserInput.getSaveAsFileName(); File file = browserInput.getSaveAsFile(); if (fileName != null && file != null && file.exists() && file.canRead()) { FileDialog dialog = new FileDialog(displayArea.getShell(), SWT.SAVE); dialog.setFileName(fileName); dialog.setFilterExtensions(new String[] { "*.html", "*.htm" }); //$NON-NLS-1$ //$NON-NLS-2$ String outputName = dialog.open(); if (outputName != null) { FileInputStream stream; try { stream = new FileInputStream(file); FileUtils.writeStreamToFile(stream, outputName); } catch (Exception e) { MessageDialog.openError(displayArea.getShell(), Messages.CoreBrowserEditor_ErrorSave_Title, Messages.CoreBrowserEditor_ErrorSave_Message + e.getMessage()); } } } } }
From source file:com.aptana.ide.logging.view.LogTab.java
License:Open Source License
/** * Clears log file.//w w w. ja v a 2 s . c o m */ public void clearLogFile() { try { resource.clear(); } catch (IOException e) { MessageDialog.openError(this.getItem().getControl().getShell(), com.aptana.ide.logging.view.Messages.LogTab_2, com.aptana.ide.logging.view.Messages.LogTab_1 //$NON-NLS-2$ + resource.getURI().getPath()); } reload(); }