KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.core.resources.IFolder;
16 import org.eclipse.core.runtime.IAdaptable;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.jface.dialogs.*;
19 import org.eclipse.jface.dialogs.Dialog;
20 import org.eclipse.jface.operation.IRunnableWithProgress;
21 import org.eclipse.jface.preference.PreferencePage;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.layout.GridData;
24 import org.eclipse.swt.layout.GridLayout;
25 import org.eclipse.swt.widgets.*;
26 import org.eclipse.team.core.TeamException;
27 import org.eclipse.team.internal.ccvs.core.*;
28 import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
29 import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
30 import org.eclipse.team.internal.ccvs.core.util.Util;
31 import org.eclipse.ui.PlatformUI;
32
33 public class CVSFolderPropertiesPage extends CVSPropertiesPage {
34
35     IFolder folder;
36     private Label root;
37     private Label repository;
38     
39     /**
40      * @see PreferencePage#createContents(Composite)
41      */

42     protected Control createContents(Composite parent) {
43         initialize();
44         noDefaultAndApplyButton();
45         Composite composite = new Composite(parent, SWT.NULL);
46         composite.setLayoutData(new GridData(GridData.FILL_BOTH));
47         GridLayout layout = new GridLayout();
48         layout.numColumns = 2;
49         composite.setLayout(layout);
50         
51         try {
52             ICVSFolder cvsResource = CVSWorkspaceRoot.getCVSFolderFor(folder);
53             if (!cvsResource.isManaged()) {
54                 if (cvsResource.isIgnored()) {
55                     createLabel(composite, CVSUIMessages.CVSFolderPropertiesPage_ignored, 2);
56                 } else {
57                     createLabel(composite, CVSUIMessages.CVSFolderPropertiesPage_notManaged, 2);
58                 }
59             } else if (!cvsResource.isCVSFolder()) {
60                 // We have a managed folder which is not a cvs folder.
61
// This is really an invalid state but it does happen once in a while
62
createLabel(composite, CVSUIMessages.CVSFolderPropertiesPage_notCVSFolder, 2);
63             } else {
64                 FolderSyncInfo syncInfo = cvsResource.getFolderSyncInfo();
65                 createLabel(composite, CVSUIMessages.CVSFolderPropertiesPage_root);
66                 root = createLabel(composite, syncInfo.getRoot());
67                 createLabel(composite, CVSUIMessages.CVSFolderPropertiesPage_repository);
68                 repository = createLabel(composite, syncInfo.getRepository());
69             
70                 // Tag
71
createLabel(composite, CVSUIMessages.CVSFilePropertiesPage_tag);
72                 CVSTag tag = syncInfo.getTag();
73
74                 if (tag != null && tag.getType() == CVSTag.BRANCH) {
75                     tag = Util.getAccurateFolderTag(folder, tag);
76                 }
77             
78                 createLabel(composite, getTagLabel(tag));
79                 
80                 // Static-ness
81
if (syncInfo.getIsStatic()) {
82                     createLabel(composite, CVSUIMessages.CVSFolderPropertiesPage_static);
83                     createLabel(composite, syncInfo.getIsStatic() ? CVSUIMessages.yes : CVSUIMessages.no); //
84
}
85                 
86                 createLabel(composite, "", 2); // spacer //$NON-NLS-1$
87

88                 // Allow the folder to be disconnected from CVS control
89
final Button disconnect = new Button(composite, SWT.NONE);
90                 disconnect.setText(CVSUIMessages.CVSFolderPropertiesPage_disconnect);
91                 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_END);
92                 int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
93                 data.widthHint = Math.max(widthHint, disconnect.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
94                 disconnect.setLayoutData(data);
95                 disconnect.addListener(SWT.Selection, new Listener() {
96                     public void handleEvent (Event event) {
97                         // perform a disconnect
98
if (disconnectFolder()) {
99                             root.setText(CVSUIMessages.CVSFilePropertiesPage_none);
100                             repository.setText(CVSUIMessages.CVSFilePropertiesPage_none);
101                             disconnect.setEnabled(false);
102                         }
103                     }
104                 });
105             }
106         } catch (TeamException e) {
107             // Display error text
108
createLabel(composite, CVSUIMessages.CVSFilePropertiesPage_error, 2);
109         }
110         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IHelpContextIds.FOLDER_PROPERTY_PAGE);
111         Dialog.applyDialogFont(parent);
112         return composite;
113     }
114
115     /**
116      * Utility method that creates a label instance
117      * and sets the default layout data.
118      *
119      * @param parent the parent for the new label
120      * @param text the text for the new label
121      * @return the new label
122      */

123     protected Label createLabel(Composite parent, String JavaDoc text, int span) {
124         Label label = new Label(parent, SWT.LEFT);
125         label.setText(text);
126         GridData data = new GridData();
127         data.horizontalSpan = span;
128         data.horizontalAlignment = GridData.FILL;
129         label.setLayoutData(data);
130         return label;
131     }
132     
133     protected Label createLabel(Composite parent, String JavaDoc text) {
134         return createLabel(parent, text, 1);
135     }
136     /**
137      * Initializes the page
138      */

139     private void initialize() {
140         // Get the file that is the source of this property page
141
folder = null;
142         IAdaptable element = getElement();
143         if (element instanceof IFolder) {
144             folder = (IFolder)element;
145         } else {
146             Object JavaDoc adapter = element.getAdapter(IFolder.class);
147             if (adapter instanceof IFolder) {
148                 folder = (IFolder)adapter;
149             }
150         }
151     }
152
153     private boolean disconnectFolder() {
154         if (MessageDialog.openQuestion(getShell(), CVSUIMessages.CVSFolderPropertiesPage_disconnectTitle, CVSUIMessages.CVSFolderPropertiesPage_disconnectQuestion)) { //
155
final ICVSFolder cvsFolder = CVSWorkspaceRoot.getCVSFolderFor(folder);
156             try {
157                 PlatformUI.getWorkbench().getProgressService().run(true, false, new IRunnableWithProgress() {
158                     public void run(IProgressMonitor monitor) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
159                         try {
160                             cvsFolder.unmanage(null);
161                         } catch (CVSException e) {
162                             throw new InvocationTargetException JavaDoc(e);
163                         }
164                     }
165                 });
166             } catch (InvocationTargetException JavaDoc e) {
167                 CVSUIPlugin.openError(getShell(), null, null, e);
168                 return false;
169             } catch (InterruptedException JavaDoc e) {
170                 // Ignore
171
}
172             return true;
173         } else {
174             return false;
175         }
176     }
177 }
178
Popular Tags