org.eclipse.e4.ui.workbench.swt_0.10.3.v20130124-133900

16:43:03.564 INFO  jd.cli.Main - Decompiling org.eclipse.e4.ui.workbench.swt_0.10.3.v20130124-133900.jar
package org.eclipse.e4.ui.internal.workbench.swt;

import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.model.application.ui.MContext;
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
import org.eclipse.e4.ui.model.application.ui.MUILabel;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.eclipse.e4.ui.workbench.modeling.EPartService;

public abstract class AbstractPartRenderer
{
  public static final String OWNING_ME = "modelElement";
  protected IEclipseContext context;
  protected EModelService modelService;
  
  public void init(IEclipseContext context)
  {
    this.context = context;
    modelService = ((EModelService)context.get(EModelService.class
      .getName()));
  }
  
  public abstract Object createWidget(MUIElement paramMUIElement, Object paramObject);
  
  public abstract void processContents(MElementContainer<MUIElement> paramMElementContainer);
  
  public void postProcess(MUIElement childElement) {}
  
  public abstract void bindWidget(MUIElement paramMUIElement, Object paramObject);
  
  protected abstract Object getParentWidget(MUIElement paramMUIElement);
  
  public abstract void disposeWidget(MUIElement paramMUIElement);
  
  public abstract void hookControllerLogic(MUIElement paramMUIElement);
  
  public abstract void childRendered(MElementContainer<MUIElement> paramMElementContainer, MUIElement paramMUIElement);
  
  public void hideChild(MElementContainer<MUIElement> parentElement, MUIElement child) {}
  
  protected abstract Object getImage(MUILabel paramMUILabel);
  
  protected IEclipseContext getContextForParent(MUIElement element)
  {
    return modelService.getContainingContext(element);
  }
  
  protected IEclipseContext getContext(MUIElement part)
  {
    if ((part instanceof MContext)) {
      return ((MContext)part).getContext();
    }
    return getContextForParent(part);
  }
  
  public void activate(MPart element)
  {
    IEclipseContext curContext = getContext(element);
    if (curContext != null)
    {
      EPartService ps = (EPartService)curContext.get(EPartService.class
        .getName());
      if (ps != null) {
        ps.activate(element, requiresFocus(element));
      }
    }
  }
  
  protected abstract boolean requiresFocus(MPart paramMPart);
  
  public void removeGui(MUIElement element, Object widget) {}
  
  public Object getUIContainer(MUIElement element)
  {
    if (element.getParent() != null) {
      return element.getParent().getWidget();
    }
    return null;
  }
}

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

class AnimationEngine$1
  implements Runnable
{
  AnimationEngine$1(AnimationEngine paramAnimationEngine) {}
  
  public void run()
  {
    if (AnimationEngine.access$0(this$0)) {
      return;
    }
    AnimationEngine.access$2(this$0, AnimationEngine.access$1(this$0));
    AnimationEngine.access$3(this$0, System.currentTimeMillis());
    if (this$0.isUpdateStep())
    {
      this$0.updateDisplay(); AnimationEngine 
        tmp56_53 = this$0;AnimationEngine.access$5(tmp56_53, AnimationEngine.access$4(tmp56_53) + 1L);
    }
  }
}

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

import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;

class AnimationEngine$2
  implements DisposeListener
{
  AnimationEngine$2(AnimationEngine paramAnimationEngine) {}
  
  public void widgetDisposed(DisposeEvent e)
  {
    this$0.cancelAnimation();
  }
}

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

class AnimationEngine$3
  implements Runnable
{
  AnimationEngine$3(AnimationEngine paramAnimationEngine) {}
  
  public void run()
  {
    if (!AnimationEngine.access$0(this$0)) {
      AnimationEngine.access$7(this$0, 
        !AnimationEngine.access$6(this$0).jobInit(this$0));
    }
  }
}

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

