Package com.ponysdk.ui.terminal.instruction

Examples of com.ponysdk.ui.terminal.instruction.PTInstruction


                final JSONArray jsonArray = new JSONArray();
                for (final Widget w : getChildren()) {
                    final PTObject ptObject = uiService.getPTObject(w);
                    if (ptObject != null) {
                        final Double wSize = getWidgetSize(w);
                        final PTInstruction ws = new PTInstruction();
                        ws.setObjectID(ptObject.getObjectID());
                        ws.put(PROPERTY.SIZE, wSize);
                        jsonArray.set(i, ws);
                        i++;
                    }
                }
                if (i > 0) {
                    final PTInstruction eventInstruction = new PTInstruction();
                    eventInstruction.setObjectID(addInstruction.getObjectID());
                    eventInstruction.put(TYPE.KEY, TYPE.KEY_.EVENT);
                    eventInstruction.put(HANDLER.KEY, HANDLER.KEY_.RESIZE_HANDLER);
                    eventInstruction.put(PROPERTY.VALUE, jsonArray);
                    uiService.sendDataToServer(eventInstruction);
                }

                return false;
            }
View Full Code Here


                @Override
                public void onChange(final ChangeEvent event) {
                    final int selectedIndex = uiObject.getSelectedIndex();
                    if (selectedIndex == -1) {
                        final PTInstruction eventInstruction = new PTInstruction();
                        eventInstruction.setObjectID(addHandler.getObjectID());
                        eventInstruction.put(TYPE.KEY, TYPE.KEY_.EVENT);
                        eventInstruction.put(HANDLER.KEY, HANDLER.KEY_.CHANGE_HANDLER);
                        eventInstruction.put(PROPERTY.VALUE, "-1");
                        uiService.sendDataToServer(eventInstruction);
                    } else {
                        String selectedIndexes = selectedIndex + "";
                        for (int i = 0; i < uiObject.getItemCount(); i++) {
                            if (uiObject.isItemSelected(i)) {
                                if (i != selectedIndex) {
                                    selectedIndexes += "," + i;
                                }
                            }
                        }
                        final PTInstruction eventInstruction = new PTInstruction();
                        eventInstruction.setObjectID(addHandler.getObjectID());
                        eventInstruction.put(TYPE.KEY, TYPE.KEY_.EVENT);
                        eventInstruction.put(HANDLER.KEY, HANDLER.KEY_.CHANGE_HANDLER);
                        eventInstruction.put(PROPERTY.VALUE, selectedIndexes);
                        uiService.sendDataToServer(eventInstruction);
                    }
                }
            });
            return;
View Full Code Here

        if (HANDLER.KEY_.SELECTION_HANDLER.equals(handler)) {
            uiObject.addSelectionHandler(new SelectionHandler<Integer>() {

                @Override
                public void onSelection(final SelectionEvent<Integer> event) {
                    final PTInstruction eventInstruction = new PTInstruction();
                    eventInstruction.setObjectID(addHandler.getObjectID());
                    eventInstruction.put(TYPE.KEY, TYPE.KEY_.EVENT);
                    eventInstruction.put(HANDLER.KEY, HANDLER.KEY_.SELECTION_HANDLER);
                    eventInstruction.put(PROPERTY.INDEX, uiObject.getSelectedIndex());
                    uiService.sendDataToServer(eventInstruction);
                }
            });
        } else if (HANDLER.KEY_.BEFORE_SELECTION_HANDLER.equals(handler)) {
            uiObject.addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>() {

                @Override
                public void onBeforeSelection(final BeforeSelectionEvent<Integer> event) {
                    final PTInstruction eventInstruction = new PTInstruction();
                    eventInstruction.setObjectID(addHandler.getObjectID());
                    eventInstruction.put(TYPE.KEY, TYPE.KEY_.EVENT);
                    eventInstruction.put(HANDLER.KEY, HANDLER.KEY_.BEFORE_SELECTION_HANDLER);
                    eventInstruction.put(PROPERTY.INDEX, event.getItem());
                    uiService.sendDataToServer(eventInstruction);
                }
            });
        } else {
            super.addHandler(addHandler, uiService);
View Full Code Here

            final StackLayoutPanel stackLayoutPanel = uiObject;
            stackLayoutPanel.addSelectionHandler(new SelectionHandler<Integer>() {

                @Override
                public void onSelection(final SelectionEvent<Integer> event) {
                    final PTInstruction eventInstruction = new PTInstruction();
                    eventInstruction.setObjectID(addHandler.getObjectID());
                    eventInstruction.put(TYPE.KEY, TYPE.KEY_.EVENT);
                    eventInstruction.put(HANDLER.KEY, HANDLER.KEY_.SELECTION_HANDLER);
                    eventInstruction.put(PROPERTY.VALUE, event.getSelectedItem());
                    uiService.sendDataToServer(eventInstruction);
                }
            });
            return;
        }

        if (handlerType.equals(HANDLER.KEY_.BEFORE_SELECTION_HANDLER)) {
            uiObject.addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>() {

                @Override
                public void onBeforeSelection(final BeforeSelectionEvent<Integer> event) {
                    final PTInstruction eventInstruction = new PTInstruction();
                    eventInstruction.setObjectID(addHandler.getObjectID());
                    eventInstruction.put(TYPE.KEY, TYPE.KEY_.EVENT);
                    eventInstruction.put(HANDLER.KEY, HANDLER.KEY_.BEFORE_SELECTION_HANDLER);
                    eventInstruction.put(PROPERTY.VALUE, event.getItem());
                    uiService.sendDataToServer(eventInstruction);
                }
            });
            return;
        }
