01: /*******************************************************************************
02: * Copyright (c) 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: ******************************************************************************/package org.eclipse.ui.internal.progress;
11:
12: import java.util.HashMap;
13:
14: import org.eclipse.ui.progress.IProgressConstants;
15: import org.eclipse.ui.statushandlers.StatusAdapter;
16:
17: /**
18: * StatusAdapterHelper is a class for caching {@link StatusAdapter} instances to make sure
19: * they are not created twice within the progress service.
20: * @since 3.3
21: */
22: public class StatusAdapterHelper {
23: private static StatusAdapterHelper instance;
24:
25: private HashMap map;
26:
27: private StatusAdapterHelper() {
28: }
29:
30: /**
31: * Return the singleton.
32: * @return StatusAdapterHelper
33: */
34: public static StatusAdapterHelper getInstance() {
35: if (instance == null) {
36: instance = new StatusAdapterHelper();
37: }
38: return instance;
39: }
40:
41: /**
42: * Set the {@link StatusAdapter} for the {@link JobInfo}
43: * @param info
44: * @param statusAdapter
45: */
46: public void putStatusAdapter(JobInfo info,
47: StatusAdapter statusAdapter) {
48: if (map == null) {
49: map = new HashMap();
50: }
51: map.put(info, statusAdapter);
52: }
53:
54: /**
55: * Return the adapter for this info.
56: * @param info
57: * @return
58: */
59: public StatusAdapter getStatusAdapter(JobInfo info) {
60: if (map == null) {
61: return null;
62: }
63: StatusAdapter statusAdapter = (StatusAdapter) map.remove(info);
64: statusAdapter.setProperty(
65: IProgressConstants.NO_IMMEDIATE_ERROR_PROMPT_PROPERTY,
66: Boolean.FALSE);
67: return statusAdapter;
68: }
69:
70: public void clear() {
71: if (map != null) {
72: map.clear();
73: }
74: }
75: }
|