/** Update the tree to only select those elements that match the selected types */
  private void setupSelectionsBasedOnSelectedTypes() {

    Runnable runnable =
        new Runnable() {
          public void run() {
            Map selectionMap = new Hashtable();
            // Only get the white selected ones
            Iterator resourceIterator = resourceGroup.getAllWhiteCheckedItems().iterator();
            while (resourceIterator.hasNext()) {
              // handle the files here - white checked containers require recursion
              IResource resource = (IResource) resourceIterator.next();
              if (resource.getType() == IResource.FILE) {
                if (hasExportableExtension(resource.getName())) {
                  List resourceList = new ArrayList();
                  IContainer parent = resource.getParent();
                  if (selectionMap.containsKey(parent)) {
                    resourceList = (List) selectionMap.get(parent);
                  }
                  resourceList.add(resource);
                  selectionMap.put(parent, resourceList);
                }
              } else {
                setupSelectionsBasedOnSelectedTypes(selectionMap, (IContainer) resource);
              }
            }
            resourceGroup.updateSelections(selectionMap);
          }
        };

    BusyIndicator.showWhile(getShell().getDisplay(), runnable);
  }
  public void execute(
      ICustomContext context, String newName, ICompilationUnit cu, PersistentType originalJPT) {
    IProject project = originalJPT.getJpaProject().getProject();
    final Diagram d = ModelIntegrationUtil.getDiagramByProject(project);
    if (d == null) return;
    final JPAEditorDiagramTypeProvider provider =
        ModelIntegrationUtil.getProviderByDiagram(d.getName());

    PictogramElement pe =
        provider.getFeatureProvider().getPictogramElementForBusinessObject(originalJPT);

    provider.getDiagramEditor().selectPictogramElements(new PictogramElement[] {null});

    final Semaphore s = new Semaphore(0);
    ShowBusy showBusy = new ShowBusy(s);
    JPASolver.ignoreEvents = true;
    Command renameEntityCommand = new RenameEntityClass(originalJPT, newName);
    try {
      getJpaProjectManager().execute(renameEntityCommand, SynchronousUiCommandContext.instance());
    } catch (InterruptedException e) {
      JPADiagramEditorPlugin.logError("Cannot delete attribute with name ", e); // $NON-NLS-1$
    }

    BusyIndicator.showWhile(Display.getCurrent(), showBusy);
    JPASolver.ignoreEvents = false;

    provider.getDiagramEditor().setPictogramElementForSelection(pe);
  }
