KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > ReleaseCommentDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.team.internal.ccvs.ui;
12
13 import org.eclipse.core.resources.IResource;
14 import org.eclipse.jface.dialogs.Dialog;
15 import org.eclipse.jface.dialogs.IDialogSettings;
16 import org.eclipse.jface.util.IPropertyChangeListener;
17 import org.eclipse.jface.util.PropertyChangeEvent;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.graphics.Point;
20 import org.eclipse.swt.graphics.Rectangle;
21 import org.eclipse.swt.layout.GridData;
22 import org.eclipse.swt.layout.GridLayout;
23 import org.eclipse.swt.widgets.*;
24 import org.eclipse.team.internal.ui.dialogs.DetailsDialog;
25
26 /**
27  * Prompts the user for a multi-line comment for releasing to CVS.
28  */

29 public class ReleaseCommentDialog extends DetailsDialog {
30     
31     CommitCommentArea commitCommentArea;
32     // dialogs settings that are persistent between workbench sessions
33
private IDialogSettings settings;
34     
35     private static final int DEFAULT_WIDTH_IN_CHARS= 80;
36
37     private static final String JavaDoc HEIGHT_KEY = "width-key"; //$NON-NLS-1$
38
private static final String JavaDoc WIDTH_KEY = "height-key"; //$NON-NLS-1$
39

40     /**
41      * ReleaseCommentDialog constructor.
42      *
43      * @param parentShell the parent of this dialog
44      * @param proposedComment
45      */

46     public ReleaseCommentDialog(Shell parentShell, IResource[] resourcesToCommit, String JavaDoc proposedComment, int depth) {
47         super(parentShell, CVSUIMessages.ReleaseCommentDialog_title);
48         int shellStyle = getShellStyle();
49         setShellStyle(shellStyle | SWT.RESIZE | SWT.MAX);
50         commitCommentArea = new CommitCommentArea();
51         // Get a project from which the commit template can be obtained
52
if (resourcesToCommit.length > 0)
53         commitCommentArea.setProject(resourcesToCommit[0].getProject());
54         commitCommentArea.setProposedComment(proposedComment);
55         
56         IDialogSettings workbenchSettings = CVSUIPlugin.getPlugin().getDialogSettings();
57         this.settings = workbenchSettings.getSection("ReleaseCommentDialog");//$NON-NLS-1$
58
if (settings == null) {
59             this.settings = workbenchSettings.addNewSection("ReleaseCommentDialog");//$NON-NLS-1$
60
}
61     }
62     
63     /* (non-Javadoc)
64      * @see org.eclipse.team.internal.ui.dialogs.DetailsDialog#includeDetailsButton()
65      */

66     protected boolean includeDetailsButton() {
67         return false;
68     }
69     
70     /* (non-Javadoc)
71      * @see org.eclipse.team.internal.ui.dialogs.DetailsDialog#includeErrorMessage()
72      */

73     protected boolean includeErrorMessage() {
74         return false;
75     }
76     
77     /*
78      * @see Dialog#createDialogArea(Composite)
79      */

80     protected void createMainDialogArea(Composite parent) {
81         getShell().setText(CVSUIMessages.ReleaseCommentDialog_title);
82         Composite composite = new Composite(parent, SWT.NULL);
83         composite.setLayout(new GridLayout());
84         composite.setLayoutData(new GridData(GridData.FILL_BOTH));
85         
86         commitCommentArea.createArea(composite);
87         commitCommentArea.addPropertyChangeListener(new IPropertyChangeListener() {
88             public void propertyChange(PropertyChangeEvent event) {
89                 if (event.getProperty() == CommitCommentArea.OK_REQUESTED)
90                     okPressed();
91             }
92         });
93         
94         Dialog.applyDialogFont(parent);
95     }
96
97     /* (non-Javadoc)
98      * @see org.eclipse.team.internal.ui.dialogs.DetailsDialog#getHelpContextId()
99      */

100     protected String JavaDoc getHelpContextId() {
101         return IHelpContextIds.RELEASE_COMMENT_DIALOG;
102     }
103     
104     /* (non-Javadoc)
105      * @see org.eclipse.jface.window.Window#getInitialSize()
106      */

107     protected Point getInitialSize() {
108         try {
109             return new Point(settings.getInt(WIDTH_KEY), settings.getInt(HEIGHT_KEY));
110         } catch(NumberFormatException JavaDoc e) {
111             final Point size= super.getInitialSize();
112             size.x= convertWidthInCharsToPixels(DEFAULT_WIDTH_IN_CHARS);
113             size.y += convertHeightInCharsToPixels(8);
114             return size;
115         }
116     }
117     
118     public String JavaDoc getComment() {
119         return commitCommentArea.getComment(true);
120     }
121
122     /* (non-Javadoc)
123      * @see org.eclipse.team.internal.ui.dialogs.DetailsDialog#createDropDownDialogArea(org.eclipse.swt.widgets.Composite)
124      */

125     protected Composite createDropDownDialogArea(Composite parent) {
126         return null;
127     }
128
129     /* (non-Javadoc)
130      * @see org.eclipse.team.internal.ui.dialogs.DetailsDialog#updateEnablements()
131      */

132     protected void updateEnablements() {
133     }
134     
135     /* (non-Javadoc)
136      * @see org.eclipse.jface.window.Window#close()
137      */

138     public boolean close() {
139         Rectangle bounds = getShell().getBounds();
140         settings.put(HEIGHT_KEY, bounds.height);
141         settings.put(WIDTH_KEY, bounds.width);
142         return super.close();
143     }
144     
145     /* (non-Javadoc)
146      * @see org.eclipse.jface.dialogs.Dialog#createContents(org.eclipse.swt.widgets.Composite)
147      */

148     protected Control createContents(Composite parent) {
149         Control c = super.createContents(parent);
150         commitCommentArea.setFocus();
151         return c;
152     }
153 }
154
Popular Tags