SCViewer/com.minres.scviewer.ui/src/com/minres/scviewer/ui/TxEditorPlugin.java

154 lines
4.4 KiB
Java

/*******************************************************************************
* Copyright (c) 2012 IT Just working.
* 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:
* IT Just working - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.ui;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.wb.swt.SWTResourceManager;
import org.osgi.framework.BundleContext;
import com.minres.scviewer.database.ITransactionDbFactory;
/**
* The activator class controls the plug-in life cycle
*/
public class TxEditorPlugin extends AbstractUIPlugin {
public static final int lineColor=0;
public static final int txBgColor=1;
public static final int highliteLineColor=2;
public static final int txHighliteBgColor=3;
public static final int trackBgLightColor=4;
public static final int trackBgDarkColor=5;
public static final int headerBgColor=6;
public static final int headerFgColor=7;
// The plug-in ID
public static final String PLUGIN_ID = "com.minres.scviewer.ui"; //$NON-NLS-1$
// The shared instance
private static TxEditorPlugin plugin;
private ResourceBundle resourceBundle;
/**
* The constructor
*/
// public TxEditorPlugin() {
// openedTxEditorPart=null;
// }
/*
* (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;
try {
resourceBundle = ResourceBundle.getBundle(plugin.getClass().getName());
} catch (MissingResourceException x) {
resourceBundle = null;
}
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
SWTResourceManager.dispose();
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static TxEditorPlugin 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) {
String fullpath = File.separator+"res"+File.separator+"images"+File.separator+path;
return imageDescriptorFromPlugin(PLUGIN_ID, fullpath);
}
public static Image createImage(String name) {
ImageDescriptor id=getImageDescriptor(name+".png");
return id.createImage();
}
public Color getColor(int idx){
switch (idx) {
case lineColor:
return SWTResourceManager.getColor(SWT.COLOR_RED);
case txBgColor:
return SWTResourceManager.getColor(SWT.COLOR_GREEN);
case highliteLineColor:
return SWTResourceManager.getColor(SWT.COLOR_CYAN);
case txHighliteBgColor:
return SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN);
case trackBgLightColor:
return SWTResourceManager.getColor(220, 220, 220);
case trackBgDarkColor:
return SWTResourceManager.getColor(200, 200, 200);
case headerBgColor:
return SWTResourceManager.getColor(255, 255, 255);
case headerFgColor:
return SWTResourceManager.getColor(55, 55, 55);
default:
break;
}
return SWTResourceManager.getColor(SWT.COLOR_BLACK);
}
public ResourceBundle getResourceBundle() {
return resourceBundle;
}
private ITransactionDbFactory transactionDbFactory;
private List<ITransactionDbFactory> factories= new ArrayList<ITransactionDbFactory>();
public ITransactionDbFactory getTransactionDbFactory() {
return transactionDbFactory;
}
public void setTransactionDbFactory(ITransactionDbFactory transactionDbFactory) {
factories.add( transactionDbFactory);
System.out.println("Service bound");
}
public void unsetTransactionDbFactory(ITransactionDbFactory transactionDbFactory) {
factories.remove(transactionDbFactory);
System.out.println("Service unbound");
}
}