Git Repositories View: Simple fetch and push
[egit.git] / org.eclipse.egit.ui / src / org / eclipse / egit / ui / internal / repository / RepositoryRemotePropertySource.java
blobc68dc6dff81533a946386fb829e80f65b92abb69
1 /*******************************************************************************
2 * Copyright (c) 2010 SAP AG.
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
8 * Contributors:
9 * Mathias Kinzler (SAP AG) - initial implementation
10 *******************************************************************************/
11 package org.eclipse.egit.ui.internal.repository;
13 import java.io.IOException;
14 import java.util.ArrayList;
15 import java.util.List;
17 import org.eclipse.egit.ui.Activator;
18 import org.eclipse.egit.ui.UIText;
19 import org.eclipse.jgit.errors.ConfigInvalidException;
20 import org.eclipse.jgit.lib.RepositoryConfig;
21 import org.eclipse.ui.views.properties.IPropertyDescriptor;
22 import org.eclipse.ui.views.properties.IPropertySource;
23 import org.eclipse.ui.views.properties.PropertyDescriptor;
24 import org.eclipse.ui.views.properties.PropertySheetPage;
26 /**
27 * Read-only view of remote configuration
29 public class RepositoryRemotePropertySource implements IPropertySource {
31 private final RepositoryConfig myConfig;
33 private final String myName;
35 /**
36 * @param config
37 * @param remoteName
38 * @param page
41 public RepositoryRemotePropertySource(RepositoryConfig config,
42 String remoteName, PropertySheetPage page) {
43 myConfig = config;
44 myName = remoteName;
47 public Object getEditableValue() {
48 return null;
51 public IPropertyDescriptor[] getPropertyDescriptors() {
53 try {
54 myConfig.load();
55 } catch (IOException e) {
56 Activator.handleError(
57 UIText.RepositoryRemotePropertySource_ErrorHeader, e, true);
58 } catch (ConfigInvalidException e) {
59 Activator.handleError(
60 UIText.RepositoryRemotePropertySource_ErrorHeader, e, true);
62 List<IPropertyDescriptor> resultList = new ArrayList<IPropertyDescriptor>();
63 PropertyDescriptor desc = new PropertyDescriptor(RepositoriesView.URL,
64 UIText.RepositoryRemotePropertySource_RemoteFetchURL_label);
65 resultList.add(desc);
66 desc = new PropertyDescriptor(RepositoriesView.FETCH,
67 UIText.RepositoryRemotePropertySource_FetchLabel);
68 resultList.add(desc);
69 desc = new PropertyDescriptor(RepositoriesView.PUSHURL,
70 UIText.RepositoryRemotePropertySource_RemotePushUrl_label);
71 resultList.add(desc);
72 desc = new PropertyDescriptor(RepositoriesView.PUSH,
73 UIText.RepositoryRemotePropertySource_PushLabel);
74 resultList.add(desc);
75 return resultList.toArray(new IPropertyDescriptor[resultList.size()]);
78 public Object getPropertyValue(Object id) {
79 String[] list = myConfig.getStringList(RepositoriesView.REMOTE, myName,
80 (String) id);
81 if (list != null && list.length > 1) {
82 // let's show this as "[some/uri][another/uri]"
83 StringBuffer sb = new StringBuffer();
84 for (String s : list) {
85 sb.append('[');
86 sb.append(s);
87 sb.append(']');
89 return sb.toString();
91 return myConfig.getString(RepositoriesView.REMOTE, myName, (String) id);
94 public boolean isPropertySet(Object id) {
95 // no default values
96 return false;
99 public void resetPropertyValue(Object id) {
100 // nothing to do
103 public void setPropertyValue(Object id, Object value) {
104 // read-only