public static boolean enableDelete(IStructuredSelection graphicalSelection) {

    boolean enableDel = false;
    List<Object> elements = new ArrayList<Object>();
    IStructuredSelection selection = Selection.getInstance().getStructuredSelection();

    if (!selection.isEmpty()) {
      if (graphicalSelection.getFirstElement() instanceof DiagramEditPart) return false;
      enableDel = true;
      // Iterate through removing elements that are only graphical
      for (Iterator<?> iter = selection.iterator(); iter.hasNext(); ) {
        Object current = iter.next();
        if (current instanceof GraphicalElement_c) {
          GraphicalElement_c ge = (GraphicalElement_c) current;
          if (ge.getRepresents() == null) {
            elements.add(current);
            Selection.getInstance().removeFromSelection(ge);
          }
        }
      }
    }

    selection = Selection.getInstance().getStructuredSelection();
    if (!selection.isEmpty()) {
      // Check the remaining items against the usual DeleteAction,
      enableDel = DeleteAction.canDeleteAction();
    }

    // Add the graphical only elements back to the selection
    for (int i = 0; i < elements.size(); ++i) {
      Selection.getInstance().addToSelection(elements.get(i));
    }

    return enableDel;
  }
 /** Refresh the enable/disable state for the buttons. */
 private void updateButtons() {
   IStructuredSelection selection = (IStructuredSelection) fVariablesViewer.getSelection();
   fRemoveButton.setEnabled(!selection.isEmpty());
   boolean enableUp = true, enableDown = true;
   Object[] libraries = fEnvironmentVariablesContentProvider.getElements(null);
   if (selection.isEmpty() || libraries.length == 0) {
     enableUp = false;
     enableDown = false;
   } else {
     Object first = libraries[0];
     Object last = libraries[libraries.length - 1];
     for (Iterator iter = selection.iterator(); iter.hasNext(); ) {
       Object element = iter.next();
       Object lib;
       lib = element;
       if (lib == first) {
         enableUp = false;
       }
       if (lib == last) {
         enableDown = false;
       }
     }
   }
   // fUpButton.setEnabled(enableUp);
   // fDownButton.setEnabled(enableDown);
 }
 /** Copied from @{link LinkEditorAction} */
 @SuppressWarnings("unchecked")
 private IStructuredSelection mergeSelection(
     IStructuredSelection aBase, IStructuredSelection aSelectionToAppend) {
   if (aBase == null || aBase.isEmpty()) {
     return (aSelectionToAppend != null) ? aSelectionToAppend : StructuredSelection.EMPTY;
   } else if (aSelectionToAppend == null || aSelectionToAppend.isEmpty()) {
     return aBase;
   } else {
     List<Object> newItems = new ArrayList<Object>(aBase.toList());
     newItems.addAll(aSelectionToAppend.toList());
     return new StructuredSelection(newItems);
   }
 }
Exemplo n.º 4
0
 /*
  * (non-Javadoc)
  *
  * @see org.talend.repository.ui.actions.ITreeContextualAction#init(org.eclipse.jface.viewers.TreeViewer,
  * org.eclipse.jface.viewers.IStructuredSelection)
  */
 public void init(TreeViewer viewer, IStructuredSelection selection) {
   boolean canWork = !selection.isEmpty() && selection.size() == 1;
   if (canWork) {
     Object o = selection.getFirstElement();
     RepositoryNode node = (RepositoryNode) o;
     if (CamelEditorUtil.hasEditorOpened(node)) {
       canWork = false;
     } else {
       switch (node.getType()) {
         case REPOSITORY_ELEMENT:
           if (node.getObjectType() != CamelRepositoryNodeType.repositoryRoutesType) {
             canWork = false;
           }
           break;
         default:
           canWork = false;
       }
     }
     if (canWork
         && node.getObject() != null
         && ProxyRepositoryFactory.getInstance().getStatus(node.getObject())
             == ERepositoryStatus.LOCK_BY_USER) {
       canWork = false;
     }
   }
   setEnabled(canWork);
 }
