1 17 package org.eclipse.emf.importer.ui.contribution.base; 18 19 import org.eclipse.core.runtime.IStatus; 20 import org.eclipse.jface.dialogs.ErrorDialog; 21 import org.eclipse.jface.dialogs.IMessageProvider; 22 import org.eclipse.jface.wizard.IWizardPage; 23 import org.eclipse.jface.wizard.WizardPage; 24 import org.eclipse.swt.graphics.Image; 25 import org.eclipse.swt.widgets.Event; 26 import org.eclipse.swt.widgets.Listener; 27 28 import org.eclipse.emf.importer.ImporterPlugin; 29 import org.eclipse.emf.importer.ModelImporter; 30 import org.eclipse.emf.importer.util.ImporterUtil; 31 32 33 36 public abstract class ModelImporterPage extends WizardPage implements Listener 37 { 38 public static final int CAUSE_UNKNOWN = 0; 39 public static final int CAUSE_BACK = 1; 40 public static final int CAUSE_NEXT = 2; 41 public static final int CAUSE_FINISH = 3; 42 public static final int CAUSE_CANCEL = 4; 43 44 protected ModelImporter modelImporter; 45 protected boolean neverVisible = true; 46 protected boolean forwardDirection = true; 47 protected boolean handlingEvent = true; 48 49 public ModelImporterPage(ModelImporter modelImporter, String pageName) 50 { 51 super(pageName); 52 this.modelImporter = modelImporter; 53 setPageComplete(false); 54 } 55 56 public void dispose() 57 { 58 modelImporter = null; 59 super.dispose(); 60 } 61 62 public ModelImporter getModelImporter() 63 { 64 return modelImporter; 65 } 66 67 protected void pageActivated(boolean firstTime, int cause) 68 { 69 } 70 71 protected void pageDeactivated(int cause) 72 { 73 } 74 75 public IWizardPage getNextPage() 76 { 77 forwardDirection = true; 78 return super.getNextPage(); 79 } 80 81 public IWizardPage getPreviousPage() 82 { 83 forwardDirection = false; 84 return super.getPreviousPage(); 85 } 86 87 public boolean isPageComplete() 88 { 89 return getErrorMessage() == null; 90 } 91 92 public boolean isHandlingEvent() 93 { 94 return handlingEvent; 95 } 96 97 public void setHandlingEvent(boolean handlingEvent) 98 { 99 this.handlingEvent = handlingEvent; 100 } 101 102 public void handleEvent(Event event) 103 { 104 if (isHandlingEvent()) 105 { 106 doHandleEvent(event); 107 } 108 } 109 110 protected void doHandleEvent(Event event) 111 { 112 113 } 114 115 protected void handleStatus(IStatus status) 116 { 117 handleStatus(status, null, null, null); 118 } 119 120 protected void handleStatus(IStatus status, String message, String dialogTitle, String dialogMessage) 121 { 122 if (status.isOK()) 123 { 124 handleOKStatus(status, message, dialogTitle, dialogMessage); 125 } 126 else 127 { 128 handleNotOKStatus(status, decodeAction(status), message, dialogTitle, dialogMessage); 129 } 130 } 131 132 protected ImporterUtil.DecodedAction decodeAction(IStatus status) 133 { 134 int actionCode = ImporterUtil.computeActionCode(status); 135 return ImporterUtil.decodeAction(actionCode); 136 } 137 138 protected void handleOKStatus(IStatus status, String message, String dialogTitle, String dialogMessage) 139 { 140 setMessage(null); 141 setErrorMessage(null); 142 } 143 144 protected void handleNotOKStatus(IStatus status, ImporterUtil.DecodedAction decodedAction, String message, String dialogTitle, String dialogMessage) 145 { 146 int messageType = 0; 147 switch(status.getSeverity()) 148 { 149 case IStatus.INFO: 150 { 151 messageType = IMessageProvider.INFORMATION; 152 if (dialogTitle == null) ImporterPlugin.INSTANCE.getString("_UI_DialogInformation_title"); 153 break; 154 } 155 case IStatus.WARNING: 156 messageType = IMessageProvider.WARNING; 157 if (dialogTitle == null) dialogTitle = ImporterPlugin.INSTANCE.getString("_UI_DialogWarning_title"); 158 break; 159 case IStatus.ERROR: 160 messageType = IMessageProvider.ERROR; 161 if (dialogTitle == null) dialogTitle = ImporterPlugin.INSTANCE.getString("_UI_DialogError_title"); 162 break; 163 } 164 165 if (message == null) message = status.getMessage(); 166 setErrorMessage(null); 167 setMessage(null); 168 switch(decodedAction.message) 169 { 170 case ImporterUtil.ACTION_MESSAGE_SET: 171 { 172 setMessage(message); 173 break; 174 } 175 case ImporterUtil.ACTION_DEFAULT: 176 case ImporterUtil.ACTION_MESSAGE_SET_TYPED: 177 { 178 if (messageType == IMessageProvider.ERROR) 179 { 180 setErrorMessage(message); 181 } 182 else 183 { 184 setMessage(message, messageType); 185 } 186 break; 187 } 188 case ImporterUtil.ACTION_MESSAGE_SET_ERROR: 189 { 190 setErrorMessage(message); 191 break; 192 } 193 } 194 195 switch(decodedAction.dialog) 196 { 197 case ImporterUtil.ACTION_DEFAULT: 198 case ImporterUtil.ACTION_DIALOG_SHOW_IF_HAS_CHILD: 199 { 200 if (status.getChildren().length > 0) 201 { 202 ErrorDialog.openError(getShell(), dialogTitle, dialogMessage, status); 203 } 204 break; 205 } 206 case ImporterUtil.ACTION_DIALOG_SHOW: 207 { 208 ErrorDialog.openError(getShell(), dialogTitle, dialogMessage, status); 209 break; 210 } 211 case ImporterUtil.ACTION_DIALOG_SHOW_ERROR: 212 { 213 new ErrorDialog(getShell(), 214 dialogTitle, 215 dialogMessage, 216 status, IStatus.INFO | IStatus.WARNING | IStatus.ERROR) 217 { 218 protected Image getImage() 219 { 220 return getErrorImage(); 221 } 222 }.open(); 223 break; 224 } 225 } 226 } 227 } | Popular Tags |