diff options
author | Susan Franklin | 2009-03-17 16:38:08 +0000 |
---|---|---|
committer | Susan Franklin | 2009-03-17 16:38:08 +0000 |
commit | a064085e3b356812914245dfe9d887f3bdda0a7d (patch) | |
tree | 05f66acb75cf50c404f820bf4f595b7a0c1ce4a5 /examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox | |
parent | b0f49fefb87f7b655ab9e5b994f7eeb7500f4825 (diff) | |
download | rt.equinox.p2-a064085e3b356812914245dfe9d887f3bdda0a7d.tar.gz rt.equinox.p2-a064085e3b356812914245dfe9d887f3bdda0a7d.tar.xz rt.equinox.p2-a064085e3b356812914245dfe9d887f3bdda0a7d.zip |
initial content
Diffstat (limited to 'examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox')
11 files changed, 744 insertions, 0 deletions
diff --git a/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/Activator.java b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/Activator.java new file mode 100644 index 000000000..1a8dd9585 --- /dev/null +++ b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/Activator.java @@ -0,0 +1,65 @@ +package org.eclipse.equinox.p2.examples.rcp.prestartupdate; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.equinox.p2.examples.rcp.prestartupdate"; + + // The shared instance + private static Activator plugin; + + // XXX Shared instance of bundle context + static BundleContext bundleContext; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + bundleContext = context; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + /** + * Returns an image descriptor for the image file at the given + * plug-in relative path + * + * @param path the path + * @return the image descriptor + */ + public static ImageDescriptor getImageDescriptor(String path) { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } +} diff --git a/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/Application.java b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/Application.java new file mode 100644 index 000000000..9eb2e7283 --- /dev/null +++ b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/Application.java @@ -0,0 +1,212 @@ +package org.eclipse.equinox.p2.examples.rcp.prestartupdate; + +import java.lang.reflect.InvocationTargetException; +import java.net.URI; +import java.util.ArrayList; +import java.util.Iterator; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.equinox.app.IApplication; +import org.eclipse.equinox.app.IApplicationContext; +import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; +import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; +import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepositoryManager; +import org.eclipse.equinox.internal.provisional.p2.director.IPlanner; +import org.eclipse.equinox.internal.provisional.p2.director.ProfileChangeRequest; +import org.eclipse.equinox.internal.provisional.p2.director.ProvisioningPlan; +import org.eclipse.equinox.internal.provisional.p2.engine.DefaultPhaseSet; +import org.eclipse.equinox.internal.provisional.p2.engine.IEngine; +import org.eclipse.equinox.internal.provisional.p2.engine.IProfile; +import org.eclipse.equinox.internal.provisional.p2.engine.IProfileRegistry; +import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningContext; +import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery; +import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager; +import org.eclipse.equinox.internal.provisional.p2.query.Collector; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.statushandlers.StatusManager; + +/** + * This class controls all aspects of the application's execution + */ +public class Application implements IApplication { + + /* + * (non-Javadoc) + * + * @seeorg.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app. + * IApplicationContext) + */ + public Object start(IApplicationContext context) { + Display display = PlatformUI.createDisplay(); + try { + // XXX check for updates before ever running a workbench + if (checkForUpdates(display)) + // An update was done, we need to restart + return IApplication.EXIT_RESTART; + else { + int returnCode = PlatformUI.createAndRunWorkbench(display, + new ApplicationWorkbenchAdvisor()); + if (returnCode == PlatformUI.RETURN_RESTART) { + return IApplication.EXIT_RESTART; + } + } + return IApplication.EXIT_OK; + } finally { + display.dispose(); + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.equinox.app.IApplication#stop() + */ + public void stop() { + final IWorkbench workbench = PlatformUI.getWorkbench(); + if (workbench == null) + return; + final Display display = workbench.getDisplay(); + display.syncExec(new Runnable() { + public void run() { + if (!display.isDisposed()) + workbench.close(); + } + }); + } + + // XXX Check for updates to this application and return true if + // we have installed updates and need a restart. + // This method is intentionally long and ugly in order to provide + // "one-stop-shopping" for how to check for and perform an update. + private boolean checkForUpdates(Display display) { + // Before we show a progress dialog, at least find out that we have + // installed content and repos to check. + final IProfileRegistry profileRegistry = (IProfileRegistry) ServiceHelper + .getService(Activator.bundleContext, IProfileRegistry.class + .getName()); + if (profileRegistry == null) + return false; + final IProfile profile = profileRegistry + .getProfile(IProfileRegistry.SELF); + if (profile == null) + return false; + + // We are going to look for updates to all IU's in the profile. A + // different query could be used if we are looking for updates to + // a subset. For example, the p2 UI only looks for updates to those + // IU's marked with a special property. + final Collector collector = profile.query(InstallableUnitQuery.ANY, + new Collector(), null); + if (collector.isEmpty()) + return false; + final IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper + .getService(Activator.bundleContext, + IMetadataRepositoryManager.class.getName()); + if (manager == null) + return false; + final URI[] reposToSearch = manager + .getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL); + if (reposToSearch.length == 0) + return false; + final IPlanner planner = (IPlanner) ServiceHelper.getService( + Activator.bundleContext, IPlanner.class.getName()); + if (planner == null) + return false; + // Looking in all known repositories for updates for each IU in the profile + final boolean[] didWeUpdate = new boolean[1]; + didWeUpdate[0] = false; + IRunnableWithProgress runnable = new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) + throws InvocationTargetException, InterruptedException { + SubMonitor sub = SubMonitor.convert(monitor, + "Checking for application updates...", 200 + (collector + .size() * 100)); + // First we look for replacement IU's for each IU + ArrayList iusWithUpdates = new ArrayList(); + ArrayList replacementIUs = new ArrayList(); + Iterator iter = collector.iterator(); + ProvisioningContext pc = new ProvisioningContext(reposToSearch); + while (iter.hasNext()) { + if (sub.isCanceled()) + throw new InterruptedException(); + IInstallableUnit iu = (IInstallableUnit) iter.next(); + IInstallableUnit[] replacements = planner.updatesFor(iu, + pc, sub.newChild(100)); + if (replacements.length > 0) { + iusWithUpdates.add(iu); + if (replacements.length == 1) + replacementIUs.add(replacements[0]); + else { + IInstallableUnit repl = replacements[0]; + for (int i = 1; i < replacements.length; i++) + if (replacements[i].getVersion().compareTo( + repl.getVersion()) > 0) + repl = replacements[i]; + replacementIUs.add(repl); + } + } + } + // Did we find any updates? + if (iusWithUpdates.size() == 0) { + sub.done(); + } else { + if (sub.isCanceled()) + throw new InterruptedException(); + // Build a profile change request + ProfileChangeRequest changeRequest = new ProfileChangeRequest( + profile); + changeRequest + .removeInstallableUnits((IInstallableUnit[]) iusWithUpdates + .toArray(new IInstallableUnit[iusWithUpdates + .size()])); + changeRequest + .addInstallableUnits((IInstallableUnit[]) iusWithUpdates + .toArray(new IInstallableUnit[iusWithUpdates + .size()])); + ProvisioningPlan plan = planner.getProvisioningPlan( + changeRequest, pc, sub.newChild(100)); + if (plan.getStatus().getSeverity() == IStatus.CANCEL) + throw new InterruptedException(); + if (plan.getStatus().getSeverity() != IStatus.ERROR) { + IEngine engine = (IEngine) ServiceHelper.getService( + Activator.bundleContext, IEngine.class + .getName()); + IArtifactRepositoryManager artifactMgr = (IArtifactRepositoryManager) ServiceHelper + .getService(Activator.bundleContext, + IArtifactRepositoryManager.class + .getName()); + if (engine != null && artifactMgr != null) { + pc + .setArtifactRepositories(artifactMgr + .getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL)); + IStatus status = engine.perform(profile, + new DefaultPhaseSet(), plan.getOperands(), + pc, sub.newChild(100)); + if (status.getSeverity() == IStatus.CANCEL) + throw new InterruptedException(); + if (status.getSeverity() != IStatus.ERROR) { + didWeUpdate[0] = true; + } + } + } + } + } + }; + try { + new ProgressMonitorDialog(null).run(true, true, runnable); + } catch (InvocationTargetException e) { + e.printStackTrace(); + return false; + } catch (InterruptedException e) { + return false; + } + return didWeUpdate[0]; + } +} diff --git a/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/ApplicationActionBarAdvisor.java b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/ApplicationActionBarAdvisor.java new file mode 100644 index 000000000..68f0ad7c4 --- /dev/null +++ b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/ApplicationActionBarAdvisor.java @@ -0,0 +1,91 @@ +package org.eclipse.equinox.p2.examples.rcp.prestartupdate; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.GroupMarker; +import org.eclipse.jface.action.ICoolBarManager; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.action.ToolBarContributionItem; +import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.swt.SWT; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.actions.ActionFactory; +import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction; +import org.eclipse.ui.application.ActionBarAdvisor; +import org.eclipse.ui.application.IActionBarConfigurer; + +/** + * An action bar advisor is responsible for creating, adding, and disposing of the + * actions added to a workbench window. Each window will be populated with + * new actions. + */ +public class ApplicationActionBarAdvisor extends ActionBarAdvisor { + + // Actions - important to allocate these only in makeActions, and then use them + // in the fill methods. This ensures that the actions aren't recreated + // when fillActionBars is called with FILL_PROXY. + private IWorkbenchAction exitAction; + private IWorkbenchAction aboutAction; + private IWorkbenchAction newWindowAction; + private OpenViewAction openViewAction; + private Action messagePopupAction; + + + public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) { + super(configurer); + } + + protected void makeActions(final IWorkbenchWindow window) { + // Creates the actions and registers them. + // Registering is needed to ensure that key bindings work. + // The corresponding commands keybindings are defined in the plugin.xml file. + // Registering also provides automatic disposal of the actions when + // the window is closed. + + exitAction = ActionFactory.QUIT.create(window); + register(exitAction); + + aboutAction = ActionFactory.ABOUT.create(window); + register(aboutAction); + + newWindowAction = ActionFactory.OPEN_NEW_WINDOW.create(window); + register(newWindowAction); + + openViewAction = new OpenViewAction(window, "Open Another Message View", View.ID); + register(openViewAction); + + messagePopupAction = new MessagePopupAction("Open Message", window); + register(messagePopupAction); + } + + protected void fillMenuBar(IMenuManager menuBar) { + MenuManager fileMenu = new MenuManager("&File", IWorkbenchActionConstants.M_FILE); + MenuManager helpMenu = new MenuManager("&Help", IWorkbenchActionConstants.M_HELP); + + menuBar.add(fileMenu); + // Add a group marker indicating where action set menus will appear. + menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); + menuBar.add(helpMenu); + + // File + fileMenu.add(newWindowAction); + fileMenu.add(new Separator()); + fileMenu.add(messagePopupAction); + fileMenu.add(openViewAction); + fileMenu.add(new Separator()); + fileMenu.add(exitAction); + + // Help + helpMenu.add(aboutAction); + } + + protected void fillCoolBar(ICoolBarManager coolBar) { + IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT); + coolBar.add(new ToolBarContributionItem(toolbar, "main")); + toolbar.add(openViewAction); + toolbar.add(messagePopupAction); + } +} diff --git a/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/ApplicationWorkbenchAdvisor.java b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/ApplicationWorkbenchAdvisor.java new file mode 100644 index 000000000..d27729b67 --- /dev/null +++ b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/ApplicationWorkbenchAdvisor.java @@ -0,0 +1,21 @@ +package org.eclipse.equinox.p2.examples.rcp.prestartupdate; + +import org.eclipse.ui.application.IWorkbenchWindowConfigurer; +import org.eclipse.ui.application.WorkbenchAdvisor; +import org.eclipse.ui.application.WorkbenchWindowAdvisor; + +/** + * This workbench advisor creates the window advisor, and specifies + * the perspective id for the initial window. + */ +public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor { + + public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) { + return new ApplicationWorkbenchWindowAdvisor(configurer); + } + + public String getInitialWindowPerspectiveId() { + return Perspective.ID; + } + +} diff --git a/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/ApplicationWorkbenchWindowAdvisor.java b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/ApplicationWorkbenchWindowAdvisor.java new file mode 100644 index 000000000..2bb795ccd --- /dev/null +++ b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/ApplicationWorkbenchWindowAdvisor.java @@ -0,0 +1,26 @@ +package org.eclipse.equinox.p2.examples.rcp.prestartupdate; + +import org.eclipse.swt.graphics.Point; +import org.eclipse.ui.application.ActionBarAdvisor; +import org.eclipse.ui.application.IActionBarConfigurer; +import org.eclipse.ui.application.IWorkbenchWindowConfigurer; +import org.eclipse.ui.application.WorkbenchWindowAdvisor; + +public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { + + public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) { + super(configurer); + } + + public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) { + return new ApplicationActionBarAdvisor(configurer); + } + + public void preWindowOpen() { + IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); + configurer.setInitialSize(new Point(600, 400)); + configurer.setShowCoolBar(true); + configurer.setShowStatusLine(false); + } + +} diff --git a/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/ICommandIds.java b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/ICommandIds.java new file mode 100644 index 000000000..42a745511 --- /dev/null +++ b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/ICommandIds.java @@ -0,0 +1,15 @@ +package org.eclipse.equinox.p2.examples.rcp.prestartupdate; + +/** + * Interface defining the application's command IDs. + * Key bindings can be defined for specific commands. + * To associate an action with a command, use IAction.setActionDefinitionId(commandId). + * + * @see org.eclipse.jface.action.IAction#setActionDefinitionId(String) + */ +public interface ICommandIds { + + public static final String CMD_OPEN = "org.eclipse.equinox.p2.examples.rcp.prestartupdate.open"; + public static final String CMD_OPEN_MESSAGE = "org.eclipse.equinox.p2.examples.rcp.prestartupdate.openMessage"; + +} diff --git a/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/MessagePopupAction.java b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/MessagePopupAction.java new file mode 100644 index 000000000..2eb2ca93d --- /dev/null +++ b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/MessagePopupAction.java @@ -0,0 +1,25 @@ +package org.eclipse.equinox.p2.examples.rcp.prestartupdate; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.ui.IWorkbenchWindow; + + +public class MessagePopupAction extends Action { + + private final IWorkbenchWindow window; + + MessagePopupAction(String text, IWorkbenchWindow window) { + super(text); + this.window = window; + // The id is used to refer to the action in a menu or toolbar + setId(ICommandIds.CMD_OPEN_MESSAGE); + // Associate the action with a pre-defined command, to allow key bindings. + setActionDefinitionId(ICommandIds.CMD_OPEN_MESSAGE); + setImageDescriptor(org.eclipse.equinox.p2.examples.rcp.prestartupdate.Activator.getImageDescriptor("/icons/sample3.gif")); + } + + public void run() { + MessageDialog.openInformation(window.getShell(), "Open", "Open Message Dialog!"); + } +}
\ No newline at end of file diff --git a/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/NavigationView.java b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/NavigationView.java new file mode 100644 index 000000000..77f69a28d --- /dev/null +++ b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/NavigationView.java @@ -0,0 +1,151 @@ +package org.eclipse.equinox.p2.examples.rcp.prestartupdate; + +import java.util.ArrayList; + +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.part.ViewPart; + +public class NavigationView extends ViewPart { + public static final String ID = "org.eclipse.equinox.p2.examples.rcp.prestartupdate.navigationView"; + private TreeViewer viewer; + + class TreeObject { + private String name; + private TreeParent parent; + + public TreeObject(String name) { + this.name = name; + } + public String getName() { + return name; + } + public void setParent(TreeParent parent) { + this.parent = parent; + } + public TreeParent getParent() { + return parent; + } + public String toString() { + return getName(); + } + } + + class TreeParent extends TreeObject { + private ArrayList children; + public TreeParent(String name) { + super(name); + children = new ArrayList(); + } + public void addChild(TreeObject child) { + children.add(child); + child.setParent(this); + } + public void removeChild(TreeObject child) { + children.remove(child); + child.setParent(null); + } + public TreeObject[] getChildren() { + return (TreeObject[]) children.toArray(new TreeObject[children.size()]); + } + public boolean hasChildren() { + return children.size()>0; + } + } + + class ViewContentProvider implements IStructuredContentProvider, + ITreeContentProvider { + + public void inputChanged(Viewer v, Object oldInput, Object newInput) { + } + + public void dispose() { + } + + public Object[] getElements(Object parent) { + return getChildren(parent); + } + + public Object getParent(Object child) { + if (child instanceof TreeObject) { + return ((TreeObject)child).getParent(); + } + return null; + } + + public Object[] getChildren(Object parent) { + if (parent instanceof TreeParent) { + return ((TreeParent)parent).getChildren(); + } + return new Object[0]; + } + + public boolean hasChildren(Object parent) { + if (parent instanceof TreeParent) + return ((TreeParent)parent).hasChildren(); + return false; + } + } + + class ViewLabelProvider extends LabelProvider { + + public String getText(Object obj) { + return obj.toString(); + } + public Image getImage(Object obj) { + String imageKey = ISharedImages.IMG_OBJ_ELEMENT; + if (obj instanceof TreeParent) + imageKey = ISharedImages.IMG_OBJ_FOLDER; + return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey); + } + } + + /** + * We will set up a dummy model to initialize tree heararchy. In real + * code, you will connect to a real model and expose its hierarchy. + */ + private TreeObject createDummyModel() { + TreeObject to1 = new TreeObject("Inbox"); + TreeObject to2 = new TreeObject("Drafts"); + TreeObject to3 = new TreeObject("Sent"); + TreeParent p1 = new TreeParent("me@this.com"); + p1.addChild(to1); + p1.addChild(to2); + p1.addChild(to3); + + TreeObject to4 = new TreeObject("Inbox"); + TreeParent p2 = new TreeParent("other@aol.com"); + p2.addChild(to4); + + TreeParent root = new TreeParent(""); + root.addChild(p1); + root.addChild(p2); + return root; + } + + /** + * This is a callback that will allow us to create the viewer and initialize + * it. + */ + public void createPartControl(Composite parent) { + viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); + viewer.setContentProvider(new ViewContentProvider()); + viewer.setLabelProvider(new ViewLabelProvider()); + viewer.setInput(createDummyModel()); + } + + /** + * Passing the focus request to the viewer's control. + */ + public void setFocus() { + viewer.getControl().setFocus(); + } +}
\ No newline at end of file diff --git a/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/OpenViewAction.java b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/OpenViewAction.java new file mode 100644 index 000000000..b741fa946 --- /dev/null +++ b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/OpenViewAction.java @@ -0,0 +1,36 @@ +package org.eclipse.equinox.p2.examples.rcp.prestartupdate; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PartInitException; + + +public class OpenViewAction extends Action { + + private final IWorkbenchWindow window; + private int instanceNum = 0; + private final String viewId; + + public OpenViewAction(IWorkbenchWindow window, String label, String viewId) { + this.window = window; + this.viewId = viewId; + setText(label); + // The id is used to refer to the action in a menu or toolbar + setId(ICommandIds.CMD_OPEN); + // Associate the action with a pre-defined command, to allow key bindings. + setActionDefinitionId(ICommandIds.CMD_OPEN); + setImageDescriptor(org.eclipse.equinox.p2.examples.rcp.prestartupdate.Activator.getImageDescriptor("/icons/sample2.gif")); + } + + public void run() { + if(window != null) { + try { + window.getActivePage().showView(viewId, Integer.toString(instanceNum++), IWorkbenchPage.VIEW_ACTIVATE); + } catch (PartInitException e) { + MessageDialog.openError(window.getShell(), "Error", "Error opening view:" + e.getMessage()); + } + } + } +} diff --git a/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/Perspective.java b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/Perspective.java new file mode 100644 index 000000000..244eca03c --- /dev/null +++ b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/Perspective.java @@ -0,0 +1,25 @@ +package org.eclipse.equinox.p2.examples.rcp.prestartupdate; + +import org.eclipse.ui.IFolderLayout; +import org.eclipse.ui.IPageLayout; +import org.eclipse.ui.IPerspectiveFactory; + +public class Perspective implements IPerspectiveFactory { + + /** + * The ID of the perspective as specified in the extension. + */ + public static final String ID = "org.eclipse.equinox.p2.examples.rcp.prestartupdate.perspective"; + + public void createInitialLayout(IPageLayout layout) { + String editorArea = layout.getEditorArea(); + layout.setEditorAreaVisible(false); + + layout.addStandaloneView(NavigationView.ID, false, IPageLayout.LEFT, 0.25f, editorArea); + IFolderLayout folder = layout.createFolder("messages", IPageLayout.TOP, 0.5f, editorArea); + folder.addPlaceholder(View.ID + ":*"); + folder.addView(View.ID); + + layout.getViewLayout(NavigationView.ID).setCloseable(false); + } +} diff --git a/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/View.java b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/View.java new file mode 100644 index 000000000..38be31690 --- /dev/null +++ b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/View.java @@ -0,0 +1,77 @@ +package org.eclipse.equinox.p2.examples.rcp.prestartupdate; + +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Link; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.part.ViewPart; + +public class View extends ViewPart { + + public static final String ID = "org.eclipse.equinox.p2.examples.rcp.prestartupdate.view"; + + public void createPartControl(Composite parent) { + Composite top = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + top.setLayout(layout); + // top banner + Composite banner = new Composite(top, SWT.NONE); + banner.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL, GridData.VERTICAL_ALIGN_BEGINNING, true, false)); + layout = new GridLayout(); + layout.marginHeight = 5; + layout.marginWidth = 10; + layout.numColumns = 2; + banner.setLayout(layout); + + // setup bold font + Font boldFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT); + + Label l = new Label(banner, SWT.WRAP); + l.setText("Subject:"); + l.setFont(boldFont); + l = new Label(banner, SWT.WRAP); + l.setText("This is a message about the cool Eclipse RCP!"); + + l = new Label(banner, SWT.WRAP); + l.setText("From:"); + l.setFont(boldFont); + + final Link link = new Link(banner, SWT.NONE); + link.setText("<a>nicole@mail.org</a>"); + link.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + MessageDialog.openInformation(getSite().getShell(), "Not Implemented", "Imagine the address book or a new message being created now."); + } + }); + + l = new Label(banner, SWT.WRAP); + l.setText("Date:"); + l.setFont(boldFont); + l = new Label(banner, SWT.WRAP); + l.setText("10:34 am"); + // message contents + Text text = new Text(top, SWT.MULTI | SWT.WRAP); + text.setText("This RCP Application was generated from the PDE Plug-in Project wizard. This sample shows how to:\n"+ + "- add a top-level menu and toolbar with actions\n"+ + "- add keybindings to actions\n" + + "- create views that can't be closed and\n"+ + " multiple instances of the same view\n"+ + "- perspectives with placeholders for new views\n"+ + "- use the default about dialog\n"+ + "- create a product definition\n"); + text.setLayoutData(new GridData(GridData.FILL_BOTH)); + } + + public void setFocus() { + } +} |