KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > progress > StatusAdapterHelper


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

11
12 package org.eclipse.ui.internal.progress;
13
14 import java.util.HashMap JavaDoc;
15
16 import org.eclipse.ui.progress.IProgressConstants;
17 import org.eclipse.ui.statushandlers.StatusAdapter;
18
19 /**
20  * StatusAdapterHelper is a class for caching {@link StatusAdapter} instances to make sure
21  * they are not created twice within the progress service.
22  * @since 3.3
23  */

24 public class StatusAdapterHelper {
25     private static StatusAdapterHelper instance;
26
27     private HashMap JavaDoc map;
28
29     private StatusAdapterHelper() {
30     }
31
32     /**
33      * Return the singleton.
34      * @return StatusAdapterHelper
35      */

36     public static StatusAdapterHelper getInstance() {
37         if (instance == null) {
38             instance = new StatusAdapterHelper();
39         }
40         return instance;
41     }
42
43     /**
44      * Set the {@link StatusAdapter} for the {@link JobInfo}
45      * @param info
46      * @param statusAdapter
47      */

48     public void putStatusAdapter(JobInfo info, StatusAdapter statusAdapter) {
49         if (map == null) {
50             map = new HashMap JavaDoc();
51         }
52         map.put(info, statusAdapter);
53     }
54
55     /**
56      * Return the adapter for this info.
57      * @param info
58      * @return
59      */

60     public StatusAdapter getStatusAdapter(JobInfo info) {
61         if (map == null) {
62             return null;
63         }
64         StatusAdapter statusAdapter = (StatusAdapter) map.remove(info);
65         statusAdapter.setProperty(
66                 IProgressConstants.NO_IMMEDIATE_ERROR_PROMPT_PROPERTY,
67                 Boolean.FALSE);
68         return statusAdapter;
69     }
70
71     public void clear() {
72         if (map != null) {
73             map.clear();
74         }
75     }
76 }
77
Popular Tags