Ejemplo n.º 1
0
  public void testSetEnabledWithoutDisabling() {
    Shell shell = new Shell();
    Composite composite = new Composite(shell, SWT.NONE);
    composite.setEnabled(false);

    CommonUiUtil.setEnabled(composite, true);
    assertFalse(composite.getEnabled());
    CommonUiUtil.setEnabled(composite, true);
    assertFalse(composite.getEnabled());
  }
Ejemplo n.º 2
0
  public void testSetEnabledStateDisableStateRemoved() {
    Shell shell = new Shell();
    Composite composite = new Composite(shell, SWT.NONE);
    Label label = new Label(composite, SWT.NONE);
    label.setEnabled(false);

    CommonUiUtil.setEnabled(composite, false);
    CommonUiUtil.setEnabled(composite, true);
    // the second call should have not changed anything
    CommonUiUtil.setEnabled(composite, true);
    assertTrue(composite.getEnabled());
    assertFalse(label.getEnabled());
  }
Ejemplo n.º 3
0
  public void testSetEnabledStateDisabledParent() {
    Shell shell = new Shell();
    Composite composite = new Composite(shell, SWT.NONE);
    composite.setEnabled(false);
    Label label = new Label(composite, SWT.NONE);

    CommonUiUtil.setEnabled(composite, false);
    assertFalse(composite.getEnabled());
    assertFalse(label.getEnabled());

    CommonUiUtil.setEnabled(composite, true);
    assertFalse(composite.getEnabled());
    assertTrue(label.getEnabled());
  }
Ejemplo n.º 4
0
  private void initialize() {
    editorBusyIndicator =
        new BusyAnimator(
            new IBusyClient() {
              public Image getImage() {
                return TaskEditor.this.getTitleImage();
              }

              public void setImage(Image image) {
                TaskEditor.this.setTitleImage(image);
              }
            });

    menuManager = new MenuManager();
    configureContextMenuManager(menuManager);
    Menu menu = menuManager.createContextMenu(getContainer());
    getContainer().setMenu(menu);

    // install context menu on form heading and title
    getHeaderForm().getForm().setMenu(menu);
    Composite head = getHeaderForm().getForm().getForm().getHead();
    if (head != null) {
      CommonUiUtil.setMenu(head, menu);
    }
  }
Ejemplo n.º 5
0
  @Override
  public void showBusy(boolean busy) {
    if (editorBusyIndicator != null) {
      if (busy) {
        if (TasksUiInternal.isAnimationsEnabled()) {
          editorBusyIndicator.start();
        }
      } else {
        editorBusyIndicator.stop();
      }
    }

    if (!isHeaderFormDisposed()) {
      Form form = getHeaderForm().getForm().getForm();
      if (form != null && !form.isDisposed()) {
        // TODO consider only disabling certain actions
        IToolBarManager toolBarManager = form.getToolBarManager();
        if (toolBarManager instanceof ToolBarManager) {
          ToolBar control = ((ToolBarManager) toolBarManager).getControl();
          if (control != null) {
            control.setEnabled(!busy);
          }
        }

        if (leftToolBar != null) {
          leftToolBar.setEnabled(!busy);
        }
        if (titleLabel != null) {
          titleLabel.setEnabled(!busy);
        }

        CommonUiUtil.setEnabled(form.getBody(), !busy);
        for (IFormPage page : getPages()) {
          if (page instanceof WorkbenchPart) {
            WorkbenchPart part = (WorkbenchPart) page;
            part.showBusy(busy);
          }
        }
      }
    }
  }
Ejemplo n.º 6
0
  private TaskData createTaskData(AbstractRepositoryConnector connector) {
    final AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler();
    if (taskDataHandler == null) {
      return null;
    }

    String repositoryUrl = selectedTask.getRepositoryUrl();
    TaskData parentTaskData = null;
    try {
      parentTaskData = TasksUi.getTaskDataManager().getTaskData(selectedTask);
    } catch (CoreException e) {
      StatusHandler.log(
          new Status(
              IStatus.ERROR,
              TasksUiPlugin.ID_PLUGIN,
              "Could not retrieve task data for task:" + selectedTask.getUrl(),
              e)); //$NON-NLS-1$
    }
    if (parentTaskData == null) {
      TasksUiInternal.displayStatus(
          Messages.NewSubTaskAction_Unable_to_create_subtask,
          new Status(
              IStatus.WARNING,
              TasksUiPlugin.ID_PLUGIN,
              Messages.NewSubTaskAction_Could_not_retrieve_task_data_for_task_
                  + selectedTask.getUrl()));
      return null;
    }

    final TaskRepository taskRepository =
        TasksUiPlugin.getRepositoryManager().getRepository(repositoryUrl);
    if (!taskDataHandler.canInitializeSubTaskData(taskRepository, selectedTask)) {
      return null;
    }

    final TaskData selectedTaskData = parentTaskData;
    final TaskAttributeMapper attributeMapper = taskDataHandler.getAttributeMapper(taskRepository);
    final TaskData taskData =
        new TaskData(
            attributeMapper,
            taskRepository.getConnectorKind(),
            taskRepository.getRepositoryUrl(),
            ""); //$NON-NLS-1$
    final boolean[] result = new boolean[1];
    IProgressService service = PlatformUI.getWorkbench().getProgressService();
    try {
      CommonUiUtil.run(
          service,
          new ICoreRunnable() {
            public void run(IProgressMonitor monitor) throws CoreException {
              result[0] =
                  taskDataHandler.initializeSubTaskData(
                      taskRepository, taskData, selectedTaskData, monitor);
            }
          });
    } catch (CoreException e) {
      TasksUiInternal.displayStatus(
          Messages.NewSubTaskAction_Unable_to_create_subtask, e.getStatus());
      return null;
    } catch (OperationCanceledException e) {
      // canceled
      return null;
    }

    if (result[0]) {
      // open editor
      return taskData;
    } else {
      TasksUiInternal.displayStatus(
          Messages.NewSubTaskAction_Unable_to_create_subtask,
          new Status(
              IStatus.INFO,
              TasksUiPlugin.ID_PLUGIN,
              Messages
                  .NewSubTaskAction_The_connector_does_not_support_creating_subtasks_for_this_task));
    }
    return null;
  }