]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/ContributedCleanUpTabPage.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / internal / ui / preferences / cleanup / ContributedCleanUpTabPage.java
CommitLineData
1b2798f6
EK
1/*******************************************************************************
2 * Copyright (c) 2008, 2012 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.preferences.cleanup;
12
13import java.util.Map;
14
15import org.eclipse.swt.SWT;
16import org.eclipse.swt.layout.GridData;
17import org.eclipse.swt.layout.GridLayout;
18import org.eclipse.swt.widgets.Composite;
19import org.eclipse.swt.widgets.Label;
20
21import org.eclipse.core.runtime.Assert;
22import org.eclipse.core.runtime.ISafeRunnable;
23import org.eclipse.core.runtime.SafeRunner;
24
25import org.eclipse.jdt.ui.cleanup.CleanUpOptions;
26import org.eclipse.jdt.ui.cleanup.ICleanUpConfigurationUI;
27
28import org.eclipse.jdt.internal.ui.JavaPlugin;
29
30/**
31 * @since 3.5
32 */
33public class ContributedCleanUpTabPage extends CleanUpTabPage {
34
35 private final ICleanUpConfigurationUI fContribution;
36
37 public ContributedCleanUpTabPage(ICleanUpConfigurationUI contribution) {
38 fContribution= contribution;
39 }
40
41 /*
42 * @see org.eclipse.jdt.internal.ui.preferences.cleanup.CleanUpTabPage#setWorkingValues(java.util.Map)
43 */
44 @Override
45 public void setWorkingValues(Map<String, String> workingValues) {
46 super.setWorkingValues(workingValues);
47
48 final CleanUpOptions options= new CleanUpOptions(workingValues) {
49 /*
50 * @see org.eclipse.jdt.internal.ui.fix.CleanUpOptions#setOption(java.lang.String, java.lang.String)
51 */
52 @Override
53 public void setOption(String key, String value) {
54 super.setOption(key, value);
55
56 doUpdatePreview();
57 notifyValuesModified();
58 }
59 };
60 SafeRunner.run(new ISafeRunnable() {
61 public void handleException(Throwable exception) {
62 ContributedCleanUpTabPage.this.handleException(exception);
63 }
64
65 public void run() throws Exception {
66 fContribution.setOptions(options);
67 }
68 });
69 }
70
71 /*
72 * @see org.eclipse.jdt.internal.ui.preferences.cleanup.ICleanUpTabPage#setOptions(org.eclipse.jdt.internal.ui.fix.CleanUpOptions)
73 */
74 public void setOptions(CleanUpOptions options) {
75 }
76
77 /*
78 * @see org.eclipse.jdt.internal.ui.preferences.formatter.ModifyDialogTabPage#doCreatePreferences(org.eclipse.swt.widgets.Composite, int)
79 */
80 @Override
81 protected void doCreatePreferences(Composite composite, int numColumns) {
82 final Composite parent= new Composite(composite, SWT.NONE);
83 GridData layoutData= new GridData(SWT.FILL, SWT.FILL, true, true);
84 layoutData.horizontalSpan= numColumns;
85 parent.setLayoutData(layoutData);
86 GridLayout layout= new GridLayout(1, false);
87 layout.marginHeight= 0;
88 layout.marginWidth= 0;
89 parent.setLayout(layout);
90
91 SafeRunner.run(new ISafeRunnable() {
92 public void handleException(Throwable exception) {
93 ContributedCleanUpTabPage.this.handleException(exception);
94
95 Label label= new Label(parent, SWT.NONE);
96 label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
97 label.setText(CleanUpMessages.ContributedCleanUpTabPage_ErrorPage_message);
98 }
99
100 public void run() throws Exception {
101 fContribution.createContents(parent);
102 }
103 });
104 }
105
106 /*
107 * @see org.eclipse.jdt.internal.ui.preferences.cleanup.ICleanUpTabPage#getPreview()
108 */
109 public String getPreview() {
110 final String[] result= new String[] { "" }; //$NON-NLS-1$
111 SafeRunner.run(new ISafeRunnable() {
112 public void handleException(Throwable exception) {
113 ContributedCleanUpTabPage.this.handleException(exception);
114 }
115
116 public void run() throws Exception {
117 result[0]= fContribution.getPreview();
118 }
119 });
120 return result[0];
121 }
122
123 /*
124 * @see org.eclipse.jdt.internal.ui.preferences.cleanup.CleanUpTabPage#getSelectedCleanUpCount()
125 */
126 @Override
127 public int getSelectedCleanUpCount() {
128 final int[] result= new int[] { 0 };
129 SafeRunner.run(new ISafeRunnable() {
130 public void handleException(Throwable exception) {
131 ContributedCleanUpTabPage.this.handleException(exception);
132 }
133
134 public void run() throws Exception {
135 int count= fContribution.getSelectedCleanUpCount();
136 Assert.isTrue(count >= 0 && count <= getCleanUpCount());
137 result[0]= count;
138 }
139 });
140 return result[0];
141 }
142
143 /*
144 * @see org.eclipse.jdt.internal.ui.preferences.cleanup.CleanUpTabPage#getCleanUpCount()
145 */
146 @Override
147 public int getCleanUpCount() {
148 final int[] result= new int[] { 0 };
149 SafeRunner.run(new ISafeRunnable() {
150 public void handleException(Throwable exception) {
151 ContributedCleanUpTabPage.this.handleException(exception);
152 }
153
154 public void run() throws Exception {
155 result[0]= fContribution.getCleanUpCount();
156 }
157 });
158 return result[0];
159 }
160
161 private void handleException(Throwable exception) {
162 JavaPlugin.log(exception);
163 }
164
165}