class AnimationEngine$4
  implements Runnable
{
  AnimationEngine$4(AnimationEngine paramAnimationEngine) {}
  
  public void run()
  {
    AnimationEngine.access$6(this$0).dispose();
  }
}

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

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class AnimationEngine
  extends Job
{
  public static final int TICK_TIMER = 1;
  public static final int FRAME_COUNT = 2;
  public static final int unlimitedDuration = -1;
  private boolean enableAnimations;
  private long startTime;
  private long curTime;
  private long prevTime;
  private int timingStyle = 1;
  private long frameCount;
  private boolean animationCanceled = false;
  private long sleepAmount;
  private Display display;
  private AnimationFeedbackBase feedbackRenderer;
  private int duration;
  
  public AnimationEngine(IEclipseContext context, AnimationFeedbackBase animationFeedback, int durationIn)
  {
    this(context, animationFeedback, durationIn, 0L);
  }
  
  public AnimationEngine(IEclipseContext context, AnimationFeedbackBase animationFeedback, int durationIn, long sleepAmountIn)
  {
    super("E4 Animation");
    sleepAmount = sleepAmountIn;
    feedbackRenderer = animationFeedback;
    duration = durationIn;
    
    enableAnimations = false;
    if (context.get("Animations Enabled") != null) {
      enableAnimations = 
        ((Boolean)context.get("Animations Enabled")).booleanValue();
    }
    if (!enableAnimations) {
      return;
    }
    animationCanceled = false;
    
    display = feedbackRenderer.getAnimationShell().getDisplay();
    
    animationFeedback.getAnimationShell().addDisposeListener(
      new DisposeListener()
      {
        public void widgetDisposed(DisposeEvent e)
        {
          cancelAnimation();
        }
      });
    setSystem(true);
    
    feedbackRenderer.initialize(this);
    
    curTime = (startTime = System.currentTimeMillis());
  }
  
  public AnimationFeedbackBase getFeedback()
  {
    return feedbackRenderer;
  }
  
  private Runnable animationStep = new Runnable()
  {
    public void run()
    {
      if (animationCanceled) {
        return;
      }
      prevTime = curTime;
      curTime = System.currentTimeMillis();
      if (isUpdateStep())
      {
        updateDisplay();
        frameCount += 1L;
      }
    }
  };
  
  protected void updateDisplay()
  {
    if (animationCanceled) {
      return;
    }
    feedbackRenderer.renderStep(this);
  }
  
  protected boolean isUpdateStep()
  {
    if ((duration == -1) || (timingStyle == 2)) {
      return true;
    }
    return prevTime != curTime;
  }
  
  private boolean done()
  {
    return (animationCanceled) || (amount() >= 1.0D);
  }
  
  public double amount()
  {
    if (duration == -1) {
      return 0.0D;
    }
    double amount = 0.0D;
    switch (timingStyle)
    {
    case 1: 
      amount = (curTime - startTime) / duration;
      break;
    case 2: 
      amount = frameCount / duration;
    }
    if (amount > 1.0D) {
      amount = 1.0D;
    }
    return amount;
  }
  
  protected IStatus run(IProgressMonitor monitor)
  {
    if (!enableAnimations) {
      return Status.OK_STATUS;
    }
    display.syncExec(new Runnable()
    {
      public void run()
      {
        if (!animationCanceled) {
          animationCanceled = 
            (!feedbackRenderer.jobInit(AnimationEngine.this));
        }
      }
    });
    if (animationCanceled) {
      return Status.CANCEL_STATUS;
    }
    curTime = (startTime = System.currentTimeMillis());
    while ((!done()) && (!animationCanceled))
    {
      display.syncExec(animationStep);
      try
      {
        Thread.sleep(sleepAmount);
      }
      catch (InterruptedException localInterruptedException) {}
    }
    if (animationCanceled) {
      return Status.CANCEL_STATUS;
    }
    display.syncExec(new Runnable()
    {
      public void run()
      {
        feedbackRenderer.dispose();
      }
    });
    return Status.OK_STATUS;
  }
  
  public void cancelAnimation()
  {
    animationCanceled = true;
    feedbackRenderer.dispose();
    cancel();
  }
  
  public long getFrameCount()
  {
    return frameCount;
  }
}

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

import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;

class AnimationFeedbackBase$1
  implements DisposeListener
{
  AnimationFeedbackBase$1(AnimationFeedbackBase paramAnimationFeedbackBase) {}
  
  public void widgetDisposed(DisposeEvent e)
  {
    if (AnimationFeedbackBase.access$0(this$0) != null) {
      AnimationFeedbackBase.access$0(this$0).cancelAnimation();
    }
  }
}

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

import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;

