Search in sources :

Example 66 with RepositoryException

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

the class JSPortal method newLabel.

/**
 * Creates a new label on the form, with the given text, place, size and an JSMethod as the onClick action.
 *
 * @sample
 * var clickMethod = form.newMethod('function clickMe() { application.output("I was clicked!"); }');
 * var childrenPortal = form.newPortal('pp', 'parent_to_my_table', 10, 10, 1180, 780);
 * var calLabel = childrenPortal.newLabel('Date', 120, 60, 20);
 * // This will result in a button being actually created, because we specify an action.
 * var textLabel = childrenPortal.newLabel('Text', 180, 60, 20, clickMethod);
 *
 * @param text The text that will be displayed in the label.
 *
 * @param x The x coordinate of the label. If the portal does not have the "multiLine" property set, then the x coordinates are used only for determining the order of the columns in the grid. If the portal has the "multiLine" property set, then the components are actually displayed at the specified coordinates.
 *
 * @param width The width of the label.
 *
 * @param height The height of the label. In a portal the height of all components is set to the height of the first component, unless the "multiLine" property is set.
 *
 * @param action The JSMethod object that should be executed when the label is clicked.
 *
 * @return A JSLabel instance that represents the newly created label.
 */
@JSFunction
public JSLabel newLabel(String text, int x, int width, int height, Object action) {
    try {
        GraphicalComponent gc = getBaseComponent(true).createNewGraphicalComponent(new Point(getX() + x, getY()));
        gc.setSize(new Dimension(width, height));
        gc.setText(text);
        if (action instanceof JSMethod) {
            JSLabel label = new JSLabel(this, gc, application, true);
            label.setOnAction((JSMethod) action);
            return label;
        } else {
            int id = JSForm.getMethodId(action, gc, application);
            if (id != -1)
                gc.setOnActionMethodID(id);
            return new JSLabel(this, gc, application, true);
        }
    } catch (RepositoryException e) {
        throw new RuntimeException(e);
    }
}
Also used : GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) RepositoryException(com.servoy.j2db.persistence.RepositoryException) Point(java.awt.Point) Dimension(java.awt.Dimension) Point(java.awt.Point) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 67 with RepositoryException

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

the class JSRelation method newRelationItem.

/**
 * Creates a new relation item for this relation. The primary dataprovider, the foreign data provider
 * and one relation operators (like '=' '!=' '>' '<') must be provided.
 *
 * @sample
 * var relation = solutionModel.newRelation('parentToChild', 'db:/example_data/parent_table', 'db:/example_data/child_table', JSRelation.INNER_JOIN);
 * relation.newRelationItem('another_parent_table_id', '=', 'another_child_table_parent_id');
 * // for literals use a prefix
 * relation.newRelationItem(JSRelationItem.LITERAL_PREFIX + "'hello'",'=', 'mytextfield');
 *
 * @param dataprovider The name of the primary dataprovider.
 *
 * @param operator The operator used to relate the primary and the foreign dataproviders.
 *
 * @param foreinColumnName The name of the foreign dataprovider.
 *
 * @return A JSRelationItem instance representing the newly added relation item.
 */
