/** * Save the values specified in the pages. * * <p>The default implementation of this framework method saves all pages of type <code> * PreferencePage</code> (if their store needs saving and is a <code>PreferenceStore</code>). * * <p>Subclasses may override. */ protected void handleSave() { Iterator<IPreferenceNode> nodes = preferenceManager.getElements(PreferenceManager.PRE_ORDER).iterator(); while (nodes.hasNext()) { IPreferenceNode node = nodes.next(); IPreferencePage page = node.getPage(); if (page instanceof PreferencePage) { // Save now in case tbe workbench does not shutdown cleanly IPreferenceStore store = ((PreferencePage) page).getPreferenceStore(); if (store != null && store.needsSaving() && store instanceof IPersistentPreferenceStore) { try { ((IPersistentPreferenceStore) store).save(); } catch (IOException e) { String message = JFaceResources.format( "PreferenceDialog.saveErrorMessage", page.getTitle(), // $NON-NLS-1$ e.getMessage()); Policy.getStatusHandler() .show( new Status(IStatus.ERROR, Policy.JFACE, message, e), JFaceResources.getString("PreferenceDialog.saveErrorTitle")); // $NON-NLS-1$ } } } } }
@Override public void updateTitle() { if (currentPage == null) { return; } messageArea.showTitle(currentPage.getTitle(), currentPage.getImage()); }
@Override public void updateMessage() { String message = null; String errorMessage = null; if (currentPage != null) { message = currentPage.getMessage(); errorMessage = currentPage.getErrorMessage(); } int messageType = IMessageProvider.NONE; if (message != null && currentPage instanceof IMessageProvider) { messageType = ((IMessageProvider) currentPage).getMessageType(); } if (errorMessage == null) { if (showingError) { // we were previously showing an error showingError = false; } } else { message = errorMessage; messageType = IMessageProvider.ERROR; if (!showingError) { // we were not previously showing an error showingError = true; } } messageArea.updateText(message, messageType); }
/** Selects the page determined by <code>lastSuccessfulNode</code> in the page hierarchy. */ void selectCurrentPageAgain() { if (lastSuccessfulNode == null) { return; } getTreeViewer().setSelection(new StructuredSelection(lastSuccessfulNode)); currentPage.setVisible(true); }
/** * Returns whether the current page is valid. * * @return <code>false</code> if the current page is not valid, or or <code>true</code> if the * current page is valid or there is no current page */ protected boolean isCurrentPageValid() { if (currentPage == null) { return true; } return currentPage.isValid(); }
/** * Notifies of the pressing of the Help button. * * <p>The default implementation of this framework method calls <code>performHelp</code> on the * currently active page. */ protected void helpPressed() { if (currentPage != null) { currentPage.performHelp(); } }
/** * Create the page control for the supplied page. * * @param page - the preference page to be shown * @param parent - the composite to parent the page * @since 3.1 */ protected void createPageControl(IPreferencePage page, Composite parent) { page.createControl(parent); }
/** * Shows the preference page corresponding to the given preference node. Does nothing if that page * is already current. * * @param node the preference node, or <code>null</code> if none * @return <code>true</code> if the page flip was successful, and <code>false</code> is * unsuccessful */ protected boolean showPage(IPreferenceNode node) { if (node == null) { return false; } // Create the page if nessessary if (node.getPage() == null) { createPage(node); } if (node.getPage() == null) { return false; } IPreferencePage newPage = getPage(node); if (newPage == currentPage) { return true; } if (currentPage != null) { if (!currentPage.okToLeave()) { return false; } } IPreferencePage oldPage = currentPage; currentPage = newPage; // Set the new page's container currentPage.setContainer(this); // Ensure that the page control has been created // (this allows lazy page control creation) if (currentPage.getControl() == null) { final boolean[] failed = {false}; SafeRunnable.run( new ISafeRunnable() { @Override public void handleException(Throwable e) { failed[0] = true; } @Override public void run() { createPageControl(currentPage, 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() { @Override public void handleException(Throwable e) { size[0] = failed; } @Override public void run() { size[0] = currentPage.computeSize(); } }); if (size[0].equals(failed)) { return false; } Point contentSize = size[0]; // 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 Shell shell = getShell(); Point shellSize = shell.getSize(); if (oldPage != null) { Rectangle rect = pageContainer.getClientArea(); Point containerSize = new Point(rect.width, rect.height); int hdiff = contentSize.x - containerSize.x; int vdiff = contentSize.y - containerSize.y; if ((hdiff > 0 || vdiff > 0) && shellSize.equals(lastShellSize)) { hdiff = Math.max(0, hdiff); vdiff = Math.max(0, vdiff); setShellSize(shellSize.x + hdiff, shellSize.y + vdiff); lastShellSize = shell.getSize(); if (currentPage.getControl().getSize().x == 0) { currentPage.getControl().setSize(containerSize); } } else { currentPage.getControl().setSize(containerSize); } } scrolled.setMinSize(contentSize); // 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 update(); return true; }