KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > ui > wizards > EditSiteDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.update.internal.ui.wizards;
12
13 import java.net.MalformedURLException JavaDoc;
14 import java.net.URL JavaDoc;
15
16 import org.eclipse.swt.widgets.Shell;
17 import org.eclipse.update.internal.ui.UpdateUI;
18 import org.eclipse.update.internal.ui.model.SiteBookmark;
19
20
21 public class EditSiteDialog extends NewUpdateSiteDialog {
22     SiteBookmark bookmark;
23     private int ignoreBookmark = -1;
24
25     public EditSiteDialog(Shell parentShell, SiteBookmark bookmark) {
26         super(parentShell);
27         this.bookmark = bookmark;
28     }
29     
30     public EditSiteDialog(Shell parentShell, SiteBookmark bookmark, SiteBookmark[] siteBookmarks) {
31         super(parentShell, siteBookmarks);
32         this.bookmark = bookmark;
33         ignoreBookmark(siteBookmarks);
34     }
35
36     public EditSiteDialog(Shell parentShell, SiteBookmark bookmark, boolean enableOK) {
37         super(parentShell,enableOK);
38         this.bookmark = bookmark;
39     }
40     
41     public EditSiteDialog(Shell parentShell, SiteBookmark bookmark, SiteBookmark[] siteBookmarks, boolean enableOK) {
42         super(parentShell, enableOK, siteBookmarks);
43         this.bookmark = bookmark;
44         ignoreBookmark(siteBookmarks);
45     }
46
47     protected void initializeFields() {
48         name.setText(bookmark.getName());
49         url.setText(bookmark.getURL().toString());
50         url.setEditable(!bookmark.isLocal());
51     }
52
53     protected void update() {
54         try {
55             bookmark.setName(name.getText());
56             bookmark.setURL(new URL JavaDoc(url.getText()));
57             UpdateUI.getDefault().getUpdateModel().fireObjectChanged(bookmark, null);
58         } catch (MalformedURLException JavaDoc e) {
59         }
60     }
61     
62     private void ignoreBookmark( SiteBookmark[] siteBookmarks) {
63         
64         for( int i = 0; i < siteBookmarks.length; i++) {
65
66             if (siteBookmarks[i].getLabel().equals(bookmark.getLabel().trim()) &&
67                 siteBookmarks[i].getURL().equals(bookmark.getURL())) {
68                 ignoreBookmark = i;
69                 return;
70             }
71             
72         }
73     }
74     
75     protected boolean isCurrentlyEditedSiteBookmark( int index) {
76         
77         return index == ignoreBookmark;
78     }
79 }
80
Popular Tags