org.eclipse.jface_3.7.0.v20110928-1505

16:45:31.595 INFO  jd.cli.Main - Decompiling org.eclipse.jface_3.7.0.v20110928-1505.jar
package org.eclipse.jface.action;

import org.eclipse.core.commands.common.EventManager;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;

public abstract class AbstractAction
  extends EventManager
  implements IAction
{
  public void addPropertyChangeListener(IPropertyChangeListener listener)
  {
    addListenerObject(listener);
  }
  
  protected final void firePropertyChange(PropertyChangeEvent event)
  {
    Object[] list = getListeners();
    for (int i = 0; i < list.length; i++) {
      ((IPropertyChangeListener)list[i]).propertyChange(event);
    }
  }
  
  protected final void firePropertyChange(String propertyName, Object oldValue, Object newValue)
  {
    if (isListenerAttached()) {
      firePropertyChange(new PropertyChangeEvent(this, propertyName, 
        oldValue, newValue));
    }
  }
  
  public void removePropertyChangeListener(IPropertyChangeListener listener)
  {
    removeListenerObject(listener);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jface.action.AbstractAction
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jface.action;

import org.eclipse.core.runtime.Assert;

public abstract class AbstractGroupMarker
  extends ContributionItem
{
  protected AbstractGroupMarker() {}
  
  protected AbstractGroupMarker(String groupName)
  {
    super(groupName);
    Assert.isTrue((groupName != null) && (groupName.length() > 0));
  }
  
  public String getGroupName()
  {
    return getId();
  }
  
  public boolean isGroupMarker()
  {
    return getId() != null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jface.action.AbstractGroupMarker
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jface.action;

import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;

class Action$1
  implements IMenuCreator
{
  public void dispose() {}
  
  public Menu getMenu(Control parent)
  {
    return null;
  }
  
  public Menu getMenu(Menu parent)
  {
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jface.action.Action.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jface.action;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.events.HelpListener;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Menu;

public abstract class Action
  extends AbstractAction
  implements IAction
{
  private static final IMenuCreator VAL_DROP_DOWN_MENU = new IMenuCreator()
  {
    public void dispose() {}
    
    public Menu getMenu(Control parent)
    {
      return null;
    }
    
    public Menu getMenu(Menu parent)
    {
      return null;
    }
  };
  private static final String VAL_PUSH_BTN = "PUSH_BTN";
  private static final Integer VAL_RADIO_BTN_OFF = new Integer(0);
  private static final Integer VAL_RADIO_BTN_ON = new Integer(1);
  private static final Boolean VAL_TOGGLE_BTN_OFF = Boolean.FALSE;
  private static final Boolean VAL_TOGGLE_BTN_ON = Boolean.TRUE;
  
  public static String convertAccelerator(int keyCode)
  {
    return LegacyActionTools.convertAccelerator(keyCode);
  }
  
  public static int convertAccelerator(String acceleratorText)
  {
    return LegacyActionTools.convertAccelerator(acceleratorText);
  }
  
  public static int findKeyCode(String token)
  {
    return LegacyActionTools.findKeyCode(token);
  }
  
  public static String findKeyString(int keyCode)
  {
    return LegacyActionTools.findKeyString(keyCode);
  }
  
  public static int findModifier(String token)
  {
    return LegacyActionTools.findModifier(token);
  }
  
  public static String findModifierString(int keyCode)
  {
    return LegacyActionTools.findModifierString(keyCode);
  }
  
  public static String removeAcceleratorText(String text)
  {
    return LegacyActionTools.removeAcceleratorText(text);
  }
  
  public static String removeMnemonics(String text)
  {
    return LegacyActionTools.removeMnemonics(text);
  }
  
  private int accelerator = 0;
  private String actionDefinitionId;
  private String description;
  private ImageDescriptor disabledImage;
  private boolean enabled = true;
  private HelpListener helpListener;
  private ImageDescriptor hoverImage;
  private String id;
  private ImageDescriptor image;
  private String text;
  private String toolTipText;
  private Object value = null;
  
  protected Action() {}
  
  protected Action(String text)
  {
    this();
    setText(text);
  }
  
  protected Action(String text, ImageDescriptor image)
  {
    this(text);
    setImageDescriptor(image);
  }
  
  protected Action(String text, int style)
  {
    this(text);
    switch (style)
    {
    case 1: 
      value = "PUSH_BTN";
      break;
    case 2: 
      value = VAL_TOGGLE_BTN_OFF;
      break;
    case 4: 
      value = VAL_DROP_DOWN_MENU;
      break;
    case 8: 
      value = VAL_RADIO_BTN_OFF;
    }
  }
  
  public int getAccelerator()
  {
    return accelerator;
  }
  
  public String getActionDefinitionId()
  {
    return actionDefinitionId;
  }
  
  public String getDescription()
  {
    if (description != null) {
      return description;
    }
    return getToolTipText();
  }
  
  public ImageDescriptor getDisabledImageDescriptor()
  {
    return disabledImage;
  }
  
  public HelpListener getHelpListener()
  {
    return helpListener;
  }
  
  public ImageDescriptor getHoverImageDescriptor()
  {
    return hoverImage;
  }
  
  public String getId()
  {
    return id;
  }
  
  public ImageDescriptor getImageDescriptor()
  {
    return image;
  }
  
  public IMenuCreator getMenuCreator()
  {
    if (value == VAL_DROP_DOWN_MENU) {
      return null;
    }
    if ((value instanceof IMenuCreator)) {
      return (IMenuCreator)value;
    }
    return null;
  }
  
  public int getStyle()
  {
    if ((value == "PUSH_BTN") || (value == null)) {
      return 1;
    }
    if ((value == VAL_TOGGLE_BTN_ON) || (value == VAL_TOGGLE_BTN_OFF)) {
      return 2;
    }
    if ((value == VAL_RADIO_BTN_ON) || (value == VAL_RADIO_BTN_OFF)) {
      return 8;
    }
    if ((value instanceof IMenuCreator)) {
      return 4;
    }
    return 1;
  }
  
  public String getText()
  {
    return text;
  }
  
  public String getToolTipText()
  {
    return toolTipText;
  }
  
  public boolean isChecked()
  {
    return (value == VAL_TOGGLE_BTN_ON) || (value == VAL_RADIO_BTN_ON);
  }
  
  public boolean isEnabled()
  {
    return enabled;
  }
  
  public boolean isHandled()
  {
    return true;
  }
  
  public final void notifyResult(boolean success)
  {
    firePropertyChange("result", null, success ? Boolean.TRUE : Boolean.FALSE);
  }
  
  public void run() {}
  
  public void runWithEvent(Event event)
  {
    run();
  }
  
  public void setAccelerator(int keycode)
  {
    accelerator = keycode;
  }
  
  public void setActionDefinitionId(String id)
  {
    actionDefinitionId = id;
  }
  
  public void setChecked(boolean checked)
  {
    Object newValue = null;
    if ((value == null) || (value == VAL_TOGGLE_BTN_ON) || 
      (value == VAL_TOGGLE_BTN_OFF)) {
      newValue = checked ? VAL_TOGGLE_BTN_ON : VAL_TOGGLE_BTN_OFF;
    } else if ((value == VAL_RADIO_BTN_ON) || (value == VAL_RADIO_BTN_OFF)) {
      newValue = checked ? VAL_RADIO_BTN_ON : VAL_RADIO_BTN_OFF;
    } else {
      return;
    }
    if (newValue != value)
    {
      value = newValue;
      if (checked) {
        firePropertyChange("checked", Boolean.FALSE, Boolean.TRUE);
      } else {
        firePropertyChange("checked", Boolean.TRUE, Boolean.FALSE);
      }
    }
  }
  
  public void setDescription(String text)
  {
    if (((description == null) && (text != null)) || 
      ((description != null) && (text == null)) || (
      (description != null) && (text != null) && 
      (!text.equals(description))))
    {
      String oldDescription = description;
      description = text;
      firePropertyChange("description", oldDescription, description);
    }
  }
  
  public void setDisabledImageDescriptor(ImageDescriptor newImage)
  {
    if (disabledImage != newImage)
    {
      ImageDescriptor oldImage = disabledImage;
      disabledImage = newImage;
      firePropertyChange("image", oldImage, newImage);
    }
  }
  
  public void setEnabled(boolean enabled)
  {
    if (enabled != this.enabled)
    {
      Boolean oldVal = this.enabled ? Boolean.TRUE : Boolean.FALSE;
      Boolean newVal = enabled ? Boolean.TRUE : Boolean.FALSE;
      this.enabled = enabled;
      firePropertyChange("enabled", oldVal, newVal);
    }
  }
  
  public void setHelpListener(HelpListener listener)
  {
    helpListener = listener;
  }
  
  public void setHoverImageDescriptor(ImageDescriptor newImage)
  {
    if (hoverImage != newImage)
    {
      ImageDescriptor oldImage = hoverImage;
      hoverImage = newImage;
      firePropertyChange("image", oldImage, newImage);
    }
  }
  
  public void setId(String id)
  {
    this.id = id;
  }
  
  public void setImageDescriptor(ImageDescriptor newImage)
  {
    if (image != newImage)
    {
      ImageDescriptor oldImage = image;
      image = newImage;
      firePropertyChange("image", oldImage, newImage);
    }
  }
  
  public void setMenuCreator(IMenuCreator creator)
  {
    if (value == null)
    {
      value = creator;
      return;
    }
    if ((value instanceof IMenuCreator)) {
      value = (creator == null ? VAL_DROP_DOWN_MENU : creator);
    }
  }
  
  public void setText(String text)
  {
    String oldText = this.text;
    int oldAccel = accelerator;
    this.text = text;
    if (text != null)
    {
      String acceleratorText = 
        LegacyActionTools.extractAcceleratorText(text);
      if (acceleratorText != null)
      {
        int newAccelerator = 
          LegacyActionTools.convertLocalizedAccelerator(acceleratorText);
        if (newAccelerator > 0) {
          setAccelerator(newAccelerator);
        }
      }
    }
    if ((accelerator != oldAccel) || (oldText == null ? this.text != null : 
      !oldText.equals(this.text))) {
      firePropertyChange("text", oldText, this.text);
    }
  }
  
  public void setToolTipText(String toolTipText)
  {
    String oldToolTipText = this.toolTipText;
    if (oldToolTipText == null ? toolTipText != null : 
      !oldToolTipText.equals(toolTipText))
    {
      this.toolTipText = toolTipText;
      firePropertyChange("toolTipText", oldToolTipText, toolTipText);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jface.action.Action
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jface.action;

import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;

class ActionContributionItem$1
  implements IPropertyChangeListener
{
  final ActionContributionItem this$0;
  
  ActionContributionItem$1(ActionContributionItem paramActionContributionItem)
  {
    this$0 = paramActionContributionItem;
  }
  
  public void propertyChange(PropertyChangeEvent event)
  {
    this$0.update(event.getProperty());
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jface.action.ActionContributionItem.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jface.action;

import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Widget;

class ActionContributionItem$10
  implements Listener
{
  final ActionContributionItem this$0;
  private final Menu val$itemMenu;
  private final Menu val$subMenu;
  
  ActionContributionItem$10(ActionContributionItem paramActionContributionItem, Menu paramMenu1, Menu paramMenu2)
  {
    this$0 = paramActionContributionItem;val$itemMenu = paramMenu1;val$subMenu = paramMenu2;
  }
  
  public void handleEvent(Event event)
  {
    widget.removeListener(22, this);
    if (type == 22) {
      ActionContributionItem.access$6(this$0, val$itemMenu, val$subMenu);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jface.action.ActionContributionItem.10
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jface.action;

import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;

class ActionContributionItem$11
  implements Runnable
{
  final ActionContributionItem this$0;
  private final Menu val$proxy;
  
  ActionContributionItem$11(ActionContributionItem paramActionContributionItem, Menu paramMenu)
  {
    this$0 = paramActionContributionItem;val$proxy = paramMenu;
  }
  
  public void run()
  {
    if (!val$proxy.isDisposed())
    {
      MenuItem parentItem = val$proxy.getParentItem();
      val$proxy.dispose();
      parentItem.setMenu(ActionContributionItem.access$7(this$0));
    }
    if ((ActionContributionItem.access$7(this$0) != null) && (!ActionContributionItem.access$7(this$0).isDisposed())) {
      ActionContributionItem.access$7(this$0).notifyListeners(23, null);
    }
    ActionContributionItem.access$8(this$0, null);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jface.action.ActionContributionItem.11
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jface.action;

import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;

class ActionContributionItem$2
  implements IPropertyChangeListener
{
  final ActionContributionItem this$0;
  
  ActionContributionItem$2(ActionContributionItem paramActionContributionItem)
  {
    this$0 = paramActionContributionItem;
  }
  
  public void propertyChange(PropertyChangeEvent event)
  {
    ActionContributionItem.access$0(this$0, event);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jface.action.ActionContributionItem.2
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jface.action;

import org.eclipse.jface.util.PropertyChangeEvent;

class ActionContributionItem$3
  implements Runnable
{
  final ActionContributionItem this$0;
  private final PropertyChangeEvent val$e;
  
  ActionContributionItem$3(ActionContributionItem paramActionContributionItem, PropertyChangeEvent paramPropertyChangeEvent)
  {
    this$0 = paramActionContributionItem;val$e = paramPropertyChangeEvent;
  }
  
  public void run()
  {
    this$0.update(val$e.getProperty());
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jface.action.ActionContributionItem.3
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jface.action;

import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Widget;

class ActionContributionItem$4
  implements Listener
{
  final ActionContributionItem this$0;
  
  ActionContributionItem$4(ActionContributionItem paramActionContributionItem)
  {
    this$0 = paramActionContributionItem;
  }
  
  public void handleEvent(Event event)
  {
    switch (type)
    {
    case 12: 
      ActionContributionItem.access$1(this$0, event);
      break;
    case 13: 
      Widget ew = widget;
      if (ew != null) {
        ActionContributionItem.access$2(this$0, event, ((Button)ew)
          .getSelection());
      }
      break;
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jface.action.ActionContributionItem.4
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jface.action;

import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Widget;

class ActionContributionItem$5
  implements Listener
{
  final ActionContributionItem this$0;
  
  ActionContributionItem$5(ActionContributionItem paramActionContributionItem)
  {
    this$0 = paramActionContributionItem;
  }
  
  public void handleEvent(Event event)
  {
    switch (type)
    {
    case 12: 
      ActionContributionItem.access$1(this$0, event);
      break;
    case 13: 
      Widget ew = widget;
      if (ew != null) {
        ActionContributionItem.access$2(this$0, event, ((MenuItem)ew)
          .getSelection());
      }
      break;
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jface.action.ActionContributionItem.5
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jface.action;

import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.widgets.Widget;

class ActionContributionItem$6
  implements Listener
{
  final ActionContributionItem this$0;
  
  ActionContributionItem$6(ActionContributionItem paramActionContributionItem)
  {
    this$0 = paramActionContributionItem;
  }
  
  public void handleEvent(Event event)
  {
    switch (type)
    {
    case 12: 
      ActionContributionItem.access$1(this$0, event);
      break;
    case 13: 
      Widget ew = widget;
      if (ew != null) {
        ActionContributionItem.access$2(this$0, event, ((ToolItem)ew)
          .getSelection());
      }
      break;
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jface.action.ActionContributionItem.6
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jface.action;

import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;

class ActionContributionItem$7
  implements IPropertyChangeListener
{
  final ActionContributionItem this$0;
  
  ActionContributionItem$7(ActionContributionItem paramActionContributionItem)
  {
    this$0 = paramActionContributionItem;
  }
  
  public void propertyChange(PropertyChangeEvent event)
  {
    if ((event.getProperty().equals("result")) && 
      ((event.getNewValue() instanceof Boolean))) {
      ActionContributionItem.access$3(this$0, (Boolean)event.getNewValue());
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jface.action.ActionContributionItem.7
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jface.action;

import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;

class ActionContributionItem$8
  implements Listener
{
  final ActionContributionItem this$0;
  
  ActionContributionItem$8(ActionContributionItem paramActionContributionItem)
  {
    this$0 = paramActionContributionItem;
  }
  
  public void handleEvent(Event event)
  {
    switch (type)
    {
    case 22: 
      ActionContributionItem.access$4(this$0, (Menu)widget);
      break;
    case 23: 
      ActionContributionItem.access$5(this$0, (Menu)widget);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jface.action.ActionContributionItem.8
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jface.action;

import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Widget;

class ActionContributionItem$9
  implements Listener
{
  final ActionContributionItem this$0;
  
  ActionContributionItem$9(ActionContributionItem paramActionContributionItem)
  {
    this$0 = paramActionContributionItem;
  }
  
  public void handleEvent(Event event)
  {
    if (!widget.isDisposed())
    {
      Widget realItem = (Widget)widget.getData();
      if (!realItem.isDisposed())
      {
        int style = widget.getStyle();
        if ((type == 13) && 
          ((style & 0x32) != 0) && 
          ((realItem instanceof MenuItem))) {
          ((MenuItem)realItem).setSelection(((MenuItem)widget)
            .getSelection());
        }
        widget = realItem;
        realItem.notifyListeners(type, event);
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jface.action.ActionContributionItem.9
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jface.action;

import java.io.PrintStream;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.NotEnabledException;
import org.eclipse.jface.bindings.Trigger;
import org.eclipse.jface.bindings.TriggerSequence;
import org.eclipse.jface.bindings.keys.IKeyLookup;
import org.eclipse.jface.bindings.keys.KeyLookupFactory;
import org.eclipse.jface.bindings.keys.KeyStroke;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.resource.LocalResourceManager;
import org.eclipse.jface.resource.ResourceManager;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.Policy;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.util.Util;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Item;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.widgets.Widget;

public class ActionContributionItem
  extends ContributionItem
{
  public static int MODE_FORCE_TEXT = 1;
  private static final String ellipsis = "...";
  private Boolean result = null;
  private static boolean USE_COLOR_ICONS = true;
  
  public static boolean getUseColorIconsInToolbars()
  {
    return USE_COLOR_ICONS;
  }
  
  public static void setUseColorIconsInToolbars(boolean useColorIcons)
  {
    USE_COLOR_ICONS = useColorIcons;
  }
  
  private int mode = 0;
  private IAction action;
  private final IPropertyChangeListener actionTextListener = new IPropertyChangeListener()
  {
    public void propertyChange(PropertyChangeEvent event)
    {
      update(event.getProperty());
    }
  };
  private LocalResourceManager imageManager;
  private Listener buttonListener;
  private Listener menuItemListener;
  private final IPropertyChangeListener propertyListener = new IPropertyChangeListener()
  {
    public void propertyChange(PropertyChangeEvent event)
    {
      ActionContributionItem.this.actionPropertyChange(event);
    }
  };
  private Listener toolItemListener;
  private Widget widget = null;
  private Listener menuCreatorListener;
  
  public ActionContributionItem(IAction action)
  {
    super(action.getId());
    this.action = action;
  }
  
  private void actionPropertyChange(PropertyChangeEvent e)
  {
    if ((isVisible()) && (widget != null))
    {
      Display display = widget.getDisplay();
      if (display.getThread() == Thread.currentThread()) {
        update(e.getProperty());
      } else {
        display.asyncExec(new Runnable()
        {
          private final PropertyChangeEvent val$e;
          
          public void run()
          {
            update(val$e.getProperty());
          }
        });
      }
    }
  }
  
  public boolean equals(Object o)
  {
    if (!(o instanceof ActionContributionItem)) {
      return false;
    }
    return action.equals(action);
  }
  
  public void fill(Composite parent)
  {
    if ((widget == null) && (parent != null))
    {
      int flags = 8;
      if (action != null)
      {
        if (action.getStyle() == 2) {
          flags = 2;
        }
        if (action.getStyle() == 8) {
          flags = 16;
        }
      }
      Button b = new Button(parent, flags);
      b.setData(this);
      b.addListener(12, getButtonListener());
      
      b.addListener(13, getButtonListener());
      if (action.getHelpListener() != null) {
        b.addHelpListener(action.getHelpListener());
      }
      widget = b;
      
      update(null);
      
      action.addPropertyChangeListener(propertyListener);
      if (action != null)
      {
        String commandId = action.getActionDefinitionId();
        ExternalActionManager.ICallback callback = 
          ExternalActionManager.getInstance().getCallback();
        if ((callback != null) && (commandId != null)) {
          callback.addPropertyChangeListener(commandId, 
            actionTextListener);
        }
      }
    }
  }
  
  public void fill(Menu parent, int index)
  {
    if ((widget == null) && (parent != null))
    {
      int flags = 8;
      if (action != null)
      {
        int style = action.getStyle();
        if (style == 2) {
          flags = 32;
        } else if (style == 8) {
          flags = 16;
        } else if (style == 4) {
          flags = 64;
        }
      }
      MenuItem mi = null;
      if (index >= 0) {
        mi = new MenuItem(parent, flags, index);
      } else {
        mi = new MenuItem(parent, flags);
      }
      widget = mi;
      
      mi.setData(this);
      mi.addListener(12, getMenuItemListener());
      mi.addListener(13, getMenuItemListener());
      if (action.getHelpListener() != null) {
        mi.addHelpListener(action.getHelpListener());
      }
      if (flags == 64)
      {
        Menu subMenu = new Menu(parent);
        subMenu.addListener(22, getMenuCreatorListener());
        subMenu.addListener(23, getMenuCreatorListener());
        mi.setMenu(subMenu);
      }
      update(null);
      
      action.addPropertyChangeListener(propertyListener);
      if (action != null)
      {
        String commandId = action.getActionDefinitionId();
        ExternalActionManager.ICallback callback = 
          ExternalActionManager.getInstance().getCallback();
        if ((callback != null) && (commandId != null)) {
          callback.addPropertyChangeListener(commandId, 
            actionTextListener);
        }
      }
    }
  }
  
  public void fill(ToolBar parent, int index)
  {
    if ((widget == null) && (parent != null))
    {
      int flags = 8;
      if (action != null)
      {
        int style = action.getStyle();
        if (style == 2) {
          flags = 32;
        } else if (style == 8) {
          flags = 16;
        } else if (style == 4) {
          flags = 4;
        }
      }
      ToolItem ti = null;
      if (index >= 0) {
        ti = new ToolItem(parent, flags, index);
      } else {
        ti = new ToolItem(parent, flags);
      }
      ti.setData(this);
      ti.addListener(13, getToolItemListener());
      ti.addListener(12, getToolItemListener());
      
      widget = ti;
      
      update(null);
      
      action.addPropertyChangeListener(propertyListener);
      if (action != null)
      {
        String commandId = action.getActionDefinitionId();
        ExternalActionManager.ICallback callback = 
          ExternalActionManager.getInstance().getCallback();
        if ((callback != null) && (commandId != null)) {
          callback.addPropertyChangeListener(commandId, 
            actionTextListener);
        }
      }
    }
  }
  
  public IAction getAction()
  {
    return action;
  }
  
  private Listener getButtonListener()
  {
    if (buttonListener == null) {
      buttonListener = new Listener()
      {
        public void handleEvent(Event event)
        {
          switch (type)
          {
          case 12: 
            ActionContributionItem.this.handleWidgetDispose(event);
            break;
          case 13: 
            Widget ew = widget;
            if (ew != null) {
              ActionContributionItem.this.handleWidgetSelection(event, ((Button)ew)
                .getSelection());
            }
            break;
          }
        }
      };
    }
    return buttonListener;
  }
  
  private Listener getMenuItemListener()
  {
    if (menuItemListener == null) {
      menuItemListener = new Listener()
      {
        public void handleEvent(Event event)
        {
          switch (type)
          {
          case 12: 
            ActionContributionItem.this.handleWidgetDispose(event);
            break;
          case 13: 
            Widget ew = widget;
            if (ew != null) {
              ActionContributionItem.this.handleWidgetSelection(event, ((MenuItem)ew)
                .getSelection());
            }
            break;
          }
        }
      };
    }
    return menuItemListener;
  }
  
  public int getMode()
  {
    return mode;
  }
  
  private Listener getToolItemListener()
  {
    if (toolItemListener == null) {
      toolItemListener = new Listener()
      {
        public void handleEvent(Event event)
        {
          switch (type)
          {
          case 12: 
            ActionContributionItem.this.handleWidgetDispose(event);
            break;
          case 13: 
            Widget ew = widget;
            if (ew != null) {
              ActionContributionItem.this.handleWidgetSelection(event, ((ToolItem)ew)
                .getSelection());
            }
            break;
          }
        }
      };
    }
    return toolItemListener;
  }
  
  private void handleWidgetDispose(Event e)
  {
    if (widget == widget)
    {
      if ((action.getStyle() == 4) && 
        (menuCreatorCalled))
      {
        IMenuCreator mc = action.getMenuCreator();
        if (mc != null) {
          mc.dispose();
        }
      }
      action.removePropertyChangeListener(propertyListener);
      if (action != null)
      {
        String commandId = action.getActionDefinitionId();
        ExternalActionManager.ICallback callback = 
          ExternalActionManager.getInstance().getCallback();
        if ((callback != null) && (commandId != null)) {
          callback.removePropertyChangeListener(commandId, 
            actionTextListener);
        }
      }
      widget = null;
      
      disposeOldImages();
    }
  }
  
  private void handleWidgetSelection(Event e, boolean selection)
  {
    Widget item = widget;
    if (item != null)
    {
      int style = item.getStyle();
      if ((style & 0x22) != 0)
      {
        if (action.getStyle() == 2) {
          action.setChecked(selection);
        }
      }
      else if ((style & 0x10) != 0)
      {
        if (action.getStyle() == 8) {
          action.setChecked(selection);
        }
      }
      else if (((style & 0x4) != 0) && 
        (detail == 4) && 
        (action.getStyle() == 4))
      {
        IMenuCreator mc = action.getMenuCreator();
        menuCreatorCalled = true;
        ToolItem ti = (ToolItem)item;
        if (mc != null)
        {
          Menu m = mc.getMenu(ti.getParent());
          if (m != null)
          {
            Point point = ti.getParent().toDisplay(
              new Point(x, y));
            m.setLocation(x, y);
            
            m.setVisible(true);
            return;
          }
        }
      }
      ExternalActionManager.IExecuteCallback callback = null;
      String actionDefinitionId = action.getActionDefinitionId();
      if (actionDefinitionId != null)
      {
        Object obj = ExternalActionManager.getInstance()
          .getCallback();
        if ((obj instanceof ExternalActionManager.IExecuteCallback)) {
          callback = (ExternalActionManager.IExecuteCallback)obj;
        }
      }
      if (action.isEnabled())
      {
        boolean trace = Policy.TRACE_ACTIONS;
        
        long ms = 0L;
        if (trace)
        {
          ms = System.currentTimeMillis();
          System.out.println("Running action: " + action.getText());
        }
        IPropertyChangeListener resultListener = null;
        if (callback != null)
        {
          resultListener = new IPropertyChangeListener()
          {
            public void propertyChange(PropertyChangeEvent event)
            {
              if ((event.getProperty().equals("result")) && 
                ((event.getNewValue() instanceof Boolean))) {
                result = ((Boolean)event.getNewValue());
              }
            }
          };
          action.addPropertyChangeListener(resultListener);
          callback.preExecute(action, e);
        }
        action.runWithEvent(e);
        if (callback != null) {
          if ((result == null) || (result.equals(Boolean.TRUE))) {
            callback.postExecuteSuccess(action, Boolean.TRUE);
          } else {
            callback.postExecuteFailure(action, 
              new ExecutionException(action.getText() + 
              " returned failure."));
          }
        }
        if (resultListener != null)
        {
          result = null;
          action.removePropertyChangeListener(resultListener);
        }
        if (trace) {
          System.out.println(System.currentTimeMillis() - ms + 
            " ms to run action: " + action.getText());
        }
      }
      else if (callback != null)
      {
        callback.notEnabled(action, new NotEnabledException(action
          .getText() + 
          " is not enabled."));
      }
    }
  }
  
  public int hashCode()
  {
    return action.hashCode();
  }
  
  private boolean hasImages(IAction actionToCheck)
  {
    return (actionToCheck.getImageDescriptor() != null) || (actionToCheck.getHoverImageDescriptor() != null) || (actionToCheck.getDisabledImageDescriptor() != null);
  }
  
  private boolean isCommandActive()
  {
    IAction actionToCheck = getAction();
    if (actionToCheck != null)
    {
      String commandId = actionToCheck.getActionDefinitionId();
      ExternalActionManager.ICallback callback = 
        ExternalActionManager.getInstance().getCallback();
      if (callback != null) {
        return callback.isActive(commandId);
      }
    }
    return true;
  }
  
  public boolean isDynamic()
  {
    if ((widget instanceof MenuItem))
    {
      boolean itemIsCheck = (widget.getStyle() & 0x20) != 0;
      boolean actionIsCheck = (getAction() != null) && 
        (getAction().getStyle() == 2);
      boolean itemIsRadio = (widget.getStyle() & 0x10) != 0;
      boolean actionIsRadio = (getAction() != null) && 
        (getAction().getStyle() == 8);
      
      return (itemIsCheck != actionIsCheck) || (itemIsRadio != actionIsRadio);
    }
    return false;
  }
  
  public boolean isEnabled()
  {
    return (action != null) && (action.isEnabled());
  }
  
  protected boolean isEnabledAllowed()
  {
    if (getParent() == null) {
      return true;
    }
    Boolean value = getParent().getOverrides().getEnabled(this);
    return value == null ? true : value.booleanValue();
  }
  
  public boolean isVisible()
  {
    return (super.isVisible()) && (isCommandActive());
  }
  
  public void setMode(int mode)
  {
    this.mode = mode;
    update();
  }
  
  public final void update()
  {
    update(null);
  }
  
  public void update(String propertyName)
  {
    if (widget != null)
    {
      boolean textChanged = (propertyName == null) || 
        (propertyName.equals("text"));
      boolean imageChanged = (propertyName == null) || 
        (propertyName.equals("image"));
      boolean tooltipTextChanged = (propertyName == null) || 
        (propertyName.equals("toolTipText"));
      if ((propertyName != null) && 
        (!propertyName.equals("enabled"))) {}
      boolean enableStateChanged = 
      
        propertyName
        .equals("enabled");
      boolean checkChanged = ((action.getStyle() == 2) || 
        (action.getStyle() == 8)) && (
        (propertyName == null) || 
        (propertyName.equals("checked")));
      if ((widget instanceof ToolItem))
      {
        ToolItem ti = (ToolItem)widget;
        String text = action.getText();
        
        boolean showText = (text != null) && (
          ((getMode() & MODE_FORCE_TEXT) != 0) || (!hasImages(action)));
        if ((showText) && (text != null))
        {
          text = Action.removeAcceleratorText(text);
          text = Action.removeMnemonics(text);
        }
        if (textChanged)
        {
          String textToSet = showText ? text : "";
          boolean rightStyle = (ti.getParent().getStyle() & 0x20000) != 0;
          if ((rightStyle) || (!ti.getText().equals(textToSet))) {
            ti.setText(textToSet);
          }
        }
        if (imageChanged) {
          updateImages(!showText);
        }
        if ((tooltipTextChanged) || (textChanged))
        {
          String toolTip = action.getToolTipText();
          if ((toolTip == null) || (toolTip.length() == 0)) {
            toolTip = text;
          }
          ExternalActionManager.ICallback callback = 
            ExternalActionManager.getInstance().getCallback();
          String commandId = action.getActionDefinitionId();
          if ((callback != null) && (commandId != null) && 
            (toolTip != null))
          {
            String acceleratorText = callback
              .getAcceleratorText(commandId);
            if ((acceleratorText != null) && 
              (acceleratorText.length() != 0)) {
              toolTip = JFaceResources.format(
                "Toolbar_Tooltip_Accelerator", 
                new Object[] { toolTip, acceleratorText });
            }
          }
          if ((!showText) || ((toolTip != null) && (!toolTip.equals(text)))) {
            ti.setToolTipText(toolTip);
          } else {
            ti.setToolTipText(null);
          }
        }
        if (enableStateChanged)
        {
          boolean shouldBeEnabled = (action.isEnabled()) && 
            (isEnabledAllowed());
          if (ti.getEnabled() != shouldBeEnabled) {
            ti.setEnabled(shouldBeEnabled);
          }
        }
        if (checkChanged)
        {
          boolean bv = action.isChecked();
          if (ti.getSelection() != bv) {
            ti.setSelection(bv);
          }
        }
        return;
      }
      if ((widget instanceof MenuItem))
      {
        MenuItem mi = (MenuItem)widget;
        if (textChanged)
        {
          int accelerator = 0;
          String acceleratorText = null;
          IAction updatedAction = getAction();
          String text = null;
          accelerator = updatedAction.getAccelerator();
          ExternalActionManager.ICallback callback = 
            ExternalActionManager.getInstance().getCallback();
          if ((accelerator != 0) && (callback != null) && 
            (callback.isAcceleratorInUse(accelerator))) {
            accelerator = 0;
          }
          String commandId = updatedAction
            .getActionDefinitionId();
          if ((Util.isGtk()) && ((callback instanceof ExternalActionManager.IBindingManagerCallback)) && 
            (commandId != null))
          {
            ExternalActionManager.IBindingManagerCallback bindingManagerCallback = (ExternalActionManager.IBindingManagerCallback)callback;
            IKeyLookup lookup = KeyLookupFactory.getDefault();
            TriggerSequence[] triggerSequences = bindingManagerCallback
              .getActiveBindingsFor(commandId);
            for (int i = 0; i < triggerSequences.length; i++)
            {
              TriggerSequence triggerSequence = triggerSequences[i];
              Trigger[] triggers = triggerSequence
                .getTriggers();
              if (triggers.length == 1)
              {
                Trigger trigger = triggers[0];
                if ((trigger instanceof KeyStroke))
                {
                  KeyStroke currentKeyStroke = (KeyStroke)trigger;
                  int currentNaturalKey = currentKeyStroke
                    .getNaturalKey();
                  if (currentKeyStroke.getModifierKeys() == 
                    (lookup.getCtrl() | lookup.getShift())) {
                    if (((currentNaturalKey >= 48) && (currentNaturalKey <= 57)) || 
                      ((currentNaturalKey >= 65) && (currentNaturalKey <= 70)) || (currentNaturalKey == 85))
                    {
                      accelerator = currentKeyStroke
                        .getModifierKeys() | 
                        cur
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

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