001: /*******************************************************************************
002: * Copyright (c) 2004, 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.ui.internal.keys;
011:
012: import org.eclipse.jface.bindings.BindingManager;
013: import org.eclipse.jface.bindings.Scheme;
014: import org.eclipse.ui.commands.IKeyConfiguration;
015: import org.eclipse.ui.commands.IKeyConfigurationListener;
016: import org.eclipse.ui.commands.NotDefinedException;
017:
018: /**
019: * A wrapper around the new {@link Scheme} class, providing supported for the
020: * old {@link IKeyConfiguration} interface.
021: *
022: * @since 3.1
023: */
024: public final class SchemeLegacyWrapper implements IKeyConfiguration {
025:
026: /**
027: * The binding manager managing this scheme. This value is never
028: * <code>null</code>.
029: */
030: private final BindingManager bindingManager;
031:
032: /**
033: * The wrapped scheme; never <code>null</code>
034: */
035: private final Scheme scheme;
036:
037: /**
038: * Constructs a new instance of <code>SchemeWrapper</code>.
039: *
040: * @param scheme
041: * The scheme to be wrapped; must not be <code>null</code>.
042: * @param bindingManager
043: * The binding manager for this scheme; must not be
044: * <code>null</code>.
045: */
046: public SchemeLegacyWrapper(final Scheme scheme,
047: final BindingManager bindingManager) {
048: if (scheme == null) {
049: throw new NullPointerException("Cannot wrap a null scheme"); //$NON-NLS-1$
050: }
051:
052: if (bindingManager == null) {
053: throw new NullPointerException(
054: "Cannot wrap a scheme without a binding manager"); //$NON-NLS-1$
055: }
056:
057: this .scheme = scheme;
058: this .bindingManager = bindingManager;
059: }
060:
061: /*
062: * (non-Javadoc)
063: *
064: * @see org.eclipse.ui.commands.IKeyConfiguration#addKeyConfigurationListener(org.eclipse.ui.commands.IKeyConfigurationListener)
065: */
066: public void addKeyConfigurationListener(
067: IKeyConfigurationListener keyConfigurationListener) {
068: scheme.addSchemeListener(new LegacySchemeListenerWrapper(
069: keyConfigurationListener, bindingManager));
070: }
071:
072: /*
073: * (non-Javadoc)
074: *
075: * @see java.lang.Comparable#compareTo(java.lang.Object)
076: */
077: public int compareTo(Object o) {
078: return scheme.compareTo(o);
079: }
080:
081: /*
082: * (non-Javadoc)
083: *
084: * @see org.eclipse.ui.commands.IKeyConfiguration#getDescription()
085: */
086: public String getDescription() throws NotDefinedException {
087: try {
088: return scheme.getDescription();
089: } catch (final org.eclipse.core.commands.common.NotDefinedException e) {
090: throw new NotDefinedException(e);
091: }
092: }
093:
094: /*
095: * (non-Javadoc)
096: *
097: * @see org.eclipse.ui.commands.IKeyConfiguration#getId()
098: */
099: public String getId() {
100: return scheme.getId();
101: }
102:
103: /*
104: * (non-Javadoc)
105: *
106: * @see org.eclipse.ui.commands.IKeyConfiguration#getName()
107: */
108: public String getName() throws NotDefinedException {
109: try {
110: return scheme.getName();
111: } catch (final org.eclipse.core.commands.common.NotDefinedException e) {
112: throw new NotDefinedException(e);
113: }
114: }
115:
116: /*
117: * (non-Javadoc)
118: *
119: * @see org.eclipse.ui.commands.IKeyConfiguration#getParentId()
120: */
121: public String getParentId() throws NotDefinedException {
122: try {
123: return scheme.getParentId();
124: } catch (final org.eclipse.core.commands.common.NotDefinedException e) {
125: throw new NotDefinedException(e);
126: }
127: }
128:
129: /*
130: * (non-Javadoc)
131: *
132: * @see org.eclipse.ui.commands.IKeyConfiguration#isActive()
133: */
134: public boolean isActive() {
135: return scheme.getId().equals(
136: bindingManager.getActiveScheme().getId());
137: }
138:
139: /*
140: * (non-Javadoc)
141: *
142: * @see org.eclipse.ui.commands.IKeyConfiguration#isDefined()
143: */
144: public boolean isDefined() {
145: return scheme.isDefined();
146: }
147:
148: /*
149: * (non-Javadoc)
150: *
151: * @see org.eclipse.ui.commands.IKeyConfiguration#removeKeyConfigurationListener(org.eclipse.ui.commands.IKeyConfigurationListener)
152: */
153: public void removeKeyConfigurationListener(
154: IKeyConfigurationListener keyConfigurationListener) {
155: scheme.removeSchemeListener(new LegacySchemeListenerWrapper(
156: keyConfigurationListener, bindingManager));
157:
158: }
159:
160: }
|