KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > internal > ui > refactoring > history > ShowRefactoringHistoryControl


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 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.internal.ui.refactoring.history;
12
13 import org.eclipse.core.runtime.Assert;
14
15 import org.eclipse.ltk.core.refactoring.history.RefactoringHistory;
16
17 import org.eclipse.ltk.internal.ui.refactoring.RefactoringUIMessages;
18 import org.eclipse.ltk.internal.ui.refactoring.util.PixelConverter;
19 import org.eclipse.ltk.internal.ui.refactoring.util.SWTUtil;
20
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.layout.GridData;
23 import org.eclipse.swt.layout.GridLayout;
24 import org.eclipse.swt.widgets.Button;
25 import org.eclipse.swt.widgets.Composite;
26
27 import org.eclipse.jface.dialogs.IDialogConstants;
28 import org.eclipse.jface.viewers.IStructuredSelection;
29 import org.eclipse.jface.viewers.TreeViewer;
30
31 import org.eclipse.ltk.ui.refactoring.history.RefactoringHistoryControlConfiguration;
32
33 /**
34  * Control which is capable of displaying and editing the global workspace
35  * refactoring history.
36  *
37  * @since 3.2
38  */

39 public class ShowRefactoringHistoryControl extends SortableRefactoringHistoryControl {
40
41     /** The delete all button, or <code>null</code> */
42     private Button fDeleteAllButton= null;
43
44     /** The delete button, or <code>null</code> */
45     private Button fDeleteButton= null;
46
47     /** The edit button, or <code>null</code> */
48     private Button fEditButton= null;
49
50     /**
51      * Creates a new show refactoring history control.
52      *
53      * @param parent
54      * the parent control
55      * @param configuration
56      * the refactoring history control configuration to use
57      */

58     public ShowRefactoringHistoryControl(final Composite parent, final RefactoringHistoryControlConfiguration configuration) {
59         super(parent, configuration);
60     }
61
62     /**
63      * {@inheritDoc}
64      */

65     protected void createBottomButtonBar(final Composite parent) {
66         // No button bar
67
}
68
69     /**
70      * {@inheritDoc}
71      */

72     public void createControl() {
73         super.createControl();
74         final GridData data= new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
75         data.heightHint= new PixelConverter(this).convertHeightInCharsToPixels(24);
76         setLayoutData(data);
77     }
78
79     /**
80      * Creates the delete all button of the control.
81      *
82      * @param parent
83      * the parent composite
84      */

85     protected void createDeleteAllButton(final Composite parent) {
86         Assert.isNotNull(parent);
87         fDeleteAllButton= new Button(parent, SWT.NONE);
88         fDeleteAllButton.setEnabled(false);
89         fDeleteAllButton.setText(RefactoringUIMessages.ShowRefactoringHistoryControl_delete_all_label);
90         final GridData data= new GridData();
91         data.horizontalAlignment= GridData.FILL;
92         data.grabExcessHorizontalSpace= true;
93         data.verticalAlignment= GridData.BEGINNING;
94         data.widthHint= SWTUtil.getButtonWidthHint(fDeleteAllButton);
95         fDeleteAllButton.setLayoutData(data);
96     }
97
98     /**
99      * Creates the delete button of the control.
100      *
101      * @param parent
102      * the parent composite
103      * @param alignment
104      * the alignment of the button
105      */

106     protected void createDeleteButton(final Composite parent, final int alignment) {
107         Assert.isNotNull(parent);
108         fDeleteButton= new Button(parent, SWT.NONE);
109         fDeleteButton.setEnabled(false);
110         fDeleteButton.setText(RefactoringUIMessages.ShowRefactoringHistoryControl_delete_label);
111         final GridData data= new GridData();
112         data.horizontalAlignment= alignment;
113         data.grabExcessHorizontalSpace= true;
114         data.verticalAlignment= GridData.BEGINNING;
115         data.widthHint= SWTUtil.getButtonWidthHint(fDeleteButton);
116         fDeleteButton.setLayoutData(data);
117     }
118
119     /**
120      * Creates the edit button of the control.
121      *
122      * @param parent
123      * the parent composite
124      */

125     protected void createEditButton(final Composite parent) {
126         Assert.isNotNull(parent);
127         fEditButton= new Button(parent, SWT.NONE);
128         fEditButton.setEnabled(false);
129         fEditButton.setText(RefactoringUIMessages.ShowRefactoringHistoryControl_edit_label);
130         final GridData data= new GridData();
131         data.verticalIndent= new PixelConverter(parent).convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
132         data.horizontalAlignment= GridData.FILL;
133         data.grabExcessHorizontalSpace= true;
134         data.verticalAlignment= GridData.BEGINNING;
135         data.widthHint= SWTUtil.getButtonWidthHint(fEditButton);
136         fEditButton.setLayoutData(data);
137     }
138
139     /**
140      * {@inheritDoc}
141      */

142     protected TreeViewer createHistoryViewer(final Composite parent) {
143         Assert.isNotNull(parent);
144         if (fControlConfiguration.isCheckableViewer())
145             return new RefactoringHistoryTreeViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI);
146         else
147             return new TreeViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI);
148     }
149
150     /**
151      * {@inheritDoc}
152      */