Exemplo n.º 5
0
  /** Handler for tree selection. */
  void handleTreeSelection() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    ElementSymbol element = null;

    if (!selection.isEmpty()) {
      ICriteriaStrategy strategy = ElementViewerFactory.getCriteriaStrategy(viewer);
      strategy.setTreeViewer(viewer); // make sure this viewer is set before using strategy

      if (strategy.isValid(selection.getFirstElement())) {
        Object eObj = selection.getFirstElement();
        if (eObj instanceof ElementSymbol) {
          element = ((ElementSymbol) eObj);
        } else {
          element = new ElementSymbol(strategy.getRuntimeFullName(eObj), true);

          // the viewer model contains EObjects. so the objects in the selection will
          // be EObjects. since the EObject is used later on in the QueryCriteriaStrategy.getNode()
          // method. save it here.
          element.setMetadataID(eObj);
        }
      }
    }

    model.selectElementSymbol(element);
  }
 /** The table viewer selection has changed. Update the toolbar and menu enablements */
 private void handleSelection() {
   ISelection selection = tableViewer.getSelection();
   if (selection == null || !(selection instanceof IStructuredSelection)) {
     return;
   }
   IStructuredSelection structuredSelection = (IStructuredSelection) selection;
   List selectionList = structuredSelection.toList();
   boolean selectionEmpty = structuredSelection.isEmpty();
   boolean firstRowSelected = true;
   boolean lastRowSelected = true;
   if (!selectionEmpty) {
     SortFilterElement element = (SortFilterElement) selectionList.get(0);
     if (tableViewer.getElementAt(0).equals(element)) {
       firstRowSelected = true;
     } else {
       firstRowSelected = false;
     }
     element = (SortFilterElement) selectionList.get(selectionList.size() - 1);
     if (tableViewer.getElementAt(tableViewer.getTable().getItemCount() - 1).equals(element)) {
       lastRowSelected = true;
     } else {
       lastRowSelected = false;
     }
   }
   if (moveUpToolItem != null) {
     moveUpToolItem.setEnabled(!firstRowSelected && !selectionEmpty);
   }
   if (moveDownToolItem != null) {
     moveDownToolItem.setEnabled(!lastRowSelected && !selectionEmpty);
   }
 }
Exemplo n.º 7
0
  /** Runs the operation, basically invert the value of isDefault property on the sequence edge. */
  @Override
  protected void doRun(IProgressMonitor progressMonitor) {
    IStructuredSelection selection = getStructuredSelection();
    if (selection == null || (selection.isEmpty())) {
      return;
    }
    if (selection.getFirstElement() instanceof IGraphicalEditPart) {
      IGraphicalEditPart part = (IGraphicalEditPart) selection.getFirstElement();
      final EObject object =
          ((IGraphicalEditPart) selection.getFirstElement()).getNotationView().getElement();
      if (object instanceof Activity) {
        part.getDiagramEditDomain()
            .getDiagramCommandStack()
            .execute(
                new ICommandProxy(
                    new MyCommand(object) {

                      @Override
                      protected CommandResult doExecuteWithResult(
                          IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
                        if (object instanceof Activity) {
                          ((Activity) object).setLooping(!(((Activity) object).isLooping()));
                        }
                        return CommandResult.newOKCommandResult();
                      }
                    }),
                progressMonitor);
      }
    }
  }
  @Override
  public void init(IWorkbench workbench, IStructuredSelection selection) {
    if (selection != null && !selection.isEmpty()) {
      final Object element = selection.getFirstElement();

      if (element instanceof IResource) {
        initialProject = ((IResource) element).getProject();
      } else if (element instanceof IJavaProject) {
        initialProject = ((IJavaProject) element).getProject();
      } else if (element instanceof IPackageFragment) {
        initialProject = ((IJavaElement) element).getResource().getProject();
      } else if (element instanceof IJavaElement) {
        initialProject = ((IJavaElement) element).getResource().getProject();
      }

      if (initialProject != null) {
        final IBundleProject bundleProject =
            LiferayCore.create(IBundleProject.class, initialProject);

        if (bundleProject != null && bundleProject.isFragmentBundle()) {
          element().setProjectName(initialProject.getName());
        }
      }
    }
  }
