KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > actions > OutgoingChangesDialog


1 /*******************************************************************************
2  * Copyright (c) 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.actions;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.jface.dialogs.Dialog;
16 import org.eclipse.jface.dialogs.IDialogConstants;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.events.DisposeEvent;
19 import org.eclipse.swt.events.DisposeListener;
20 import org.eclipse.swt.layout.GridData;
21 import org.eclipse.swt.layout.GridLayout;
22 import org.eclipse.swt.widgets.*;
23 import org.eclipse.team.core.mapping.ISynchronizationContext;
24 import org.eclipse.team.core.mapping.ISynchronizationScopeManager;
25 import org.eclipse.team.core.mapping.provider.SynchronizationContext;
26 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages;
27 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
28 import org.eclipse.team.internal.ccvs.ui.mappings.WorkspaceSubscriberContext;
29 import org.eclipse.team.internal.ui.SWTUtils;
30 import org.eclipse.team.internal.ui.dialogs.DetailsDialog;
31 import org.eclipse.team.ui.synchronize.*;
32
33 public class OutgoingChangesDialog extends DetailsDialog {
34
35     private final String JavaDoc message;
36     private ParticipantPagePane pane;
37     private ModelSynchronizeParticipant participant;
38     private final String JavaDoc title;
39     private final String JavaDoc detailsMessage;
40     private final ISynchronizationScopeManager manager;
41     private String JavaDoc helpContextId;
42
43     public OutgoingChangesDialog(Shell parentShell, ISynchronizationScopeManager manager, String JavaDoc title, String JavaDoc message, String JavaDoc detailsMessage) {
44         super(parentShell, title);
45         this.manager = manager;
46         this.title = title;
47         this.message = message;
48         this.detailsMessage = detailsMessage;
49     }
50
51     protected void createMainDialogArea(Composite parent) {
52         Composite composite = SWTUtils.createHVFillComposite(parent, SWTUtils.MARGINS_NONE);
53         composite.setLayout(new GridLayout());
54         composite.setLayoutData(new GridData(GridData.FILL_BOTH));
55         createWrappingLabel(composite, message);
56         Dialog.applyDialogFont(parent);
57     }
58
59     protected Label createWrappingLabel(Composite parent, String JavaDoc text) {
60         Label label = new Label(parent, SWT.LEFT | SWT.WRAP);
61         label.setText(text);
62         GridData data = new GridData();
63         data.horizontalSpan = 1;
64         data.horizontalAlignment = GridData.FILL;
65         data.horizontalIndent = 0;
66         data.grabExcessHorizontalSpace = true;
67         data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
68         label.setLayoutData(data);
69         label.setFont(parent.getFont());
70         return label;
71     }
72     
73     protected Composite createDropDownDialogArea(Composite parent) {
74         Composite composite = SWTUtils.createHVFillComposite(parent, SWTUtils.MARGINS_DIALOG);
75         GridData data = new GridData(GridData.FILL_BOTH);
76         data.heightHint = 200;
77         data.widthHint = 200;
78         composite.setLayoutData(data);
79         composite.addDisposeListener(new DisposeListener() {
80             public void widgetDisposed(DisposeEvent e) {
81                 if (pane != null)
82                     pane.dispose();
83                 if (participant != null)
84                     participant.dispose();
85             }
86         });
87         
88         createWrappingLabel(composite, detailsMessage);
89         
90         try {
91             participant = createParticipant();
92             ISynchronizePageConfiguration configuration = participant.createPageConfiguration();
93             configuration.setSupportedModes(ISynchronizePageConfiguration.OUTGOING_MODE);
94             configuration.setMode(ISynchronizePageConfiguration.OUTGOING_MODE);
95             configuration.setMenuGroups(ISynchronizePageConfiguration.P_TOOLBAR_MENU, new String JavaDoc[] { ISynchronizePageConfiguration.NAVIGATE_GROUP, ISynchronizePageConfiguration.LAYOUT_GROUP });
96             pane = new ParticipantPagePane(getShell(), true, configuration, participant);
97             Control control = pane.createPartControl(composite);
98             control.setLayoutData(SWTUtils.createHVFillGridData());
99         } catch (InvocationTargetException JavaDoc e) {
100             CVSUIPlugin.openError(getShell(), null, null, e);
101             SWTUtils.createLabel(parent, CVSUIMessages.OutgoingChangesDialog_0);
102         } catch (InterruptedException JavaDoc e) {
103             SWTUtils.createLabel(parent, CVSUIMessages.OutgoingChangesDialog_1);
104         }
105         
106         return composite;
107     }
108
109     private ModelSynchronizeParticipant createParticipant() throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
110         SynchronizationContext context = createSynchronizationContext(manager);
111         ModelSynchronizeParticipant participant = ModelSynchronizeParticipant.createParticipant(context, title);
112         participant.setMergingEnabled(false);
113         return participant;
114     }
115
116     private SynchronizationContext createSynchronizationContext(final ISynchronizationScopeManager manager) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
117         final SynchronizationContext[] context = new SynchronizationContext[] { null };
118         context[0] = WorkspaceSubscriberContext.createContext(manager, ISynchronizationContext.THREE_WAY);
119         return context[0];
120     }
121     
122     /* (non-Javadoc)
123      * @see org.eclipse.team.internal.ui.dialogs.DetailsDialog#isMainGrabVertical()
124      */

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

132     protected void updateEnablements() {
133         // Can always finish
134
setPageComplete(true);
135     }
136     
137     /* (non-Javadoc)
138      * @see org.eclipse.team.internal.ui.dialogs.DetailsDialog#includeErrorMessage()
139      */

140     protected boolean includeErrorMessage() {
141         return false;
142     }
143
144     public void setHelpContextId(String JavaDoc helpContextId) {
145         this.helpContextId = helpContextId;
146     }
147     
148     protected String JavaDoc getHelpContextId() {
149         return helpContextId;
150     }
151 }
Popular Tags