KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > core > refactoring > RefactoringTickProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.ltk.core.refactoring;
12
13 import org.eclipse.core.runtime.Assert;
14 import org.eclipse.core.runtime.IProgressMonitor;
15
16 /**
17  * Implementors of refactorings uses instances of <code>RefactoringTickProvider</code>
18  * to specify the tick distribution during progress reporting when executing the
19  * check conditions, create change and change initialization steps.
20  *
21  * @since 3.2
22  */

23 public class RefactoringTickProvider {
24     
25     /**
26      * The default refactoring tick provider
27      */

28     public final static RefactoringTickProvider DEFAULT= new RefactoringTickProvider(4, 40, 22, 11);
29     
30     private int[] fValues;
31     
32     private static final int CHECK_INITIAL_CONDITIONS= 0;
33     private static final int CHECK_FINAL_CONDITIONS= 1;
34     private static final int CREATE_CHANGE= 2;
35     private static final int INITIALIZE_CHANGE= 3;
36     
37     /**
38      * Creates a new refactoring tick provider with the given values
39      *
40      * @param checkInitialConditionsTicks ticks used in the initial condition
41      * check step
42      * @param checkFinalConditionsTicks ticks used in the final condition
43      * check step
44      * @param createChangeTicks ticks used in the create change step
45      * @param initializeChangeTicks ticks used in the change validation steps
46      */

47     public RefactoringTickProvider(
48             int checkInitialConditionsTicks,
49             int checkFinalConditionsTicks,
50             int createChangeTicks,
51             int initializeChangeTicks) {
52         Assert.isTrue(checkInitialConditionsTicks >= 0 && checkFinalConditionsTicks >= 0 &&
53             createChangeTicks >= 0 && initializeChangeTicks >= 0);
54         
55         fValues= new int[4];
56         fValues[CHECK_INITIAL_CONDITIONS]= checkInitialConditionsTicks;
57         fValues[CHECK_FINAL_CONDITIONS]= checkFinalConditionsTicks;
58         fValues[CREATE_CHANGE]= createChangeTicks;
59         fValues[INITIALIZE_CHANGE]= initializeChangeTicks;
60     }
61     
62     /**
63      * Sum of <code>getCheckConditionsTicks</code>, <code>getCreateChangeTicks</code>
64      * and <code>getInitializeChangeTicks</code>.
65      *
66      * @return the number of ticks, >= 0
67      */

68     public int getAllTicks() {
69         return getCheckAllConditionsTicks() + fValues[CREATE_CHANGE] + fValues[INITIALIZE_CHANGE];
70     }
71     
72     /**
73      * Sum of <code>getCheckInitialConditionsTicks()</code> and
74      * <code>getCheckFinalConditionsTicks</code>
75      *
76      * @return the number of ticks, >= 0
77      */

78     public int getCheckAllConditionsTicks() {
79         return fValues[CHECK_INITIAL_CONDITIONS] + fValues[CHECK_FINAL_CONDITIONS];
80     }
81     
82     /**
83      * Number of ticks reserved in the parent progress monitor of the progress monitor
84      * passed to <code>Refactoring#checkInitialConditions()</code>.
85      *
86      * @return the number of ticks, >= 0
87      */

88     public int getCheckInitialConditionsTicks() {
89         return fValues[CHECK_INITIAL_CONDITIONS];
90     }
91     
92     /**
93      * Number of ticks reserved in the parent progress monitor of the progress monitor
94      * passed to <code>Refactoring#checkFinalConditions()</code>.
95      *
96      * @return the number of ticks, >= 0
97      */

98     public int getCheckFinalConditionsTicks() {
99         return fValues[CHECK_FINAL_CONDITIONS];
100     }
101
102     /**
103      * Number of ticks reserved in the parent progress monitor of the progress monitor
104      * passed to <code>Refactoring#createChange()</code>.
105      *
106      * @return the number of ticks, >= 0
107      */

108     public int getCreateChangeTicks() {
109         return fValues[CREATE_CHANGE];
110     }
111
112     /**
113      * Number of ticks reserved in the parent progress monitor for the progress monitor
114      * passed to <code>{@link Change#initializeValidationData(IProgressMonitor)}</code>
115      * which is executed on the object returned by <code>Refactoring#createChange()</code>.
116      *
117      * @return the number of ticks, >= 0
118      */

119     public int getInitializeChangeTicks() {
120         return fValues[INITIALIZE_CHANGE];
121     }
122 }
Popular Tags