]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-after/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/nls/MultiStateCellEditor.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui refactoring / org / eclipse / jdt / internal / ui / refactoring / nls / MultiStateCellEditor.java
CommitLineData
1b2798f6
EK
1/*******************************************************************************
2 * Copyright (c) 2000, 2011 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 *******************************************************************************/
11package org.eclipse.jdt.internal.ui.refactoring.nls;
12
13import org.eclipse.swt.widgets.Composite;
14import org.eclipse.swt.widgets.Control;
15
16import org.eclipse.core.runtime.Assert;
17
18import org.eclipse.jface.viewers.CellEditor;
19
20
21public class MultiStateCellEditor extends CellEditor {
22
23 private int fValue;
24 private final int fStateCount;
25
26 /**
27 * @param parent the parent
28 * @param stateCount must be > 1
29 * @param initialValue initialValue
30 */
31 public MultiStateCellEditor(Composite parent, int stateCount, int initialValue) {
32 super(parent);
33 Assert.isTrue(stateCount > 1, "incorrect state count"); //$NON-NLS-1$
34 fStateCount= stateCount;
35
36 Assert.isTrue(initialValue >= 0 && initialValue < stateCount, "incorrect initial value"); //$NON-NLS-1$
37 fValue= initialValue;
38
39 setValueValid(true);
40 }
41
42 /*
43 * @see org.eclipse.jface.viewers.CellEditor#activate()
44 */
45 @Override
46 public void activate() {
47 fValue= getNextValue(fStateCount, fValue);
48 fireApplyEditorValue();
49 }
50
51 public static int getNextValue(int stateCount, int currentValue){
52 Assert.isTrue(stateCount > 1, "incorrect state count"); //$NON-NLS-1$
53 Assert.isTrue(currentValue >= 0 && currentValue < stateCount, "incorrect initial value"); //$NON-NLS-1$
54 return (currentValue + 1) % stateCount;
55 }
56
57 /*
58 * @see org.eclipse.jface.viewers.CellEditor#createControl(org.eclipse.swt.widgets.Composite)
59 */
60 @Override
61 protected Control createControl(Composite parent) {
62 return null;
63 }
64
65 /*
66 * @see org.eclipse.jface.viewers.CellEditor#doGetValue()
67 * @return the Integer value
68 */
69 @Override
70 protected Object doGetValue() {
71 return new Integer(fValue);
72 }
73
74 /*
75 * @see org.eclipse.jface.viewers.CellEditor#doSetFocus()
76 */
77 @Override
78 protected void doSetFocus() {
79 // ignore
80 }
81
82 /*
83 * @see org.eclipse.jface.viewers.CellEditor#doSetValue(java.lang.Object)
84 * @param value an Integer value
85 * must be >=0 and < stateCount (value passed in the constructor)
86 */
87 @Override
88 protected void doSetValue(Object value) {
89 Assert.isTrue(value instanceof Integer, "value must be Integer"); //$NON-NLS-1$
90 fValue = ((Integer) value).intValue();
91 Assert.isTrue(fValue >= 0 && fValue < fStateCount, "invalid value"); //$NON-NLS-1$
92 }
93}