1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
/******************************************************************************
* Copyright (c) 2011, 2015 GitHub Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Kevin Sawicki (GitHub Inc.) - initial API and implementation
*****************************************************************************/
package org.eclipse.egit.ui.internal.repository;
import java.io.File;
import java.io.IOException;
import org.eclipse.core.runtime.Adapters;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.internal.preferences.ConfigurationEditorComponent;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jgit.events.ConfigChangedEvent;
import org.eclipse.jgit.events.ConfigChangedListener;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.dialogs.PropertyPage;
/**
* Property page for elements that can adapt to a {@link Repository} object.
*/
public class RepositoryPropertyPage extends PropertyPage {
private ConfigurationEditorComponent editor;
@Override
protected Control createContents(Composite parent) {
Composite displayArea = new Composite(parent, SWT.NONE);
GridLayoutFactory.fillDefaults().applyTo(displayArea);
GridDataFactory.fillDefaults().applyTo(displayArea);
final Repository repo = Adapters.adapt(getElement(), Repository.class);
if (repo == null)
return displayArea;
StoredConfig config = repo.getConfig();
if (config instanceof FileBasedConfig) {
File configFile = ((FileBasedConfig) config).getFile();
config = new FileBasedConfig(configFile, repo.getFS());
config.addChangeListener(new ConfigChangedListener() {
@Override
public void onConfigChanged(ConfigChangedEvent event) {
repo.fireEvent(new ConfigChangedEvent());
}
});
}
editor = new ConfigurationEditorComponent(displayArea, config, true,
0) {
@Override
protected void setErrorMessage(String message) {
RepositoryPropertyPage.this.setErrorMessage(message);
}
};
editor.createContents();
return displayArea;
}
@Override
protected void performDefaults() {
if (editor != null)
try {
editor.restore();
} catch (IOException e) {
Activator.handleError(e.getMessage(), e, true);
}
super.performDefaults();
}
@Override
public boolean performOk() {
if (editor != null)
try {
editor.save();
} catch (IOException e) {
Activator.handleError(e.getMessage(), e, true);
}
return super.performOk();
}
}
|