1 11 package org.eclipse.ui.internal.contexts; 12 13 import org.eclipse.core.commands.contexts.Context; 14 import org.eclipse.core.commands.contexts.ContextManager; 15 import org.eclipse.ui.contexts.IContext; 16 import org.eclipse.ui.contexts.IContextListener; 17 import org.eclipse.ui.contexts.NotDefinedException; 18 import org.eclipse.ui.internal.util.Util; 19 20 27 public class ContextLegacyWrapper implements IContext { 28 29 33 private final ContextManager contextManager; 34 35 39 private final Context wrappedContext; 40 41 50 public ContextLegacyWrapper(final Context context, 51 final ContextManager contextManager) { 52 if (context == null) { 53 throw new NullPointerException ( 54 "A wrapper cannot be created on a null context"); } 56 57 if (contextManager == null) { 58 throw new NullPointerException ( 59 "A wrapper cannot be created with a null manager"); } 61 62 wrappedContext = context; 63 this.contextManager = contextManager; 64 } 65 66 71 public void addContextListener(IContextListener contextListener) { 72 final LegacyContextListenerWrapper wrapper = new LegacyContextListenerWrapper( 73 contextListener, contextManager, this); 74 wrappedContext.addContextListener(wrapper); 75 76 80 contextManager.addContextManagerListener(wrapper); 81 } 82 83 88 public int compareTo(Object o) { 89 return Util 90 .compare(wrappedContext, ((ContextLegacyWrapper) o).wrappedContext); 91 } 92 93 98 public String getId() { 99 return wrappedContext.getId(); 100 } 101 102 107 public String getName() throws NotDefinedException { 108 try { 109 return wrappedContext.getName(); 110 } catch (final org.eclipse.core.commands.common.NotDefinedException e) { 111 throw new NotDefinedException(e); 112 } 113 } 114 115 120 public String getParentId() throws NotDefinedException { 121 try { 122 return wrappedContext.getParentId(); 123 } catch (final org.eclipse.core.commands.common.NotDefinedException e) { 124 throw new NotDefinedException(e); 125 } 126 } 127 128 133 public boolean isDefined() { 134 return wrappedContext.isDefined(); 135 } 136 137 142 public boolean isEnabled() { 143 return contextManager.getActiveContextIds().contains( 144 wrappedContext.getId()); 145 } 146 147 152 public void removeContextListener(IContextListener contextListener) { 153 final LegacyContextListenerWrapper wrapper = new LegacyContextListenerWrapper( 154 contextListener, contextManager, this); 155 wrappedContext.removeContextListener(wrapper); 156 contextManager.removeContextManagerListener(wrapper); 157 } 158 159 } 160 | Popular Tags |