class AnimationFeedbackBase$2
  implements DisposeListener
{
  AnimationFeedbackBase$2(AnimationFeedbackBase paramAnimationFeedbackBase) {}
  
  public void widgetDisposed(DisposeEvent e)
  {
    if (AnimationFeedbackBase.access$0(this$0) != null) {
      AnimationFeedbackBase.access$0(this$0).cancelAnimation();
    }
  }
}

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

import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Shell;

public abstract class AnimationFeedbackBase
{
  private AnimationEngine engine;
  private Shell baseShell;
  private Shell animationShell = null;
  
  public AnimationFeedbackBase(Shell parentShell)
  {
    baseShell = parentShell;
    
    baseShell.addDisposeListener(new DisposeListener()
    {
      public void widgetDisposed(DisposeEvent e)
      {
        if (engine != null) {
          engine.cancelAnimation();
        }
      }
    });
  }
  
  public abstract void initialize(AnimationEngine paramAnimationEngine);
  
  public abstract void renderStep(AnimationEngine paramAnimationEngine);
  
  public boolean jobInit(AnimationEngine engine)
  {
    this.engine = engine;
    return engine != null;
  }
  
  public void dispose()
  {
    if ((animationShell != null) && (!animationShell.isDisposed())) {
      animationShell.dispose();
    }
  }
  
  public Shell getBaseShell()
  {
    return baseShell;
  }
  
  public Shell getAnimationShell()
  {
    if (animationShell == null)
    {
      animationShell = new Shell(getBaseShell(), 16392);
      
      animationShell.addDisposeListener(new DisposeListener()
      {
        public void widgetDisposed(DisposeEvent e)
        {
          if (engine != null) {
            engine.cancelAnimation();
          }
        }
      });
    }
    return animationShell;
  }
}

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

import java.util.HashMap;
import java.util.Map;
import org.eclipse.e4.ui.css.core.engine.CSSEngine;
import org.eclipse.e4.ui.css.swt.dom.ControlElement;
import org.eclipse.e4.ui.css.swt.dom.WidgetElement;
import org.eclipse.e4.ui.widgets.ImageBasedFrame;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.Transform;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.w3c.dom.css.CSSPrimitiveValue;
import org.w3c.dom.css.CSSStyleDeclaration;
import org.w3c.dom.css.CSSValue;
import org.w3c.dom.css.CSSValueList;
import org.w3c.dom.css.ViewCSS;

public class CSSRenderingUtils
{
  private Map<Image, Image> rotatedImageMap = new HashMap();
  
  public Control frameMeIfPossible(Control toFrame, String classId, boolean vertical, boolean draggable)
  {
    Integer[] frameInts = new Integer[4];
    Image frameImage = createImage(toFrame, classId, "frame-image", 
      frameInts);
    if ((vertical) && (frameImage != null)) {
      frameImage = rotateImage(toFrame.getDisplay(), frameImage, 
        frameInts);
    }
    Image handleImage = createImage(toFrame, classId, "handle-image", null);
    if ((vertical) && (handleImage != null)) {
      handleImage = rotateImage(toFrame.getDisplay(), handleImage, null);
    }
    if (frameImage != null)
    {
      ImageBasedFrame frame = new ImageBasedFrame(toFrame.getParent(), 
        toFrame, vertical, draggable);
      frame.setImages(frameImage, frameInts, handleImage);
      return frame;
    }
    if (handleImage != null)
    {
      ImageBasedFrame frame = new ImageBasedFrame(toFrame.getParent(), 
        toFrame, vertical, draggable);
      frame.setImages(null, null, handleImage);
      return frame;
    }
    return toFrame;
  }
  
