The main plugin class to be used in the desktop. : Eclipse Plugin « SWT JFace Eclipse « Java






The main plugin class to be used in the desktop.


/*******************************************************************************
 * Copyright (c) 2000, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.examples.paint;


import org.eclipse.core.runtime.*;
import org.eclipse.ui.plugin.*;

/**
 * The main plugin class to be used in the desktop.
 */
public class PaintPlugin extends AbstractUIPlugin {
  private static PaintPlugin plugin;

  /**
   * Constructs the Paint plugin.
   */
  public PaintPlugin() {
    super();
    plugin = this;
  }
  
  /**
   * Log an error to the ILog for this plugin
   * 
   * @param message the localized error message text
   * @param exception the associated exception, or null
   */
  public static void logError(String message, Throwable exception) {
    plugin.getLog().log(
      new Status(IStatus.ERROR, plugin.getBundle().getSymbolicName(), 0, message, exception));
  }
}


/*******************************************************************************
 * Copyright (c) 2000, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.examples.paint;


import org.eclipse.jface.action.*;
import org.eclipse.jface.resource.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.*;
import org.eclipse.ui.part.*;

/**
 * The view for the paint application.
 * All rendering happens inside the area created by createPartControl().
 * 
 * @see ViewPart
 */
public class PaintView extends ViewPart {
  PaintExample instance = null;

  /**
   * Constructs a Paint view.
   */
  public PaintView() {
  }

  /**
   * Creates the example.
   * 
   * @see ViewPart#createPartControl
   */
  public void createPartControl(Composite parent) {
    instance = new PaintExample(parent);
    instance.createGUI(parent);

    /*** Add toolbar contributions ***/
    final IActionBars actionBars = getViewSite().getActionBars();
    IToolBarManager toolbarManager = actionBars.getToolBarManager();
    Tool tools[] = PaintExample.tools;
    String group = tools[0].group;
    toolbarManager.add(new GroupMarker(group));
    for (int i = 0; i < tools.length; i++) {
      Tool tool = tools[i];
      if (!tool.group.equals(group)) {
        toolbarManager.add(new Separator());
        toolbarManager.add(new GroupMarker(tool.group));
      }
      group = tool.group;
      PaintAction action = new PaintAction(tool);
      toolbarManager.appendToGroup(group, action);
      if (i == PaintExample.Default_tool || i == PaintExample.Default_fill || i == PaintExample.Default_linestyle) {
        action.setChecked(true);
      }
    }
    actionBars.updateActionBars();

    instance.setDefaults();
  }

  /**
   * Called when the View is to be disposed
   */  
  public void dispose() {
    instance.dispose();
    instance = null;
    super.dispose();
  }
  
  /**
   * Returns the Display.
   * 
   * @return the display we're using
   */
  public Display getDisplay() {
    return instance.getDisplay();
  }
  
  /**
   * Called when we must grab focus.
   * 
   * @see org.eclipse.ui.part.ViewPart#setFocus
   */
  public void setFocus() {
    instance.setFocus();
  }

  /**
   * Action set glue.
   */
  class PaintAction extends Action {
    private int style;
    private Runnable action;
    public PaintAction(Tool tool) {
      super();
      String id = tool.group + '.' + tool.name;
      setId(id);
      style = tool.type == SWT.RADIO ? IAction.AS_RADIO_BUTTON : IAction.AS_PUSH_BUTTON;
      action = tool.action;
      setText(PaintExample.getResourceString(id + ".label"));
      setToolTipText(PaintExample.getResourceString(id + ".tooltip"));
      setDescription(PaintExample.getResourceString(id + ".description"));
      setImageDescriptor(ImageDescriptor.createFromFile(
          PaintExample.class,
          PaintExample.getResourceString(id + ".image")));
    }
    public int getStyle() { return style; }
    public void run() { action.run(); }
  }
}

           
       








Related examples in the same category

1.Bdaum Spell Checker Eclipse Plugin
2.HEX Eclipse Plugin
3.Eclipse PlugIn Image Viewer
4.Eclipse Plug In RCP Example Plugin
5.Eclipse PlugIn Gadget
6.Eclipse PlugIn Demo
7.Eclipse PlugIn Hello World
8.Eclipse PlugIn Menu Editor
9.Eclipse PlugIn Game
10.Eclipse Help PlugIn
11.Eclipse PlugIn Wizards Plugin
12.Eclipse Plugin Spell Checker
13.Eclipse PlugIn FlowChart
14.Eclipse PlugIn shapes merlin
15.Eclipse PlugIn Hello World 2
16.Table Viewer Example Plugin
17.Custom widget PlugIn
18.View Article PlugIn
19.Shapes Emf PlugIn
20.Shape srcp PlugIn
21.XML Editor Plugin
22.Tree viewer PlugIn
23.WizardsPlugin