KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > internal > ui > refactoring > RefactoringStatusDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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;
12
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.custom.ViewForm;
15 import org.eclipse.swt.graphics.Color;
16 import org.eclipse.swt.graphics.Rectangle;
17 import org.eclipse.swt.layout.GridData;
18 import org.eclipse.swt.layout.GridLayout;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Control;
21 import org.eclipse.swt.widgets.Label;
22 import org.eclipse.swt.widgets.Shell;
23
24 import org.eclipse.jface.dialogs.Dialog;
25 import org.eclipse.jface.dialogs.IDialogConstants;
26
27 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
28
29 public class RefactoringStatusDialog extends Dialog {
30     
31     private RefactoringStatus fStatus;
32     private String JavaDoc fWindowTitle;
33     private boolean fBackButton;
34     private boolean fLightWeight;
35     
36     public RefactoringStatusDialog(RefactoringStatus status, Shell parent, String JavaDoc windowTitle, boolean backButton) {
37         super(parent);
38         fStatus= status;
39         fWindowTitle= windowTitle;
40         fBackButton= backButton;
41         setShellStyle(getShellStyle() | SWT.RESIZE | SWT.MAX);
42     }
43
44     public RefactoringStatusDialog(RefactoringStatus status, Shell parent, String JavaDoc windowTitle, boolean backButton, boolean light) {
45         this(status, parent, windowTitle, backButton);
46         fLightWeight= light;
47     }
48
49     public RefactoringStatusDialog(Shell parent, ErrorWizardPage page, boolean backButton) {
50         this(page.getStatus(), parent, parent.getText(), backButton);
51     }
52     
53     protected void configureShell(Shell newShell) {
54         super.configureShell(newShell);
55         newShell.setText(fWindowTitle);
56     }
57
58     protected Control createDialogArea(Composite parent) {
59         Composite result= new Composite(parent, SWT.NONE);
60         initializeDialogUnits(result);
61         GridLayout layout= new GridLayout();
62         result.setLayout(layout);
63         GridData gd= new GridData(GridData.FILL_BOTH);
64         gd.widthHint= 600;
65         gd.heightHint= 400;
66         result.setLayoutData(gd);
67         if (!fLightWeight) {
68             Color background= parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND);
69             ViewForm messagePane= new ViewForm(result, SWT.BORDER | SWT.FLAT);
70             messagePane.marginWidth= layout.marginWidth;
71             messagePane.marginHeight= layout.marginHeight;
72             gd= new GridData(GridData.FILL_HORIZONTAL);
73             // XXX http://bugs.eclipse.org/bugs/show_bug.cgi?id=27572
74
Rectangle rect= messagePane.computeTrim(0, 0, 0, convertHeightInCharsToPixels(2) + messagePane.marginHeight * 2);
75             gd.heightHint= rect.height;
76             messagePane.setLayoutData(gd);
77             messagePane.setBackground(background);
78             Label label= new Label(messagePane, SWT.LEFT | SWT.WRAP);
79             if (fStatus.hasFatalError())
80                 label.setText(RefactoringUIMessages.RefactoringStatusDialog_Cannot_proceed);
81             else
82                 label.setText(RefactoringUIMessages.RefactoringStatusDialog_Please_look);
83             label.setBackground(background);
84             messagePane.setContent(label);
85         }
86         RefactoringStatusViewer viewer= new RefactoringStatusViewer(result, SWT.NONE);
87         viewer.setLayoutData(new GridData(GridData.FILL_BOTH));
88         viewer.setStatus(fStatus);
89         applyDialogFont(result);
90         return result;
91     }
92
93     protected void buttonPressed(int buttonId) {
94         if (buttonId == IDialogConstants.BACK_ID) {
95             setReturnCode(IDialogConstants.BACK_ID);
96             close();
97         } else {
98             super.buttonPressed(buttonId);
99         }
100     }
101
102     protected void createButtonsForButtonBar(Composite parent) {
103         if (!fStatus.hasFatalError()) {
104             if (fBackButton)
105                 createButton(parent, IDialogConstants.BACK_ID, IDialogConstants.BACK_LABEL, false);
106             createButton(parent, IDialogConstants.OK_ID, fLightWeight ? IDialogConstants.OK_LABEL : RefactoringUIMessages.RefactoringStatusDialog_Continue, true);
107             createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
108         } else {
109             if (fBackButton)
110                 createButton(parent, IDialogConstants.BACK_ID, IDialogConstants.BACK_LABEL, true);
111             createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, fBackButton ? false : true);
112         }
113     }
114 }
115
Popular Tags