Beispiel #3
0
 /**
  * Creates an extension. If the extension plugin has not been loaded, a busy cursor will be
  * activated during the duration of the load.
  *
  * @param element the config element defining the extension
  * @param classAttribute the name of the attribute carrying the class
  * @return the extension object
  */
 public static Object createExtension(
     final IConfigurationElement element, final String classAttribute) throws CoreException {
   // If plugin has been loaded, create extension.
   // Otherwise, show busy cursor then create extension.
   String id = element.getContributor().getName();
   Bundle bundle = Platform.getBundle(id);
   if (bundle.getState() == org.osgi.framework.Bundle.ACTIVE) {
     return element.createExecutableExtension(classAttribute);
   }
   final Object[] ret = new Object[1];
   final CoreException[] exc = new CoreException[1];
   BusyIndicator.showWhile(
       null,
       new Runnable() {
         @Override
         public void run() {
           try {
             ret[0] = element.createExecutableExtension(classAttribute);
           } catch (CoreException e) {
             exc[0] = e;
           }
         }
       });
   if (exc[0] != null) throw exc[0];
   return ret[0];
 }
 /**
  * A new resource has been selected. Change the contents of the folder names list.
  *
  * @desc resource descriptor of the selected resource
  */
 private void updateFolders(final ResourceDescriptor desc) {
   BusyIndicator.showWhile(
       getShell().getDisplay(),
       new Runnable() {
         public void run() {
           if (!desc.resourcesSorted) {
             // sort the folder names
             Collections.sort(
                 desc.resources,
                 new Comparator() {
                   public int compare(Object o1, Object o2) {
                     String s1 = getParentLabel((ENamedElement) o1);
                     String s2 = getParentLabel((ENamedElement) o2);
                     return collator.compare(s1, s2);
                   }
                 });
             desc.resourcesSorted = true;
           }
           folderNames.removeAll();
           for (int i = 0; i < desc.resources.size(); i++) {
             TableItem newItem = new TableItem(folderNames, SWT.NONE);
             ENamedElement r = (ENamedElement) desc.resources.get(i);
             newItem.setText(getParentLabel(r));
             newItem.setImage(getParentImage(r));
             newItem.setData(r);
           }
           folderNames.setSelection(0);
         }
       });
 }
 /**
  * Creates an extension. If the extension plugin has not been loaded a busy cursor will be
  * activated during the duration of the load.
  *
  * @param element the config element defining the extension
  * @param classAttribute the name of the attribute carrying the class
  * @returns the extension object if successful. If an error occurs when createing executable
  *     extension, the exception is logged, and null returned.
  */
 public static Object createExtension(
     final IConfigurationElement element, final String classAttribute) {
   final Object[] result = new Object[1];
   // If plugin has been loaded create extension.
   // Otherwise, show busy cursor then create extension.
   String pluginId = element.getDeclaringExtension().getNamespace();
   Bundle bundle = Platform.getBundle(pluginId);
   if (bundle.getState() == Bundle.ACTIVE) {
     try {
       result[0] = element.createExecutableExtension(classAttribute);
     } catch (Exception e) {
       // catch and log ANY exception from extension point
       handleCreateExecutableException(result, e);
     }
   } else {
     BusyIndicator.showWhile(
         null,
         new Runnable() {
           public void run() {
             try {
               result[0] = element.createExecutableExtension(classAttribute);
             } catch (Exception e) {
               // catch and log ANY exception from extension point
               handleCreateExecutableException(result, e);
             }
           }
         });
   }
   return result[0];
 }
    public void widgetSelected(SelectionEvent e) {
      // Get the selected item and get the associated path.
      // open a PathSettingDialog to modify the path.
      TableItem selected = fTable.getSelection()[0];
      AVRPathManager path = (AVRPathManager) selected.getData();

      if (e.getSource() == fEditButton) {
        PathSettingDialog dialog = new PathSettingDialog(fTable.getShell(), path);
        if (dialog.open() == Window.OK) {
          // OK Button selected:
          // get the modified Path, keep it and update this Editor
          path = dialog.getResult();
        }
      } else if (e.getSource() == fRescanButton) {
        // force a search for the current system path.
        // This may take a while so we display a Wait cursor
        final AVRPathManager finalpath = path;
        BusyIndicator.showWhile(
            fTable.getDisplay(),
            new Runnable() {
              public void run() {
                finalpath.getSystemPath(true);
              }
            });
      }
      selected.setData(path);
      updateTableItem(selected);
      refreshValidState();
    }
  @Override
  public void run() {
    if (canEdit()) {
      Runnable longJob =
          new Runnable() {

            public void run() {
              Object element = getStructuredSelection().getFirstElement();
              if (element instanceof MakeTarget) {
                MakeTargetDialog<MakeTarget> dialog =
                    new MakeTargetDialog.StandardMakeTargetDialog(shell, (MakeTarget) element);
                dialog.openMakeTargetDialog();
              } else if (element instanceof IProject) {
                try {
                  ProjectTOS tos = TinyOSPlugin.getDefault().getProjectTOS((IProject) element);
                  if (tos != null) {
                    MakeTargetDialog<MakeTargetSkeleton> dialog =
                        new MakeTargetDialog.ProjectDefaultsMakeTargetDialog(shell, tos);
                    dialog.openMakeTargetDialog();
                  }
                } catch (MissingNatureException ex) {
                  TinyOSCore.inform("edit make-option", ex);
                }
              }
            };
          };

      BusyIndicator.showWhile(TinyOSPlugin.getStandardDisplay(), longJob);
    }
  }
  /**
   * Implementation of the <code>IAction</code> prototype. Checks if the selected lines are all
   * commented or not and uncomments/comments them respectively.
   */
  public void run() {
    if (fOperationTarget == null || fDocumentPartitioning == null || fPrefixesMap == null) return;
    ITextEditor editor = getTextEditor();
    if (editor == null) return;
    if (!validateEditorInputState()) return;
    final int operationCode;
    if (isSelectionCommented(editor.getSelectionProvider().getSelection()))
      operationCode = ITextOperationTarget.STRIP_PREFIX;
    else operationCode = ITextOperationTarget.PREFIX;
    Shell shell = editor.getSite().getShell();
    if (!fOperationTarget.canDoOperation(operationCode)) {
      if (shell != null)
        // MessageDialog.openError(shell,
        // JavaEditorMessages.getString("ToggleComment.error.title"),
        // JavaEditorMessages.getString("ToggleComment.error.message"));
        // //$NON-NLS-1$ //$NON-NLS-2$
        return;
    }
    Display display = null;
    if (shell != null && !shell.isDisposed()) display = shell.getDisplay();
    BusyIndicator.showWhile(
        display,
        new Runnable() {

          public void run() {
            fOperationTarget.doOperation(operationCode);
          }
        });
  }
