Search in sources :

Example 11 with IDesktop

use of org.eclipse.scout.rt.client.ui.desktop.IDesktop in project scout.rt by eclipse.

the class AbstractPage method execDataChanged.

/**
 * Called by the data change listener registered with this page (and the current desktop) through
 * {@link #registerDataChangeListener(Object...)}. Use this callback method to react to data change events by
 * reloading current data, or throwing away cached data etc.
 * <p>
 * Subclasses can override this method.<br/>
 * This default implementation does the following:
 * <ol>
 * <li>if this page is an ancestor of the selected page (or is selected itself) and this page is in the active
 * outline, a full re-load of the page is performed
 * <li>else the children of this page are marked dirty and the page itself is unloaded
 * </ol>
 *
 * @see IDesktop#dataChanged(Object...)
 */
@ConfigOperation
@Order(55)
protected void execDataChanged(Object... dataTypes) {
    if (getTree() == null) {
        return;
    }
    // 
    HashSet<ITreeNode> pathsToSelections = new HashSet<ITreeNode>();
    for (ITreeNode node : getTree().getSelectedNodes()) {
        ITreeNode tmp = node;
        while (tmp != null) {
            pathsToSelections.add(tmp);
            tmp = tmp.getParentNode();
        }
    }
    IDesktop desktop = ClientSessionProvider.currentSession().getDesktop();
    final boolean isActiveOutline = (desktop != null ? desktop.getOutline() == this.getOutline() : false);
    final boolean isRootNode = pathsToSelections.isEmpty() && getTree() != null && getTree().getRootNode() == this;
    if (isActiveOutline && (pathsToSelections.contains(this) || isRootNode)) {
        try {
            // TODO [7.0] fko: maybe remove when bookmarks can be done on outline level? (currently only pages)
            if (isRootNode) {
                this.reloadPage();
            } else /*
         * Ticket 77332 (deleting a node in the tree) also requires a reload So
         * the selected and its ancestor nodes require same processing
         */
            if (desktop != null) {
                // NOSONAR
                Bookmark bm = desktop.createBookmark();
                setChildrenDirty(true);
                // activate bookmark without activating the outline, since this would hide active tabs.
                desktop.activateBookmark(bm, false);
            }
        } catch (RuntimeException | PlatformError e) {
            BEANS.get(ExceptionHandler.class).handle(e);
        }
    } else {
        // not active outline OR not on selection path
        setChildrenDirty(true);
        if (isExpanded()) {
            setExpanded(false);
        }
        try {
            if (isChildrenLoaded()) {
                getTree().unloadNode(this);
            }
        } catch (RuntimeException | PlatformError e) {
            BEANS.get(ExceptionHandler.class).handle(e);
        }
    }
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) Bookmark(org.eclipse.scout.rt.shared.services.common.bookmark.Bookmark) PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) HashSet(java.util.HashSet) Order(org.eclipse.scout.rt.platform.Order) ConfigOperation(org.eclipse.scout.rt.platform.annotations.ConfigOperation)

Example 12 with IDesktop

use of org.eclipse.scout.rt.client.ui.desktop.IDesktop in project scout.rt by eclipse.

the class BookmarkToInvisibleOutlineTest method testBookmarkToInvisibleOutline.

@Test
public void testBookmarkToInvisibleOutline() throws Exception {
    IDesktop desktop = TestEnvironmentClientSession.get().getDesktop();
    desktop.setAvailableOutlines(CollectionUtility.arrayList(new CockpitOutline(), new AdminOutline()));
    desktop.setOutline(CockpitOutline.class);
    Bookmark bm = desktop.createBookmark();
    // 
    desktop.setOutline(AdminOutline.class);
    desktop.findOutline(CockpitOutline.class).setVisible(false);
    Thread.sleep(400);
    Exception err = null;
    try {
        desktop.activateBookmark(bm);
    } catch (Exception e) {
        err = e;
    }
    assertNotNull(err);
    assertEquals(desktop.findOutline(AdminOutline.class), desktop.getOutline());
}
Also used : Bookmark(org.eclipse.scout.rt.shared.services.common.bookmark.Bookmark) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) Test(org.junit.Test)

Example 13 with IDesktop

use of org.eclipse.scout.rt.client.ui.desktop.IDesktop in project scout.rt by eclipse.

the class AbstractPageWithNodesTest method testRenameChildPages.

@Test
public void testRenameChildPages() throws Exception {
    IDesktop desktop = TestEnvironmentClientSession.get().getDesktop();
    desktop.setAvailableOutlines(CollectionUtility.arrayList(new PageWithNodeOutline()));
    desktop.setOutline(PageWithNodeOutline.class);
    desktop.activateFirstPage();
    AbstractPageWithNodes parentPage = (AbstractPageWithNodes) desktop.getOutline().getActivePage();
    ITreeNode parentPageNode = desktop.getOutline().getSelectedNode();
    ITreeNode childPageNode = parentPageNode.getChildNode(0);
    assertEquals("Parent page", parentPageNode.getCell().getText());
    assertEquals("Child page", childPageNode.getCell().getText());
    // this is the childPages name in the table
    assertEquals("Child page", parentPage.getTable().getRow(0).getCell(0).getText());
    // update the child node's cell text
    childPageNode.getCellForUpdate().setText("my new long text");
    assertEquals("my new long text", childPageNode.getCell().getText());
    // text must also be changed in the parent's table
    assertEquals("my new long text", parentPage.getTable().getRow(0).getCell(0).getText());
    // rename again
    childPageNode.getCellForUpdate().setText("Child page");
    assertEquals("Parent page", parentPageNode.getCell().getText());
    assertEquals("Child page", childPageNode.getCell().getText());
    assertEquals("Child page", parentPage.getTable().getRow(0).getCell(0).getText());
    // rename on table, must be reflected to the tree
    parentPage.getTable().getRow(0).getCellForUpdate(0).setText("my new long text");
    assertEquals("my new long text", parentPage.getTable().getRow(0).getCell(0).getText());
    assertEquals("Parent page", parentPageNode.getCell().getText());
    assertEquals("my new long text", childPageNode.getCell().getText());
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) Test(org.junit.Test)

