KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > part > services > StatusLineManagerAdapter


1 /*******************************************************************************
2  * Copyright (c) 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.part.services;
12
13 import org.eclipse.core.runtime.IProgressMonitor;
14 import org.eclipse.core.runtime.NullProgressMonitor;
15 import org.eclipse.jface.action.IStatusLineManager;
16 import org.eclipse.jface.resource.ImageDescriptor;
17 import org.eclipse.swt.graphics.Image;
18 import org.eclipse.ui.internal.part.components.services.IStatusFactory;
19 import org.eclipse.ui.internal.part.components.services.IStatusHandler;
20
21 /**
22  * TODO: fix progress reporting and actual contribution items
23  *
24  * @since 3.1
25  */

26 public class StatusLineManagerAdapter extends NullContributionManager implements
27     IStatusLineManager {
28
29     private IStatusHandler handler;
30     private IStatusFactory factory;
31     
32     private String JavaDoc currentError;
33     private Image currentErrorImage;
34     private String JavaDoc currentMessage;
35     private Image currentMessageImage;
36     
37     public StatusLineManagerAdapter(IStatusHandler handler, IStatusFactory factory) {
38         this.handler = handler;
39         this.factory = factory;
40     }
41     
42     public IProgressMonitor getProgressMonitor() {
43         return new NullProgressMonitor();
44     }
45
46     public boolean isCancelEnabled() {
47         return false;
48     }
49
50     public void setCancelEnabled(boolean enabled) {
51     }
52
53     public void setErrorMessage(String JavaDoc message) {
54         setErrorMessage(null, message);
55     }
56
57     public void setErrorMessage(Image image, String JavaDoc message) {
58         currentErrorImage = image;
59         currentError = message;
60         updateHandler();
61     }
62
63     public void setMessage(String JavaDoc message) {
64         setMessage(null, message);
65     }
66
67     public void setMessage(Image image, String JavaDoc message) {
68         currentMessageImage = image;
69         currentMessage = message;
70         updateHandler();
71     }
72     
73     private void updateHandler() {
74         if (currentError != null) {
75             handler.set(factory.newError(currentError, null), currentErrorImage == null ? null :
76                     ImageDescriptor.createFromImage(currentErrorImage));
77             return;
78         }
79         
80         if (currentMessage != null) {
81             handler.set(factory.newMessage(currentMessage), currentMessageImage == null ? null :
82                 ImageDescriptor.createFromImage(currentMessageImage));
83             return;
84         }
85         
86         handler.set(null, null);
87     }
88
89 }
90
Popular Tags