| /** |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| */ |
| package org.eclipse.osbp.preferences.ui.page; |
| |
| import org.eclipse.jface.preference.FieldEditor; |
| |
| import org.eclipse.osbp.preferences.*; |
| import org.eclipse.osbp.preferences.ui.component.APreferencePage; |
| import org.eclipse.osbp.preferences.ui.component.Item; |
| import org.eclipse.osbp.preferences.ui.component.Type; |
| import org.eclipse.osbp.preferences.ui.utils.CheckStateServerName; |
| import org.eclipse.osbp.webserver.messagequeue.CXMqConnection; |
| |
| public class PreferencePageServiceCommunication extends APreferencePage { |
| |
| public PreferencePageServiceCommunication() { |
| super( |
| "serviceCommunication", |
| "service communications" |
| ); |
| } |
| |
| @Override |
| protected Item[] initializeItems() { |
| return new Item[] { |
| new Item(Type.TEXT, Preference.SHOW_PRODUCT_CONFIGURATION, "Product Configuration", false), |
| new Item(""), |
| new Item("Service Communication Server ActiveMQ Broker"), |
| new Item(Type.TEXT, Preference.ACTIVEMQ_BROKER_SERVER, "Server Name or IP"), |
| new Item(Type.INTEGER, Preference.ACTIVEMQ_BROKER_PORT, "Port (default="+IProductConfigurationPrefs.DEFAULT_PORT_ACTIVE_MQ_BROKER_SERVICE+")") |
| }; |
| } |
| |
| @Override |
| public boolean doCheckState(FieldEditor editor, String input) { |
| switch (Preference.by(editor.getPreferenceName())) { |
| case ACTIVEMQ_BROKER_PORT: |
| Object brokerHost = getValue(Preference.ACTIVEMQ_BROKER_SERVER); |
| if (brokerHost instanceof String) { |
| int brokerPort = ItemDescription.parseInt(input, 0); |
| if (!CXMqConnection.checkValidBroker((String) brokerHost, brokerPort)) { |
| String errorMessage = "ActiveMQ Broker not responding"; |
| setErrorMessage(errorMessage); |
| return false; |
| } |
| } |
| } |
| return super.doCheckState(editor, input); |
| } |
| |
| @Override |
| public boolean performOk() { |
| Object brokerHost = getValue(Preference.ACTIVEMQ_BROKER_SERVER); |
| Object sbrokerPort = getValue(Preference.ACTIVEMQ_BROKER_PORT); |
| if (brokerHost instanceof String) { |
| String errorMessage = CheckStateServerName.doCheckState((String)brokerHost, 5000); |
| if (errorMessage != null) { |
| setErrorMessage(errorMessage); |
| return false; |
| } |
| int brokerPort = ItemDescription.parseInt((String)sbrokerPort, 0); |
| if (!CXMqConnection.checkValidBroker((String) brokerHost, brokerPort)) { |
| errorMessage = "ActiveMQ Broker not responding"; |
| setErrorMessage(errorMessage); |
| return true; |
| } |
| } |
| return super.performOk(); |
| } |
| |
| |
| } |