blob: bb42a3990fa2cf457092f0e13d872adf7d850553 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2012 Wind River Systems, Inc. and others. 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:
* Wind River Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.tcf.te.ui.terminals.serial.launcher;
import java.text.DateFormat;
import java.util.Date;
import org.eclipse.core.runtime.Assert;
import org.eclipse.osgi.util.NLS;
import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback;
import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
import org.eclipse.tcf.te.runtime.services.ServiceManager;
import org.eclipse.tcf.te.runtime.services.interfaces.ITerminalService;
import org.eclipse.tcf.te.runtime.services.interfaces.constants.ITerminalsConnectorConstants;
import org.eclipse.tcf.te.ui.controls.BaseDialogPageControl;
import org.eclipse.tcf.te.ui.terminals.interfaces.IConfigurationPanel;
import org.eclipse.tcf.te.ui.terminals.interfaces.IMementoHandler;
import org.eclipse.tcf.te.ui.terminals.launcher.AbstractLauncherDelegate;
import org.eclipse.tcf.te.ui.terminals.serial.controls.SerialWizardConfigurationPanel;
import org.eclipse.tcf.te.ui.terminals.serial.nls.Messages;
/**
* Serial launcher delegate implementation.
*/
public class SerialLauncherDelegate extends AbstractLauncherDelegate {
// The serial terminal connection memento handler
private final IMementoHandler mementoHandler = new SerialMementoHandler();
/* (non-Javadoc)
* @see org.eclipse.tcf.te.ui.terminals.interfaces.ILauncherDelegate#needsUserConfiguration()
*/
@Override
public boolean needsUserConfiguration() {
return true;
}
/* (non-Javadoc)
* @see org.eclipse.tcf.te.ui.terminals.interfaces.ILauncherDelegate#getPanel(org.eclipse.tcf.te.ui.controls.BaseDialogPageControl)
*/
@Override
public IConfigurationPanel getPanel(BaseDialogPageControl parentControl) {
return new SerialWizardConfigurationPanel(parentControl);
}
/* (non-Javadoc)
* @see org.eclipse.tcf.te.ui.terminals.interfaces.ILauncherDelegate#execute(org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer, org.eclipse.tcf.te.runtime.interfaces.callback.ICallback)
*/
@Override
public void execute(IPropertiesContainer properties, ICallback callback) {
Assert.isNotNull(properties);
// Set the terminal tab title
String terminalTitle = getTerminalTitle(properties);
if (terminalTitle != null) {
properties.setProperty(ITerminalsConnectorConstants.PROP_TITLE, terminalTitle);
}
// Serial terminals do have a disconnect button
if (!properties.containsKey(ITerminalsConnectorConstants.PROP_HAS_DISCONNECT_BUTTON)) {
properties.setProperty(ITerminalsConnectorConstants.PROP_HAS_DISCONNECT_BUTTON, true);
}
// Get the terminal service
ITerminalService terminal = ServiceManager.getInstance().getService(ITerminalService.class);
// If not available, we cannot fulfill this request
if (terminal != null) {
terminal.openConsole(properties, callback);
}
}
/**
* Returns the terminal title string.
* <p>
* The default implementation constructs a title like &quot;Serial &lt;port&gt; (Start time) &quot;.
*
* @return The terminal title string or <code>null</code>.
*/
private String getTerminalTitle(IPropertiesContainer properties) {
String port = properties.getStringProperty(ITerminalsConnectorConstants.PROP_SERIAL_DEVICE);
if (port != null) {
DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
String date = format.format(new Date(System.currentTimeMillis()));
return NLS.bind(Messages.SerialLauncherDelegate_terminalTitle, new String[]{port, date});
}
return Messages.SerialLauncherDelegate_terminalTitle_default;
}
/* (non-Javadoc)
* @see org.eclipse.core.runtime.PlatformObject#getAdapter(java.lang.Class)
*/
@Override
public Object getAdapter(Class adapter) {
if (IMementoHandler.class.equals(adapter)) {
return mementoHandler;
}
return super.getAdapter(adapter);
}
}