From: shleh Date: Sat, 18 Sep 2004 17:42:48 +0000 (+0000) Subject: new class to manage icons. Showing failures,etc on a test suite. X-Git-Url: http://git.phpeclipse.com?hp=a7b0b4971bb14df3cd35a3cd5a04c0f83df5be1c new class to manage icons. Showing failures,etc on a test suite. --- diff --git a/net.sourceforge.phpeclipse.phpunit/icons/start.gif b/net.sourceforge.phpeclipse.phpunit/icons/start.gif new file mode 100644 index 0000000..1486517 Binary files /dev/null and b/net.sourceforge.phpeclipse.phpunit/icons/start.gif differ diff --git a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitImages.java b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitImages.java new file mode 100644 index 0000000..006336a --- /dev/null +++ b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitImages.java @@ -0,0 +1,94 @@ +package net.sourceforge.phpeclipse.phpunit; + +import java.net.MalformedURLException; +import java.net.URL; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.swt.graphics.Image; + +public class PHPUnitImages { + + protected static final String NAME_PREFIX = + "net.sourceforge.phpeclipse.phpunit"; + protected static final int NAME_PREFIX_LENGTH = NAME_PREFIX.length(); + + protected static URL iconBaseURL; + + static { + String pathSuffix = "icons/"; + try { + iconBaseURL = + new URL( + PHPUnitPlugin.getDefault().getDescriptor().getInstallURL(), + pathSuffix); + } catch (MalformedURLException e) { + //PHPUnitPlugin.log(e); + e.printStackTrace(); + } + } + + protected static final ImageRegistry IMAGE_REGISTRY = new ImageRegistry(); + + /* + * Available cached Images in the Java plugin image registry. + */ + + public static final String IMG_SELECT_TEST_SUITE = + NAME_PREFIX + "tsuite.gif"; + public static final String IMG_RUN_TEST_SUITE = NAME_PREFIX + "start.gif"; + public static final String IMG_TEST_ERROR = NAME_PREFIX + "testerr.gif"; + public static final String IMG_TEST_FAILURE = NAME_PREFIX + "testfail.gif"; + public static final String IMG_TEST_PASS = NAME_PREFIX + "testok.gif"; + public static final String IMG_TEST_SUITE_ERROR = NAME_PREFIX + "tsuiteerror.gif"; + public static final String IMG_TEST_SUITE_PASS = NAME_PREFIX + "tsuiteok.gif"; + public static final String IMG_TEST_SUITE_FAILURE = NAME_PREFIX + "tsuitefail.gif"; + + + + + public static final ImageDescriptor DESC_SELECT_TEST_SUITE = createManaged(IMG_SELECT_TEST_SUITE); + public static final ImageDescriptor DESC_RUN_TEST_SUITE =createManaged(IMG_RUN_TEST_SUITE); + public static final ImageDescriptor DESC_TEST_ERROR = createManaged(IMG_TEST_ERROR); + public static final ImageDescriptor DESC_TEST_FAILURE = createManaged(IMG_TEST_FAILURE); + public static final ImageDescriptor DESC_TEST_PASS = createManaged(IMG_TEST_PASS); + public static final ImageDescriptor DESC_TEST_SUITE_ERROR = createManaged(IMG_TEST_SUITE_ERROR); + public static final ImageDescriptor DESC_TEST_SUITE_PASS = createManaged(IMG_TEST_SUITE_PASS); + public static final ImageDescriptor DESC_TEST_SUITE_FAILURE = createManaged(IMG_TEST_SUITE_FAILURE); + + /** + * Returns the image managed under the given key in this registry. + * + * @param key the image's key + * @return the image managed under the given key + */ + public static Image get(String key) { + return IMAGE_REGISTRY.get(key); + } + + public static ImageRegistry getImageRegistry() { + return IMAGE_REGISTRY; + } + + //---- Helper methods to access icons on the file system -------------------------------------- + + protected static ImageDescriptor createManaged(String name) { + try { + ImageDescriptor result = + ImageDescriptor.createFromURL( + makeIconFileURL(name.substring(NAME_PREFIX_LENGTH))); + IMAGE_REGISTRY.put(name, result); + return result; + } catch (MalformedURLException e) { + return ImageDescriptor.getMissingImageDescriptor(); + } + } + + protected static URL makeIconFileURL(String name) + throws MalformedURLException { + if (iconBaseURL == null) + throw new MalformedURLException(); + + return new URL(iconBaseURL, name); + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitPlugin.java b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitPlugin.java index e3873a4..fb89999 100644 --- a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitPlugin.java +++ b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitPlugin.java @@ -6,15 +6,13 @@ */ package net.sourceforge.phpeclipse.phpunit; -import java.net.MalformedURLException; -import java.net.URL; import java.util.ResourceBundle; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPluginDescriptor; +import org.eclipse.core.runtime.Platform; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.plugin.AbstractUIPlugin; @@ -31,21 +29,42 @@ public class PHPUnitPlugin extends AbstractUIPlugin { private static PHPUnitPlugin plugin; private ResourceBundle resourceBundle; - + public static final String PLUGIN_ID= "net.sourceforge.phpeclipse.phpunit"; //$NON-NLS-1$ /** * @param descriptor */ public PHPUnitPlugin(IPluginDescriptor descriptor) { + super(descriptor); - plugin = this; - + System.out.println("desc: " + descriptor.getInstallURL()); + + + plugin= this; + + + String pathSuffix= "icons/"; //$NON-NLS-1$ + + System.out.println("" + Platform.getLocation()); + + System.out.println("" + Platform.getPluginStateLocation(plugin)); + + System.out.println("" + Platform.getLogFileLocation()); + + + } + public String getPath() { + return plugin.getDescriptor().getInstallURL().getFile(); + } + + + public static PHPUnitPlugin getDefault() { return plugin; } @@ -158,25 +177,6 @@ public class PHPUnitPlugin extends AbstractUIPlugin { super.startup(); } - /** - * @param string - */ - public static ImageDescriptor getImageDescriptor(String name) { - - String iconPath = "icons/"; - try { - URL installURL = getDefault().getDescriptor().getInstallURL(); - URL url = new URL(installURL, iconPath + name); - - System.out.println("url:" + url.toExternalForm()); - - return ImageDescriptor.createFromURL(url); - } catch (MalformedURLException e) { - // should not happen - return ImageDescriptor.getMissingImageDescriptor(); - } - - - } + } diff --git a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitView.java b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitView.java index 9f388dd..e304352 100644 --- a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitView.java +++ b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitView.java @@ -6,8 +6,6 @@ import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; import net.sourceforge.phpeclipse.phpunit.testpool.TestCase; import net.sourceforge.phpeclipse.phpunit.testpool.TestPool; @@ -15,8 +13,6 @@ import net.sourceforge.phpeclipse.phpunit.testpool.TestSuite; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; @@ -183,11 +179,6 @@ public class PHPUnitView extends ViewPart { final IActionBars actionBars = getViewSite().getActionBars(); IToolBarManager toolBarManager = actionBars.getToolBarManager(); - String iconsPath = "C:\\Documents and Settings\\Ali Echihabi\\My Documents\\workspace.eclipse2.1\\net.sourceforge.phpeclipse.phpunit\\icons"; - - ImageDescriptor descriptor = null; - String icon = ""; - Action selectTestAction = new Action() { public void run() { @@ -195,16 +186,10 @@ public class PHPUnitView extends ViewPart { testSuiteToRun = dialog.open(); } }; + selectTestAction.setText("Select Test Suite"); - selectTestAction.setToolTipText("Select Test Suite"); - try { - icon = "tsuite.gif"; - descriptor = ImageDescriptor.createFromURL(new URL("file://" + iconsPath + "//" + icon)); - selectTestAction.setImageDescriptor(descriptor); - } catch (MalformedURLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + selectTestAction.setToolTipText("Select Test Suite"); + selectTestAction.setImageDescriptor(PHPUnitImages.DESC_SELECT_TEST_SUITE); toolBarManager.add(selectTestAction); @@ -228,18 +213,11 @@ public class PHPUnitView extends ViewPart { } }; + startTestAction.setText("Start Test"); startTestAction.setToolTipText("Start Test Suite"); - - try { - icon = "start.gif"; - descriptor = ImageDescriptor.createFromURL(new URL("file://" + iconsPath + "//" + icon)); - startTestAction.setImageDescriptor(descriptor); - } catch (MalformedURLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - + startTestAction.setImageDescriptor(PHPUnitImages.DESC_RUN_TEST_SUITE); + toolBarManager.add(startTestAction); } @@ -275,29 +253,7 @@ public class PHPUnitView extends ViewPart { } - // action to start tests: - public void startTests() throws IOException { - -// // preparation: -// // take the full test suite (could containt other test suites). -// // create temp php file that starts that suite and uses socketTestReport -// // as a test result reporter. -// // add listener: localhost , port 13579 -// // start listening at port. -// -// testPool = new TestPool("RUN MONDAY 11:15 PM"); -// listenForReports(); -// -// try { -// Runtime.getRuntime().exec("php.exe \"C:/Program Files/Apache Group/Apache2/htdocs/phpUnit/suite.php\""); -// } catch (Exception e) { -// -// e.printStackTrace(); -// } - - startTests("C:/Program Files/Apache Group/Apache2/htdocs/phpUnit/suite.php"); - } public void startTests(String testSuite) throws IOException { @@ -322,7 +278,10 @@ public class PHPUnitView extends ViewPart { out.write("