List of usage examples for org.eclipse.jface.dialogs MessageDialog MessageDialog
public MessageDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage, int dialogImageType, int defaultIndex, String... dialogButtonLabels)
From source file:com.googlecode.osde.internal.runtime.ShowKeysAction.java
License:Apache License
public void run(IAction action) { try {/* w w w . j a v a2 s .c o m*/ ApplicationInformation appInfo = OpenSocialUtil.createApplicationInformation(file); ApplicationService service = Activator.getDefault().getApplicationService(); final ApplicationImpl application = service.getApplication(appInfo.getAppId()); if (application != null) { ImageDescriptor imageDescriptor = Activator.getDefault().getImageRegistry() .getDescriptor("icons/icon_key.gif"); MessageDialog dialog = new MessageDialog(shell, "Application information", imageDescriptor.createImage(), "This is keys for accessing from external service.", MessageDialog.INFORMATION, new String[] { "OK" }, 0) { @Override protected Control createCustomArea(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2; composite.setLayout(gridLayout); GridData layoutData = new GridData(GridData.FILL_HORIZONTAL); composite.setLayoutData(layoutData); Label label = new Label(composite, SWT.NONE); label.setText("Title:"); label = new Label(composite, SWT.NONE); label.setText(application.getTitle()); label = new Label(composite, SWT.NONE); label.setText("Path:"); label = new Label(composite, SWT.NONE); label.setText(application.getPath()); label = new Label(composite, SWT.NONE); label.setText("Consumer Key:"); Text text = new Text(composite, SWT.BORDER | SWT.MULTI); text.setText(application.getConsumerKey()); text.setEditable(false); text.setSelection(0); layoutData = new GridData(GridData.FILL_HORIZONTAL); layoutData.heightHint = 20; text.setLayoutData(layoutData); label = new Label(composite, SWT.NONE); label.setText("Consumer Secret:"); text = new Text(composite, SWT.BORDER | SWT.MULTI); text.setText(application.getConsumerSecret()); text.setEditable(false); text.setSelection(0); layoutData = new GridData(GridData.FILL_HORIZONTAL); layoutData.heightHint = 20; text.setLayoutData(layoutData); return parent; } }; dialog.open(); } else { MessageDialog.openWarning(shell, "Warning", "This application does not run yet."); } } catch (CoreException e) { MessageDialog.openError(shell, "Error", "Invalid gadget file. " + e.getMessage()); } catch (ConnectionException e) { MessageDialog.openError(shell, "Error", "Shindig database not started yet."); } catch (ParserException e) { MessageDialog.openError(shell, "Error", "Invalid gadget file. " + e.getMessage()); } }
From source file:com.googlecode.osde.internal.shindig.ShowPublicCertificateAction.java
License:Apache License
public void run(IAction action) { ImageDescriptor imageDescriptor = Activator.getDefault().getImageRegistry() .getDescriptor("icons/icon_key.gif"); MessageDialog dialog = new MessageDialog(shell, "Public Certificate", imageDescriptor.createImage(), "This is Public Certificate for OAuth.", MessageDialog.INFORMATION, new String[] { "OK" }, 0) { @Override/*from w w w. java2 s . c o m*/ protected Control createCustomArea(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout()); GridData layoutData = new GridData(GridData.FILL_HORIZONTAL); composite.setLayoutData(layoutData); Text text = new Text(composite, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); text.setText(PUBLIC_CER); text.setSelection(0, PUBLIC_CER.length()); text.setEditable(false); layoutData = new GridData(GridData.FILL_HORIZONTAL); layoutData.heightHint = 250; text.setLayoutData(layoutData); return parent; } }; dialog.open(); }
From source file:com.gorillalogic.monkeyconsole.editors.FoneMonkeyTestContributor.java
License:Open Source License
private void createActions(String extention) { actions.removeAll(actions);/*w w w .j a v a 2 s . c o m*/ clearToolItem = new Action() { public void run() { MessageDialog dlg = new MessageDialog(activeEditorPart.getSite().getShell(), "Delete All?", MonkeyTalkImagesEnum.CLEAR.image.createImage(), "Are you sure you would like to delete all items?", MessageDialog.WARNING, new String[] { "Cancel", "OK" }, 1); if (dlg.open() == 1) FoneMonkeyPlugin.getDefault().getController().clear(); } }; clearToolItem.setText("Clear"); clearToolItem.setToolTipText("Clear All"); clearToolItem.setImageDescriptor(MonkeyTalkImagesEnum.CLEARROW.image); clearToolItem.setId("monkeyclear"); clearToolItem.setEnabled(false); actions.add(clearToolItem); componentTreeToolItem = new Action() { public void run() { FoneMonkeyPlugin.getDefault().getController().fetchAndShowComponentTree(); } }; componentTreeToolItem.setText("View Component Tree"); componentTreeToolItem.setToolTipText("View Component Tree"); componentTreeToolItem.setImageDescriptor(MonkeyTalkImagesEnum.TREE.image); componentTreeToolItem.setId("refreshtree"); componentTreeToolItem.setEnabled(false); actions.add(componentTreeToolItem); actions.add(new Separator()); // ///////////////////// // Play Back selection type component // ///////////////////// if (extention.equalsIgnoreCase("mt")) { playToolItem = new Action() { public void run() { if (FoneMonkeyPlugin.getDefault().getController().isRecordingON()) { editor.getFmch().writeToConsole( "WARNING: PlayAll action invoked, but current console window reports recording ON"); return; } if (editor.getActivePage() == 1) { editor.convertFromMonkeyTalk(); } editor.getEditorSite().getWorkbenchWindow().getWorkbench().saveAllEditors(true); FoneMonkeyPlugin.getDefault().getController().startReplayAll(); } }; playToolItem.setText("Play All"); playToolItem.setToolTipText("Play All"); playToolItem.setEnabled(false); playToolItem.setImageDescriptor(MonkeyTalkImagesEnum.PLAY.image); playToolItem.setId("monkeyplay"); actions.add(playToolItem); } else if (extention.equalsIgnoreCase("mts")) { playToolItem = new Action() { public void run() { editor.getEditorSite().getWorkbenchWindow().getWorkbench().saveAllEditors(true); FoneMonkeyPlugin.getDefault().getController().startSuiteReplay(); } }; playToolItem.setText("Run As Suite"); playToolItem.setToolTipText("Run as a Test Suite"); playToolItem.setImageDescriptor(MonkeyTalkImagesEnum.PLAY.image); playToolItem.setId("monkeyplaysuite"); playToolItem.setEnabled(false); actions.add(playToolItem); } else if (extention.equalsIgnoreCase("js")) { playToolItem = new Action() { public void run() { try { jsEditor.getEditorSite().getWorkbenchWindow().getWorkbench().saveAllEditors(true); FoneMonkeyPlugin.getDefault().getController().startJScriptReplay(); } catch (Exception e) { e.printStackTrace(); } } }; playToolItem.setText("Run Script"); playToolItem.setToolTipText("Run Script"); playToolItem.setImageDescriptor(MonkeyTalkImagesEnum.PLAY.image); playToolItem.setId("org.eclipse.wst.jsdt.internal.ui.javaeditor.monkeytalk.runaction"); playToolItem.setEnabled(false); actions.add(playToolItem); } stopToolItem.setText("Stop"); stopToolItem.setToolTipText("Stop"); stopToolItem.setEnabled(false); stopToolItem.setImageDescriptor(MonkeyTalkImagesEnum.STOP.image); stopToolItem.setId("monkeystop"); actions.add(stopToolItem); recordToolItem.setEnabled(false); recordToolItem.setText("Record"); recordToolItem.setToolTipText("Record"); recordToolItem.setImageDescriptor(MonkeyTalkImagesEnum.RECORDING.image); recordToolItem.setId("monkeyrecord"); actions.add(recordToolItem); playOnCloudAction.setText("Submit to Cloud"); playOnCloudAction.setToolTipText("Submit Job to CloudMonkey"); playOnCloudAction.setImageDescriptor(MonkeyTalkImagesEnum.PLAYONCLOUD.image); playOnCloudAction.setId("monkeyplaysuiteoncloud"); playOnCloudAction.setEnabled(false); actions.add(playOnCloudAction); actions.add(new Separator()); // ////////////////////// // Connection Component // ///////////////////// List<Action> connectionItems = new ArrayList<Action>(); // //////////// connectionDropdown = new DropDownMenuAction(connectionItems) { }; connectionDropdown.setId("monkeyconnect"); actions.add(connectionDropdown); // //////////////////////////////////// connectToAndroidEmulatorTethered = new ConnectionItem(connectionDropdown, ConnectionTypesEnum.EMULATOR, "Android Emulator/Tethered Device", MonkeyTalkImagesEnum.CONNECTANDROIDEMULATOR.image); if (new Boolean(FoneMonkeyPlugin.getDefault().getPreferenceStore() .getString(PreferenceConstants.P_INCLUDEANDROID))) { connectionItems.add(connectToAndroidEmulatorTethered); } // /////////////// connectToiOSSimulator = new ConnectionItem(connectionDropdown, ConnectionTypesEnum.SIMULATOR, "iOS Simulator", MonkeyTalkImagesEnum.CONNECTIOSEMMULATOR.image); if (new Boolean( FoneMonkeyPlugin.getDefault().getPreferenceStore().getString(PreferenceConstants.P_INCLUDEIOS))) { connectionItems.add(connectToiOSSimulator); } // //////////////////////////////////////////////////////// connectNetworked = new ConnectionItem(connectionDropdown, ConnectionTypesEnum.NETWORKED_ANDROID, "Networked Android Device...", MonkeyTalkImagesEnum.CONNECTNETWORKEDANDROID.image) { @Override public void doRun(MonkeyTalkController controller) { String host = controller.getHost(true); if (host != null) { this.setText("Device at " + controller.preferenceStore.getString(PreferenceConstants.C_HOST)); this.setToolTipText( "Device at " + controller.preferenceStore.getString(PreferenceConstants.C_HOST)); controller.connect(ConnectionTypesEnum.NETWORKED_ANDROID); controller.setHost(host); } } }; if (new Boolean(FoneMonkeyPlugin.getDefault().getPreferenceStore() .getString(PreferenceConstants.P_INCLUDEANDROID))) { connectionItems.add(connectNetworked); } // //////////////////////////////////////////////////////// connectCloud = new ConnectionItem(connectionDropdown, ConnectionTypesEnum.CLOUD_ANDROID, "CloudMonkey Android Emulator", MonkeyTalkImagesEnum.CONNECTCLOUDMONKEY.image) { public void doRun(MonkeyTalkController controller) { String host = controller.getCloudHost(); if (host != null) { connectCloud.setText("CloudMonkey at " + controller.preferenceStore.getString(PreferenceConstants.C_CLOUD_HOST)); connectCloud.setToolTipText("CloudMonkey at " + controller.preferenceStore.getString(PreferenceConstants.C_CLOUD_HOST)); controller.setHost(host); controller.connect(ConnectionTypesEnum.CLOUD_ANDROID); } } }; if (new Boolean(FoneMonkeyPlugin.getDefault().getPreferenceStore() .getString(PreferenceConstants.P_INCLUDEANDROID))) { // Uncomment to enable interactive record/playback on Cloud // connectionItems.add(connectCloud); } connectNetworkedIos = new ConnectionItem(connectionDropdown, ConnectionTypesEnum.NETWORKED_IOS, "Networked iOS Device...", MonkeyTalkImagesEnum.CONNECTNETWORKEDIOS.image) { public void doRun(MonkeyTalkController controller) { String host = controller.getHost(true); if (host != null) { connectNetworkedIos.setText( "Device at " + controller.preferenceStore.getString(PreferenceConstants.C_HOST)); connectNetworkedIos.setToolTipText( "Device at " + controller.preferenceStore.getString(PreferenceConstants.C_HOST)); controller.connect(ConnectionTypesEnum.NETWORKED_IOS); controller.setHost(host); } } }; if (new Boolean( FoneMonkeyPlugin.getDefault().getPreferenceStore().getString(PreferenceConstants.P_INCLUDEIOS))) { connectionItems.add(connectNetworkedIos); } noDeviceSelected = new ConnectionItem(connectionDropdown, ConnectionTypesEnum.NO_DEVICE, "No Device Selected", MonkeyTalkImagesEnum.NOCONNECTION.image); connectionItems.add(noDeviceSelected); if (connectionDropdown != null && connectionItems.size() > 0) { connectionDropdown.setSelectedAction(connectionItems.get(0)); } setupFilterDropdown(actions); Action webAction = new Action() { public void run() { URL webUrl; try { webUrl = new URL("http://www.gorillalogic.com/testing-tools/support-services"); } catch (MalformedURLException e) { return; } try { IWebBrowser browser = PlatformUI.getWorkbench().getBrowserSupport() .createBrowser("GorillaLogic"); browser.openURL(webUrl); } catch (PartInitException e) { return; } } }; webAction.setToolTipText("Having trouble getting started? Let us help!"); //$NON-NLS-1$ ImageDescriptor newImage = FoneMonkeyPlugin.getImageDescriptor("icons/gl-icon-16.png"); webAction.setImageDescriptor(newImage); //$NON-NLS-1$ webAction.setId("monkeycontactus"); actions.add(webAction); // ////////////////////////////////////////////////////////////////////////// // / Section for configuration options // ////////////////////////////////////////////////////////////////////////// actions.add(new Separator()); // This action setup the thinktime and timeout Action timeSetupAction = new Action() { public void run() { TimeSetupWizard wizard = new TimeSetupWizard(); WizardDialog dialog = new WizardDialog(new Shell(), wizard); dialog.create(); dialog.open(); } }; timeSetupAction.setToolTipText("Thinktime/Timeout setup"); timeSetupAction.setImageDescriptor(MonkeyTalkImagesEnum.TIME.image); //$NON-NLS-1$ timeSetupAction.setId("monkeytimeSetup"); actions.add(timeSetupAction); // This action is to set up if the execution should take screenshots on errors Action screenshotOnErrorAction = new Action() { public void run() { FoneMonkeyPlugin.getDefault().getPreferenceStore() .setValue(PreferenceConstants.P_TAKEERRORSCREENSHOTS, this.isChecked()); } }; screenshotOnErrorAction.setImageDescriptor(MonkeyTalkImagesEnum.SCREENSHOTERROR.image); if (FoneMonkeyPlugin.getDefault().getPreferenceStore() .getBoolean(PreferenceConstants.P_TAKEERRORSCREENSHOTS)) { screenshotOnErrorAction.setChecked(true); } else { screenshotOnErrorAction.setChecked(false); } screenshotOnErrorAction.setToolTipText("Take screenshot on error."); screenshotOnErrorAction.setId("monkeyScreenshotOnError"); actions.add(screenshotOnErrorAction); // This action is to set up the taking of screenshots while executing commands Action takeScreenshot = new Action() { public void run() { FoneMonkeyPlugin.getDefault().getPreferenceStore() .setValue(PreferenceConstants.P_TAKEAFTERSCREENSHOTS, this.isChecked()); } }; takeScreenshot.setImageDescriptor(MonkeyTalkImagesEnum.SCREENSHOT.image); if (FoneMonkeyPlugin.getDefault().getPreferenceStore() .getBoolean(PreferenceConstants.P_TAKEAFTERSCREENSHOTS)) { takeScreenshot.setChecked(true); } else { takeScreenshot.setChecked(false); } takeScreenshot.setToolTipText("Take screenchots on command execution."); takeScreenshot.setId("monkeyTakeScreenShot"); actions.add(takeScreenshot); }
From source file:com.hangum.tadpole.rdb.core.util.GrantCheckerUtils.java
License:Open Source License
/** * execute query//from ww w . ja v a 2 s . c o m * * @param userDB * @return * @throws Exception */ public static boolean ifExecuteQuery(UserDBDAO userDB) throws Exception { // security check. if (!TadpoleSecurityManager.getInstance().isLock(userDB)) { throw new Exception(Messages.get().ResultMainComposite_1); } if (PublicTadpoleDefine.YES_NO.YES.name().equals(userDB.getQuestion_dml()) || PermissionChecker.isProductBackup(userDB)) { MessageDialog dialog = new MessageDialog(null, Messages.get().Confirm, null, Messages.get().GrantCheckerUtils_0, MessageDialog.ERROR, new String[] { Messages.get().YES, Messages.get().NO }, 1); if (dialog.open() == 1) return false; } return true; }
From source file:com.hangum.tadpole.rdb.core.util.GrantCheckerUtils.java
License:Open Source License
/** * ?? .//from ww w.ja va 2s .co m * * - DB lock ??? * - dml ? ??? * - ?, ? select ? * * @param userDB * @param reqQuery * @throws Exception */ public static boolean ifExecuteQuery(UserDBDAO userDB, RequestQuery reqQuery) throws Exception { // security check. if (!TadpoleSecurityManager.getInstance().isLock(userDB)) { throw new Exception(Messages.get().ResultMainComposite_1); } // ? ? . if (PublicTadpoleDefine.YES_NO.YES.name().equals(userDB.getQuestion_dml()) || PermissionChecker.isProductBackup(userDB)) { boolean isDDLQuestion = !reqQuery.isStatement(); if (reqQuery.getExecuteType() == EditorDefine.EXECUTE_TYPE.ALL) { for (String strSQL : reqQuery.getOriginalSql().split(PublicTadpoleDefine.SQL_DELIMITER)) { if (!SQLUtil.isStatement(strSQL)) { isDDLQuestion = true; break; } } } if (isDDLQuestion) { MessageDialog dialog = new MessageDialog(null, Messages.get().Execute, null, Messages.get().GrantCheckerUtils_0, MessageDialog.QUESTION, new String[] { Messages.get().YES, Messages.get().NO }, 1); if (dialog.open() != MessageDialog.OK) return false; } } return true; }
From source file:com.heroku.eclipse.ui.git.HerokuCredentialsProvider.java
License:Open Source License
/** * Opens a dialog for a single non-user, non-password type item. * @param shell the shell to use/*from ww w.j a va 2 s .co m*/ * @param uri the uri of the get request * @param item the item to handle * @return <code>true</code> if the request was successful and values were supplied; * <code>false</code> if the user canceled the request and did not supply all requested values. */ private boolean getSingleSpecial(Shell shell, URIish uri, CredentialItem item) { if (item instanceof CredentialItem.InformationalMessage) { MessageDialog.openInformation(shell, UIText.EGitCredentialsProvider_information, item.getPromptText()); return true; } else if (item instanceof CredentialItem.YesNoType) { CredentialItem.YesNoType v = (CredentialItem.YesNoType) item; String[] labels = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }; int[] resultIDs = new int[] { IDialogConstants.YES_ID, IDialogConstants.NO_ID, IDialogConstants.CANCEL_ID }; MessageDialog dialog = new MessageDialog(shell, UIText.EGitCredentialsProvider_question, null, item.getPromptText(), MessageDialog.QUESTION_WITH_CANCEL, labels, 0); dialog.setBlockOnOpen(true); int r = dialog.open(); if (r < 0) { return false; } switch (resultIDs[r]) { case IDialogConstants.YES_ID: { v.setValue(true); return true; } case IDialogConstants.NO_ID: { v.setValue(false); return true; } default: // abort return false; } } else { // generically handles all other types of items return getMultiSpecial(shell, uri, item); } }
From source file:com.hilotec.elexis.messwerte.v2.views.ExportDialog.java
License:Open Source License
@Override protected void okPressed() { try {/* www . j a va2 s . c om*/ if (btnPatFromTo.getSelection()) { int from = Integer.parseInt(patNumberFrom.getText()); int to = Integer.parseInt(patNumberTo.getText()); if (to < from) { throw new Exception(Messages.ExportDialog_Exception_PatNumber); } expData.setPatientNumberFrom(from); expData.setPatientNumberTo(to); } else { if (patNrMin == -1 || patNrMax == -1) { calcMinMaxPatNumbers(); } expData.setPatientNumberFrom(patNrMin); expData.setPatientNumberTo(patNrMax); } if (btnDateFromTo.getSelection()) { Date from = dateFrom.getDate(); Date to = dateTo.getDate(); if (to.before(from)) { throw new Exception(Messages.ExportDialog_Exception_Datum); } expData.setDateFrom(new TimeTool(from.getTime())); expData.setDateTo(new TimeTool(to.getTime())); expData.setCheckDate(true); } else { expData.setDateFrom(new TimeTool(TimeTool.BEGINNING_OF_UNIX_EPOCH)); expData.setDateTo(new TimeTool(TimeTool.END_OF_UNIX_EPOCH)); expData.setCheckDate(false); } close(); } catch (Exception e) { MessageDialog md = new MessageDialog(parent, Messages.ExportDialog_ExceptionDialog, null, e.getMessage(), MessageDialog.WARNING, new String[] { "Ok" //$NON-NLS-1$ }, 0); md.open(); } }
From source file:com.htmlhifive.tools.wizard.download.DownloadModule.java
License:Apache License
/** * 1????.//from w ww .j a v a 2s . c o m * * @param monitor * @param totalWork * @param iFile * @param fileContentsHandler ? * @throws IOException IO * @return ? */ private boolean updateFile(IProgressMonitor monitor, int totalWork, ResultStatus logger, IFile iFile, IFileContentsHandler fileContentsHandler) throws IOException { // PI0112=INFO,[{0}]... monitor.subTask(Messages.PI0112.format(iFile.getFullPath())); int ret = 0; InputStream is = null; try { if (iFile.exists()) { // ????. if (defaultOverwriteMode != 0) { ret = defaultOverwriteMode; } else { MessageDialog dialog = new MessageDialog(null, Messages.SE0113.format(), Dialog.getImage(Dialog.DLG_IMG_MESSAGE_INFO), Messages.SE0114.format(iFile.getRawLocation().toString()), MessageDialog.QUESTION, new String[] { UIMessages.Dialog_OVERWRITE, UIMessages.Dialog_ALL_OVERWRITE, UIMessages.Dialog_IGNORE, UIMessages.Dialog_ALL_IGNORE }, 0); ret = dialog.open(); } switch (ret) { case 1: defaultOverwriteMode = ret; case 0: // ???. logger.log(Messages.SE0097, iFile.getFullPath()); is = fileContentsHandler.getInputStream(); iFile.setContents(is, true, true, null); logger.log(Messages.SE0098, iFile.getFullPath()); break; case 3: defaultOverwriteMode = ret; case 2: // ?. break; } } else { if (!iFile.getParent().exists()) { // ??. H5IOUtils.createParentFolder(iFile.getParent(), null); } is = fileContentsHandler.getInputStream(); logger.log(Messages.SE0091, iFile.getFullPath()); iFile.create(is, true, null); logger.log(Messages.SE0092, iFile.getFullPath()); } return true; } catch (CoreException e) { // SE0024=ERROR,({0})??????? logger.log(e, Messages.SE0024, iFile.getFullPath().toString()); } finally { IOUtils.closeQuietly(is); } return false; }
From source file:com.htmlhifive.tools.wizard.download.DownloadModule.java
License:Apache License
/** * 1???./* w w w.j a va2 s.c o m*/ * * @param monitor * @param totalWork * @param file * @param uri URI * @throws CoreException */ private ZipFile download(final IProgressMonitor monitor, final int totalWork, ResultStatus logger, IFile file, final String urlStr) throws CoreException { // PI0111=INFO,[{0}]... monitor.subTask(Messages.PI0111.format(urlStr)); lastDownloadStatus = false; int ret = 0; while (ret == 0) { try { if (file != null) { // ??. IConnectMethod method = ConnectMethodFactory.getMethod(urlStr, true); method.setConnectionTimeout(PluginConstant.URL_LIBRARY_CONNECTION_TIMEOUT); method.setProxy(getProxyService()); method.getInputStream(); boolean updateResult = updateFile(monitor, 0, logger, file, method); if (updateResult) { lastDownloadStatus = true; } monitor.worked(totalWork); } else { // file?null?????ZipFile???. BufferedInputStream bufferIs = null; OutputStream os = null; try { IConnectMethod method = ConnectMethodFactory.getMethod(urlStr, true); method.setConnectionTimeout(PluginConstant.URL_LIBRARY_CONNECTION_TIMEOUT); method.setProxy(getProxyService()); if (!method.connect()) { // SE0101=ERROR,({0})??????URL={1}, File={2} logger.log(Messages.SE0101, urlStr, file != null ? file.toString() : ""); return null; } final int contentLength = method.getContentLength(); // final int perWork; // if (contentLength > 0) { // perWork = Math.max(1, totalWork * DEFAULT_BUFFER_SIZE / 8 / contentLength); // }else{ // perWork = totalWork; // } InputStream is = method.getInputStream(); // if (H5IOUtils.isClassResources(urlStr)) { // // url?null??????. // is = DownloadModule.class.getResourceAsStream(urlStr); // } else { // // ?URL // HttpMethod method = DownloadModule.this.connect(urlStr, // PluginResource.URL_LIBRARY_CONNECTION_TIMEOUT); // if (method == null) { // return null; // } // // // ??????. // Header header = method.getResponseHeader("Content-Length"); // if (header != null) { // contentLength = Integer.valueOf(header.getValue()); // } // if (contentLength > 0) { // perWork = Math.max(1, perWork * DEFAULT_BUFFER_SIZE / contentLength); // } // is = method.getResponseBodyAsStream(); // } if (is == null) { // SE0101=ERROR,({0})??????URL={1}, File={2} logger.log(Messages.SE0101, urlStr, file != null ? file.toString() : ""); return null; } bufferIs = new BufferedInputStream(is) { private int current = 0; private final int perWork = Math.max(1, totalWork * buf.length / 8 / contentLength); @Override public synchronized int read() throws IOException { int result = super.read(); current += result * 16; monitor.subTask(Messages.PI0143.format(current, contentLength, urlStr)); //monitor.worked(result * 16); monitor.worked(perWork); return result; } }; // SE0093=INFO,{0}??? logger.log(Messages.SE0093, urlStr); // ZIP. File tempFile = File.createTempFile(H5WizardPlugin.getId(), "tmp"); // VM????. tempFile.deleteOnExit(); // ??. os = FileUtils.openOutputStream(tempFile); IOUtils.copy(bufferIs, os); // byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; // int n = 0; // while (-1 != (n = is.read(buffer))) { // os.write(buffer, 0, n); // if (contentLength > 0) { // monitor.worked(perWork); // } // } if (contentLength == 0) { monitor.worked(totalWork); } // SE0094=INFO,{0}???? logger.log(Messages.SE0094, urlStr); lastDownloadStatus = true; return new ZipFile(tempFile); } finally { IOUtils.closeQuietly(bufferIs); IOUtils.closeQuietly(os); } } ret = 1; } catch (IOException e) { // SE0101=ERROR,({0})??????URL={1}, File={2} logger.log(e, Messages.SE0101, urlStr, file != null ? file.toString() : ""); // ?????. MessageDialog dialog = new MessageDialog(null, Messages.SE0115.format(), Dialog.getImage(Dialog.DLG_IMG_MESSAGE_WARNING), Messages.SE0116.format(urlStr), MessageDialog.QUESTION, new String[] { UIMessages.Dialog_RETRY, UIMessages.Dialog_IGNORE, UIMessages.Dialog_STOP }, 0); ret = dialog.open(); if (ret == 2) { // throw new OperationCanceledException( Messages.SE0101.format(urlStr, file != null ? file.toString() : "")); } } } return null; }
From source file:com.iauto.mist.spec.m2t.uml2html.launch.UML2HtmlDynamicSpecificationLaunch.java
License:Open Source License
private void giveErrorMessage(List<StateMachine> stateMachines) { // ??// w w w . j av a 2 s . com StringBuffer opendFilesb = new StringBuffer(); FileOutputStream out = null; for (StateMachine sm : stateMachines) { try { File filePath = new File(XlsRender2.write_path); if (!filePath.exists()) { filePath.mkdirs(); } String fileName = XlsRender2.write_path + File.separator + sm.getName() + Define.FILE_SUFFIX_XLS; File file = new File(fileName); if (file.exists()) { out = new FileOutputStream(fileName); } } catch (FileNotFoundException e) { // ??? opendFilesb.append(sm.getName()); opendFilesb.append("\r\n"); } finally { if (out != null) { try { out.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } } } // ??? String dialogMessageFixed = "The excel file corresponding to the following model(s) is opening now, please close it(them) and click \"Retry\"."; if ("".equals(opendFilesb.toString())) { retryFlg = false; return; } final String dialogMessage = dialogMessageFixed + "\r\n\r\n" + opendFilesb.toString(); // ?? Display.getDefault().syncExec(new Runnable() { @Override public void run() { MessageDialog dialog = new MessageDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error", null, dialogMessage, MessageDialog.ERROR, new String[] { IDialogConstants.RETRY_LABEL }, 0); dialog.open(); if (dialog.getReturnCode() == Window.OK) { retryFlg = true; } } }); }