KickJava   Java API By Example, From Geeks To Geeks.

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


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
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.core.runtime.IAdaptable;
16 import org.eclipse.jface.dialogs.Dialog;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.layout.GridData;
19 import org.eclipse.swt.layout.GridLayout;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Control;
22 import org.eclipse.swt.widgets.Label;
23 import org.eclipse.team.core.TeamException;
24 import org.eclipse.team.internal.ccvs.core.ICVSFolder;
25 import org.eclipse.team.internal.ccvs.core.ICVSResource;
26 import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
27 import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo;
28 import org.eclipse.ui.dialogs.PropertyPage;
29
30 /**
31  * A property page which displays the CVS-specific properties for the
32  * selected resource.
33  */

34 public class ResourcePropertiesPage extends PropertyPage {
35     // The resource to show properties for
36
IResource resource;
37
38     /*
39      * @see PreferencePage#createContents(Composite)
40      */

41     protected Control createContents(Composite parent) {
42         Composite composite = new Composite(parent, SWT.NONE);
43         GridLayout layout = new GridLayout();
44         layout.numColumns = 2;
45         layout.marginHeight = layout.marginWidth = 0;
46         composite.setLayout(layout);
47         composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
48         
49         try {
50             IResource resource = getSelectedElement();
51             if (resource != null) {
52                 ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource);
53                 if (!cvsResource.isManaged()) {
54                     createPair(composite, CVSUIMessages.ResourcePropertiesPage_status, CVSUIMessages.ResourcePropertiesPage_notManaged); //
55
} else {
56                     boolean hasRemote = false;
57                     if(cvsResource.isFolder()) {
58                         hasRemote = ((ICVSFolder)cvsResource).isCVSFolder();
59                     } else {
60                         ResourceSyncInfo info = cvsResource.getSyncInfo();
61                         if(info!=null && !info.isAdded()) {
62                             hasRemote = true;
63                         }
64                     }
65                     createPair(composite, CVSUIMessages.ResourcePropertiesPage_status, hasRemote ? CVSUIMessages.ResourcePropertiesPage_versioned : CVSUIMessages.ResourcePropertiesPage_notVersioned); //
66
}
67             }
68         } catch (TeamException e) {
69             createPair(composite, CVSUIMessages.ResourcePropertiesPage_error, e.getMessage());
70         }
71         Dialog.applyDialogFont(parent);
72         return composite;
73     }
74
75     /**
76      * Creates a key-value property pair in the given parent.
77      *
78      * @param parent the parent for the labels
79      * @param left the string for the left label
80      * @param right the string for the right label
81      */

82     protected void createPair(Composite parent, String JavaDoc left, String JavaDoc right) {
83         Label label = new Label(parent, SWT.NONE);
84         label.setText(left);
85     
86         label = new Label(parent, SWT.NONE);
87         label.setText(right);
88         label.setToolTipText(right);
89         label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
90     }
91
92     /**
93      * Returns the element selected when the properties was run
94      *
95      * @return the selected element
96      */

97     protected IResource getSelectedElement() {
98         // get the resource that is the source of this property page
99
IResource resource = null;
100         IAdaptable element = getElement();
101         if (element instanceof IResource) {
102             resource = (IResource)element;
103         } else {
104             Object JavaDoc adapter = element.getAdapter(IResource.class);
105             if (adapter instanceof IResource) {
106                 resource = (IResource)adapter;
107             }
108         }
109         return resource;
110     }
111 }
112
Popular Tags