2
* Copyright (C) 2009 Canonical Ltd
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
package org.vcs.bazaar.eclipse.ui.dialogs;
20
import java.util.ArrayList;
21
import java.util.HashMap;
22
import java.util.List;
24
import java.util.Map.Entry;
26
import org.eclipse.core.resources.IResource;
27
import org.eclipse.jface.dialogs.Dialog;
28
import org.eclipse.jface.dialogs.IDialogConstants;
29
import org.eclipse.jface.layout.GridDataFactory;
30
import org.eclipse.jface.layout.TableColumnLayout;
31
import org.eclipse.jface.viewers.CheckboxTableViewer;
32
import org.eclipse.jface.viewers.ColumnWeightData;
33
import org.eclipse.jface.viewers.IStructuredContentProvider;
34
import org.eclipse.jface.viewers.TableViewer;
35
import org.eclipse.jface.viewers.Viewer;
36
import org.eclipse.swt.SWT;
37
import org.eclipse.swt.graphics.Point;
38
import org.eclipse.swt.layout.GridData;
39
import org.eclipse.swt.layout.GridLayout;
40
import org.eclipse.swt.widgets.Composite;
41
import org.eclipse.swt.widgets.Control;
42
import org.eclipse.swt.widgets.Display;
43
import org.eclipse.swt.widgets.Label;
44
import org.eclipse.swt.widgets.Shell;
45
import org.eclipse.swt.widgets.Table;
46
import org.eclipse.swt.widgets.TableColumn;
47
import org.vcs.bazaar.eclipse.ui.UITexts;
51
* @author Javier Der Derian
52
* @BasedOn RevertDialog from BzrEclipse
54
public class IgnoredDialog extends Dialog {
56
private Map<IResource, String> ignored;
57
private TableViewer tableViewer;
58
private List<IResource> unchecked;
64
* @param selectedResources
65
* @param commiteableResources
67
public IgnoredDialog(Shell parentShell, Map<IResource, String> ignored) {
69
setShellStyle(SWT.RESIZE | SWT.MODELESS | SWT.CLOSE | SWT.BORDER | SWT.TITLE);
71
this.ignored = ignored;
74
private void createControls(Composite container)
76
Composite control = new Composite(container, SWT.NONE);
77
control.setLayout(new GridLayout());
79
final Label label = new Label(control, SWT.NONE);
80
label.setText(UITexts.IgnoredDialog_label);
83
tableStyle = SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI | SWT.CHECK | SWT.BORDER;
85
Composite tablecontainer = new Composite(container, SWT.NONE);
87
final Table table = new Table(tablecontainer, tableStyle);
88
table.setHeaderVisible(true);
89
table.setLinesVisible(true);
91
TableColumnLayout layout = new TableColumnLayout();
92
tablecontainer.setLayout(layout);
94
final TableColumn file = new TableColumn(table, SWT.LEFT);
95
file.setResizable(true);
96
file.setText(UITexts.IgnoredDialog_ignoredfile);
97
layout.setColumnData(file, new ColumnWeightData(60, true));
99
final TableColumn pattern = new TableColumn(table, SWT.LEFT);
100
pattern.setResizable(true);
101
pattern.setText(UITexts.IgnoredDialog_match);
102
layout.setColumnData(pattern, new ColumnWeightData(60, true));
104
tableViewer = new CheckboxTableViewer(table);
105
tableViewer.setContentProvider(new IStructuredContentProvider() {
107
public Object[] getElements(Object inputElement) {
108
Map<IResource, String> elements = (Map<IResource, String>)inputElement;
109
return elements.entrySet().toArray();
112
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
116
public void dispose() {
120
tableViewer.setLabelProvider(new IgnoredFilesLabelProvider());
122
tableViewer.setInput(ignored);
123
tableViewer.refresh(true);
124
((CheckboxTableViewer)tableViewer).setAllChecked(true);
127
GridDataFactory gf = GridDataFactory.fillDefaults().align(GridData.FILL, GridData.FILL).grab(true, true);
128
gf.applyTo(tablecontainer);
133
* Create contents of the dialog
138
protected Control createDialogArea(Composite parent) {
139
Composite container = (Composite) super.createDialogArea(parent);
140
container.setLayout(new GridLayout());
141
createControls(container);
146
* Saves list of unchecked items
148
protected void readUnChecked() {
149
final List<IResource> files = new ArrayList<IResource>();
150
for (Entry<IResource, String> element : ignored.entrySet()) {
151
if(((CheckboxTableViewer)tableViewer).getChecked(element) == false) {
152
files.add(element.getKey());
155
this.unchecked = files;
158
public List<IResource> getUnChecked() {
159
return this.unchecked;
164
* Create contents of the button bar
169
protected void createButtonsForButtonBar(Composite parent) {
170
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
172
createButton(parent, IDialogConstants.CANCEL_ID,
173
IDialogConstants.CANCEL_LABEL, false);
177
* Return the initial size of the dialog
180
protected Point getInitialSize() {
181
return new Point(530, 500);
185
protected void okPressed() {
190
// this main is for test the dialog during development
191
public static void main(String[] args) {
192
Display display = new Display();
193
Shell shell = new Shell(display);
194
shell.setMinimumSize(280, 400);
196
IgnoredDialog dialog = new IgnoredDialog(shell, new HashMap<IResource, String>());
197
dialog.setBlockOnOpen(true);
198
int exit = dialog.open();
199
System.out.println("exit: " + exit);