Exemplo n.º 9
0
  public void performVisibleTableDragOver(DropTargetEvent event) {
    if (!TextTransfer.getInstance().isSupportedType(event.currentDataType)) {
      event.detail = DND.DROP_NONE;
      return;
    }

    Tree tree = visibleColTable.getViewer().getTree();
    TreeItem dragOverTreeItem =
        tree.getItem(visibleColTable.getViewer().getTree().toControl(event.x, event.y));
    if (dragOverTreeItem == null) {
      return;
    }

    event.feedback = DND.FEEDBACK_EXPAND;
    event.detail = DND.DROP_NONE;

    IStructuredSelection selectedItem =
        (IStructuredSelection) visibleColTable.getViewer().getSelection();
    if (selectedItem == null || selectedItem.isEmpty()) {
      selectedItem = (IStructuredSelection) hiddenColTable.getViewer().getSelection();
    }
    if (selectedItem == null) {
      return;
    }
    Object obj = selectedItem.getFirstElement();
    if (obj instanceof XViewerColumn) {
      if (isFeedbackAfter) {
        event.feedback = DND.FEEDBACK_INSERT_AFTER;
      } else {
        event.feedback = DND.FEEDBACK_INSERT_BEFORE;
      }
      event.detail = DND.DROP_MOVE;
    }
  }
    @Override
    public void run() {
      IStructuredSelection selection = (IStructuredSelection) getColumnViewer().getSelection();
      List<RevisionHistory> viewerInput = (List<RevisionHistory>) getColumnViewer().getInput();
      if (selection != null && !selection.isEmpty()) {
        Object[] objs = selection.toArray();
        for (int i = 0; i < objs.length; i++) {

          int oldIndex = viewerInput.indexOf(objs[i]);

          // 已经最顶了,上移无意义
          if (oldIndex == 0) {
            continue;
          }

          // 不能超过一起被选中的
          if (i > 0 && viewerInput.get(oldIndex - 1) == objs[i - 1]) {
            continue;
          }

          RevisionHistory tmp = viewerInput.get(oldIndex - 1);
          RevisionHistory item1 = CoreFactory.eINSTANCE.createRevisionHistory();
          RevisionHistory item2 = CoreFactory.eINSTANCE.createRevisionHistory();
          viewerInput.set(oldIndex - 1, item1);
          viewerInput.set(oldIndex, item2);
          viewerInput.set(oldIndex - 1, (RevisionHistory) objs[i]);
          viewerInput.set(oldIndex, tmp);
        }
      }

      getColumnViewer().setInput(viewerInput);
    }
 /*
  * (non-Javadoc)
  *
  * @see org.talend.commons.ui.swt.actions.ITreeContextualAction#init(org.eclipse.jface.viewers.TreeViewer,
  * org.eclipse.jface.viewers.IStructuredSelection)
  */
 @Override
 public void init(TreeViewer viewer, IStructuredSelection selection) {
   boolean canWork = !selection.isEmpty() && selection.size() == 1;
   IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
   if (factory.isUserReadOnlyOnCurrentProject()) {
     canWork = false;
   }
   if (canWork) {
     Object o = selection.getFirstElement();
     RepositoryNode node = (RepositoryNode) o;
     switch (node.getType()) {
       case SIMPLE_FOLDER:
       case SYSTEM_FOLDER:
         ERepositoryObjectType nodeType =
             (ERepositoryObjectType) node.getProperties(EProperties.CONTENT_TYPE);
         if (nodeType != ERepositoryObjectType.PIG_UDF) {
           canWork = false;
         }
         if (node.getObject() != null && node.getObject().isDeleted()) {
           canWork = false;
         }
         break;
       default:
         canWork = false;
     }
     if (canWork && !ProjectManager.getInstance().isInCurrentMainProject(node)) {
       canWork = false;
     }
   }
   setEnabled(canWork);
 }
