From 41ac47d732eed8392d60d0f6773e5a279d49b999 Mon Sep 17 00:00:00 2001 From: Adrian Dudau Date: Thu, 12 Dec 2013 13:36:50 +0100 Subject: initial commit of Enea Linux 3.1 Migrated from the internal git server on the dora-enea branch Signed-off-by: Adrian Dudau --- .../yocto/sdk/remotetools/views/BaseFileView.java | 140 +++++++ .../sdk/remotetools/views/TerminalViewTab.java | 457 +++++++++++++++++++++ .../sdk/remotetools/views/TerminalViewer.java | 139 +++++++ 3 files changed, 736 insertions(+) create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/BaseFileView.java create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/TerminalViewTab.java create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/TerminalViewer.java (limited to 'plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views') diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/BaseFileView.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/BaseFileView.java new file mode 100644 index 0000000..a5801c7 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/BaseFileView.java @@ -0,0 +1,140 @@ +/******************************************************************************* + * Copyright (c) 2010 Intel Corporation. + * 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: + * Intel - initial API and implementation + *******************************************************************************/ +package org.yocto.sdk.remotetools.views; + + +import java.io.BufferedReader; +import java.io.FileReader; +import java.util.ArrayList; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.part.*; +import org.eclipse.jface.viewers.*; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.*; +import org.eclipse.swt.SWT; + + +/** + * This sample class demonstrates how to plug-in a new + * workbench view. The view shows data obtained from the + * model. The sample creates a dummy model on the fly, + * but a real implementation would connect to the model + * available either in this or another plug-in (e.g. the workspace). + * The view is connected to the model using a content provider. + *

+ * The view uses a label provider to define how model + * objects should be presented in the view. Each + * view can present the same model objects using + * different labels and icons, if needed. Alternatively, + * a single label provider can be shared between views + * in order to ensure that objects of the same type are + * presented in the same way everywhere. + *

+ */ + +public class BaseFileView extends ViewPart { + + /** + * The ID of the view as specified by the extension. + */ + public static final String ID = "org.yocto.sdk.remotetools.views.BaseFileView"; + + private TableViewer viewer; + + private String filename; + + /* + * The content provider class is responsible for + * providing objects to the view. It can wrap + * existing objects in adapters or simply return + * objects as-is. These objects may be sensitive + * to the current input of the view, or ignore + * it and always show the same content + * (like Task List, for example). + */ + + class ViewContentProvider implements IStructuredContentProvider { + public void inputChanged(Viewer v, Object oldInput, Object newInput) { + if(newInput instanceof String) + filename=(String)newInput; + } + public void dispose() { + } + public Object[] getElements(Object parent) { + ArrayList elements=new ArrayList (); + BufferedReader in; + String line; + try { + in=new BufferedReader(new FileReader(filename)); + }catch (Exception e) { + return new String [] {"Invalid file " + filename}; + } + + try { + do { + line=in.readLine(); + if(line!=null) + elements.add(line); + }while(line!=null); + }catch (Exception e) { + e.printStackTrace(); + } + return (String[]) elements.toArray(new String[elements.size()]); + } + } + class ViewLabelProvider extends LabelProvider implements ITableLabelProvider { + public String getColumnText(Object obj, int index) { + return getText(obj); + } + public Image getColumnImage(Object obj, int index) { + //return getImage(obj); + return null; + } + public Image getImage(Object obj) { + return PlatformUI.getWorkbench(). + getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT); + } + } + + /** + * The constructor. + */ + public BaseFileView() { + } + + public BaseFileView(String file) { + this(); + this.filename=file; + } + + /** + * This is a callback that will allow us + * to create the viewer and initialize it. + */ + public void createPartControl(Composite parent) { + viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); + viewer.setContentProvider(new ViewContentProvider()); + viewer.setLabelProvider(new ViewLabelProvider()); + viewer.setInput(filename); + } + + public void setInput(String filename) { + viewer.setInput(filename); + } + + /** + * Passing the focus request to the viewer's control. + */ + public void setFocus() { + viewer.getControl().setFocus(); + } +} \ No newline at end of file diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/TerminalViewTab.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/TerminalViewTab.java new file mode 100644 index 0000000..bbb2d02 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/TerminalViewTab.java @@ -0,0 +1,457 @@ +/******************************************************************************* + * Copyright (c) 2002, 2009 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 + * + * Initial Contributors: + * The following IBM employees contributed to the Remote System Explorer + * component that contains this file: David McKnight, Kushal Munir, + * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, + * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. + * + * Contributors: + * David McKnight (IBM) - [165680] "Show in Remote Shell View" does not work + * Yu-Fen Kuo (MontaVista) - Adapted from CommandsViewWorkbook + * Anna Dushistova (MontaVista) - Adapted from CommandsViewWorkbook + * Yu-Fen Kuo (MontaVista) - [227572] RSE Terminal doesn't reset the "connected" state when the shell exits + * Martin Oberhuber (Wind River) - [227571] RSE Terminal should honor Encoding set on the IHost + * Michael Scharf (Wind River) - [236203] [rseterminal] Potentially UI blocking code in TerminalViewTab.createTabItem + * Anna Dushistova (MontaVista) - [244437] [rseterminal] Possible race condition when multiple Terminals are launched after each other + * Martin Oberhuber (Wind River) - [247700] Terminal uses ugly fonts in JEE package + * Anna Dushistova (MontaVista) - [267609] [rseterminal] The first "Launch Terminal" command creates no terminal tab + ********************************************************************************/ +package org.yocto.sdk.remotetools.views; + +import java.io.UnsupportedEncodingException; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.resource.FontRegistry; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.rse.core.model.IHost; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CTabFolder; +import org.eclipse.swt.custom.CTabItem; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.MenuEvent; +import org.eclipse.swt.events.MenuListener; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.tm.internal.terminal.control.ITerminalListener; +import org.eclipse.tm.internal.terminal.control.ITerminalViewControl; +import org.eclipse.tm.internal.terminal.control.TerminalViewControlFactory; +import org.eclipse.tm.internal.terminal.control.actions.TerminalActionClearAll; +import org.eclipse.tm.internal.terminal.control.actions.TerminalActionCopy; +import org.eclipse.tm.internal.terminal.control.actions.TerminalActionCut; +import org.eclipse.tm.internal.terminal.control.actions.TerminalActionPaste; +import org.eclipse.tm.internal.terminal.control.actions.TerminalActionSelectAll; +import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector; +import org.eclipse.tm.internal.terminal.provisional.api.TerminalState; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.themes.IThemeManager; + +/** + * This is the desktop view wrapper of the System View viewer. + */ +public class TerminalViewTab extends Composite { + + public static String DATA_KEY_CONTROL = "$_control_$"; //$NON-NLS-1$ + + private final CTabFolder tabFolder; + + private IPropertyChangeListener propertyChangeListener; + + private Menu menu; + + private boolean fMenuAboutToShow; + + private TerminalActionCopy fActionEditCopy; + + private TerminalActionCut fActionEditCut; + + private TerminalActionPaste fActionEditPaste; + + private TerminalActionClearAll fActionEditClearAll; + + private TerminalActionSelectAll fActionEditSelectAll; + + protected class TerminalContextMenuHandler implements MenuListener, + IMenuListener { + public void menuHidden(MenuEvent event) { + fMenuAboutToShow = false; + fActionEditCopy.updateAction(fMenuAboutToShow); + } + + public void menuShown(MenuEvent e) { + + } + + public void menuAboutToShow(IMenuManager menuMgr) { + fMenuAboutToShow = true; + fActionEditCopy.updateAction(fMenuAboutToShow); + fActionEditCut.updateAction(fMenuAboutToShow); + fActionEditSelectAll.updateAction(fMenuAboutToShow); + fActionEditPaste.updateAction(fMenuAboutToShow); + fActionEditClearAll.updateAction(fMenuAboutToShow); + } + } + + public TerminalViewTab(final Composite parent, TerminalViewer viewer) { + super(parent, SWT.NONE); + tabFolder = new CTabFolder(this, SWT.NONE); + tabFolder.setLayout(new FillLayout()); + tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH)); + setLayout(new FillLayout()); + tabFolder.setBackground(parent.getBackground()); + tabFolder.setSimple(false); + tabFolder.setUnselectedImageVisible(false); + tabFolder.setUnselectedCloseVisible(false); + + tabFolder.setMinimizeVisible(false); + tabFolder.setMaximizeVisible(false); +//TODO setupActions(); + } + + public void dispose() { + if (propertyChangeListener != null) { + IThemeManager mgr = PlatformUI.getWorkbench().getThemeManager(); + mgr.removePropertyChangeListener(propertyChangeListener); + propertyChangeListener = null; + } + if (!tabFolder.isDisposed()) { + tabFolder.dispose(); + } + super.dispose(); + } + + public CTabFolder getFolder() { + return tabFolder; + } + + public void remove(Object root) { + + } + + public int getItemCount(){ + return tabFolder.getItemCount(); + } + + public CTabItem getSelectedTab() { + if (tabFolder.getItemCount() > 0) { + int index = tabFolder.getSelectionIndex(); + CTabItem item = tabFolder.getItem(index); + return item; + } + + return null; + } + + public void showCurrentPage() { + tabFolder.setFocus(); + } + + public void showPageFor(Object root) { + for (int i = 0; i < tabFolder.getItemCount(); i++) { + CTabItem item = tabFolder.getItem(i); + if (item.getData() == root) { + tabFolder.setSelection(item); + } + + } + } + + public void showPageFor(String tabName) { + for (int i = 0; i < tabFolder.getItemCount(); i++) { + CTabItem item = tabFolder.getItem(i); + if (item.getText().equals(tabName)) { + tabFolder.setSelection(item); + return; + } + + } + } + + public void disposePageFor(String tabName) { + for (int i = 0; i < tabFolder.getItemCount(); i++) { + CTabItem item = tabFolder.getItem(i); + if (item.getText().equals(tabName)) { + item.dispose(); + return; + } + + } + } + + public void propertyChange(PropertyChangeEvent e) { + // for now always update + if (tabFolder!=null) { + CTabItem[] items = tabFolder.getItems(); + for (int i=0; i