  private Image rotateImage(Display display, Image image, Integer[] frameInts)
  {
    if (frameInts != null)
    {
      int tmp = frameInts[0].intValue();
      frameInts[0] = frameInts[2];
      frameInts[2] = Integer.valueOf(tmp);
      tmp = frameInts[1].intValue();
      frameInts[1] = frameInts[3];
      frameInts[3] = Integer.valueOf(tmp);
    }
    if (rotatedImageMap.get(image) != null) {
      return (Image)rotatedImageMap.get(image);
    }
    Rectangle bounds = image.getBounds();
    ImageData imageData = new ImageData(height, width, 32, 
      new PaletteData(16711680, 65280, 255));
    Image rotatedImage = new Image(display, imageData);
    GC gc = new GC(rotatedImage);
    RGB rgb = new RGB(125, 0, 0);
    Color offRed = new Color(display, rgb);
    gc.setBackground(offRed);
    gc.fillRectangle(0, 0, height, width);
    Transform t = new Transform(display);
    int w = getBoundsheight;
    int offset = 0;
    t.translate(w - offset, 0.0F);
    t.rotate(90.0F);
    gc.setTransform(t);
    gc.drawImage(image, 0, 0);
    gc.dispose();
    t.dispose();
    offRed.dispose();
    ImageData alphaData = rotatedImage.getImageData();
    rotatedImage.dispose();
    int transparentPix = palette.getPixel(rgb);
    for (int i = 0; i < width; i++) {
      for (int j = 0; j < height; j++) {
        if (alphaData.getPixel(i, j) != transparentPix) {
          alphaData.setAlpha(i, j, 255);
        }
      }
    }
    rotatedImage = new Image(display, alphaData);
    
    rotatedImageMap.put(image, rotatedImage);
    
    return rotatedImage;
  }
  
  public CSSValue getCSSValue(Control styleControl, String className, String attributeName)
  {
    CSSEngine csseng = WidgetElement.getEngine(styleControl);
    if (csseng == null) {
      return null;
    }
    ControlElement tempEment = (ControlElement)csseng
      .getElement(styleControl);
    if (tempEment == null) {
      return null;
    }
    if (className != null) {
      WidgetElement.setCSSClass(styleControl, className);
    }
    CSSStyleDeclaration styleDeclarations = csseng.getViewCSS()
      .getComputedStyle(tempEment, "");
    if (styleDeclarations == null) {
      return null;
    }
    return styleDeclarations.getPropertyCSSValue(attributeName);
  }
  
  public Image createImage(Control styleControl, String classId, String attName, Integer[] frameInts)
  {
    Image image = null;
    
    CSSEngine csseng = WidgetElement.getEngine(styleControl);
    if (csseng == null) {
      return null;
    }
    ControlElement tempEment = (ControlElement)csseng
      .getElement(styleControl);
    if (tempEment == null) {
      return null;
    }
    if (classId != null) {
      ControlElement.setCSSClass(styleControl, classId);
    }
    CSSStyleDeclaration styleDeclarations = csseng.getViewCSS()
      .getComputedStyle(tempEment, "");
    if (styleDeclarations == null) {
      return null;
    }
    CSSValue imagePath = styleDeclarations.getPropertyCSSValue(attName);
    if (imagePath == null) {
      return null;
    }
    if ((imagePath != null) && 
      (imagePath.getCssValueType() == 1)) {
      try
      {
        image = (Image)csseng.convert(imagePath, Image.class, 
          styleControl.getDisplay());
        if ((image != null) && (frameInts != null))
        {
          CSSValue value = styleDeclarations
            .getPropertyCSSValue("frame-cuts");
          if (value.getCssValueType() == 2)
          {
            CSSValueList valueList = (CSSValueList)value;
            if (valueList.getLength() != 4) {
              return null;
            }
            for (int i = 0; i < valueList.getLength(); i++)
            {
              CSSValue val = valueList.item(i);
              if ((val.getCssValueType() == 1) && 
                (((CSSPrimitiveValue)val)
                .getPrimitiveType() == 5)) {
                frameInts[i] = 
                  Integer.valueOf((int)((CSSPrimitiveValue)val).getFloatValue(5));
              } else {
                return null;
              }
            }
          }
        }
      }
      catch (Exception localException) {}
    }
    return image;
  }
}

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

import org.eclipse.e4.ui.di.UISynchronize;
import org.eclipse.swt.widgets.Display;

class E4Application$1
  extends UISynchronize
{
  E4Application$1(E4Application paramE4Application, Display paramDisplay) {}
  
  public void syncExec(Runnable runnable)
  {
    val$display.syncExec(runnable);
  }
  
  public void asyncExec(Runnable runnable)
  {
    val$display.asyncExec(runnable);
  }
}

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

import org.eclipse.e4.ui.services.IStylingEngine;
import org.w3c.dom.css.CSSStyleDeclaration;

class E4Application$2
  implements IStylingEngine
{
  public void setClassname(Object widget, String classname) {}
  
  public void setId(Object widget, String id) {}
  
  public void style(Object widget) {}
  
  public CSSStyleDeclaration getStyle(Object widget)
  {
    return null;
  }
  
  public void setClassnameAndId(Object widget, String classname, String id) {}
}

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

