KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.core.runtime.*;
14 import org.eclipse.jface.dialogs.Dialog;
15 import org.eclipse.swt.*;
16 import org.eclipse.swt.layout.*;
17 import org.eclipse.swt.widgets.*;
18 import org.eclipse.ui.*;
19 import org.eclipse.ui.dialogs.*;
20 import org.eclipse.update.core.*;
21 import org.eclipse.update.internal.operations.*;
22 import org.eclipse.update.internal.ui.model.*;
23 import org.eclipse.update.internal.ui.UpdateUI;
24 import org.eclipse.update.internal.ui.UpdateUIMessages;
25 import org.eclipse.update.operations.*;
26
27 /**
28  * @see PropertyPage
29  */

30 public class FeatureStatusPropertyPage
31     extends PropertyPage
32     implements IWorkbenchPropertyPage {
33     /**
34      *
35      */

36     public FeatureStatusPropertyPage() {
37         noDefaultAndApplyButton();
38     }
39
40     protected Control createContents(Composite parent) {
41         try {
42
43             Composite composite = new Composite(parent, SWT.NONE);
44             GridLayout layout = new GridLayout();
45             layout.numColumns = 1;
46             layout.verticalSpacing = 20;
47             composite.setLayout(layout);
48
49             Text message = new Text(composite, SWT.MULTI | SWT.WRAP);
50             message.setEditable(false);
51             GridData gd = new GridData();
52             gd.widthHint = 350;
53             message.setLayoutData(gd);
54             
55             ConfiguredFeatureAdapter adapter = (ConfiguredFeatureAdapter) getElement();
56             IFeature feature = adapter.getFeature(null);
57             
58             if (OperationsManager.findPendingOperation(feature) != null) {
59                 message.setText(UpdateUIMessages.FeatureStatusPropertyPage_pendingChanges);
60                 return composite;
61             }
62             
63             IStatus status = getStatus(feature);
64             int severity = status.getSeverity();
65             if (severity == IStatus.ERROR
66                 && getStatusCode(feature, status) == IFeature.STATUS_HAPPY) {
67                 severity = IStatus.OK;
68                 message.setText(UpdateUIMessages.FeatureStatusPropertyPage_goodConfiguration);
69             } else {
70                 message.setText(status.getMessage());
71             }
72             if (severity != IStatus.OK && status.isMultiStatus()) {
73                 String JavaDoc reason = getReason(status);
74                 if (reason.length() > 0) {
75                     Composite comp = new Composite(composite, SWT.NONE);
76                     comp.setLayout(new GridLayout());
77                     gd = new GridData(GridData.FILL_BOTH);
78                     comp.setLayoutData(gd);
79
80                     Label label = new Label(comp, SWT.NONE);
81                     label.setText(UpdateUIMessages.FeatureStatusPropertyPage_reason);
82
83                     Text text =
84                         new Text(comp, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
85                     text.setEditable(false);
86                     text.setText(reason);
87                     gd.widthHint = 350;
88                     text.setLayoutData(gd);
89                 }
90
91             }
92             
93             Dialog.applyDialogFont(parent);
94             
95             return composite;
96
97         } catch (CoreException e) {
98         }
99
100         return null;
101     }
102
103     private String JavaDoc getReason(IStatus status) {
104         IStatus[] children = status.getChildren();
105         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
106         for (int i = 0; i < children.length; i++) {
107             String JavaDoc message = children[i].getMessage();
108             if (message != null && message.length() > 0) {
109                 buffer.append(
110                     message
111                         + System.getProperty("line.separator") //$NON-NLS-1$
112
+ System.getProperty("line.separator")); //$NON-NLS-1$
113
}
114         }
115         return buffer.toString();
116     }
117
118     private IStatus getStatus(IFeature feature) throws CoreException {
119         if (feature instanceof MissingFeature) {
120             int severity;
121             String JavaDoc message = ""; //$NON-NLS-1$
122
if (((MissingFeature) feature).isOptional()) {
123                 severity = IStatus.OK;
124                 message = UpdateUIMessages.FeatureStatusPropertyPage_missingOptional;
125             } else {
126                 severity = IStatus.ERROR;
127                 message = UpdateUIMessages.FeatureStatusPropertyPage_missing;
128             }
129             return new Status(severity, UpdateUI.PLUGIN_ID, IStatus.OK, message, null);
130         }
131         return SiteManager.getLocalSite().getFeatureStatus(feature);
132     }
133
134     private int getStatusCode(IFeature feature, IStatus status) {
135         int code = status.getCode();
136         if (code == IFeature.STATUS_UNHAPPY) {
137             if (status.isMultiStatus()) {
138                 IStatus[] children = status.getChildren();
139                 for (int i = 0; i < children.length; i++) {
140                     IStatus child = children[i];
141                     if (child.isMultiStatus()
142                         || child.getCode() != IFeature.STATUS_DISABLED)
143                         return code;
144                 }
145                 // If we are here, global status is unhappy
146
// because one or more included features
147
// is disabled.
148
if (UpdateUtils.hasObsoletePatches(feature)) {
149                     // The disabled included features
150
// are old patches that are now
151
// subsumed by better versions of
152
// the features they were designed to
153
// patch.
154
return IFeature.STATUS_HAPPY;
155                 }
156             }
157         }
158         return code;
159     }
160 }
161
Popular Tags