List of usage examples for org.eclipse.jface.dialogs MessageDialog openInformation
public static void openInformation(Shell parent, String title, String message)
From source file:com.android.ddmuilib.screenrecord.ScreenRecorderAction.java
License:Apache License
public void performAction() { ScreenRecorderOptionsDialog optionsDialog = new ScreenRecorderOptionsDialog(mParentShell); if (optionsDialog.open() == Window.CANCEL) { return;/*from w w w.j a va 2s . co m*/ } final ScreenRecorderOptions options = new ScreenRecorderOptions.Builder() .setBitRate(optionsDialog.getBitRate()).setSize(optionsDialog.getWidth(), optionsDialog.getHeight()) .build(); final CountDownLatch latch = new CountDownLatch(1); final CollectingOutputReceiver receiver = new CollectingOutputReceiver(latch); new Thread(new Runnable() { @Override public void run() { try { mDevice.startScreenRecorder(REMOTE_PATH, options, receiver); } catch (Exception e) { showError("Unexpected error while launching screenrecorder", e); latch.countDown(); } } }, "Screen Recorder").start(); try { new ProgressMonitorDialog(mParentShell).run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { int timeInSecond = 0; monitor.beginTask("Recording...", IProgressMonitor.UNKNOWN); while (true) { // Wait for a second to see if the command has completed if (latch.await(1, TimeUnit.SECONDS)) { break; } // update recording time in second monitor.subTask(String.format("Recording...%d seconds elapsed", timeInSecond++)); // If not, check if user has cancelled if (monitor.isCanceled()) { receiver.cancel(); monitor.subTask("Stopping..."); // wait for an additional second to make sure that the command // completed and screenrecorder finishes writing the output latch.await(1, TimeUnit.SECONDS); break; } } } }); } catch (InvocationTargetException e) { showError("Unexpected error while recording: ", e.getTargetException()); return; } catch (InterruptedException ignored) { } try { mDevice.pullFile(REMOTE_PATH, optionsDialog.getDestination().getAbsolutePath()); } catch (Exception e) { showError("Unexpected error while copying video recording from device", e); } MessageDialog.openInformation(mParentShell, TITLE, "Screen recording saved at " + optionsDialog.getDestination().getAbsolutePath()); }
From source file:com.android.ddmuilib.SysinfoPanel.java
License:Apache License
/** * Fetches a new bugreport from the device and updates the display. * Fetching is asynchronous. See also addOutput, flush, and isCancelled. *//*from www .j ava 2s . com*/ private void loadFromDevice() { clearDataSet(); if (mMode == MODE_GFXINFO) { boolean en = isGfxProfilingEnabled(); if (!en) { if (enableGfxProfiling()) { MessageDialog.openInformation(Display.getCurrent().getActiveShell(), "DDMS", "Graphics profiling was enabled on the device.\n" + "It may be necessary to relaunch your application to see profile information."); } else { MessageDialog.openError(Display.getCurrent().getActiveShell(), "DDMS", "Unexpected error enabling graphics profiling on device.\n"); return; } } } final String command = getDumpsysCommand(mMode); if (command == null) { return; } Thread t = new Thread(new Runnable() { @Override public void run() { try { String header = null; if (mMode == MODE_MEMINFO) { // Hack to add bugreport-style section header for meminfo header = "------ MEMORY INFO ------\n"; } IShellOutputReceiver receiver = initShellOutputBuffer(header); getCurrentDevice().executeShellCommand(command, receiver); } catch (IOException e) { Log.e("DDMS", e); } catch (TimeoutException e) { Log.e("DDMS", e); } catch (AdbCommandRejectedException e) { Log.e("DDMS", e); } catch (ShellCommandUnresponsiveException e) { Log.e("DDMS", e); } } }, "Sysinfo Output Collector"); t.start(); }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.gre.ClientRulesEngine.java
License:Open Source License
@Override public void displayAlert(@NonNull String message) { MessageDialog.openInformation(AdtPlugin.getShell(), mFqcn, // title message); }
From source file:com.android.ide.eclipse.adt.internal.refactorings.core.RenameResourceXmlTextAction.java
License:Open Source License
@Override public void run() { if (!validateEditorInputState()) { return;//from w ww .ja v a 2s . c o m } IFile file = getFile(); if (file == null) { return; } IProject project = file.getProject(); if (project == null) { return; } IDocument document = getDocument(); if (document == null) { return; } ITextSelection selection = getSelection(); if (selection == null) { return; } ResourceUrl resource = findResource(document, selection.getOffset()); if (resource == null) { resource = findItemDefinition(document, selection.getOffset()); } if (resource != null) { ResourceType type = resource.type; String name = resource.name; Shell shell = mEditor.getSite().getShell(); boolean canClear = false; RenameResourceWizard.renameResource(shell, project, type, name, null, canClear); return; } String className = findClassName(document, file, selection.getOffset()); if (className != null) { assert className.equals(className.trim()); IType type = findType(className, project); if (type != null) { RenameTypeProcessor processor = new RenameTypeProcessor(type); //processor.setNewElementName(className); processor.setUpdateQualifiedNames(true); processor.setUpdateSimilarDeclarations(false); //processor.setMatchStrategy(?); //processor.setFilePatterns(patterns); processor.setUpdateReferences(true); RenameRefactoring refactoring = new RenameRefactoring(processor); RenameTypeWizard wizard = new RenameTypeWizard(refactoring); RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard); try { IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); op.run(window.getShell(), wizard.getDefaultPageTitle()); } catch (InterruptedException e) { } } return; } // Fallback: tell user the cursor isn't in the right place MessageDialog.openInformation(mEditor.getSite().getShell(), "Rename", "Operation unavailable on the current selection.\n" + "Select an Android resource name or class."); }
From source file:com.android.ide.eclipse.apt.internal.handlers.AptHandler.java
License:Apache License
/** * the command has been executed, so extract the needed information * from the application context./*w ww. j a v a2s. c om*/ */ public Object execute(final ExecutionEvent event) throws ExecutionException { final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); final IWorkbenchPage page = window.getActivePage(); if (page != null) { final ISelection selection = page.getSelection(); final IResource resource = extractSelection(selection); if (resource != null) { final IProject project = resource.getProject(); try { if (!project.isOpen()) { project.open(null); } if (project.hasNature(AptPlugin.ANDROID_NATURE)) { final IFolder bin = project.getFolder(AptPlugin.CLASS_FOLDER); if (bin.exists()) { final String projectPath = project.getLocation().toOSString(); final Collection<ClassNode> classes = ClassCrawler .scanAndroidProject(projectPath + "/" + AptPlugin.CLASS_FOLDER); Analyzer.analyseProject(project, classes); } else { MessageDialog.openInformation(window.getShell(), "Apt", "The bin folder cannot be found in the " + "Android project: " + project.getName()); } } else { MessageDialog.openInformation(window.getShell(), "Apt", "The project " + project.getName() + " is not an Android project"); } } catch (final CoreException e) { MessageDialog.openInformation(window.getShell(), "Apt", "An eclipse core error occured during the anlysis of the " + "Android project: " + project.getName()); e.printStackTrace(); return null; } catch (final FileNotFoundException e) { MessageDialog.openInformation(window.getShell(), "Apt", "The bin folder cannot be found in the " + "Android project: " + project.getName()); e.printStackTrace(); return null; } catch (final IOException e) { MessageDialog.openInformation(window.getShell(), "Apt", "An IO error occured during the anlysis of the " + "Android project: " + project.getName()); e.printStackTrace(); return null; } } } return null; }
From source file:com.android.ide.eclipse.auidt.internal.editors.layout.gre.ClientRulesEngine.java
License:Open Source License
@Override public void displayAlert(@NonNull String message) { MessageDialog.openInformation(AdtPlugin.getDisplay().getActiveShell(), mFqcn, // title message); }
From source file:com.android.ide.eclipse.cheatsheets.actions.ImportProject.java
License:Open Source License
private void importProject(final String projectURL, final String[] params, final ICheatSheetManager manager) { final String projectName = params[1]; WorkspaceJob workspaceJob = new WorkspaceJob("Importing projects ...") { @Override//from w ww. j a v a 2s . c o m public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProject project = workspace.getRoot().getProject(projectName); if (project.exists()) { Display.getDefault().syncExec(new Runnable() { public void run() { overwrite = MessageDialog.openQuestion(getShell(), "Question", "Overwrite project " + projectName); } }); if (!overwrite) { return Status.CANCEL_STATUS; } project.delete(true, true, monitor); } InputStream in = null; OutputStream out = null; File file = null; try { URL url = new URL(projectURL); URL entry = FileLocator.resolve(url); file = File.createTempFile("HelloWorld", ".zip"); //$NON-NLS-1$//$NON-NLS-2$ file.deleteOnExit(); in = entry.openStream(); out = new FileOutputStream(file); copy(in, out); } catch (MalformedURLException e) { Activator.log(e); return Status.CANCEL_STATUS; } catch (IOException e) { Activator.log(e); return Status.CANCEL_STATUS; } finally { if (in != null) { try { in.close(); } catch (IOException e) { // ignore } } if (out != null) { try { out.close(); } catch (IOException e) { // ignore } } } project.create(monitor); project.open(monitor); ZipFile sourceFile; try { sourceFile = new ZipFile(file); } catch (IOException e) { Activator.log(e); return Status.CANCEL_STATUS; } ZipFileStructureProvider structureProvider = new ZipFileStructureProvider(sourceFile); Enumeration<? extends ZipEntry> entries = sourceFile.entries(); ZipEntry entry = null; List<ZipEntry> filesToImport = new ArrayList<ZipEntry>(); String prefix = projectName + "/"; //$NON-NLS-1$ while (entries.hasMoreElements()) { entry = entries.nextElement(); if (entry.getName().startsWith(prefix)) { filesToImport.add(entry); } } ImportOperation operation = new ImportOperation(workspace.getRoot().getFullPath(), structureProvider.getRoot(), structureProvider, OVERWRITE_ALL_QUERY, filesToImport); operation.setContext(getShell()); try { operation.run(new NullProgressMonitor()); } catch (InvocationTargetException e) { Activator.log(e); return Status.CANCEL_STATUS; } catch (InterruptedException e) { Activator.log(e); return Status.CANCEL_STATUS; } finally { file.delete(); } return Status.OK_STATUS; } }; workspaceJob.setUser(true); workspaceJob.addJobChangeListener(new IJobChangeListener() { public void aboutToRun(IJobChangeEvent event) { } public void awake(IJobChangeEvent event) { } public void done(IJobChangeEvent event) { try { Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, new NullProgressMonitor()); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProject project = workspace.getRoot().getProject(projectName); Sdk currentSdk = Sdk.getCurrent(); if (currentSdk != null && project.isOpen()) { IJavaProject javaProject = JavaCore.create(project); ProjectState state = Sdk.getProjectState(project); IAndroidTarget projectTarget = state.getTarget(); if (projectTarget == null) { IAndroidTarget[] targets = Sdk.getCurrent().getTargets(); if (targets != null && targets.length > 0) { IAndroidTarget newTarget = targets[0]; ProjectPropertiesWorkingCopy mPropertiesWorkingCopy = state.getProperties() .makeWorkingCopy(); mPropertiesWorkingCopy.setProperty(ProjectProperties.PROPERTY_TARGET, newTarget.hashString()); try { mPropertiesWorkingCopy.save(); IResource defaultProp = project.findMember(SdkConstants.FN_DEFAULT_PROPERTIES); defaultProp.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor()); ProjectHelper.fixProject(project); } catch (Exception e) { String msg = String.format("Failed to save %1$s for project %2$s", SdkConstants.FN_DEFAULT_PROPERTIES, project.getName()); AdtPlugin.log(e, msg); } } else { Display.getDefault().syncExec(new Runnable() { public void run() { MessageDialog.openInformation(getShell(), "Hello World target", "'Hello world' cheatsheet requires " + "an Android target. You can download " + "them using the 'Open SDK and AVD Manager'" + " action."); } }); } } } Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, new NullProgressMonitor()); if (params[2] != null) { new OpenFile().run(new String[] { params[1], "src", params[2] }, manager); } } catch (OperationCanceledException e) { Activator.log(e); } catch (InterruptedException e) { Activator.log(e); } } public void running(IJobChangeEvent event) { } public void scheduled(IJobChangeEvent event) { } public void sleeping(IJobChangeEvent event) { } }); workspaceJob.schedule(); }
From source file:com.android.ide.eclipse.common.project.ExportHelper.java
License:Open Source License
/** * Exports an <b>unsigned</b> version of the application created by the given project. * @param project the project to export//from w w w .java2s . co m */ public static void exportProject(IProject project) { Shell shell = Display.getCurrent().getActiveShell(); // get the java project to get the output directory IFolder outputFolder = BaseProjectHelper.getOutputFolder(project); if (outputFolder != null) { IPath binLocation = outputFolder.getLocation(); // make the full path to the package String fileName = project.getName() + AndroidConstants.DOT_ANDROID_PACKAGE; File file = new File(binLocation.toOSString() + File.separator + fileName); if (file.exists() == false || file.isFile() == false) { MessageDialog.openInformation(Display.getCurrent().getActiveShell(), "Android IDE Plug-in", String .format("Failed to export %1$s: %2$s doesn't exist!", project.getName(), file.getPath())); return; } // ok now pop up the file save window FileDialog fileDialog = new FileDialog(shell, SWT.SAVE); fileDialog.setText("Export Project"); fileDialog.setFileName(fileName); String saveLocation = fileDialog.open(); if (saveLocation != null) { // get the stream from the original file ZipInputStream zis = null; ZipOutputStream zos = null; FileInputStream input = null; FileOutputStream output = null; try { input = new FileInputStream(file); zis = new ZipInputStream(input); // get an output stream into the new file File saveFile = new File(saveLocation); output = new FileOutputStream(saveFile); zos = new ZipOutputStream(output); } catch (FileNotFoundException e) { // only the input/output stream are throwing this exception. // so we only have to close zis if output is the one that threw. if (zis != null) { try { zis.close(); } catch (IOException e1) { // pass } } MessageDialog.openInformation(shell, "Android IDE Plug-in", String.format( "Failed to export %1$s: %2$s doesn't exist!", project.getName(), file.getPath())); return; } try { ZipEntry entry; byte[] buffer = new byte[4096]; while ((entry = zis.getNextEntry()) != null) { String name = entry.getName(); // do not take directories or anything inside the META-INF folder since // we want to strip the signature. if (entry.isDirectory() || name.startsWith("META-INF/")) { //$NON-NL1$ continue; } ZipEntry newEntry; // Preserve the STORED method of the input entry. if (entry.getMethod() == JarEntry.STORED) { newEntry = new JarEntry(entry); } else { // Create a new entry so that the compressed len is recomputed. newEntry = new JarEntry(name); } // add the entry to the jar archive zos.putNextEntry(newEntry); // read the content of the entry from the input stream, and write it into the archive. int count; while ((count = zis.read(buffer)) != -1) { zos.write(buffer, 0, count); } // close the entry for this file zos.closeEntry(); zis.closeEntry(); } } catch (IOException e) { MessageDialog.openInformation(shell, "Android IDE Plug-in", String.format("Failed to export %1$s: %2$s", project.getName(), e.getMessage())); } finally { try { zos.close(); } catch (IOException e) { // pass } try { zis.close(); } catch (IOException e) { // pass } } } } else { MessageDialog.openInformation(shell, "Android IDE Plug-in", String .format("Failed to export %1$s: Could not get project output location", project.getName())); } }
From source file:com.android.sdkuilib.internal.repository.SettingsController.java
License:Apache License
/** * Saves settings to the settings file.//from w w w . j a va 2s .co m */ public void saveSettings() { FileOutputStream fos = null; String path = null; try { String folder = AndroidLocation.getFolder(); File f = new File(folder, SETTINGS_FILENAME); path = f.getPath(); fos = new FileOutputStream(f); mProperties.store(fos, "## Settings for Android Tool"); //$NON-NLS-1$ } catch (Exception e) { ISdkLog log = mUpdaterData.getSdkLog(); if (log != null) { log.error(e, "Failed to save settings at '%1$s'", path); } // This is important enough that we want to really nag the user about it String reason = null; if (e instanceof FileNotFoundException) { reason = "File not found"; } else if (e instanceof AndroidLocationException) { reason = ".android folder not found, please define ANDROID_SDK_HOME"; } else if (e.getMessage() != null) { reason = String.format("%1$s: %2$s", e.getClass().getSimpleName(), e.getMessage()); } else { reason = e.getClass().getName(); } MessageDialog.openInformation(mUpdaterData.getWindowShell(), "SDK Manager Settings", String.format( "The Android SDK and AVD Manager failed to save its settings (%1$s) at %2$s", reason, path)); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { } } } }
From source file:com.android.sdkuilib.internal.repository.SwtUpdaterData.java
License:Apache License
@Override protected void notifyToolsNeedsToBeRestarted(int flags) { String msg = null;/*from w w w . j av a 2 s . co m*/ if ((flags & TOOLS_MSG_UPDATED_FROM_ADT) != 0) { msg = "The Android SDK and AVD Manager that you are currently using has been updated. " + "Please also run Eclipse > Help > Check for Updates to see if the Android " + "plug-in needs to be updated."; } else if ((flags & TOOLS_MSG_UPDATED_FROM_SDKMAN) != 0) { msg = "The Android SDK and AVD Manager that you are currently using has been updated. " + "It is recommended that you now close the manager window and re-open it. " + "If you use Eclipse, please run Help > Check for Updates to see if the Android " + "plug-in needs to be updated."; } final String msg2 = msg; final Shell shell = getWindowShell(); if (msg2 != null && shell != null && !shell.isDisposed()) { shell.getDisplay().syncExec(new Runnable() { @Override public void run() { if (!shell.isDisposed()) { MessageDialog.openInformation(shell, "Android Tools Updated", msg2); } } }); } }