⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 preferencedialog.java

📁 jfa2ce 源码帮助开发人员更好的理解运用
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	 */	public void setErrorMessage(String newErrorMessage) {		if (newErrorMessage == null) {			messageArea.clearErrorMessage();		} else {			messageArea.updateText(newErrorMessage, IMessageProvider.ERROR);		}	}	/**	 * Save the last known tree width.	 * 	 * @param width	 *            the width.	 */	private void setLastTreeWidth(int width) {		lastTreeWidth = width;	}	/**	 * Set the message text. If the message line currently displays an error,	 * the message is stored and will be shown after a call to clearErrorMessage	 * <p>	 * Shortcut for <code>setMessage(newMessage, NONE)</code>	 * </p>	 * 	 * @param newMessage	 *            the message, or <code>null</code> to clear the message	 */	public void setMessage(String newMessage) {		setMessage(newMessage, IMessageProvider.NONE);	}	/**	 * Sets the message for this dialog with an indication of what type of	 * message it is.	 * <p>	 * The valid message types are one of <code>NONE</code>,	 * <code>INFORMATION</code>,<code>WARNING</code>, or	 * <code>ERROR</code>.	 * </p>	 * <p>	 * Note that for backward compatibility, a message of type	 * <code>ERROR</code> is different than an error message (set using	 * <code>setErrorMessage</code>). An error message overrides the current	 * message until the error message is cleared. This method replaces the	 * current message and does not affect the error message.	 * </p>	 * 	 * @param newMessage	 *            the message, or <code>null</code> to clear the message	 * @param newType	 *            the message type	 * @since 2.0	 */	public void setMessage(String newMessage, int newType) {		messageArea.updateText(newMessage, newType);	}	/**	 * Sets the minimum page size.	 * 	 * @param minWidth	 *            the minimum page width	 * @param minHeight	 *            the minimum page height	 * @see #setMinimumPageSize(Point)	 */	public void setMinimumPageSize(int minWidth, int minHeight) {		minimumPageSize.x = minWidth;		minimumPageSize.y = minHeight;	}	/**	 * Sets the minimum page size.	 * 	 * @param size	 *            the page size encoded as <code>new Point(width,height)</code>	 * @see #setMinimumPageSize(int,int)	 */	public void setMinimumPageSize(Point size) {		minimumPageSize.x = size.x;		minimumPageSize.y = size.y;	}	/**	 * Sets the preference store for this preference dialog.	 * 	 * @param store	 *            the preference store	 * @see #getPreferenceStore	 */	public void setPreferenceStore(IPreferenceStore store) {		Assert.isNotNull(store);		preferenceStore = store;	}	/**	 * Save the currently selected node.	 */	private void setSelectedNode() {		String storeValue = null;		IStructuredSelection selection = (IStructuredSelection) getTreeViewer().getSelection();		if (selection.size() == 1) {			IPreferenceNode node = (IPreferenceNode) selection.getFirstElement();			storeValue = node.getId();		}		setSelectedNodePreference(storeValue);	}	/**	 * Sets the name of the selected item preference. Public equivalent to	 * <code>setSelectedNodePreference</code>.	 * 	 * @param pageId	 *            The identifier for the page	 * @since 3.0	 */	public void setSelectedNode(String pageId) {		setSelectedNodePreference(pageId);	}	/**	 * Sets the name of the selected item preference.	 * 	 * @param pageId	 *            The identifier for the page	 */	protected void setSelectedNodePreference(String pageId) {		lastPreferenceId = pageId;	}	/**	 * Changes the shell size to the given size, ensuring that it is no larger	 * than the display bounds.	 * 	 * @param width	 *            the shell width	 * @param height	 *            the shell height	 */	private void setShellSize(int width, int height) {		Rectangle preferred = getShell().getBounds();		preferred.width = width;		preferred.height = height;		getShell().setBounds(getConstrainedShellBounds(preferred));	}	/**	 * 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() {				public void handleException(Throwable e) {					failed[0] = true;				}				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() {			public void handleException(Throwable e) {				size[0] = failed;			}			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.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		update();		return true;	}	/**	 * Create the page for the node.	 * @param node	 * 	 * @since 3.1	 */	protected void createPage(IPreferenceNode node) {		node.createPage();	}	/**	 * Get the page for the node.	 * @param node	 * @return IPreferencePage	 * 	 * @since 3.1	 */	protected IPreferencePage getPage(IPreferenceNode node) {		return node.getPage();	}	/**	 * Shows the "Page Flipping abort" dialog.	 */	void showPageFlippingAbortDialog() {		MessageDialog.openError(getShell(), JFaceResources				.getString("AbortPageFlippingDialog.title"), //$NON-NLS-1$				JFaceResources.getString("AbortPageFlippingDialog.message")); //$NON-NLS-1$	}	/**	 * Updates this dialog's controls to reflect the current page.	 */	protected void update() {		// Update the title bar		updateTitle();		// Update the message line		updateMessage();		// Update the buttons		updateButtons();		//Saved the selected node in the preferences		setSelectedNode();		firePageChanged(new PageChangedEvent(this, getCurrentPage()));	}	/*	 * (non-Javadoc)	 * 	 * @see org.eclipse.jface.preference.IPreferencePageContainer#updateButtons()	 */	public void updateButtons() {		okButton.setEnabled(isCurrentPageValid());	}	/*	 * (non-Javadoc)	 * 	 * @see org.eclipse.jface.preference.IPreferencePageContainer#updateMessage()	 */	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);	}	/*	 * (non-Javadoc)	 * 	 * @see org.eclipse.jface.preference.IPreferencePageContainer#updateTitle()	 */	public void updateTitle() {		if(currentPage == null) {			return;		}		messageArea.showTitle(currentPage.getTitle(), currentPage.getImage());	}	/**	 * Update the tree to use the specified <code>Font</code>.	 * 	 * @param dialogFont	 *            the <code>Font</code> to use.	 * @since 3.0	 */	protected void updateTreeFont(Font dialogFont) {		getTreeViewer().getControl().setFont(dialogFont);	}	/**	 * Returns the currentPage.	 * @return IPreferencePage	 * @since 3.1	 */	protected IPreferencePage getCurrentPage() {		return currentPage;	}	/**	 * Sets the current page.	 * @param currentPage	 * 	 * @since 3.1	 */	protected void setCurrentPage(IPreferencePage currentPage) {		this.currentPage = currentPage;	}	/**	 * Set the treeViewer.	 * @param treeViewer	 * 	 * @since 3.1	 */	protected void setTreeViewer(TreeViewer treeViewer) {		this.treeViewer = treeViewer;	}	/**	 * Get the composite that is showing the page.	 *	 * @return Composite.	 * 	 * @since 3.1	 */	protected Composite getPageContainer() {		return this.pageContainer;	}	/**	 * Set the composite that is showing the page.	 * @param pageContainer Composite	 * 	 * @since 3.1	 */	protected void setPageContainer(Composite pageContainer) {		this.pageContainer = pageContainer;	}	/**	 * 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);	}		/**	 * @see org.eclipse.jface.dialogs.IPageChangeProvider#getSelectedPage()	 * 	 * @since 3.1	 */	public Object getSelectedPage() {			return getCurrentPage();		}		/**	 * @see org.eclipse.jface.dialogs.IPageChangeProvider#addPageChangedListener(org.eclipse.jface.dialogs.IPageChangedListener)	 * @since 3.1	 */	public void addPageChangedListener(IPageChangedListener listener) {		pageChangedListeners.add(listener);	}		/**	 * @see org.eclipse.jface.dialogs.IPageChangeProvider#removePageChangedListener(org.eclipse.jface.dialogs.IPageChangedListener)	 * @since 3.1	 */	public void removePageChangedListener(IPageChangedListener listener) {		pageChangedListeners.remove(listener);			}	/**     * Notifies any selection changed listeners that the selected page     * has changed.     * Only listeners registered at the time this method is called are notified.     *     * @param event a selection changed event     *     * @see IPageChangedListener#pageChanged     *      * @since 3.1     */    protected void firePageChanged(final PageChangedEvent event) {        Object[] listeners = pageChangedListeners.getListeners();        for (int i = 0; i < listeners.length; i++) {            final IPageChangedListener l = (IPageChangedListener) listeners[i];            SafeRunnable.run(new SafeRunnable() {                public void run() {                    l.pageChanged(event);                }            });        }    }	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -