KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > commands > operations > OperationHistoryFactory


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 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 package org.eclipse.core.commands.operations;
12
13 /**
14  * <p>
15  * This class is used to maintain the instance of the operation history that
16  * should be used by classes that access the undo or redo history and add
17  * undoable operations to the history.
18  *
19  * <p>
20  * It is intended that an application can create an operation history appropriate
21  * for its needs and set it into this class. Otherwise, a default operation history
22  * will be created. The operation history may only be set one time. All classes that
23  * access an operations history use this class to obtain the correct instance.
24  *
25  * @since 3.1
26  */

27 public final class OperationHistoryFactory {
28
29     private static IOperationHistory operationHistory;
30
31     /**
32      * Return the operation history to be used for managing undoable operations.
33      *
34      * @return the operation history to be used for executing, undoing, and
35      * redoing operations.
36      */

37     public static IOperationHistory getOperationHistory() {
38         if (operationHistory == null) {
39             operationHistory = new DefaultOperationHistory();
40         }
41         return operationHistory;
42     }
43
44     /**
45      * Set the operation history to be used for managing undoable operations.
46      * This method may only be called one time, and must be called before any
47      * request to get the history. Attempts to set the operation history will
48      * be ignored after it has been already set, or after a default one has
49      * been created.
50      *
51      * @param history
52      * the operation history to be used for executing, undoing, and
53      * redoing operations.
54      */

55     public static void setOperationHistory(IOperationHistory history) {
56         // If one has already been set or created, ignore this request.
57
if (operationHistory == null) {
58             operationHistory = history;
59         }
60     }
61     
62     private OperationHistoryFactory() {
63         // may not be instantiated
64
}
65
66 }
67
Popular Tags