Exemplo n.º 12
0
  @Override
  public void doRun(
      IStructuredSelection selection, Event event, UIInstrumentationBuilder instrumentation) {

    instrumentation.metric("command", command);

    if (!selection.isEmpty() && selection.getFirstElement() instanceof IResource) {
      Object object = selection.getFirstElement();
      if (object instanceof IFile) {
        object = ((IFile) object).getParent();
      }
      while (object != null
          && ((IContainer) object).findMember(DartCore.PUBSPEC_FILE_NAME) == null) {
        object = ((IContainer) object).getParent();
      }
      if (object instanceof IContainer) {
        IContainer container = (IContainer) object;
        instrumentation.data("name", container.getName());
        savePubspecFile(container);
        runPubJob(container);
        return;
      } else {
        instrumentation.metric("Problem", "Object was null").log();
      }
    }

    instrumentation.metric("Problem", "pubspec.yaml file not selected, showing dialog");

    MessageDialog.openError(
        getShell(), ActionMessages.RunPubAction_fail, ActionMessages.RunPubAction_fileNotFound);

    instrumentation.log();
  }
  private GradleProject getContext() {
    IWorkbench wb = PlatformUI.getWorkbench();
    IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
    IWorkbenchPage page = win == null ? null : win.getActivePage();

    if (page != null) {
      ISelection selection = page.getSelection();
      if (selection instanceof IStructuredSelection) {
        IStructuredSelection ss = (IStructuredSelection) selection;
        if (!ss.isEmpty()) {
          Object obj = ss.getFirstElement();
          if (obj instanceof IResource) {
            IResource rsrc = (IResource) obj;
            IProject prj = rsrc.getProject();
            if (prj != null) {
              return GradleCore.create(prj);
            }
          }
        }
      }
      IEditorPart part = page.getActiveEditor();
      if (part != null) {
        IEditorInput input = part.getEditorInput();
        IResource rsrc = (IResource) input.getAdapter(IResource.class);
        if (rsrc != null) {
          IProject prj = rsrc.getProject();
          if (prj != null) {
            return GradleCore.create(prj);
          }
        }
      }
    }
    return null;
  }