Beispiel #9
0
  protected void refreshChart() {
    BusyIndicator.showWhile(
        Display.getCurrent(),
        new Runnable() {

          @Override
          public void run() {
            ChartRowViewItem[] rowViewItem =
                (ChartRowViewItem[]) view.getAdapter(ChartRowViewItem[].class);
            if (rowViewItem != null) {
              IChartObject[][] input = new IChartObject[rowViewItem.length][];
              for (int i = 0; i < input.length; i++) {
                input[i] = (IChartObject[]) rowViewItem[i].getAdapter(IChartObject[].class);
              }
              viewer.setInput(input);

              if (memento != null && memento.getString("weights") != null) { // $NON-NLS-1$
                String[] s = memento.getString("weights").split(";"); // $NON-NLS-1$ //$NON-NLS-2$
                int[] weights = viewer.getWeights();
                for (int i = 0; i < weights.length && i < s.length; i++) {
                  weights[i] = Integer.valueOf(s[i]);
                }
                viewer.setWeights(weights);
              }
            }
          }
        });
  }
Beispiel #10
0
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    fTargetPart = HandlerUtil.getActivePartChecked(event);

    if (getCastToType() == null || getCastToType().length == 0) return null;

    BusyIndicator.showWhile(
        Display.getCurrent(),
        new Runnable() {

          @Override
          public void run() {
            try {
              doAction(getCastToType());
              setStatus(null);
            } catch (DebugException e) {
              setStatus(e.getStatus());
            }
          }
        });
    if (getStatus() != null && !getStatus().isOK()) {
      IWorkbenchWindow window = CDebugUIPlugin.getActiveWorkbenchWindow();
      if (window != null) {
        CDebugUIPlugin.errorDialog(
            ActionMessages.getString("CastToTypeActionDelegate.3"), getStatus()); // $NON-NLS-1$
      } else {
        CDebugUIPlugin.log(getStatus());
      }
    }

    return null;
  }
Beispiel #11
0
  /* (non-Javadoc)
   * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
   */
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    // clear console
    Console.getInstance().clear();

    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window != null) {
      Activator.getDefault().testsStarted();

      // get the selections in the Project explorer
      IStructuredSelection selection =
          (IStructuredSelection)
              window.getSelectionService().getSelection("org.eclipse.ui.navigator.ProjectExplorer");
      final Object[] selectedElements = selection.toArray();

      BusyIndicator.showWhile(
          null,
          new Runnable() {
            @Override
            public void run() {
              // go through each open selected project
              for (int index = 0; index < selectedElements.length; index++) {
                Object element = selectedElements[index];
                log.debug("Calling runTestsObject on " + selectedElements[index]);
                runTestsObject(element);
              }
            }
          });
    }
    return null;
  }
 private void handleNewFeature() {
   final Control control = fCategoryViewer.getControl();
   BusyIndicator.showWhile(
       control.getDisplay(),
       new Runnable() {
         public void run() {
           IFeatureModel[] allModels = PDECore.getDefault().getFeatureModelManager().getModels();
           ArrayList<IFeatureModel> newModels = new ArrayList<IFeatureModel>();
           for (int i = 0; i < allModels.length; i++) {
             if (canAdd(allModels[i])) newModels.add(allModels[i]);
           }
           IFeatureModel[] candidateModels =
               newModels.toArray(new IFeatureModel[newModels.size()]);
           FeatureSelectionDialog dialog =
               new FeatureSelectionDialog(
                   fCategoryViewer.getTree().getShell(), candidateModels, true);
           if (dialog.open() == Window.OK) {
             Object[] models = dialog.getResult();
             try {
               doAdd(models);
             } catch (CoreException e) {
               PDEPlugin.log(e);
             }
           }
         }
       });
 }
Beispiel #13
0
  /**
   * Implementation of the <code>IAction</code> prototype. Checks if the selected lines are all
   * commented or not and uncomments/comments them respectively.
   */
  @Override
  public void run() {
    if (fOperationTarget == null || fDocumentPartitioning == null || fPrefixesMap == null) return;

    final int operationCode;
    if (isSelectionCommented(fViewer.getSelectionProvider().getSelection()))
      operationCode = ITextOperationTarget.STRIP_PREFIX;
    else operationCode = ITextOperationTarget.PREFIX;

    Shell shell = fViewer.getTextWidget().getShell();
    if (!fOperationTarget.canDoOperation(operationCode)) {
      if (shell != null)
        MessageDialog.openError(
            shell,
            "An error occured",
            "ToggleComment_error_message=An error occurred while toggling comments."); //$NON-NLS-1$//$NON-NLS-2$
      return;
    }

    Display display = null;
    if (shell != null && !shell.isDisposed()) display = shell.getDisplay();

    BusyIndicator.showWhile(
        display,
        new Runnable() {
          public void run() {
            fOperationTarget.doOperation(operationCode);
          }
        });
  }
  /*
   * @see org.eclipse.ui.texteditor.ITextEditorExtension2#validateEditorInputState()
   * @since 2.1
   */
  public boolean validateEditorInputState() {

    boolean enabled = false;

    synchronized (this) {
      enabled = fIsStateValidationEnabled;
    }

    if (enabled) {

      ISourceViewer viewer = fSourceViewer;
      if (viewer == null) return false;

      final IEditorInput input = getEditorInput();
      BusyIndicator.showWhile(
          getSite().getShell().getDisplay(),
          new Runnable() {
            /*
             * @see java.lang.Runnable#run()
             */
            public void run() {
              validateState(input);
            }
          });
      sanityCheckState(input);
      return true;
    }

    return true;
  }
 /*
  * @see Action#actionPerformed
  */
 public void run() {
   BusyIndicator.showWhile(
       fView.getSite().getShell().getDisplay(),
       new Runnable() {
         public void run() {
           fView.showQualifiedTypeNames(isChecked());
         }
       });
 }
 /** @generated */
 protected void performDirectEdit() {
   BusyIndicator.showWhile(
       Display.getDefault(),
       new java.lang.Runnable() {
         public void run() {
           getManager().show();
         }
       });
 }
Beispiel #17
0
 /**
  * Toggles the filtering of properties from the Ant outline
  *
  * @see org.eclipse.jface.action.IAction#run()
  */
 public void run() {
   BusyIndicator.showWhile(
       fPage.getControl().getDisplay(),
       new Runnable() {
         public void run() {
           fPage.setFilterProperties(isChecked());
         }
       });
 }
Beispiel #18
0
  private void initializeCheckedState() {

    BusyIndicator.showWhile(
        getShell().getDisplay(),
        new Runnable() {
          public void run() {
            Object[] elements;
            if (fWorkingSet == null) {
              // Use current part's selection for initialization
              IWorkbenchPage page = DLTKUIPlugin.getActivePage();
              if (page == null) return;

              IWorkbenchPart part = DLTKUIPlugin.getActivePage().getActivePart();
              if (part == null) return;

              try {
                elements = SelectionConverter.getStructuredSelection(part).toArray();
                for (int i = 0; i < elements.length; i++) {
                  if (elements[i] instanceof IResource) {
                    IModelElement je =
                        (IModelElement) ((IResource) elements[i]).getAdapter(IModelElement.class);
                    if (je != null
                        && je.exists()
                        && je.getScriptProject().isOnBuildpath((IResource) elements[i]))
                      elements[i] = je;
                  }
                }
              } catch (ModelException e) {
                return;
              }
            } else elements = fWorkingSet.getElements();

            // Use closed project for elements in closed project
            for (int i = 0; i < elements.length; i++) {
              Object element = elements[i];
              if (element instanceof IResource) {
                IProject project = ((IResource) element).getProject();
                if (!project.isAccessible()) elements[i] = project;
              }
              if (element instanceof IModelElement) {
                IScriptProject jProject = ((IModelElement) element).getScriptProject();
                if (jProject != null && !jProject.getProject().isAccessible())
                  elements[i] = jProject.getProject();
              }
            }

            fTree.setCheckedElements(elements);
            for (int i = 0; i < elements.length; i++) {
              Object element = elements[i];
              if (isExpandable(element)) setSubtreeChecked(element, true, true);

              updateParentState(element, true);
            }
          }
        });
  }
 protected boolean savePreferences() {
   BusyIndicator.showWhile(
       getControl().getDisplay(),
       new Runnable() {
         public void run() {
           storeValues();
         }
       });
   return true;
 }
 public void run(IAction action) {
   BusyIndicator.showWhile(
       window.getShell().getDisplay(),
       new Runnable() {
         public void run() {
           UpdateJob job = new UpdateJob("Searching for updates", false, false);
           UpdateManagerUI.openInstaller(window.getShell(), job);
         }
       });
 }
 private void handleImportEnvironment() {
   IStructuredSelection sel = (IStructuredSelection) fCategoryViewer.getSelection();
   final ISiteFeature[] selectedFeatures = getFeaturesFromSelection(sel);
   BusyIndicator.showWhile(
       fCategoryTreePart.getControl().getDisplay(),
       new Runnable() {
         public void run() {
           new SynchronizePropertiesAction(selectedFeatures, getModel()).run();
         }
       });
 }
