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
.egit
.ui
.UIText
;
25 import org
.spearce
.jgit
.lib
.ObjectId
;
26 import org
.spearce
.jgit
.lib
.Repository
;
29 * Property page to be shown in project properties, if project is shared using
30 * git provider. Currently there aren't any modifiable element.
32 public class GitProjectPropertyPage
extends PropertyPage
{
45 protected Control
createContents(Composite parent
) {
46 final Composite composite
= new Composite(parent
, SWT
.NULL
);
48 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
49 final GridLayout layout
= new GridLayout();
50 layout
.numColumns
= 2;
51 layout
.marginHeight
= 0;
52 layout
.marginWidth
= 0;
53 layout
.horizontalSpacing
= 0;
54 layout
.verticalSpacing
= 0;
55 composite
.setLayout(layout
);
57 gitDir
= createLabeledReadOnlyText(composite
, UIText
.GitProjectPropertyPage_LabelGitDir
);
58 workDir
= createLabeledReadOnlyText(composite
, UIText
.GitProjectPropertyPage_LabelWorkdir
);
59 branch
= createLabeledReadOnlyText(composite
, UIText
.GitProjectPropertyPage_LabelBranch
);
60 id
= createLabeledReadOnlyText(composite
, UIText
.GitProjectPropertyPage_LabelId
);
61 state
= createLabeledReadOnlyText(composite
, UIText
.GitProjectPropertyPage_LabelState
);
63 // Get the project that is the source of this property page
64 IProject project
= null;
65 final IAdaptable element
= getElement();
66 if (element
instanceof IProject
) {
67 project
= (IProject
) element
;
69 Object adapter
= element
.getAdapter(IProject
.class);
70 if (adapter
instanceof IProject
) {
71 project
= (IProject
) adapter
;
75 Repository repository
= RepositoryMapping
.getMapping(project
)
78 if (repository
!= null) {
80 fillValues(repository
);
81 } catch (IOException e
) {
89 private void fillValues(Repository repository
) throws IOException
{
90 gitDir
.setText(repository
.getDirectory().getAbsolutePath());
91 branch
.setText(repository
.getBranch());
92 workDir
.setText(repository
.getWorkDir().getAbsolutePath());
94 state
.setText(repository
.getRepositoryState().getDescription());
96 final ObjectId objectId
= repository
97 .resolve(repository
.getFullBranch());
98 if (objectId
== null) {
99 if (repository
.getAllRefs().size() == 0)
100 id
.setText(UIText
.GitProjectPropertyPage_ValueEmptyRepository
);
102 id
.setText(UIText
.GitProjectPropertyPage_ValueUnbornBranch
);
104 id
.setText(objectId
.name());
108 * Create a read only text field with a label
111 * the parent composite for new widgets
114 * @return the new read only text field
116 protected Text
createLabeledReadOnlyText(Composite parent
,
117 final String labelText
) {
118 Label label
= new Label(parent
, SWT
.LEFT
);
119 label
.setText(labelText
);
120 GridData data
= new GridData();
121 data
.horizontalSpan
= 1;
122 data
.horizontalAlignment
= GridData
.FILL
;
123 label
.setLayoutData(data
);
125 Text text
= new Text(parent
, SWT
.LEFT
| SWT
.READ_ONLY
);
126 text
.setBackground(Display
.getDefault().getSystemColor(
127 SWT
.COLOR_WIDGET_BACKGROUND
));
128 data
= new GridData();
129 data
.horizontalSpan
= 1;
130 data
.horizontalAlignment
= GridData
.FILL
;
131 text
.setLayoutData(data
);