1 package com.generalrobotix.ui.grxui;
4 import java.io.IOException;
5 import java.io.RandomAccessFile;
6 import java.nio.channels.OverlappingFileLockException;
9 import java.text.SimpleDateFormat;
11 import org.eclipse.core.runtime.FileLocator;
12 import org.eclipse.jface.preference.IPreferenceStore;
13 import org.eclipse.jface.preference.PreferenceConverter;
14 import org.eclipse.jface.resource.ColorRegistry;
15 import org.eclipse.jface.resource.FontRegistry;
16 import org.eclipse.jface.resource.ImageDescriptor;
17 import org.eclipse.jface.resource.ImageRegistry;
18 import org.eclipse.jface.resource.StringConverter;
19 import org.eclipse.jface.dialogs.MessageDialog;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.graphics.Color;
22 import org.eclipse.swt.graphics.Font;
23 import org.eclipse.swt.graphics.FontData;
24 import org.eclipse.swt.graphics.Image;
25 import org.eclipse.swt.graphics.RGB;
26 import org.eclipse.swt.widgets.Display;
27 import org.eclipse.ui.IPerspectiveDescriptor;
28 import org.eclipse.ui.IPerspectiveListener;
29 import org.eclipse.ui.IPerspectiveRegistry;
30 import org.eclipse.ui.IWindowListener;
31 import org.eclipse.ui.IWorkbench;
32 import org.eclipse.ui.IWorkbenchListener;
33 import org.eclipse.ui.IWorkbenchPage;
34 import org.eclipse.ui.IWorkbenchWindow;
35 import org.eclipse.ui.PerspectiveAdapter;
36 import org.eclipse.ui.PlatformUI;
37 import org.eclipse.ui.plugin.AbstractUIPlugin;
38 import org.eclipse.ui.preferences.ScopedPreferenceStore;
40 import org.osgi.framework.BundleContext;
41 import org.osgi.framework.BundleEvent;
42 import org.osgi.framework.FrameworkEvent;
43 import org.osgi.framework.FrameworkListener;
44 import org.osgi.framework.SynchronousBundleListener;
58 public class Activator extends AbstractUIPlugin implements IWorkbenchListener, IWindowListener, IPerspectiveListener{
59 public static final String
PLUGIN_ID =
"com.generalrobotix.ui.grxui";
63 private static final String
LINUX_TMP_DIR = LINUX_HOME_DIR +
".OpenHRP-3.1" +
File.separator;
64 private static final String
WIN_TMP_DIR = WIN_HOME_DIR +
"OpenHRP-3.1" +
File.separator;
73 private final static String[]
images_ = {
"save_edit.png",
77 "sim_script_start.png",
78 "sim_script_stop.png",
80 "robot_servo_start.png",
81 "robot_servo_stop.png",
97 private SimpleDateFormat
dateFormat_ =
new SimpleDateFormat(
"yyyyMMdd HH:mm:ss.SSS z Z");
103 public boolean preShutdown(IWorkbench workbench,
boolean forced) {
105 IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
106 for(IWorkbenchWindow window : windows){
107 IWorkbenchPage[] pages = window.getPages();
108 for(IWorkbenchPage page : pages){
109 IPerspectiveDescriptor[] perspectives = page.getOpenPerspectives();
110 for(IPerspectiveDescriptor perspective : perspectives){
112 page.closePerspective(perspective,
false,
false);
116 IPerspectiveRegistry perspectiveRegistry=workbench.getPerspectiveRegistry();
119 perspectiveRegistry.deletePerspective(tempPd);
120 }
catch (Exception ex) {
121 ex.printStackTrace();
131 window.removePerspectiveListener(
this);
138 window.addPerspectiveListener(
this);
143 IPerspectiveDescriptor perspective) {
144 if(!initProjectLoad_)
150 if(!initProjectLoad_){
151 initProjectLoad_ =
true;
157 IPerspectiveDescriptor perspective, String changeId) {
161 System.out.println(
"[ACTIVATOR] CONSTRUCT");
167 public void start(BundleContext context)
169 super.start(context);
176 URL cur_url = cur.toURI().toURL();
180 if(PlatformUI.isWorkbenchRunning()){
181 IWorkbench workbench = PlatformUI.getWorkbench();
182 workbench.addWorkbenchListener(
this);
183 workbench.addWindowListener(
this);
184 IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
186 window.addPerspectiveListener(
this);
191 if( lockFile_ ==
null ){
194 }
catch (Exception ex) {
195 ex.printStackTrace();
204 ireg_ =
new ImageRegistry();
205 for(
int i=0;
i<images_.length;
i++){
206 URL url = getClass().getResource(
"/resources/images/"+images_[
i]);
207 ireg_.put(images_[i], ImageDescriptor.createFromURL(url));
213 freg_ =
new FontRegistry();
214 FontData[] monospaced = {
new FontData(
"monospaced", 10, SWT.NORMAL)};
215 freg_.put(
"monospaced", monospaced);
216 FontData[] dialog10 = {
new FontData(
"dialog", 10, SWT.NORMAL )};
217 freg_.put(
"dialog10", dialog10);
218 FontData[] dialog12 = {
new FontData(
"dialog", 12, SWT.NORMAL )};
219 freg_.put(
"dialog12", dialog12);
228 IPreferenceStore store = getPreferenceStore();
230 freg_.put(
"preference_table", table);
232 FontData[] normal = table.clone();
233 for (
int i=0;
i<table.length;
i++) {
234 normal[
i] =
new FontData(table[
i].getName(), table[
i].getHeight(), SWT.NORMAL);
236 freg_.put(
"robot_state_plain", normal);
238 FontData[] bold = table.clone();
239 for (
int i=0;
i<bold.length;
i++) {
240 bold[
i] =
new FontData(table[
i].getName(), table[
i].getHeight(), SWT.NORMAL);
242 freg_.put(
"robot_state_bold", bold);
249 IPreferenceStore store = getPreferenceStore();
251 freg_.put(
"preference_editer", editer);
255 creg_ =
new ColorRegistry();
256 RGB focusedColor =
new RGB(0,0,100);
257 setColor(
"focusedColor", focusedColor);
258 RGB markerColor =
new RGB(255,128,128);
259 setColor(
"markerColor", markerColor);
260 RGB
green = Display.getDefault().getSystemColor(SWT.COLOR_GREEN).getRGB();
262 RGB yellow = Display.getDefault().getSystemColor(SWT.COLOR_YELLOW).getRGB();
264 RGB cyan = Display.getDefault().getSystemColor(SWT.COLOR_CYAN).getRGB();
265 creg_.put(
"cyan", cyan);
266 RGB magenta = Display.getDefault().getSystemColor(SWT.COLOR_MAGENTA).getRGB();
268 RGB
red = Display.getDefault().getSystemColor(SWT.COLOR_RED).getRGB();
270 RGB blue = Display.getDefault().getSystemColor(SWT.COLOR_BLUE).getRGB();
272 RGB black = Display.getDefault().getSystemColor(SWT.COLOR_BLACK).getRGB();
274 RGB gray = Display.getDefault().getSystemColor(SWT.COLOR_GRAY).getRGB();
276 RGB darkGray = Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY).getRGB();
278 RGB white = Display.getDefault().getSystemColor(SWT.COLOR_WHITE).getRGB();
289 URL entry =
getDefault().getBundle().getEntry(
"/");
290 String pluginDirectory =
"";
292 pluginDirectory = FileLocator.resolve(entry).
getPath();
293 }
catch (IOException e) {
296 return pluginDirectory;
332 public static void refNSHostPort(StringBuffer nsHost, StringBuffer nsPort) {
333 if (nsHost.length() == 0){
336 if (nsPort.length() == 0){
343 return ireg_.get(iconName);
348 return ireg_.getDescriptor(iconName);
352 return freg_.get(fontName);
356 String s=StringConverter.asString(rgb);
357 Color color = creg_.get(s);
364 Color color = creg_.get(colorName);
366 color = creg_.get(
"white");
371 creg_.put(colorName, rgb);
380 public void stop(BundleContext context)
387 if( !bStartedGrxUI_ ) {
392 bStartedGrxUI_ =
true;
404 ScopedPreferenceStore store = (ScopedPreferenceStore)plugin.getPreferenceStore();
407 }
catch (IOException e) {
410 bStartedGrxUI_ =
false;
427 String localStr =
"Start GrxUI:" +
428 dateFormat_.format(
new Date()) + System.getProperty(
"line.separator");
429 lockFile_ =
new RandomAccessFile(lockFilePath_,
"rwd");
431 if ( lockFile_.getChannel().tryLock() ==
null){
432 throw new OverlappingFileLockException();
434 lockFile_.seek(lockFile_.length());
435 lockFile_.write(localStr.getBytes());
436 }
catch(Exception eX){
437 eX.printStackTrace();
438 if(lockFile_ !=
null){
448 if(lockFile_ !=
null){
449 String localStr =
"End GrxUI:" +
450 dateFormat_.format(
new Date()) + System.getProperty(
"line.separator");
451 lockFile_.write(localStr.getBytes());
455 }
catch(Exception ex){
456 ex.printStackTrace();
460 public void breakStart(Exception eX, IPerspectiveDescriptor closeDesc ){
462 MessageDialog.openError(
463 Display.getDefault().getActiveShell(),
467 IWorkbench work = PlatformUI.getWorkbench();
468 IWorkbenchWindow wnd = work.getActiveWorkbenchWindow();
472 System.exit( PlatformUI.RETURN_UNSTARTABLE );
474 IWorkbenchPage page = wnd.getActivePage();
475 if(closeDesc ==
null){
477 closeDesc = page.getPerspective();
479 page.closePerspective(closeDesc,
false,
false);
480 for( IPerspectiveDescriptor
local : page.getOpenPerspectives()){
482 page.setPerspective(
local);
492 String dir = System.getenv(
"ROBOT_DIR");
493 if (dir !=
null &&
new File(dir).isDirectory()) {
496 if ( System.getProperty(
"os.name").equals(
"Linux") ||
497 System.getProperty(
"os.name").equals(
"Mac OS X")) {
498 ret =
new File(LINUX_TMP_DIR);
500 ret =
new File(WIN_TMP_DIR);
513 if ( System.getProperty(
"os.name").equals(
"Linux") ||
514 System.getProperty(
"os.name").equals(
"Mac OS X")) {
515 ret =
new File(LINUX_HOME_DIR);
517 ret =
new File(WIN_HOME_DIR);
531 }
catch (Exception ex) {
ColorRegistry getColorRegistry()
SimpleDateFormat dateFormat_
static final String LINUX_HOME_DIR
static final String PLUGIN_ID
static final String get(String key)
void breakStart(Exception eX, IPerspectiveDescriptor closeDesc)
void shutdown()
shutdown this manager
void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective)
#define null
our own NULL pointer
static synchronized void shutDown()
static final File TMP_DIR
void windowActivated(IWorkbenchWindow window)
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
ImageRegistry getImageRegistry()
static final String LINUX_TMP_DIR
FontRegistry getFontRegistry()
static String nsHost()
get hostname where naming server is running
static final File HOME_DIR
Image getImage(String iconName)
Color getColor(String colorName)
RandomAccessFile lockFile_
void loadInitialProject()
static final String FONT_TABLE
boolean preShutdown(IWorkbench workbench, boolean forced)
static Shell getCurrentShell()
static final File lockFilePath_
static Activator getDefault()
static final String WIN_HOME_DIR
static void refNSHostPort(StringBuffer nsHost, StringBuffer nsPort)
static void setDebugFlag(boolean flag)
static final String [] images_
static File initTempDir()
GrxBaseItem getItem(Class<? extends GrxBaseItem > cls, String name)
static void println(String s)
GrxPluginManager manager_
Font getFont(String fontName)
static org.omg.CORBA.Object getReference(String id)
get CORBA object which is associated with id
void loadInitialProject()
static int nsPort()
get port number where naming server is listening
void setColor(String colorName, RGB rgb)
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
Vector< ProcessInfo > getServerInfo()
vecServerInfoの取得
void postShutdown(IWorkbench workbench)
void start(BundleContext context)
static final String FONT_EDITER
void windowDeactivated(IWorkbenchWindow window)
static final String WIN_TMP_DIR
void windowClosed(IWorkbenchWindow window)
ImageDescriptor getDescriptor(String iconName)
void stop(BundleContext context)
void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, String changeId)
static File initHomeDir()
void windowOpened(IWorkbenchWindow window)