Beispiel #22
0
  protected void showHexDump(final String filePath) {
    Runnable runnable =
        new Runnable() {

          @Override
          public void run() {
            hexview.ViewHexDump(filePath);
          }
        };
    BusyIndicator.showWhile(AndrospyMain.shell.getDisplay(), runnable);
  }
  /**
   * Update the selections of the tree elements in items to reflect the new selections provided.
   *
   * @param items with keys of Object (the tree element) and values of List (the selected list
   *     elements).
   */
  public void updateSelections(final Map<Object, List<Object>> items) {

    // Potentially long operation - show a busy cursor
    BusyIndicator.showWhile(
        fTreeViewer.getControl().getDisplay(),
        new Runnable() {
          public void run() {
            handleUpdateSelection(items);
          }
        });
  }
    private void valueChanged(final boolean on, boolean store) {
      setChecked(on);
      BusyIndicator.showWhile(
          fOutlineViewer.getControl().getDisplay(),
          new Runnable() {
            public void run() {
              fOutlineViewer.refresh(false);
            }
          });

      if (store) getDialogSettings().put(STORE_LEXICAL_SORTING_CHECKED, on);
    }
 protected boolean loadPreferences() {
   BusyIndicator.showWhile(
       getControl().getDisplay(),
       new Runnable() {
         public void run() {
           initializeValues();
           validateValues();
           enableValues();
         }
       });
   return true;
 }
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
   */
  public void run(IAction action) {

    BusyIndicator.showWhile(
        window.getShell().getDisplay(),
        new Runnable() {

          public void run() {

            UpdateManagerUI.openInstaller(window.getShell());
          }
        });
  }
  /**
   * Selects or deselect all of the elements in the tree depending on the value of the selection
   * boolean. Be sure to update the displayed files as well.
   *
   * @param selection
   */
  public void setAllSelections(final boolean selection) {

    // Potentially long operation - show a busy cursor
    BusyIndicator.showWhile(
        fTreeViewer.getControl().getDisplay(),
        new Runnable() {
          public void run() {
            setTreeChecked(fRoot, selection);
            fListViewer.setAllChecked(selection);
          }
        });
  }
  @Override
  protected Control createContents(final Composite parent) {
    final Control[] control = new Control[1];
    BusyIndicator.showWhile(
        getShell().getDisplay(),
        () -> {
          control[0] = PreferenceDialog.super.createContents(parent);
          // Add the first page
          selectSavedItem();
        });

    return control[0];
  }
  private void initControls() {

    _switchYardProject =
        SwitchYardProjectManager.instance().getSwitchYardProject(getProject()).createWorkingCopy();
    if (_switchYardProject.needsLoading()) {
      BusyIndicator.showWhile(
          getShell().getDisplay(),
          new Runnable() {
            @Override
            public void run() {
              _switchYardProject.load(new NullProgressMonitor());
            }
          });
    }
    try {
      _ifp = ProjectFacetsManager.create(_switchYardProject.getProject());
      _ifpwc = SharedWorkingCopyManager.getWorkingCopy(_ifp);
      _configuredRuntimes = _ifpwc.getTargetedRuntimes();
    } catch (CoreException e) {
      Activator.getDefault().getLog().log(e.getStatus());
    }

    _settingsGroup.setProject(_ifpwc);

    initTargetRuntime();
    initRuntimeVersion();
    initComponentsTable();

    _useSwitchYardDependencyBOMCheckbox.setSelection(pomUsesSwitchYardBOM());

    String errmsg = null;
    if (!pomDefinesSwitchYardVersion()) {
      _settingsGroup.setRuntimeControlEnablement(false);
    } else if (pomUsesSwitchYardBOM()) {
      if (!isSelectedRuntimeVersion2OrHigher()) {
        // only valid versions with BOM dependency support are 2.0+
        errmsg = Messages.ProjectConfigurationWizardPage_errorMessage_bomRequiresVersion2;
      }
    } else if (!isSelectedConfigurationVersionOkForRuntime()) {
      String configVersion = getMajorMinorFromVersion(getRuntimeVersion().toString());
      errmsg =
          "The Configuration Version must be "
              + configVersion
              + " or lower to work with Library Version "
              + getRuntimeVersion().toString()
              + ".";
    }
    setErrorMessage(errmsg);
    getContainer().updateMessage();
  }
Beispiel #30
0
  /**
   * Creates a ResourceDescriptor for each IResource, sorts them and removes the duplicated ones.
   *
   * @param resources resources to create resource descriptors for
   */
  private void initDescriptors(final IResource resources[]) {
    BusyIndicator.showWhile(
        null,
        new Runnable() {
          public void run() {
            descriptors = new ResourceDescriptor[resources.length];
            for (int i = 0; i < resources.length; i++) {
              IResource r = resources[i];
              ResourceDescriptor d = new ResourceDescriptor();
              // TDB: Should use the label provider and compare performance.
              d.label = r.getName();
              d.resources.add(r);
              descriptors[i] = d;
            }
            Arrays.sort(descriptors);
            descriptorsSize = descriptors.length;

            // Merge the resource descriptor with the same label and type.
            int index = 0;
            if (descriptorsSize < 2) {
              return;
            }
            ResourceDescriptor current = descriptors[index];
            IResource currentResource = (IResource) current.resources.get(0);
            for (int i = 1; i < descriptorsSize; i++) {
              ResourceDescriptor next = descriptors[i];
              IResource nextResource = (IResource) next.resources.get(0);
              if (nextResource.getType() == currentResource.getType()
                  && next.label.equals(current.label)) {
                current.resources.add(nextResource);
                // If we are merging resources with the same name, into a single descriptor,
                // then we must mark the descriptor unsorted so that we will sort the folder
                // names.
                // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=76496
                current.resourcesSorted = false;
              } else {
                if (current.resources.size() > 1) {
                  current.resourcesSorted = false;
                }
                descriptors[index + 1] = descriptors[i];
                index++;
                current = descriptors[index];
                currentResource = (IResource) current.resources.get(0);
              }
            }
            descriptorsSize = index + 1;
          }
        });
  }