Exemplo n.º 14
0
  @Override
  public void selectionChanged(IAction action, ISelection selection) {
    super.selectionChanged(action, selection);

    task = null;

    if (selection instanceof IStructuredSelection) {

      IStructuredSelection ss = (IStructuredSelection) selection;

      if (!ss.isEmpty()) {

        Iterator<?> iter = ss.iterator();
        while (iter.hasNext()) {
          Object sel = iter.next();
          if (sel instanceof IJiraTask) {
            task = ((IJiraTask) sel).getTask();
            try {
              taskData = TasksUiPlugin.getTaskDataManager().getTaskData(task);
            } catch (CoreException e) {
              handleError(
                  Messages.JiraConnectorUiActions_Cannot_get_task_data + task.getTaskKey(), e);
            }

            break;
          }
        }
      }
    }

    update(action);
  }
  /**
   * Handles selection of working sets and their configurations. Among potentially other actions,
   * this injects the working-set configuration selection into the project configurations controller
   * and updates the enablement of the buttons.
   */
  public void selectionChanged(SelectionChangedEvent event) {
    currentConfig = null;
    currentWorkingSet = null;

    if (event.getSelection() instanceof IStructuredSelection) {
      IStructuredSelection sel = (IStructuredSelection) event.getSelection();

      if (!sel.isEmpty()) {
        Object first = sel.getFirstElement();

        if (first instanceof IWorkingSetConfiguration) {
          currentConfig = (IWorkingSetConfiguration.ISnapshot) first;
          currentWorkingSet = currentConfig.getWorkingSet();
        } else if (first instanceof IWorkingSetProxy) {
          currentWorkingSet = (IWorkingSetProxy.ISnapshot) first;
        }
      }
    }

    if (projectsController != null) {
      // tell the project controller
      projectsController.setWorkingSetConfiguration(currentConfig);
    }

    updateButtons();
  }
 /**
  * Since these actions are re-created each time the run/debug as menu is filled, the enablement of
  * this action is static.
  */
 private void updateEnablement() {
   IWorkbenchWindow wb = DebugUIPlugin.getActiveWorkbenchWindow();
   boolean enabled = false;
   if (wb != null) {
     IWorkbenchPage page = wb.getActivePage();
     if (page != null) {
       ISelection selection = page.getSelection();
       if (selection instanceof IStructuredSelection) {
         IStructuredSelection structuredSelection = (IStructuredSelection) selection;
         try {
           // check enablement logic, if any
           Expression expression = fShortcut.getShortcutEnablementExpression();
           if (expression == null) {
             enabled = !structuredSelection.isEmpty();
           } else {
             List list = structuredSelection.toList();
             IEvaluationContext context = new EvaluationContext(null, list);
             context.addVariable("selection", list); // $NON-NLS-1$
             enabled = fShortcut.evalEnablementExpression(context, expression);
           }
         } catch (CoreException e) {
         }
       } else {
         IEditorPart editor = page.getActiveEditor();
         if (editor != null) {
           enabled = true;
         }
       }
     }
   }
   setEnabled(enabled);
 }
 /*
  * (non-Javadoc)
  *
  * @see org.talend.repository.ui.actions.ITreeContextualAction#init(org.eclipse.jface.viewers.TreeViewer,
  * org.eclipse.jface.viewers.IStructuredSelection)
  */
 @Override
 public void init(TreeViewer viewer, IStructuredSelection selection) {
   super.init(viewer, selection);
   boolean canWork = !selection.isEmpty() && selection.size() == 1;
   IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
   if (factory.isUserReadOnlyOnCurrentProject()) {
     canWork = false;
   }
   RepositoryNode node = (RepositoryNode) selection.getFirstElement();
   if (canWork) {
     if (node.getObjectType() != ERepositoryObjectType.ROUTINES
         || !ProjectManager.getInstance().isInCurrentMainProject(node)
         || !isLastVersion(node)) {
       canWork = false;
     } else {
       Item item = node.getObject().getProperty().getItem();
       if (item instanceof RoutineItem) {
         canWork = !((RoutineItem) item).isBuiltIn();
       }
     }
   }
   if (canWork) {
     canWork = (factory.getStatus(node.getObject()) != ERepositoryStatus.DELETED);
   }
   setEnabled(canWork);
 }
  protected IJavaElement getInitialJavaElement(IStructuredSelection selection) {
    IJavaElement jelem = null;
    if (selection != null && !selection.isEmpty()) {
      Object selectedElement = selection.getFirstElement();
      if (selectedElement instanceof IAdaptable) {
        IAdaptable adaptable = (IAdaptable) selectedElement;

        jelem = (IJavaElement) adaptable.getAdapter(IJavaElement.class);
        if (jelem == null || !jelem.exists()) {
          jelem = null;
          IResource resource = (IResource) adaptable.getAdapter(IResource.class);
          if (resource != null && resource.getType() != IResource.ROOT) {
            while (jelem == null && resource.getType() != IResource.PROJECT) {
              resource = resource.getParent();
              jelem = (IJavaElement) resource.getAdapter(IJavaElement.class);
            }
            if (jelem == null) {
              jelem = JavaCore.create(resource); // java project
            }
          }
        }
      }
    }

    return jelem;
  }
  protected void createNewFileFromTemplate(final TemplateElement template) {
    IStructuredSelection selection = getActiveSelection();
    if (!selection.isEmpty()) {
      Object element = selection.getFirstElement();
      if (element instanceof IAdaptable) {
        IFileStore fileStore = (IFileStore) ((IAdaptable) element).getAdapter(IFileStore.class);
        if (fileStore != null) {
          // this is a non-workspace selection
          String filetype = template.getFiletype();
          // strips the leading * before . if there is one
          int index = filetype.lastIndexOf('.');
          if (index > -1) {
            filetype = filetype.substring(index);
          }
          NewFileAction action = new NewFileAction("new_file" + filetype, template); // $NON-NLS-1$
          action.updateSelection(selection);
          action.run();
          return;
        }
      }
    }

    NewTemplateFileWizard wizard = new NewTemplateFileWizard(template);
    wizard.init(PlatformUI.getWorkbench(), selection);
    WizardDialog dialog = new WizardDialog(UIUtils.getActiveShell(), wizard);
    dialog.open();
  }
  private void init(IStructuredSelection selection) {
    project = null;

    Object selected = (selection.isEmpty() ? project : selection.getFirstElement());

    if (selected instanceof IArchiveNode) {
      IArchiveNode node = (IArchiveNode) selected;
      if (node.getNodeType() == IArchiveNode.TYPE_ARCHIVE
          || node.getNodeType() == IArchiveNode.TYPE_ARCHIVE_FOLDER) {
        initialDestinationNode = (IArchiveNode) selected;
      }
      project = ResourcesPlugin.getWorkspace().getRoot().getProject(node.getProjectName());
    } else if (selected instanceof IContainer) {
      project = ((IContainer) selected).getProject();
      initialDestinationPath = ((IContainer) selected).getFullPath().toString();
      isPathWorkspaceRelative = true;
    } else if (selected instanceof WrappedProject) {
      project = ((WrappedProject) selected).getElement();
      initialDestinationPath = project.getFullPath().toString();
      isPathWorkspaceRelative = true;
    } else {
      project = ProjectArchivesCommonView.getInstance().getCurrentProject();
      if (project != null) {
        initialDestinationPath = project.getFullPath().toString();
        isPathWorkspaceRelative = true;
      }
    }
  }
