org.eclipse.e4.ui.workbench_0.11.0.v20130125-100758

16:43:04.718 INFO  jd.cli.Main - Decompiling org.eclipse.e4.ui.workbench_0.11.0.v20130125-100758.jar
package org.eclipse.e4.ui.internal.workbench;

import java.io.PrintStream;
import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogService;

class Activator$1
  implements LogService
{
  Activator$1(Activator paramActivator) {}
  
  public void log(int level, String message)
  {
    log(null, level, message, null);
  }
  
  public void log(int level, String message, Throwable exception)
  {
    log(null, level, message, exception);
  }
  
  public void log(ServiceReference sr, int level, String message)
  {
    log(sr, level, message, null);
  }
  
  public void log(ServiceReference sr, int level, String message, Throwable exception)
  {
    if (level == 1) {
      System.err.print("ERROR: ");
    } else if (level == 2) {
      System.err.print("WARNING: ");
    } else if (level == 3) {
      System.err.print("INFO: ");
    } else if (level == 4) {
      System.err.print("DEBUG: ");
    } else {
      System.err.print("log level " + level + ": ");
    }
    System.err.println(message);
    if (exception != null) {
      exception.printStackTrace(System.err);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.ui.internal.workbench.Activator.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.ui.internal.workbench;

import java.io.PrintStream;
import org.eclipse.osgi.service.datalocation.Location;
import org.eclipse.osgi.service.debug.DebugOptions;
import org.eclipse.osgi.service.debug.DebugTrace;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogService;
import org.osgi.service.packageadmin.PackageAdmin;
import org.osgi.util.tracker.ServiceTracker;

public class Activator
  implements BundleActivator
{
  public static final String PI_WORKBENCH = "org.eclipse.e4.ui.workbench";
  private static Activator activator;
  private BundleContext context;
  private ServiceTracker locationTracker;
  private ServiceTracker pkgAdminTracker;
  private ServiceTracker debugTracker;
  private ServiceTracker logTracker;
  private DebugTrace trace;
  
  public static Activator getDefault()
  {
    return activator;
  }
  
  public Bundle getBundle()
  {
    return context.getBundle();
  }
  
  public PackageAdmin getBundleAdmin()
  {
    if (pkgAdminTracker == null)
    {
      if (context == null) {
        return null;
      }
      pkgAdminTracker = new ServiceTracker(context, PackageAdmin.class.getName(), null);
      pkgAdminTracker.open();
    }
    return (PackageAdmin)pkgAdminTracker.getService();
  }
  
  public Bundle getBundleForName(String bundleName)
  {
    Bundle[] bundles = getBundleAdmin().getBundles(bundleName, null);
    if (bundles == null) {
      return null;
    }
    for (int i = 0; i < bundles.length; i++) {
      if ((bundles[i].getState() & 0x3) == 0) {
        return bundles[i];
      }
    }
    return null;
  }
  
  public BundleContext getContext()
  {
    return context;
  }
  
  public Location getInstanceLocation()
  {
    if (locationTracker == null)
    {
      Filter filter = null;
      try
      {
        filter = context.createFilter(Location.INSTANCE_FILTER);
      }
      catch (InvalidSyntaxException localInvalidSyntaxException) {}
      locationTracker = new ServiceTracker(context, filter, null);
      locationTracker.open();
    }
    return (Location)locationTracker.getService();
  }
  
  public void start(BundleContext context)
    throws Exception
  {
    activator = this;
    this.context = context;
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    if (pkgAdminTracker != null)
    {
      pkgAdminTracker.close();
      pkgAdminTracker = null;
    }
    if (locationTracker != null)
    {
      locationTracker.close();
      locationTracker = null;
    }
    if (debugTracker != null)
    {
      trace = null;
      debugTracker.close();
      debugTracker = null;
    }
    if (logTracker != null)
    {
      logTracker.close();
      logTracker = null;
    }
  }
  
  public DebugOptions getDebugOptions()
  {
    if (debugTracker == null)
    {
      if (context == null) {
        return null;
      }
      debugTracker = new ServiceTracker(context, DebugOptions.class.getName(), null);
      debugTracker.open();
    }
    return (DebugOptions)debugTracker.getService();
  }
  
  public DebugTrace getTrace()
  {
    if (trace == null) {
      trace = getDebugOptions().newDebugTrace("org.eclipse.e4.ui.workbench");
    }
    return trace;
  }
  
  public static void trace(String option, String msg, Throwable error)
  {
    DebugOptions debugOptions = activator.getDebugOptions();
    if ((debugOptions.isDebugEnabled()) && 
      (debugOptions.getBooleanOption("org.eclipse.e4.ui.workbench" + option, false)))
    {
      System.out.println(msg);
      if (error != null) {
        error.printStackTrace(System.out);
      }
    }
    activator.getTrace().trace(option, msg, error);
  }
  
  public LogService getLogService()
  {
    LogService logService = null;
    if (logTracker != null)
    {
      logService = (LogService)logTracker.getService();
    }
    else if (context != null)
    {
      logTracker = new ServiceTracker(context, LogService.class.getName(), null);
      logTracker.open();
      logService = (LogService)logTracker.getService();
    }
    if (logService == null) {
      logService = new LogService()
      {
        public void log(int level, String message)
        {
          log(null, level, message, null);
        }
        
        public void log(int level, String message, Throwable exception)
        {
          log(null, level, message, exception);
        }
        
        public void log(ServiceReference sr, int level, String message)
        {
          log(sr, level, message, null);
        }
        
        public void log(ServiceReference sr, int level, String message, Throwable exception)
        {
          if (level == 1) {
            System.err.print("ERROR: ");
          } else if (level == 2) {
            System.err.print("WARNING: ");
          } else if (level == 3) {
            System.err.print("INFO: ");
          } else if (level == 4) {
            System.err.print("DEBUG: ");
          } else {
            System.err.print("log level " + level + ": ");
          }
          System.err.println(message);
          if (exception != null) {
            exception.printStackTrace(System.err);
          }
        }
      };
    }
    return logService;
  }
  
  public static void log(int level, String message)
  {
    LogService logService = activator.getLogService();
    if (logService != null) {
      logService.log(level, message);
    }
  }
  
  public static void log(int level, String message, Throwable exception)
  {
    LogService logService = activator.getLogService();
    if (logService != null) {
      logService.log(level, message, exception);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.ui.internal.workbench.Activator
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.ui.internal.workbench;

import org.eclipse.e4.core.contexts.ContextFunction;
import org.eclipse.e4.core.contexts.IEclipseContext;

public class ActiveChildLookupFunction
  extends ContextFunction
{
  private String localVar;
  private String var;
  
  public ActiveChildLookupFunction(String var, String localVar)
  {
    this.var = var;
    this.localVar = localVar;
  }
  
  public Object compute(IEclipseContext context)
  {
    IEclipseContext childContext = context.getActiveChild();
    if (childContext != null) {
      return childContext.get(var);
    }
    return context.get(localVar);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.ui.internal.workbench.ActiveChildLookupFunction
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.ui.internal.workbench;

import org.eclipse.e4.core.contexts.ContextFunction;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.MContext;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;

public class ActivePartLookupFunction
  extends ContextFunction
{
  public Object compute(IEclipseContext context)
  {
    MContext window = (MContext)context.get(MWindow.class);
    if (window == null)
    {
      window = (MContext)context.get(MApplication.class);
      if (window == null) {
        return null;
      }
    }
    IEclipseContext current = window.getContext();
    if (current == null) {
      return null;
    }
    return current.getActiveLeaf().get(MPart.class);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.ui.internal.workbench.ActivePartLookupFunction
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.ui.internal.workbench;

import java.util.Collection;
import javax.inject.Inject;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
import org.eclipse.e4.ui.model.application.ui.basic.MInputPart;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
import org.eclipse.e4.ui.workbench.modeling.IPartListener;

public class ApplicationPartServiceImpl
  implements EPartService
{
  private MApplication application;
  
  @Inject
  ApplicationPartServiceImpl(MApplication application)
  {
    this.application = application;
  }
  
  private EPartService getActiveWindowService()
  {
    IEclipseContext activeWindowContext = application.getContext().getActiveChild();
    if (activeWindowContext == null) {
      throw new IllegalStateException("Application does not have an active window");
    }
    EPartService activeWindowPartService = (EPartService)activeWindowContext.get(EPartService.class);
    if (activeWindowPartService == null) {
      throw new IllegalStateException("Active window context is invalid");
    }
    if (activeWindowPartService == this) {
      throw new IllegalStateException("Application does not have an active window");
    }
    return activeWindowPartService;
  }
  
  public void addPartListener(IPartListener listener)
  {
    throw new UnsupportedOperationException(
      "Listeners should only be attached/removed from a window's part service");
  }
  
  public void removePartListener(IPartListener listener)
  {
    throw new UnsupportedOperationException(
      "Listeners should only be attached/removed from a window's part service");
  }
  
  public void switchPerspective(MPerspective perspective)
  {
    getActiveWindowService().switchPerspective(perspective);
  }
  
  public void activate(MPart part)
  {
    getActiveWindowService().activate(part);
  }
  
  public void activate(MPart part, boolean requiresFocus)
  {
    getActiveWindowService().activate(part, requiresFocus);
  }
  
  public void requestActivation()
  {
    getActiveWindowService().requestActivation();
  }
  
  public void bringToTop(MPart part)
  {
    getActiveWindowService().bringToTop(part);
  }
  
  public MPart findPart(String id)
  {
    return getActiveWindowService().findPart(id);
  }
  
  public Collection<MPart> getParts()
  {
    return getActiveWindowService().getParts();
  }
  
  public MPart getActivePart()
  {
    return getActiveWindowService().getActivePart();
  }
  
  public boolean isPartVisible(MPart part)
  {
    return getActiveWindowService().isPartVisible(part);
  }
  
  public MPart createPart(String id)
  {
    return getActiveWindowService().createPart(id);
  }
  
  public MPlaceholder createSharedPart(String id)
  {
    return getActiveWindowService().createSharedPart(id);
  }
  
  public MPlaceholder createSharedPart(String id, boolean force)
  {
    return getActiveWindowService().createSharedPart(id, force);
  }
  
  public MPart showPart(String id, EPartService.PartState partState)
  {
    return getActiveWindowService().showPart(id, partState);
  }
  
  public MPart showPart(MPart part, EPartService.PartState partState)
  {
    return getActiveWindowService().showPart(part, partState);
  }
  
  public void hidePart(MPart part)
  {
    getActiveWindowService().hidePart(part);
  }
  
  public void hidePart(MPart part, boolean force)
  {
    getActiveWindowService().hidePart(part, force);
  }
  
  public Collection<MPart> getDirtyParts()
  {
    return getActiveWindowService().getDirtyParts();
  }
  
  public boolean savePart(MPart part, boolean confirm)
  {
    return getActiveWindowService().savePart(part, confirm);
  }
  
  public boolean saveAll(boolean confirm)
  {
    return getActiveWindowService().saveAll(confirm);
  }
  
  public Collection<MInputPart> getInputParts(String inputUri)
  {
    return getActiveWindowService().getInputParts(inputUri);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.ui.internal.workbench.ApplicationPartServiceImpl
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.ui.internal.workbench;

import java.util.LinkedList;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.e4.ui.workbench.modeling.IDelta;

public class CompositeDelta
  implements IDelta
{
  private final Object object;
  private final LinkedList<IDelta> deltas = new LinkedList();
  
  public CompositeDelta(Object object)
  {
    this.object = object;
  }
  
  public void add(IDelta delta)
  {
    deltas.add(delta);
  }
  
  public IStatus apply()
  {
    for (IDelta delta : deltas) {
      delta.apply();
    }
    return Status.OK_STATUS;
  }
  
  public Object getObject()
  {
    return object;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.ui.internal.workbench.CompositeDelta
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.ui.internal.workbench;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.e4.ui.workbench.modeling.ModelHandlerBase;

public class ConfigurationElementAdapter
  extends ModelHandlerBase
  implements IAdapterFactory
{
  public static final String CLASS_IMPL = "classImpl";
  
  public Object getAdapter(Object adaptableObject, Class adapterType)
  {
    return this;
  }
  
  public Class[] getAdapterList()
  {
    return new Class[] { ModelHandlerBase.class };
  }
  
  public Object[] getChildren(Object element, String id)
  {
    IConfigurationElement ice = (IConfigurationElement)element;
    IConfigurationElement[] kids = ice.getChildren(id);
    return kids;
  }
  
  public Object getProperty(Object element, String id)
  {
    IConfigurationElement ice = (IConfigurationElement)element;
    if ("label".equals(id))
    {
      String idVal = ice.getAttribute("id");
      String nameVal = ice.getAttribute("name");
      
      String constructedName = "";
      if (nameVal != null)
      {
        constructedName = nameVal;
        if (idVal != null) {
          constructedName = constructedName + " [" + idVal + "]";
        }
      }
      else if (idVal != null)
      {
        constructedName = idVal;
      }
      else
      {
        constructedName = ice.getName();
      }
      return constructedName;
    }
    if ("classImpl".equals(id)) {
      try
      {
        return ice.createExecutableExtension("class");
      }
      catch (CoreException e)
      {
        e.printStackTrace();
        
        return null;
      }
    }
    return ice.getAttribute(id);
  }
  
  public String[] getPropIds(Object element)
  {
    IConfigurationElement ice = (IConfigurationElement)element;
    return ice.getAttributeNames();
  }
  
  public void setProperty(Object element, String id, Object value)
  {
    super.setProperty(element, id, value);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.ui.internal.workbench.ConfigurationElementAdapter
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.ui.internal.workbench;

import java.util.List;
import org.eclipse.e4.ui.model.application.ui.MCoreExpression;

class ContributionsAnalyzer$Key
{
  private int tag = -1;
  private int hc = -1;
  private String parentId;
  private String position;
  private MCoreExpression vexp;
  private Object factory;
  
  public ContributionsAnalyzer$Key(String parentId, String position, List<String> tags, MCoreExpression vexp, Object factory)
  {
    this.parentId = parentId;
    this.position = position;
    this.vexp = vexp;
    this.factory = factory;
    if (tags.contains("scheme:menu")) {
      tag = 1;
    } else if (tags.contains("scheme:popup")) {
      tag = 2;
    } else if (tags.contains("scheme:toolbar")) {
      tag = 3;
    } else {
      tag = 0;
    }
  }
  
  int getSchemeTag()
  {
    return tag;
  }
  
  public boolean equals(Object obj)
  {
    if (!(obj instanceof Key)) {
      return false;
    }
    Key other = (Key)obj;
    Object exp1 = vexp == null ? null : vexp.getCoreExpression();
    Object exp2 = vexp == null ? null : vexp.getCoreExpression();
    return (Util.equals(parentId, parentId)) && (Util.equals(position, position)) && 
      (getSchemeTag() == other.getSchemeTag()) && (Util.equals(exp1, exp2)) && 
      (Util.equals(factory, factory));
  }
  
  public int hashCode()
  {
    if (hc == -1)
    {
      Object exp1 = vexp == null ? null : vexp.getCoreExpression();
      hc = Util.hashCode(parentId);
      hc = (hc * 87 + Util.hashCode(position));
      hc = (hc * 87 + getSchemeTag());
      hc = (hc * 87 + Util.hashCode(exp1));
      hc = (hc * 87 + Util.hashCode(factory));
    }
    return hc;
  }
  
  public String toString()
  {
    return 
      getClass().getName() + " " + parentId + "--" + position + "--" + getSchemeTag() + "--" + vexp;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer.Key
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.ui.internal.workbench;

import java.util.Map;
import org.eclipse.e4.ui.model.application.ui.MCoreExpression;
import org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution;

class ContributionsAnalyzer$MenuKey
  extends ContributionsAnalyzer.Key
{
  static final String FACTORY = "ContributionFactory";
  private MMenuContribution contribution;
  
  public ContributionsAnalyzer$MenuKey(MMenuContribution mc)
  {
    super(mc.getParentId(), mc.getPositionInParent(), mc.getTags(), (MCoreExpression)mc.getVisibleWhen(), mc.getTransientData().get("ContributionFactory"));
    contribution = mc;
    mc.setWidget(this);
  }
  
  public MMenuContribution getContribution()
  {
    return contribution;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer.MenuKey
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.ui.internal.workbench;

import java.util.Map;
import org.eclipse.e4.ui.model.application.ui.MCoreExpression;
import org.eclipse.e4.ui.model.application.ui.menu.MToolBarContribution;

class ContributionsAnalyzer$ToolBarKey
  extends ContributionsAnalyzer.Key
{
  static final String FACTORY = "ToolBarContributionFactory";
  private MToolBarContribution contribution;
  
  public ContributionsAnalyzer$ToolBarKey(MToolBarContribution mc)
  {
    super(mc.getParentId(), mc.getPositionInParent(), mc.getTags(), (MCoreExpression)mc.getVisibleWhen(), mc.getTransientData().get("ToolBarContributionFactory"));
    contribution = mc;
    mc.setWidget(this);
  }
  
  public MToolBarContribution getContribution()
  {
    return contribution;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer.ToolBarKey
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.ui.internal.workbench;

import org.eclipse.e4.ui.model.application.ui.MCoreExpression;
import org.eclipse.e4.ui.model.application.ui.menu.MTrimContribution;

class ContributionsAnalyzer$TrimKey
  extends ContributionsAnalyzer.Key
{
  private MTrimContribution contribution;
  
  public ContributionsAnalyzer$TrimKey(MTrimContribution mc)
  {
    super(mc.getParentId(), mc.getPositionInParent(), mc.getTags(), (MCoreExpression)mc.getVisibleWhen(), null);
    contribution = mc;
    mc.setWidget(this);
  }
  
  public MTrimContribution getContribution()
  {
    return contribution;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer.TrimKey
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.ui.internal.workbench;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.core.expressions.EvaluationResult;
import org.eclipse.core.expressions.Expression;
import org.eclipse.core.expressions.ExpressionInfo;
import org.eclipse.core.internal.expressions.ReferenceExpression;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.commands.MCommand;
import org.eclipse.e4.ui.model.application.ui.MCoreExpression;
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
import org.eclipse.e4.ui.model.application.ui.MExpression;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
import org.eclipse.e4.ui.model.application.ui.basic.MTrimBar;
import org.eclipse.e4.ui.model.application.ui.basic.MTrimElement;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
import org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution;
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
import org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator;
import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu;
import org.eclipse.e4.ui.model.application.ui.menu.MToolBar;
import org.eclipse.e4.ui.model.application.ui.menu.MToolBarContribution;
import org.eclipse.e4.ui.model.application.ui.menu.MToolBarElement;
import org.eclipse.e4.ui.model.application.ui.menu.MToolBarSeparator;
import org.eclipse.e4.ui.model.application.ui.menu.MTrimContribution;
import org.eclipse.e4.ui.workbench.modeling.ExpressionContext;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;

public final class ContributionsAnalyzer
{
  public static void trace(String msg, Throwable error)
  {
    Activator.trace("/trace/menus", msg, error);
  }
  
  private static boolean DEBUG = true;
  public static final String MC_POPUP = "menuContribution:popup";
  public static final String MC_MENU = "menuContribution:menu";
  public static final String MC_TOOLBAR = "menuContribution:toolbar";
  public static final String POPUP_PARENT_ID = "popup";
  
  private static void trace(String msg, Object menu, Object menuModel)
  {
    trace(msg + ": " + menu + ": " + menuModel, null);
  }
  
  public static void gatherTrimContributions(MTrimBar trimModel, List<MTrimContribution> trimContributions, String elementId, ArrayList<MTrimContribution> toContribute, ExpressionContext eContext)
  {
    if ((elementId == null) || (elementId.length() == 0)) {
      return;
    }
    for (MTrimContribution contribution : trimContributions)
    {
      String parentId = contribution.getParentId();
      boolean filtered = isFiltered(trimModel, contribution);
      if ((!filtered) && (elementId.equals(parentId)) && (contribution.isToBeRendered())) {
        toContribute.add(contribution);
      }
    }
  }
  
  static boolean isFiltered(MTrimBar trimModel, MTrimContribution contribution)
  {
    return false;
  }
  
  public static void XXXgatherToolBarContributions(MToolBar toolbarModel, List<MToolBarContribution> toolbarContributionList, String id, ArrayList<MToolBarContribution> toContribute)
  {
    if ((id == null) || (id.length() == 0)) {
      return;
    }
    for (MToolBarContribution toolBarContribution : toolbarContributionList)
    {
      String parentID = toolBarContribution.getParentId();
      boolean filtered = isFiltered(toolbarModel, toolBarContribution);
      if ((!filtered) && (id.equals(parentID)) && (toolBarContribution.isToBeRendered())) {
        toContribute.add(toolBarContribution);
      }
    }
  }
  
  public static void gatherToolBarContributions(MToolBar toolbarModel, List<MToolBarContribution> toolbarContributionList, String id, ArrayList<MToolBarContribution> toContribute, ExpressionContext eContext)
  {
    if ((id == null) || (id.length() == 0)) {
      return;
    }
    for (MToolBarContribution toolBarContribution : toolbarContributionList)
    {
      String parentID = toolBarContribution.getParentId();
      boolean filtered = isFiltered(toolbarModel, toolBarContribution);
      if ((!filtered) && (id.equals(parentID)) && (toolBarContribution.isToBeRendered())) {
        toContribute.add(toolBarContribution);
      }
    }
  }
  
  static boolean isFiltered(MToolBar toolbarModel, MToolBarContribution toolBarContribution)
  {
    return false;
  }
  
  public static void XXXgatherMenuContributions(MMenu menuModel, List<MMenuContribution> menuContributionList, String id, ArrayList<MMenuContribution> toContribute, ExpressionContext eContext, boolean includePopups)
  {
    if ((id == null) || (id.length() == 0)) {
      return;
    }
    ArrayList<String> popupIds = new ArrayList();
    if (includePopups)
    {
      popupIds.add(id);
      for (String tag : menuModel.getTags()) {
        if (tag.startsWith("popup:"))
        {
          String tmp = tag.substring("popup:".length());
          if (!popupIds.contains(tmp)) {
            popupIds.add(tmp);
          }
        }
      }
    }
    for (MMenuContribution menuContribution : menuContributionList)
    {
      String parentID = menuContribution.getParentId();
      if (parentID != null)
      {
        boolean popupTarget = (includePopups) && (popupIds.contains(parentID));
        boolean popupAny = (includePopups) && ((menuModel instanceof MPopupMenu)) && 
          ("popup".equals(parentID));
        boolean filtered = isFiltered(menuModel, menuContribution, includePopups);
        if ((!filtered) && ((popupAny) || (popupTarget) || (parentID.equals(id))) && 
          (menuContribution.isToBeRendered())) {
          toContribute.add(menuContribution);
        }
      }
    }
  }
  
  public static void gatherMenuContributions(MMenu menuModel, List<MMenuContribution> menuContributionList, String id, ArrayList<MMenuContribution> toContribute, ExpressionContext eContext, boolean includePopups)
  {
    if ((id == null) || (id.length() == 0)) {
      return;
    }
    boolean menuBar = (MUIElement)((EObject)menuModel).eContainer() instanceof MWindow;
    for (MMenuContribution menuContribution : menuContributionList)
    {
      String parentID = menuContribution.getParentId();
      if (parentID != null)
      {
        boolean popup = (parentID.equals("popup")) && ((menuModel instanceof MPopupMenu)) && 
          (includePopups);
        boolean filtered = isFiltered(menuModel, menuContribution, includePopups);
        if ((!filtered) && ((popup) || (parentID.equals(id))) && (menuContribution.isToBeRendered())) {
          if ((menuBar) || (isVisible(menuContribution, eContext))) {
            toContribute.add(menuContribution);
          }
        }
      }
    }
  }
  
  static boolean isFiltered(MMenu menuModel, MMenuContribution menuContribution, boolean includePopups)
  {
    if ((includePopups) || (menuModel.getTags().contains("menuContribution:popup"))) {
      return (!menuContribution.getTags().contains("menuContribution:popup")) && 
        (menuContribution.getTags().contains("menuContribution:menu"));
    }
    if (menuModel.getTags().contains("menuContribution:menu")) {
      return (!menuContribution.getTags().contains("menuContribution:menu")) && 
        (menuContribution.getTags().contains("menuContribution:popup"));
    }
    if (!includePopups) {
      return menuContribution.getTags().contains("menuContribution:popup");
    }
    return false;
  }
  
  public static void collectInfo(ExpressionInfo info, MExpression exp)
  {
    if (!(exp instanceof MCoreExpression)) {
      return;
    }
    MCoreExpression expr = (MCoreExpression)exp;
    Expression ref = null;
    if ((expr.getCoreExpression() instanceof Expression))
    {
      ref = (Expression)expr.getCoreExpression();
    }
    else
    {
      ref = new ReferenceExpression(expr.getCoreExpressionId());
      expr.setCoreExpression(ref);
    }
    ref.collectExpressionInfo(info);
  }
  
  public static boolean isVisible(MMenuContribution menuContribution, ExpressionContext eContext)
  {
    if (menuContribution.getVisibleWhen() == null) {
      return true;
    }
    return isVisible((MCoreExpression)menuContribution.getVisibleWhen(), eContext);
  }
  
  public static boolean isVisible(MToolBarContribution contribution, ExpressionContext eContext)
  {
    if (contribution.getVisibleWhen() == null) {
      return true;
    }
    return isVisible((MCoreExpression)contribution.getVisibleWhen(), eContext);
  }
  
  public static boolean isVisible(MTrimContribution contribution, ExpressionContext eContext)
  {
    if (contribution.getVisibleWhen() == null) {
      return true;
    }
    return isVisible((MCoreExpression)contribution.getVisibleWhen(), eContext);
  }
  
  public static boolean isVisible(MCoreExpression exp, ExpressionContext eContext)
  {
    Expression ref = null;
    if ((exp.getCoreExpression() instanceof Expression))
    {
      ref = (Expression)exp.getCoreExpression();
    }
    else
    {
      ref = new ReferenceExpression(exp.getCoreExpressionId());
      exp.setCoreExpression(ref);
    }
    try
    {
      ExpressionInfo info = ref.computeExpressionInfo();
      String[] names = info.getAccessedPropertyNames();
      String[] arrayOfString1;
      int j = (arrayOfString1 = names).length;
      for (int i = 0; i < j; i++)
      {
        String name = arrayOfString1[i];
        eContext.getVariable(name + ".evaluationServiceLink");
      }
      return ref.evaluate(eContext) != EvaluationResult.FALSE;
    }
    catch (CoreException e)
    {
      trace("isVisible exception", e);
    }
    return false;
  }
  
  public static void addMenuContributions(MMenu menuModel, ArrayList<MMenuContribution> toContribute, ArrayList<MMenuElement> menuContributionsToRemove)
  {
    HashSet<String> existingMenuIds = new HashSet();
    HashSet<String> existingSeparatorNames = new HashSet();
    for (MMenuElement child : menuModel.getChildren())
    {
      String elementId = child.getElementId();
      if (((child instanceof MMenu)) && (elementId != null)) {
        existingMenuIds.add(elementId);
      } else if (((child instanceof MMenuSeparator)) && (elementId != null)) {
        existingSeparatorNames.add(elementId);
      }
    }
    boolean done = toContribute.size() == 0;
    while (!done)
    {
      Object curList = new ArrayList(toContribute);
      int retryCount = toContribute.size();
      toContribute.clear();
      for (MMenuContribution menuContribution : (ArrayList)curList) {
        if (!processAddition(menuModel, menuContributionsToRemove, menuContribution, existingMenuIds, existingSeparatorNames)) {
          toContribute.add(menuContribution);
        }
      }
      done = (toContribute.size() == 0) || (toContribute.size() == retryCount);
    }
  }
  
  public static boolean processAddition(MMenu menuModel, ArrayList<MMenuElement> menuContributionsToRemove, MMenuContribution menuContribution, HashSet<String> existingMenuIds, HashSet<String> existingSeparatorNames)
  {
    int idx = getIndex(menuModel, menuContribution.getPositionInParent());
    if (idx == -1) {
      return false;
    }
    for (MMenuElement item : menuContribution.getChildren()) {
      if ((!(item instanceof MMenu)) || (!existingMenuIds.contains(item.getElementId()))) {
        if ((!(item instanceof MMenuSeparator)) || 
          (!existingSeparatorNames.contains(item.getElementId())))
        {
          MMenuElement copy = (MMenuElement)EcoreUtil.copy((EObject)item);
          if (DEBUG) {
            trace("addMenuContribution " + copy, menuModel.getWidget(), menuModel);
          }
          menuContributionsToRemove.add(copy);
          menuModel.getChildren().add(idx++, copy);
          if (((copy instanceof MMenu)) && (copy.getElementId() != null)) {
            existingMenuIds.add(copy.getElementId());
          } else if (((copy instanceof MMenuSeparator)) && (copy.getElementId() != null)) {
            existingSeparatorNames.add(copy.getElementId());
          }
        }
      }
    }
    return true;
  }
  
  public static boolean processAddition(MToolBar toolBarModel, MToolBarContribution toolBarContribution, List<MToolBarElement> contributions, HashSet<String> existingSeparatorNames)
  {
    int idx = getIndex(toolBarModel, toolBarContribution.getPositionInParent());
    if (idx == -1) {
      return false;
    }
    for (MToolBarElement item : toolBarContribution.getChildren()) {
      if ((!(item instanceof MToolBarSeparator)) || 
        (!existingSeparatorNames.contains(item.getElementId())))
      {
        MToolBarElement copy = (MToolBarElement)EcoreUtil.copy((EObject)item);
        if (DEBUG) {
          trace("addToolBarContribution " + copy, toolBarModel.getWidget(), toolBarModel);
        }
        toolBarModel.getChildren().add(idx++, copy);
        contributions.add(copy);
        if (((copy instanceof MToolBarSeparator)) && (copy.getElementId() != null)) {
          existingSeparatorNames.add(copy.getElementId());
        }
      }
    }
    return true;
  }
  
  public static boolean processAddition(MTrimBar trimBar, MTrimContribution contribution, List<MTrimElement> contributions, HashSet<String> existingToolbarIds)
  {
    int idx = getIndex(trimBar, contribution.getPositionInParent());
    if (idx == -1) {
      return false;
    }
    for (MTrimElement item : contribution.getChildren()) {
      if ((!(item instanceof MToolBar)) || (!existingToolbarIds.contains(item.getElementId())))
      {
        MTrimElement copy = (MTrimElement)EcoreUtil.copy((EObject)item);
        if (DEBUG) {
          trace("addTrimContribution " + copy, trimBar.getWidget(), trimBar);
        }
        trimBar.getChildren().add(idx++, copy);
        contributions.add(copy);
        if (((copy instanceof MToolBar)) && (copy.getElementId() != null)) {
          existingToolbarIds.add(copy.getElementId());
        }
      }
    }
    return true;
  }
  
  private static int getIndex(MElementContainer<?> menuModel, String positionInParent)
  {
    String id = null;
    String modifier = null;
    if ((positionInParent != null) && (positionInParent.length() > 0))
    {
      String[] array = positionInParent.split("=");
      modifier = array[0];
      if (array.length > 1) {
        id = array[1];
      }
    }
    if (id == null) {
      return menuModel.getChildren().size();
    }
    int idx = 0;
    int size = menuModel.getChildren().size();
    while (idx < size)
    {
      if (id.equals(((MUIElement)menuModel.getChildren().get(idx)).getElementId()))
      {
        if ("after".equals(modifier)) {
          idx++;
        }
        return idx;
      }
      idx++;
    }
    return id.equals("additions") ? menuModel.getChildren().size() : -1;
  }
  
  public static MCommand getCommandById(MApplication app, String cmdId)
  {
    List<MCommand> cmds = app.getCommands();
    for (MCommand cmd : cmds) {
      if (cmdId.equals(cmd.getElementId())) {
        return cmd;
      }
    }
    return null;
  }
  
  static class Key
  {
    private int tag = -1;
    private int hc = -1;
    private String parentId;
    private String position;
    private MCoreExpression vexp;
    private Object factory;
    
    public Key(String parentId, String position, List<String> tags, MCoreExpression vexp, Object factory)
    {
      this.parentId = parentId;
      this.position = position;
      this.vexp = vexp;
      this.factory = factory;
      if (tags.contains("scheme:menu")) {
        tag = 1;
      } else if (tags.contains("scheme:popup")) {
        tag = 2;
      } else if (tags.contains("scheme:toolbar")) {
        tag = 3;
      } else {
        tag = 0;
      }
    }
    
    int getSchemeTag()
    {
      return tag;
    }
    
    public boolean equals(Object obj)
    {
      if (!(obj instanceof Key)) {
        return false;
      }
      Key other = (Key)obj;
      Object exp1 = vexp == null ? null : vexp.getCoreExpression();
      Object exp2 = vexp == null ? null : vexp.getCoreExpression();
      return (Util.equals(parentId, parentId)) && (Util.equals(position, position)) && 
        (getSchemeTag() == other.getSchemeTag()) && (Util.equals(exp1, exp2)) && 
        (Util.equals(factory, factory));
    }
    
    public int hashCode()
    {
      if (hc == -1)
      {
        Object exp1 = vexp == null ? null : vexp.getCoreExpression();
        hc = Util.hashCode(parentId);
        hc = (hc * 87 + Util.hashCode(position));
        hc = (hc * 87 + getSchemeTag());
        hc = (hc * 87 + Util.hashCode(exp1));
        hc = (hc * 87 + Util.hashCode(factory));
      }
      return hc;
    }
    
    public String toString()
    {
      return 
        getClass().getName() + " " + parentId + "--" + position + "--" + getSchemeTag() + "--" + vexp;
    }
  }
  
  static class MenuKey
    extends ContributionsAnalyzer.Key
  {
    static final String FACTORY = "ContributionFactory";
    private MMenuContribution contribution;
    
    public MenuKey(MMenuContribution mc)
    {
      super(mc.getPositionInParent(), mc.getTags(), (MCoreExpression)mc.getVisibleWhen(), mc.getTransientData().get("ContributionFactory"));
      contribution = mc;
      mc.setWidget(this);
    }
    
    public MMenuContribution getContribution()
    {
      return contribution;
    }
  }
  
  static class ToolBarKey
    extends ContributionsAnalyzer.Key
  {
    static final String FACTORY = "ToolBarContributionFactory";
    private MToolBarContribution contribution;
    
    public ToolBarKey(MToolBarContribution mc)
    {
      super(mc.getPositionInParent(), mc.getTags(), (MCoreExpression)mc.getVisibleWhen(), mc.getTransientData().get("ToolBarContributionFactory"));
      contribution = mc;
      mc.setWidget(this);
    }
    
    public MToolBarContribution getContribution()
    {
      return contribution;
    }
  }
  
  static class TrimKey
    extends ContributionsAnalyzer.Key
  {
    private MTrimContribution contribution;
    
    public TrimKey(MTrimContribution mc)
    {
      super(mc.getPositionInParent(), mc.getTags(), (MCoreExpression)mc.getVisibleWhen(), null);
      contribution = mc;
      mc.setWidget(this);
    }
    
    public MTrimContribution getContribution()
    {
      return contribution;
    }
  }
  
  private static MenuKey getKey(MMenuContribution contribution)
  {
    if ((contribution.getWidget() instanceof MenuKey)) {
      return (MenuKey)contribution.getWidget();
    }
    return new MenuKey(contribution);
  }
  
  private static ToolBarKey getKey(MToolBarContribution contribution)
  {
    if ((contribution.getWidget() instanceof ToolBarKey)) {
      return (ToolBarKey)con
1 2 3 4 5 6 7 8 9 10 11 12

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd