Index: /Users/fm/Development/XWiki/Workspace.XWikiEclipse/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/impl/XWikiConnectionManager.java =================================================================== --- /Users/fm/Development/XWiki/Workspace.XWikiEclipse/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/impl/XWikiConnectionManager.java (revision 5289) +++ /Users/fm/Development/XWiki/Workspace.XWikiEclipse/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/impl/XWikiConnectionManager.java (working copy) @@ -90,18 +90,20 @@ // Assume older version of xwiki and turn-off conversion on client. rpc.setConvertor(new IdentityObjectConvertor()); } - XWikiConnection conection = new XWikiConnection(); - conection.setServerUrl(serverUrl); - conection.setUserName(userName); - conection.setRpcProxy(rpc); + XWikiConnection connection = new XWikiConnection(); + connection.setServerUrl(serverUrl); + connection.setUserName(userName); + connection.setPassword(password); + connection.setProxy(proxy); + connection.setRpcProxy(rpc); IPath masterCacheDir = CacheUtils.getMasterCacheDirectory(); IPath cachePath = masterCacheDir.addTrailingSeparator().append(String.valueOf(new Date().getTime())); - conection.setCachePath(cachePath); - CacheUtils.updateCache(conection); - conection.getCachePath().toFile().mkdir(); - connections.add(conection); - return conection; + connection.setCachePath(cachePath); + CacheUtils.updateCache(connection); + connection.getCachePath().toFile().mkdir(); + connections.add(connection); + return connection; } /** Index: /Users/fm/Development/XWiki/Workspace.XWikiEclipse/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/impl/XWikiConnection.java =================================================================== --- /Users/fm/Development/XWiki/Workspace.XWikiEclipse/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/impl/XWikiConnection.java (revision 5289) +++ /Users/fm/Development/XWiki/Workspace.XWikiEclipse/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/impl/XWikiConnection.java (working copy) @@ -79,6 +79,16 @@ private transient IPath cachePath; /** + * The password for this connection. + */ + private String password; + + /** + * The proxy for this connection. + */ + private String proxy; + + /** * Default constructor. A connection should only be acquired by going through ConnectionManager */ protected XWikiConnection() @@ -119,6 +129,15 @@ /** * used by ConnectionManager to set initial parameters. * + * @param password password. + */ + protected void setPassword(String password) { + this.password = password; + } + + /** + * used by ConnectionManager to set initial parameters. + * * @param spacesReady Set whether spaces have been retrieved or not. */ protected void setSpacesReady(boolean spacesReady) @@ -292,6 +311,7 @@ { return serverUrl; } + /** * {@inheritDoc} @@ -322,6 +342,11 @@ { return userName; } + + public String getPassword() + { + return password; + } /** * {@inheritDoc} @@ -379,4 +404,13 @@ { // We'll worry about this later. } + + public void setProxy(String proxy) + { + this.proxy = proxy; + } + + public String getProxy() { + return proxy; + } } Index: /Users/fm/Development/XWiki/Workspace.XWikiEclipse/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/wrappers/XWikiConnectionWrapper.java =================================================================== --- /Users/fm/Development/XWiki/Workspace.XWikiEclipse/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/wrappers/XWikiConnectionWrapper.java (revision 5289) +++ /Users/fm/Development/XWiki/Workspace.XWikiEclipse/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/wrappers/XWikiConnectionWrapper.java (working copy) @@ -262,4 +262,13 @@ { return connection.getRpcProxy(); } + + public String getPassword() { + return connection.getPassword(); + } + + public String getProxy() + { + return connection.getProxy(); + } } Index: /Users/fm/Development/XWiki/Workspace.XWikiEclipse/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/IXWikiConnection.java =================================================================== --- /Users/fm/Development/XWiki/Workspace.XWikiEclipse/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/IXWikiConnection.java (revision 5289) +++ /Users/fm/Development/XWiki/Workspace.XWikiEclipse/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/IXWikiConnection.java (working copy) @@ -47,11 +47,22 @@ public String getUserName(); /** + * @return Password. + */ + public String getPassword(); + + + /** * @return Server url. */ public String getServerUrl(); /** + * @return proxy. + */ + public String getProxy(); + + /** * @return The XML-RPC proxy used by this connection */ public Confluence getRpcProxy(); Index: /Users/fm/Development/XWiki/Workspace.XWikiEclipse/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/IPreferenceKeys.java =================================================================== --- /Users/fm/Development/XWiki/Workspace.XWikiEclipse/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/IPreferenceKeys.java (revision 0) +++ /Users/fm/Development/XWiki/Workspace.XWikiEclipse/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/IPreferenceKeys.java (revision 0) @@ -0,0 +1,16 @@ +package org.xwiki.plugins.eclipse; + +/** + * Constans used for saving preferences. + * + * @author Fabio Mancinelli <fm@fabiomancinelli.org>, <fabio.mancinelli@xwiki.com> + * + */ +public interface IPreferenceKeys { + public static final String CONNECTIONS_NODE = "connections"; + public static final String CONNECTION_URL = "url"; + public static final String CONNECTION_USERNAME = "username"; + public static final String CONNECTION_PASSWORD = "password"; + public static final String CONNECTION_PROXY = "proxy"; + public static final String CONNECTION_SPACES_NODE = "spaces"; +} Index: /Users/fm/Development/XWiki/Workspace.XWikiEclipse/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/Activator.java =================================================================== --- /Users/fm/Development/XWiki/Workspace.XWikiEclipse/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/Activator.java (revision 5289) +++ /Users/fm/Development/XWiki/Workspace.XWikiEclipse/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/Activator.java (working copy) @@ -21,70 +21,129 @@ package org.xwiki.plugins.eclipse; +import java.security.MessageDigest; +import java.util.Collection; +import java.util.UUID; + +import org.eclipse.core.runtime.preferences.ConfigurationScope; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; +import org.osgi.service.prefs.BackingStoreException; +import org.osgi.service.prefs.Preferences; +import org.xwiki.plugins.eclipse.model.IXWikiConnection; +import org.xwiki.plugins.eclipse.model.IXWikiSpace; +import org.xwiki.plugins.eclipse.model.impl.XWikiConnectionManager; /** - * The activator class controls the plug-in life cycle, this is a mandatory class and is used by the - * eclipse plugin framework. + * The activator class controls the plug-in life cycle, this is a mandatory + * class and is used by the eclipse plugin framework. */ -public class Activator extends AbstractUIPlugin -{ +public class Activator extends AbstractUIPlugin { - /** - * The plugin ID. - */ - public static final String PLUGIN_ID = "XWiki_Eclipse_Plugin"; + /** + * The plugin ID. + */ + public static final String PLUGIN_ID = "XWiki_Eclipse_Plugin"; - /** - * The shared instance. - */ - private static Activator plugin; + /** + * The shared instance. + */ + private static Activator plugin; - /** - * The constructor. - */ - public Activator() - { - plugin = this; - } + /** + * The constructor. + */ + public Activator() { + plugin = this; + } - /** - * {@inheritDoc} - * - * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) - */ - public void start(BundleContext context) throws Exception - { - super.start(context); - } + /** + * {@inheritDoc} + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception + { + super.start(context); + } - /** - * {@inheritDoc} - * - * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) - */ - public void stop(BundleContext context) throws Exception - { - plugin = null; - super.stop(context); - } + /** + * {@inheritDoc} + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception + { + saveConnections(); + plugin = null; + super.stop(context); + } - /** - * @return The shared instance of this plugin. - */ - public static Activator getDefault() - { - return plugin; - } + /** + * @return The shared instance of this plugin. + */ + public static Activator getDefault() + { + return plugin; + } - /** - * @param path The path to image file. - * @return An image descriptor for the image file at the given plug-in relative path. - */ - public static ImageDescriptor getImageDescriptor(String path) - { - return imageDescriptorFromPlugin(PLUGIN_ID, path); - } + /** + * @param path + * The path to image file. + * @return An image descriptor for the image file at the given plug-in + * relative path. + */ + public static ImageDescriptor getImageDescriptor(String path) + { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } + + private static void saveConnections() throws BackingStoreException + { + /* Remove previous saved connections */ + IEclipsePreferences preferences = new ConfigurationScope() + .getNode(PLUGIN_ID); + Preferences connectionPreferences = preferences + .node(IPreferenceKeys.CONNECTIONS_NODE); + connectionPreferences.removeNode(); + + /* Save new connections */ + connectionPreferences = preferences + .node(IPreferenceKeys.CONNECTIONS_NODE); + + Collection connections = XWikiConnectionManager + .getInstance().getAllConnections(); + for (IXWikiConnection connection : connections) + { + Preferences connectionNode = connectionPreferences.node(UUID + .randomUUID().toString()); + connectionNode.put(IPreferenceKeys.CONNECTION_URL, connection + .getServerUrl()); + connectionNode.put(IPreferenceKeys.CONNECTION_USERNAME, connection + .getUserName()); + connectionNode.put(IPreferenceKeys.CONNECTION_PASSWORD, connection + .getPassword()); + connectionNode.put(IPreferenceKeys.CONNECTION_PROXY, connection + .getProxy()); + + Preferences spacesNode = connectionNode + .node(IPreferenceKeys.CONNECTION_SPACES_NODE); + for (IXWikiSpace space : connection.getSpaces()) + { + /* Save only non masked spaces so the next time we will retrieve the same layout */ + if (!space.isMasked()) + { + Preferences spaceNode = spacesNode.node(space.getKey()); + + /* This is needed otherwise empty nodes are not saved!!! */ + spaceNode.put("dummy", "dummy"); + } + } + } + + preferences.flush(); + + } } Index: /Users/fm/Development/XWiki/Workspace.XWikiEclipse/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/views/navigator/XWikiNavigator.java =================================================================== --- /Users/fm/Development/XWiki/Workspace.XWikiEclipse/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/views/navigator/XWikiNavigator.java (revision 5289) +++ /Users/fm/Development/XWiki/Workspace.XWikiEclipse/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/views/navigator/XWikiNavigator.java (working copy) @@ -21,7 +21,12 @@ package org.xwiki.plugins.eclipse.views.navigator; +import java.lang.reflect.InvocationTargetException; + import org.codehaus.swizzle.confluence.SwizzleConfluenceException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.preferences.ConfigurationScope; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; @@ -48,13 +53,20 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.DrillDownAdapter; import org.eclipse.ui.part.ViewPart; +import org.osgi.service.prefs.Preferences; +import org.xwiki.plugins.eclipse.Activator; +import org.xwiki.plugins.eclipse.IPreferenceKeys; import org.xwiki.plugins.eclipse.model.IXWikiConnection; +import org.xwiki.plugins.eclipse.model.IXWikiConnectionManager; import org.xwiki.plugins.eclipse.model.IXWikiPage; import org.xwiki.plugins.eclipse.model.IXWikiSpace; +import org.xwiki.plugins.eclipse.model.impl.XWikiConnectionManager; +import org.xwiki.plugins.eclipse.model.wrappers.XWikiConnectionManagerWrapper; import org.xwiki.plugins.eclipse.model.wrappers.XWikiConnectionWrapper; import org.xwiki.plugins.eclipse.model.wrappers.XWikiSpaceWrapper; import org.xwiki.plugins.eclipse.util.GuiUtils; import org.xwiki.plugins.eclipse.util.XWikiConstants; +import org.xwiki.plugins.eclipse.util.XWikiProgressRunner; import org.xwiki.plugins.eclipse.wizards.XWikiWizardDialog; import org.xwiki.plugins.eclipse.wizards.connect.ConnectWizard; import org.xwiki.plugins.eclipse.wizards.newpage.NewPageWizard; @@ -63,438 +75,541 @@ /** * Document navigator (Tree Navigator) of the plug-in. */ -public class XWikiNavigator extends ViewPart -{ - /** - * built-in TreeViewer UI widget. - */ - private TreeViewer viewer; +public class XWikiNavigator extends ViewPart { + /** + * built-in TreeViewer UI widget. + */ + private TreeViewer viewer; - /** - * @see org.eclipse.ui.part.DrillDownAdapter. - */ - private DrillDownAdapter drillDownAdapter; + /** + * @see org.eclipse.ui.part.DrillDownAdapter. + */ + private DrillDownAdapter drillDownAdapter; - /** - * Action for adding a new XWikiConnection. - */ - private Action addConnectionAction; + /** + * Action for adding a new XWikiConnection. + */ + private Action addConnectionAction; - /** - * Action for removing an existing XWikiConnection. - */ - private Action removeConnectionAction; + /** + * Action for removing an existing XWikiConnection. + */ + private Action removeConnectionAction; - /** - * Action for adding a new page. - */ - private Action addPageAction; + /** + * Action for adding a new page. + */ + private Action addPageAction; - /** - * Action for removing an existing page. - */ - private Action removePageAction; + /** + * Action for removing an existing page. + */ + private Action removePageAction; - /** - * Action for adding a new Space. - */ - private Action addSpaceAction; + /** + * Action for adding a new Space. + */ + private Action addSpaceAction; - /** - * Action for removing a Space. - */ - private Action removeSpaceAction; + /** + * Action for removing a Space. + */ + private Action removeSpaceAction; - /** - * Action executed when the user double clicks on a tree item (edit document). - */ - private Action editAction; + /** + * Action executed when the user double clicks on a tree item (edit + * document). + */ + private Action editAction; - /** - * {@inheritDoc} - * - * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) - */ - public void createPartControl(Composite parent) - { - viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); - drillDownAdapter = new DrillDownAdapter(viewer); - viewer.setContentProvider(new XWikiNavigatorContentProvider()); - viewer.setLabelProvider(new XWikiNavigatorLabelProvider()); - viewer.setInput(getViewSite()); - getSite().setSelectionProvider(viewer); - makeActions(); - hookContextMenu(); - hookDoubleClickAction(); - contributeToActionBars(); - } + /** + * {@inheritDoc} + * + * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) + */ + public void createPartControl(Composite parent) + { + viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); + drillDownAdapter = new DrillDownAdapter(viewer); + viewer.setContentProvider(new XWikiNavigatorContentProvider()); + viewer.setLabelProvider(new XWikiNavigatorLabelProvider()); + viewer.setInput(getViewSite()); + getSite().setSelectionProvider(viewer); + makeActions(); + hookContextMenu(); + hookDoubleClickAction(); + contributeToActionBars(); + restoreConnections(); + } - /** - * Eclipse auto-generated code. hack these if you need to add items to different places in - * workbench. - */ - private void hookContextMenu() - { - MenuManager menuMgr = new MenuManager("#PopupMenu"); - menuMgr.setRemoveAllWhenShown(true); - menuMgr.addMenuListener(new IMenuListener() - { - public void menuAboutToShow(IMenuManager manager) - { - XWikiNavigator.this.fillContextMenu(manager); - } - }); - Menu menu = menuMgr.createContextMenu(viewer.getControl()); - viewer.getControl().setMenu(menu); - getSite().registerContextMenu(menuMgr, viewer); - } + private void restoreConnections() + { + XWikiProgressRunner operation = new XWikiProgressRunner() { + /** + * {@inheritDoc} + * + * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor) + */ + public void run(IProgressMonitor monitor) + throws InvocationTargetException, InterruptedException + { + monitor + .beginTask("Removing space...", + IProgressMonitor.UNKNOWN); - /** - * Eclipse auto-generated code. hack these if you need to add items to different places in - * workbench. - */ - private void contributeToActionBars() - { - IActionBars bars = getViewSite().getActionBars(); - fillLocalPullDown(bars.getMenuManager()); - fillLocalToolBar(bars.getToolBarManager()); - } + try + { + IXWikiConnectionManager connectionManager = + new XWikiConnectionManagerWrapper(XWikiConnectionManager.getInstance()); + IEclipsePreferences preferences = new ConfigurationScope() + .getNode(Activator.PLUGIN_ID); + Preferences connectionPreferences = preferences + .node(IPreferenceKeys.CONNECTIONS_NODE); + String[] connectionIDs = connectionPreferences + .childrenNames(); + + for(String id : connectionIDs) { + Preferences connectionNode = connectionPreferences.node(id); + String url = connectionNode.get(IPreferenceKeys.CONNECTION_URL, ""); + String userName = connectionNode.get(IPreferenceKeys.CONNECTION_USERNAME, ""); + String password = connectionNode.get(IPreferenceKeys.CONNECTION_PASSWORD, ""); + String proxy = connectionNode.get(IPreferenceKeys.CONNECTION_PROXY, null); + Preferences spacesNode = connectionNode.node(IPreferenceKeys.CONNECTION_SPACES_NODE); + String[] spaces = spacesNode.childrenNames(); + + IXWikiConnection connection = connectionManager.connect(url, userName, password, proxy); + IXWikiConnection wrapper = new XWikiConnectionWrapper(connection); + wrapper.getSpaces(); + + /* Set all spaces to masked state */ + for(IXWikiSpace space : connection.getSpaces()) { + space.setMasked(true); + } + + /* Unmask only saved space keys */ + for(String spaceKey : spaces) { + connection.getSpace(spaceKey).setMasked(false); + } + + viewer.refresh(); + } + } catch (Exception e) + { + e.printStackTrace(); + } - /** - * Eclipse auto-generated code. hack these if you need to add items to different places in - * workbench. - */ - private void fillLocalPullDown(IMenuManager manager) - { - manager.add(addConnectionAction); - manager.add(removeConnectionAction); - } + monitor.done(); - /** - * Eclipse auto-generated code. hack these if you need to add items to different places in - * workbench. - */ - private void fillContextMenu(IMenuManager manager) - { - manager.add(addPageAction); - manager.add(removePageAction); - manager.add(new Separator()); - manager.add(addSpaceAction); - manager.add(removeSpaceAction); - manager.add(new Separator()); - manager.add(removeConnectionAction); - manager.add(new Separator()); - drillDownAdapter.addNavigationActions(manager); - // Other plug-ins can contribute there actions here - manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); - } + } + }; + GuiUtils.runOperationWithProgress(operation, null); + } - /** - * Eclipse auto-generated code. hack these if you need to add items to different places in - * workbench. - */ - private void fillLocalToolBar(IToolBarManager manager) - { - manager.add(addConnectionAction); - manager.add(removeConnectionAction); - manager.add(new Separator()); - drillDownAdapter.addNavigationActions(manager); - } + /** + * Eclipse auto-generated code. hack these if you need to add items to + * different places in workbench. + */ + private void hookContextMenu() + { + MenuManager menuMgr = new MenuManager("#PopupMenu"); + menuMgr.setRemoveAllWhenShown(true); + menuMgr.addMenuListener(new IMenuListener() { + public void menuAboutToShow(IMenuManager manager) + { + XWikiNavigator.this.fillContextMenu(manager); + } + }); + Menu menu = menuMgr.createContextMenu(viewer.getControl()); + viewer.getControl().setMenu(menu); + getSite().registerContextMenu(menuMgr, viewer); + } - /** - * Make actions alive. - */ - private void makeActions() - { - /** - * Add new connection action. - */ - addConnectionAction = new Action() - { - public void run() - { - openConnectWizard(); - } - }; - addConnectionAction.setText("New Login"); - addConnectionAction.setToolTipText("New Login"); - addConnectionAction.setImageDescriptor(GuiUtils - .loadIconImage(XWikiConstants.ADD_CONNECTION_ICON)); + /** + * Eclipse auto-generated code. hack these if you need to add items to + * different places in workbench. + */ + private void contributeToActionBars() + { + IActionBars bars = getViewSite().getActionBars(); + fillLocalPullDown(bars.getMenuManager()); + fillLocalToolBar(bars.getToolBarManager()); + } - /** - * Remove connection action. - */ - removeConnectionAction = new Action() - { - public void run() - { - ISelection selection = viewer.getSelection(); - Object obj = ((IStructuredSelection) selection).getFirstElement(); - if (obj instanceof IXWikiConnection) { - IXWikiConnection connection = - new XWikiConnectionWrapper((IXWikiConnection) obj); - try { - connection.disconnect(); - } catch (SwizzleConfluenceException e) { - // Will be logged else where. - } - viewer.refresh(); - } - } - }; - removeConnectionAction.setText("Logout"); - removeConnectionAction.setToolTipText("Logout"); - removeConnectionAction.setImageDescriptor(GuiUtils - .loadIconImage(XWikiConstants.REMOVE_CONNECTION_ICON)); - removeConnectionAction.setEnabled(false); + /** + * Eclipse auto-generated code. hack these if you need to add items to + * different places in workbench. + */ + private void fillLocalPullDown(IMenuManager manager) + { + manager.add(addConnectionAction); + manager.add(removeConnectionAction); + } - /** - * Add page action. - */ - addPageAction = new Action() - { - public void run() - { - ISelection selection = viewer.getSelection(); - Object obj = ((IStructuredSelection) selection).getFirstElement(); - IXWikiSpace space = null; - if (obj instanceof IXWikiPage) { - space = new XWikiSpaceWrapper(((IXWikiPage) obj).getParentSpace()); - } else if (obj instanceof IXWikiSpace) { - space = new XWikiSpaceWrapper((IXWikiSpace) obj); - } - if (space != null) { - openAddNewPageWizard(space); - } - } - }; - addPageAction.setText("New Page"); - addPageAction.setToolTipText("New Page"); - addPageAction.setImageDescriptor(GuiUtils.loadIconImage(XWikiConstants.ADD_PAGE_ICON)); - addPageAction.setEnabled(false); + /** + * Eclipse auto-generated code. hack these if you need to add items to + * different places in workbench. + */ + private void fillContextMenu(IMenuManager manager) + { + manager.add(addPageAction); + manager.add(removePageAction); + manager.add(new Separator()); + manager.add(addSpaceAction); + manager.add(removeSpaceAction); + manager.add(new Separator()); + manager.add(removeConnectionAction); + manager.add(new Separator()); + drillDownAdapter.addNavigationActions(manager); + // Other plug-ins can contribute there actions here + manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); + } - /** - * Remove page action. - */ - removePageAction = new Action() - { - public void run() - { - ISelection selection = viewer.getSelection(); - Object obj = ((IStructuredSelection) selection).getFirstElement(); - if (obj instanceof IXWikiPage) { - IXWikiPage wikipage = (IXWikiPage) obj; - IXWikiSpace space = new XWikiSpaceWrapper(wikipage.getParentSpace()); - try { - space.removeChildPage(wikipage.getId()); - } catch (SwizzleConfluenceException e) { - // Will be logged else where. - } - viewer.refresh(); - } - } - }; - removePageAction.setText("Remove Page"); - removePageAction.setToolTipText("Remove Page"); - removePageAction.setImageDescriptor(GuiUtils - .loadIconImage(XWikiConstants.REMOVE_PAGE_ICON)); - removePageAction.setEnabled(false); + /** + * Eclipse auto-generated code. hack these if you need to add items to + * different places in workbench. + */ + private void fillLocalToolBar(IToolBarManager manager) + { + manager.add(addConnectionAction); + manager.add(removeConnectionAction); + manager.add(new Separator()); + drillDownAdapter.addNavigationActions(manager); + } - /** - * Add space action. - */ - addSpaceAction = new Action() - { - public void run() - { - ISelection selection = viewer.getSelection(); - Object obj = ((IStructuredSelection) selection).getFirstElement(); - IXWikiConnection connection = null; - if (obj instanceof IXWikiConnection) { - connection = new XWikiConnectionWrapper((IXWikiConnection) obj); - } else if (obj instanceof IXWikiSpace) { - connection = new XWikiConnectionWrapper(((IXWikiSpace) obj).getConnection()); - } - if (connection != null) { - openAddSpaceWizard(connection); - } - } - }; - addSpaceAction.setText("New Space"); - addSpaceAction.setToolTipText("New Space"); - addSpaceAction.setImageDescriptor(GuiUtils.loadIconImage(XWikiConstants.ADD_SPACE_ICON)); - addSpaceAction.setEnabled(false); + /** + * Make actions alive. + */ + private void makeActions() + { + /** + * Add new connection action. + */ + addConnectionAction = new Action() { + public void run() + { + openConnectWizard(); + } + }; + addConnectionAction.setText("New Login"); + addConnectionAction.setToolTipText("New Login"); + addConnectionAction.setImageDescriptor(GuiUtils + .loadIconImage(XWikiConstants.ADD_CONNECTION_ICON)); - /** - * Remove space action. - */ - removeSpaceAction = new Action() - { - public void run() - { - ISelection selection = viewer.getSelection(); - Object obj = ((IStructuredSelection) selection).getFirstElement(); - if (obj instanceof IXWikiSpace) { - IXWikiSpace space = (IXWikiSpace) obj; - IXWikiConnection connection = - new XWikiConnectionWrapper(space.getConnection()); - try { - connection.removeSpace(space.getKey()); - } catch (SwizzleConfluenceException e) { - // Will be logged elsewhere. - } - viewer.refresh(); - } - } - }; - removeSpaceAction.setText("Remove Space"); - removeSpaceAction.setToolTipText("Remove Space"); - removeSpaceAction.setImageDescriptor(GuiUtils - .loadIconImage(XWikiConstants.REMOVE_SPACE_ICON)); - removeSpaceAction.setEnabled(false); + /** + * Remove connection action. + */ + removeConnectionAction = new Action() { + public void run() + { + ISelection selection = viewer.getSelection(); + Object obj = ((IStructuredSelection) selection) + .getFirstElement(); + if (obj instanceof IXWikiConnection) + { + IXWikiConnection connection = new XWikiConnectionWrapper( + (IXWikiConnection) obj); + try + { + connection.disconnect(); + } catch (SwizzleConfluenceException e) + { + // Will be logged else where. + } + viewer.refresh(); + } + } + }; + removeConnectionAction.setText("Logout"); + removeConnectionAction.setToolTipText("Logout"); + removeConnectionAction.setImageDescriptor(GuiUtils + .loadIconImage(XWikiConstants.REMOVE_CONNECTION_ICON)); + removeConnectionAction.setEnabled(false); - /** - * Edit action. - */ - editAction = new Action() - { - public void run() - { - ISelection selection = viewer.getSelection(); - Object obj = ((IStructuredSelection) selection).getFirstElement(); - if (obj instanceof IXWikiPage) { - IXWikiPage page = (IXWikiPage) obj; - openEditor((IEditorInput) page); - } - } - }; + /** + * Add page action. + */ + addPageAction = new Action() { + public void run() + { + ISelection selection = viewer.getSelection(); + Object obj = ((IStructuredSelection) selection) + .getFirstElement(); + IXWikiSpace space = null; + if (obj instanceof IXWikiPage) + { + space = new XWikiSpaceWrapper(((IXWikiPage) obj) + .getParentSpace()); + } else if (obj instanceof IXWikiSpace) + { + space = new XWikiSpaceWrapper((IXWikiSpace) obj); + } + if (space != null) + { + openAddNewPageWizard(space); + } + } + }; + addPageAction.setText("New Page"); + addPageAction.setToolTipText("New Page"); + addPageAction.setImageDescriptor(GuiUtils + .loadIconImage(XWikiConstants.ADD_PAGE_ICON)); + addPageAction.setEnabled(false); - /** - * Viewer selection listener - */ - viewer.addSelectionChangedListener(new ISelectionChangedListener() - { - public void selectionChanged(SelectionChangedEvent event) - { - Object selection = - ((IStructuredSelection) event.getSelection()).getFirstElement(); - if (selection instanceof IXWikiConnection) { - removeConnectionAction.setEnabled(true); - } else { - removeConnectionAction.setEnabled(false); - } - if (selection instanceof IXWikiConnection || selection instanceof IXWikiSpace) { - addSpaceAction.setEnabled(true); - } else { - addSpaceAction.setEnabled(false); - } - if (selection instanceof IXWikiSpace) { - removeSpaceAction.setEnabled(true); - } else { - removeSpaceAction.setEnabled(false); - } - if (selection instanceof IXWikiSpace || selection instanceof IXWikiPage) { - addPageAction.setEnabled(true); - } else { - addPageAction.setEnabled(false); - } - if (selection instanceof IXWikiPage) { - removePageAction.setEnabled(true); - } else { - removePageAction.setEnabled(false); - } - } - }); - } + /** + * Remove page action. + */ + removePageAction = new Action() { + public void run() + { + ISelection selection = viewer.getSelection(); + Object obj = ((IStructuredSelection) selection) + .getFirstElement(); + if (obj instanceof IXWikiPage) + { + IXWikiPage wikipage = (IXWikiPage) obj; + IXWikiSpace space = new XWikiSpaceWrapper(wikipage + .getParentSpace()); + try + { + space.removeChildPage(wikipage.getId()); + } catch (SwizzleConfluenceException e) + { + // Will be logged else where. + } + viewer.refresh(); + } + } + }; + removePageAction.setText("Remove Page"); + removePageAction.setToolTipText("Remove Page"); + removePageAction.setImageDescriptor(GuiUtils + .loadIconImage(XWikiConstants.REMOVE_PAGE_ICON)); + removePageAction.setEnabled(false); - /** - * Eclipse auto-generated code. hack these if you need to add items to different places in - * workbench. - */ - private void hookDoubleClickAction() - { - viewer.addDoubleClickListener(new IDoubleClickListener() - { - public void doubleClick(DoubleClickEvent event) - { - editAction.run(); - } - }); - } + /** + * Add space action. + */ + addSpaceAction = new Action() { + public void run() + { + ISelection selection = viewer.getSelection(); + Object obj = ((IStructuredSelection) selection) + .getFirstElement(); + IXWikiConnection connection = null; + if (obj instanceof IXWikiConnection) + { + connection = new XWikiConnectionWrapper( + (IXWikiConnection) obj); + } else if (obj instanceof IXWikiSpace) + { + connection = new XWikiConnectionWrapper(((IXWikiSpace) obj) + .getConnection()); + } + if (connection != null) + { + openAddSpaceWizard(connection); + } + } + }; + addSpaceAction.setText("New Space"); + addSpaceAction.setToolTipText("New Space"); + addSpaceAction.setImageDescriptor(GuiUtils + .loadIconImage(XWikiConstants.ADD_SPACE_ICON)); + addSpaceAction.setEnabled(false); - /** - * {@inheritDoc} - * - * @see org.eclipse.ui.part.WorkbenchPart#setFocus() - */ - public void setFocus() - { - viewer.getControl().setFocus(); - } + /** + * Remove space action. + */ + removeSpaceAction = new Action() { + public void run() + { + ISelection selection = viewer.getSelection(); + Object obj = ((IStructuredSelection) selection) + .getFirstElement(); + if (obj instanceof IXWikiSpace) + { + IXWikiSpace space = (IXWikiSpace) obj; + IXWikiConnection connection = new XWikiConnectionWrapper( + space.getConnection()); + try + { + connection.removeSpace(space.getKey()); + } catch (SwizzleConfluenceException e) + { + // Will be logged elsewhere. + } + viewer.refresh(); + } + } + }; + removeSpaceAction.setText("Remove Space"); + removeSpaceAction.setToolTipText("Remove Space"); + removeSpaceAction.setImageDescriptor(GuiUtils + .loadIconImage(XWikiConstants.REMOVE_SPACE_ICON)); + removeSpaceAction.setEnabled(false); - /** - * Opens up the new connection wizard. - */ - private void openConnectWizard() - { - ConnectWizard connectWizard = new ConnectWizard(); - WizardDialog wizardDialog = - new XWikiWizardDialog(Display.getCurrent().getActiveShell(), connectWizard); - wizardDialog.setTitle("Connect..."); - wizardDialog.setBlockOnOpen(true); - wizardDialog.open(); - viewer.refresh(); - } + /** + * Edit action. + */ + editAction = new Action() { + public void run() + { + ISelection selection = viewer.getSelection(); + Object obj = ((IStructuredSelection) selection) + .getFirstElement(); + if (obj instanceof IXWikiPage) + { + IXWikiPage page = (IXWikiPage) obj; + openEditor((IEditorInput) page); + } + } + }; - /** - * Opens up the add new space wizard. - * - * @param connection Connection into which the space should be added. - */ - private void openAddSpaceWizard(IXWikiConnection connection) - { - NewSpaceWizard newSpaceWizard = new NewSpaceWizard(connection); - WizardDialog wizardDialog = - new XWikiWizardDialog(Display.getCurrent().getActiveShell(), newSpaceWizard); - wizardDialog.setTitle("New Space..."); - wizardDialog.setBlockOnOpen(true); - wizardDialog.open(); - viewer.refresh(); - } + /** + * Viewer selection listener + */ + viewer.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) + { + Object selection = ((IStructuredSelection) event.getSelection()) + .getFirstElement(); + if (selection instanceof IXWikiConnection) + { + removeConnectionAction.setEnabled(true); + } else + { + removeConnectionAction.setEnabled(false); + } + if (selection instanceof IXWikiConnection + || selection instanceof IXWikiSpace) + { + addSpaceAction.setEnabled(true); + } else + { + addSpaceAction.setEnabled(false); + } + if (selection instanceof IXWikiSpace) + { + removeSpaceAction.setEnabled(true); + } else + { + removeSpaceAction.setEnabled(false); + } + if (selection instanceof IXWikiSpace + || selection instanceof IXWikiPage) + { + addPageAction.setEnabled(true); + } else + { + addPageAction.setEnabled(false); + } + if (selection instanceof IXWikiPage) + { + removePageAction.setEnabled(true); + } else + { + removePageAction.setEnabled(false); + } + } + }); + } - /** - * Opens up the add new page wizard. - * - * @param space Space into which the page should be added. - */ - private void openAddNewPageWizard(IXWikiSpace space) - { - NewPageWizard newPageWizard = new NewPageWizard(space); - WizardDialog wizardDialog = - new XWikiWizardDialog(Display.getCurrent().getActiveShell(), newPageWizard); - wizardDialog.setTitle("New Page..."); - wizardDialog.setBlockOnOpen(true); - wizardDialog.open(); - viewer.refresh(); - } + /** + * Eclipse auto-generated code. hack these if you need to add items to + * different places in workbench. + */ + private void hookDoubleClickAction() + { + viewer.addDoubleClickListener(new IDoubleClickListener() { + public void doubleClick(DoubleClickEvent event) + { + editAction.run(); + } + }); + } - /** - * Opens up the document for editing. - * - * @param editorInput The XWikiPage to be edited. - */ - private void openEditor(IEditorInput editorInput) - { - IWorkbenchPage page = - PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - if (page != null) { - try { - page.openEditor(editorInput, "org.xwiki.plugins.eclipse.editors.XWikiEditor"); - } catch (PartInitException e) { - GuiUtils.reportError(true, "Error", e.getMessage()); - } - } else { - GuiUtils.reportError(true, "Error", "Internal Error : Could not create page."); - } - } + /** + * {@inheritDoc} + * + * @see org.eclipse.ui.part.WorkbenchPart#setFocus() + */ + public void setFocus() + { + viewer.getControl().setFocus(); + } + + /** + * Opens up the new connection wizard. + */ + private void openConnectWizard() + { + ConnectWizard connectWizard = new ConnectWizard(); + WizardDialog wizardDialog = new XWikiWizardDialog(Display.getCurrent() + .getActiveShell(), connectWizard); + wizardDialog.setTitle("Connect..."); + wizardDialog.setBlockOnOpen(true); + wizardDialog.open(); + viewer.refresh(); + } + + /** + * Opens up the add new space wizard. + * + * @param connection + * Connection into which the space should be added. + */ + private void openAddSpaceWizard(IXWikiConnection connection) + { + NewSpaceWizard newSpaceWizard = new NewSpaceWizard(connection); + WizardDialog wizardDialog = new XWikiWizardDialog(Display.getCurrent() + .getActiveShell(), newSpaceWizard); + wizardDialog.setTitle("New Space..."); + wizardDialog.setBlockOnOpen(true); + wizardDialog.open(); + viewer.refresh(); + } + + /** + * Opens up the add new page wizard. + * + * @param space + * Space into which the page should be added. + */ + private void openAddNewPageWizard(IXWikiSpace space) + { + NewPageWizard newPageWizard = new NewPageWizard(space); + WizardDialog wizardDialog = new XWikiWizardDialog(Display.getCurrent() + .getActiveShell(), newPageWizard); + wizardDialog.setTitle("New Page..."); + wizardDialog.setBlockOnOpen(true); + wizardDialog.open(); + viewer.refresh(); + } + + /** + * Opens up the document for editing. + * + * @param editorInput + * The XWikiPage to be edited. + */ + private void openEditor(IEditorInput editorInput) + { + IWorkbenchPage page = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow().getActivePage(); + if (page != null) + { + try + { + page.openEditor(editorInput, + "org.xwiki.plugins.eclipse.editors.XWikiEditor"); + } catch (PartInitException e) + { + GuiUtils.reportError(true, "Error", e.getMessage()); + } + } else + { + GuiUtils.reportError(true, "Error", + "Internal Error : Could not create page."); + } + } }