Exemplo n.º 21
0
  /**
   * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench,
   *     org.eclipse.jface.viewers.IStructuredSelection)
   * @since 4.0
   */
  @Override
  public void init(final IWorkbench workbench, final IStructuredSelection originalSelection) {

    IStructuredSelection selection = originalSelection;
    openProjectExists = ModelerUiViewUtils.workspaceHasOpenModelProjects();
    if (!openProjectExists) {
      newProject = ModelerUiViewUtils.queryUserToCreateModelProject();

      if (newProject != null) {
        selection = new StructuredSelection(newProject);
        openProjectExists = true;
      } else {
        openProjectExists = false;
      }
    }

    if (isAllModelsSelected(selection)) {
      initialSelection = new StructuredSelection(selection.toArray());
    }
    if (selection != null && !selection.isEmpty()) {
      this.folder = ModelUtil.getContainer(selection.getFirstElement());
    }

    if (folder != null && !folderInModelProject()) {
      // Create empty page
      this.mainPage =
          new WizardPage(NewVdbWizard.class.getSimpleName(), PAGE_TITLE, null) {
            @Override
            public void createControl(final Composite parent) {
              setControl(createEmptyPageControl(parent));
            }
          };
      this.mainPage.setMessage(NOT_MODEL_PROJECT_MSG, IMessageProvider.ERROR);
    } else {

      // Create and add page
      this.mainPage =
          new WizardPage(NewVdbWizard.class.getSimpleName(), PAGE_TITLE, null) {
            @Override
            public void createControl(final Composite parent) {
              setControl(createPageControl(parent));
            }
          };
      this.mainPage.setMessage(INITIAL_MESSAGE);

      // If current selection not null, set folder to selection if a folder, or to containing folder
      // if not
      if (this.folder != null) {
        if (!projectValidator.validate(new Object[] {this.folder}).isOK()) {
          this.folder = null;
        }
      } else { // folder == null
        this.mainPage.setMessage(SELECT_FOLDER_MESSAGE, IMessageProvider.ERROR);
      }
    }

    this.mainPage.setPageComplete(false);
    addPage(mainPage);
  }
 public void setSelection(IStructuredSelection selection) {
   if (selection != null && !selection.isEmpty()) {
     Object selected = selection.getFirstElement();
     if (selected instanceof RichObject) {
       setSelectedObject((RichObject) selected);
     }
   }
 }
Exemplo n.º 23
0
 private CustomizeData getCustTableSelection() {
   IStructuredSelection selection = (IStructuredSelection) custTable.getViewer().getSelection();
   if (selection.isEmpty()) {
     return null;
   }
   Iterator<?> i = selection.iterator();
   return (CustomizeData) i.next();
 }
