Ejemplo n.º 1
0
/**
 * Abstract implementation of {@link EditorPartPresenter} that is intended to be used by subclassing
 * instead of directly implementing an interface.
 *
 * @author Evgen Vidolob
 */
public abstract class AbstractEditorPresenter extends AbstractPartPresenter
    implements EditorPartPresenter {
  protected boolean dirtyState;
  protected EditorInput input;
  protected final Array<EditorPartCloseHandler> closeHandlers = Collections.createArray();

  /** {@inheritDoc} */
  @Override
  public void init(@Nonnull EditorInput input) throws EditorInitException {
    this.input = input;
    initializeEditor();
  }

  /** Initializes this editor. */
  protected abstract void initializeEditor();

  /**
   * Set dirty state and notify expressions
   *
   * @param dirty
   */
  protected void updateDirtyState(boolean dirty) {
    dirtyState = dirty;
    firePropertyChange(EditorPartPresenter.TITLE_PROPERTY);
    firePropertyChange(EditorPartPresenter.PROP_DIRTY);
  }

  /** {@inheritDoc} */
  @Override
  public boolean isDirty() {
    return dirtyState;
  }

  /** {@inheritDoc} */
  @Override
  public void addCloseHandler(@Nonnull EditorPartCloseHandler closeHandler) {
    if (!closeHandlers.contains(closeHandler)) {
      closeHandlers.add(closeHandler);
    }
  }

  /** {@inheritDoc} */
  @Override
  public EditorInput getEditorInput() {
    return input;
  }

  protected void handleClose() {
    for (int i = 0; i < closeHandlers.size(); i++) {
      EditorPartCloseHandler handler = closeHandlers.get(i);
      handler.onClose(this);
    }
  }

  /** {@inheritDoc} */
  @Override
  public void onFileChanged() {
    firePropertyChange(TITLE_PROPERTY);
  }
}
Ejemplo n.º 2
0
  @Test
  public void testGetChildrenWhenHiddenItemsAreNotShown() throws Exception {
    when(treeSettings.isShowHiddenItems()).thenReturn(false);

    String path = "path";
    AsyncCallback asyncCallback = mock(AsyncCallback.class);
    Array<ItemReference> children = Collections.createArray();

    ItemReference item = mock(ItemReference.class);
    when(item.getName()).thenReturn("item");
    ItemReference hiddenItem = mock(ItemReference.class);
    when(hiddenItem.getName()).thenReturn(".item");

    children.add(item);
    children.add(hiddenItem);

    projectNode.getChildren(path, asyncCallback);

    verify(projectServiceClient).getChildren(eq(path), asyncRequestCallbackCaptor.capture());
    AsyncRequestCallback<Array<ItemReference>> requestCallback =
        asyncRequestCallbackCaptor.getValue();
    GwtReflectionUtils.callOnSuccess(requestCallback, children);

    verify(asyncCallback).onSuccess(arrayCaptor.capture());

    Array<ItemReference> array = arrayCaptor.getValue();
    assertEquals(1, array.size());
    assertTrue(array.contains(item));
    assertFalse(array.contains(hiddenItem));
  }
Ejemplo n.º 3
0
  @Before
  public void setUp() {
    super.setUp();

    when(projectDescriptor.getPath()).thenReturn(ITEM_PATH);
    when(projectDescriptor.getName()).thenReturn(ITEM_NAME);
    when(projectDescriptor.getType()).thenReturn(PROJECT_TYPE_ID);

    Array<TreeNode<?>> children = Collections.createArray();
    when(parentProjectNode.getChildren()).thenReturn(children);
  }
Ejemplo n.º 4
0
  @Override
  public Array<Object> getChildren(Object data) {
    Array<Object> res = Collections.createArray();
    if (data instanceof RunnerEnvironmentTree) {
      RunnerEnvironmentTree environmentTree = (RunnerEnvironmentTree) data;
      for (RunnerEnvironmentTree runnerEnvironmentTree : environmentTree.getNodes()) {
        res.add(runnerEnvironmentTree);
      }

      for (RunnerEnvironmentLeaf leaf : environmentTree.getLeaves()) {
        RunnerEnvironment environment = leaf.getEnvironment();
        if (environment != null) {
          res.add(leaf);
        }
      }
    }
    res.sort(COMPARATOR);
    return res;
  }