1 /*******************************************************************************
2 * Copyright (C) 2008, Tomi Pakarinen <tomi.pakarinen@iki.fi>
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * See LICENSE for the full license text, also available.
7 *******************************************************************************/
8 package org
.spearce
.egit
.ui
.internal
.preferences
;
10 import java
.io
.IOException
;
12 import org
.eclipse
.core
.resources
.IProject
;
13 import org
.eclipse
.core
.runtime
.IAdaptable
;
14 import org
.eclipse
.swt
.SWT
;
15 import org
.eclipse
.swt
.layout
.GridData
;
16 import org
.eclipse
.swt
.layout
.GridLayout
;
17 import org
.eclipse
.swt
.widgets
.Composite
;
18 import org
.eclipse
.swt
.widgets
.Control
;
19 import org
.eclipse
.swt
.widgets
.Display
;
20 import org
.eclipse
.swt
.widgets
.Label
;
21 import org
.eclipse
.swt
.widgets
.Text
;
22 import org
.eclipse
.ui
.dialogs
.PropertyPage
;
23 import org
.spearce
.egit
.core
.project
.RepositoryMapping
;
24 import org
.spearce
.jgit
.lib
.ObjectId
;
25 import org
.spearce
.jgit
.lib
.Repository
;
28 * Property page to be shown in project properties, if project is shared using
29 * git provider. Currently there aren't any modifiable element.
31 public class GitProjectPropertyPage
extends PropertyPage
{
44 protected Control
createContents(Composite parent
) {
45 final Composite composite
= new Composite(parent
, SWT
.NULL
);
47 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
48 final GridLayout layout
= new GridLayout();
49 layout
.numColumns
= 2;
50 layout
.marginHeight
= 0;
51 layout
.marginWidth
= 0;
52 layout
.horizontalSpacing
= 0;
53 layout
.verticalSpacing
= 0;
54 composite
.setLayout(layout
);
56 gitDir
= createLabeledReadOnlyText(composite
, "Git directory:");
57 workDir
= createLabeledReadOnlyText(composite
, "Working directory:");
58 branch
= createLabeledReadOnlyText(composite
, "Branch:");
59 id
= createLabeledReadOnlyText(composite
, "Id:");
60 state
= createLabeledReadOnlyText(composite
, "Current state:");
62 // Get the project that is the source of this property page
63 IProject project
= null;
64 final IAdaptable element
= getElement();
65 if (element
instanceof IProject
) {
66 project
= (IProject
) element
;
68 Object adapter
= element
.getAdapter(IProject
.class);
69 if (adapter
instanceof IProject
) {
70 project
= (IProject
) adapter
;
74 Repository repository
= RepositoryMapping
.getMapping(project
)
77 if (repository
!= null) {
79 fillValues(repository
);
80 } catch (IOException e
) {
88 private void fillValues(Repository repository
) throws IOException
{
89 gitDir
.setText(repository
.getDirectory().getAbsolutePath());
90 branch
.setText(repository
.getBranch());
91 workDir
.setText(repository
.getWorkDir().getAbsolutePath());
93 state
.setText(repository
.getRepositoryState().getDescription());
95 final ObjectId objectId
= repository
96 .resolve(repository
.getFullBranch());
97 id
.setText(objectId
.name());
101 * Create a read only text field with a label
104 * the parent composite for new widgets
107 * @return the new read only text field
109 protected Text
createLabeledReadOnlyText(Composite parent
,
110 final String labelText
) {
111 Label label
= new Label(parent
, SWT
.LEFT
);
112 label
.setText(labelText
);
113 GridData data
= new GridData();
114 data
.horizontalSpan
= 1;
115 data
.horizontalAlignment
= GridData
.FILL
;
116 label
.setLayoutData(data
);
118 Text text
= new Text(parent
, SWT
.LEFT
| SWT
.READ_ONLY
);
119 text
.setBackground(Display
.getDefault().getSystemColor(
120 SWT
.COLOR_WIDGET_BACKGROUND
));
121 data
= new GridData();
122 data
.horizontalSpan
= 1;
123 data
.horizontalAlignment
= GridData
.FILL
;
124 text
.setLayoutData(data
);