# HG changeset patch # User dadubrow # Date 1280175070 18000 # Node ID c2eba6dabd384995f31d0b7e9a5bbb76f6ccd864 # Parent 4dbd593daf6d53d004edbccef23f88adf060b8d3 refactor to allow better support for multiple layers diff -r 4dbd593daf6d -r c2eba6dabd38 core/com.nokia.carbide.discovery.ui/plugin.xml --- a/core/com.nokia.carbide.discovery.ui/plugin.xml Fri Jul 23 15:40:47 2010 -0500 +++ b/core/com.nokia.carbide.discovery.ui/plugin.xml Mon Jul 26 15:11:10 2010 -0500 @@ -2,6 +2,7 @@ + - - - - diff -r 4dbd593daf6d -r c2eba6dabd38 core/com.nokia.carbide.discovery.ui/schema/portalPage.exsd --- a/core/com.nokia.carbide.discovery.ui/schema/portalPage.exsd Fri Jul 23 15:40:47 2010 -0500 +++ b/core/com.nokia.carbide.discovery.ui/schema/portalPage.exsd Mon Jul 26 15:11:10 2010 -0500 @@ -18,7 +18,7 @@ - + @@ -49,20 +49,27 @@ - + - + - + - relative ordering of pages in the navigation bar (1-100) + relative ordering of pages in the navigation bar (integer used to sort pages) + + + + + + + identifier for the page - required for multi-layer pages diff -r 4dbd593daf6d -r c2eba6dabd38 core/com.nokia.carbide.discovery.ui/schema/portalPageLayer.exsd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/com.nokia.carbide.discovery.ui/schema/portalPageLayer.exsd Mon Jul 26 15:11:10 2010 -0500 @@ -0,0 +1,116 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + relative ordering of layers in a page navigation bar (integer used to sort layers) + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff -r 4dbd593daf6d -r c2eba6dabd38 core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/editor/ActionUIUpdater.java --- a/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/editor/ActionUIUpdater.java Fri Jul 23 15:40:47 2010 -0500 +++ b/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/editor/ActionUIUpdater.java Mon Jul 26 15:11:10 2010 -0500 @@ -19,7 +19,7 @@ import java.util.ArrayList; import java.util.List; -import com.nokia.carbide.internal.discovery.ui.extension.IPortalPage.IActionUIUpdater; +import com.nokia.carbide.internal.discovery.ui.extension.IPortalExtension.IActionUIUpdater; class ActionUIUpdater implements IActionUIUpdater { diff -r 4dbd593daf6d -r c2eba6dabd38 core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/editor/NavigationBar.java --- a/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/editor/NavigationBar.java Fri Jul 23 15:40:47 2010 -0500 +++ b/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/editor/NavigationBar.java Mon Jul 26 15:11:10 2010 -0500 @@ -32,8 +32,6 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import com.nokia.carbide.internal.discovery.ui.extension.IPortalPage; - class NavigationBar extends RoundedCornerComposite { private PortalEditor portalEditor; @@ -47,7 +45,7 @@ } } - private Map buttonToPageMap; + private Map buttonToPageMap; private SelectionListener listener; private Font buttonFont; private Font selectedButtonFont; @@ -57,7 +55,7 @@ parent.getDisplay().getSystemColor(SWT.COLOR_BLACK), parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); this.portalEditor = portalEditor; - buttonToPageMap = new LinkedHashMap(); + buttonToPageMap = new LinkedHashMap(); RowLayoutFactory.swtDefaults().margins(3, 3).wrap(false).applyTo(this); listener = new ButtonListener(); selectedButtonFont = JFaceResources.getHeaderFont(); @@ -75,11 +73,11 @@ selectNavButton(buttonToPageMap.keySet().iterator().next()); } - public void addNavButton(NavigationBar bar, IPortalPage page) { + public void addNavButton(NavigationBar bar, PortalPage page) { Button b = new Button(bar, SWT.TOGGLE | SWT.FLAT); b.setFont(buttonFont); - b.setText(page.getText()); - b.setImage(portalEditor.createImage(page.getImageDescriptor(), 16, 16)); + b.setText(page.getPortalExtension().getText()); + b.setImage(portalEditor.createImage(page.getPortalExtension().getImageDescriptor(), 16, 16)); b.addSelectionListener(listener); RowDataFactory.swtDefaults().applyTo(b); buttonToPageMap.put(b, page); diff -r 4dbd593daf6d -r c2eba6dabd38 core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/editor/PortalEditor.java --- a/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/editor/PortalEditor.java Fri Jul 23 15:40:47 2010 -0500 +++ b/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/editor/PortalEditor.java Mon Jul 26 15:11:10 2010 -0500 @@ -20,9 +20,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; @@ -45,6 +43,7 @@ import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorSite; import org.eclipse.ui.IPersistableElement; import org.eclipse.ui.PartInitException; @@ -53,64 +52,63 @@ import com.nokia.carbide.discovery.ui.Activator; import com.nokia.carbide.discovery.ui.Messages; -import com.nokia.carbide.internal.discovery.ui.extension.IPortalPage; -import com.nokia.carbide.internal.discovery.ui.extension.IPortalPage.IActionBar; +import com.nokia.carbide.internal.discovery.ui.extension.IPortalEditor; +import com.nokia.carbide.internal.discovery.ui.extension.IPortalExtension; +import com.nokia.carbide.internal.discovery.ui.extension.IPortalExtension.IActionBar; import com.nokia.cpp.internal.api.utils.core.Pair; import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils; -public class PortalEditor extends EditorPart { +public class PortalEditor extends EditorPart implements IPortalEditor { private static final String ID = "com.nokia.carbide.discovery.ui.portalEditor"; //$NON-NLS-1$ private static final String CONTEXT_ID = ID + ".context"; //$NON-NLS-1$ private static IEditorInput input; - private List uninitializedPages; + private List pages; private Composite backgroundParent; private Image oldBGImg; private List resources; private StackComposite stackComposite; - - private Map pageToControlMap; private NavigationBar navigationBar; public PortalEditor() { resources = new ArrayList(); loadPortalPages(); - pageToControlMap = new HashMap(); } private void loadPortalPages() { - List> pageExtensions = new ArrayList>(); + List> pageList = new ArrayList>(); IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(Activator.PLUGIN_ID + ".portalPage"); //$NON-NLS-1$ for (IConfigurationElement element : elements) { try { - IPortalPage portalPage = (IPortalPage) element.createExecutableExtension("class"); //$NON-NLS-1$ - String rankString = element.getAttribute("rank"); //$NON-NLS-1$ - int rank = Integer.MAX_VALUE; - if (rankString != null) { + IPortalExtension portalExtension = (IPortalExtension) element.createExecutableExtension("class"); //$NON-NLS-1$ + String id = element.getAttribute("id"); //$NON-NLS-1$ + String orderString = element.getAttribute("order"); //$NON-NLS-1$ + int order = Integer.MAX_VALUE; + if (orderString != null) { try { - rank = Integer.parseInt(rankString); + order = Integer.parseInt(orderString); } catch (NumberFormatException e) { Activator.logError(MessageFormat.format(Messages.PortalEditor_PageRankError, - portalPage.getClass().getName()), e); + portalExtension.getClass().getName()), e); } } - pageExtensions.add(new Pair(portalPage, rank)); + pageList.add(new Pair(new PortalPage(portalExtension, id), order)); } catch (CoreException e) { Activator.logError(Messages.PortalEditor_PageLoadError, e); } } - Collections.sort(pageExtensions, new Comparator>() { + Collections.sort(pageList, new Comparator>() { @Override - public int compare(Pair o1, Pair o2) { + public int compare(Pair o1, Pair o2) { return o1.second.compareTo(o2.second); } }); - uninitializedPages = new ArrayList(); - for (Pair pair : pageExtensions) { - uninitializedPages.add(pair.first); + pages = new ArrayList(); + for (Pair pair : pageList) { + pages.add(pair.first); } } @@ -151,7 +149,7 @@ backgroundParent = new Composite(parent, SWT.NONE); applyBG(backgroundParent); GridLayoutFactory.fillDefaults().applyTo(backgroundParent); - // create top naviation bar + // create top navigation bar navigationBar = createNavigationBar(backgroundParent); GridDataFactory.swtDefaults().grab(true, false).align(SWT.CENTER, SWT.TOP).indent(10, 10).applyTo(navigationBar); // create stack composite @@ -161,14 +159,13 @@ private void createStackComposite(Composite parent, NavigationBar bar) { stackComposite = new StackComposite(parent, backgroundParent); - for (IPortalPage page : uninitializedPages) { - Control control = createPage(page); - pageToControlMap.put(page, control); + for (PortalPage page : pages) { + page.setControl(createPage(page.getPortalExtension())); } GridDataFactory.fillDefaults().grab(true, true).applyTo(stackComposite); } - private Control createPage(IPortalPage page) { + private Control createPage(IPortalExtension page) { Composite pageComposite = new SharedBackgroundComposite(stackComposite, backgroundParent); GridLayoutFactory.fillDefaults().numColumns(2).spacing(20, 0).extendedMargins(20, 20, 20, 0).applyTo(pageComposite); ActionUIUpdater updater = new ActionUIUpdater(); @@ -199,19 +196,18 @@ private NavigationBar createNavigationBar(Composite parent) { NavigationBar bar = new NavigationBar(this, parent); - for (IPortalPage page : uninitializedPages) { + for (PortalPage page : pages) { bar.addNavButton(bar, page); } return bar; } - void showPage(IPortalPage page) { - if (uninitializedPages.contains(page)) { - uninitializedPages.remove(page); - page.init(); + void showPage(PortalPage page) { + if (!page.isInitialized()) { + page.getPortalExtension().init(); } - stackComposite.showControl(pageToControlMap.get(page)); + stackComposite.showControl(page.getControl()); } private void applyBG(final Composite composite) { @@ -319,4 +315,14 @@ return backgroundParent; } + @Override + public IEditorPart getEditorPart() { + return this; + } + + @Override + public void refreshCommandBars() { + // TODO ask portal page to recreate command bars + } + } diff -r 4dbd593daf6d -r c2eba6dabd38 core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/editor/PortalPage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/editor/PortalPage.java Mon Jul 26 15:11:10 2010 -0500 @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +package com.nokia.carbide.internal.discovery.ui.editor; + +import org.eclipse.swt.widgets.Control; + +import com.nokia.carbide.internal.discovery.ui.extension.IPortalExtension; + + +public class PortalPage { + + private IPortalExtension portalExtension; + private String pageId; + private Control control; + private boolean initialized; + + public PortalPage(IPortalExtension portalExtension, String pageId) { + this.portalExtension = portalExtension; + this.pageId = pageId; + } + + public IPortalExtension getPortalExtension() { + return portalExtension; + } + + public String getPageId() { + return pageId; + } + + public void setControl(Control control) { + this.control = control; + } + + public Control getControl() { + return control; + } + + public void setInitialized(boolean initialized) { + this.initialized = initialized; + } + + public boolean isInitialized() { + return initialized; + } + +} diff -r 4dbd593daf6d -r c2eba6dabd38 core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/editor/TaskBar.java --- a/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/editor/TaskBar.java Fri Jul 23 15:40:47 2010 -0500 +++ b/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/editor/TaskBar.java Mon Jul 26 15:11:10 2010 -0500 @@ -31,7 +31,7 @@ import org.eclipse.ui.forms.events.IHyperlinkListener; import org.eclipse.ui.forms.widgets.Hyperlink; -import com.nokia.carbide.internal.discovery.ui.extension.IPortalPage.IActionBar; +import com.nokia.carbide.internal.discovery.ui.extension.IPortalExtension.IActionBar; class TaskBar extends RoundedCornerComposite { diff -r 4dbd593daf6d -r c2eba6dabd38 core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/extension/AbstractBrowserPortalPage.java --- a/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/extension/AbstractBrowserPortalPage.java Fri Jul 23 15:40:47 2010 -0500 +++ b/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/extension/AbstractBrowserPortalPage.java Mon Jul 26 15:11:10 2010 -0500 @@ -35,10 +35,11 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.ui.IEditorPart; +import com.nokia.carbide.internal.discovery.ui.extension.IPortalExtension; import com.nokia.carbide.discovery.ui.Activator; import com.nokia.carbide.discovery.ui.Messages; -public abstract class AbstractBrowserPortalPage implements IPortalPage { +public abstract class AbstractBrowserPortalPage implements IPortalExtension { private final class NavigationActionBar implements IActionBar { private List actions; diff -r 4dbd593daf6d -r c2eba6dabd38 core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/extension/AbstractMultiLayerPortalPage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/extension/AbstractMultiLayerPortalPage.java Mon Jul 26 15:11:10 2010 -0500 @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +package com.nokia.carbide.internal.discovery.ui.extension; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.IEditorPart; + +import com.nokia.carbide.internal.discovery.ui.editor.PortalEditor; +import com.nokia.carbide.internal.discovery.ui.editor.StackComposite; +import com.nokia.carbide.internal.discovery.ui.extension.IPortalExtension; + +/** + * An abstract class implementing IPortalPage allowing a single portal page + * to contain multiple layers controlled by a command bar + */ +public abstract class AbstractMultiLayerPortalPage implements IPortalExtension { + + private StackComposite stackComposite; + + @Override + public Control createControl(Composite parent, IEditorPart part) { + PortalEditor portalEditor = (PortalEditor) part.getAdapter(PortalEditor.class); + stackComposite = new StackComposite(parent, portalEditor.getBackgroundParent()); + return stackComposite; + } + + + + @Override + public void init() { + // TODO Auto-generated method stub + + } + + @Override + public IActionBar[] createCommandBars(IEditorPart part, IActionUIUpdater updater) { + // TODO Auto-generated method stub + return null; + } + +} diff -r 4dbd593daf6d -r c2eba6dabd38 core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/extension/IPortalEditor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/extension/IPortalEditor.java Mon Jul 26 15:11:10 2010 -0500 @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +package com.nokia.carbide.internal.discovery.ui.extension; + +import org.eclipse.ui.IEditorPart; + + +public interface IPortalEditor { + + IEditorPart getEditorPart(); + + void refreshCommandBars(); + +} diff -r 4dbd593daf6d -r c2eba6dabd38 core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/extension/IPortalExtension.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/extension/IPortalExtension.java Mon Jul 26 15:11:10 2010 -0500 @@ -0,0 +1,113 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +package com.nokia.carbide.internal.discovery.ui.extension; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.IEditorPart; + +/** + * Interface to a portal extension + */ +public interface IPortalExtension { + + /** + * Interface to an action/navigation bar for the portal extension + */ + public interface IActionBar { + + /** + * Required title for the action bar + * @return String + */ + String getTitle(); + + /** + * Actions shown in the action bar: + * Required: text and run() methods + * Optional: tool tip text + * Unused: image/check + * @return IAction + */ + IAction[] getActions(); + + /** + * Action ids for actions that should be emphasized in the action bar (e.g., bold font) + * @return String[] or null + */ + String[] getHighlightedActionIds(); + + } + + /** + * Interface allowing the UI for provided actions of an IActionBar to be updated (e.g., enabled state) + */ + public interface IActionUIUpdater { + + /** + * Update the UI for a specific action by id + * @param actionId + */ + void update(String actionId); + + /** + * Update the UI for all actions in the IActionBar + */ + void updateAll(); + + } + + /** + * Required title text used by main navigation bar + * @return String + */ + String getText(); + + /** + * Required image descriptor used by main navigation bar + * @return ImageDescriptor + */ + ImageDescriptor getImageDescriptor(); + + /** + * Called to create the control for the extension + * @param parent Composite + * @param part IEditorPart + * @return Control + */ + Control createControl(Composite parent, IEditorPart part); + + /** + * Called to initialize the extension when shown for the first time + */ + void init(); + + /** + * Return action bars for the extension + * @param part IEditorPart + * @param updater IActionUIUpdater + * @return IActionBar[] + */ + IActionBar[] createCommandBars(IEditorPart part, IActionUIUpdater updater); + + /** + * Called to dispose internal resources of the extension + */ + void dispose(); +} diff -r 4dbd593daf6d -r c2eba6dabd38 core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/extension/IPortalPage.java --- a/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/extension/IPortalPage.java Fri Jul 23 15:40:47 2010 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -/* -* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of the License "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". -* -* Initial Contributors: -* Nokia Corporation - initial contribution. -* -* Contributors: -* -* Description: -* -*/ -package com.nokia.carbide.internal.discovery.ui.extension; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.IEditorPart; - -/** - * Interface to a portal page extension - */ -public interface IPortalPage { - - /** - * Interface to an action/navigation bar for the portal page - */ - public interface IActionBar { - - /** - * Required title for the action bar - * @return String - */ - String getTitle(); - - /** - * Actions shown in the action bar: - * Required: text and run() methods - * Optional: tool tip text - * Unused: image - * @return IAction - */ - IAction[] getActions(); - - /** - * Action ids for actions that should be emphasized in the action bar (e.g., bold font) - * @return String[] or null - */ - String[] getHighlightedActionIds(); - - } - - /** - * Interface allowing the UI for provided actions of an IActionBar to be updated (e.g., enabled state) - */ - public interface IActionUIUpdater { - - /** - * Update the UI for a specific action by id - * @param actionId - */ - void update(String actionId); - - /** - * Update the UI for all actions in the IActionBar - */ - void updateAll(); - - } - - /** - * Required title text used by main navigation bar - * @return String - */ - String getText(); - - /** - * Required image descriptor used by main navigation bar - * @return ImageDescriptor - */ - ImageDescriptor getImageDescriptor(); - - /** - * Called to create the control for the page - * @param parent Composite - * @param part IEditorPart - * @return Control - */ - Control createControl(Composite parent, IEditorPart part); - - /** - * Called to initialize the page when shown for the first time - */ - void init(); - - /** - * Return action bars for the page (can't be null) - * @param part IEditorPart - * @param updater IActionUIUpdater - * @return IActionBar[] - */ - IActionBar[] createCommandBars(IEditorPart part, IActionUIUpdater updater); - - /** - * Called to dispose internal resources of the page - */ - void dispose(); -} diff -r 4dbd593daf6d -r c2eba6dabd38 core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/view/InstallExtensionsPage.java --- a/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/view/InstallExtensionsPage.java Fri Jul 23 15:40:47 2010 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,346 +0,0 @@ -package com.nokia.carbide.internal.discovery.ui.view; - -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -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.equinox.p2.core.IProvisioningAgent; -import org.eclipse.equinox.p2.operations.ProvisioningSession; -import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager; -import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager; -import org.eclipse.equinox.p2.ui.ProvisioningUI; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IAction; -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.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.actions.BaseSelectionListenerAction; -import org.eclipse.ui.browser.IWorkbenchBrowserSupport; - -import com.nokia.carbide.discovery.ui.Activator; -import com.nokia.carbide.discovery.ui.Messages; -import com.nokia.carbide.internal.discovery.ui.extension.IPortalPage; -import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils; - -@SuppressWarnings("restriction") -public class InstallExtensionsPage implements IPortalPage { - - private static final String INSTALL_ACTION_ID = InstallExtensionsPage.class.getName() + ".install"; //$NON-NLS-1$ - - private final class RunnableContextDialog extends ProgressMonitorDialog { - private final String title; - - private RunnableContextDialog(Shell parent, String title) { - super(parent); - this.title = title; - } - - @Override - protected void configureShell(Shell shell) { - super.configureShell(shell); - shell.setText(title); - } - - } - - private final class ActionBar implements IActionBar { - private IAction[] actions; - - public ActionBar(IEditorPart part) { - actions = makeActions(part); - } - - @Override - public String getTitle() { - return Messages.InstallExtensionsPage_ActionBarTitle; - } - - @Override - public IAction[] getActions() { - return actions; - } - - @Override - public String[] getHighlightedActionIds() { - return new String[] {INSTALL_ACTION_ID}; - } - } - - private final class LinkBar implements IActionBar { - @Override - public String getTitle() { - return Messages.InstallExtensionsPage_LinkBarTitle; - } - - @Override - public IAction[] getActions() { - IAction action = new Action(Messages.InstallExtensionsPage_BuzillaActionName) { - @Override - public void run() { - try { - URL url = new URL("https://xdabug001.ext.nokia.com/bugzilla"); //$NON-NLS-1$ - IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench().getBrowserSupport(); - browserSupport.createBrowser(null).openURL(url); - } catch (MalformedURLException e) { - } catch (PartInitException e) { - } - } - }; - return new IAction[] { action }; - } - - @Override - public String[] getHighlightedActionIds() { - return null; - } - } - - private static final String DIRECTORY_KEY = "com.nokia.carbide.discovery.directory"; //$NON-NLS-1$ - - private CatalogViewer viewer; - private List selectionListeners; - private IActionUIUpdater updater; - - public InstallExtensionsPage() { - } - - @Override - public String getText() { - return Messages.InstallExtensionsPage_Title; - } - - @Override - public ImageDescriptor getImageDescriptor() { - return Activator.getImageDescriptor("icons/icon-discovery.png"); //$NON-NLS-1$ - } - - @Override - public Control createControl(Composite parent, IEditorPart part) { - Composite c = new Composite(parent, SWT.NONE); - GridLayoutFactory.swtDefaults().applyTo(c); - viewer = new CatalogViewer(getCatalog(), part.getEditorSite(), - new RunnableContextDialog(part.getEditorSite().getShell(), - Messages.InstallExtensionsPage_GatherExtensionsTitle), - getConfiguration()); - viewer.createControl(c); - GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getControl()); - - // Create the help context id for the viewer's control - PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), - "com.nokia.carbide.discovery.ui.view.DiscoveryView.catalogviewer"); //$NON-NLS-1$ - return c; - } - - @Override - public void init() { - if (!WorkbenchUtils.isJUnitRunning()) { // do not initialize the catalog if JUnit is running - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - for (ISelectionChangedListener listener : selectionListeners) { - viewer.addSelectionChangedListener(listener); - } - viewer.updateCatalog(); - } - }); - } - } - - @Override - public IActionBar[] createCommandBars(IEditorPart part, IActionUIUpdater updater) { - this.updater = updater; - return new IActionBar[] { new ActionBar(part), new LinkBar() }; - } - - 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 remote descriptor - RemoteBundleDiscoveryStrategy remoteDiscoveryStrategy = new RemoteBundleDiscoveryStrategy(); - String url = Activator.getFromServerProperties(DIRECTORY_KEY); - if (url != null) { - remoteDiscoveryStrategy.setDirectoryUrl(url); - catalog.getDiscoveryStrategies().add(remoteDiscoveryStrategy); - } - else // look for descriptors from installed bundles - catalog.getDiscoveryStrategies().add(new BundleDiscoveryStrategy()); - - return catalog; - } - - private IAction[] makeActions(final IEditorPart part) { - selectionListeners = new ArrayList(); - List actions = new ArrayList(); - IAction action; - - // install - action = new BaseSelectionListenerAction(Messages.InstallExtensionsPage_InstallLabel) { - public void run() { - DiscoveryUi.install(viewer.getCheckedItems(), - new RunnableContextDialog(part.getEditorSite().getShell(), - Messages.InstallExtensionsPage_GatheringInstallInfoTitle)); - }; - - protected boolean updateSelection(IStructuredSelection selection) { - scheduleUpdateAllActionUIs(); - return !selection.isEmpty(); - }; - }; - action.setToolTipText(Messages.InstallExtensionsPage_InstallTip); - action.setId(INSTALL_ACTION_ID); - selectionListeners.add((ISelectionChangedListener) action); - actions.add(action); - - // refresh - action = new Action(Messages.InstallExtensionsPage_RefreshLabel) { - public void run() { - viewer.setSelection(StructuredSelection.EMPTY); - viewer.updateCatalog(); - viewer.refresh(); - } - }; - actions.add(action); - - // check all - action = new BaseSelectionListenerAction(Messages.InstallExtensionsPage_CheckAllLabel) { - public void run() { - viewer.setSelection(StructuredSelection.EMPTY); - viewer.setSelection(getAllItemsSelection()); - viewer.refresh(); - } - - private IStructuredSelection getAllItemsSelection() { - List catalogItems = new ArrayList(); - for (CatalogItem catalogItem : viewer.getCatalog().getItems()) { - if (!catalogItem.isInstalled()) - catalogItems.add(catalogItem); - } - return new StructuredSelection(catalogItems); - } - - protected boolean updateSelection(IStructuredSelection selection) { - scheduleUpdateAllActionUIs(); - return !getAllItemsSelection().equals(selection); - } - }; - action.setId(InstallExtensionsPage.class.getName() + ".checkAll"); //$NON-NLS-1$ - selectionListeners.add((ISelectionChangedListener) action); - actions.add(action); - - // uncheck all - action = new BaseSelectionListenerAction(Messages.InstallExtensionsPage_UncheckAllLabel) { - public void run() { - viewer.setSelection(StructuredSelection.EMPTY); - viewer.refresh(); - }; - - protected boolean updateSelection(IStructuredSelection selection) { - scheduleUpdateAllActionUIs(); - return !selection.isEmpty(); - }; - }; - action.setId(InstallExtensionsPage.class.getName() + ".uncheckAll"); //$NON-NLS-1$ - selectionListeners.add((ISelectionChangedListener) action); - actions.add(action); - - // advanced install - action = new Action(Messages.InstallExtensionsPage_AdvancedInstallLabel) { - public void run() { - showInstallWizard(); - } - }; - actions.add(action); - - ISelectionChangedListener selectionListener = new ISelectionChangedListener() { - @Override - public void selectionChanged(SelectionChangedEvent event) { - IStructuredSelection selection = (IStructuredSelection) event.getSelection(); - IActionBars bars = part.getEditorSite().getActionBars(); - bars.getStatusLineManager().setMessage( - selection.isEmpty() ? null : MessageFormat.format( - Messages.InstallExtensionsPage_StatusLineFmt, selection.size())); - } - }; - selectionListeners.add(selectionListener); - - return (IAction[]) actions.toArray(new IAction[actions.size()]); - } - - @Override - public void dispose() { - for (ISelectionChangedListener listener : selectionListeners) { - viewer.removeSelectionChangedListener(listener); - } - } - - private void showInstallWizard() { - ProvisioningUI defaultUI = ProvisioningUI.getDefaultUI(); - ProvisioningSession session = defaultUI.getSession(); - IProvisioningAgent agent = session.getProvisioningAgent(); - IMetadataRepositoryManager metadataManager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME); - IArtifactRepositoryManager artifactManager = (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME); - for (URI uri : getCatalogURIs()) { - metadataManager.addRepository(uri); - artifactManager.addRepository(uri); - } - defaultUI.openInstallWizard(null, null, null); - } - - private Collection getCatalogURIs() { - Set uris = new HashSet(); - for (CatalogItem catalogItem : viewer.getCatalog().getItems()) { - try { - uris.add(new URI(catalogItem.getSiteUrl())); - } catch (URISyntaxException e) { - // ignore bad URIs - } - } - return uris; - }; - - private void scheduleUpdateAllActionUIs() { - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - updater.updateAll(); - } - }); - }; -} diff -r 4dbd593daf6d -r c2eba6dabd38 core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/view/InstallExtensionsPortalExtension.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/view/InstallExtensionsPortalExtension.java Mon Jul 26 15:11:10 2010 -0500 @@ -0,0 +1,346 @@ +package com.nokia.carbide.internal.discovery.ui.view; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +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.equinox.p2.core.IProvisioningAgent; +import org.eclipse.equinox.p2.operations.ProvisioningSession; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager; +import org.eclipse.equinox.p2.ui.ProvisioningUI; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +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.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.actions.BaseSelectionListenerAction; +import org.eclipse.ui.browser.IWorkbenchBrowserSupport; + +import com.nokia.carbide.discovery.ui.Activator; +import com.nokia.carbide.discovery.ui.Messages; +import com.nokia.carbide.internal.discovery.ui.extension.IPortalExtension; +import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils; + +@SuppressWarnings("restriction") +public class InstallExtensionsPortalExtension implements IPortalExtension { + + private static final String INSTALL_ACTION_ID = InstallExtensionsPortalExtension.class.getName() + ".install"; //$NON-NLS-1$ + + private final class RunnableContextDialog extends ProgressMonitorDialog { + private final String title; + + private RunnableContextDialog(Shell parent, String title) { + super(parent); + this.title = title; + } + + @Override + protected void configureShell(Shell shell) { + super.configureShell(shell); + shell.setText(title); + } + + } + + private final class ActionBar implements IActionBar { + private IAction[] actions; + + public ActionBar(IEditorPart part) { + actions = makeActions(part); + } + + @Override + public String getTitle() { + return Messages.InstallExtensionsPage_ActionBarTitle; + } + + @Override + public IAction[] getActions() { + return actions; + } + + @Override + public String[] getHighlightedActionIds() { + return new String[] {INSTALL_ACTION_ID}; + } + } + + private final class LinkBar implements IActionBar { + @Override + public String getTitle() { + return Messages.InstallExtensionsPage_LinkBarTitle; + } + + @Override + public IAction[] getActions() { + IAction action = new Action(Messages.InstallExtensionsPage_BuzillaActionName) { + @Override + public void run() { + try { + URL url = new URL("https://xdabug001.ext.nokia.com/bugzilla"); //$NON-NLS-1$ + IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench().getBrowserSupport(); + browserSupport.createBrowser(null).openURL(url); + } catch (MalformedURLException e) { + } catch (PartInitException e) { + } + } + }; + return new IAction[] { action }; + } + + @Override + public String[] getHighlightedActionIds() { + return null; + } + } + + private static final String DIRECTORY_KEY = "com.nokia.carbide.discovery.directory"; //$NON-NLS-1$ + + private CatalogViewer viewer; + private List selectionListeners; + private IActionUIUpdater updater; + + public InstallExtensionsPortalExtension() { + } + + @Override + public String getText() { + return Messages.InstallExtensionsPage_Title; + } + + @Override + public ImageDescriptor getImageDescriptor() { + return Activator.getImageDescriptor("icons/icon-discovery.png"); //$NON-NLS-1$ + } + + @Override + public Control createControl(Composite parent, IEditorPart part) { + Composite c = new Composite(parent, SWT.NONE); + GridLayoutFactory.swtDefaults().applyTo(c); + viewer = new CatalogViewer(getCatalog(), part.getEditorSite(), + new RunnableContextDialog(part.getEditorSite().getShell(), + Messages.InstallExtensionsPage_GatherExtensionsTitle), + getConfiguration()); + viewer.createControl(c); + GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getControl()); + + // Create the help context id for the viewer's control + PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), + "com.nokia.carbide.discovery.ui.view.DiscoveryView.catalogviewer"); //$NON-NLS-1$ + return c; + } + + @Override + public void init() { + if (!WorkbenchUtils.isJUnitRunning()) { // do not initialize the catalog if JUnit is running + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + for (ISelectionChangedListener listener : selectionListeners) { + viewer.addSelectionChangedListener(listener); + } + viewer.updateCatalog(); + } + }); + } + } + + @Override + public IActionBar[] createCommandBars(IEditorPart part, IActionUIUpdater updater) { + this.updater = updater; + return new IActionBar[] { new ActionBar(part), new LinkBar() }; + } + + 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 remote descriptor + RemoteBundleDiscoveryStrategy remoteDiscoveryStrategy = new RemoteBundleDiscoveryStrategy(); + String url = Activator.getFromServerProperties(DIRECTORY_KEY); + if (url != null) { + remoteDiscoveryStrategy.setDirectoryUrl(url); + catalog.getDiscoveryStrategies().add(remoteDiscoveryStrategy); + } + else // look for descriptors from installed bundles + catalog.getDiscoveryStrategies().add(new BundleDiscoveryStrategy()); + + return catalog; + } + + private IAction[] makeActions(final IEditorPart part) { + selectionListeners = new ArrayList(); + List actions = new ArrayList(); + IAction action; + + // install + action = new BaseSelectionListenerAction(Messages.InstallExtensionsPage_InstallLabel) { + public void run() { + DiscoveryUi.install(viewer.getCheckedItems(), + new RunnableContextDialog(part.getEditorSite().getShell(), + Messages.InstallExtensionsPage_GatheringInstallInfoTitle)); + }; + + protected boolean updateSelection(IStructuredSelection selection) { + scheduleUpdateAllActionUIs(); + return !selection.isEmpty(); + }; + }; + action.setToolTipText(Messages.InstallExtensionsPage_InstallTip); + action.setId(INSTALL_ACTION_ID); + selectionListeners.add((ISelectionChangedListener) action); + actions.add(action); + + // refresh + action = new Action(Messages.InstallExtensionsPage_RefreshLabel) { + public void run() { + viewer.setSelection(StructuredSelection.EMPTY); + viewer.updateCatalog(); + viewer.refresh(); + } + }; + actions.add(action); + + // check all + action = new BaseSelectionListenerAction(Messages.InstallExtensionsPage_CheckAllLabel) { + public void run() { + viewer.setSelection(StructuredSelection.EMPTY); + viewer.setSelection(getAllItemsSelection()); + viewer.refresh(); + } + + private IStructuredSelection getAllItemsSelection() { + List catalogItems = new ArrayList(); + for (CatalogItem catalogItem : viewer.getCatalog().getItems()) { + if (!catalogItem.isInstalled()) + catalogItems.add(catalogItem); + } + return new StructuredSelection(catalogItems); + } + + protected boolean updateSelection(IStructuredSelection selection) { + scheduleUpdateAllActionUIs(); + return !getAllItemsSelection().equals(selection); + } + }; + action.setId(InstallExtensionsPortalExtension.class.getName() + ".checkAll"); //$NON-NLS-1$ + selectionListeners.add((ISelectionChangedListener) action); + actions.add(action); + + // uncheck all + action = new BaseSelectionListenerAction(Messages.InstallExtensionsPage_UncheckAllLabel) { + public void run() { + viewer.setSelection(StructuredSelection.EMPTY); + viewer.refresh(); + }; + + protected boolean updateSelection(IStructuredSelection selection) { + scheduleUpdateAllActionUIs(); + return !selection.isEmpty(); + }; + }; + action.setId(InstallExtensionsPortalExtension.class.getName() + ".uncheckAll"); //$NON-NLS-1$ + selectionListeners.add((ISelectionChangedListener) action); + actions.add(action); + + // advanced install + action = new Action(Messages.InstallExtensionsPage_AdvancedInstallLabel) { + public void run() { + showInstallWizard(); + } + }; + actions.add(action); + + ISelectionChangedListener selectionListener = new ISelectionChangedListener() { + @Override + public void selectionChanged(SelectionChangedEvent event) { + IStructuredSelection selection = (IStructuredSelection) event.getSelection(); + IActionBars bars = part.getEditorSite().getActionBars(); + bars.getStatusLineManager().setMessage( + selection.isEmpty() ? null : MessageFormat.format( + Messages.InstallExtensionsPage_StatusLineFmt, selection.size())); + } + }; + selectionListeners.add(selectionListener); + + return (IAction[]) actions.toArray(new IAction[actions.size()]); + } + + @Override + public void dispose() { + for (ISelectionChangedListener listener : selectionListeners) { + viewer.removeSelectionChangedListener(listener); + } + } + + private void showInstallWizard() { + ProvisioningUI defaultUI = ProvisioningUI.getDefaultUI(); + ProvisioningSession session = defaultUI.getSession(); + IProvisioningAgent agent = session.getProvisioningAgent(); + IMetadataRepositoryManager metadataManager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME); + IArtifactRepositoryManager artifactManager = (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME); + for (URI uri : getCatalogURIs()) { + metadataManager.addRepository(uri); + artifactManager.addRepository(uri); + } + defaultUI.openInstallWizard(null, null, null); + } + + private Collection getCatalogURIs() { + Set uris = new HashSet(); + for (CatalogItem catalogItem : viewer.getCatalog().getItems()) { + try { + uris.add(new URI(catalogItem.getSiteUrl())); + } catch (URISyntaxException e) { + // ignore bad URIs + } + } + return uris; + }; + + private void scheduleUpdateAllActionUIs() { + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + updater.updateAll(); + } + }); + }; +}