Skip to content

Commit

Permalink
Merge pull request #3820 from jburel/jnlp-parameters
Browse files Browse the repository at this point in the history
Jnlp parameters
  • Loading branch information
joshmoore committed May 25, 2015
2 parents 32b2911 + afbcbe5 commit b869d7d
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@

package org.openmicroscopy.shoola.env;

import ij.IJ;

import java.io.File;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.apache.commons.io.FilenameUtils;
import org.openmicroscopy.shoola.util.CommonsLangUtils;

import org.openmicroscopy.shoola.env.config.AgentInfo;
import org.openmicroscopy.shoola.env.config.Registry;
import org.openmicroscopy.shoola.env.config.RegistryFactory;
Expand All @@ -45,7 +43,6 @@
import org.openmicroscopy.shoola.env.event.AgentEventListener;
import org.openmicroscopy.shoola.env.init.Initializer;
import org.openmicroscopy.shoola.env.init.StartupException;
import org.openmicroscopy.shoola.env.ui.UserNotifier;
import org.openmicroscopy.shoola.util.file.IOUtil;
import org.openmicroscopy.shoola.util.ui.UIUtilities;

Expand Down Expand Up @@ -126,7 +123,7 @@ private static void runStartupProcedure(String home, String configFile)
initManager.configure();
initManager.doInit();
initManager.notifyEnd();

//startService() called by Initializer at end of doInit().
} catch (StartupException se) {
if (initManager != null) initManager.rollback();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.openmicroscopy.shoola.env.ui.SplashScreen;
import org.openmicroscopy.shoola.env.ui.UIFactory;
import org.openmicroscopy.shoola.env.ui.UserNotifier;
import org.openmicroscopy.shoola.util.CommonsLangUtils;

/**
* Does some configuration required for the initialization process to run.
Expand Down Expand Up @@ -85,8 +86,6 @@ public final class SplashScreenInit
void configure()
{
initializer.register(this);
//splashScreen = UIFactory.makeSplashScreen(container);
//splashScreen.open();
}

/**
Expand Down Expand Up @@ -115,7 +114,6 @@ void rollback() {}
*/
public void onStart(int totalTasks)
{
//splashScreen.setTotalTasks(totalTasks);
this.totalTasks = totalTasks;
}

Expand Down Expand Up @@ -151,21 +149,31 @@ public void onEnd()
b = v.intValue() == LookupNames.INSIGHT_ENTRY ||
v.intValue() == LookupNames.IMPORTER_ENTRY;
}

if (!b) {
splashScreen.close();
return;
}

LoginConfig cfg = new LoginConfig(reg);
int max = cfg.getMaxRetry();
LoginService loginSvc = (LoginService) reg.lookup(LookupNames.LOGIN);

int index = max;
UserCredentials uc;
UserNotifier un = UIFactory.makeUserNotifier(container);