import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;

class E4Application$3
  extends AdapterImpl
{
  public void notifyChanged(Notification notification)
  {
    if (notification.getFeatureID(MApplication.class) != 15) {
      return;
    }
    if (notification.getEventType() != 3) {
      return;
    }
    MWindow childWindow = (MWindow)notification.getNewValue();
    E4Application.initializeWindowServices(childWindow);
  }
}

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

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

class E4Application$4
  extends RunAndTrack
{
  E4Application$4(IEclipseContext paramIEclipseContext) {}
  
  public boolean changed(IEclipseContext context)
  {
    IEclipseContext activeChildContext = context.getActiveChild();
    if (activeChildContext != null)
    {
      Object selection = activeChildContext
        .get("org.eclipse.ui.selection");
      val$theContext.set("org.eclipse.ui.selection", 
        selection);
    }
    return true;
  }
}

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

import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IContextFunction;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.internal.workbench.SelectionServiceImpl;

class E4Application$5
  implements IContextFunction
{
  public Object compute(IEclipseContext context)
  {
    return ContextInjectionFactory.make(
      SelectionServiceImpl.class, context);
  }
}

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

import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;

class E4Application$6
  extends AdapterImpl
{
  public void notifyChanged(Notification notification)
  {
    if (notification.getFeatureID(MWindow.class) != 20) {
      return;
    }
    IEclipseContext windowContext = (IEclipseContext)notification
      .getNewValue();
    E4Application.access$0(windowContext);
  }
}

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

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.net.URL;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IProduct;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.RegistryFactory;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.EclipseContextFactory;
import org.eclipse.e4.core.contexts.IContextFunction;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.contexts.RunAndTrack;
import org.eclipse.e4.core.internal.services.EclipseAdapter;
import org.eclipse.e4.core.services.adapter.Adapter;
import org.eclipse.e4.core.services.contributions.IContributionFactory;
import org.eclipse.e4.core.services.log.ILoggerProvider;
import org.eclipse.e4.core.services.log.Logger;
import org.eclipse.e4.core.services.translation.TranslationProviderFactory;
import org.eclipse.e4.core.services.translation.TranslationService;
import org.eclipse.e4.ui.di.UISynchronize;
import org.eclipse.e4.ui.internal.workbench.ActiveChildLookupFunction;
import org.eclipse.e4.ui.internal.workbench.ActivePartLookupFunction;
import org.eclipse.e4.ui.internal.workbench.DefaultLoggerProvider;
import org.eclipse.e4.ui.internal.workbench.E4Workbench;
import org.eclipse.e4.ui.internal.workbench.ExceptionHandler;
import org.eclipse.e4.ui.internal.workbench.ModelServiceImpl;
import org.eclipse.e4.ui.internal.workbench.PlaceholderResolver;
import org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory;
import org.eclipse.e4.ui.internal.workbench.ResourceHandler;
import org.eclipse.e4.ui.internal.workbench.SelectionAggregator;
import org.eclipse.e4.ui.internal.workbench.SelectionServiceImpl;
import org.eclipse.e4.ui.internal.workbench.WorkbenchLogger;
import org.eclipse.e4.ui.model.application.MAddon;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.services.IStylingEngine;
import org.eclipse.e4.ui.workbench.IExceptionHandler;
import org.eclipse.e4.ui.workbench.IModelResourceHandler;
import org.eclipse.e4.ui.workbench.lifecycle.PostContextCreate;
import org.eclipse.e4.ui.workbench.lifecycle.PreSave;
import org.eclipse.e4.ui.workbench.lifecycle.ProcessAdditions;
import org.eclipse.e4.ui.workbench.lifecycle.ProcessRemovals;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.eclipse.e4.ui.workbench.modeling.EPlaceholderResolver;
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
import org.eclipse.e4.ui.workbench.swt.internal.copy.WorkbenchSWTMessages;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.osgi.service.datalocation.Location;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.osgi.framework.Bundle;
import org.w3c.dom.css.CSSStyleDeclaration;

