-// $Id$
/**
* Copyright (C) 2015 EDIT
* European Distributed Institute of Taxonomy
*/
package eu.etaxonomy.taxeditor.ui.dialog;
+import java.io.File;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.preferences.ConfigurationScope;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.SWTException;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.forms.events.ExpansionEvent;
+import org.eclipse.ui.forms.events.IExpansionListener;
+import org.eclipse.ui.forms.widgets.ExpandableComposite;
+import org.eclipse.ui.progress.IProgressConstants;
import org.eclipse.wb.swt.SWTResourceManager;
+import org.osgi.service.prefs.BackingStoreException;
+import org.osgi.service.prefs.Preferences;
+import org.springframework.security.authentication.BadCredentialsException;
+import org.springframework.security.authentication.LockedException;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
-import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
+import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteConfiguration;
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
+import eu.etaxonomy.cdm.api.service.IUserService;
+import eu.etaxonomy.cdm.model.metadata.CdmMetaData;
+import eu.etaxonomy.cdm.persistence.hibernate.permission.Role;
+import eu.etaxonomy.taxeditor.l10n.Messages;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.remoting.server.CDMServerException;
+import eu.etaxonomy.taxeditor.remoting.server.CDMServerUtils;
+import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource;
import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo;
import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo.CdmInstanceInfo;
import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;
import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.store.LoginManager;
+import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
+import eu.etaxonomy.taxeditor.webapp.CDMEmbeddedServerException;
+import eu.etaxonomy.taxeditor.webapp.CDMServer;
+import eu.etaxonomy.taxeditor.webapp.ICDMServerError;
+
/**
* @author cmathew
* @date 20 Jan 2015
*
*/
-public class RemotingLoginDialog extends Dialog {
+public class RemotingLoginDialog extends Dialog implements ICDMServerError {
+
+ private Logger logger = Logger.getLogger(getClass());
- protected Object result;
+ private static final String DEFAULT_PASS = "00000"; //$NON-NLS-1$
+ private static final String DEFAULT_USER = "admin"; //$NON-NLS-1$
+ private static final String UBUNTU = "Ubuntu"; //$NON-NLS-1$
+ protected Object result;
protected Shell shlConnect;
- private Text txtPort;
private Text txtCdmServerStatus;
private Text txtCdmInstanceStatus;
private Combo comboCdmServer;
private final Map<String, CdmServerInfo> csiiMap = new HashMap<String, CdmServerInfo>();
- private final String STATUS_AVAILABLE = "Available";
- private final String STATUS_NOT_AVAILABLE = "Not Available";
- private final String STATUS_RETRIEVING = "Retrieving ...";
- private final String STATUS_CHECKING_AVAILABILITY = "Checking ...";
- private final String STATUS_NO_INSTANCES = "No Instances Found";
- private final String STATUS_ERROR = "Error";
- private final String STATUS_REMOTING_NOT_ACTIVATED = "Remoting not activated";
+ private final static String STATUS_AVAILABLE = Messages.RemotingLoginDialog_STATUS_AVAILABLE;
+ private final static String STATUS_NOT_AVAILABLE = Messages.RemotingLoginDialog_STATUS_NOT_AVAILABLE;
+ private final static String STATUS_STARTED = Messages.RemotingLoginDialog_STATUS_STARTED;
+ private final static String STATUS_NOT_STARTED = Messages.RemotingLoginDialog_STATUS_NOT_STARTED;
+ private final static String STATUS_RETRIEVING = Messages.RemotingLoginDialog_STATUS_RETRIEVING;
+ private final static String STATUS_CHECKING_AVAILABILITY = Messages.RemotingLoginDialog_STATUS_CHECKING;
+ private final static String STATUS_NO_INSTANCES = Messages.RemotingLoginDialog_STATUS_NO_INSTANCES_FOUND;
+ private final static String STATUS_NOT_COMPATIBLE = Messages.RemotingLoginDialog_STATUS_NOT_COMPATIBLE;
+
+ private final static String MESG_COMPATIBLE_EDITOR_OLD = Messages.RemotingLoginDialog_UPDATE_EDITOR;
+ private final static String MESG_COMPATIBLE_SERVER_OLD = Messages.RemotingLoginDialog_CHOOSE_COMPATIBLE_CDM_SERVER;
+
+ private final static String STORE_PREFERENCES_NODE = "eu.etaxonomy.taxeditor.store"; //$NON-NLS-1$
+
+ private final static String LOGIN_NODE = "login"; //$NON-NLS-1$
+ private final static String USERNAME_SUFFIX = "_username"; //$NON-NLS-1$
+ private final static String PASSWORD_SUFFIX = "_password"; //$NON-NLS-1$
+
+ private final static String LAST_SERVER_INSTANCE_NODE = "lastServerInstance"; //$NON-NLS-1$
+ private final static String LAST_SERVER_KEY = "lastServerKey"; //$NON-NLS-1$
+ private final static String LAST_INSTANCE_KEY = "lastInstanceKey"; //$NON-NLS-1$
+
+ private Composite remotingComposite;
private CdmServerInfo selectedCsii;
private CdmInstanceInfo selectedCdmInstance;
private Button btnCdmServerRefresh;
+ private Button btnCdmInstanceRefresh;
+ private Button btnStopServer;
+ private Composite loginComposite;
+ private Label lblLogin;
+ private Text txtLogin;
+ private Label lblPassword;
+ private Text txtPassword;
+ private Button btnRememberMe;
+ private Composite compAdvanced;
+ private Label lblPort;
+ private Text txtPort;
+ private Label lblServerVersion;
+ private Text txtServerVersion;
+ private ExpandableComposite xpndblcmpstAdvanced;
+ private StyledText styledTxtMessage;
+
+ private final int MIN_WIDTH = 530;
+ private final int MIN_HEIGHT = 220;
+ private final int MIN_EXP_HEIGHT = 380;
+ private final int MESSAGE_HEIGHT = 50;
+ private Label lblEditorVersion;
+ private Text txtEditorVersion;
+ private Label lblServerCDMVersion;
+ private Text txtServerCDMVersion;
+ private Label lblEditorCDMVersion;
+ private Text txtEditorCDMVersion;
+ private String serverName, instanceName;
+ private boolean autoConnect = false;
+ private boolean loadLoginPrefs = true;
+ private boolean isDevRemoteSource = false;
+ private Job serverJob;
/**
* Create the dialog.
* @param parent
*/
public RemotingLoginDialog(Shell parent, int style) {
super(parent, style);
- setText("Login");
+ setText(Messages.RemotingLoginDialog_LABEL_LOGIN);
+ }
+
+ public Object open(CdmRemoteSource source, boolean loadLoginPrefs, boolean autoConnect) {
+ this.loadLoginPrefs = loadLoginPrefs;
+ this.serverName = source.getName();
+ String contextPath = source.getContextPath();
+ this.instanceName = contextPath.substring(contextPath.lastIndexOf("/") + 1); //$NON-NLS-1$
+ return open(serverName, instanceName, loadLoginPrefs, autoConnect);
+ }
+
+
+ public Object open(String serverName, String instanceName, boolean loadLoginPrefs, boolean autoConnect) {
+ this.serverName = serverName;
+ this.instanceName = instanceName;
+ this.loadLoginPrefs = loadLoginPrefs;
+ this.autoConnect = autoConnect;
+ return open();
}
/**
* @return the result
*/
public Object open() {
- ICdmRemoteSource devRemoteSource = CdmServerInfo.getDevServerRemoteSource();
- if(devRemoteSource != null) {
- connect(devRemoteSource);
- } else {
- createContents();
- populateCdmServerCombo();
- shlConnect.open();
- shlConnect.layout();
- Display display = getParent().getDisplay();
+ createContents();
+ if(serverName == null && instanceName == null) {
+ readPrefLastServerInstance();
+ }
+
+ setEditorInfo();
+ populateCdmServerCombo();
+ shlConnect.open();
+ shlConnect.layout();
+
+ xpndblcmpstAdvanced.setExpanded(false);
+
+ Display display = getParent().getDisplay();
- while (!shlConnect.isDisposed()) {
+ while (!shlConnect.isDisposed()) {
+ if (!display.isDisposed()){
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
+
return result;
}
* Create contents of the dialog.
*/
private void createContents() {
- shlConnect = new Shell(getParent(), getStyle());
- shlConnect.setSize(490, 157);
- shlConnect.setText("Connect");
+ shlConnect = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
+ shlConnect.setMinimumSize(new Point(MIN_WIDTH, MIN_HEIGHT));
+ shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT);
+ shlConnect.setText(Messages.RemotingLoginDialog_LABEL_CONNECT);
shlConnect.setLayout(new FillLayout(SWT.HORIZONTAL));
- Composite composite = new Composite(shlConnect, SWT.NONE);
- FillLayout fl_composite = new FillLayout(SWT.VERTICAL);
- fl_composite.spacing = 5;
- composite.setLayout(fl_composite);
-
- Composite remotingComposite = new Composite(composite, SWT.NONE);
- FillLayout fl_remotingComposite = new FillLayout(SWT.VERTICAL);
- fl_remotingComposite.spacing = 5;
- remotingComposite.setLayout(fl_remotingComposite);
+ remotingComposite = new Composite(shlConnect, SWT.NONE);
+ remotingComposite.setLayout(new GridLayout(1, false));
Composite cdmServerComposite = new Composite(remotingComposite, SWT.NONE);
- cdmServerComposite.setLayout(new GridLayout(6, false));
+ GridData gd_cdmServerComposite = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
+ gd_cdmServerComposite.heightHint = 68;
+ cdmServerComposite.setLayoutData(gd_cdmServerComposite);
+ cdmServerComposite.setLayout(new GridLayout(4, false));
Label lblCdmServer = new Label(cdmServerComposite, SWT.NONE);
- lblCdmServer.setText("CDM Server : ");
- lblCdmServer.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
+ lblCdmServer.setText(Messages.RemotingLoginDialog_LABEL_CDM_SERVER);
+ lblCdmServer.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
lblCdmServer.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
comboCdmServer = new Combo(cdmServerComposite, SWT.READ_ONLY);
@Override
public void widgetSelected(SelectionEvent e) {
refreshCdmServer();
+
}
});
GridData gd_comboCdmServer = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
comboCdmServer.setLayoutData(gd_comboCdmServer);
comboCdmServer.select(0);
- Label lblPortSeparator = new Label(cdmServerComposite, SWT.NONE);
- lblPortSeparator.setText(" : ");
-
- txtPort = new Text(cdmServerComposite, SWT.BORDER);
- GridData gd_txtPort = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
- gd_txtPort.widthHint = 50;
- txtPort.setLayoutData(gd_txtPort);
-
txtCdmServerStatus = new Text(cdmServerComposite, SWT.BORDER);
txtCdmServerStatus.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
txtCdmServerStatus.setEditable(false);
GridData gd_txtCdmServerStatus = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
gd_txtCdmServerStatus.widthHint = 100;
+
txtCdmServerStatus.setLayoutData(gd_txtCdmServerStatus);
btnCdmServerRefresh = new Button(cdmServerComposite, SWT.NONE);
}
});
btnCdmServerRefresh.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
- btnCdmServerRefresh.setText("Refresh");
+ btnCdmServerRefresh.setText(Messages.RemotingLoginDialog_LABEL_REFRESH);
Label lblCdmInstance = new Label(cdmServerComposite, SWT.NONE);
GridData gd_lblCdmInstance = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
gd_lblCdmInstance.heightHint = 30;
lblCdmInstance.setLayoutData(gd_lblCdmInstance);
- lblCdmInstance.setText("CDM Instance : ");
- lblCdmInstance.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
+ lblCdmInstance.setText(Messages.RemotingLoginDialog_LABEL_CDM_INSTANCE);
+ lblCdmInstance.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
comboCdmInstance = new Combo(cdmServerComposite, SWT.READ_ONLY);
comboCdmInstance.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- updateSelectedCdmInstance();
- checkSelectedCdmServerInstance();
+ refreshCdmInstance();
}
});
GridData gd_comboCdmInstance = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
txtCdmInstanceStatus = new Text(cdmServerComposite, SWT.BORDER);
txtCdmInstanceStatus.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
txtCdmInstanceStatus.setEditable(false);
- GridData gd_txtCdmInstanceStatus = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
+ GridData gd_txtCdmInstanceStatus = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
gd_txtCdmInstanceStatus.widthHint = 100;
txtCdmInstanceStatus.setLayoutData(gd_txtCdmInstanceStatus);
- Button btnCdmInstanceRefresh = new Button(cdmServerComposite, SWT.FLAT);
+ btnCdmInstanceRefresh = new Button(cdmServerComposite, SWT.FLAT);
btnCdmInstanceRefresh.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
gd_btnCdmInstanceRefresh.widthHint = 110;
gd_btnCdmInstanceRefresh.heightHint = 30;
btnCdmInstanceRefresh.setLayoutData(gd_btnCdmInstanceRefresh);
- btnCdmInstanceRefresh.setText("Refresh");
- new Label(cdmServerComposite, SWT.NONE);
+ btnCdmInstanceRefresh.setText(Messages.RemotingLoginDialog_LABEL_REFRESH);
+
+ loginComposite = new Composite(remotingComposite, SWT.NONE);
+ GridData gd_loginComposite = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
+ gd_loginComposite.widthHint = 487;
+ gd_loginComposite.heightHint = 70;
+ loginComposite.setLayoutData(gd_loginComposite);
+ GridLayout gl_loginComposite = new GridLayout(6, false);
+ gl_loginComposite.marginTop = 5;
+ loginComposite.setLayout(gl_loginComposite);
+
+ lblLogin = new Label(loginComposite, SWT.CENTER);
+ GridData gd_lblLogin = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
+ gd_lblLogin.widthHint = 50;
+ lblLogin.setLayoutData(gd_lblLogin);
+ lblLogin.setText(Messages.RemotingLoginDialog_LABEL_LOGIN_COLON);
+ lblLogin.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
- btnConnect = new Button(cdmServerComposite, SWT.FLAT);
- btnConnect.addMouseListener(new MouseAdapter() {
+ txtLogin = new Text(loginComposite, SWT.BORDER);
+ GridData gd_txtLogin = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
+ gd_txtLogin.minimumWidth = 80;
+ gd_txtLogin.widthHint = 80;
+ gd_txtLogin.heightHint = 15;
+ txtLogin.setLayoutData(gd_txtLogin);
+
+ lblPassword = new Label(loginComposite, SWT.CENTER);
+ lblPassword.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ lblPassword.setText(Messages.RemotingLoginDialog_LABEL_PASSWORD);
+ lblPassword.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
+
+ txtPassword = new Text(loginComposite, SWT.BORDER | SWT.PASSWORD);
+ GridData gd_txtPassword = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
+ gd_txtPassword.minimumWidth = 80;
+ gd_txtPassword.widthHint = 80;
+ gd_txtPassword.heightHint = 15;
+ txtPassword.setLayoutData(gd_txtPassword);
+ new Label(loginComposite, SWT.NONE);
+ txtPassword.addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyPressed(KeyEvent e) {
+ if(e.character==SWT.CR){
+ connectButtonPressed();
+ }
+ }
+ });
+
+ btnConnect = new Button(loginComposite, SWT.FLAT);
+ btnConnect.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
+ btnConnect.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ connectButtonPressed();
+ }
+ });
+ btnConnect.setText(Messages.RemotingLoginDialog_LABEL_CONNECT);
+
+ btnRememberMe = new Button(loginComposite, SWT.CHECK);
+ btnRememberMe.setSelection(true);
+ GridData gd_btnRememberMe = new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1);
+ btnRememberMe.setLayoutData(gd_btnRememberMe);
+ btnRememberMe.setText(Messages.RemotingLoginDialog_LABEL_REMEMBER_ME);
+
+ Label lblDefaultLogin = new Label(loginComposite, SWT.NONE);
+ GridDataFactory.fillDefaults().span(4, 1).align(SWT.TRAIL, SWT.CENTER).applyTo(lblDefaultLogin);
+ lblDefaultLogin.setText(String.format(Messages.RemotingLoginDialog_DEFAULT_LOGIN, DEFAULT_USER, DEFAULT_PASS));
+
+ styledTxtMessage = new StyledText(remotingComposite, SWT.NONE);
+ styledTxtMessage.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
+ styledTxtMessage.setForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_RED));
+ styledTxtMessage.setFont(SWTResourceManager.getFont(UBUNTU, 12, SWT.BOLD));
+ styledTxtMessage.setSelectionBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_SELECTION_TEXT));
+ styledTxtMessage.setSelectionForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_RED));
+ styledTxtMessage.setDoubleClickEnabled(false);
+ styledTxtMessage.setEditable(false);
+ styledTxtMessage.setWordWrap(true);
+
+ GridData gd_styledTxtMessage = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
+ gd_styledTxtMessage.exclude = true;
+ gd_styledTxtMessage.minimumHeight = MESSAGE_HEIGHT;
+ gd_styledTxtMessage.heightHint = MESSAGE_HEIGHT;
+ gd_styledTxtMessage.widthHint = MIN_WIDTH - 5;
+
+ styledTxtMessage.setLayoutData(gd_styledTxtMessage);
+
+ xpndblcmpstAdvanced = new ExpandableComposite(remotingComposite, SWT.NONE, ExpandableComposite.TWISTIE);
+ GridData gd_xpndblcmpstAdvanced = new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1);
+ gd_xpndblcmpstAdvanced.heightHint = 19;
+ gd_xpndblcmpstAdvanced.widthHint = MIN_WIDTH - 10;
+ xpndblcmpstAdvanced.setLayoutData(gd_xpndblcmpstAdvanced);
+ xpndblcmpstAdvanced.addExpansionListener(new IExpansionListener() {
+ @Override
+ public void expansionStateChanged(ExpansionEvent e) {
+ if(e.getState()) {
+ shlConnect.setSize(MIN_WIDTH, MIN_EXP_HEIGHT);
+ } else {
+ shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT);
+ }
+
+ }
+ @Override
+ public void expansionStateChanging(ExpansionEvent e) {
+ }
+ });
+ xpndblcmpstAdvanced.setText(Messages.RemotingLoginDialog_LABEL_ADVANCED);
+ xpndblcmpstAdvanced.setExpanded(true);
+
+ compAdvanced = new Composite(xpndblcmpstAdvanced, SWT.NONE);
+ xpndblcmpstAdvanced.setClient(compAdvanced);
+ compAdvanced.setLayout(new GridLayout(4, false));
+
+ lblPort = new Label(compAdvanced, SWT.CENTER);
+ lblPort.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ lblPort.setSize(0, 0);
+ lblPort.setText(Messages.RemotingLoginDialog_LABEL_PORT);
+ lblPort.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
+
+ txtPort = new Text(compAdvanced, SWT.BORDER);
+ GridData gd_txtPort = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
+ gd_txtPort.minimumWidth = 50;
+ gd_txtPort.widthHint = 50;
+ txtPort.setLayoutData(gd_txtPort);
+
+ lblServerVersion = new Label(compAdvanced, SWT.CENTER);
+ lblServerVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ lblServerVersion.setText(Messages.RemotingLoginDialog_LABEL_SERVER_CDMLIB_VERSION);
+ lblServerVersion.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
+
+ txtServerVersion = new Text(compAdvanced, SWT.BORDER);
+ txtServerVersion.setEditable(false);
+ txtServerVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
+ btnStopServer = new Button(compAdvanced, SWT.FLAT);
+ btnStopServer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
+ btnStopServer.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
- int selInstanceIndex = comboCdmInstance.getSelectionIndex();
- String instance = comboCdmInstance.getItem(selInstanceIndex);
- checkSelectedCdmServerInstance();
- connect(selectedCsii.getCdmRemoteSource(selectedCdmInstance));
+ stopManagedServer();
}
});
- GridData gd_btnConnect = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
- gd_btnConnect.heightHint = 30;
- btnConnect.setLayoutData(gd_btnConnect);
- btnConnect.setText("Connect");
- new Label(cdmServerComposite, SWT.NONE);
- new Label(cdmServerComposite, SWT.NONE);
- new Label(cdmServerComposite, SWT.NONE);
- new Label(cdmServerComposite, SWT.NONE);
+ btnStopServer.setText(Messages.RemotingLoginDialog_LABEL_STOP_MANAGED_SERVER);
+
+ lblEditorVersion = new Label(compAdvanced, SWT.CENTER);
+ lblEditorVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ lblEditorVersion.setText(Messages.RemotingLoginDialog_LABEL_EDITOR_CDMLIB_VERSION);
+ lblEditorVersion.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
+
+ txtEditorVersion = new Text(compAdvanced, SWT.BORDER);
+ txtEditorVersion.setEditable(false);
+ txtEditorVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ new Label(compAdvanced, SWT.NONE);
+ new Label(compAdvanced, SWT.NONE);
+
+ lblServerCDMVersion = new Label(compAdvanced, SWT.CENTER);
+ lblServerCDMVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ lblServerCDMVersion.setText(Messages.RemotingLoginDialog_LABEL_SERVER_CDM_VERSION);
+ lblServerCDMVersion.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
+
+ txtServerCDMVersion = new Text(compAdvanced, SWT.BORDER);
+ txtServerCDMVersion.setEditable(false);
+ txtServerCDMVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ new Label(compAdvanced, SWT.NONE);
+ new Label(compAdvanced, SWT.NONE);
+
+ lblEditorCDMVersion = new Label(compAdvanced, SWT.CENTER);
+ lblEditorCDMVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ lblEditorCDMVersion.setText(Messages.RemotingLoginDialog_LABEL_EDITOR_CDM_VERSION);
+ lblEditorCDMVersion.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
+
+ txtEditorCDMVersion = new Text(compAdvanced, SWT.BORDER);
+ txtEditorCDMVersion.setEditable(false);
+ txtEditorCDMVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
}
+ private void connectButtonPressed() {
+ if(selectedCsii.isLocalhostMgd() && !isSelectedCdmInstanceRunningInManagedServer()) {
+ startManagedServer();
+ } else {
+ connect();
+ if (CdmStore.isActive() && CdmStore.currentAuthentiationHasOneOfRoles(Role.ROLE_REMOTING)){
+ PreferencesUtil.setNomenclaturalCodePreferences();
+ }
+
+ }
+ }
+
private void populateCdmServerCombo() {
- Job job = new Job("Retrieve Server Instances") {
+ Job job = new Job(Messages.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES) {
@Override
protected IStatus run(IProgressMonitor monitor) {
- Display.getDefault().asyncExec(new Runnable() {
+ Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
for(CdmServerInfo csii : CdmServerInfo.getCdmServers()) {
csiiMap.put(csii.getName(), csii);
comboCdmServer.add(csii.getName());
}
- comboCdmServer.select(0);
- refreshCdmServer();
+ int serverIndex = -1;
+ if(serverName != null) {
+ serverIndex = comboCdmServer.indexOf(serverName);
+ }
+ if(serverIndex == -1) {
+ comboCdmServer.select(0);
+ autoConnect = false;
+ } else {
+ comboCdmServer.select(serverIndex);
+ }
+ CdmRemoteSource devRemoteSource = CdmServerInfo.getDevServerRemoteSource();
+ if(devRemoteSource != null) {
+ isDevRemoteSource = true;
+ String username = System.getProperty("cdm.server.dev.username"); //$NON-NLS-1$
+ String password = System.getProperty("cdm.server.dev.password"); //$NON-NLS-1$
+ if(username != null && !username.isEmpty() && password != null && !password.isEmpty()) {
+ txtLogin.setText(username);
+ txtPassword.setText(password);
+ CdmStore.connect(devRemoteSource, RemotingLoginDialog.this);
+ }
+ } else {
+ refreshCdmServer();
+ }
}
});
return Status.OK_STATUS;
private void refreshCdmServer() {
- txtCdmServerStatus.setText(STATUS_CHECKING_AVAILABILITY);
- updateSelectedCdmServer();
- updatePort();
- checkSelectedCdmServer();
+ try{
+ txtCdmServerStatus.setText(STATUS_CHECKING_AVAILABILITY);
+ clearOnServerChange();
+ emptyCredentials();
+ updateSelectedCdmServer();
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ checkSelectedCdmServer();
+ }
+ });
+ }
+ catch(SWTException e){
+ //catch widget is disposed exception which may occurr if
+ //dialog is closed but the runnable tries to update
+ }
}
private void updateSelectedCdmServer() {
}
private void updatePort() {
- txtPort.setText("");
+ txtPort.setText(""); //$NON-NLS-1$
if(selectedCsii != null) {
- txtPort.setText(String.valueOf(selectedCsii.getPort()));
+ int port = selectedCsii.getPort();
+ if(port == CdmServerInfo.NULL_PORT) {
+ txtPort.setText(CdmServerInfo.NULL_PORT_STRING);
+ } else {
+ txtPort.setText(String.valueOf(port));
+ }
+ }
+ }
+
+ private int getPort() {
+ int port = CdmServerInfo.NULL_PORT;
+ try {
+ port = Integer.valueOf(txtPort.getText());
+ } catch (NumberFormatException nfe) {
+ if(!CdmServerInfo.NULL_PORT_STRING.equals(txtPort.getText())) {
+ setMessage(Messages.RemotingLoginDialog_MESSAGE_PORT_SHOULD_BE_INTEGER);
+ }
}
+ return port;
}
private void checkSelectedCdmServer() {
- int selIndex = comboCdmServer.getSelectionIndex();
- txtCdmInstanceStatus.setText("");
- if(selectedCsii != null) {
- if(selectedCsii.pingServer()) {
- txtCdmServerStatus.setText(STATUS_AVAILABLE);
- populateCdmInstanceCombo(true);
- } else {
- txtCdmServerStatus.setText(STATUS_NOT_AVAILABLE);
- comboCdmInstance.removeAll();
+ try{
+ if(selectedCsii != null) {
+ if(selectedCsii.isLocalhost()) {
+ txtPort.setEditable(true);
+ txtPort.setEnabled(true);
+ }
+ try {
+ if(selectedCsii.pingServer()) {
+ txtCdmServerStatus.setText(STATUS_AVAILABLE);
+ populateCdmInstanceCombo(true);
+ String serverVersionTimestamp = generateLastModifiedTooltip(selectedCsii.getCdmlibLastModified());
+ txtServerVersion.setText(selectedCsii.getCdmlibServicesVersion() + ":" + serverVersionTimestamp); //$NON-NLS-1$
+ } else {
+ txtCdmServerStatus.setText(STATUS_NOT_AVAILABLE);
+ comboCdmInstance.removeAll();
+ disableCdmInstanceControls("", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ } catch (CDMServerException | IOException e) {
+ txtCdmServerStatus.setText(STATUS_NOT_AVAILABLE);
+ MessagingUtils.warningDialog(Messages.RemotingLoginDialog_CONNECTION_FAILED_TITLE, this,
+ Messages.RemotingLoginDialog_CONNECTION_FAILED_MESSAGE);
+ logger.warn(Messages.RemotingLoginDialog_CONNECTION_FAILED_TITLE, e);
+ }
}
+ updatePort();
+ }
+ catch(SWTException e){
+ //catch widget is disposed exception which may occurr if
+ //dialog is closed but the runnable tries to update
}
}
comboCdmInstance.setEnabled(false);
btnConnect.setEnabled(false);
txtCdmInstanceStatus.setText(STATUS_RETRIEVING);
- Job job = new Job("Retrieve Server Instances") {
+ txtCdmInstanceStatus.setToolTipText(""); //$NON-NLS-1$
+
+ serverJob = new Job(Messages.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES) {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
for(CdmInstanceInfo cdmInstance : instances) {
comboCdmInstance.add(cdmInstance.getName());
}
- comboCdmInstance.select(0);
- updateSelectedCdmInstance();
- checkSelectedCdmServerInstance();
+ int instanceIndex = -1;
+ if(instanceName != null) {
+ instanceIndex = comboCdmInstance.indexOf(instanceName);
+ }
+ if(instanceIndex == -1) {
+ comboCdmInstance.select(0);
+ autoConnect = false;
+ } else {
+ comboCdmInstance.select(instanceIndex);
+ }
+ refreshCdmInstance();
comboCdmInstance.setEnabled(true);
+ if(autoConnect) {
+ connect();
+ }
+
} else {
txtCdmInstanceStatus.setText(STATUS_NO_INSTANCES);
btnConnect.setEnabled(false);
}
});
}
- } catch (CDMServerException e) {
+ } catch (final CDMServerException e) {
MessagingUtils.warn(getClass(), e);
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
- txtCdmInstanceStatus.setText(STATUS_REMOTING_NOT_ACTIVATED);
- comboCdmInstance.setEnabled(false);
- btnConnect.setEnabled(false);
+ disableCdmInstanceControls(STATUS_NOT_AVAILABLE, e.getMessage());
}
});
}
}
};
- if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE)) {
+ if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE) && !isDevRemoteSource) {
// Start the Job
- job.schedule();
+ serverJob.schedule();
}
-
}
+ private void disableCdmInstanceControls(String cdmInstanceStatus, String tooltip) {
+ txtCdmInstanceStatus.setText(cdmInstanceStatus);
+ txtCdmInstanceStatus.setToolTipText(tooltip);
+ comboCdmInstance.setEnabled(false);
+ btnConnect.setEnabled(false);
+
+ }
private void refreshCdmInstance() {
txtCdmInstanceStatus.setText(STATUS_CHECKING_AVAILABILITY);
+ clearOnInstanceChange();
updateSelectedCdmInstance();
- checkSelectedCdmServerInstance();
+ checkSelectedCdmInstance();
+ updateManagedServerControls();
}
private void updateSelectedCdmInstance() {
int selIndex = comboCdmInstance.getSelectionIndex();
if(selIndex != -1) {
selectedCdmInstance = selectedCsii.getInstanceFromName(comboCdmInstance.getItem(selIndex));
+
+ if(loadLoginPrefs) {
+ readPrefCredentials();
+ }
+ }
+ }
+
+ private void updateManagedServerControls() {
+ if(selectedCsii.isLocalhostMgd()) {
+ if(isSelectedCdmInstanceRunningInManagedServer()) {
+ txtCdmInstanceStatus.setText(STATUS_STARTED);
+ } else {
+ txtCdmInstanceStatus.setText(STATUS_NOT_STARTED);
+ }
+ btnConnect.setEnabled(true);
+ selectedCsii.setPort(getManagedServerPort());
+ updatePort();
+ }
+
+
+ if(isManagedServerRunning()) {
+ btnStopServer.setEnabled(true);
+ } else {
+ btnStopServer.setEnabled(false);
+ }
+ }
+
+ private boolean isManagedServerRunning() {
+ return CdmStore.getManagedServer() != null && CdmStore.getManagedServer().isAlive();
+ }
+
+ private boolean isSelectedCdmInstanceRunningInManagedServer() {
+ return CdmStore.getManagedServer() != null &&
+ CdmStore.getManagedServer().isAlive() &&
+ selectedCsii.isLocalhostMgd() &&
+ CdmStore.getManagedServer().getDataSourceName().equals(selectedCdmInstance.getName());
+ }
+
+ private void startManagedServer() {
+ if(isManagedServerRunning()) {
+ if(CdmStore.getManagedServer().getDataSourceName().equals(selectedCdmInstance.getName())) {
+ return;
+ } else {
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ stopManagedServer();
+ }
+ });
+ }
+ }
+
+
+ Job job = new Job(Messages.RemotingLoginDialog_JOB_SERVER_LAUNCH) {
+
+ @Override
+ public IStatus run(IProgressMonitor monitor) {
+ String mgdServerConfigFileName = "mgd.datasources.xml"; //$NON-NLS-1$
+ String config = CDMServerUtils.convertEditorToServerConfig();
+ File managedServerConfigFile;
+ int maxUnits = 50;
+ monitor.beginTask(Messages.RemotingLoginDialog_TASK_LAUNCHING_SERVER, maxUnits);
+ try {
+ monitor.subTask(String.format(Messages.RemotingLoginDialog_GENERATING_CONFIG_FILE, selectedCdmInstance.getName()));
+ managedServerConfigFile = CDMServerUtils.writeManagedServerConfig(config, mgdServerConfigFileName);
+ monitor.worked(1);
+ CdmStore.setManagedServer(new CDMServer(selectedCdmInstance.getName(), managedServerConfigFile));
+ monitor.subTask(Messages.RemotingLoginDialog_STARTING_MGD_SERVER);
+ CdmStore.getManagedServer().start(false, RemotingLoginDialog.this);
+ int serverUnits = 0;
+
+ // the following loop is a 'fake' progress monitoring where the progress
+ // bar is advanced by one unit every second until maxUnits -2
+ while(!CdmStore.getManagedServer().isStarted() && !CdmStore.getManagedServer().isFailed()) {
+ if(serverUnits < maxUnits - 2) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ }
+ monitor.worked(1);
+ serverUnits++;
+ }
+ }
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ hide(false);
+ updateManagedServerControls();
+ connect();
+ }
+ });
+ } catch (IOException ioe) {
+ MessagingUtils.errorDialog(Messages.RemotingLoginDialog_ERROR_GENERATING_CONFIG_FILE,
+ this,
+ ioe.getMessage(),
+ TaxeditorStorePlugin.PLUGIN_ID,
+ ioe,
+ true);
+ } catch (CDMEmbeddedServerException cse) {
+ MessagingUtils.errorDialog(Messages.RemotingLoginDialog_ERROR_STARTING_SERVER,
+ this,
+ cse.getMessage(),
+ TaxeditorStorePlugin.PLUGIN_ID,
+ cse,
+ true);
+ } finally {
+ monitor.done();
+ }
+ return Status.OK_STATUS;
+ }
+ };
+
+ // configure the job
+ job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
+ job.setUser(true);
+ // schedule job
+ hide(true);
+ job.schedule();
+ }
+
+ private void stopManagedServer() {
+ try {
+ CdmStore.getManagedServer().stop();
+ } catch (Exception e) {
+ MessagingUtils.errorDialog(Messages.RemotingLoginDialog_ERROR_STOPPING_SERVER,
+ this,
+ String.format(Messages.RemotingLoginDialog_COULD_NOT_STOP_SERVER, CdmStore.getManagedServer().getPort()),
+ TaxeditorStorePlugin.PLUGIN_ID,
+ e,
+ true);
}
+ CdmStore.setManagedServer(null);
+ updateManagedServerControls();
+ }
+
+ private int getManagedServerPort() {
+ return CdmStore.getManagedServer() == null ? CdmServerInfo.NULL_PORT : CdmStore.getManagedServer().getPort();
}
- private void checkSelectedCdmServerInstance() {
+ private void checkSelectedCdmInstance() {
+ boolean available = false;
+ String status = STATUS_NOT_AVAILABLE;
+ String message = null;
+
if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE)) {
try {
- if(selectedCsii.pingInstance(selectedCdmInstance)) {
- txtCdmInstanceStatus.setText(STATUS_AVAILABLE);
- btnConnect.setEnabled(true);
+ if(selectedCsii.pingInstance(selectedCdmInstance, getPort())) {
+ status = STATUS_AVAILABLE;
+ available = true;
} else {
- txtCdmInstanceStatus.setText(STATUS_NOT_AVAILABLE);
- btnConnect.setEnabled(false);
+ status = STATUS_NOT_AVAILABLE;
+ available = false;
+ }
+
+ if(available) {
+ txtServerCDMVersion.setText(selectedCsii.getCdmRemoteSource(selectedCdmInstance, getPort()).getDbSchemaVersion());
+ int compareDbSchemaVersion = selectedCsii.compareDbSchemaVersion(selectedCdmInstance, getPort());
+ int compareCdmlibServicesVersion = 0;
+ boolean disableServicesApiTimestampCheck =
+ PreferencesUtil.getBooleanValue((IPreferenceKeys.DISABLE_SERVICES_API_TIMESTAMP_CHECK));
+ if(!disableServicesApiTimestampCheck) {
+ compareCdmlibServicesVersion = selectedCsii.compareCdmlibServicesVersion();
+ }
+ if(compareDbSchemaVersion > 0 || compareCdmlibServicesVersion > 0) {
+ status = STATUS_NOT_COMPATIBLE;
+ available = false;
+ message = MESG_COMPATIBLE_EDITOR_OLD;
+ } else if(compareDbSchemaVersion < 0 || compareCdmlibServicesVersion < 0) {
+ status = STATUS_NOT_COMPATIBLE;
+ available = false;
+ message = MESG_COMPATIBLE_SERVER_OLD;
+ } else {
+ status = STATUS_AVAILABLE;
+ available = true;
+ message = ""; //$NON-NLS-1$
+ }
}
} catch (Exception e) {
- txtCdmInstanceStatus.setText(STATUS_NOT_AVAILABLE);
- MessagingUtils.warn(this.getClass(), e);
+ txtCdmInstanceStatus.setToolTipText(e.getMessage());
+ } finally {
+ btnConnect.setEnabled(available);
+ txtCdmInstanceStatus.setText(status);
+ if(!StringUtils.isBlank(message)) {
+ setMessage(message);
+ }
}
}
-
}
- private void connect(ICdmRemoteSource source) {
- if(CdmStore.isConnecting()){
- MessagingUtils.warningDialog("Already connecting", this, "You are currently connecting to a different CDM Instance already.");
+ private void connect() {
+ checkSelectedCdmInstance();
+
+ if(!txtCdmInstanceStatus.getText().equals(STATUS_AVAILABLE)) {
+ return;
+ }
+
+ ICdmRemoteSource source = selectedCsii.getCdmRemoteSource(selectedCdmInstance, getPort());
+
+ if(!validateLogin(source)) {
return;
}
try {
- CdmDataSourceRepository.changeDataSource(source);
+ CdmStore.connect(source, this);
} catch (Exception e) {
// Do not expect anything to go wrong at this point, so we throw a runtime exception
// if any problems
throw new RuntimeException(e);
}
- if(shlConnect != null) {
- shlConnect.dispose();
+ }
+
+
+ public boolean isRememberMe() {
+ return btnRememberMe.getSelection();
+ }
+
+ private void persistPrefLastServerInstance() {
+ IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
+ Preferences lastServerInstancePrefs = preferences.node(LAST_SERVER_INSTANCE_NODE);
+
+ lastServerInstancePrefs.put(LAST_SERVER_KEY, selectedCsii.getName());
+ lastServerInstancePrefs.put(LAST_INSTANCE_KEY, selectedCdmInstance.getName());
+
+ flushPreferences(lastServerInstancePrefs);
+ }
+
+ private void persistPrefCredentials() {
+ IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
+ Preferences credentialsPrefs = preferences.node(LOGIN_NODE);
+ credentialsPrefs.put(getUsernamePrefKey(), txtLogin.getText());
+ credentialsPrefs.put(getPasswordPrefKey(), txtPassword.getText());
+ flushPreferences(credentialsPrefs);
+ }
+
+ private void removePrefCredentials() {
+ IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
+ Preferences credentialsPrefs = preferences.node(LOGIN_NODE);
+ credentialsPrefs.put(getUsernamePrefKey(), txtLogin.getText());
+ credentialsPrefs.put(getPasswordPrefKey(), txtPassword.getText());
+ removePreferences(credentialsPrefs);
+ }
+ private void removePreferences(Preferences prefs) {
+ try {
+ prefs.removeNode();
+ } catch (BackingStoreException bse) {
+ setMessage(bse.getMessage());
+ }
+ }
+ private void flushPreferences(Preferences prefs) {
+ try {
+ prefs.flush();
+ } catch (BackingStoreException bse) {
+ setMessage(bse.getMessage());
+ }
+ }
+
+
+
+ private void readPrefCredentials() {
+ String username, password;
+ IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
+ Preferences credentialsPrefs = preferences.node(LOGIN_NODE);
+ username = credentialsPrefs.get(getUsernamePrefKey(), ""); //$NON-NLS-1$
+ txtLogin.setText(username);
+ password = credentialsPrefs.get(getPasswordPrefKey(),""); //$NON-NLS-1$
+ txtPassword.setText(password);
+ if(username.isEmpty() || password.isEmpty()) {
+ autoConnect = false;
+ }
+ }
+
+ private void readPrefLastServerInstance() {
+ IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
+ Preferences lastServerInstancePrefs = preferences.node(LAST_SERVER_INSTANCE_NODE);
+
+ serverName = lastServerInstancePrefs.get(LAST_SERVER_KEY, null);
+ instanceName = lastServerInstancePrefs.get(LAST_INSTANCE_KEY, null);
+ }
+
+ private void emptyCredentials() {
+ txtLogin.setText(""); //$NON-NLS-1$
+ txtPassword.setText(""); //$NON-NLS-1$
+ }
+
+ private String getUsernamePrefKey() {
+ return selectedCsii.toString(selectedCdmInstance.getName(), isDevRemoteSource?getPort():-1) + USERNAME_SUFFIX;
+ }
+
+ private String getPasswordPrefKey() {
+ return selectedCsii.toString(selectedCdmInstance.getName(), isDevRemoteSource?getPort():-1) + PASSWORD_SUFFIX;
+ }
+
+ private boolean validateLogin(ICdmRemoteSource remoteSource) {
+ if(getUsername() == null || getUsername().isEmpty()) {
+ setMessage(Messages.RemotingLoginDialog_LOGIN_CANNOT_BE_EMPTY);
+ return false;
+ }
+ if(getPassword() == null || getPassword().isEmpty()) {
+ setMessage(Messages.RemotingLoginDialog_PASSWORD_CANNOT_BE_EMPTY);
+ return false;
+ }
+
+
+ try {
+ IUserService userService = CdmApplicationRemoteConfiguration.getUserService(remoteSource);
+ UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(getUsername(), getPassword());
+ CdmApplicationRemoteConfiguration.getAuthenticationManager(userService).authenticate(token);
+ } catch(BadCredentialsException e){
+ setMessage(LoginManager.INCORRECT_CREDENTIALS_MESSAGE);
+ return false;
+ } catch(LockedException e){
+ setMessage(LoginManager.ACCOUNT_LOCKED_MESSAGE);
+ return false;
+ } catch(IllegalArgumentException e){
+ setMessage(LoginManager.INCORRECT_CREDENTIALS_MESSAGE);
+ return false;
+ }
+ return true;
+ }
+
+ public String getUsername() {
+ return txtLogin.getText();
+ }
+
+ public String getPassword() {
+ return txtPassword.getText();
+ }
+
+ public void setMessage(String message) {
+ if(message != null && !message.isEmpty()) {
+// if(message.length() > 50) {
+// styledTxtMessage.setToolTipText(message);
+// message = message.substring(0,50) + "..."; //$NON-NLS-1$
+// }
+ styledTxtMessage.setText(message);
+ styledTxtMessage.setVisible(true);
+ ((GridData)styledTxtMessage.getLayoutData()).exclude = false;
+ shlConnect.setSize(MIN_WIDTH, getHeightWithoutMessage() + MESSAGE_HEIGHT);
+ shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage() + MESSAGE_HEIGHT);
+ } else {
+ if (!styledTxtMessage.isDisposed()){
+ styledTxtMessage.setText(""); //$NON-NLS-1$
+ styledTxtMessage.setVisible(false);
+ ((GridData)styledTxtMessage.getLayoutData()).exclude = true;
+ }
+ if(!shlConnect.isDisposed()){
+ shlConnect.setSize(MIN_WIDTH, getHeightWithoutMessage());
+ shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage());
+ }
+ }
+ if (!remotingComposite.isDisposed()){
+ remotingComposite.layout();
+ }
+ }
+
+ private int getHeightWithoutMessage() {
+ if(xpndblcmpstAdvanced.isExpanded()) {
+ return MIN_EXP_HEIGHT;
+ } else {
+ return MIN_HEIGHT;
+ }
+ }
+
+
+ public void hide(boolean isHidden) {
+ if (!shlConnect.isDisposed()){
+ if(shlConnect != null && shlConnect.getDisplay() != null) {
+ shlConnect.setVisible(!isHidden);
+ }
}
}
+ public void dispose() {
+ if (!shlConnect.isDisposed()){
+ if(shlConnect != null && shlConnect.getDisplay() != null) {
+ shlConnect.dispose();
+ }
+ }
+ }
+
+ public void onComplete() {
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ if(selectedCdmInstance!=null){
+ if(isRememberMe()) {
+ persistPrefCredentials();
+ }else{
+ removePrefCredentials();
+ }
+ persistPrefLastServerInstance();
+ }
+ dispose();
+ }
+ });
+ }
+
+ private String generateLastModifiedTooltip(String cdmlibLastModified) {
+ if(StringUtils.isBlank(cdmlibLastModified)) {
+ return ""; //$NON-NLS-1$
+ }
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd.HH.mm.z"); //$NON-NLS-1$
+ Date cdmlibLastModifiedDate;
+ String cdmlibLastModifiedTimestamp = ""; //$NON-NLS-1$
+
+ cdmlibLastModifiedDate = new Date(Long.valueOf(cdmlibLastModified));
+ cdmlibLastModifiedTimestamp = sdf.format(cdmlibLastModifiedDate);
+
+ return cdmlibLastModifiedTimestamp;
+ }
+
+ private void setEditorInfo() {
+ txtEditorCDMVersion.setText(CdmMetaData.getDbSchemaVersion());
+ String editorVersionTimestamp = generateLastModifiedTooltip(CdmApplicationState.getCdmlibLastModified());
+ txtEditorVersion.setText(CdmApplicationState.getCdmlibVersion() + ":" + editorVersionTimestamp); //$NON-NLS-1$
+ }
+
+ private void clearOnServerChange() {
+ setMessage(""); //$NON-NLS-1$
+ txtServerCDMVersion.setText(""); //$NON-NLS-1$
+ txtServerVersion.setText(""); //$NON-NLS-1$
+ txtServerVersion.setToolTipText(""); //$NON-NLS-1$
+ txtServerCDMVersion.setText(""); //$NON-NLS-1$
+ comboCdmInstance.removeAll();
+ txtCdmInstanceStatus.setText(""); //$NON-NLS-1$
+ txtPort.setEditable(false);
+ txtPort.setEnabled(false);
+ }
+
+ private void clearOnInstanceChange() {
+ setMessage(""); //$NON-NLS-1$
+ txtServerCDMVersion.setText(""); //$NON-NLS-1$
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void handleError(final Throwable t) {
+
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ serverJob.cancel();
+
+ String title = Messages.RemotingLoginDialog_SERVER_LAUNCH_ERROR;
+ String message = t.getMessage();
+
+
+ MessagingUtils.errorDialog(title,
+ this,
+ message,
+ TaxeditorStorePlugin.PLUGIN_ID,
+ t,
+ true);
+ }
+ });
+ }
}