List of usage examples for org.eclipse.jface.dialogs ProgressMonitorDialog ProgressMonitorDialog
public ProgressMonitorDialog(Shell parent)
From source file:com.android.glesv2debugger.CodeGen.java
License:Apache License
void codeGenFrames(final DebugContext dbgCtx, int count, final Shell shell) { this.dbgCtx = dbgCtx; this.count = count; ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell); this.progress = dialog.getProgressMonitor(); try {//from w w w.j a v a 2 s . c o m dialog.run(false, true, this); } catch (InvocationTargetException e) { e.printStackTrace(); assert false; } catch (InterruptedException e) { e.printStackTrace(); } this.dbgCtx = null; this.count = 0; progress = null; }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.gre.ClientRulesEngine.java
License:Open Source License
@Override public String displayFragmentSourceInput() { try {//from w w w . ja v a2s . c o m // Compute a search scope: We need to merge all the subclasses // android.app.Fragment and android.support.v4.app.Fragment IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); IProject project = mRulesEngine.getProject(); final IJavaProject javaProject = BaseProjectHelper.getJavaProject(project); if (javaProject != null) { IType oldFragmentType = javaProject.findType(CLASS_V4_FRAGMENT); // First check to make sure fragments are available, and if not, // warn the user. IAndroidTarget target = Sdk.getCurrent().getTarget(project); // No, this should be using the min SDK instead! if (target.getVersion().getApiLevel() < 11 && oldFragmentType == null) { // Compatibility library must be present MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(), "Fragment Warning", null, "Fragments require API level 11 or higher, or a compatibility " + "library for older versions.\n\n" + " Do you want to install the compatibility library?", MessageDialog.QUESTION, new String[] { "Install", "Cancel" }, 1 /* default button: Cancel */); int answer = dialog.open(); if (answer == 0) { if (!AddSupportJarAction.install(project)) { return null; } } else { return null; } } // Look up sub-types of each (new fragment class and compatibility fragment // class, if any) and merge the two arrays - then create a scope from these // elements. IType[] fragmentTypes = new IType[0]; IType[] oldFragmentTypes = new IType[0]; if (oldFragmentType != null) { ITypeHierarchy hierarchy = oldFragmentType.newTypeHierarchy(new NullProgressMonitor()); oldFragmentTypes = hierarchy.getAllSubtypes(oldFragmentType); } IType fragmentType = javaProject.findType(CLASS_FRAGMENT); if (fragmentType != null) { ITypeHierarchy hierarchy = fragmentType.newTypeHierarchy(new NullProgressMonitor()); fragmentTypes = hierarchy.getAllSubtypes(fragmentType); } IType[] subTypes = new IType[fragmentTypes.length + oldFragmentTypes.length]; System.arraycopy(fragmentTypes, 0, subTypes, 0, fragmentTypes.length); System.arraycopy(oldFragmentTypes, 0, subTypes, fragmentTypes.length, oldFragmentTypes.length); scope = SearchEngine.createJavaSearchScope(subTypes, IJavaSearchScope.SOURCES); } Shell parent = AdtPlugin.getShell(); final AtomicReference<String> returnValue = new AtomicReference<String>(); final AtomicReference<SelectionDialog> dialogHolder = new AtomicReference<SelectionDialog>(); final SelectionDialog dialog = JavaUI.createTypeDialog(parent, new ProgressMonitorDialog(parent), scope, IJavaElementSearchConstants.CONSIDER_CLASSES, false, // Use ? as a default filter to fill dialog with matches "?", //$NON-NLS-1$ new TypeSelectionExtension() { @Override public Control createContentArea(Composite parentComposite) { Composite composite = new Composite(parentComposite, SWT.NONE); composite.setLayout(new GridLayout(1, false)); Button button = new Button(composite, SWT.PUSH); button.setText("Create New..."); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String fqcn = createNewFragmentClass(javaProject); if (fqcn != null) { returnValue.set(fqcn); dialogHolder.get().close(); } } }); return composite; } @Override public ITypeInfoFilterExtension getFilterExtension() { return new ITypeInfoFilterExtension() { @Override public boolean select(ITypeInfoRequestor typeInfoRequestor) { int modifiers = typeInfoRequestor.getModifiers(); if (!Flags.isPublic(modifiers) || Flags.isInterface(modifiers) || Flags.isEnum(modifiers) || Flags.isAbstract(modifiers)) { return false; } return true; } }; } }); dialogHolder.set(dialog); dialog.setTitle("Choose Fragment Class"); dialog.setMessage("Select a Fragment class (? = any character, * = any string):"); if (dialog.open() == IDialogConstants.CANCEL_ID) { return null; } if (returnValue.get() != null) { return returnValue.get(); } Object[] types = dialog.getResult(); if (types != null && types.length > 0) { return ((IType) types[0]).getFullyQualifiedName(); } } catch (JavaModelException e) { AdtPlugin.log(e, null); } catch (CoreException e) { AdtPlugin.log(e, null); } return null; }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.gre.ClientRulesEngine.java
License:Open Source License
@Override public String displayCustomViewClassInput() { try {//from w w w . ja v a2 s. co m IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); IProject project = mRulesEngine.getProject(); final IJavaProject javaProject = BaseProjectHelper.getJavaProject(project); if (javaProject != null) { // Look up sub-types of each (new fragment class and compatibility fragment // class, if any) and merge the two arrays - then create a scope from these // elements. IType[] viewTypes = new IType[0]; IType fragmentType = javaProject.findType(CLASS_VIEW); if (fragmentType != null) { ITypeHierarchy hierarchy = fragmentType.newTypeHierarchy(new NullProgressMonitor()); viewTypes = hierarchy.getAllSubtypes(fragmentType); } scope = SearchEngine.createJavaSearchScope(viewTypes, IJavaSearchScope.SOURCES); } Shell parent = AdtPlugin.getShell(); final AtomicReference<String> returnValue = new AtomicReference<String>(); final AtomicReference<SelectionDialog> dialogHolder = new AtomicReference<SelectionDialog>(); final SelectionDialog dialog = JavaUI.createTypeDialog(parent, new ProgressMonitorDialog(parent), scope, IJavaElementSearchConstants.CONSIDER_CLASSES, false, // Use ? as a default filter to fill dialog with matches "?", //$NON-NLS-1$ new TypeSelectionExtension() { @Override public Control createContentArea(Composite parentComposite) { Composite composite = new Composite(parentComposite, SWT.NONE); composite.setLayout(new GridLayout(1, false)); Button button = new Button(composite, SWT.PUSH); button.setText("Create New..."); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String fqcn = createNewCustomViewClass(javaProject); if (fqcn != null) { returnValue.set(fqcn); dialogHolder.get().close(); } } }); return composite; } @Override public ITypeInfoFilterExtension getFilterExtension() { return new ITypeInfoFilterExtension() { @Override public boolean select(ITypeInfoRequestor typeInfoRequestor) { int modifiers = typeInfoRequestor.getModifiers(); if (!Flags.isPublic(modifiers) || Flags.isInterface(modifiers) || Flags.isEnum(modifiers) || Flags.isAbstract(modifiers)) { return false; } return true; } }; } }); dialogHolder.set(dialog); dialog.setTitle("Choose Custom View Class"); dialog.setMessage("Select a Custom View class (? = any character, * = any string):"); if (dialog.open() == IDialogConstants.CANCEL_ID) { return null; } if (returnValue.get() != null) { return returnValue.get(); } Object[] types = dialog.getResult(); if (types != null && types.length > 0) { return ((IType) types[0]).getFullyQualifiedName(); } } catch (JavaModelException e) { AdtPlugin.log(e, null); } catch (CoreException e) { AdtPlugin.log(e, null); } return null; }
From source file:com.android.ide.eclipse.adt.internal.wizards.templates.NewTemplatePage.java
License:Open Source License
private String chooseActivity() { try {//from ww w.j a v a 2s.c om // Compute a search scope: We need to merge all the subclasses // android.app.Fragment and android.support.v4.app.Fragment IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); IProject project = mValues.project; IJavaProject javaProject = BaseProjectHelper.getJavaProject(project); IType activityType = null; if (javaProject != null) { activityType = javaProject.findType(CLASS_ACTIVITY); } if (activityType == null) { IJavaProject[] projects = BaseProjectHelper.getAndroidProjects(null); for (IJavaProject p : projects) { activityType = p.findType(CLASS_ACTIVITY); if (activityType != null) { break; } } } if (activityType != null) { NullProgressMonitor monitor = new NullProgressMonitor(); ITypeHierarchy hierarchy = activityType.newTypeHierarchy(monitor); IType[] classes = hierarchy.getAllSubtypes(activityType); scope = SearchEngine.createJavaSearchScope(classes, IJavaSearchScope.SOURCES); } Shell parent = AdtPlugin.getShell(); final SelectionDialog dialog = JavaUI.createTypeDialog(parent, new ProgressMonitorDialog(parent), scope, IJavaElementSearchConstants.CONSIDER_CLASSES, false, // Use ? as a default filter to fill dialog with matches "?", //$NON-NLS-1$ new TypeSelectionExtension() { @Override public ITypeInfoFilterExtension getFilterExtension() { return new ITypeInfoFilterExtension() { @Override public boolean select(ITypeInfoRequestor typeInfoRequestor) { int modifiers = typeInfoRequestor.getModifiers(); if (!Flags.isPublic(modifiers) || Flags.isInterface(modifiers) || Flags.isEnum(modifiers)) { return false; } return true; } }; } }); dialog.setTitle("Choose Activity Class"); dialog.setMessage("Select an Activity class (? = any character, * = any string):"); if (dialog.open() == IDialogConstants.CANCEL_ID) { return null; } Object[] types = dialog.getResult(); if (types != null && types.length > 0) { return ((IType) types[0]).getFullyQualifiedName(); } } catch (JavaModelException e) { AdtPlugin.log(e, null); } catch (CoreException e) { AdtPlugin.log(e, null); } return null; }
From source file:com.android.ide.eclipse.auidt.internal.editors.layout.gre.ClientRulesEngine.java
License:Open Source License
@Override public String displayFragmentSourceInput() { try {//from w w w .j ava2 s.co m // Compute a search scope: We need to merge all the subclasses // android.app.Fragment and android.support.v4.app.Fragment IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); IProject project = mRulesEngine.getProject(); final IJavaProject javaProject = BaseProjectHelper.getJavaProject(project); if (javaProject != null) { IType oldFragmentType = javaProject.findType(CLASS_V4_FRAGMENT); // First check to make sure fragments are available, and if not, // warn the user. IAndroidTarget target = Sdk.getCurrent().getTarget(project); // No, this should be using the min SDK instead! if (target.getVersion().getApiLevel() < 11 && oldFragmentType == null) { // Compatibility library must be present MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(), "Fragment Warning", null, "Fragments require API level 11 or higher, or a compatibility " + "library for older versions.\n\n" + " Do you want to install the compatibility library?", MessageDialog.QUESTION, new String[] { "Install", "Cancel" }, 1 /* default button: Cancel */); int answer = dialog.open(); if (answer == 0) { if (!AddSupportJarAction.install(project)) { return null; } } else { return null; } } // Look up sub-types of each (new fragment class and compatibility fragment // class, if any) and merge the two arrays - then create a scope from these // elements. IType[] fragmentTypes = new IType[0]; IType[] oldFragmentTypes = new IType[0]; if (oldFragmentType != null) { ITypeHierarchy hierarchy = oldFragmentType.newTypeHierarchy(new NullProgressMonitor()); oldFragmentTypes = hierarchy.getAllSubtypes(oldFragmentType); } IType fragmentType = javaProject.findType(CLASS_FRAGMENT); if (fragmentType != null) { ITypeHierarchy hierarchy = fragmentType.newTypeHierarchy(new NullProgressMonitor()); fragmentTypes = hierarchy.getAllSubtypes(fragmentType); } IType[] subTypes = new IType[fragmentTypes.length + oldFragmentTypes.length]; System.arraycopy(fragmentTypes, 0, subTypes, 0, fragmentTypes.length); System.arraycopy(oldFragmentTypes, 0, subTypes, fragmentTypes.length, oldFragmentTypes.length); scope = SearchEngine.createJavaSearchScope(subTypes, IJavaSearchScope.SOURCES); } Shell parent = AdtPlugin.getDisplay().getActiveShell(); final AtomicReference<String> returnValue = new AtomicReference<String>(); final AtomicReference<SelectionDialog> dialogHolder = new AtomicReference<SelectionDialog>(); final SelectionDialog dialog = JavaUI.createTypeDialog(parent, new ProgressMonitorDialog(parent), scope, IJavaElementSearchConstants.CONSIDER_CLASSES, false, // Use ? as a default filter to fill dialog with matches "?", //$NON-NLS-1$ new TypeSelectionExtension() { @Override public Control createContentArea(Composite parentComposite) { Composite composite = new Composite(parentComposite, SWT.NONE); composite.setLayout(new GridLayout(1, false)); Button button = new Button(composite, SWT.PUSH); button.setText("Create New..."); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String fqcn = createNewFragmentClass(javaProject); if (fqcn != null) { returnValue.set(fqcn); dialogHolder.get().close(); } } }); return composite; } @Override public ITypeInfoFilterExtension getFilterExtension() { return new ITypeInfoFilterExtension() { @Override public boolean select(ITypeInfoRequestor typeInfoRequestor) { int modifiers = typeInfoRequestor.getModifiers(); if (!Flags.isPublic(modifiers) || Flags.isInterface(modifiers) || Flags.isEnum(modifiers)) { return false; } return true; } }; } }); dialogHolder.set(dialog); dialog.setTitle("Choose Fragment Class"); dialog.setMessage("Select a Fragment class (? = any character, * = any string):"); if (dialog.open() == IDialogConstants.CANCEL_ID) { return null; } if (returnValue.get() != null) { return returnValue.get(); } Object[] types = dialog.getResult(); if (types != null && types.length > 0) { return ((IType) types[0]).getFullyQualifiedName(); } } catch (JavaModelException e) { AdtPlugin.log(e, null); } catch (CoreException e) { AdtPlugin.log(e, null); } return null; }
From source file:com.android.ide.eclipse.auidt.internal.wizards.templates.NewTemplatePage.java
License:Open Source License
private String chooseActivity() { try {/*from www . j av a 2 s . co m*/ // Compute a search scope: We need to merge all the subclasses // android.app.Fragment and android.support.v4.app.Fragment IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); IProject project = mValues.project; IJavaProject javaProject = BaseProjectHelper.getJavaProject(project); IType activityType = null; if (javaProject != null) { activityType = javaProject.findType(CLASS_ACTIVITY); } if (activityType == null) { IJavaProject[] projects = BaseProjectHelper.getAndroidProjects(null); for (IJavaProject p : projects) { activityType = p.findType(CLASS_ACTIVITY); if (activityType != null) { break; } } } if (activityType != null) { NullProgressMonitor monitor = new NullProgressMonitor(); ITypeHierarchy hierarchy = activityType.newTypeHierarchy(monitor); IType[] classes = hierarchy.getAllSubtypes(activityType); scope = SearchEngine.createJavaSearchScope(classes, IJavaSearchScope.SOURCES); } Shell parent = AdtPlugin.getDisplay().getActiveShell(); final SelectionDialog dialog = JavaUI.createTypeDialog(parent, new ProgressMonitorDialog(parent), scope, IJavaElementSearchConstants.CONSIDER_CLASSES, false, // Use ? as a default filter to fill dialog with matches "?", //$NON-NLS-1$ new TypeSelectionExtension() { @Override public ITypeInfoFilterExtension getFilterExtension() { return new ITypeInfoFilterExtension() { @Override public boolean select(ITypeInfoRequestor typeInfoRequestor) { int modifiers = typeInfoRequestor.getModifiers(); if (!Flags.isPublic(modifiers) || Flags.isInterface(modifiers) || Flags.isEnum(modifiers)) { return false; } return true; } }; } }); dialog.setTitle("Choose Activity Class"); dialog.setMessage("Select an Activity class (? = any character, * = any string):"); if (dialog.open() == IDialogConstants.CANCEL_ID) { return null; } Object[] types = dialog.getResult(); if (types != null && types.length > 0) { return ((IType) types[0]).getFullyQualifiedName(); } } catch (JavaModelException e) { AdtPlugin.log(e, null); } catch (CoreException e) { AdtPlugin.log(e, null); } return null; }
From source file:com.android.ide.eclipse.cheatsheets.actions.LaunchAndroidApplication.java
License:Open Source License
public void run(final String[] params, ICheatSheetManager manager) { if (params == null || params[0] == null) { Activator.log("Invalid parameters"); return;//from w ww .j ava 2s .c o m } String mode = RUN_MODE; if (params[1] != null) { mode = params[1]; } IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); final IProject project = workspaceRoot.getProject(params[0]); if (project == null || !project.isOpen()) { Activator.log("The " + params[0] + " project is invalid"); return; } IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.setTaskName("Checking AVD..."); checkAvd(project); } }; try { new ProgressMonitorDialog(Display.getDefault().getActiveShell()).run(true, false, op); } catch (InvocationTargetException e) { InstallerActivator.log(e); } catch (InterruptedException e) { // ignore } ILaunchConfiguration config = AndroidLaunchController.getLaunchConfig(project); if (config != null) { // and launch! DebugUITools.launch(config, mode); } }
From source file:com.android.ide.eclipse.ddms.views.DeviceView.java
License:Apache License
private void takeUiAutomatorSnapshot(final IDevice device, final Shell shell) { ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell); try {/*from ww w . ja v a 2 s.c o m*/ dialog.run(true, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { UiAutomatorResult result = null; try { result = UiAutomatorHelper.takeSnapshot(device, monitor); } catch (UiAutomatorException e) { throw new InvocationTargetException(e); } finally { monitor.done(); } UiAutomatorViewer.openEditor(result); } }); } catch (Exception e) { Throwable t = e; if (e instanceof InvocationTargetException) { t = ((InvocationTargetException) e).getTargetException(); } Status s = new Status(IStatus.ERROR, DdmsPlugin.PLUGIN_ID, "Error obtaining UI hierarchy", t); ErrorDialog.openError(shell, "UI Automator", "Unexpected error while obtaining UI hierarchy", s); } }
From source file:com.android.ide.eclipse.ddms.views.DeviceView.java
License:Apache License
private void launchSystrace(final IDevice device, final Shell parentShell) { final File systraceAssets = new File(DdmsPlugin.getPlatformToolsFolder(), "systrace"); //$NON-NLS-1$ if (!systraceAssets.isDirectory()) { MessageDialog.openError(parentShell, "Systrace", "Updated version of platform-tools (18.0.1 or greater) is required.\n" + "Please update your platform-tools using SDK Manager."); return;// w w w .ja v a 2s.c om } SystraceVersionDetector detector = new SystraceVersionDetector(device); try { new ProgressMonitorDialog(parentShell).run(true, false, detector); } catch (InvocationTargetException e) { MessageDialog.openError(parentShell, "Systrace", "Unexpected error while detecting atrace version: " + e); return; } catch (InterruptedException e) { return; } final ISystraceOptionsDialog dlg; if (detector.getVersion() == SystraceVersionDetector.SYSTRACE_V1) { dlg = new SystraceOptionsDialogV1(parentShell); } else { Client[] clients = device.getClients(); List<String> apps = new ArrayList<String>(clients.length); for (int i = 0; i < clients.length; i++) { String name = clients[i].getClientData().getClientDescription(); if (name != null && !name.isEmpty()) { apps.add(name); } } dlg = new SystraceOptionsDialogV2(parentShell, detector.getTags(), apps); } if (dlg.open() != SystraceOptionsDialogV1.OK) { return; } final ISystraceOptions options = dlg.getSystraceOptions(); // set trace tag if necessary: // adb shell setprop debug.atrace.tags.enableflags <tag> String tag = options.getTags(); if (tag != null) { CountDownLatch setTagLatch = new CountDownLatch(1); CollectingOutputReceiver receiver = new CollectingOutputReceiver(setTagLatch); try { String cmd = "setprop debug.atrace.tags.enableflags " + tag; device.executeShellCommand(cmd, receiver); setTagLatch.await(5, TimeUnit.SECONDS); } catch (Exception e) { MessageDialog.openError(parentShell, "Systrace", "Unexpected error while setting trace tags: " + e); return; } String shellOutput = receiver.getOutput(); if (shellOutput.contains("Error type")) { //$NON-NLS-1$ throw new RuntimeException(receiver.getOutput()); } } // obtain the output of "adb shell atrace <trace-options>" and generate the html file ProgressMonitorDialog d = new ProgressMonitorDialog(parentShell); try { d.run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { boolean COMPRESS_DATA = true; monitor.setTaskName("Collecting Trace Information"); final String atraceOptions = options.getOptions() + (COMPRESS_DATA ? " -z" : ""); SystraceTask task = new SystraceTask(device, atraceOptions); Thread t = new Thread(task, "Systrace Output Receiver"); t.start(); // check if the user has cancelled tracing every so often while (true) { t.join(1000); if (t.isAlive()) { if (monitor.isCanceled()) { task.cancel(); return; } } else { break; } } if (task.getError() != null) { throw new RuntimeException(task.getError()); } monitor.setTaskName("Saving trace information"); SystraceOutputParser parser = new SystraceOutputParser(COMPRESS_DATA, SystraceOutputParser.getJs(systraceAssets), SystraceOutputParser.getCss(systraceAssets), SystraceOutputParser.getHtmlPrefix(systraceAssets), SystraceOutputParser.getHtmlSuffix(systraceAssets)); parser.parse(task.getAtraceOutput()); String html = parser.getSystraceHtml(); try { Files.write(html.getBytes(), new File(dlg.getTraceFilePath())); } catch (IOException e) { throw new InvocationTargetException(e); } } }); } catch (InvocationTargetException e) { ErrorDialog.openError(parentShell, "Systrace", "Unable to collect system trace.", new Status(Status.ERROR, DdmsPlugin.PLUGIN_ID, "Unexpected error while collecting system trace.", e.getCause())); } catch (InterruptedException ignore) { } }
From source file:com.android.ide.eclipse.gltrace.editors.GLFunctionTraceViewer.java
License:Apache License
public void setInput(Shell shell, String tracePath) { ProgressMonitorDialog dlg = new ProgressMonitorDialog(shell); TraceFileParserTask parser = new TraceFileParserTask(mFilePath); try {/*from www. ja va 2 s.c o m*/ dlg.run(true, true, parser); } catch (InvocationTargetException e) { // exception while parsing, display error to user MessageDialog.openError(shell, "Error parsing OpenGL Trace File", e.getCause().getMessage()); return; } catch (InterruptedException e) { // operation canceled by user, just return return; } mTrace = parser.getTrace(); mShowContextSwitcher = (mTrace == null) ? false : mTrace.getContexts().size() > 1; if (mStateViewPage != null) { mStateViewPage.setInput(mTrace); } if (mFrameSummaryViewPage != null) { mFrameSummaryViewPage.setInput(mTrace); } if (mDetailsPage != null) { mDetailsPage.setInput(mTrace); } if (mDurationMinimap != null) { mDurationMinimap.setInput(mTrace); } Display.getDefault().asyncExec(new Runnable() { @Override public void run() { refreshUI(); } }); }