public class E4Application
  implements IApplication
{
  private static final String PLUGIN_ID = "org.eclipse.e4.ui.workbench.swt";
  public static final String METADATA_FOLDER = ".metadata";
  private static final String VERSION_FILENAME = "version.ini";
  private static final String WORKSPACE_VERSION_KEY = "org.eclipse.core.runtime";
  private static final String WORKSPACE_VERSION_VALUE = "2";
  private static final String APPLICATION_MODEL_PATH_DEFAULT = "Application.e4xmi";
  private String[] args;
  private IModelResourceHandler handler;
  private Display display = null;
  private E4Workbench workbench = null;
  public static final String THEME_ID = "cssTheme";
  private Object lcManager;
  private static final String CONTEXT_INITIALIZED = "org.eclipse.ui.contextInitialized";
  
  public Display getApplicationDisplay()
  {
    if (display == null) {
      display = Display.getDefault();
    }
    return display;
  }
  
  public Object start(IApplicationContext applicationContext)
    throws Exception
  {
    IProduct product = Platform.getProduct();
    if ((product != null) && (product.getName() != null)) {
      Display.setAppName(product.getName());
    }
    Display display = getApplicationDisplay();
    E4Workbench workbench = createE4Workbench(applicationContext, display);
    
    Location instanceLocation = (Location)workbench.getContext().get(
      "instanceLocation");
    Shell shell = display.getActiveShell();
    if (shell == null)
    {
      shell = new Shell();
      
      shell.setLocation(0, 10000);
    }
    try
    {
      Integer localInteger;
      if (!checkInstanceLocation(instanceLocation, shell)) {
        return EXIT_OK;
      }
      IEclipseContext workbenchContext = workbench.getContext();
      workbenchContext.set(Display.class, display);
      
      workbench.createAndRunUI(workbench.getApplication());
      if (lcManager != null) {
        ContextInjectionFactory.invoke(lcManager, PreSave.class, 
          workbenchContext, null);
      }
      saveModel();
      workbench.close();
      return EXIT_OK;
    }
    finally
    {
      if (display != null) {
        display.dispose();
      }
      if (instanceLocation != null) {
        instanceLocation.release();
      }
    }
  }
  
  public void saveModel()
  {
    try
    {
      handler.save();
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }
  }
  
  public E4Workbench createE4Workbench(IApplicationContext applicationContext, final Display display)
  {
    args = ((String[])applicationContext.getArguments().get(
      "application.args"));
    
    IEclipseContext appContext = createDefaultContext();
    appContext.set(Realm.class, SWTObservables.getRealm(display));
    appContext.set(UISynchronize.class, new UISynchronize()
    {
      public void syncExec(Runnable runnable)
      {
        display.syncExec(runnable);
      }
      
      public void asyncExec(Runnable runnable)
      {
        display.asyncExec(runnable);
      }
    });
    appContext.set(IApplicationContext.class, applicationContext);
    if (!appContext.containsKey("org.eclipse.e4.ui.workbench.modeling.EPartService")) {
      throw new IllegalStateException(
        "Core services not available. Please make sure that a declarative service implementation (such as the bundle 'org.eclipse.equinox.ds') is available!");
    }
    IContributionFactory factory = (IContributionFactory)appContext
      .get(IContributionFactory.class.getName());
    
    String lifeCycleURI = getArgValue("lifeCycleURI", 
      applicationContext, false);
    if (lifeCycleURI != null)
    {
      lcManager = factory.create(lifeCycleURI, appContext);
      if (lcManager != null) {
        ContextInjectionFactory.invoke(lcManager, 
          PostContextCreate.class, appContext, null);
      }
    }
    MApplication appModel = loadApplicationModel(applicationContext, 
      appContext);
    appModel.setContext(appContext);
    
    boolean isRtl = (Window.getDefaultOrientation() & 0x4000000) != 0;
    appModel.getTransientData().put("dir", Boolean.valueOf(isRtl));
    if (!E4Workbench.getServiceContext().containsKey(MApplication.class.getName())) {
      E4Workbench.getServiceContext().set(MApplication.class.getName(), 
        appModel);
    }
    appContext.set(MApplication.class.getName(), appModel);
    
    ContextInjectionFactory.setDefault(appContext);
    
    initializeServices(appModel);
    if (lcManager != null)
    {
      ContextInjectionFactory.invoke(lcManager, ProcessAdditions.class, 
        appContext, null);
      ContextInjectionFactory.invoke(lcManager, ProcessRemovals.class, 
        appContext, null);
    }
    IEclipseContext addonStaticContext = EclipseContextFactory.create();
    for (MAddon addon : appModel.getAddons())
    {
      addonStaticContext.set(MAddon.class, addon);
      Object obj = factory.create(addon.getContributionURI(), appContext, 
        addonStaticContext);
      addon.setObject(obj);
    }
    String xmiURI = getArgValue("applicationXMI", 
      applicationContext, false);
    appContext.set("applicationXMI", xmiURI);
    
    String themeId = getArgValue("cssTheme", 
      applicationContext, false);
    appContext.set("cssTheme", themeId);
    
    String cssURI = getArgValue("applicationCSS", 
      applicationContext, false);
    if (cssURI != null) {
      appContext.set("applicationCSS", cssURI);
    }
    if ((cssURI != null) && (!cssURI.startsWith("platform:")))
    {
      System.err.println("Warning " + 
        cssURI + 
        " changed its meaning it is used now to run without theme support");
      appContext.set("cssTheme", cssURI);
    }
    String cssResourcesURI = getArgValue("applicationCSSResources", 
      applicationContext, false);
    appContext.set("applicationCSSResources", cssResourcesURI);
    appContext.set(
      "rendererFactoryUri", 
      getArgValue("rendererFactoryUri", 
      applicationContext, false));
    
    String presentationURI = getArgValue("presentationURI", 
      applicationContext, false);
    if (presentationURI == null) {
      presentationURI = "bundleclass://org.eclipse.e4.ui.workbench.swt/org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine";
    }
    appContext.set("presentationURI", presentationURI);
    
    return workbench = new E4Workbench(appModel, appContext);
  }
  
  private MApplication loadApplicationModel(IApplicationContext appContext, IEclipseContext eclipseContext)
  {
    MApplication theApp = null;
    
    Location instanceLocation = WorkbenchSWTActivator.getDefault()
      .getInstanceLocation();
    
    String appModelPath = getArgValue("applicationXMI", appContext, 
      false);
    if ((appModelPath == null) || (appModelPath.length() == 0))
    {
      Bundle brandingBundle = appContext.getBrandingBundle();
      if (brandingBundle != null) {
        appModelPath = 
          brandingBundle.getSymbolicName() + "/" + "Application.e4xmi";
      }
    }
    Assert.isNotNull(appModelPath, "applicationXMI argument missing");
    
    URI initialWorkbenchDefinitionInstance = 
      URI.createPlatformPluginURI(appModelPath, true);
    
    eclipseContext.set("initialWorkbenchModelURI", 
      initialWorkbenchDefinitionInstance);
    eclipseContext.set("instanceLocation", instanceLocation);
    
    String value = getArgValue("persistState", appContext, false);
    
    boolean saveAndRestore = (value == null) || (Boolean.parseBoolean(value));
    
    eclipseContext.set("persistState", 
      Boolean.valueOf(saveAndRestore));
    
    value = getArgValue("clearPersistedState", appContext, true);
    boolean clearPersistedState = (value != null) && (Boolean.parseBoolean(value));
    eclipseContext.set("clearPersistedState", 
      Boolean.valueOf(clearPersistedState));
    
    value = getArgValue("deltaRestore", appContext, false);
    boolean deltaRestore = (value == null) || (Boolean.parseBoolean(value));
    eclipseContext.set("deltaRestore", 
      Boolean.valueOf(deltaRestore));
    
    String resourceHandler = getArgValue(
      "modelResourceHandler", appContext, false);
    if (resourceHandler == null) {
      resourceHandler = 
        "bundleclass://org.eclipse.e4.ui.workbench/" + ResourceHandler.class.getName();
    }
    IContributionFactory factory = 
      (IContributionFactory)eclipseContext.get(IContributionFactory.class);
    
    handler = ((IModelResourceHandler)factory.create(resourceHandler, 
      eclipseContext));
    
    Resource resource = handler.loadMostRecentModel();
    theApp = (MApplication)resource.getContents().get(0);
    
    return theApp;
  }
  
  private String getArgValue(String argName, IApplicationContext appContext, boolean singledCmdArgValue)
  {
    if ((argName == null) || (argName.length() == 0)) {
      return null;
    }
    if (singledCmdArgValue) {
      for (int i = 0; i < args.length; i++) {
        if (("-" + argName).equals(args[i])) {
          return "true";
        }
      }
    } else {
      for (int i = 0; i < args.length; i++) {
        if ((("-" + argName).equals(args[i])) && (i + 1 < args.length)) {
          return args[(i + 1)];
        }
      }
    }
    String brandingProperty = appContext.getBrandingProperty(argName);
    return brandingProperty == null ? System.getProperty(argName) : 
      brandingProperty;
  }
  
  public void stop()
  {
    if (workbench != null) {
      workbench.close();
    }
  }
  
  public static IEclipseContext createDefaultHeadlessContext()
  {
    IEclipseContext serviceContext = E4Workbench.getServiceContext();
    
    IExtensionRegistry registry = RegistryFactory.getRegistry();
    ExceptionHandler exceptionHandler = new ExceptionHandler();
    ReflectionContributionFactory contributionFactory = new ReflectionContributionFactory(
      registry);
    serviceContext.set(IContributionFactory.class, contributionFactory);
    serviceContext.set(IExceptionHandler.class, exceptionHandler);
    serviceContext.set(IExtensionRegistry.class, registry);
    
    String locale = Locale.getDefault().toString();
    serviceContext.set("org.eclipse.e4.core.locale", locale);
    TranslationService bundleTranslationProvider = 
      TranslationProviderFactory.bundleTranslationService(serviceContext);
    serviceContext.set(TranslationService.class, bundleTranslationProvider);
    
    serviceContext.set(Adapter.class, (Adapter)ContextInjectionFactory.make(
      EclipseAdapter.class, serviceContext));
    if (serviceContext.get(ILoggerProvider.class) == null) {
      serviceContext.set(ILoggerProvider.class, 
        (ILoggerProvider)ContextInjectionFactory.make(DefaultLoggerProvider.class, serviceContext));
    }
    return serviceContext;
  }
  
  public static IEclipseContext createDefaultContext()
  {
    IEclipseContext serviceContext = createDefaultHeadlessContext();
    IEclipseContext appContext = serviceContext
      .createChild("WorkbenchContext");
    
    appContext
      .set(Logger.class, (Logger)ContextInjectionFactory.make(
      WorkbenchLogger.class, appContext));
    
    appContext.set(EModelService.class, new ModelServiceImpl(appContext));
    
    appContext.set(EPlaceholderResolver.class, new PlaceholderResolver());
    
    appContext.set("e4ActivePart", 
      new ActivePartLookupFunction());
    
    appContext.set("activeShell", 
      new ActiveChildLookupFunction("activeShell", 
      "localActiveShell"));
    
    appContext.set(IStylingEngine.class, new IStylingEngine()
    {
      public void setClassname(Object widget, String classname) {}
      
      public void setId(Object widget, String id) {}
      
      public void style(Object widget) {}
      
      public CSSStyleDeclaration getStyle(Object widget)
      {
        return null;
      }
      
      public void setClassnameAndId(Object widget, String classname, String id) {}
    });
    return appContext;
  }
  
  private boolean checkInstanceLocation(Location instanceLocation, Shell shell)
  {
    if (instanceLocation == null)
    {
      MessageDialog.openError(
        shell, 
        WorkbenchSWTMessages.IDEApplication_workspaceMandatoryTitle, 
        WorkbenchSWTMessages.IDEApplication_workspaceMandatoryMessage);
      return false;
    }
    if (instanceLocation.isSet())
    {
      if (!checkValidWorkspace(shell, instanceLocation.getURL())) {
        return false;
      }
      try
      {
        if (instanceLocation.lock())
        {
          writeWorkspaceVersion();
          return true;
        }
        File workspaceDirectory = new File(instanceLocation.getURL()
          .getFile());
        if (workspaceDirectory.exists()) {
          MessageDialog.openError(
            shell, 
            WorkbenchSWTMessages.IDEApplication_workspaceCannotLockTitle, 
            WorkbenchSWTMessages.IDEApplication_workspaceCannotLockMessage);
        } else {
          MessageDialog.openError(
            shell, 
            WorkbenchSWTMessages.IDEApplication_workspaceCannotBeSetTitle, 
            WorkbenchSWTMessages.IDEApplication_workspaceCannotBeSetMessage);
        }
      }
      catch (IOException e)
      {
        Logger logger = new WorkbenchLogge
1 2 3 4 5 6 7 8

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