1 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 30 public class FeatureStatusPropertyPage 31 extends PropertyPage 32 implements IWorkbenchPropertyPage { 33 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 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 getReason(IStatus status) { 104 IStatus[] children = status.getChildren(); 105 StringBuffer buffer = new StringBuffer (); 106 for (int i = 0; i < children.length; i++) { 107 String message = children[i].getMessage(); 108 if (message != null && message.length() > 0) { 109 buffer.append( 110 message 111 + System.getProperty("line.separator") + System.getProperty("line.separator")); } 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 message = ""; 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 (UpdateUtils.hasObsoletePatches(feature)) { 149 return IFeature.STATUS_HAPPY; 155 } 156 } 157 } 158 return code; 159 } 160 } 161 | Popular Tags |