List of usage examples for org.eclipse.jface.preference IPreferencePage okToLeave
public boolean okToLeave();
From source file:de.uniluebeck.itm.spyglass.gui.configuration.PluginPreferenceDialog.java
License:Open Source License
/** * Returns if the currently visible preference dialog page has unsaved changes * /*from w w w .j av a2s . c o m*/ * @return <code>true</code> if the currently visible preference dialog page has unsaved changes */ @SuppressWarnings("unchecked") private boolean hasUnsavedChanges() { final IPreferencePage selectedPage = (IPreferencePage) preferenceDialog.getSelectedPage(); // no page selected so it's ok to continue if (selectedPage == null) { return false; } boolean hashUnsavedChanges = false; // check if we're looking at general preference page or plug-in preference page if (selectedPage instanceof PluginManagerPreferencePage) { hashUnsavedChanges = !selectedPage.okToLeave(); } // check if we're looking at general preference page or plug-in preference page if (selectedPage instanceof GeneralPreferencePage) { hashUnsavedChanges = ((GeneralPreferencePage) selectedPage).hasUnsavedChanges(); } if (selectedPage instanceof PluginPreferencePage) { // check if currently opened preference page contains unsaved values if (((PluginPreferencePage<? extends Plugin, ? extends PluginXMLConfig>) selectedPage) .hasUnsavedChanges()) { hashUnsavedChanges = true; } } else { if (!(selectedPage).okToLeave()) { hashUnsavedChanges = true; } } return hashUnsavedChanges; }
From source file:org.mailster.gui.prefs.ConfigurationDialog.java
License:Open Source License
/** * Shows the preference page corresponding to the given preference node. * Does nothing if that page is already current. This implementation * prevents auto resizing./*from w w w . j av a 2 s . c o m*/ * * @param node the preference node, or <code>null</code> if none * @return <code>true</code> if the page flip was successful; * <code>false</code> if unsuccessful */ protected boolean showPage(IPreferenceNode node) { IPreferencePage currentPage = this.getCurrentPage(); final Composite pageContainer = this.getPageContainer(); if (node == null) return false; // Create the page if nessessary if (node.getPage() == null) this.createPage(node); if (node.getPage() == null) return false; IPreferencePage newPage = this.getPage(node); if (newPage == currentPage) return true; if (currentPage != null && !currentPage.okToLeave()) return (false); IPreferencePage oldPage = currentPage; this.setCurrentPage(newPage); currentPage = this.getCurrentPage(); // Set the new page's container currentPage.setContainer(this); // Ensure that the page control has been created // (this allows lazy page control creation) final IPreferencePage curPage = currentPage; if (currentPage.getControl() == null) { final boolean[] failed = { false }; SafeRunnable.run(new ISafeRunnable() { public void handleException(Throwable e) { failed[0] = true; } public void run() { createPageControl(curPage, pageContainer); } }); if (failed[0]) return false; // the page is responsible for ensuring the created control is // accessable via getControl. Assert.isNotNull(currentPage.getControl()); } // Force calculation of the page's description label because // label can be wrapped. final Point[] size = new Point[1]; final Point failed = new Point(-1, -1); SafeRunnable.run(new ISafeRunnable() { public void handleException(Throwable e) { size[0] = failed; } public void run() { size[0] = curPage.computeSize(); } }); if (size[0].equals(failed)) return false; // Do we need resizing. Computation not needed if the // first page is inserted since computing the dialog's // size is done by calling dialog.open(). // Also prevent auto resize if the user has manually resized if (oldPage != null) { Rectangle rect = pageContainer.getClientArea(); Point containerSize = new Point(rect.width, rect.height); // Set the size to be sure we use the result of computeSize currentPage.setSize(containerSize); } // Ensure that all other pages are invisible // (including ones that triggered an exception during // their creation). Control[] children = pageContainer.getChildren(); Control currentControl = currentPage.getControl(); for (int i = 0; i < children.length; i++) { if (children[i] != currentControl) children[i].setVisible(false); } // Make the new page visible currentPage.setVisible(true); if (oldPage != null) oldPage.setVisible(false); // update the dialog controls this.update(); return true; }