Honor workbench setting for Dialog font
[egit.git] / org.eclipse.egit.ui / src / org / eclipse / egit / ui / internal / repository / ConfigureKeysDialog.java
blob9cd71b4e8b569a7590491b50fa74491fa96cffc3
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.util.ArrayList;
14 import java.util.Collections;
15 import java.util.List;
17 import org.eclipse.egit.ui.UIText;
18 import org.eclipse.jface.dialogs.Dialog;
19 import org.eclipse.jface.dialogs.IInputValidator;
20 import org.eclipse.jface.dialogs.InputDialog;
21 import org.eclipse.jface.layout.GridDataFactory;
22 import org.eclipse.jface.viewers.BaseLabelProvider;
23 import org.eclipse.jface.viewers.CheckStateChangedEvent;
24 import org.eclipse.jface.viewers.CheckboxTableViewer;
25 import org.eclipse.jface.viewers.ICheckStateListener;
26 import org.eclipse.jface.viewers.IStructuredContentProvider;
27 import org.eclipse.jface.viewers.ITableLabelProvider;
28 import org.eclipse.jface.viewers.Viewer;
29 import org.eclipse.jface.window.Window;
30 import org.eclipse.osgi.util.NLS;
31 import org.eclipse.swt.SWT;
32 import org.eclipse.swt.events.SelectionAdapter;
33 import org.eclipse.swt.events.SelectionEvent;
34 import org.eclipse.swt.graphics.Image;
35 import org.eclipse.swt.layout.GridLayout;
36 import org.eclipse.swt.widgets.Composite;
37 import org.eclipse.swt.widgets.Control;
38 import org.eclipse.swt.widgets.Shell;
39 import org.eclipse.swt.widgets.ToolBar;
40 import org.eclipse.swt.widgets.ToolItem;
42 /**
43 * Configures the Git configuration keys to display in the Properties view
45 class ConfigureKeysDialog extends Dialog {
47 private static final class ContentProvider implements
48 IStructuredContentProvider {
50 public Object[] getElements(Object inputElement) {
51 return ((List) inputElement).toArray();
54 public void dispose() {
55 // nothing
58 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
59 // nothing
64 private static final class LabelProvider extends BaseLabelProvider
65 implements ITableLabelProvider {
67 public Image getColumnImage(Object element, int columnIndex) {
68 return null;
71 public String getColumnText(Object element, int columnIndex) {
72 return (String) element;
77 /**
78 * The standard keys
80 public static final List<String> standardKeys = new ArrayList<String>();
82 static {
83 standardKeys.add("core.logallrefupdates"); //$NON-NLS-1$
84 standardKeys.add("core.compression"); //$NON-NLS-1$
86 standardKeys.add("remote.?.url"); //$NON-NLS-1$
87 standardKeys.add("remote.?.fetch"); //$NON-NLS-1$
88 standardKeys.add("remote.?.push"); //$NON-NLS-1$
90 standardKeys.add("user.name"); //$NON-NLS-1$
91 standardKeys.add("user.email"); //$NON-NLS-1$
93 Collections.sort(standardKeys);
96 private final List<String> activeKeys = new ArrayList<String>();
98 /**
99 * @param parentShell
100 * @param activeKeys
102 ConfigureKeysDialog(Shell parentShell, List<String> activeKeys) {
103 super(parentShell);
104 this.activeKeys.addAll(activeKeys);
105 setShellStyle(getShellStyle() | SWT.SHELL_TRIM);
109 * @return the strings
111 public List<String> getActiveKeys() {
112 return activeKeys;
115 @Override
116 protected void configureShell(Shell newShell) {
117 super.configureShell(newShell);
118 newShell.setText(UIText.ConfigureKeysDialog_DialogTitle);
121 @Override
122 protected Control createDialogArea(Composite parent) {
124 Composite main = new Composite(parent, SWT.NONE);
125 main.setLayout(new GridLayout(1, false));
126 GridDataFactory.fillDefaults().grab(true, true).applyTo(main);
128 final CheckboxTableViewer tv = CheckboxTableViewer.newCheckList(main,
129 SWT.NONE);
131 GridDataFactory.fillDefaults().grab(true, true).applyTo(tv.getTable());
133 ToolBar tb = new ToolBar(main, SWT.HORIZONTAL);
134 final ToolItem del = new ToolItem(tb, SWT.PUSH);
135 del.setEnabled(false);
136 del.setText(UIText.ConfigureKeysDialog_DeleteButton);
137 del.addSelectionListener(new SelectionAdapter() {
139 @Override
140 public void widgetSelected(SelectionEvent e) {
141 for (Object ob : tv.getCheckedElements()) {
142 activeKeys.remove(ob);
143 tv.setInput(activeKeys);
149 final ToolItem addStandard = new ToolItem(tb, SWT.PUSH);
150 addStandard.setText(UIText.ConfigureKeysDialog_AddStandardButton);
151 addStandard.addSelectionListener(new SelectionAdapter() {
153 @Override
154 public void widgetSelected(SelectionEvent e) {
155 for (String key : standardKeys) {
156 if (!activeKeys.contains(key)) {
157 activeKeys.add(key);
159 tv.setInput(activeKeys);
161 Collections.sort(activeKeys);
166 ToolItem add = new ToolItem(tb, SWT.PUSH);
167 add.setText(UIText.ConfigureKeysDialog_NewButton);
168 add.addSelectionListener(new SelectionAdapter() {
170 @Override
171 public void widgetSelected(SelectionEvent e) {
172 IInputValidator validator = new IInputValidator() {
174 public String isValid(String newText) {
175 if (activeKeys.contains(newText))
176 return NLS
177 .bind(
178 UIText.ConfigureKeysDialog_AlreadyThere_Message,
179 newText);
180 return null;
183 InputDialog id = new InputDialog(getShell(),
184 UIText.ConfigureKeysDialog_NewKeyLabel,
185 UIText.ConfigureKeysDialog_NewKeyLabel, null, validator);
186 if (id.open() == Window.OK) {
187 activeKeys.add(id.getValue());
188 Collections.sort(activeKeys);
189 tv.setInput(activeKeys);
195 tv.addCheckStateListener(new ICheckStateListener() {
197 public void checkStateChanged(CheckStateChangedEvent event) {
198 boolean anyChecked = tv.getCheckedElements().length > 0;
199 del.setEnabled(anyChecked);
204 tv.setLabelProvider(new LabelProvider());
205 tv.setContentProvider(new ContentProvider());
206 tv.setInput(this.activeKeys);
207 applyDialogFont(main);
209 return main;