Exemplo n.º 24
0
  private void handleSelectionChanged(IStructuredSelection selection) {
    if (selection != null && !selection.isEmpty()) {
      selectedFile = findFile(selection);
    } else {
      selectedFile = null;
    }

    setEnabled(isValidSelectedFile());
  }
 public void run() {
   IStructuredSelection selection = getStructuredSelection();
   if (selection.isEmpty()) return;
   Object obj = selection.getFirstElement();
   if (accept(obj)) {
     perform(obj);
   }
   selectionChanged(selection);
 }
Exemplo n.º 26
0
    private SimpleProperty getSelectedProperty() {
      IStructuredSelection selection = (IStructuredSelection) propertiesViewer.getSelection();

      if (selection.isEmpty()) {
        return null;
      }

      return (SimpleProperty) selection.getFirstElement();
    }
  /**
   * The framework calls this to create the contents of the wizard.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @generated
   */
  @Override
  public void addPages() {
    // Create a page, set the title, and the initial model file name.
    //
    newFileCreationPage = new RecordModelWizardNewFileCreationPage("Whatever", selection);
    newFileCreationPage.setTitle(
        Cwm_mipEditorPlugin.INSTANCE.getString("_UI_RecordModelWizard_label"));
    newFileCreationPage.setDescription(
        Cwm_mipEditorPlugin.INSTANCE.getString("_UI_RecordModelWizard_description"));
    newFileCreationPage.setFileName(
        Cwm_mipEditorPlugin.INSTANCE.getString("_UI_RecordEditorFilenameDefaultBase")
            + "."
            + Cwm_mipEditorPlugin.INSTANCE.getString("_UI_RecordEditorFilenameExtension"));
    addPage(newFileCreationPage);

    // Try and get the resource selection to determine a current directory for the file dialog.
    //
    if (selection != null && !selection.isEmpty()) {
      // Get the resource...
      //
      Object selectedElement = selection.iterator().next();
      if (selectedElement instanceof IResource) {
        // Get the resource parent, if its a file.
        //
        IResource selectedResource = (IResource) selectedElement;
        if (selectedResource.getType() == IResource.FILE) {
          selectedResource = selectedResource.getParent();
        }

        // This gives us a directory...
        //
        if (selectedResource instanceof IFolder || selectedResource instanceof IProject) {
          // Set this for the container.
          //
          newFileCreationPage.setContainerFullPath(selectedResource.getFullPath());

          // Make up a unique new name here.
          //
          String defaultModelBaseFilename =
              Cwm_mipEditorPlugin.INSTANCE.getString("_UI_RecordEditorFilenameDefaultBase");
          String defaultModelFilenameExtension =
              Cwm_mipEditorPlugin.INSTANCE.getString("_UI_RecordEditorFilenameExtension");
          String modelFilename = defaultModelBaseFilename + "." + defaultModelFilenameExtension;
          for (int i = 1; ((IContainer) selectedResource).findMember(modelFilename) != null; ++i) {
            modelFilename = defaultModelBaseFilename + i + "." + defaultModelFilenameExtension;
          }
          newFileCreationPage.setFileName(modelFilename);
        }
      }
    }
    initialObjectCreationPage = new RecordModelWizardInitialObjectCreationPage("Whatever2");
    initialObjectCreationPage.setTitle(
        Cwm_mipEditorPlugin.INSTANCE.getString("_UI_RecordModelWizard_label"));
    initialObjectCreationPage.setDescription(
        Cwm_mipEditorPlugin.INSTANCE.getString("_UI_Wizard_initial_object_description"));
    addPage(initialObjectCreationPage);
  }
