Added externaltools plugin
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.news / src / net / sourceforge / phpeclipse / news / dialogs / NewChannelDialog.java
1 /*******************************************************************************
2  * Copyright (c) 2004 J�r�me N�gre.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.jnegre.org/cpl1_0.html
7  * 
8  * Contributors:
9  *     J�r�me N�gre - initial API and implementation
10  *******************************************************************************/
11
12 /*
13  * Created on 19 d�c. 2004
14  */
15 package net.sourceforge.phpeclipse.news.dialogs;
16
17 import java.util.ArrayList;
18
19 import net.sourceforge.phpeclipse.news.Channel;
20 import net.sourceforge.phpeclipse.news.Plugin;
21 import net.sourceforge.phpeclipse.news.pref.ChannelStore;
22
23 import org.eclipse.jface.dialogs.Dialog;
24 import org.eclipse.swt.SWT;
25 import org.eclipse.swt.layout.GridData;
26 import org.eclipse.swt.layout.GridLayout;
27 import org.eclipse.swt.widgets.Composite;
28 import org.eclipse.swt.widgets.Control;
29 import org.eclipse.swt.widgets.Label;
30 import org.eclipse.swt.widgets.Shell;
31 import org.eclipse.swt.widgets.Text;
32
33 /**
34  * @author J�r�me N�gre
35  */
36 public class NewChannelDialog extends Dialog {
37
38         private Text titleText;
39         private Text urlText;
40         
41         /**
42          * @param parentShell
43          */
44         public NewChannelDialog(Shell parentShell) {
45                 super(parentShell);
46                 setShellStyle(SWT.DIALOG_TRIM|SWT.RESIZE);
47         }
48         
49         protected Control createDialogArea(Composite parent) {
50               Composite composite = (Composite)super.createDialogArea(parent);
51               GridLayout layout = new GridLayout(2,false);
52               composite.setLayout(layout);
53               //composite.setBackground(composite.getDisplay().getSystemColor(SWT.COLOR_CYAN));
54               
55               Label label = new Label(composite, SWT.NONE);
56               label.setText("Title: ");
57               titleText = new Text(composite, SWT.BORDER);
58               GridData gd = new GridData(GridData.FILL_HORIZONTAL);
59               titleText.setLayoutData(gd);
60
61               label = new Label(composite, SWT.NONE);
62               label.setText("Url: ");
63               urlText = new Text(composite, SWT.BORDER);
64               gd = new GridData(GridData.FILL_HORIZONTAL);
65               urlText.setLayoutData(gd);
66
67               return composite;
68            }
69
70         protected void configureShell(Shell newShell) {
71               super.configureShell(newShell);
72               newShell.setText("Add New Channel");
73            }
74
75         /* (non-Javadoc)
76          * @see org.eclipse.jface.dialogs.Dialog#okPressed()
77          */
78         protected void okPressed() {
79                 Channel channel = new Channel(titleText.getText(), urlText.getText());
80                 ArrayList channels = Plugin.getDefault().getChannelList();
81                 ChannelStore.saveReadStatus(channels);
82                 channels.add(channel);
83                 ChannelStore.setChannels(channels);
84                 Plugin.getDefault().updateChannelList();
85                 Plugin.getDefault().update();
86                 this.close();
87         }
88         
89 }