Example 14 with IDesktop

use of org.eclipse.scout.rt.client.ui.desktop.IDesktop in project scout.rt by eclipse.

the class AbstractPageWithTableTest method testModelContextOfInitPageAndInitTable.

@Test
public void testModelContextOfInitPageAndInitTable() {
    IForm mockForm = Mockito.mock(IForm.class);
    IOutline mockOutline = Mockito.mock(IOutline.class);
    ClientRunContexts.copyCurrent().withOutline(mockOutline, true).withForm(mockForm).run(new IRunnable() {

        @Override
        public void run() throws Exception {
            IDesktop desktop = TestEnvironmentClientSession.get().getDesktop();
            assertNotNull(desktop);
            desktop.setAvailableOutlines(CollectionUtility.arrayList(new PageWithTableOutline()));
            desktop.setOutline(PageWithTableOutline.class);
            desktop.activateFirstPage();
            IOutline outline = desktop.getOutline();
            assertNotNull(outline);
            assertSame(PageWithTableOutline.class, outline.getClass());
            IPage<?> page = outline.getActivePage();
            assertNotNull(page);
            assertSame(ParentItemTablePage.class, page.getClass());
            ParentItemTablePage tablePage = (ParentItemTablePage) page;
            // init page
            ModelContext initPageContext = tablePage.getInitPageContext();
            assertNotNull(initPageContext);
            assertSame(desktop, initPageContext.getDesktop());
            assertSame(outline, initPageContext.getOutline());
            // no context form must be set
            assertNull(initPageContext.getForm());
            // init table
            ModelContext initTableContext = tablePage.getInitTableContext();
            assertNotNull(initTableContext);
            assertSame(desktop, initTableContext.getDesktop());
            assertSame(outline, initTableContext.getOutline());
            // no context form must be set
            assertNull(initTableContext.getForm());
        }
    });
}
Also used : ModelContext(org.eclipse.scout.rt.client.ModelContextProxy.ModelContext) IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) IForm(org.eclipse.scout.rt.client.ui.form.IForm) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) Test(org.junit.Test)

Example 15 with IDesktop

use of org.eclipse.scout.rt.client.ui.desktop.IDesktop in project scout.rt by eclipse.

the class OutlineTreeContextMenuNestedPageWithTablesTest method testEmptySpaceAndRowMenus.

@Test
public void testEmptySpaceAndRowMenus() throws Exception {
    IDesktop desktop = TestEnvironmentClientSession.get().getDesktop();
    assertNotNull(desktop);
    desktop.setAvailableOutlines(Collections.singletonList(new PageWithTableOutline()));
    desktop.setOutline(PageWithTableOutline.class);
    desktop.activateFirstPage();
    IOutline outline = desktop.getOutline();
    assertNotNull(outline);
    assertSame(PageWithTableOutline.class, outline.getClass());
    IPage<?> page = outline.getActivePage();
    assertNotNull(page);
    assertSame(PageWithTable.class, page.getClass());
    assertRowMenusExistOnTablePageNode(outline);
}
Also used : IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) Test(org.junit.Test)

Aggregations

IDesktop (org.eclipse.scout.rt.client.ui.desktop.IDesktop)61 Test (org.junit.Test)36 IOutline (org.eclipse.scout.rt.client.ui.desktop.outline.IOutline)18 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)7 JsonAdapterRegistryTest (org.eclipse.scout.rt.ui.html.json.JsonAdapterRegistryTest)7 IOutlineViewButton (org.eclipse.scout.rt.client.ui.desktop.outline.IOutlineViewButton)5 JsonEvent (org.eclipse.scout.rt.ui.html.json.JsonEvent)5 JsonForm (org.eclipse.scout.rt.ui.html.json.form.JsonForm)5 JSONObject (org.json.JSONObject)5 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)4 IClientSession (org.eclipse.scout.rt.client.IClientSession)3 ITree (org.eclipse.scout.rt.client.ui.basic.tree.ITree)3 IForm (org.eclipse.scout.rt.client.ui.form.IForm)3 DesktopWithOneOutline (org.eclipse.scout.rt.ui.html.json.desktop.fixtures.DesktopWithOneOutline)3 OutlineViewButton (org.eclipse.scout.rt.ui.html.json.desktop.fixtures.OutlineViewButton)3 OutlineWithOneNode (org.eclipse.scout.rt.ui.html.json.desktop.fixtures.OutlineWithOneNode)3 FormWithOneField (org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 Locale (java.util.Locale)2