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