String jnlpHost = System.getProperty("jnlp.omero.host");
String jnlpPort = System.getProperty("jnlp.omero.port");
String jnlpSession = System.getProperty("jnlp.omero.sessionid");
while (0 < max--) {
uc = splashScreen.getUserCredentials((max == index-1));
if (CommonsLangUtils.isNotBlank(jnlpSession)) {
uc = new UserCredentials(jnlpSession,
jnlpSession, jnlpHost, UserCredentials.HIGH);
try {
uc.setPort(Integer.parseInt(jnlpPort));
} catch (Exception e) {}//use the default port.
} else {
uc = splashScreen.getUserCredentials((max == index-1));
}
//needed b/c need to retrieve user's details later.
reg.bind(LookupNames.USER_CREDENTIALS, uc);

Expand All @@ -181,6 +189,7 @@ public void onEnd()
if (max != 0) {
loginSvc.notifyLoginFailure();
splashScreen.onLoginFailure();
jnlpSession = null;
} else if (max == 0) {
//Exit if we couldn't manage to log in.
un.notifyError("Login Failure",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,22 @@
import java.awt.event.WindowStateListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.Icon;
import javax.swing.JFrame;

//Third-party libraries




//Application-internal dependencies
import org.openmicroscopy.shoola.env.Container;
import org.openmicroscopy.shoola.env.LookupNames;
import org.openmicroscopy.shoola.env.config.OMEROInfo;
import org.openmicroscopy.shoola.env.config.Registry;
import org.openmicroscopy.shoola.env.data.login.UserCredentials;
import org.openmicroscopy.shoola.util.CommonsLangUtils;
import org.openmicroscopy.shoola.util.image.geom.Factory;
import org.openmicroscopy.shoola.util.ui.login.LoginCredentials;
import org.openmicroscopy.shoola.util.ui.login.ScreenLogin;
Expand Down Expand Up @@ -170,15 +175,32 @@ private void initializedView(Icon splashscreen)
v = (String) version;
OMEROInfo info =
(OMEROInfo) container.getRegistry().lookup(LookupNames.OMERODS);

String port = ""+info.getPortSSL();

view = new ScreenLogin(Container.TITLE, splashscreen, img, v, port,
info.getHostName(), connectToServer());
int p = -1;
String port = ""+ info.getPortSSL();
String host = info.getHostName();
boolean configurable = info.isHostNameConfigurable();
//check if we have jnlp option
String jnlpHost = System.getProperty("jnlp.omero.host");
if (CommonsLangUtils.isNotBlank(jnlpHost)) {
host = jnlpHost;
configurable = false;
}
String jnlpPort = System.getProperty("jnlp.omero.port");
if (CommonsLangUtils.isNotBlank(jnlpPort)) {
port = jnlpPort;
p = Integer.parseInt(port);
configurable = false;
}
String jnlpSession = System.getProperty("jnlp.omero.sessionid");
boolean serverAvailable = connectToServer();
if (CommonsLangUtils.isNotBlank(jnlpSession)) {
serverAvailable = false;
}
view = new ScreenLogin(Container.TITLE, splashscreen, img, v, port,
host, serverAvailable);
view.setEncryptionConfiguration(info.isEncrypted(),
info.isEncryptedConfigurable());
view.setHostNameConfiguration(info.getHostName(),
info.isHostNameConfigurable());
view.setHostNameConfiguration(host, configurable, p);
view.showConnectionSpeed(true);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension d = view.getPreferredSize();
Expand Down Expand Up @@ -308,7 +330,9 @@ void updateProgress(String task)
if (doneTasks == totalTasks) {
view.setStatusVisible(false, lc == null);
if (lc == null) view.requestFocusOnField();
if (!connectToServer()) view.setVisible(false);
if (!connectToServer()) {
view.setVisible(false);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@ public class ScreenLogin

/** The default server name from the configuration file.*/
private String configureServerName;


/** List of components to show or hide depending on connection status.*/
private List<JComponent> components;

/** Quits the application. */
private void quit()
{
Expand Down Expand Up @@ -495,6 +498,7 @@ private void initializeGroups()
*/
private void initialize(String userName, String hostName)
{
components = new ArrayList<JComponent>();
//status update.
currentTask = new JLabel();
Font newFont = currentTask.getFont().deriveFont(8);
Expand All @@ -516,7 +520,7 @@ private void initialize(String userName, String hostName)
pass.setToolTipText("Enter your password.");
pass.setColumns(TEXT_COLUMN);
Map<String, String> servers = editor.getServers();
if (hostName != null && hostName.trim().length() > 0) {
if (CommonsLangUtils.isNotBlank(hostName)) {
serverName = hostName;
//if user did point to another server
if (servers != null && servers.size() > 0) {
Expand Down Expand Up @@ -683,7 +687,7 @@ private JPanel buildLogin()
row.add(bar);

mainPanel.add(row);

components.add(row);
//user name
JPanel group = new JPanel();
group.setOpaque(false);
Expand All @@ -706,20 +710,20 @@ private JPanel buildLogin()
group.add(row);

mainPanel.add(group);
components.add(group);
//controls
JPanel controls = new JPanel();
controls.setOpaque(false);
controls.add(Box.createHorizontalGlue());
controls.add(login);
controls.add(cancel);
mainPanel.add(UIUtilities.buildComponentPanelCenter(controls, 0, 0,
false));

p = UIUtilities.buildComponentPanelCenter(controls, 0, 0, false);
mainPanel.add(p);
components.add(p);


return mainPanel;
}

/**
* Lays out the widgets and positions the window in the middle of
* the screen.
Expand Down Expand Up @@ -759,16 +763,30 @@ private void buildGUI(Icon logo, String version, boolean serverAvailable)
versionInfo.setOpaque(false);
//Add login details.
int y = height-bottom-10;
if (serverAvailable) {
y = top+2*h;
buildLogin();
}

y = top+2*h;
buildLogin();
displayComponents(serverAvailable);
mainPanel.add(UIUtilities.buildComponentPanelCenter(
versionInfo, 0, 0, false));
mainPanel.setBounds(0, y, width, height-top-bottom);
addToLayer(mainPanel);
}

/**
* Shows or hides the components.
*
* @param visible Pass <code>true</code> to show,
* <code>false</code> to hide.
*/
private void displayComponents(boolean visible)
{
Iterator<JComponent> i = components.iterator();
while (i.hasNext()) {
i.next().setVisible(visible);
}
repaint();
}

/**
* Returns the server's name.
*
Expand Down Expand Up @@ -803,7 +821,7 @@ private String getConnectionSpeed()
*/
private void setNewServer(String s)
{
if (s == null || s.length() == 0) {
if (CommonsLangUtils.isBlank(s)) {
if (configureServerName != null)
s = configureServerName;
else s = DEFAULT_SERVER;
Expand Down Expand Up @@ -1148,6 +1166,7 @@ public void onLoginFailure()
{
loginAttempt = false;
setControlsEnabled(true);
displayComponents(true);
}

/** Sets the text of all textFields to <code>null</code>. */
Expand Down Expand Up @@ -1176,7 +1195,7 @@ public void cleanField(int fieldID)
pass.setText("");
break;
default:
cleanFields();
cleanFields();
}
}

Expand Down Expand Up @@ -1309,7 +1328,50 @@ public void setEncryptionConfiguration(boolean encrypted,
if (!configurable)
encryptedButton.removeActionListener(encryptionListener);
}

/**
* Indicates if the user can modify or not the host name from the UI.
*
* @param hostName The hostname.
* @param configurable Pass <code>true</code> to allow to change the
* host name, <code>false</code> otherwise.
* @param port The selected port.
*/
public void setHostNameConfiguration(String hostName, boolean configurable,
int port)
{
hostConfigurable = configurable;
configureServerName = hostName;
if (CommonsLangUtils.isNotBlank(hostName)) {
if (configurable) {
Map<String, String> servers = editor.getServers();
if (servers == null || servers.size() == 0)
editor.addRow(hostName);
else {
Iterator<String> i = servers.keySet().iterator();
String value;
boolean exist = false;
while (i.hasNext()) {
value = i.next();
if (hostName.equals(value)) {
exist = true;
break;
}
}
if (!exist) editor.addRow(hostName);
}
} else {
serverName = hostName;
originalServerName = serverName;
if (port < 0) {
selectedPort = Integer.parseInt(editor.getDefaultPort());
} else {
selectedPort = port;
}
setNewServer(originalServerName);
}
}
}

/**
* Indicates if the user can modify or not the host name from the UI.
*
Expand All @@ -1319,33 +1381,7 @@ public void setEncryptionConfiguration(boolean encrypted,
*/
public void setHostNameConfiguration(String hostName, boolean configurable)
{
hostConfigurable = configurable;
configureServerName = hostName;
if (hostName != null && hostName.trim().length() > 0) {
if (configurable) {
Map<String, String> servers = editor.getServers();
if (servers == null || servers.size() == 0)
editor.addRow(hostName);
else {
Iterator<String> i = servers.keySet().iterator();
String value;
boolean exist = false;
while (i.hasNext()) {
value = i.next();
if (hostName.equals(value)) {
exist = true;
break;
}
}
if (!exist) editor.addRow(hostName);
}
} else {
serverName = hostName;
originalServerName = serverName;
selectedPort = Integer.parseInt(editor.getDefaultPort());
setNewServer(originalServerName);
}
}
setHostNameConfiguration(hostName, configurable, -1);
}

/**
Expand Down

0 comments on commit b869d7d

Please sign in to comment.