@Override
  public void run() {
    final VirtualViewerListener listener = new VirtualViewerListener();
    VirtualTreeModelViewer virtualViewer = initVirtualViewer(fClientViewer, listener);

    ProgressMonitorDialog dialog =
        new TimeTriggeredProgressMonitorDialog(fClientViewer.getControl().getShell(), 500);
    final IProgressMonitor monitor = dialog.getProgressMonitor();
    dialog.setCancelable(true);

    try {
      dialog.run(
          true,
          true,
          new IRunnableWithProgress() {
            @Override
            public void run(final IProgressMonitor m)
                throws InvocationTargetException, InterruptedException {
              synchronized (listener) {
                listener.fProgressMonitor = m;
                listener.fProgressMonitor.beginTask(
                    DebugUIPlugin.removeAccelerators(getText()), listener.fRemainingUpdatesCount);
              }

              while ((!listener.fLabelUpdatesComplete || !listener.fViewerUpdatesComplete)
                  && !listener.fProgressMonitor.isCanceled()) {
                Thread.sleep(1);
              }
              synchronized (listener) {
                listener.fProgressMonitor = null;
              }
            }
          });
    } catch (InvocationTargetException e) {
      DebugUIPlugin.log(e);
      return;
    } catch (InterruptedException e) {
      return;
    }

    VirtualItem root = virtualViewer.getTree();
    if (!monitor.isCanceled()) {
      List<VirtualItem> list = new ArrayList<VirtualItem>();
      collectAllChildren(root, list);
      FindLabelProvider labelProvider = new FindLabelProvider(virtualViewer, list);
      VirtualItem result = performFind(list, labelProvider);
      if (result != null) {
        setSelectionToClient(virtualViewer, labelProvider, result);
      }
    }

    virtualViewer.removeLabelUpdateListener(listener);
    virtualViewer.removeViewerUpdateListener(listener);
    virtualViewer.dispose();
  }
  private void runCommand(final List<EObject> exportModelElements, String filePath) {
    final File file = new File(filePath);

    final URI uri = URI.createFileURI(filePath);

    final ProgressMonitorDialog progressDialog =
        new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());

    progressDialog.open();
    progressDialog.getProgressMonitor().beginTask("Export modelelement...", 100);
    progressDialog.getProgressMonitor().worked(10);

    try {
      saveEObjectToResource(exportModelElements, uri);
    } catch (IOException e) {
      DialogHandler.showExceptionDialog(e.getMessage(), e);
    }
    progressDialog.getProgressMonitor().done();
    progressDialog.close();

    MessageDialog.openInformation(
        null, "Export", "Exported modelelement to file " + file.getName());
  }
Exemple #3
0
  @Override
  public void run(IAction action) {
    FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);

    dialog.setText("Select text file...");
    String sourceFile = dialog.open();
    if (sourceFile == null) return;
    ProgressMonitorDialog pd = new ProgressMonitorDialog(getShell());
    try {
      List<Type> types = TypeCollector.getData(new File(sourceFile), "UTF-8");
      pd.setBlockOnOpen(false);
      pd.open();
      pd.getProgressMonitor().beginTask("Generating cloud...", 200);
      TagCloudViewer viewer = getViewer();
      viewer.setInput(types, pd.getProgressMonitor());
      long start = System.currentTimeMillis();
      viewer.getCloud().layoutCloud(pd.getProgressMonitor(), false);
      long end = System.currentTimeMillis();
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      pd.close();
    }
  }
  private void executeCommand(
      final ObjectDeleteCommand odcDeleteCommand,
      final EObject[] eObjects,
      TransactionSettings ts) {

    if (odcDeleteCommand == null) {
      createObjectDeleteCommand();
    }

    String tempString = UiConstants.Util.getString(DELETE_ONE_TITLE_KEY);
    if (eObjects.length > 1) {
      tempString = UiConstants.Util.getString(DELETE_MANY_TITLE_KEY, eObjects.length);
    }
    final String deleteTitle = tempString;

    WorkspaceModifyOperation operation =
        new WorkspaceModifyOperation() {
          @Override
          public void execute(final IProgressMonitor monitor) {

            if (monitor instanceof SubProgressMonitor) {
              ((SubProgressMonitor) monitor).getWrappedProgressMonitor().setTaskName(deleteTitle);
            }

            monitor.beginTask(CoreStringUtil.Constants.EMPTY_STRING, 100);
            monitor.worked(5);
            // execute the command
            IStatus status = odcDeleteCommand.execute(monitor);

            setResult(status);
          }
        };

    // start the txn
    ts.setSource(this);
    boolean started =
        ModelerCore.startTxn(
            ts.isSignificant(), ts.isUndoable(), ts.getDescription(), ts.getSource());

    boolean succeeded = false;

    try {
      ProgressMonitorDialog progressDialog =
          new ProgressMonitorDialog(Display.getDefault().getActiveShell());

      // run the operation
      progressDialog.run(true, true, operation);
      if (!progressDialog.getProgressMonitor().isCanceled()) {
        succeeded = true;
      }

      if (!getStatus().isOK()) {
        UiConstants.Util.log(getStatus());
      }
    } catch (Exception e) {
      UiConstants.Util.log(IStatus.ERROR, e, e.getMessage());
    } finally {
      if (started) {
        if (succeeded) {
          ModelerCore.commitTxn();
        } else {
          ModelerCore.rollbackTxn();
        }
      }
    }
  }