153     protected void createRightButtonBar(final Composite parent) {
154         Assert.isNotNull(parent);
155         final Composite composite= new Composite(parent, SWT.NONE);
156         final GridLayout layout= new GridLayout(1, false);
157         composite.setLayout(layout);
158
159         final GridData data= new GridData();
160         data.grabExcessHorizontalSpace= false;
161         data.grabExcessVerticalSpace= true;
162         data.horizontalAlignment= SWT.FILL;
163         data.verticalAlignment= SWT.TOP;
164         composite.setLayoutData(data);
165
166         createDeleteButton(composite, GridData.FILL);
167         createDeleteAllButton(composite);
168         createEditButton(composite);
169     }
170
171     /**
172      * {@inheritDoc}
173      */

174     protected void createSelectionLabel(final Composite parent) {
175         // No selection label
176
}
177
178     /**
179      * {@inheritDoc}
180      */

181     protected int getContainerColumns() {
182         return 2;
183     }
184
185     /**
186      * Returns the delete all button.
187      *
188      * @return the delete all button, or <code>null</code>
189      */

190     public Button getDeleteAllButton() {
191         return fDeleteAllButton;
192     }
193
194     /**
195      * Returns the delete button.
196      *
197      * @return the delete button, or <code>null</code>
198      */

199     public Button getDeleteButton() {
200         return fDeleteButton;
201     }
202
203     /**
204      * {@inheritDoc}
205      */

206     protected int getDetailColumns() {
207         return 1;
208     }
209
210     /**
211      * Returns the edit button.
212      *
213      * @return the edit button, or <code>null</code>
214      */

215     public Button getEditButton() {
216         return fEditButton;
217     }
218
219     /**
220      * {@inheritDoc}
221      */

222     protected void handleCheckStateChanged() {
223         super.handleCheckStateChanged();
224         if (fDeleteButton != null)
225             fDeleteButton.setEnabled(getCheckedDescriptors().length > 0);
226     }
227
228     /**
229      * {@inheritDoc}
230      */

231     protected void handleSelectionChanged(final IStructuredSelection selection) {
232         super.handleSelectionChanged(selection);
233         if (fEditButton != null)
234             fEditButton.setEnabled(getSelectedDescriptors().length == 1);
235         if (fDeleteButton != null)
236             fDeleteButton.setEnabled(getCheckedDescriptors().length > 0);
237     }
238
239     /**
240      * {@inheritDoc}
241      */

242     public void setInput(final RefactoringHistory history) {
243         super.setInput(history);
244         if (fDeleteAllButton != null)
245             fDeleteAllButton.setEnabled(history != null && !history.isEmpty());
246         if (fDeleteButton != null)
247             fDeleteButton.setEnabled(false);
248         if (fEditButton != null)
249             fEditButton.setEnabled(false);
250     }
251 }
252
Popular Tags