KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-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.jface.dialogs.Dialog;
14 import org.eclipse.jface.dialogs.IDialogSettings;
15 import org.eclipse.jface.util.IPropertyChangeListener;
16 import org.eclipse.jface.util.PropertyChangeEvent;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.events.SelectionAdapter;
19 import org.eclipse.swt.events.SelectionEvent;
20 import org.eclipse.swt.layout.GridData;
21 import org.eclipse.swt.widgets.Button;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Control;
24 import org.eclipse.swt.widgets.Label;
25 import org.eclipse.swt.widgets.Shell;
26 import org.eclipse.ui.IWorkingSet;
27 import org.eclipse.ui.help.WorkbenchHelp;
28
29 /**
30  *
31  */

32 public class SynchronizeProjectsDialog extends Dialog {
33     
34     private Button outgoingChangesButton;
35
36     private static final String JavaDoc SYNC_OUTGOING_CHANGES = "SyncOutgoingChanges"; //$NON-NLS-1$
37

38     IWorkingSet workingSet;
39     boolean syncOutgoingChanges;
40     
41     // dialogs settings that are persistent between workbench sessions
42
private IDialogSettings settings;
43     private WorkingSetSelectionArea workingSetArea;
44
45     /**
46      * Creates a filter selection dialog.
47      *
48      * @param parentShell the parent shell
49      * @param input the root element to populate this dialog with
50      * @param contentProvider the content provider for navigating the model
51      * @param labelProvider the label provider for displaying model elements
52      * @param message the message to be displayed at the top of this dialog, or
53      * <code>null</code> to display a default message
54      */

55     public SynchronizeProjectsDialog(Shell parentShell) {
56         super(parentShell);
57         IDialogSettings workbenchSettings = CVSUIPlugin.getPlugin().getDialogSettings();
58         this.settings = workbenchSettings.getSection("SynchronizeProjectsDialog");//$NON-NLS-1$
59
if (settings == null) {
60             this.settings = workbenchSettings.addNewSection("SynchronizeProjectsDialog");//$NON-NLS-1$
61
}
62     }
63
64     /**
65      * Overrides method in Dialog
66      *
67      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(Composite)
68      */

69     protected Control createDialogArea(Composite parent) {
70         // page group
71
Composite composite = (Composite)super.createDialogArea(parent);
72                     
73         workingSetArea = new WorkingSetSelectionArea(this, Policy.bind("SynchronizeProjectsDialog.allSharedProjects"), Policy.bind("SynchronizeProjectsDialog.sharedWorkingSetProjects"), settings); //$NON-NLS-1$ //$NON-NLS-2$
74
setWorkingSet(workingSet);
75         workingSetArea.addPropertyChangeListener(new IPropertyChangeListener() {
76             public void propertyChange(PropertyChangeEvent event) {
77                 workingSet = (IWorkingSet)event.getNewValue();
78             }
79         });
80         workingSetArea.createArea(composite);
81         
82         // Create the checkbox to enable/disable working set use
83
outgoingChangesButton = createCheckbox(composite, Policy.bind("SynchronizeProjectsDialog.syncOutgoingChanges")); //$NON-NLS-1$
84
outgoingChangesButton.addSelectionListener(new SelectionAdapter() {
85             public void widgetSelected(SelectionEvent e) {
86                 syncOutgoingChanges = outgoingChangesButton.getSelection();
87             }
88         });
89         if (settings != null) {
90             syncOutgoingChanges = settings.getBoolean(SYNC_OUTGOING_CHANGES);
91             outgoingChangesButton.setSelection(syncOutgoingChanges);
92         }
93         
94         // F1 Help
95
WorkbenchHelp.setHelp(composite, IHelpContextIds.SYNCHRONIZE_PROJECTS_DIALOG);
96         Dialog.applyDialogFont(parent);
97         
98         return composite;
99     }
100
101     /* (non-Javadoc)
102      * Method declared on Window.
103      */

104     protected void configureShell(Shell newShell) {
105         super.configureShell(newShell);
106         newShell.setText(Policy.bind("SynchronizeProjectsDialog.title")); //$NON-NLS-1$
107
}
108     /**
109      * Returns the selected working set or null if none is selected.
110      *
111      * @return the selected working set or null if none is selected.
112      */

113     public IWorkingSet getWorkingSet() {
114         return workingSet;
115     }
116
117     /**
118      * Overrides method in Dialog
119      *
120      * @see org.eclipse.jface.dialogs.Dialog#okPressed()
121      */

122     protected void okPressed() {
123         workingSet = workingSetArea.getWorkingSet();
124         if (workingSet != null) {
125             workingSetArea.useSelectedWorkingSet();
126         }
127         if (settings != null) {
128             settings.put(SYNC_OUTGOING_CHANGES, outgoingChangesButton.getSelection());
129         }
130         super.okPressed();
131     }
132     /**
133      * Sets the working set that should be selected in the most recently
134      * used working set list.
135      *
136      * @param workingSet the working set that should be selected.
137      * has to exist in the list returned by
138      * org.eclipse.ui.IWorkingSetManager#getRecentWorkingSets().
139      * Must not be null.
140      */

141     public void setWorkingSet(IWorkingSet workingSet) {
142         this.workingSet = workingSet;
143
144         if (workingSetArea != null) {
145             workingSetArea.setWorkingSet(workingSet);
146         }
147     }
148     
149     protected Button createCheckbox(Composite parent, String JavaDoc label) {
150         Button button = new Button(parent, SWT.CHECK | SWT.LEFT);
151         button.setText(label);
152         GridData data = new GridData();
153         button.setLayoutData(data);
154         return button;
155     }
156
157     protected Label createLabel(Composite composite, String JavaDoc text) {
158         Label label = new Label(composite,SWT.NONE);
159         if (text != null) {
160             label.setText(text);
161         }
162         return label;
163     }
164     
165     /**
166      * @return boolean
167      */

168     public boolean isSyncOutgoingChanges() {
169         return syncOutgoingChanges;
170     }
171
172 }
173
Popular Tags