Search in sources :

Example 11 with Portal

use of com.servoy.j2db.persistence.Portal in project servoy-client by Servoy.

the class JSForm method getPortals.

/**
 * Returns all JSPortal objects of this form (optionally also the ones from the parent form), including the ones without a name.
 *
 * @sample
 * var frm = solutionModel.getForm("myForm");
 * var portals = frm.getPortals();
 * for (var i in portals)
 * {
 * 	var p = portals[i];
 * 	if (p.name != null)
 * 		application.output(p.name);
 * 	else
 * 		application.output("unnamed portal detected");
 * }
 *
 * @param returnInheritedElements boolean true to also return the elements from parent form
 * @return an array of all JSPortal objects on this form
 */
@JSFunction
public JSPortal[] getPortals(boolean returnInheritedElements) {
    List<JSPortal> portals = new ArrayList<JSPortal>();
    AbstractContainer form2use = returnInheritedElements ? getFlattenedContainer() : getContainer();
    Iterator<Portal> iterator = form2use.getPortals();
    while (iterator.hasNext()) {
        portals.add(new JSPortal(this, iterator.next(), application, false));
    }
    return portals.toArray(new JSPortal[portals.size()]);
}
Also used : AbstractContainer(com.servoy.j2db.persistence.AbstractContainer) ArrayList(java.util.ArrayList) Portal(com.servoy.j2db.persistence.Portal) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 12 with Portal

use of com.servoy.j2db.persistence.Portal in project servoy-client by Servoy.

the class JSForm method newPortal.

/**
 * Creates a new JSPortal object on the form - including the name of the JSPortal object; the relation the JSPortal object is based on, the "x" and "y" position of the JSPortal object in pixels, as well as the width and height of the JSPortal object in pixels.
 *
 * @sample
 * var form = solutionModel.newForm('newForm1', 'db:/server1/table1', null, true, 800, 600);
 * var relation = solutionModel.newRelation('parentToChild','db:/server1/table1','db:/server2/table2',JSRelation.INNER_JOIN);
 * relation.newRelationItem('another_parent_table_id', '=', 'another_child_table_parent_id');
 * var portal = form.newPortal('portal',relation,200,200,300,300);
 * portal.newField('someColumn',JSField.TEXT_FIELD,200,200,120);
 * forms['newForm1'].controller.show();
 *
 * @param name the specified name of the JSPortal object
 * @param relation the relation of the JSPortal object
 * @param x the horizontal "x" position of the JSPortal object in pixels
 * @param y the vertical "y" position of the JSPortal object in pixels
 * @param width the width of the JSPortal object in pixels
 * @param height the height of the JSPortal object in pixels
 *
 * @return a JSPortal object
 */
@JSFunction
public JSPortal newPortal(String name, Object relation, int x, int y, int width, int height) {
    checkModification();
    try {
        Portal portal = getContainer().createNewPortal(IdentDocumentValidator.checkName(name), new Point(x, y));
        CSSPositionUtils.setSize(portal, width, height);
        String relationName = null;
        if (relation instanceof RelatedFoundSet) {
            relationName = ((RelatedFoundSet) relation).getRelationName();
        } else if (relation instanceof String) {
            relationName = (String) relation;
        } else if (relation instanceof JSRelation) {
            relationName = ((JSRelation) relation).getName();
        }
        portal.setRelationName(relationName);
        return new JSPortal(this, portal, application, true);
    } catch (RepositoryException e) {
        throw new RuntimeException(e);
    }
}
Also used : RelatedFoundSet(com.servoy.j2db.dataprocessing.RelatedFoundSet) Portal(com.servoy.j2db.persistence.Portal) RepositoryException(com.servoy.j2db.persistence.RepositoryException) Point(java.awt.Point) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 13 with Portal

use of com.servoy.j2db.persistence.Portal in project servoy-client by Servoy.

the class TableView method onDragOver.

public boolean onDragOver(JSDNDEvent event) {
    int onDragOverID = 0;
    if (cellview instanceof Portal) {
        Portal cellviewPortal = (Portal) cellview;
        onDragOverID = cellviewPortal.getOnDragOverMethodID();
    } else {
        onDragOverID = fc.getForm().getOnDragOverMethodID();
    }
    if (onDragOverID > 0) {
        // $NON-NLS-1$
        Object dragOverReturn = fc.executeFunction(Integer.toString(onDragOverID), new Object[] { event }, false, null, false, "onDragOverMethodID");
        if (dragOverReturn instanceof Boolean)
            return ((Boolean) dragOverReturn).booleanValue();
    }
    return getOnDropMethodID() > 0;
}
Also used : Portal(com.servoy.j2db.persistence.Portal) EventObject(java.util.EventObject) Point(java.awt.Point)

Example 14 with Portal

use of com.servoy.j2db.persistence.Portal in project servoy-client by Servoy.

the class TableView method initDragNDrop.

