KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > ui > properties > FeatureCopyrightPropertyPage


1 /*******************************************************************************
2  * Copyright (c) 2003, 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.properties;
12
13 import java.net.*;
14
15 import org.eclipse.core.runtime.*;
16 import org.eclipse.jface.dialogs.Dialog;
17 import org.eclipse.swt.*;
18 import org.eclipse.swt.events.*;
19 import org.eclipse.swt.graphics.*;
20 import org.eclipse.swt.layout.*;
21 import org.eclipse.swt.widgets.*;
22 import org.eclipse.ui.*;
23 import org.eclipse.ui.dialogs.*;
24 import org.eclipse.update.core.*;
25 import org.eclipse.update.internal.ui.model.*;
26 import org.eclipse.update.internal.ui.parts.*;
27 import org.eclipse.update.internal.ui.UpdateUI;
28 import org.eclipse.update.internal.ui.UpdateUIMessages;
29
30 /**
31  * @see PropertyPage
32  */

33 public class FeatureCopyrightPropertyPage extends PropertyPage implements IWorkbenchPropertyPage {
34     /**
35      *
36      */

37     public FeatureCopyrightPropertyPage() {
38         noDefaultAndApplyButton();
39     }
40
41     protected Control createContents(Composite parent) {
42         try {
43             IFeatureAdapter adapter = (IFeatureAdapter) getElement();
44             IFeature feature = adapter.getFeature(null);
45
46             Composite composite = new Composite(parent, SWT.NULL);
47             composite.setLayout(new GridLayout());
48
49             Label label = new Label(composite, SWT.WRAP);
50             GridData gd =
51                 new GridData(
52                     GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
53             gd.widthHint = computeWidthLimit(label, 80);
54             label.setLayoutData(gd);
55
56             IURLEntry copyright = feature.getCopyright();
57             String JavaDoc annotation = (copyright != null) ? copyright.getAnnotation() : null;
58
59             if (annotation != null && annotation.length() > 0) {
60                 label.setText(annotation);
61                 final URL url = copyright.getURL();
62                 String JavaDoc filename = (url != null) ? url.getFile() : null;
63                 if (filename != null
64                     && (filename.endsWith(".htm") || filename.endsWith(".html"))) { //$NON-NLS-1$ //$NON-NLS-2$
65
Button button = new Button(composite, SWT.PUSH);
66                     button.setText(UpdateUIMessages.FeatureCopyrightPropertyPage_showInBrowser);
67                     button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
68                     SWTUtil.setButtonDimensionHint(button);
69                     button.addSelectionListener(new SelectionAdapter() {
70                         public void widgetSelected(SelectionEvent e) {
71                             UpdateUI.showURL(url.toExternalForm());
72                         }
73                     });
74                 }
75             } else {
76                 label.setText(UpdateUIMessages.FeatureCopyrightPropertyPage_noCopyright);
77             }
78             Dialog.applyDialogFont(parent);
79         } catch (CoreException e) {
80         }
81         return null;
82     }
83     
84     private int computeWidthLimit(Label label, int nchars) {
85         GC gc = new GC(label);
86         gc.setFont(label.getFont());
87         FontMetrics fontMetrics= gc.getFontMetrics();
88         gc.dispose();
89         return Dialog.convertWidthInCharsToPixels(fontMetrics, nchars);
90     }
91
92 }
93
Popular Tags