Initial drop of org.eclipse.wst.server.util.tests
diff --git a/tests/org.eclipse.wst.server.util.tests/.classpath b/tests/org.eclipse.wst.server.util.tests/.classpath new file mode 100644 index 0000000..ad32c83 --- /dev/null +++ b/tests/org.eclipse.wst.server.util.tests/.classpath
@@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath>
diff --git a/tests/org.eclipse.wst.server.util.tests/.settings/org.eclipse.jdt.core.prefs b/tests/org.eclipse.wst.server.util.tests/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..e6d0f16 --- /dev/null +++ b/tests/org.eclipse.wst.server.util.tests/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@ +#Thu Apr 08 17:10:09 EDT 2010 +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6
diff --git a/tests/org.eclipse.wst.server.util.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.wst.server.util.tests/META-INF/MANIFEST.MF new file mode 100644 index 0000000..fa2c5b9 --- /dev/null +++ b/tests/org.eclipse.wst.server.util.tests/META-INF/MANIFEST.MF
@@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Server Test utilities +Bundle-SymbolicName: org.eclipse.wst.server.util.tests;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.eclipse.wst.server.test.util.Activator +Bundle-Vendor: Eclipse.org +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.wst.server.core;bundle-version="1.1.202", + org.eclipse.core.resources;bundle-version="3.6.0" +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-ActivationPolicy: lazy
diff --git a/tests/org.eclipse.wst.server.util.tests/README.txt b/tests/org.eclipse.wst.server.util.tests/README.txt new file mode 100644 index 0000000..751bb79 --- /dev/null +++ b/tests/org.eclipse.wst.server.util.tests/README.txt
@@ -0,0 +1,13 @@ +About this plugin: +------------------ +This plugin is a set of utilities used to create scenarios that would +otherwise require code hack modifications to test a particular scenario. + +It is not to be included as part of any product, and it shouldn't be +included in any WTP BUILDS. + +The use of this utilities can potentially damage important data in your +workspace. Do not use this utilities unless you assume full responsability +of any damages(or improvements :)) to your workspace. + +-The WTP Server tools lead \ No newline at end of file
diff --git a/tests/org.eclipse.wst.server.util.tests/build.properties b/tests/org.eclipse.wst.server.util.tests/build.properties new file mode 100644 index 0000000..0d3d3a7 --- /dev/null +++ b/tests/org.eclipse.wst.server.util.tests/build.properties
@@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + icons/
diff --git a/tests/org.eclipse.wst.server.util.tests/icons/sample.gif b/tests/org.eclipse.wst.server.util.tests/icons/sample.gif new file mode 100644 index 0000000..34fb3c9 --- /dev/null +++ b/tests/org.eclipse.wst.server.util.tests/icons/sample.gif Binary files differ
diff --git a/tests/org.eclipse.wst.server.util.tests/plugin.xml b/tests/org.eclipse.wst.server.util.tests/plugin.xml new file mode 100644 index 0000000..1a9bff7 --- /dev/null +++ b/tests/org.eclipse.wst.server.util.tests/plugin.xml
@@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.4"?> +<plugin> + + <extension + point="org.eclipse.ui.views"> + <view + name="Server Cache" + icon="icons/sample.gif" + category="org.eclipse.wst.server.ui" + class="org.eclipse.wst.server.test.util.views.ServerCacheView" + id="org.eclipse.wst.server.test.util.views.ServerCacheView"> + </view> + </extension> + +</plugin>
diff --git a/tests/org.eclipse.wst.server.util.tests/src/org/eclipse/wst/server/test/util/Activator.java b/tests/org.eclipse.wst.server.util.tests/src/org/eclipse/wst/server/test/util/Activator.java new file mode 100644 index 0000000..6cb5379 --- /dev/null +++ b/tests/org.eclipse.wst.server.util.tests/src/org/eclipse/wst/server/test/util/Activator.java
@@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.server.test.util; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.wst.server.test.util"; //$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 --git a/tests/org.eclipse.wst.server.util.tests/src/org/eclipse/wst/server/test/util/views/ServerCacheView.java b/tests/org.eclipse.wst.server.util.tests/src/org/eclipse/wst/server/test/util/views/ServerCacheView.java new file mode 100644 index 0000000..7b430c5 --- /dev/null +++ b/tests/org.eclipse.wst.server.util.tests/src/org/eclipse/wst/server/test/util/views/ServerCacheView.java
@@ -0,0 +1,385 @@ +/******************************************************************************* + * Copyright (c) 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.wst.server.test.util.views; + +import java.util.ArrayList; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerSorter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.part.DrillDownAdapter; +import org.eclipse.ui.part.ViewPart; +import org.eclipse.wst.server.core.IModule; +import org.eclipse.wst.server.core.IServer; +import org.eclipse.wst.server.core.ServerCore; +import org.eclipse.wst.server.core.ServerUtil; +import org.eclipse.wst.server.core.internal.Module; +import org.eclipse.wst.server.core.internal.Server; +import org.eclipse.wst.server.core.model.IModuleFile; +import org.eclipse.wst.server.core.model.IModuleFolder; +import org.eclipse.wst.server.core.model.IModuleResource; +import org.eclipse.wst.server.core.util.ProjectModule; + + +/** + * 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. + * <p> + * 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. + * <p> + */ + +public class ServerCacheView extends ViewPart { + + /** + * The ID of the view as specified by the extension. + */ + public static final String ID = "org.eclipse.wst.server.test.util.views.ServerCacheView"; + + private TreeViewer viewer; + private DrillDownAdapter drillDownAdapter; + private Action action1; + private Action action2; + private Action doubleClickAction; + + /* + * The content provider class is responsible for + * providing objects to the view. It can wrap + * existing objects in adapters or simply return + * objects as-is. These objects may be sensitive + * to the current input of the view, or ignore + * it and always show the same content + * (like Task List, for example). + */ + + class TreeObject implements IAdaptable { + private String name; + private TreeParent parent; + + public TreeObject(String name) { + this.name = name; + } + public String getName() { + return name; + } + public void setParent(TreeParent parent) { + this.parent = parent; + } + public TreeParent getParent() { + return parent; + } + public String toString() { + return getName(); + } + public Object getAdapter(Class key) { + if (key.equals(IServer.class)){ + return ServerCore.findServer(name); + } + else if (key.equals(IModule.class)){ + return ServerUtil.getModule(name); + } + return null; + } + public boolean equals(Object o){ + if (o instanceof IModule || o instanceof Module){ + return (this.name.equalsIgnoreCase(((Module)o).getId())); + } + else if (o instanceof TreeObject){ + return (this.name.equalsIgnoreCase(((TreeObject)o).name)); + } + + return false; + } + } + + class TreeParent extends TreeObject { + private ArrayList children; + public TreeParent(String name) { + super(name); + children = new ArrayList(); + } + public void addChild(TreeObject child) { + children.add(child); + child.setParent(this); + } + public void removeChild(TreeObject child) { + children.remove(child); + child.setParent(null); + } + public TreeObject [] getChildren() { + // If this is a server, return the modules + if (super.getAdapter(IServer.class)!= null){ + Server server = (Server)super.getAdapter(IServer.class); + IModule[] modules = server.getModules(); + for (IModule module : modules){ + TreeParent mElement = new TreeParent(module.getId()); + if (!children.contains(mElement)) + addChild(mElement); + } + return (TreeParent [])children.toArray(new TreeParent[children.size()]); + } + // if this is a module + else if (super.getAdapter(IModule.class)!= null){ + Module module = (Module)super.getAdapter(IModule.class); + // Add the child modules + IModule[] modules = module.getChildModules(null); + for (IModule m : modules){ + TreeParent mElement = new TreeParent(m.getId()); + if (!children.contains(mElement)) + addChild(mElement); + } + // Add the members + ProjectModule pm = (ProjectModule)module.getAdapter(ProjectModule.class); + try{ + IModuleResource[] members = pm.members(); + for (IModuleResource r: members){ + // Check if it is a folder + if (r instanceof IModuleFolder){ + TreeParent mElement = new TreeParent("Folder: "+r.getName()); + if (!children.contains(mElement)) + addChild(mElement); + } + // If it isn't not a folder, assuming is a file + else { + TreeObject mElement = new TreeObject(r.getName()); + if (!children.contains(mElement)) + addChild(mElement); + } + } + } + catch (CoreException e){ + // In case of exception add a child with the error message + TreeObject errElement= new TreeObject("Unable to retrieve members due to: "+e.getMessage()); + addChild(errElement); + } + + return (TreeObject[])children.toArray(new TreeObject[children.size()]); + } + + + return (TreeParent [])children.toArray(new TreeParent[children.size()]); + } + public boolean hasChildren() { + return getChildren().length > 0; + } + } + + class ViewContentProvider implements IStructuredContentProvider, + ITreeContentProvider { + private TreeParent invisibleRoot; + + public void inputChanged(Viewer v, Object oldInput, Object newInput) { + } + public void dispose() { + } + public Object[] getElements(Object parent) { + if (parent.equals(getViewSite())) { + if (invisibleRoot==null) initialize(); + return getChildren(invisibleRoot); + } + return getChildren(parent); + } + public Object getParent(Object child) { + if (child instanceof TreeObject) { + return ((TreeObject)child).getParent(); + } + return null; + } + public Object [] getChildren(Object parent) { + if (parent instanceof TreeParent) { + return ((TreeParent)parent).getChildren(); + } + return new Object[0]; + } + public boolean hasChildren(Object parent) { + if (parent instanceof TreeParent) + return ((TreeParent)parent).hasChildren(); + return false; + } +/* + * We will set up a dummy model to initialize tree heararchy. + * In a real code, you will connect to a real model and + * expose its hierarchy. + */ + private void initialize() { + invisibleRoot = new TreeParent(""); + + IServer[] servers = ServerCore.getServers(); + + for (IServer server:servers){ + invisibleRoot.addChild(new TreeParent(server.getName())); + } + } + } + class ViewLabelProvider extends LabelProvider { + + public String getText(Object obj) { + return obj.toString(); + } + public Image getImage(Object obj) { + String imageKey = ISharedImages.IMG_OBJ_ELEMENT; + if (obj instanceof TreeParent) + imageKey = ISharedImages.IMG_OBJ_FOLDER; + return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey); + } + } + class NameSorter extends ViewerSorter { + } + + /** + * The constructor. + */ + public ServerCacheView() { + } + + /** + * This is a callback that will allow us + * to create the viewer and initialize it. + */ + public void createPartControl(Composite parent) { + viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); + drillDownAdapter = new DrillDownAdapter(viewer); + viewer.setContentProvider(new ViewContentProvider()); + viewer.setLabelProvider(new ViewLabelProvider()); + viewer.setSorter(new NameSorter()); + viewer.setInput(getViewSite()); + makeActions(); + hookContextMenu(); + hookDoubleClickAction(); + contributeToActionBars(); + } + + private void hookContextMenu() { + MenuManager menuMgr = new MenuManager("#PopupMenu"); + menuMgr.setRemoveAllWhenShown(true); + menuMgr.addMenuListener(new IMenuListener() { + public void menuAboutToShow(IMenuManager manager) { + ServerCacheView.this.fillContextMenu(manager); + } + }); + Menu menu = menuMgr.createContextMenu(viewer.getControl()); + viewer.getControl().setMenu(menu); + getSite().registerContextMenu(menuMgr, viewer); + } + + private void contributeToActionBars() { + IActionBars bars = getViewSite().getActionBars(); + fillLocalPullDown(bars.getMenuManager()); + fillLocalToolBar(bars.getToolBarManager()); + } + + private void fillLocalPullDown(IMenuManager manager) { + manager.add(action1); + manager.add(new Separator()); + manager.add(action2); + } + + private void fillContextMenu(IMenuManager manager) { + manager.add(action1); + manager.add(action2); + manager.add(new Separator()); + drillDownAdapter.addNavigationActions(manager); + // Other plug-ins can contribute there actions here + manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); + } + + private void fillLocalToolBar(IToolBarManager manager) { + manager.add(action1); + manager.add(action2); + manager.add(new Separator()); + drillDownAdapter.addNavigationActions(manager); + } + + private void makeActions() { + action1 = new Action() { + public void run() { + showMessage("Action 1 executed"); + } + }; + action1.setText("Action 1"); + action1.setToolTipText("Action 1 tooltip"); + action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages(). + getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); + + action2 = new Action() { + public void run() { + showMessage("Action 2 executed"); + } + }; + action2.setText("Action 2"); + action2.setToolTipText("Action 2 tooltip"); + action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages(). + getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); + doubleClickAction = new Action() { + public void run() { + ISelection selection = viewer.getSelection(); + Object obj = ((IStructuredSelection)selection).getFirstElement(); + showMessage("Double-click detected on "+obj.toString()); + } + }; + } + + private void hookDoubleClickAction() { + viewer.addDoubleClickListener(new IDoubleClickListener() { + public void doubleClick(DoubleClickEvent event) { + doubleClickAction.run(); + } + }); + } + private void showMessage(String message) { + MessageDialog.openInformation( + viewer.getControl().getShell(), + "Server Cache", + message); + } + + /** + * Passing the focus request to the viewer's control. + */ + public void setFocus() { + viewer.getControl().setFocus(); + } +} \ No newline at end of file