@JSFunction
public JSRelationItem newRelationItem(String dataprovider, String operator, String foreinColumnName) {
    if (dataprovider == null) {
        // $NON-NLS-1$
        throw new IllegalArgumentException("dataprovider cannot be null");
    }
    if (foreinColumnName == null) {
        // $NON-NLS-1$
        throw new IllegalArgumentException("foreinColumnName cannot be null");
    }
    int validOperator = RelationItem.getValidOperator(operator, RelationItem.RELATION_OPERATORS, null);
    if (validOperator == -1) {
        // $NON-NLS-1$//$NON-NLS-2$
        throw new IllegalArgumentException("operator " + operator + " is not a valid relation operator");
    }
    checkModification();
    try {
        IDataProvider primaryDataProvider = null;
        if (ScopesUtils.isVariableScope(dataprovider)) {
            primaryDataProvider = application.getFlattenedSolution().getGlobalDataProvider(dataprovider);
        } else if (dataprovider.startsWith(LiteralDataprovider.LITERAL_PREFIX)) {
            primaryDataProvider = new LiteralDataprovider(dataprovider);
            if (((LiteralDataprovider) primaryDataProvider).getValue() == null) {
                // $NON-NLS-1$
                throw new IllegalArgumentException("primary data provider " + dataprovider + " is not a valid relation primary data provider");
            }
        } else {
            primaryDataProvider = application.getFlattenedSolution().getDataProviderForTable((Table) application.getFoundSetManager().getTable(relation.getPrimaryDataSource()), dataprovider);
        }
        if (primaryDataProvider == null) {
            // $NON-NLS-1$
            throw new IllegalArgumentException("cant create relation item primary dataprovider not found: " + dataprovider);
        }
        IDataProvider dp = application.getFlattenedSolution().getDataProviderForTable((Table) application.getFoundSetManager().getTable(relation.getForeignDataSource()), foreinColumnName);
        if (!(dp instanceof Column)) {
            // $NON-NLS-1$ //$NON-NLS-2$
            throw new IllegalArgumentException("Foreign columnname " + foreinColumnName + " is not a valid column");
        }
        RelationItem result = relation.createNewRelationItem(application.getFoundSetManager(), primaryDataProvider, validOperator, (Column) dp);
        if (result != null)
            return new JSRelationItem(result, this, isCopy);
        return null;
    } catch (RepositoryException e) {
        throw new RuntimeException(e);
    }
}
Also used : RelationItem(com.servoy.j2db.persistence.RelationItem) Column(com.servoy.j2db.persistence.Column) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IDataProvider(com.servoy.j2db.persistence.IDataProvider) LiteralDataprovider(com.servoy.j2db.persistence.LiteralDataprovider) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 68 with RepositoryException

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

the class JSSolutionModel method newMedia.

/**
 * Creates a new media object that can be assigned to a label or a button.
 *
 * @sample
 * var myMedia = solutionModel.newMedia('button01.gif',bytes)
 * //now set the imageMedia property of your label or button
 * //myButton.imageMedia = myMedia
 * // OR
 * //myLabel.imageMedia = myMedia
 *
 * @param name The name of the new media
 *
 * @param bytes The content
 *
 * @return a JSMedia object
 */
@JSFunction
public JSMedia newMedia(String name, byte[] bytes) {
    FlattenedSolution fs = application.getFlattenedSolution();
    try {
        Media media = fs.getSolutionCopy().createNewMedia(new ScriptNameValidator(fs), name);
        media.setPermMediaData(bytes);
        media.setMimeType(MimeTypes.getContentType(bytes));
        return new JSMedia(media, application.getFlattenedSolution(), true);
    } catch (RepositoryException e) {
        throw new RuntimeException("error createing new media with name " + name, e);
    }
}
Also used : Media(com.servoy.j2db.persistence.Media) FlattenedSolution(com.servoy.j2db.FlattenedSolution) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ScriptNameValidator(com.servoy.j2db.persistence.ScriptNameValidator) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 69 with RepositoryException

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

the class JSTabPanel method newTab.

/**
 * Adds a new tab with the text label and JSForm and JSRelation (can be null for unrelated).
 *
 * @sample
 * // Create a parent form.
 * var form = solutionModel.newForm('parentForm', 'db:/example_data/parent_table', null, false, 640, 480);
 * // Create a first child form.
 * var childOne = solutionModel.newForm('childOne', 'db:/example_data/child_table', null, false, 400, 300);
 * childOne.newField('child_table_text', JSField.TEXT_FIELD, 10, 10, 100, 20);
 * // Create a relation to link the parent form to the first child form.
 * var parentToChild = solutionModel.newRelation('parentToChild','db:/example_data/parent_table','db:/example_data/child_table',JSRelation.INNER_JOIN);
 * parentToChild.newRelationItem('parent_table_id','=','child_table_parent_id');
 * // Create a second child form.
 * var childTwo = solutionModel.newForm('childTwo', 'db:/example_data/my_table', null, false, 400, 300);
 * childTwo.newField('my_table_image', JSField.IMAGE_MEDIA, 10, 10, 100, 100);
 * // Create a tab panel and add two tabs to it, with the two child forms.
 * var tabPanel = form.newTabPanel('tabs', 10, 10, 620, 460);
 * tabPanel.newTab('tab1', 'Child Two', childOne, parentToChild); // The first form uses the relation.
 * tabPanel.newTab('tab2', 'Child Two', childTwo);
 *
 * @param name The name of the new tab.
 *
 * @param text The text to be displayed on the new tab.
 *
 * @param form The JSForm instance that should be displayed in the new tab.
 *
 * @param relation A JSRelation object that relates the parent form with the form
 *                          that will be displayed in the new tab.
 *
 * @return A JSTab instance representing the newly created and added tab.
 */
