### Eclipse Workspace Patch 1.0 #P org.eclipse.tm.terminal Index: src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java =================================================================== RCS file: /cvsroot/dsdp/org.eclipse.tm.core/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java,v retrieving revision 1.22 diff -u -r1.22 VT100TerminalControl.java --- src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java 10 Jun 2008 00:46:10 -0000 1.22 +++ src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java 13 Jun 2008 03:46:20 -0000 @@ -549,6 +549,9 @@ public Control getControl() { return fCtlText; } + public Control getRootControl() { + return fWndParent; + } protected void setupControls(Composite parent) { // The Terminal view now aims to be an ANSI-conforming terminal emulator, so it // can't have a horizontal scroll bar (but a vertical one is ok). Also, do Index: src/org/eclipse/tm/internal/terminal/control/ITerminalViewControl.java =================================================================== RCS file: /cvsroot/dsdp/org.eclipse.tm.core/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/control/ITerminalViewControl.java,v retrieving revision 1.13 diff -u -r1.13 ITerminalViewControl.java --- src/org/eclipse/tm/internal/terminal/control/ITerminalViewControl.java 9 Jun 2008 23:38:52 -0000 1.13 +++ src/org/eclipse/tm/internal/terminal/control/ITerminalViewControl.java 13 Jun 2008 03:46:20 -0000 @@ -48,7 +48,14 @@ void setFont(Font font); void setInvertedColors(boolean invert); Font getFont(); + /** + * @return the text control + */ Control getControl(); + /** + * @return the root of all controls + */ + Control getRootControl(); boolean isDisposed(); void selectAll(); void clearTerminal(); #P org.eclipse.tm.terminal.view Index: src/org/eclipse/tm/internal/terminal/view/TerminalView.java =================================================================== RCS file: /cvsroot/dsdp/org.eclipse.tm.core/terminal/org.eclipse.tm.terminal.view/src/org/eclipse/tm/internal/terminal/view/TerminalView.java,v retrieving revision 1.27 diff -u -r1.27 TerminalView.java --- src/org/eclipse/tm/internal/terminal/view/TerminalView.java 7 May 2008 14:48:03 -0000 1.27 +++ src/org/eclipse/tm/internal/terminal/view/TerminalView.java 13 Jun 2008 03:46:30 -0000 @@ -19,6 +19,7 @@ * Michael Scharf (Wind River) - [217999] Duplicate context menu entries in Terminal * Anna Dushistova (MontaVista) - [227537] moved actions from terminal.view to terminal plugin * Martin Oberhuber (Wind River) - [168186] Add Terminal User Docs + * Michael Scharf (Wind River) - [172483] switch between connections *******************************************************************************/ package org.eclipse.tm.internal.terminal.view; @@ -26,6 +27,7 @@ import java.util.Set; import org.eclipse.core.runtime.Preferences; +import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; @@ -35,8 +37,10 @@ import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; import org.eclipse.swt.events.MenuEvent; import org.eclipse.swt.events.MenuListener; +import org.eclipse.swt.graphics.Font; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; @@ -45,9 +49,11 @@ import org.eclipse.tm.internal.terminal.actions.TerminalActionConnect; import org.eclipse.tm.internal.terminal.actions.TerminalActionDisconnect; import org.eclipse.tm.internal.terminal.actions.TerminalActionNewTerminal; +import org.eclipse.tm.internal.terminal.actions.TerminalActionPin; +import org.eclipse.tm.internal.terminal.actions.TerminalActionRemove; +import org.eclipse.tm.internal.terminal.actions.TerminalActionSelectionDropDown; import org.eclipse.tm.internal.terminal.actions.TerminalActionSettings; import org.eclipse.tm.internal.terminal.actions.TerminalActionToggleCommandInputField; -import org.eclipse.tm.internal.terminal.control.CommandInputFieldWithHistory; import org.eclipse.tm.internal.terminal.control.ITerminalListener; import org.eclipse.tm.internal.terminal.control.ITerminalViewControl; import org.eclipse.tm.internal.terminal.control.TerminalViewControlFactory; @@ -61,6 +67,8 @@ import org.eclipse.tm.internal.terminal.provisional.api.Logger; import org.eclipse.tm.internal.terminal.provisional.api.TerminalConnectorExtension; import org.eclipse.tm.internal.terminal.provisional.api.TerminalState; +import org.eclipse.tm.internal.terminal.view.ITerminalViewConnectionManager.ITerminalViewConnectionFactory; +import org.eclipse.tm.internal.terminal.view.ITerminalViewConnectionManager.TerminalViewConnectionListener; import org.eclipse.ui.IMemento; import org.eclipse.ui.IViewReference; import org.eclipse.ui.IViewSite; @@ -69,14 +77,12 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.ViewPart; -public class TerminalView extends ViewPart implements ITerminalView, ITerminalListener { +public class TerminalView extends ViewPart implements ITerminalView, TerminalViewConnectionListener { private static final String STORE_CONNECTION_TYPE = "ConnectionType"; //$NON-NLS-1$ private static final String STORE_SETTING_SUMMARY = "SettingSummary"; //$NON-NLS-1$ - - private static final String STORE_HAS_COMMAND_INPUT_FIELD = "HasCommandInputField"; //$NON-NLS-1$ - - private static final String STORE_COMMAND_INPUT_FIELD_HISTORY = "CommandInputFieldHistory"; //$NON-NLS-1$ + + private static final String STORE_PINNED = "Pinned"; //$NON-NLS-1$ private static final String STORE_TITLE = "Title"; //$NON-NLS-1$ @@ -84,6 +90,10 @@ protected ITerminalViewControl fCtlTerminal; + // TODO (scharf): this decorator is only there to deal wit the common + // actions. Find a better solution. + TerminalViewControlDecorator fCtlDecorator=new TerminalViewControlDecorator(); + protected TerminalAction fActionTerminalNewTerminal; protected TerminalAction fActionTerminalConnect; @@ -108,12 +118,15 @@ protected TerminalPropertyChangeHandler fPropertyChangeHandler; + protected Action fActionTerminalDropDown; + protected Action fActionTerminalPin; + protected Action fActionTerminalRemove; + protected boolean fMenuAboutToShow; private SettingsStore fStore; - private CommandInputFieldWithHistory fCommandInputField; - + private final ITerminalViewConnectionManager fMultiConnectionManager=new TerminalViewConnectionManager(); /** * Listens to changes in the preferences */ @@ -126,11 +139,65 @@ } } }; + + private PageBook fPageBook; + + private boolean fPinned=true; + + /** + * This listener updates both, the view and the + * ITerminalViewConnection. + * + */ + class TerminalListener implements ITerminalListener { + volatile ITerminalViewConnection fConnection; + void setConnection(ITerminalViewConnection connection) { + fConnection=connection; + } + public void setState(final TerminalState state) { + runInDisplayThread(new Runnable() { + public void run() { + fConnection.setState(state); + // if the current connection changes, update the view + if(fConnection==fMultiConnectionManager.getCurrentConnection()) { + updateStatus(); + } + } + }); + } + public void setTerminalTitle(final String title) { + runInDisplayThread(new Runnable() { + public void run() { + fConnection.setTerminalTitle(title); + // if the current connection changes, update the view + if(fConnection==fMultiConnectionManager.getCurrentConnection()) { + updateSummary(); + } + } + }); + } + /** + * @param runnable run in display thread + */ + private void runInDisplayThread(Runnable runnable) { + if(Thread.currentThread()==Display.getDefault().getThread()) + runnable.run(); + else + Display.getDefault().syncExec(runnable); + } + + } + public TerminalView() { Logger .log("==============================================================="); //$NON-NLS-1$ + fMultiConnectionManager.addListener(this); } + /** + * @param title + * @return a unique part name + */ String findUniqueTitle(String title) { IWorkbenchPage[] pages = getSite().getWorkbenchWindow().getPages(); String id= getViewSite().getId(); @@ -165,50 +232,47 @@ // if(!limitOutput) // bufferLineLimit=-1; int bufferLineLimit = preferences.getInt(TerminalPreferencePage.PREF_BUFFERLINES); - fCtlTerminal.setBufferLineLimit(bufferLineLimit); - fCtlTerminal.setInvertedColors(preferences.getBoolean(TerminalPreferencePage.PREF_INVERT_COLORS)); - } - // TerminalTarget interface - public void setState(final TerminalState state) { - Runnable runnable=new Runnable() { - public void run() { - updateStatus(); - onTerminalStatus(); - } - }; - if(Thread.currentThread()==Display.getDefault().getThread()) - runnable.run(); - else - Display.getDefault().syncExec(runnable); + boolean invert=preferences.getBoolean(TerminalPreferencePage.PREF_INVERT_COLORS); + // update the preferences for all controls + ITerminalViewConnection[] conn=fMultiConnectionManager.getConnections(); + for (int i = 0; i < conn.length; i++) { + conn[i].getCtlTerminal().setBufferLineLimit(bufferLineLimit); + conn[i].getCtlTerminal().setInvertedColors(invert); + } } - - /** * Display a new Terminal view. This method is called when the user clicks the New * Terminal button in any Terminal view's toolbar. */ public void onTerminalNewTerminal() { Logger.log("creating new Terminal instance."); //$NON-NLS-1$ - - try { - // The second argument to showView() is a unique String identifying the - // secondary view instance. If it ever matches a previously used secondary - // view identifier, then this call will not create a new Terminal view, - // which is undesirable. Therefore, we append the current time in - // milliseconds to the secondary view identifier to ensure it is always - // unique. This code runs only when the user clicks the New Terminal - // button, so there is no risk that this code will run twice in a single - // millisecond. - - getSite().getPage().showView( - "org.eclipse.tm.terminal.view.TerminalView",//$NON-NLS-1$ - "SecondaryTerminal" + System.currentTimeMillis(), //$NON-NLS-1$ - IWorkbenchPage.VIEW_ACTIVATE); - } catch (PartInitException ex) { - Logger.logException(ex); + if(isPinned()) { + try { + // The second argument to showView() is a unique String identifying the + // secondary view instance. If it ever matches a previously used secondary + // view identifier, then this call will not create a new Terminal view, + // which is undesirable. Therefore, we append the current time in + // milliseconds to the secondary view identifier to ensure it is always + // unique. This code runs only when the user clicks the New Terminal + // button, so there is no risk that this code will run twice in a single + // millisecond. + + getSite().getPage().showView( + "org.eclipse.tm.terminal.view.TerminalView",//$NON-NLS-1$ + "SecondaryTerminal" + System.currentTimeMillis(), //$NON-NLS-1$ + IWorkbenchPage.VIEW_ACTIVATE); + } catch (PartInitException ex) { + Logger.logException(ex); + } + } else { + setupControls(); + if(newConnection()==null) { + fMultiConnectionManager.removeCurrent(); + } } } + public void onTerminalConnect() { //if (isConnected()) if (fCtlTerminal.getState()!=TerminalState.CLOSED) @@ -222,6 +286,8 @@ updateTerminalConnect(); updateTerminalDisconnect(); updateTerminalSettings(); + fActionToggleCommandInputField.setChecked(hasCommandInputField()); + updateSummary(); } public void updateTerminalConnect() { @@ -246,12 +312,16 @@ } public void onTerminalSettings() { + newConnection(); + } + + private ITerminalConnector newConnection() { ITerminalConnector c=showSettingsDialog(); if(c!=null) { setConnector(c); - onTerminalConnect(); } + return c; } private ITerminalConnector showSettingsDialog() { @@ -259,7 +329,7 @@ // persistent settings. TerminalSettingsDlg dlgTerminalSettings = new TerminalSettingsDlg(getViewSite().getShell(),fCtlTerminal.getConnectors(),fCtlTerminal.getTerminalConnector()); - dlgTerminalSettings.setTerminalTitle(getPartName()); + dlgTerminalSettings.setTerminalTitle(getCurrentConnection().getPartName()); Logger.log("opening Settings dialog."); //$NON-NLS-1$ if (dlgTerminalSettings.open() == Window.CANCEL) { @@ -272,7 +342,7 @@ // When the settings dialog is closed, we persist the Terminal settings. saveSettings(dlgTerminalSettings.getConnector()); - setPartName(dlgTerminalSettings.getTerminalTitle()); + setViewTitle(dlgTerminalSettings.getTerminalTitle()); return dlgTerminalSettings.getConnector(); } @@ -286,74 +356,28 @@ fActionTerminalSettings.setEnabled(bEnabled); } - - public void setTerminalTitle(String strTitle) { - if (fCtlTerminal.isDisposed()) - return; - - if (strTitle != null) { - // When parameter 'data' is not null, it is a String containing text to - // display in the view's content description line. This is used by class - // TerminalText when it processes an ANSI OSC escape sequence that commands - // the terminal to display text in its title bar. - } else if(fCtlTerminal.getTerminalConnector()==null){ - strTitle=ViewMessages.NO_CONNECTION_SELECTED; - } else { - // When parameter 'data' is null, we construct a descriptive string to - // display in the content description line. - String strConnected = getStateDisplayName(fCtlTerminal.getState()); - String summary = getSettingsSummary(); - //TODO Title should use an NLS String and com.ibm.icu.MessageFormat - //In order to make the logic of assembling, and the separators, better adapt to foreign languages - if(summary.length()>0) - summary=summary+" - "; //$NON-NLS-1$ - String name=fCtlTerminal.getTerminalConnector().getName(); - if(name.length()>0) { - name+=": "; //$NON-NLS-1$ - } - strTitle = name + "("+ summary + strConnected + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - } - - setContentDescription(strTitle); + private void setViewTitle(String title) { + setPartName(title); + getCurrentConnection().setPartName(title); + } + private void setViewSummary(String summary) { + setContentDescription(summary); getViewSite().getActionBars().getStatusLineManager().setMessage( - strTitle); - setTitleToolTip(getPartName()+": "+strTitle); //$NON-NLS-1$ + summary); + setTitleToolTip(getPartName()+": "+summary); //$NON-NLS-1$ + } - /** - * @return the setting summary. If there is no connection, or the connection - * has not been initialized, use the last stored state. - */ - private String getSettingsSummary() { - // TODO: use another mechanism than "?" for the magic non initialized state - // see TerminalConnectorProxy.getSettingsSummary - String summary="?"; //$NON-NLS-1$ - if(fCtlTerminal.getTerminalConnector()!=null) - summary=fCtlTerminal.getSettingsSummary(); - if("?".equals(summary)) { //$NON-NLS-1$ - summary=fStore.get(STORE_SETTING_SUMMARY, ""); //$NON-NLS-1$ - } - return summary; - } - public void onTerminalStatus() { - setTerminalTitle(null); - } - - private String getStateDisplayName(TerminalState state) { - if(state==TerminalState.CONNECTED) { - return ViewMessages.STATE_CONNECTED; - } else if(state==TerminalState.CONNECTING) { - return ViewMessages.STATE_CONNECTING; - } else if(state==TerminalState.OPENED) { - return ViewMessages.STATE_OPENED; - } else if(state==TerminalState.CLOSED) { - return ViewMessages.STATE_CLOSED; - } else { - throw new IllegalStateException(state.toString()); - } + public void updateSummary() { + setViewSummary(getCurrentConnection().getFullSummary()); } public void onTerminalFontChanged() { - fCtlTerminal.setFont(JFaceResources.getFont(FONT_DEFINITION)); + // set the font for all + Font font=JFaceResources.getFont(FONT_DEFINITION); + ITerminalViewConnection[] conn=fMultiConnectionManager.getConnections(); + for (int i = 0; i < conn.length; i++) { + conn[i].getCtlTerminal().setFont(font); + } } // ViewPart interface @@ -362,25 +386,54 @@ // Bind plugin.xml key bindings to this plugin. Overrides global Control-W key // sequence. - setPartName(findUniqueTitle(ViewMessages.PROP_TITLE)); - setupControls(wndParent); + fPageBook=new PageBook(wndParent,SWT.NONE); + ISettingsStore s=new SettingStorePrefixDecorator(fStore,"connectionManager"); //$NON-NLS-1$ + fMultiConnectionManager.loadState(s,new ITerminalViewConnectionFactory() { + public ITerminalViewConnection create() { + return makeViewConnection(); + } + }); + // if there is no connection loaded, create at least one + // needed to read old states from the old terminal + if(fMultiConnectionManager.size()==0) { + ITerminalViewConnection conn = makeViewConnection(); + fMultiConnectionManager.addConnection(conn); + fMultiConnectionManager.setConnection(conn); + fPageBook.showPage(fCtlTerminal.getRootControl()); + } + setTerminalControl(fMultiConnectionManager.getCurrentConnection().getCtlTerminal()); + setViewTitle(findUniqueTitle(ViewMessages.PROP_TITLE)); setupActions(); setupLocalToolBars(); - setupContextMenus(); + // setup all context menus + ITerminalViewConnection[] conn=fMultiConnectionManager.getConnections(); + for (int i = 0; i < conn.length; i++) { + setupContextMenus(conn[i].getCtlTerminal().getControl()); + } setupListeners(wndParent); PlatformUI.getWorkbench().getHelpSystem().setHelp(wndParent, TerminalViewPlugin.HELPPREFIX + "terminal_page"); //$NON-NLS-1$ - onTerminalStatus(); + legacyLoadState(); + legacySetTitle(); + + refresh(); onTerminalFontChanged(); + } + public void dispose() { Logger.log("entered."); //$NON-NLS-1$ TerminalViewPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(fPreferenceListener); JFaceResources.getFontRegistry().removeListener(fPropertyChangeHandler); - fCtlTerminal.disposeTerminal(); + + // dispose all connections + ITerminalViewConnection[] conn=fMultiConnectionManager.getConnections(); + for (int i = 0; i < conn.length; i++) { + conn[i].getCtlTerminal().disposeTerminal(); + } super.dispose(); } /** @@ -393,24 +446,31 @@ /** * This method creates the top-level control for the Terminal view. */ - protected void setupControls(Composite wndParent) { - ITerminalConnector[] connectors = makeConnectors(); - fCtlTerminal = TerminalViewControlFactory.makeControl(this, wndParent, connectors); + protected void setupControls() { + ITerminalViewConnection conn = makeViewConnection(); + fMultiConnectionManager.addConnection(conn); + fMultiConnectionManager.setConnection(conn); + setupContextMenus(fCtlTerminal.getControl()); + } + private ITerminalViewConnection makeViewConnection() { + ITerminalConnector[] connectors = makeConnectors(); + TerminalListener listener=new TerminalListener(); + ITerminalViewControl ctrl = TerminalViewControlFactory.makeControl(listener, fPageBook, connectors); + setTerminalControl(ctrl); + ITerminalViewConnection conn = new TerminalViewConnection(fCtlTerminal); + listener.setConnection(conn); + conn.setPartName(getPartName()); String connectionType=fStore.get(STORE_CONNECTION_TYPE); for (int i = 0; i < connectors.length; i++) { connectors[i].load(getStore(connectors[i])); if(connectors[i].getId().equals(connectionType)) - fCtlTerminal.setConnector(connectors[i]); + ctrl.setConnector(connectors[i]); } - setCommandInputField("true".equals(fStore.get(STORE_HAS_COMMAND_INPUT_FIELD))); //$NON-NLS-1$ updatePreferences(); TerminalViewPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(fPreferenceListener); - - // restore the title of this view - String title=fStore.get(STORE_TITLE); - if(title!=null && title.length()>0) - setPartName(title); + + return conn; } /** @@ -434,15 +494,15 @@ public void init(IViewSite site, IMemento memento) throws PartInitException { super.init(site, memento); fStore=new SettingsStore(memento); + // have we stored the pinned status? + if(fStore.get(STORE_PINNED)!=null) + setPinned("true".equals(fStore.get(STORE_PINNED))); //$NON-NLS-1$ } - public void saveState(IMemento memento) { super.saveState(memento); - if(fCommandInputField!=null) - fStore.put(STORE_COMMAND_INPUT_FIELD_HISTORY, fCommandInputField.getHistory()); - fStore.put(STORE_HAS_COMMAND_INPUT_FIELD,hasCommandInputField()?"true":"false"); //$NON-NLS-1$//$NON-NLS-2$ - fStore.put(STORE_SETTING_SUMMARY, getSettingsSummary()); + fStore.put(STORE_PINNED, isPinned()?"true":"false"); //$NON-NLS-1$ //$NON-NLS-2$ fStore.put(STORE_TITLE,getPartName()); + fMultiConnectionManager.saveState(new SettingStorePrefixDecorator(fStore,"connectionManager")); //$NON-NLS-1$ fStore.saveState(memento); } private ISettingsStore getStore(ITerminalConnector connector) { @@ -450,36 +510,42 @@ } protected void setupActions() { + fActionTerminalDropDown = new TerminalActionSelectionDropDown(fMultiConnectionManager); + fActionTerminalPin=new TerminalActionPin(this); + fActionTerminalPin.setChecked(isPinned()); + fActionTerminalRemove=new TerminalActionRemove(fMultiConnectionManager); fActionTerminalNewTerminal = new TerminalActionNewTerminal(this); // fActionTerminalScrollLock = new TerminalActionScrollLock(this); fActionTerminalConnect = new TerminalActionConnect(this); fActionTerminalDisconnect = new TerminalActionDisconnect(this); fActionTerminalSettings = new TerminalActionSettings(this); - fActionEditCopy = new TerminalActionCopy(fCtlTerminal); - fActionEditCut = new TerminalActionCut(fCtlTerminal); - fActionEditPaste = new TerminalActionPaste(fCtlTerminal); - fActionEditClearAll = new TerminalActionClearAll(fCtlTerminal); - fActionEditSelectAll = new TerminalActionSelectAll(fCtlTerminal); + fActionEditCopy = new TerminalActionCopy(fCtlDecorator); + fActionEditCut = new TerminalActionCut(fCtlDecorator); + fActionEditPaste = new TerminalActionPaste(fCtlDecorator); + fActionEditClearAll = new TerminalActionClearAll(fCtlDecorator); + fActionEditSelectAll = new TerminalActionSelectAll(fCtlDecorator); fActionToggleCommandInputField = new TerminalActionToggleCommandInputField(this); } protected void setupLocalToolBars() { IToolBarManager toolBarMgr = getViewSite().getActionBars().getToolBarManager(); - toolBarMgr.add(fActionTerminalNewTerminal); // toolBarMgr.add(fActionTerminalScrollLock); toolBarMgr.add(fActionTerminalConnect); toolBarMgr.add(fActionTerminalDisconnect); toolBarMgr.add(fActionTerminalSettings); toolBarMgr.add(fActionToggleCommandInputField); + toolBarMgr.add(new Separator("fixedGroup")); //$NON-NLS-1$ + toolBarMgr.add(fActionTerminalPin); + toolBarMgr.add(fActionTerminalDropDown); + toolBarMgr.add(fActionTerminalNewTerminal); + toolBarMgr.add(fActionTerminalRemove); } - protected void setupContextMenus() { - Control ctlText; + protected void setupContextMenus(Control ctlText) { MenuManager menuMgr; Menu menu; TerminalContextMenuHandler contextMenuHandler; - ctlText = fCtlTerminal.getControl(); menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ menu = menuMgr.createContextMenu(ctlText); loadContextMenus(menuMgr); @@ -538,20 +604,11 @@ } public boolean hasCommandInputField() { - return fCommandInputField!=null; + return getCurrentConnection().hasCommandInputField(); } + public void setCommandInputField(boolean on) { - // save the old history - if(fCommandInputField!=null) { - fStore.put(STORE_COMMAND_INPUT_FIELD_HISTORY, fCommandInputField.getHistory()); - fCommandInputField=null; - } - if(on) { - // TODO make history size configurable - fCommandInputField=new CommandInputFieldWithHistory(100); - fCommandInputField.setHistory(fStore.get(STORE_COMMAND_INPUT_FIELD_HISTORY)); - } - fCtlTerminal.setCommandInputField(fCommandInputField); + getCurrentConnection().setCommandInputField(on); } public boolean isScrollLock() { @@ -561,4 +618,71 @@ public void setScrollLock(boolean on) { fCtlTerminal.setScrollLock(on); } + + private ITerminalViewConnection getCurrentConnection() { + return fMultiConnectionManager.getCurrentConnection(); + } + /** + * @param ctrl this control becomes the currently used one + */ + private void setTerminalControl(ITerminalViewControl ctrl) { + fCtlTerminal=ctrl; + fCtlDecorator.setViewContoler(ctrl); + } + public void connectionsChanged() { + if(getCurrentConnection()!=null) { + // update the current {@link ITerminalViewControl} + ITerminalViewControl ctrl = getCurrentConnection().getCtlTerminal(); + if(fCtlTerminal!=ctrl) { + setTerminalControl(ctrl); + refresh(); + } + } + } + + /** + * Show the current {@link ITerminalViewControl} in the view + */ + private void refresh() { + fPageBook.showPage(fCtlTerminal.getRootControl()); + updateStatus(); + setPartName(getCurrentConnection().getPartName()); + } + + public void setPinned(boolean pinned) { + fPinned=pinned; + } + public boolean isPinned() { + return fPinned; + } + + /** + * TODO REMOVE This code (added 2008-06-11) + * Legacy code to real the old state. Once the state of the + * terminal has been saved this method is not needed anymore. + * Remove this code with eclipse 3.5. + */ + private void legacyLoadState() { + // TODO legacy: load the old title.... + String summary=fStore.get(STORE_SETTING_SUMMARY); + if(summary!=null) { + getCurrentConnection().setSummary(summary); + fStore.put(STORE_SETTING_SUMMARY,null); + } + } + /** + * TODO REMOVE This code (added 2008-06-11) + * Legacy code to real the old state. Once the state of the + * terminal has been saved this method is not needed anymore. + * Remove this code with eclipse 3.5. + */ + private void legacySetTitle() { + // restore the title of this view + String title=fStore.get(STORE_TITLE); + if(title!=null && title.length()>0) { + setViewTitle(title); + fStore.put(STORE_TITLE, null); + } + } + } Index: src/org/eclipse/tm/internal/terminal/view/ITerminalView.java =================================================================== RCS file: /cvsroot/dsdp/org.eclipse.tm.core/terminal/org.eclipse.tm.terminal.view/src/org/eclipse/tm/internal/terminal/view/ITerminalView.java,v retrieving revision 1.5 diff -u -r1.5 ITerminalView.java --- src/org/eclipse/tm/internal/terminal/view/ITerminalView.java 25 Apr 2008 20:14:49 -0000 1.5 +++ src/org/eclipse/tm/internal/terminal/view/ITerminalView.java 13 Jun 2008 03:46:30 -0000 @@ -8,6 +8,7 @@ * Contributors: * Michael Scharf (Wind River) - initial API and implementation * Martin Oberhuber (Wind River) - [227537] moved actions from terminal.view to terminal plugin + * Michael Scharf (Wind River) - [172483] switch between connections *******************************************************************************/ package org.eclipse.tm.internal.terminal.view; @@ -26,4 +27,6 @@ public void setCommandInputField(boolean on); public boolean isScrollLock(); public void setScrollLock(boolean b); + public void setPinned(boolean pin); + public boolean isPinned(); } Index: src/org/eclipse/tm/internal/terminal/view/ImageConsts.java =================================================================== RCS file: /cvsroot/dsdp/org.eclipse.tm.core/terminal/org.eclipse.tm.terminal.view/src/org/eclipse/tm/internal/terminal/view/ImageConsts.java,v retrieving revision 1.5 diff -u -r1.5 ImageConsts.java --- src/org/eclipse/tm/internal/terminal/view/ImageConsts.java 25 Apr 2008 20:14:49 -0000 1.5 +++ src/org/eclipse/tm/internal/terminal/view/ImageConsts.java 13 Jun 2008 03:46:30 -0000 @@ -14,37 +14,40 @@ * Michael Scharf (Wind River) - extracted from TerminalConsts * Martin Oberhuber (Wind River) - fixed copyright headers and beautified * Anna Dushistova (MontaVista) - [227537] moved actions from terminal.view to terminal plugin + * Michael Scharf (Wind River) - [172483] added some more icons *******************************************************************************/ package org.eclipse.tm.internal.terminal.view; public interface ImageConsts { public final static String IMAGE_DIR_ROOT = "icons/"; //$NON-NLS-1$ - public final static String IMAGE_DIR_CTOOL = "ctool16/"; // basic colors - size 16x16 //$NON-NLS-1$ public final static String IMAGE_DIR_LOCALTOOL = "clcl16/"; // basic colors - size 16x16 //$NON-NLS-1$ public final static String IMAGE_DIR_DLCL = "dlcl16/"; // disabled - size 16x16 //$NON-NLS-1$ public final static String IMAGE_DIR_ELCL = "elcl16/"; // enabled - size 16x16 //$NON-NLS-1$ - public final static String IMAGE_DIR_OBJECT = "obj16/"; // basic colors - size 16x16 //$NON-NLS-1$ - public final static String IMAGE_DIR_WIZBAN = "wizban/"; // basic colors - size 16x16 //$NON-NLS-1$ - public final static String IMAGE_DIR_OVR = "ovr16/"; // basic colors - size 7x8 //$NON-NLS-1$ public final static String IMAGE_DIR_VIEW = "cview16/"; // views //$NON-NLS-1$ public final static String IMAGE_DIR_EVIEW = "eview16/"; // views //$NON-NLS-1$ public static final String IMAGE_NEW_TERMINAL = "TerminalViewNewTerminal"; //$NON-NLS-1$ + public static final String IMAGE_TERMINAL_VIEW = "TerminalView"; //$NON-NLS-1$ public static final String IMAGE_CLCL_CONNECT = "ImageClclConnect"; //$NON-NLS-1$ public static final String IMAGE_CLCL_DISCONNECT = "ImageClclDisconnect"; //$NON-NLS-1$ public static final String IMAGE_CLCL_SETTINGS = "ImageClclSettings"; //$NON-NLS-1$ public static final String IMAGE_CLCL_SCROLL_LOCK = "ImageClclScrollLock"; //$NON-NLS-1$ + public static final String IMAGE_CLCL_PIN = "ImageClclPin"; //$NON-NLS-1$ public static final String IMAGE_DLCL_CONNECT = "ImageDlclConnect"; //$NON-NLS-1$ public static final String IMAGE_DLCL_DISCONNECT = "ImageDlclDisconnect"; //$NON-NLS-1$ public static final String IMAGE_DLCL_SETTINGS = "ImageDlclSettings"; //$NON-NLS-1$ public static final String IMAGE_DLCL_SCROLL_LOCK = "ImageDlclScrollLock"; //$NON-NLS-1$ + public static final String IMAGE_DLCL_PIN = "ImageDlclPin"; //$NON-NLS-1$ + public static final String IMAGE_DLCL_REMOVE = "ImageDlclRemove"; //$NON-NLS-1$ public static final String IMAGE_ELCL_CONNECT = "ImageElclConnect"; //$NON-NLS-1$ public static final String IMAGE_ELCL_DISCONNECT = "ImageElclDisconnect"; //$NON-NLS-1$ public static final String IMAGE_ELCL_SETTINGS = "ImageElclSettings"; //$NON-NLS-1$ public static final String IMAGE_ELCL_SCROLL_LOCK = "ImageElclScrollLock"; //$NON-NLS-1$ + public static final String IMAGE_ELCL_PIN = "ImageElclPin"; //$NON-NLS-1$ + public static final String IMAGE_ELCL_REMOVE = "ImageElclRemove"; //$NON-NLS-1$ public static final String IMAGE_CLCL_COMMAND_INPUT_FIELD = "ImageClclCommandInputField";//$NON-NLS-1$ public static final String IMAGE_ELCL_COMMAND_INPUT_FIELD = "ImageDlclCommandInputField";//$NON-NLS-1$ public static final String IMAGE_DLCL_COMMAND_INPUT_FIELD = "ImageDlclCommandInputField";//$NON-NLS-1$ Index: src/org/eclipse/tm/internal/terminal/view/TerminalViewPlugin.java =================================================================== RCS file: /cvsroot/dsdp/org.eclipse.tm.core/terminal/org.eclipse.tm.terminal.view/src/org/eclipse/tm/internal/terminal/view/TerminalViewPlugin.java,v retrieving revision 1.8 diff -u -r1.8 TerminalViewPlugin.java --- src/org/eclipse/tm/internal/terminal/view/TerminalViewPlugin.java 7 May 2008 14:48:03 -0000 1.8 +++ src/org/eclipse/tm/internal/terminal/view/TerminalViewPlugin.java 13 Jun 2008 03:46:30 -0000 @@ -15,6 +15,7 @@ * Martin Oberhuber (Wind River) - fixed copyright headers and beautified * Anna Dushistova (MontaVista) - [227537] moved actions from terminal.view to terminal plugin * Martin Oberhuber (Wind River) - [168186] Add Terminal User Docs + * Michael Scharf (Wind River) - [172483] switch between connections *******************************************************************************/ package org.eclipse.tm.internal.terminal.view; @@ -53,6 +54,7 @@ map.put(ImageConsts.IMAGE_CLCL_SETTINGS, "properties_tsk.gif"); //$NON-NLS-1$ map.put(ImageConsts.IMAGE_CLCL_COMMAND_INPUT_FIELD, "command_input_field.gif"); //$NON-NLS-1$ map.put(ImageConsts.IMAGE_CLCL_SCROLL_LOCK, "lock_co.gif"); //$NON-NLS-1$ + map.put(ImageConsts.IMAGE_CLCL_PIN, "pin.gif"); //$NON-NLS-1$ loadImageRegistry(imageRegistry, ImageConsts.IMAGE_DIR_LOCALTOOL, map); @@ -65,7 +67,9 @@ map.put(ImageConsts.IMAGE_ELCL_SETTINGS, "properties_tsk.gif"); //$NON-NLS-1$ map.put(ImageConsts.IMAGE_ELCL_COMMAND_INPUT_FIELD, "command_input_field.gif"); //$NON-NLS-1$ map.put(ImageConsts.IMAGE_ELCL_SCROLL_LOCK, "lock_co.gif"); //$NON-NLS-1$ - + map.put(ImageConsts.IMAGE_ELCL_PIN, "pin.gif"); //$NON-NLS-1$ + map.put(ImageConsts.IMAGE_ELCL_REMOVE, "rem_co.gif"); //$NON-NLS-1$ + loadImageRegistry(imageRegistry, ImageConsts.IMAGE_DIR_ELCL, map); map.clear(); @@ -77,10 +81,19 @@ map.put(ImageConsts.IMAGE_DLCL_SETTINGS, "properties_tsk.gif"); //$NON-NLS-1$ map.put(ImageConsts.IMAGE_DLCL_COMMAND_INPUT_FIELD, "command_input_field.gif"); //$NON-NLS-1$ map.put(ImageConsts.IMAGE_DLCL_SCROLL_LOCK, "lock_co.gif"); //$NON-NLS-1$ + map.put(ImageConsts.IMAGE_DLCL_PIN, "pin.gif"); //$NON-NLS-1$ + map.put(ImageConsts.IMAGE_DLCL_REMOVE, "rem_co.gif"); //$NON-NLS-1$ loadImageRegistry(imageRegistry, ImageConsts.IMAGE_DIR_DLCL, map); map.clear(); + + map.put(ImageConsts.IMAGE_TERMINAL_VIEW, "terminal_view.gif"); //$NON-NLS-1$ + + loadImageRegistry(imageRegistry, ImageConsts.IMAGE_DIR_EVIEW, map); + + map.clear(); + } catch (MalformedURLException malformedURLException) { malformedURLException.printStackTrace(); } Index: src/org/eclipse/tm/internal/terminal/actions/ActionMessages.properties =================================================================== RCS file: /cvsroot/dsdp/org.eclipse.tm.core/terminal/org.eclipse.tm.terminal.view/src/org/eclipse/tm/internal/terminal/actions/ActionMessages.properties,v retrieving revision 1.5 diff -u -r1.5 ActionMessages.properties --- src/org/eclipse/tm/internal/terminal/actions/ActionMessages.properties 25 Apr 2008 20:14:49 -0000 1.5 +++ src/org/eclipse/tm/internal/terminal/actions/ActionMessages.properties 13 Jun 2008 03:46:30 -0000 @@ -14,6 +14,7 @@ # Michael Scharf (Wind River) - split into core, view and connector plugins # Martin Oberhuber (Wind River) - fixed copyright headers and beautified # Anna Dushistova (MontaVista) - [227537] moved actions from terminal.view to terminal plugin +# Michael Scharf (Wind River) - [172483] switch between connections ############################################################################### NEW_TERMINAL = New Terminal CONNECT = Connect @@ -23,3 +24,9 @@ SCROLL_LOCK_1 = Scroll Lock SETTINGS = Settings TOGGLE_COMMAND_INPUT_FIELD= Toggle Command Input Field +REMOVE = Remove Terminal +PIN = Pin Terminal + +ConsoleDropDownAction_0=Select Connection +ConsoleDropDownAction_1=Display Selected Connections + Index: src/org/eclipse/tm/internal/terminal/actions/ActionMessages.java =================================================================== RCS file: /cvsroot/dsdp/org.eclipse.tm.core/terminal/org.eclipse.tm.terminal.view/src/org/eclipse/tm/internal/terminal/actions/ActionMessages.java,v retrieving revision 1.5 diff -u -r1.5 ActionMessages.java --- src/org/eclipse/tm/internal/terminal/actions/ActionMessages.java 25 Apr 2008 20:14:48 -0000 1.5 +++ src/org/eclipse/tm/internal/terminal/actions/ActionMessages.java 13 Jun 2008 03:46:30 -0000 @@ -20,6 +20,7 @@ import org.eclipse.osgi.util.NLS; public class ActionMessages extends NLS { + static { NLS.initializeMessages(ActionMessages.class.getName(), ActionMessages.class); } @@ -30,6 +31,11 @@ public static String SETTINGS_ELLIPSE; public static String SCROLL_LOCK_0; public static String SCROLL_LOCK_1; + public static String REMOVE; + public static String PIN; + + public static String ConsoleDropDownAction_0; + public static String ConsoleDropDownAction_1; public static String SETTINGS; Index: src/org/eclipse/tm/internal/terminal/actions/TerminalActionPin.java =================================================================== RCS file: src/org/eclipse/tm/internal/terminal/actions/TerminalActionPin.java diff -N src/org/eclipse/tm/internal/terminal/actions/TerminalActionPin.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/tm/internal/terminal/actions/TerminalActionPin.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2008 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 + * + * Initial Contributors: + * The following Wind River employees contributed to the Terminal component + * that contains this file: Chris Thew, Fran Litterio, Stephen Lamb, + * Helmut Haigermoser and Ted Williams. + * + * Contributors: + * Michael Scharf (Wind River) - initial contribution + *******************************************************************************/ +package org.eclipse.tm.internal.terminal.actions; + +import org.eclipse.jface.action.IAction; +import org.eclipse.tm.internal.terminal.view.ITerminalView; +import org.eclipse.tm.internal.terminal.view.ImageConsts; + +public class TerminalActionPin extends TerminalAction +{ + public TerminalActionPin(ITerminalView target) + { + super(target, + TerminalActionPin.class.getName(),IAction.AS_RADIO_BUTTON); + + setupAction(ActionMessages.PIN, + ActionMessages.PIN, + ImageConsts.IMAGE_CLCL_PIN, + ImageConsts.IMAGE_ELCL_PIN, + ImageConsts.IMAGE_DLCL_PIN, + true); + setChecked(fTarget.isPinned()); + } + public void run() { + fTarget.setPinned(!fTarget.isPinned()); + setChecked(fTarget.isPinned()); + } +} Index: src/org/eclipse/tm/internal/terminal/actions/ShowConsoleAction.java =================================================================== RCS file: src/org/eclipse/tm/internal/terminal/actions/ShowConsoleAction.java diff -N src/org/eclipse/tm/internal/terminal/actions/ShowConsoleAction.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/tm/internal/terminal/actions/ShowConsoleAction.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2008 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: + * Michael Scharf (Wind River) - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.internal.terminal.actions; + +import org.eclipse.jface.action.Action; +import org.eclipse.tm.internal.terminal.view.ITerminalViewConnection; +import org.eclipse.tm.internal.terminal.view.ITerminalViewConnectionManager; + +/** + * Shows a specific console in the console view + */ +public class ShowConsoleAction extends Action { + + private final ITerminalViewConnection fConnection; + private final ITerminalViewConnectionManager fConnectionManager; + + /** + * Constructs an action to display the given console. + * + * @param manager the console view in which the given console is contained + * @param console the console + */ + public ShowConsoleAction(ITerminalViewConnectionManager manager, ITerminalViewConnection console) { + super(quoteName(buildName(manager,console)), AS_RADIO_BUTTON); + fConnection = console; + fConnectionManager = manager; + setImageDescriptor(console.getImageDescriptor()); + } + /** + * the tab at the end quotes '@' chars?!? see + * {@link #setText(String)} + * @param name + * @return a quoted sting + */ + private static String quoteName(String name) { + return name+"\t"; //$NON-NLS-1$ + } + /** + * Builds the name. It uses the summary. If the connections have different + * partNames (the names showed in the view title) then this name is perfixed. + * @param m the connection manager + * @param console the console for which the name should me extracted + * @return The name to be displayed + */ + private static String buildName(ITerminalViewConnectionManager m,ITerminalViewConnection console) { + String name = console.getFullSummary(); + if(!checkIfAllPartNamesTheSame(m)) + name=console.getPartName()+" - " +name; //$NON-NLS-1$ + return name; + } + /** + * @param m the connection manager + * @return true if the part names of all connections are the same + */ + private static boolean checkIfAllPartNamesTheSame(ITerminalViewConnectionManager m) { + ITerminalViewConnection[] connections = m.getConnections(); + if(connections.length>1) { + String partName=connections[0].getPartName(); + for (int i = 1; i < connections.length; i++) { + if(!partName.equals(connections[i].getPartName())) { + return false; + } + } + + } + return true; + } + /* (non-Javadoc) + * @see org.eclipse.jface.action.IAction#run() + */ + public void run() { + fConnectionManager.setConnection(fConnection); + } +} Index: src/org/eclipse/tm/internal/terminal/view/ITerminalViewConnectionManager.java =================================================================== RCS file: src/org/eclipse/tm/internal/terminal/view/ITerminalViewConnectionManager.java diff -N src/org/eclipse/tm/internal/terminal/view/ITerminalViewConnectionManager.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/tm/internal/terminal/view/ITerminalViewConnectionManager.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2008 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: + * Michael Scharf (Wind River) - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.internal.terminal.view; + +import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore; + + +/** + * Supports multiple connections + * + */ +public interface ITerminalViewConnectionManager { + /** + * Notifies any change in the state of the connections: + * + * + */ + interface TerminalViewConnectionListener { + void connectionsChanged(); + } + /** + * Used to create instances of the ITerminalViewConnection + * when the state is read from the {@link ISettingsStore} + * + */ + interface ITerminalViewConnectionFactory { + ITerminalViewConnection create(); + } + /** + * @return a list of all connections this view can display + */ + ITerminalViewConnection[] getConnections(); + /** + * If more than two connections are available, remove the current connection + */ + void removeCurrent(); + + /** + * @param conn adds a new connection + */ + void addConnection(ITerminalViewConnection conn); + /** + * @return the number of connections + */ + int size(); + /** + * @return th connection the view is showing at the moment + */ + ITerminalViewConnection getCurrentConnection(); + + /** + * @param conn make this connection the current connection + */ + void setConnection(ITerminalViewConnection conn); + + /** + * If there are more than two connections toggle between this and the + * previously shown connection + */ + void swapConnection(); + + void addListener(TerminalViewConnectionListener listener); + void removeListener(TerminalViewConnectionListener listener); + + void saveState(ISettingsStore store); + /** + * @param store + */ + void loadState(ISettingsStore store,ITerminalViewConnectionFactory factory); + +} Index: src/org/eclipse/tm/internal/terminal/view/ITerminalViewConnection.java =================================================================== RCS file: src/org/eclipse/tm/internal/terminal/view/ITerminalViewConnection.java diff -N src/org/eclipse/tm/internal/terminal/view/ITerminalViewConnection.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/tm/internal/terminal/view/ITerminalViewConnection.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2008 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: + * Michael Scharf (Wind River) - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.internal.terminal.view; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.tm.internal.terminal.control.ITerminalViewControl; +import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore; +import org.eclipse.tm.internal.terminal.provisional.api.TerminalState; + +/** + * Represents a connection. The connection might be connected + * or not. + * + */ +public interface ITerminalViewConnection { + + /** + * @return the summary shown in the status line and + * in the drop down box of the connections + */ + String getFullSummary(); + + /** + * @param name the name of the view + */ + void setPartName(String name); + /** + * @return the name of the view (never null) + */ + String getPartName(); + + /** + * @return an image that represents this connection + */ + ImageDescriptor getImageDescriptor(); + /** + * @return the control of this connection + */ + ITerminalViewControl getCtlTerminal(); + + void saveState(ISettingsStore store); + + void loadState(ISettingsStore store); + + /** + * @return true if the input field is visible + */ + boolean hasCommandInputField(); + /** + * @param on turns the input field on + */ + void setCommandInputField(boolean on); + + /** + * @param state changes of the state (might change the summary) + */ + void setState(TerminalState state); + + /** + * @param title used in the summary. If null the summary + * is created automatically + */ + void setTerminalTitle(String title); + + /** + * TODO: legacy (needed to read the old state) + * @param summary + */ + void setSummary(String summary); +} Index: src/org/eclipse/tm/internal/terminal/view/TerminalViewConnectionManager.java =================================================================== RCS file: src/org/eclipse/tm/internal/terminal/view/TerminalViewConnectionManager.java diff -N src/org/eclipse/tm/internal/terminal/view/TerminalViewConnectionManager.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/tm/internal/terminal/view/TerminalViewConnectionManager.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,180 @@ +/******************************************************************************* + * Copyright (c) 2008 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: + * Michael Scharf (Wind River) - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.internal.terminal.view; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore; + +public class TerminalViewConnectionManager implements ITerminalViewConnectionManager { + private static final String STORE_CONNECTION_PREFIX = "c"; //$NON-NLS-1$ + private static final String STORE_SIZE = "size"; //$NON-NLS-1$ + private static final String STORE_CURRENT_CONNECTION = "current"; //$NON-NLS-1$ + /** + * The list of {@link ITerminalViewConnection} in the order they were cerated. + * Ordered by creation time + */ + private final List fConnections=new ArrayList(); + /** + * The currently displayed connection + */ + private ITerminalViewConnection fCurrentConnection; + /** + * The list of {@link ITerminalViewConnection} in the order they + * were made the current connection. The most recently accessed + * connection is at the beginning of the list. + */ + private final List fConnectionHistory=new ArrayList(); + /** + * The {@link TerminalViewConnectionListener} + */ + private final List fListeners=new ArrayList(); + + public ITerminalViewConnection[] getConnections() { + return (ITerminalViewConnection[]) fConnections.toArray(new ITerminalViewConnection[fConnections.size()]); + } + + public int size() { // TODO Auto-generated method stub + return fConnections.size(); + } + + public ITerminalViewConnection getCurrentConnection() { + return fCurrentConnection; + } + public void setConnection(ITerminalViewConnection conn) { + fCurrentConnection=conn; + // put the connection at the end of the history list + fConnectionHistory.remove(conn); + fConnectionHistory.add(0,conn); + + fireListeners(); + } + + public void swapConnection() { + ITerminalViewConnection conn=getPreviousConnection(); + if(conn!=null) + setConnection(conn); + } + + /** + * @return the connection that was most recently the current connection or null if there is + * no previous connection + */ + private ITerminalViewConnection getPreviousConnection() { + // find the first connection that is not the current connection in + // the list + for (Iterator iterator = fConnectionHistory.iterator(); iterator.hasNext();) { + ITerminalViewConnection conn = (ITerminalViewConnection) iterator.next(); + if(conn!=fCurrentConnection) { + return conn; + } + } + return null; + } + + public void addConnection(ITerminalViewConnection conn) { + fConnections.add(conn); + fireListeners(); + } + public void removeConnection(ITerminalViewConnection conn) { + fConnections.remove(conn); + fConnectionHistory.remove(conn); + fireListeners(); + } + + public void addListener(TerminalViewConnectionListener listener) { + fListeners.add(listener); + } + + public void removeListener(TerminalViewConnectionListener listener) { + fListeners.remove(listener); + } + protected void fireListeners() { + TerminalViewConnectionListener[] listeners=(TerminalViewConnectionListener[]) fListeners.toArray(new TerminalViewConnectionListener[fListeners.size()]); + for (int i = 0; i < listeners.length; i++) { + listeners[i].connectionsChanged(); + } + } + + public void saveState(ISettingsStore store) { + store.put(STORE_SIZE,""+fConnections.size()); //$NON-NLS-1$ + // save all connections + int n=0; + for (Iterator iterator = fConnections.iterator(); iterator.hasNext();) { + // the name under which we store the connection + String prefix=STORE_CONNECTION_PREFIX+n; + n++; + ITerminalViewConnection connection = (ITerminalViewConnection) iterator.next(); + // remember the current connection by its prefix + if(connection.equals(fCurrentConnection)) + store.put(STORE_CURRENT_CONNECTION,prefix); + connection.saveState(new SettingStorePrefixDecorator(store,prefix)); + } + } + + public void loadState(ISettingsStore store,ITerminalViewConnectionFactory factory) { + int size=0; + try { + size=Integer.parseInt(store.get(STORE_SIZE)); + } catch(Exception e) { + // ignore + } + if(size>0) { + // a slot for the connections + String current=store.get(STORE_CURRENT_CONNECTION); + int n=0; + for (int i=0;i1) { + fConnections.remove(fCurrentConnection); + fConnectionHistory.remove(fCurrentConnection); + + // make sure connection is not null.... + fCurrentConnection=getPreviousConnection(); + // if there is no previous connection then make + // the first connection the list the current connection + if(fCurrentConnection==null) + fCurrentConnection=(ITerminalViewConnection) fConnections.get(0); + + fireListeners(); + } + } +} Index: src/org/eclipse/tm/internal/terminal/view/TerminalViewConnection.java =================================================================== RCS file: src/org/eclipse/tm/internal/terminal/view/TerminalViewConnection.java diff -N src/org/eclipse/tm/internal/terminal/view/TerminalViewConnection.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/tm/internal/terminal/view/TerminalViewConnection.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,190 @@ +/******************************************************************************* + * Copyright (c) 20078 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: + * Michael Scharf (Wind River) - initial API and implementation + *******************************************************************************/ +/** + * + */ +package org.eclipse.tm.internal.terminal.view; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.tm.internal.terminal.control.CommandInputFieldWithHistory; +import org.eclipse.tm.internal.terminal.control.ITerminalViewControl; +import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore; +import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector; +import org.eclipse.tm.internal.terminal.provisional.api.TerminalState; + +/** + * This class represents one connection. The connection might be + * closed or open. + * + */ +class TerminalViewConnection implements ITerminalViewConnection { + private static final String STORE_SUMMARY = "Summary"; //$NON-NLS-1$ + private static final String STORE_PART_NAME = "PartName"; //$NON-NLS-1$ + private static final String STORE_CONNECTION_TYPE = "ConnectionType"; //$NON-NLS-1$ + private static final String STORE_HAS_COMMAND_INPUT_FIELD = "HasCommandInputField"; //$NON-NLS-1$ + private static final String STORE_COMMAND_INPUT_FIELD_HISTORY = "CommandInputFieldHistory"; //$NON-NLS-1$ + + final private ITerminalViewControl fCtlTerminal; + private String fTitle; + private String fSummary; + private String fHistory; + private CommandInputFieldWithHistory fCommandInputField; + private String fPartName; + + public TerminalViewConnection(ITerminalViewControl ctl) { + fCtlTerminal = ctl; + } + + /* (non-Javadoc) + * @see org.eclipse.tm.internal.terminal.actions.ITerminalViewConnection#getName() + */ + public String getFullSummary() { + if(fTitle==null) + return makeTitle(); + return fTitle; + } + + /* (non-Javadoc) + * @see org.eclipse.tm.internal.terminal.view.ITerminalViewConnection#getImageDescriptor() + */ + public ImageDescriptor getImageDescriptor() { + return TerminalViewPlugin.getDefault().getImageRegistry().getDescriptor(ImageConsts.IMAGE_TERMINAL_VIEW); + } + + public ITerminalViewControl getCtlTerminal() { + return fCtlTerminal; + } + private ISettingsStore getStore(ISettingsStore store,ITerminalConnector connector) { + return new SettingStorePrefixDecorator(store,connector.getId()+"."); //$NON-NLS-1$ + } + public void loadState(ISettingsStore store) { + fPartName=store.get(STORE_PART_NAME); + fSummary=store.get(STORE_SUMMARY); + fHistory=store.get(STORE_COMMAND_INPUT_FIELD_HISTORY); + ITerminalConnector[] connectors=fCtlTerminal.getConnectors(); + String connectionType=store.get(STORE_CONNECTION_TYPE); + for (int i = 0; i < connectors.length; i++) { + connectors[i].load(getStore(store,connectors[i])); + if(connectors[i].getId().equals(connectionType)) + fCtlTerminal.setConnector(connectors[i]); + } + if("true".equals(store.get(STORE_HAS_COMMAND_INPUT_FIELD))) //$NON-NLS-1$ + setCommandInputField(true); + } + + public void saveState(ISettingsStore store) { + store.put(STORE_PART_NAME, fPartName); + store.put(STORE_SUMMARY,fSummary); + store.put(STORE_COMMAND_INPUT_FIELD_HISTORY, fHistory); + if(fCommandInputField!=null) + store.put(STORE_COMMAND_INPUT_FIELD_HISTORY, fCommandInputField.getHistory()); + else + store.put(STORE_COMMAND_INPUT_FIELD_HISTORY, fHistory); + store.put(STORE_HAS_COMMAND_INPUT_FIELD,hasCommandInputField()?"true":"false"); //$NON-NLS-1$//$NON-NLS-2$ + ITerminalConnector[] connectors=fCtlTerminal.getConnectors(); + for (int i = 0; i < connectors.length; i++) { + connectors[i].save(getStore(store,connectors[i])); + } + if(fCtlTerminal.getTerminalConnector()!=null) { + store.put(STORE_CONNECTION_TYPE,fCtlTerminal.getTerminalConnector().getId()); + } + } + public boolean hasCommandInputField() { + return fCommandInputField!=null; + } + public void setCommandInputField(boolean on) { + // save the old history + if(fCommandInputField!=null) { + fHistory= fCommandInputField.getHistory(); + fCommandInputField=null; + } + if(on) { + // TODO make history size configurable + fCommandInputField=new CommandInputFieldWithHistory(100); + fCommandInputField.setHistory(fHistory); + } + fCtlTerminal.setCommandInputField(fCommandInputField); + } + + public void setState(TerminalState state) { + // update the title.... + fTitle=null; + } + + public void setTerminalTitle(String title) { + // When parameter 'title' is not null, it is a String containing text to + // display in the view's content description line. This is used by class + // TerminalText when it processes an ANSI OSC escape sequence that commands + // the terminal to display text in its title bar. + fTitle=title; + } + + private String getStateDisplayName(TerminalState state) { + if(state==TerminalState.CONNECTED) { + return ViewMessages.STATE_CONNECTED; + } else if(state==TerminalState.CONNECTING) { + return ViewMessages.STATE_CONNECTING; + } else if(state==TerminalState.OPENED) { + return ViewMessages.STATE_OPENED; + } else if(state==TerminalState.CLOSED) { + return ViewMessages.STATE_CLOSED; + } else { + throw new IllegalStateException(state.toString()); + } + } + + private String makeTitle() { + String strTitle = ""; //$NON-NLS-1$ + if(fCtlTerminal.getTerminalConnector()==null){ + strTitle=ViewMessages.NO_CONNECTION_SELECTED; + } else { + // When parameter 'data' is null, we construct a descriptive string to + // display in the content description line. + String strConnected = getStateDisplayName(fCtlTerminal.getState()); + String summary = getSettingsSummary(); + //TODO Title should use an NLS String and com.ibm.icu.MessageFormat + //In order to make the logic of assembling, and the separators, better adapt to foreign languages + if(summary.length()>0) + summary=summary+" - "; //$NON-NLS-1$ + String name=fCtlTerminal.getTerminalConnector().getName(); + if(name.length()>0) { + name+=": "; //$NON-NLS-1$ + } + strTitle = name + "("+ summary + strConnected + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + } + return strTitle; + } + /** + * @return the setting summary. If there is no connection, or the connection + * has not been initialized, use the last stored state. + */ + private String getSettingsSummary() { + if(fCtlTerminal.getTerminalConnector().isInitialized()) + fSummary=fCtlTerminal.getSettingsSummary(); + if(fSummary==null) + return ""; //$NON-NLS-1$ + return fSummary; + } + + public void setSummary(String summary) { + fSummary=summary; + } + + public String getPartName() { + return fPartName==null?ViewMessages.PROP_TITLE:fPartName; + } + + public void setPartName(String name) { + fPartName=name; + + } + +} Index: src/org/eclipse/tm/internal/terminal/actions/TerminalActionRemove.java =================================================================== RCS file: src/org/eclipse/tm/internal/terminal/actions/TerminalActionRemove.java diff -N src/org/eclipse/tm/internal/terminal/actions/TerminalActionRemove.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/tm/internal/terminal/actions/TerminalActionRemove.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2008 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 + * + * Initial Contributors: + * The following Wind River employees contributed to the Terminal component + * that contains this file: Chris Thew, Fran Litterio, Stephen Lamb, + * Helmut Haigermoser and Ted Williams. + * + * Contributors: + * Michael Scharf (Wind River) - initial contribution + *******************************************************************************/ +package org.eclipse.tm.internal.terminal.actions; + +import org.eclipse.tm.internal.terminal.view.ITerminalViewConnectionManager; +import org.eclipse.tm.internal.terminal.view.ImageConsts; +import org.eclipse.tm.internal.terminal.view.ITerminalViewConnectionManager.TerminalViewConnectionListener; + +public class TerminalActionRemove extends TerminalAction implements TerminalViewConnectionListener +{ + private final ITerminalViewConnectionManager fConnectionManager; + public TerminalActionRemove(ITerminalViewConnectionManager target) + { + super(null, + TerminalActionRemove.class.getName()); + fConnectionManager=target; + setupAction(ActionMessages.REMOVE, + ActionMessages.REMOVE, + null, + ImageConsts.IMAGE_ELCL_REMOVE, + ImageConsts.IMAGE_DLCL_REMOVE, + true); + fConnectionManager.addListener(this); + connectionsChanged(); + } + public void run() { + fConnectionManager.removeCurrent(); + } + public void connectionsChanged() { + setEnabled(fConnectionManager.size()>1); + } +} Index: src/org/eclipse/tm/internal/terminal/actions/TerminalActionSelectionDropDown.java =================================================================== RCS file: src/org/eclipse/tm/internal/terminal/actions/TerminalActionSelectionDropDown.java diff -N src/org/eclipse/tm/internal/terminal/actions/TerminalActionSelectionDropDown.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/tm/internal/terminal/actions/TerminalActionSelectionDropDown.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + * Michael Scharf (Wind River) - [172483] switch between connections + * (Adapted from org.eclipse.ui.internal.console.ConsoleDropDownAction) + *******************************************************************************/ +package org.eclipse.tm.internal.terminal.actions; + + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.ActionContributionItem; +import org.eclipse.jface.action.IMenuCreator; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.tm.internal.terminal.view.ITerminalViewConnection; +import org.eclipse.tm.internal.terminal.view.ITerminalViewConnectionManager; +import org.eclipse.tm.internal.terminal.view.ImageConsts; +import org.eclipse.tm.internal.terminal.view.TerminalViewPlugin; +import org.eclipse.tm.internal.terminal.view.ITerminalViewConnectionManager.TerminalViewConnectionListener; + +/** + * Drop down action in the console to select the console to display. + */ +public class TerminalActionSelectionDropDown extends Action implements IMenuCreator, TerminalViewConnectionListener { + private ITerminalViewConnectionManager fConnections; + private Menu fMenu; + public TerminalActionSelectionDropDown(ITerminalViewConnectionManager view) { + fConnections= view; + setText(ActionMessages.ConsoleDropDownAction_0); + setToolTipText(ActionMessages.ConsoleDropDownAction_1); + setImageDescriptor(TerminalViewPlugin.getDefault().getImageRegistry().getDescriptor(ImageConsts.IMAGE_TERMINAL_VIEW)); +// PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IConsoleHelpContextIds.CONSOLE_DISPLAY_CONSOLE_ACTION); + setMenuCreator(this); + fConnections.addListener(this); + connectionsChanged(); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.action.IMenuCreator#dispose() + */ + public void dispose() { + if (fMenu != null) { + fMenu.dispose(); + } + fConnections.removeListener(this); + fConnections= null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Menu) + */ + public Menu getMenu(Menu parent) { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Control) + */ + public Menu getMenu(Control parent) { + if (fMenu != null) { + fMenu.dispose(); + } + + fMenu= new Menu(parent); + ITerminalViewConnection[] consoles= fConnections.getConnections(); + ITerminalViewConnection current = fConnections.getCurrentConnection(); + for (int i = 0; i < consoles.length; i++) { + ITerminalViewConnection console = consoles[i]; + Action action = new ShowConsoleAction(fConnections, console); + action.setChecked(console.equals(current)); + addActionToMenu(fMenu, action, i + 1); + } + return fMenu; + } + + private void addActionToMenu(Menu parent, Action action, int accelerator) { + if (accelerator < 10) { + StringBuffer label= new StringBuffer(); + //add the numerical accelerator + label.append('&'); + label.append(accelerator); + label.append(' '); + label.append(action.getText()); + action.setText(label.toString()); + } + ActionContributionItem item= new ActionContributionItem(action); + item.fill(parent, -1); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.action.IAction#run() + */ + public void run() { + fConnections.swapConnection(); + } + + public void connectionsChanged() { + ITerminalViewConnection[] consoles= fConnections.getConnections(); + setEnabled(consoles.length > 1); + } +} Index: src/org/eclipse/tm/internal/terminal/view/TerminalViewControlDecorator.java =================================================================== RCS file: src/org/eclipse/tm/internal/terminal/view/TerminalViewControlDecorator.java diff -N src/org/eclipse/tm/internal/terminal/view/TerminalViewControlDecorator.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/tm/internal/terminal/view/TerminalViewControlDecorator.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,167 @@ +/******************************************************************************* + * Copyright (c) 2007 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: + * Michael Scharf (Wind River) - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.internal.terminal.view; + +import java.io.UnsupportedEncodingException; + +import org.eclipse.swt.dnd.Clipboard; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.widgets.Control; +import org.eclipse.tm.internal.terminal.control.ICommandInputField; +import org.eclipse.tm.internal.terminal.control.ITerminalViewControl; +import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector; +import org.eclipse.tm.internal.terminal.provisional.api.TerminalState; + +// TODO (scharf): this decorator is only there to deal wit the common +// actions. Find a better solution. +public class TerminalViewControlDecorator implements ITerminalViewControl { + ITerminalViewControl fViewContoler; + + public void clearTerminal() { + fViewContoler.clearTerminal(); + } + + public void connectTerminal() { + fViewContoler.connectTerminal(); + } + + public void copy() { + fViewContoler.copy(); + } + + public void disconnectTerminal() { + fViewContoler.disconnectTerminal(); + } + + public void disposeTerminal() { + fViewContoler.disposeTerminal(); + } + + public int getBufferLineLimit() { + return fViewContoler.getBufferLineLimit(); + } + + public Clipboard getClipboard() { + return fViewContoler.getClipboard(); + } + + public ICommandInputField getCommandInputField() { + return fViewContoler.getCommandInputField(); + } + + public ITerminalConnector[] getConnectors() { + return fViewContoler.getConnectors(); + } + + public Control getControl() { + return fViewContoler.getControl(); + } + + public String getEncoding() { + return fViewContoler.getEncoding(); + } + + public Font getFont() { + return fViewContoler.getFont(); + } + + public Control getRootControl() { + return fViewContoler.getRootControl(); + } + + public String getSelection() { + return fViewContoler.getSelection(); + } + + public String getSettingsSummary() { + return fViewContoler.getSettingsSummary(); + } + + public TerminalState getState() { + return fViewContoler.getState(); + } + + public ITerminalConnector getTerminalConnector() { + return fViewContoler.getTerminalConnector(); + } + + public boolean isConnected() { + return fViewContoler.isConnected(); + } + + public boolean isDisposed() { + return fViewContoler.isDisposed(); + } + + public boolean isEmpty() { + return fViewContoler.isEmpty(); + } + + public boolean isScrollLock() { + return fViewContoler.isScrollLock(); + } + + public void paste() { + fViewContoler.paste(); + } + + public boolean pasteString(String string) { + return fViewContoler.pasteString(string); + } + + public void selectAll() { + fViewContoler.selectAll(); + } + + public void sendKey(char arg0) { + fViewContoler.sendKey(arg0); + } + + public void setBufferLineLimit(int bufferLineLimit) { + fViewContoler.setBufferLineLimit(bufferLineLimit); + } + + public void setCommandInputField(ICommandInputField inputField) { + fViewContoler.setCommandInputField(inputField); + } + + public void setConnector(ITerminalConnector connector) { + fViewContoler.setConnector(connector); + } + + public void setEncoding(String encoding) throws UnsupportedEncodingException { + fViewContoler.setEncoding(encoding); + } + + public void setFocus() { + fViewContoler.setFocus(); + } + + public void setFont(Font font) { + fViewContoler.setFont(font); + } + + public void setInvertedColors(boolean invert) { + fViewContoler.setInvertedColors(invert); + } + + public void setScrollLock(boolean on) { + fViewContoler.setScrollLock(on); + } + + public ITerminalViewControl getViewContoler() { + return fViewContoler; + } + + public void setViewContoler(ITerminalViewControl viewContoler) { + fViewContoler = viewContoler; + } +}