# HG changeset patch # User dadubrow # Date 1273864100 18000 # Node ID b609311b7b1c79ffb175f254a0b4e5903ff2c705 # Parent d927acd507a60724ef8e71cf185733b1e577a5f9 initial commit diff -r d927acd507a6 -r b609311b7b1c core/com.nokia.carbide.discovery.ui/.classpath --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/com.nokia.carbide.discovery.ui/.classpath Fri May 14 14:08:20 2010 -0500 @@ -0,0 +1,7 @@ + + + + + + + diff -r d927acd507a6 -r b609311b7b1c core/com.nokia.carbide.discovery.ui/.project --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/com.nokia.carbide.discovery.ui/.project Fri May 14 14:08:20 2010 -0500 @@ -0,0 +1,28 @@ + + + com.nokia.carbide.discovery.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff -r d927acd507a6 -r b609311b7b1c core/com.nokia.carbide.discovery.ui/.settings/org.eclipse.jdt.core.prefs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/com.nokia.carbide.discovery.ui/.settings/org.eclipse.jdt.core.prefs Fri May 14 14:08:20 2010 -0500 @@ -0,0 +1,8 @@ +#Mon Mar 22 09:12:01 CDT 2010 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff -r d927acd507a6 -r b609311b7b1c core/com.nokia.carbide.discovery.ui/META-INF/MANIFEST.MF --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/com.nokia.carbide.discovery.ui/META-INF/MANIFEST.MF Fri May 14 14:08:20 2010 -0500 @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: DiscoveryUI +Bundle-SymbolicName: com.nokia.carbide.discovery.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: com.nokia.carbide.discovery.ui.Activator +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.equinox.p2.discovery;bundle-version="1.0.0", + org.eclipse.equinox.p2.discovery.compatibility;bundle-version="1.0.0", + org.eclipse.equinox.p2.ui.discovery;bundle-version="1.0.0", + org.eclipse.equinox.p2.ui;bundle-version="2.0.0" +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-Vendor: Nokia diff -r d927acd507a6 -r b609311b7b1c core/com.nokia.carbide.discovery.ui/build.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/com.nokia.carbide.discovery.ui/build.properties Fri May 14 14:08:20 2010 -0500 @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + icons/,\ + contexts.xml diff -r d927acd507a6 -r b609311b7b1c core/com.nokia.carbide.discovery.ui/contexts.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/com.nokia.carbide.discovery.ui/contexts.xml Fri May 14 14:08:20 2010 -0500 @@ -0,0 +1,12 @@ + + + This is the context help for the sample view with a table viewer. It was generated by a PDE template. + + + + + + + + + diff -r d927acd507a6 -r b609311b7b1c core/com.nokia.carbide.discovery.ui/icons/banner-discovery.png Binary file core/com.nokia.carbide.discovery.ui/icons/banner-discovery.png has changed diff -r d927acd507a6 -r b609311b7b1c core/com.nokia.carbide.discovery.ui/icons/icon-discovery.png Binary file core/com.nokia.carbide.discovery.ui/icons/icon-discovery.png has changed diff -r d927acd507a6 -r b609311b7b1c core/com.nokia.carbide.discovery.ui/icons/refresh.gif Binary file core/com.nokia.carbide.discovery.ui/icons/refresh.gif has changed diff -r d927acd507a6 -r b609311b7b1c core/com.nokia.carbide.discovery.ui/plugin.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/com.nokia.carbide.discovery.ui/plugin.xml Fri May 14 14:08:20 2010 -0500 @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + diff -r d927acd507a6 -r b609311b7b1c core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/discovery/ui/Activator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/discovery/ui/Activator.java Fri May 14 14:08:20 2010 -0500 @@ -0,0 +1,60 @@ +package com.nokia.carbide.discovery.ui; + +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 = "com.nokia.carbide.discovery.ui"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * 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; + } + + /* + * (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 -r d927acd507a6 -r b609311b7b1c core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/discovery/ui/view/DiscoveryView.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/discovery/ui/view/DiscoveryView.java Fri May 14 14:08:20 2010 -0500 @@ -0,0 +1,234 @@ +package com.nokia.carbide.discovery.ui.view; + + +import java.io.File; +import java.net.MalformedURLException; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.equinox.internal.p2.discovery.Catalog; +import org.eclipse.equinox.internal.p2.discovery.DiscoveryCore; +import org.eclipse.equinox.internal.p2.discovery.compatibility.BundleDiscoveryStrategy; +import org.eclipse.equinox.internal.p2.discovery.compatibility.RemoteBundleDiscoveryStrategy; +import org.eclipse.equinox.internal.p2.discovery.model.CatalogItem; +import org.eclipse.equinox.internal.p2.ui.discovery.DiscoveryUi; +import org.eclipse.equinox.internal.p2.ui.discovery.wizards.CatalogConfiguration; +import org.eclipse.equinox.internal.p2.ui.discovery.wizards.CatalogViewer; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.actions.BaseSelectionListenerAction; +import org.eclipse.ui.part.ViewPart; + +import com.nokia.carbide.discovery.ui.Activator; + + + +/** + * This sample class demonstrates how to plug-in a new + * workbench view. The view shows data obtained from the + * model. The sample creates a dummy model on the fly, + * but a real implementation would connect to the model + * available either in this or another plug-in (e.g. the workspace). + * The view is connected to the model using a content provider. + *