@JSFunction
public JSTab newTab(String name, String text, IBaseSMForm form, Object relation) {
    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();
    }
    try {
        if (relationName != null && application.getFlattenedSolution().getRelationSequence(relationName) == null) {
            // invalid relation
            return null;
        }
        Tab newTab = getBaseComponent(true).createNewTab(text, relationName, ((JSForm) form).getSupportChild());
        newTab.setName(name);
        return new JSTab(this, newTab, application, true);
    } catch (RepositoryException e) {
        throw new RuntimeException(e);
    }
}
Also used : Tab(com.servoy.j2db.persistence.Tab) RelatedFoundSet(com.servoy.j2db.dataprocessing.RelatedFoundSet) RepositoryException(com.servoy.j2db.persistence.RepositoryException) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 70 with RepositoryException

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

the class JSForm method newMethod.

/**
 * Creates a new form JSMethod - based on the specified code.
 *
 * @sample
 * var form = solutionModel.newForm('newForm1', myDatasource, null, true, 800, 600);
 * var method = form.newMethod('function aMethod(event){application.output("Hello world!");}');
 * var button = myListViewForm.newButton('Show message!',50,50,100,30,method);
 * forms['newForm1'].controller.show();
 *
 * @param code the specified code for the new method
 *
 * @return a new JSMethod object for this form
 */
@JSFunction
public JSMethod newMethod(String code) {
    checkModification();
    String name = JSMethod.parseName(code);
    try {
        ScriptMethod method = getForm().createNewScriptMethod(new ScriptNameValidator(application.getFlattenedSolution()), name);
        method.setDeclaration(code);
        // addMethodToScopes(method);
        refreshFromScopes();
        return new JSMethod(this, method, application, true);
    } catch (RepositoryException e) {
        throw new RuntimeException(e);
    }
}
Also used : RepositoryException(com.servoy.j2db.persistence.RepositoryException) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) ScriptNameValidator(com.servoy.j2db.persistence.ScriptNameValidator) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Aggregations

RepositoryException (com.servoy.j2db.persistence.RepositoryException)116 RemoteException (java.rmi.RemoteException)45 QuerySelect (com.servoy.j2db.query.QuerySelect)25 ITable (com.servoy.j2db.persistence.ITable)22 JSFunction (org.mozilla.javascript.annotations.JSFunction)22 ServoyException (com.servoy.j2db.util.ServoyException)21 Column (com.servoy.j2db.persistence.Column)19 ArrayList (java.util.ArrayList)19 BaseQueryTable (com.servoy.base.query.BaseQueryTable)16 Table (com.servoy.j2db.persistence.Table)16 QueryTable (com.servoy.j2db.query.QueryTable)16 FlattenedSolution (com.servoy.j2db.FlattenedSolution)14 Point (java.awt.Point)14 IDataProvider (com.servoy.j2db.persistence.IDataProvider)13 QueryColumn (com.servoy.j2db.query.QueryColumn)13 IColumn (com.servoy.j2db.persistence.IColumn)12 ApplicationException (com.servoy.j2db.ApplicationException)11 ScriptNameValidator (com.servoy.j2db.persistence.ScriptNameValidator)10 SafeArrayList (com.servoy.j2db.util.SafeArrayList)10 FoundSetManager (com.servoy.j2db.dataprocessing.FoundSetManager)8