public void initDragNDrop(FormController formController, int clientDesignYOffset) {
    this.yOffset = clientDesignYOffset;
    boolean enableDragDrop = false;
    if (cellview instanceof Portal) {
        Portal cellviewPortal = (Portal) cellview;
        enableDragDrop = (cellviewPortal.getOnDragMethodID() > 0 || cellviewPortal.getOnDragEndMethodID() > 0 || cellviewPortal.getOnDragOverMethodID() > 0 || cellviewPortal.getOnDropMethodID() > 0);
    } else {
        Form form = fc.getForm();
        enableDragDrop = (form.getOnDragMethodID() > 0 || form.getOnDragEndMethodID() > 0 || form.getOnDragOverMethodID() > 0 || form.getOnDropMethodID() > 0);
    }
    if (enableDragDrop && !GraphicsEnvironment.isHeadless()) {
        setDragEnabled(true);
        setTransferHandler(FormDataTransferHandler.getInstance());
        new DropTarget(this, (DropTargetListener) FormDataTransferHandler.getInstance());
        addHierarchyListener(new HierarchyListener() {

            public void hierarchyChanged(HierarchyEvent e) {
                JComponent changedParent = (JComponent) e.getChangedParent();
                if (changedParent != null && e.getChanged() == TableView.this && (e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) == HierarchyEvent.PARENT_CHANGED) {
                    changedParent.setTransferHandler(FormDataTransferHandler.getInstance());
                    new DropTarget(changedParent, (DropTargetListener) FormDataTransferHandler.getInstance());
                    DragStartTester dragTester = new DragStartTester();
                    changedParent.addMouseListener(dragTester);
                    changedParent.addMouseMotionListener(dragTester);
                    TableView.this.removeHierarchyListener(this);
                }
            }
        });
    }
}
Also used : DropTargetListener(java.awt.dnd.DropTargetListener) Form(com.servoy.j2db.persistence.Form) HierarchyEvent(java.awt.event.HierarchyEvent) JComponent(javax.swing.JComponent) Portal(com.servoy.j2db.persistence.Portal) DropTarget(java.awt.dnd.DropTarget) HierarchyListener(java.awt.event.HierarchyListener)

Example 15 with Portal

use of com.servoy.j2db.persistence.Portal in project servoy-client by Servoy.

the class JSForm method removePortal.

/**
 * Removes a JSPortal that has the given name. Returns true if removal was successful, false otherwise.
 *
 * @sample
 * var form = solutionModel.newForm('newFormX',myDatasource,null,true,800,600);
 * var relation = solutionModel.newRelation('parentToChild','db:/server1/myTable','db:/server1/myOtherTable',JSRelation.INNER_JOIN);
 * relation.newRelationItem('parent_table_id', '=', 'child_table_id');
 * var jsportal = form.newPortal('jsp',relation,100,400,300,300);
 * jsportal.newField('child_table_id',JSField.TEXT_FIELD,200,200,120);
 * var jsmethod = form.newMethod("function removeMe(event) { var form = solutionModel.getForm('newFormX');\n if (form.removeComponent('jsp') == true) application.output('Portal removed ok'); else application.output('Portal could not be deleted'); forms['newFormX'].controller.recreateUI();}");
 * var removerButton = form.newButton('Click here to remove the portal',450,500,250,50,jsmethod);
 * removerButton.name = 'remover';
 * forms['newFormX'].controller.show();
 *
 * @param name the specified name of the JSPortal to be removed
 *
 * @return true if the JSPortal has successfully been removed; false otherwise
 */
@JSFunction
public boolean removePortal(String name) {
    if (name == null)
        return false;
    checkModification();
    Iterator<Portal> portals = getContainer().getPortals();
    while (portals.hasNext()) {
        Portal portal = portals.next();
        if (name.equals(portal.getName())) {
            getContainer().removeChild(portal);
            return true;
        }
    }
    return false;
}
Also used : Portal(com.servoy.j2db.persistence.Portal) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Aggregations

Portal (com.servoy.j2db.persistence.Portal)25 Point (java.awt.Point)13 RuntimePortal (com.servoy.j2db.ui.scripting.RuntimePortal)10 Form (com.servoy.j2db.persistence.Form)6 IPersist (com.servoy.j2db.persistence.IPersist)6 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)5 Field (com.servoy.j2db.persistence.Field)4 IFormElement (com.servoy.j2db.persistence.IFormElement)4 IForm (com.servoy.j2db.IForm)3 IServoyAwareBean (com.servoy.j2db.dataui.IServoyAwareBean)3 AbstractBase (com.servoy.j2db.persistence.AbstractBase)3 BaseComponent (com.servoy.j2db.persistence.BaseComponent)3 Bean (com.servoy.j2db.persistence.Bean)3 Part (com.servoy.j2db.persistence.Part)3 RepositoryException (com.servoy.j2db.persistence.RepositoryException)3 WebForm (com.servoy.j2db.server.headlessclient.WebForm)3 IComponent (com.servoy.j2db.ui.IComponent)3 ISupportAnchors (com.servoy.j2db.persistence.ISupportAnchors)2 ISupportName (com.servoy.j2db.persistence.ISupportName)2 TabPanel (com.servoy.j2db.persistence.TabPanel)2