KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > cheatsheets > composite > explorer > ConfirmRestartDialog


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
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
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.cheatsheets.composite.explorer;
12
13 import org.eclipse.jface.dialogs.Dialog;
14 import org.eclipse.jface.viewers.IStructuredContentProvider;
15 import org.eclipse.jface.viewers.ITableLabelProvider;
16 import org.eclipse.jface.viewers.LabelProvider;
17 import org.eclipse.jface.viewers.TableViewer;
18 import org.eclipse.jface.viewers.Viewer;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.graphics.Image;
21 import org.eclipse.swt.layout.GridData;
22 import org.eclipse.swt.layout.GridLayout;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.swt.widgets.Control;
25 import org.eclipse.swt.widgets.Label;
26 import org.eclipse.swt.widgets.Shell;
27 import org.eclipse.ui.ISharedImages;
28 import org.eclipse.ui.PlatformUI;
29 import org.eclipse.ui.internal.cheatsheets.CheatSheetPlugin;
30 import org.eclipse.ui.internal.cheatsheets.ICheatSheetResource;
31 import org.eclipse.ui.internal.cheatsheets.Messages;
32 import org.eclipse.ui.internal.cheatsheets.composite.model.AbstractTask;
33
34 public class ConfirmRestartDialog extends Dialog {
35
36     public class TaskLabelProvider extends LabelProvider implements ITableLabelProvider {
37         public String JavaDoc getColumnText(Object JavaDoc obj, int index) {
38             return treeLabelProvider.getText(obj);
39         }
40         
41         public Image getColumnImage(Object JavaDoc obj, int index) {
42             return treeLabelProvider.getImage(obj);
43         }
44         
45         public Image getImage(Object JavaDoc obj) {
46             return PlatformUI.getWorkbench().
47                     getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
48         }
49         
50     }
51
52     public class TaskContentProvider implements IStructuredContentProvider {
53         
54         Object JavaDoc[] input;
55         
56         public void inputChanged(Viewer v, Object JavaDoc oldInput, Object JavaDoc newInput) {
57             input = (Object JavaDoc[])newInput;
58         }
59         
60         public void dispose() {
61         }
62         
63         public Object JavaDoc[] getElements(Object JavaDoc parent) {
64             return input;
65         }
66     }
67     
68     private AbstractTask[] tasks;
69     
70     private TreeLabelProvider treeLabelProvider;
71
72     protected ConfirmRestartDialog(Shell parentShell, AbstractTask[] restartTasks,
73                                    TreeLabelProvider treeLabelProvider) {
74         super(parentShell);
75         this.tasks = restartTasks;
76         this.treeLabelProvider = treeLabelProvider;
77     }
78     
79     protected Control createDialogArea(Composite parent) {
80         Composite composite = new Composite(parent, SWT.NULL);
81         composite.setLayout(new GridLayout());
82         Label header = new Label(composite,SWT.NULL);
83         header.setText(Messages.COMPOSITE_RESET_TASK_DIALOG_MESSAGE);
84         TableViewer viewer = new TableViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
85         viewer.setContentProvider(new TaskContentProvider());
86         viewer.setLabelProvider(new TaskLabelProvider());
87         viewer.setInput(tasks);
88         GridData taskData = new GridData();
89         taskData.widthHint = 400;
90         taskData.heightHint = 200;
91         taskData.horizontalAlignment = SWT.FILL;
92         taskData.verticalAlignment = SWT.FILL;
93         viewer.getControl().setLayoutData(taskData);
94         return composite;
95     }
96     
97     protected void configureShell(Shell newShell) {
98         super.configureShell(newShell);
99         newShell.setImage(CheatSheetPlugin.getPlugin().getImage(ICheatSheetResource.CHEATSHEET_RETURN));
100         setShellStyle(getShellStyle() | SWT.RESIZE);
101         newShell.setText(Messages.COMPOSITE_RESET_TASK_DIALOG_TITLE);
102     }
103
104 }
105
Popular Tags