View Full Code Here

    public void create(final PTInstruction create, final UIService uiService) {
        if (!WebSocketClient.isSupported()) {

            UIBuilder.getRootEventBus().addHandler(CommunicationErrorEvent.TYPE, this);

            final PTInstruction eventInstruction = new PTInstruction();
            eventInstruction.setObjectID(create.getObjectID());
            eventInstruction.put(TYPE.KEY, TYPE.KEY_.EVENT);
            eventInstruction.put(PROPERTY.ERROR_MSG, "WebSocket not supported");
            uiService.sendDataToServer(eventInstruction);

            int delay = 1000;
            if (create.containsKey(PROPERTY.FIXDELAY)) delay = create.getInt(PROPERTY.FIXDELAY);

            Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {

                @Override
                public boolean execute() {
                    final PTInstruction eventInstruction = new PTInstruction();
                    eventInstruction.setObjectID(create.getObjectID());
                    eventInstruction.put(TYPE.KEY, TYPE.KEY_.EVENT);
                    eventInstruction.put(PROPERTY.POLL, true);
                    uiService.sendDataToServer(eventInstruction);
                    return !hasCommunicationError;
                }
            }, delay);
        } else {
View Full Code Here

            final Storage storage = Storage.getSessionStorageIfSupported();
            if (storage != null) {
                final String v = storage.getItem(APPLICATION.VIEW_ID);
                if (v != null && !v.isEmpty()) viewID = Long.parseLong(v);
            }
            final PTInstruction requestData = new PTInstruction();

            final JSONArray cookies = new JSONArray();

            // load all cookies at startup
            final Collection<String> cookieNames = Cookies.getCookieNames();
            if (cookieNames != null) {
                int i = 0;
                for (final String cookie : cookieNames) {
                    final JSONObject jsoObject = new JSONObject();
                    jsoObject.put(PROPERTY.KEY, new JSONString(cookie));
                    jsoObject.put(PROPERTY.VALUE, new JSONString(Cookies.getCookie(cookie)));
                    cookies.set(i++, jsoObject);
                }
            }

            requestData.put(APPLICATION.KEY, APPLICATION.KEY_.START);
            requestData.put(APPLICATION.SEQ_NUM, 0);
            requestData.put(HISTORY.TOKEN, History.getToken());
            requestData.put(PROPERTY.COOKIES, cookies);

            if (viewID != null) requestData.put(APPLICATION.VIEW_ID, viewID);

            final RequestCallback requestCallback = new RequestCallback() {

                @Override
                public void onDataReceived(final JSONObject data) {
                    try {
                        if (data.containsKey(APPLICATION.VIEW_ID)) {
                            applicationViewID = (long) data.get(APPLICATION.VIEW_ID).isNumber().doubleValue();

                            if (storage != null) storage.setItem(APPLICATION.VIEW_ID, Long.toString(applicationViewID));

                            uiBuilder.init(applicationViewID, requestBuilder);
                        }

                        uiBuilder.update(data);

                    } catch (final RuntimeException exception) {
                        log.log(Level.SEVERE, "Failed to process data with error #" + exception.getMessage() + ", data: " + data, exception);
                        Window.alert("Failed to process data with error #" + exception.getMessage() + ", data: " + data);
                    }
                }

                @Override
                public void onError(final Throwable exception) {
                    uiBuilder.onCommunicationError(exception);
                }

            };

            requestBuilder = newRequestBuilder(requestCallback);
            requestBuilder.send(requestData.toString());

        } catch (final Exception e) {
            log.log(Level.SEVERE, "Loading application has failed #" + e.getMessage(), e);
            Window.alert("Loading application has failed #" + e);
        }
