~verterok/bzr-eclipse/pluginpath-fix

« back to all changes in this revision

Viewing changes to org.vcs.bazaar.eclipse.ui/src/org/vcs/bazaar/eclipse/ui/dialogs/IgnoredDialog.java

  • Committer: Guillermo Gonzalez
  • Date: 2009-07-09 20:40:43 UTC
  • mfrom: (212.1.4 add-ignore)
  • Revision ID: guillo.gonzo@gmail.com-20090709204043-9l55py1bij7799s0
mergeĀ lp:~verterok/bzr-eclipse/add-ignore

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
* Copyright (C) 2009 Canonical Ltd
 
3
 
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.
 
8
*
 
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.
 
13
*
 
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
 
17
*/
 
18
package org.vcs.bazaar.eclipse.ui.dialogs;
 
19
 
 
20
import java.util.ArrayList;
 
21
import java.util.HashMap;
 
22
import java.util.List;
 
23
import java.util.Map;
 
24
import java.util.Map.Entry;
 
25
 
 
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;
 
48
 
 
49
/**
 
50
 * 
 
51
 * @author Javier Der Derian
 
52
 * @BasedOn RevertDialog from BzrEclipse 
 
53
 */
 
54
public class IgnoredDialog extends Dialog {
 
55
 
 
56
        private Map<IResource, String> ignored;
 
57
        private TableViewer tableViewer;
 
58
        private List<IResource> unchecked;
 
59
        
 
60
        /**
 
61
         * Create the dialog
 
62
         * 
 
63
         * @param parentShell
 
64
         * @param selectedResources 
 
65
         * @param commiteableResources 
 
66
         */
 
67
        public IgnoredDialog(Shell parentShell, Map<IResource, String> ignored) {
 
68
                super(parentShell);
 
69
                setShellStyle(SWT.RESIZE | SWT.MODELESS | SWT.CLOSE | SWT.BORDER | SWT.TITLE);
 
70
                setBlockOnOpen(true);
 
71
                this.ignored = ignored;
 
72
        }
 
73
        
 
74
        private void createControls(Composite container)
 
75
        {
 
76
                Composite control = new Composite(container, SWT.NONE);
 
77
                control.setLayout(new GridLayout());
 
78
                
 
79
                final Label label = new Label(control, SWT.NONE);
 
80
                label.setText(UITexts.IgnoredDialog_label);
 
81
                
 
82
                int tableStyle;
 
83
                tableStyle = SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI | SWT.CHECK | SWT.BORDER;
 
84
                
 
85
                Composite tablecontainer = new Composite(container, SWT.NONE);
 
86
        
 
87
                final Table table = new Table(tablecontainer, tableStyle);
 
88
                table.setHeaderVisible(true);
 
89
                table.setLinesVisible(true);
 
90
                
 
91
                TableColumnLayout layout = new TableColumnLayout(); 
 
92
                tablecontainer.setLayout(layout);
 
93
                // File name
 
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));
 
98
 
 
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));
 
103
                
 
104
                tableViewer = new CheckboxTableViewer(table);
 
105
                tableViewer.setContentProvider(new IStructuredContentProvider() {
 
106
 
 
107
                    public Object[] getElements(Object inputElement) {
 
108
                        Map<IResource, String> elements = (Map<IResource, String>)inputElement;
 
109
                        return elements.entrySet().toArray();
 
110
                    }
 
111
 
 
112
                    public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
 
113
                        // do nothing   
 
114
                    }
 
115
 
 
116
            public void dispose() {
 
117
                // do nothing                
 
118
            }
 
119
                });
 
120
                tableViewer.setLabelProvider(new IgnoredFilesLabelProvider());
 
121
 
 
122
                tableViewer.setInput(ignored);
 
123
                tableViewer.refresh(true);
 
124
                ((CheckboxTableViewer)tableViewer).setAllChecked(true);
 
125
 
 
126
                
 
127
                GridDataFactory gf = GridDataFactory.fillDefaults().align(GridData.FILL, GridData.FILL).grab(true, true);
 
128
        gf.applyTo(tablecontainer);
 
129
        
 
130
        }
 
131
        
 
132
        /**
 
133
         * Create contents of the dialog
 
134
         * 
 
135
         * @param parent
 
136
         */
 
137
        @Override
 
138
        protected Control createDialogArea(Composite parent) {
 
139
                Composite container = (Composite) super.createDialogArea(parent);
 
140
                container.setLayout(new GridLayout());
 
141
                createControls(container);
 
142
                return container;
 
143
        }
 
144
        
 
145
        /**
 
146
         * Saves list of unchecked items
 
147
         */
 
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());
 
153
                        }
 
154
                }
 
155
                this.unchecked = files;
 
156
        }
 
157
        
 
158
        public List<IResource> getUnChecked() {
 
159
                return this.unchecked;
 
160
        }
 
161
        
 
162
        
 
163
        /**
 
164
         * Create contents of the button bar
 
165
         * 
 
166
         * @param parent
 
167
         */
 
168
        @Override
 
169
        protected void createButtonsForButtonBar(Composite parent) {
 
170
                createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
 
171
                                true);
 
172
                createButton(parent, IDialogConstants.CANCEL_ID,
 
173
                                IDialogConstants.CANCEL_LABEL, false);
 
174
        }
 
175
 
 
176
        /**
 
177
         * Return the initial size of the dialog
 
178
         */
 
179
        @Override
 
180
        protected Point getInitialSize() {
 
181
                return new Point(530, 500);
 
182
        }
 
183
        
 
184
        @Override
 
185
        protected void okPressed() { 
 
186
                readUnChecked();
 
187
                super.okPressed();
 
188
        }
 
189
        
 
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);
 
195
                
 
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);
 
200
        }
 
201
}