Exemplo n.º 28
0
 /** @see org.eclipse.jface.action.Action#isEnabled() */
 public boolean isEnabled() {
   IStructuredSelection selection = (IStructuredSelection) provider.getSelection();
   if (!selection.isEmpty()) {
     IServer server = (IServer) selection.getFirstElement();
     IStatus canStart = server.canStart(mode);
     return canStart.isOK();
   }
   return false;
 }
  /**
   * Utility method to inspect a selection to find a Java element.
   *
   * @param selection the selection to be inspected
   * @return a Java element to be used as the initial selection, or <code>null</code>, if no Java
   *     element exists in the given selection
   */
  protected IJavaElement getInitialJavaElement(IStructuredSelection selection) {
    IJavaElement jelem = null;
    if (selection != null && !selection.isEmpty()) {
      Object selectedElement = selection.getFirstElement();
      if (selectedElement instanceof IAdaptable) {
        IAdaptable adaptable = (IAdaptable) selectedElement;

        jelem = adaptable.getAdapter(IJavaElement.class);
        if (jelem == null || !jelem.exists()) {
          jelem = null;
          IResource resource = adaptable.getAdapter(IResource.class);
          if (resource != null && resource.getType() != IResource.ROOT) {
            while (jelem == null && resource.getType() != IResource.PROJECT) {
              resource = resource.getParent();
              jelem = resource.getAdapter(IJavaElement.class);
            }
            if (jelem == null) {
              jelem = JavaCore.create(resource); // java project
            }
          }
        }
      }
    }
    if (jelem == null) {
      IWorkbenchPart part = JavaPlugin.getActivePage().getActivePart();
      if (part instanceof ContentOutline) {
        part = JavaPlugin.getActivePage().getActiveEditor();
      }

      if (part instanceof IViewPartInputProvider) {
        Object elem = ((IViewPartInputProvider) part).getViewPartInput();
        if (elem instanceof IJavaElement) {
          jelem = (IJavaElement) elem;
        }
      }
    }

    if (jelem == null || jelem.getElementType() == IJavaElement.JAVA_MODEL) {
      try {
        IJavaProject[] projects = JavaCore.create(getWorkspaceRoot()).getJavaProjects();
        if (projects.length == 1) {
          IClasspathEntry[] rawClasspath = projects[0].getRawClasspath();
          for (int i = 0; i < rawClasspath.length; i++) {
            if (rawClasspath[i].getEntryKind()
                == IClasspathEntry.CPE_SOURCE) { // add only if the project contains a source folder
              jelem = projects[0];
              break;
            }
          }
        }
      } catch (JavaModelException e) {
        JavaPlugin.log(e);
      }
    }
    return jelem;
  }
Exemplo n.º 30
0
  public Object execute(ExecutionEvent event) throws ExecutionException {
    final Shell activeShell = HandlerUtil.getActiveShell(event);
    ISelection currentSelection = HandlerUtil.getCurrentSelection(event);

    if (currentSelection instanceof IStructuredSelection) {
      IStructuredSelection selection = (IStructuredSelection) currentSelection;
      if (selection.isEmpty()) {
        return null;
      }

      Iterator<?> selectionIterator = selection.iterator();
      while (selectionIterator.hasNext()) {
        Object selectedElement = selectionIterator.next();
        IFile file = (IFile) Platform.getAdapterManager().getAdapter(selectedElement, IFile.class);
        if (file != null && "psf".equals(file.getLocation().getFileExtension())) { // $NON-NLS-1$
          final String fileName = file.getLocation().toString();

          Job job =
              new Job(String.format("Import %s", file.getName())) {

                @Override
                protected IStatus run(IProgressMonitor monitor) {
                  AbstractOperation operation =
                      new ImportProjectSetOperation(getName(), fileName, activeShell);

                  try {
                    final IStatus result =
                        OperationHistoryFactory.getOperationHistory()
                            .execute(operation, monitor, null);

                    if (monitor.isCanceled() || result.getSeverity() == IStatus.CANCEL) {
                      // TODO: Abort or Undo
                    }

                    return result;
                  } catch (ExecutionException ex) {
                    Activator.log.error(ex);
                    return new Status(
                        IStatus.ERROR,
                        Activator.PLUGIN_ID,
                        String.format("An error occurred when importing the PSF %s", fileName),
                        ex);
                  }
                }
              };

          job.setUser(true);
          job.schedule();

          job.setPriority(Job.LONG);
        }
      }
    }

    return null;
  }