View Full Code Here

        return new HttpRequestBuilder(requestCallback);
    }

    @Export
    public void sendDataToServer(final String objectID, final JavaScriptObject jsObject) {
        final PTInstruction instruction = new PTInstruction();
        instruction.setObjectID(Long.parseLong(objectID));
        instruction.put(TYPE.KEY, TYPE.KEY_.EVENT);
        instruction.put(PROPERTY.NATIVE, jsObject);
        uiBuilder.sendDataToServer(instruction);
    }
View Full Code Here

        if (HANDLER.KEY_.STRING_VALUE_CHANGE_HANDLER.equals(handler)) {
            uiObject.addValueChangeHandler(new ValueChangeHandler<String>() {

                @Override
                public void onValueChange(final ValueChangeEvent<String> event) {
                    final PTInstruction eventInstruction = new PTInstruction();

                    eventInstruction.setObjectID(addHandler.getObjectID());
                    eventInstruction.put(TYPE.KEY, TYPE.KEY_.EVENT);
                    eventInstruction.put(HANDLER.KEY, HANDLER.KEY_.STRING_VALUE_CHANGE_HANDLER);
                    eventInstruction.put(PROPERTY.VALUE, event.getValue());
                    uiService.sendDataToServer(eventInstruction);
                }
            });
        } else {
            super.addHandler(addHandler, uiService);
View Full Code Here

        lastReceived = receivedSeqNum;

        final List<PTInstruction> instructions = new ArrayList<PTInstruction>();
        final JSONArray jsonArray = data.get(APPLICATION.INSTRUCTIONS).isArray();
        for (int i = 0; i < jsonArray.size(); i++) {
            instructions.add(new PTInstruction(jsonArray.get(i).isObject().getJavaScriptObject()));
        }

        if (!incomingMessageQueue.isEmpty()) {
            long expected = receivedSeqNum + 1;
            while (incomingMessageQueue.containsKey(expected)) {
                final JSONObject jsonObject = incomingMessageQueue.remove(expected);
                final JSONArray jsonArray2 = jsonObject.get(APPLICATION.INSTRUCTIONS).isArray();
                for (int i = 0; i < jsonArray2.size(); i++) {
                    instructions.add(new PTInstruction(jsonArray2.get(i).isObject().getJavaScriptObject()));
                }
                lastReceived = expected;
                expected++;
            }
            log.log(Level.SEVERE, "Message synchronized from #" + receivedSeqNum + " to #" + lastReceived);
        }

        updateMode = true;
        PTInstruction currentInstruction = null;
        try {

            for (final PTInstruction instruction : instructions) {
                currentInstruction = instruction;
                try {
View Full Code Here

        stackedInstructions.clear();
    }

    private void sendDataToServer(final List<PTInstruction> instructions) {

        final PTInstruction requestData = new PTInstruction();
        requestData.put(APPLICATION.VIEW_ID, sessionID);

        final JSONArray jsonArray = new JSONArray();
        for (int i = 0; i < instructions.size(); i++) {
            jsonArray.set(i, instructions.get(i));
        }

        final JSONArray errors = new JSONArray();
        if (!stackedErrors.isEmpty()) {
            int i = 0;
            for (final JSONObject jsoObject : stackedErrors) {
                errors.set(i++, jsoObject);
            }
            stackedErrors.clear();
        }

        requestData.put(APPLICATION.INSTRUCTIONS, jsonArray);
        requestData.put(APPLICATION.ERRORS, errors);
        requestData.put(APPLICATION.SEQ_NUM, nextSent++);

        requestBuilder.send(requestData.toString());
    }
View Full Code Here

TOP

Related Classes of com.ponysdk.ui.terminal.instruction.PTInstruction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.