KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > ui > decorate > DerbyIsRunningDecorator


1 /*
2
3     Derby - Class org.apache.derby.ui.decorator.DerbyIsRunningDecorator
4     
5     Licensed to the Apache Software Foundation (ASF) under one or more
6     contributor license agreements. See the NOTICE file distributed with
7     this work for additional information regarding copyright ownership.
8     The ASF licenses this file to you under the Apache License, Version 2.0
9     (the "License"); you may not use this file except in compliance with
10     the License. You may obtain a copy of the License at
11     
12        http://www.apache.org/licenses/LICENSE-2.0
13     
14     Unless required by applicable law or agreed to in writing, software
15     distributed under the License is distributed on an "AS IS" BASIS,
16     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17     See the License for the specific language governing permissions and
18     limitations under the License.
19
20 */

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 JavaDoc 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 JavaDoc() {
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