1 21 22 23 package org.apache.derby.ui.decorate; 24 25 import org.apache.derby.ui.DerbyPlugin; 26 import org.apache.derby.ui.common.CommonNames; 27 import org.apache.derby.ui.util.DerbyServerUtils; 28 import org.apache.derby.ui.util.Logger; 29 import org.apache.derby.ui.util.SelectionUtil; 30 import org.eclipse.core.resources.IProject; 31 import org.eclipse.core.runtime.CoreException; 32 import org.eclipse.core.runtime.IStatus; 33 import org.eclipse.core.runtime.Platform; 34 import org.eclipse.jdt.core.IJavaProject; 35 import org.eclipse.jface.resource.ImageDescriptor; 36 import org.eclipse.jface.viewers.IDecoration; 37 import org.eclipse.jface.viewers.ILightweightLabelDecorator; 38 import org.eclipse.jface.viewers.LabelProvider; 39 import org.eclipse.jface.viewers.LabelProviderChangedEvent; 40 import org.eclipse.swt.widgets.Display; 41 import org.eclipse.ui.IDecoratorManager; 42 43 44 45 public class DerbyIsRunningDecorator extends LabelProvider 46 implements ILightweightLabelDecorator { 47 48 49 private static final ImageDescriptor derbyRunningImageDesc = ImageDescriptor. 50 createFromURL(Platform.getBundle(CommonNames.UI_PATH).getEntry("/icons/"+CommonNames.ISRUNNING+".gif")); 51 52 public void decorate(Object element, IDecoration decoration) { 53 IProject proj=null; 54 if(element instanceof IJavaProject){ 55 proj = ((IJavaProject)element).getProject(); 56 }else{ 57 proj=(IProject)element; 58 } 59 try { 60 if (DerbyServerUtils.getDefault().getRunning(proj)) { 61 decoration.addOverlay(derbyRunningImageDesc); 62 } 63 } 64 catch (CoreException ce) { 65 Logger.log(SelectionUtil.getStatusMessages(ce),IStatus.ERROR); 66 } 67 } 68 69 70 private void startUpdateDecor(IProject proj) { 71 final LabelProviderChangedEvent evnt = new LabelProviderChangedEvent(this, proj); 72 Display.getDefault().asyncExec(new Runnable () { 73 public void run() { 74 fireLabelProviderChanged(evnt); 75 } 76 }); 77 } 78 79 public static void performUpdateDecor(IProject proj) { 80 IDecoratorManager dm = DerbyPlugin.getDefault().getWorkbench().getDecoratorManager(); 81 DerbyIsRunningDecorator decorator = (DerbyIsRunningDecorator)dm.getBaseLabelProvider(CommonNames.RUNDECORATOR); 82 decorator.startUpdateDecor(proj); 83 } 84 85 } 86 | Popular Tags |