001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.ui.preferences;
011:
012: import org.eclipse.core.runtime.IStatus;
013:
014: import org.eclipse.swt.widgets.Composite;
015: import org.eclipse.swt.widgets.Control;
016:
017: import org.eclipse.ui.texteditor.spelling.IPreferenceStatusMonitor;
018: import org.eclipse.ui.texteditor.spelling.ISpellingPreferenceBlock;
019:
020: import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener;
021:
022: /**
023: * Spelling preference block
024: *
025: * @since 3.1
026: */
027: public class SpellingPreferenceBlock implements
028: ISpellingPreferenceBlock {
029:
030: private class NullStatusChangeListener implements
031: IStatusChangeListener {
032:
033: /*
034: * @see org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener#statusChanged(org.eclipse.core.runtime.IStatus)
035: */
036: public void statusChanged(IStatus status) {
037: }
038: }
039:
040: private class StatusChangeListenerAdapter implements
041: IStatusChangeListener {
042:
043: private IPreferenceStatusMonitor fMonitor;
044:
045: private IStatus fStatus;
046:
047: public StatusChangeListenerAdapter(
048: IPreferenceStatusMonitor monitor) {
049: super ();
050: fMonitor = monitor;
051: }
052:
053: /*
054: * @see org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener#statusChanged(org.eclipse.core.runtime.IStatus)
055: */
056: public void statusChanged(IStatus status) {
057: fStatus = status;
058: fMonitor.statusChanged(status);
059: }
060:
061: public IStatus getStatus() {
062: return fStatus;
063: }
064: }
065:
066: private SpellingConfigurationBlock fBlock = new SpellingConfigurationBlock(
067: new NullStatusChangeListener(), null, null);
068:
069: private SpellingPreferenceBlock.StatusChangeListenerAdapter fStatusMonitor;
070:
071: /*
072: * @see org.eclipse.ui.texteditor.spelling.ISpellingPreferenceBlock#createControl(org.eclipse.swt.widgets.Composite)
073: */
074: public Control createControl(Composite parent) {
075: return fBlock.createContents(parent);
076: }
077:
078: /*
079: * @see org.eclipse.ui.texteditor.spelling.ISpellingPreferenceBlock#initialize(org.eclipse.ui.texteditor.spelling.IPreferenceStatusMonitor)
080: */
081: public void initialize(IPreferenceStatusMonitor statusMonitor) {
082: fStatusMonitor = new StatusChangeListenerAdapter(statusMonitor);
083: fBlock.fContext = fStatusMonitor;
084: }
085:
086: /*
087: * @see org.eclipse.ui.texteditor.spelling.ISpellingPreferenceBlock#canPerformOk()
088: */
089: public boolean canPerformOk() {
090: return fStatusMonitor == null
091: || fStatusMonitor.getStatus() == null
092: || !fStatusMonitor.getStatus().matches(IStatus.ERROR);
093: }
094:
095: /*
096: * @see org.eclipse.ui.texteditor.spelling.ISpellingPreferenceBlock#performOk()
097: */
098: public void performOk() {
099: fBlock.performOk();
100: }
101:
102: /*
103: * @see org.eclipse.ui.texteditor.spelling.ISpellingPreferenceBlock#performDefaults()
104: */
105: public void performDefaults() {
106: fBlock.performDefaults();
107: }
108:
109: /*
110: * @see org.eclipse.ui.texteditor.spelling.ISpellingPreferenceBlock#performRevert()
111: */
112: public void performRevert() {
113: fBlock.performRevert();
114: }
115:
116: /*
117: * @see org.eclipse.ui.texteditor.spelling.ISpellingPreferenceBlock#dispose()
118: */
119: public void dispose() {
120: fBlock.dispose();
121: }
122:
123: /*
124: * @see org.eclipse.ui.texteditor.spelling.ISpellingPreferenceBlock#setEnabled(boolean)
125: */
126: public void setEnabled(boolean enabled) {
127: fBlock.setEnabled(enabled);
128: }
129: }
|