List of usage examples for org.eclipse.jface.dialogs DialogPage getShell
public Shell getShell()
From source file:org.eclipse.ui.ide.dialogs.ResourceEncodingFieldEditor.java
License:Open Source License
protected void doStore() { String encoding = getSelectedEncoding(); // Clear the value if nothing is selected if (isDefaultSelected()) { encoding = null;/*from ww w. j a v a2s.c o m*/ } // Don't update if the same thing is selected final boolean hasSameEncoding = hasSameEncoding(encoding); final boolean hasSameSeparateDerivedEncodings = hasSameSeparateDerivedEncodings(); if (hasSameEncoding && hasSameSeparateDerivedEncodings) { return; } String descriptionCharset = getCharsetFromDescription(); if (descriptionCharset != null && !(descriptionCharset.equals(encoding)) && encoding != null) { Shell shell = null; DialogPage page = getPage(); if (page != null) { shell = page.getShell(); } MessageDialog dialog = new MessageDialog(shell, IDEWorkbenchMessages.ResourceEncodingFieldEditor_EncodingConflictTitle, null, NLS.bind(IDEWorkbenchMessages.ResourceEncodingFieldEditor_EncodingConflictMessage, encoding, descriptionCharset), MessageDialog.WARNING, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0) { protected int getShellStyle() { return super.getShellStyle() | SWT.SHEET; } }; // yes is the // default if (dialog.open() > 0) { return; } } IDEEncoding.addIDEEncoding(encoding); final String finalEncoding = encoding; Job charsetJob = new Job(IDEWorkbenchMessages.IDEEncoding_EncodingJob) { /* * (non-Javadoc) * * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) */ protected IStatus run(IProgressMonitor monitor) { try { if (!hasSameEncoding) { if (resource instanceof IContainer) { ((IContainer) resource).setDefaultCharset(finalEncoding, monitor); } else { ((IFile) resource).setCharset(finalEncoding, monitor); } } if (!hasSameSeparateDerivedEncodings) { Preferences prefs = new ProjectScope((IProject) resource) .getNode(ResourcesPlugin.PI_RESOURCES); if (getStoredSeparateDerivedEncodingsValue()) prefs.remove(ResourcesPlugin.PREF_SEPARATE_DERIVED_ENCODINGS); else prefs.putBoolean(ResourcesPlugin.PREF_SEPARATE_DERIVED_ENCODINGS, true); prefs.flush(); } return Status.OK_STATUS; } catch (CoreException e) {// If there is an error return the // default IDEWorkbenchPlugin.log(IDEWorkbenchMessages.ResourceEncodingFieldEditor_ErrorStoringMessage, e.getStatus()); return e.getStatus(); } catch (BackingStoreException e) { IDEWorkbenchPlugin.log(IDEWorkbenchMessages.ResourceEncodingFieldEditor_ErrorStoringMessage, e); return new Status(IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH, e.getMessage(), e); } } }; charsetJob.schedule(); }