]> git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/SlcIdeUiPlugin.java
088b4f48b56cab5f9478fe921f01c53723e5611c
[gpl/argeo-slc.git] / plugins / org.argeo.slc.ide.ui / src / main / java / org / argeo / slc / ide / ui / SlcIdeUiPlugin.java
1 package org.argeo.slc.ide.ui;
2
3 import java.net.URL;
4
5 import org.eclipse.core.resources.IResource;
6 import org.eclipse.core.runtime.CoreException;
7 import org.eclipse.debug.core.DebugEvent;
8 import org.eclipse.debug.core.DebugPlugin;
9 import org.eclipse.debug.core.IDebugEventSetListener;
10 import org.eclipse.debug.core.ILaunch;
11 import org.eclipse.debug.core.model.IProcess;
12 import org.eclipse.jface.resource.ImageDescriptor;
13 import org.eclipse.jface.resource.ImageRegistry;
14 import org.eclipse.swt.graphics.Image;
15 import org.eclipse.ui.plugin.AbstractUIPlugin;
16 import org.osgi.framework.BundleContext;
17
18 /**
19 * The activator class controls the plug-in life cycle
20 */
21 public class SlcIdeUiPlugin extends AbstractUIPlugin {
22
23 // The plug-in ID
24 public static final String ID = "org.argeo.slc.ide.ui";
25
26 // The shared instance
27 private static SlcIdeUiPlugin plugin;
28
29 /**
30 * The constructor
31 */
32 public SlcIdeUiPlugin() {
33 }
34
35 @Override
36 public void start(BundleContext context) throws Exception {
37 super.start(context);
38 plugin = this;
39 DebugPlugin.getDefault()
40 .addDebugEventListener(new DebugEventListener());
41 }
42
43 @Override
44 public void stop(BundleContext context) throws Exception {
45 plugin = null;
46 super.stop(context);
47 }
48
49 /**
50 * Returns the shared instance
51 *
52 * @return the shared instance
53 */
54 public static SlcIdeUiPlugin getDefault() {
55 return plugin;
56 }
57
58 public Image getImage(String relativeURL) {
59 ImageRegistry imageRegistry = getImageRegistry();
60 Image image = imageRegistry.get(relativeURL);
61 if (image == null) {
62 URL imageURL = getBundle().getEntry(relativeURL);
63 ImageDescriptor descriptor = ImageDescriptor
64 .createFromURL(imageURL);
65 image = descriptor.createImage();
66 imageRegistry.put(relativeURL, image);
67 }
68 return image;
69 }
70
71 protected static class DebugEventListener implements IDebugEventSetListener {
72 public void handleDebugEvents(DebugEvent[] events) {
73 if (events == null)
74 return;
75
76 for (int i = 0; i < events.length; i++) {
77 DebugEvent event = events[i];
78 if (event == null)
79 continue;
80 Object source = event.getSource();
81 if (source instanceof IProcess
82 && event.getKind() == DebugEvent.TERMINATE) {
83 IProcess process = (IProcess) source;
84 if (process == null)
85 continue;
86 ILaunch launch = process.getLaunch();
87 if (launch != null)
88 refreshOsgiBootLaunch(launch);
89
90 }
91 }
92 }
93
94 protected void refreshOsgiBootLaunch(ILaunch launch) {
95 try {
96 if (launch == null)
97 return;
98 IResource[] resources = launch.getLaunchConfiguration()
99 .getMappedResources();
100 if (resources == null)
101 return;
102 if (resources.length > 0) {
103 IResource propertiesFile = resources[0];
104 if (propertiesFile.getParent() == null)
105 return;
106 propertiesFile.getParent().refreshLocal(
107 IResource.DEPTH_INFINITE, null);
108 // System.out.println("Refreshed "
109 // + propertiesFile.getParent());
110 }
111 } catch (CoreException e) {
112 e.printStackTrace();
113 }
114
115 }
116
117 }
118
119 }