+ * The view uses a label provider to define how model + * objects should be presented in the view. Each + * view can present the same model objects using + * different labels and icons, if needed. Alternatively, + * a single label provider can be shared between views + * in order to ensure that objects of the same type are + * presented in the same way everywhere. + *

+ */ + +@SuppressWarnings("restriction") +public class DiscoveryView extends ViewPart implements ISelectionChangedListener { + + /** + * The ID of the view as specified by the extension. + */ + public static final String ID = "testdiscovery.views.TestView"; + + private CatalogViewer viewer; + private Action refreshAction; + private BaseSelectionListenerAction selectAllAction; + private BaseSelectionListenerAction selectNoneAction; + + private boolean updated; + + private Button installButton; + + public DiscoveryView() { + } + + /** + * This is a callback that will allow us + * to create the viewer and initialize it. + */ + public void createPartControl(Composite parent) { + Composite c = new Composite(parent, SWT.NONE); + GridLayoutFactory.fillDefaults().applyTo(c); + viewer = new CatalogViewer(getCatalog(), getSite(), getSite().getWorkbenchWindow(), getConfiguration()); + viewer.createControl(c); + GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getControl()); + + installButton = new Button(c, SWT.PUSH); + installButton.setText("Install Checked Items..."); + ImageDescriptor imgDesc = Activator.getImageDescriptor("icons/icon-discovery.png"); + installButton.setImage(imgDesc.createImage()); + installButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + DiscoveryUi.install(viewer.getCheckedItems(), getSite().getWorkbenchWindow()); + } + }); + viewer.addSelectionChangedListener(this); + + // Create the help context id for the viewer's control + PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "TestDiscovery.viewer"); + makeActions(); + contributeToActionBars(); + } + + @Override + public void selectionChanged(SelectionChangedEvent event) { + installButton.setEnabled(!event.getSelection().isEmpty()); + } + + private CatalogConfiguration getConfiguration() { + CatalogConfiguration configuration = new CatalogConfiguration(); + configuration.setShowTagFilter(false); + return configuration; + } + + private Catalog getCatalog() { + Catalog catalog = new Catalog(); + catalog.setEnvironment(DiscoveryCore.createEnvironment()); + catalog.setVerifyUpdateSiteAvailability(false); + + // look for descriptors from installed bundles + catalog.getDiscoveryStrategies().add(new BundleDiscoveryStrategy()); + + // look for remote descriptor + RemoteBundleDiscoveryStrategy remoteDiscoveryStrategy = new RemoteBundleDiscoveryStrategy(); + File f = new File("D:\\Users\\Discovery\\discovery.xml"); + try { + remoteDiscoveryStrategy.setDirectoryUrl(f.toURI().toURL().toExternalForm()); + } catch (MalformedURLException e) { + throw new IllegalArgumentException(e); + } +// catalog.getDiscoveryStrategies().add(remoteDiscoveryStrategy); + + return catalog; + } + + private void contributeToActionBars() { + IActionBars bars = getViewSite().getActionBars(); + fillLocalPullDown(bars.getMenuManager()); + fillLocalToolBar(bars.getToolBarManager()); + } + + private void fillLocalPullDown(IMenuManager manager) { + manager.add(selectAllAction); + manager.add(selectNoneAction); + } + + private void fillLocalToolBar(IToolBarManager manager) { + manager.add(refreshAction); + } + + private void makeActions() { + refreshAction = new Action() { + public void run() { + viewer.refresh(); + } + }; + refreshAction.setText("Refresh"); + refreshAction.setImageDescriptor(Activator.getImageDescriptor("icons/refresh.gif")); + selectAllAction = new BaseSelectionListenerAction("Select All Items") { + public void run() { + viewer.setSelection(getAllItemsSelection()); + viewer.refresh(); + } + + private IStructuredSelection getAllItemsSelection() { + Object[] elements = getAllCatalogItems(); + IStructuredSelection allItemsSelection = new StructuredSelection(elements); + return allItemsSelection; + } + + private Object[] getAllCatalogItems() { + List catalogItems = new ArrayList(); + IStructuredContentProvider provider = + (IStructuredContentProvider) viewer.getViewer().getContentProvider(); + Object[] elements = provider.getElements(viewer.getViewer().getInput()); + for (Object item : elements) { + if (item instanceof CatalogItem) + catalogItems.add(item); + } + return catalogItems.toArray(); + }; + + protected boolean updateSelection(IStructuredSelection selection) { + return !getAllItemsSelection().equals(selection); + }; + }; + selectNoneAction = new BaseSelectionListenerAction("Deselect All Items") { + public void run() { + viewer.setSelection(StructuredSelection.EMPTY); + viewer.refresh(); + }; + + protected boolean updateSelection(IStructuredSelection selection) { + return !selection.isEmpty(); + }; + }; + viewer.addSelectionChangedListener(selectAllAction); + viewer.addSelectionChangedListener(selectNoneAction); + } + + @Override + public void dispose() { + viewer.removeSelectionChangedListener(selectAllAction); + viewer.removeSelectionChangedListener(selectNoneAction); + viewer.removeSelectionChangedListener(this); + super.dispose(); + } + + /** + * Passing the focus request to the viewer's control. + */ + public void setFocus() { + updateCatalog(); + } + + private void updateCatalog() { + if (!updated) { + updated = true; + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + viewer.updateCatalog(); + } + }); + } + } + +} \ No newline at end of file