--- a/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/discovery/ui/view/DiscoveryView.java Fri May 14 14:08:20 2010 -0500
+++ b/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/discovery/ui/view/DiscoveryView.java Mon May 17 08:52:30 2010 -0500
@@ -1,14 +1,10 @@
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;
@@ -17,18 +13,12 @@
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
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;
@@ -59,7 +49,7 @@
*/
@SuppressWarnings("restriction")
-public class DiscoveryView extends ViewPart implements ISelectionChangedListener {
+public class DiscoveryView extends ViewPart {
/**
* The ID of the view as specified by the extension.
@@ -70,10 +60,9 @@
private Action refreshAction;
private BaseSelectionListenerAction selectAllAction;
private BaseSelectionListenerAction selectNoneAction;
+ private BaseSelectionListenerAction installAction;
- private boolean updated;
-
- private Button installButton;
+ private boolean initialized;
public DiscoveryView() {
}
@@ -89,29 +78,12 @@
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);
@@ -124,17 +96,12 @@
catalog.setVerifyUpdateSiteAvailability(false);
// look for descriptors from installed bundles
- catalog.getDiscoveryStrategies().add(new BundleDiscoveryStrategy());
+// 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);
+ remoteDiscoveryStrategy.setDirectoryUrl("http://daaus001.americas.nokia.com/carbide/public/updates/3.0");
+ catalog.getDiscoveryStrategies().add(remoteDiscoveryStrategy);
return catalog;
}
@@ -152,12 +119,13 @@
private void fillLocalToolBar(IToolBarManager manager) {
manager.add(refreshAction);
+ manager.add(installAction);
}
private void makeActions() {
refreshAction = new Action() {
public void run() {
- viewer.refresh();
+ viewer.updateCatalog();
}
};
refreshAction.setText("Refresh");
@@ -169,23 +137,10 @@
}
private IStructuredSelection getAllItemsSelection() {
- Object[] elements = getAllCatalogItems();
- IStructuredSelection allItemsSelection = new StructuredSelection(elements);
- return allItemsSelection;
+ List<CatalogItem> catalogItems = viewer.getCatalog().getItems();
+ return new StructuredSelection(catalogItems);
}
- private Object[] getAllCatalogItems() {
- List<Object> catalogItems = new ArrayList<Object>();
- 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);
};
@@ -200,15 +155,27 @@
return !selection.isEmpty();
};
};
+ installAction = new BaseSelectionListenerAction("Install Checked Items...") {
+ public void run() {
+ DiscoveryUi.install(viewer.getCheckedItems(), new ProgressMonitorDialog(DiscoveryView.this.getViewSite().getShell()));
+ };
+
+ protected boolean updateSelection(IStructuredSelection selection) {
+ return !selection.isEmpty();
+ };
+ };
+ installAction.setImageDescriptor(Activator.getImageDescriptor("icons/icon-discovery.png"));
viewer.addSelectionChangedListener(selectAllAction);
viewer.addSelectionChangedListener(selectNoneAction);
+ viewer.addSelectionChangedListener(installAction);
}
@Override
public void dispose() {
viewer.removeSelectionChangedListener(selectAllAction);
viewer.removeSelectionChangedListener(selectNoneAction);
- viewer.removeSelectionChangedListener(this);
+ viewer.removeSelectionChangedListener(installAction);
+
super.dispose();
}
@@ -216,19 +183,15 @@
* Passing the focus request to the viewer's control.
*/
public void setFocus() {
- updateCatalog();
- }
-
- private void updateCatalog() {
- if (!updated) {
- updated = true;
+ if (!initialized) {
+ initialized = true;
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
viewer.updateCatalog();
+ viewer.setSelection(StructuredSelection.EMPTY);
}
});
}
}
-
}
\ No newline at end of file