X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=org.eclipse.linuxtools.lttng2.ui%2Fsrc%2Forg%2Feclipse%2Flinuxtools%2Finternal%2Flttng2%2Fui%2Fviews%2Fcontrol%2Fdialogs%2FCreateSessionDialog.java;h=b3d9cd631a9de8b6aa53b91348e6484c1f83917b;hb=152ba1a7fabe7175ba1a6f267eda2b3891cbcb63;hp=fb61d3d1ee078e4a418756677d249a3515db9131;hpb=a30e79fec228287cbaf58fbb86b9df65df7ccaee;p=deliverable%2Ftracecompass.git diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/CreateSessionDialog.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/CreateSessionDialog.java index fb61d3d1ee..b3d9cd631a 100644 --- a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/CreateSessionDialog.java +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/CreateSessionDialog.java @@ -13,9 +13,10 @@ package org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs; import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.linuxtools.internal.lttng2.core.control.model.ISessionInfo; +import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.SessionInfo; import org.eclipse.linuxtools.internal.lttng2.ui.Activator; import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages; import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent; @@ -30,8 +31,6 @@ import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; @@ -49,7 +48,7 @@ import org.eclipse.swt.widgets.Text; * * @author Bernd Hufmann */ -public class CreateSessionDialog extends Dialog implements ICreateSessionDialog { +public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessionDialog { // ------------------------------------------------------------------------ // Constants @@ -84,17 +83,15 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog /** * Index of last supported streaming protocol for common URL configuration. */ - private final static int COMMON_URL_LAST_INDEX = 1; + private static final int COMMON_URL_LAST_INDEX = 1; /** * Index of default streaming protocol. */ - private final static int DEFAULT_URL_INDEX = 0; + private static final int DEFAULT_URL_INDEX = 0; // ------------------------------------------------------------------------ // Attributes // ------------------------------------------------------------------------ - - private Control fControl = null; /** * The dialog composite. */ @@ -111,6 +108,10 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog * The text widget for the session path. */ private Text fSessionPathText = null; + /** + * The button widget to select a snapshot session + */ + private Button fSnapshotButton = null; /** * The Group for stream configuration. */ @@ -155,6 +156,10 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog * A key listener that copies the host address from control to data when being linked. */ private CopyModifyListener fControlUrlKeyListener; + /** + * A modify listener that updates the enablement of the dialog. + */ + private UpdateEnablementModifyListener fUpdateEnablementModifyListener; /** * The text box for the control port. */ @@ -183,6 +188,10 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog * The session path string. */ private String fSessionPath = null; + /** + * Flag whether the session is snapshot or not + */ + private boolean fIsSnapshot = false; /** * Flag whether default location (path) shall be used or not */ @@ -220,96 +229,30 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog */ public CreateSessionDialog(Shell shell) { super(shell); - setShellStyle(SWT.RESIZE); + setShellStyle(SWT.RESIZE | getShellStyle()); } // ------------------------------------------------------------------------ // Accessors // ------------------------------------------------------------------------ - /* - * (non-Javadoc) - * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog#getSessionName() - */ - @Override - public String getSessionName() { - return fSessionName; - } - - /* - * (non-Javadoc) - * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog#getSessionPath() - */ - @Override - public String getSessionPath() { - return fSessionPath; - } - - /* - * (non-Javadoc) - * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog#isDefaultSessionPath() - */ - @Override - public boolean isDefaultSessionPath() { - return fIsDefaultPath; - } - /* - * (non-Javadoc) - * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog#initialze(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionGroup) - */ @Override public void initialize(TraceSessionGroup group) { fParent = group; fStreamingComposite = null; fSessionName = null; fSessionPath = null; + fIsSnapshot = false; fIsDefaultPath = true; fIsStreamedTrace = false; fNetworkUrl = null; fControlUrl = null; fDataUrl = null; } - - @Override - public boolean isStreamedTrace() { - return fIsStreamedTrace; - } - @Override - public String getNetworkUrl() { - return fNetworkUrl; - } - @Override - public String getControlUrl() { - return fControlUrl; - } - @Override - public String getDataUrl() { - return fDataUrl; - } - // ------------------------------------------------------------------------ // Operations // ------------------------------------------------------------------------ - - /* (non-Javadoc) - * @see org.eclipse.jface.dialogs.Dialog#createContents(org.eclipse.swt.widgets.Composite) - */ - @Override - protected Control createContents(Composite parent) { - fControl = super.createContents(parent); - - /* set the shell minimum size */ - Point clientArea = fControl.computeSize(SWT.DEFAULT, SWT.DEFAULT); - Rectangle trim = getShell().computeTrim(0, 0, clientArea.x, clientArea.y); - getShell().setMinimumSize(trim.width, trim.height); - - return fControl; - } - /* - * (non-Javadoc) - * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) - */ @Override protected void configureShell(Shell newShell) { super.configureShell(newShell); @@ -317,15 +260,14 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog newShell.setImage(Activator.getDefault().loadIcon(CREATE_SESSION_ICON_FILE)); } - /* - * (non-Javadoc) - * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) - */ @Override protected Control createDialogArea(Composite parent) { + Composite dialogAreaa = (Composite) super.createDialogArea(parent); + setTitle(Messages.TraceControl_CreateSessionDialogTitle); + setMessage(Messages.TraceControl_CreateSessionDialogMessage); // Main dialog panel - fDialogComposite = new Composite(parent, SWT.NONE); + fDialogComposite = new Composite(dialogAreaa, SWT.NONE); GridLayout layout = new GridLayout(1, true); fDialogComposite.setLayout(layout); fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); @@ -334,15 +276,28 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog sessionGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); sessionGroup.setLayout(new GridLayout(4, true)); + fUpdateEnablementModifyListener = new UpdateEnablementModifyListener(); + Label sessionNameLabel = new Label(sessionGroup, SWT.RIGHT); sessionNameLabel.setText(Messages.TraceControl_CreateSessionNameLabel); fSessionNameText = new Text(sessionGroup, SWT.NONE); fSessionNameText.setToolTipText(Messages.TraceControl_CreateSessionNameTooltip); + fSessionNameText.addModifyListener(fUpdateEnablementModifyListener); fSessionPathLabel = new Label(sessionGroup, SWT.RIGHT); fSessionPathLabel.setText(Messages.TraceControl_CreateSessionPathLabel); fSessionPathText = new Text(sessionGroup, SWT.NONE); fSessionPathText.setToolTipText(Messages.TraceControl_CreateSessionPathTooltip); + fSessionPathText.addModifyListener(fUpdateEnablementModifyListener); + + if (fParent.isSnapshotSupported()) { + fSnapshotButton = new Button(sessionGroup, SWT.CHECK); + fSnapshotButton.setText(Messages.TraceControl_CreateSessionSnapshotLabel); + fSnapshotButton.setToolTipText(Messages.TraceControl_CreateSessionSnapshotTooltip); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan = 4; + fSnapshotButton.setData(data); + } // layout widgets GridData data = new GridData(GridData.FILL_HORIZONTAL); @@ -390,11 +345,8 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog createConfigureStreamingComposite(); } - fDialogComposite.layout(); - - Point clientArea = fControl.computeSize(SWT.DEFAULT, SWT.DEFAULT); - Rectangle trim = getShell().computeTrim(0, 0, clientArea.x, clientArea.y); - getShell().setSize(trim.width, trim.height); + updateEnablement(); + getShell().pack(); } }); } @@ -420,6 +372,7 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog GridData data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 6; fTracePathText.setLayoutData(data); + fTracePathText.addModifyListener(fUpdateEnablementModifyListener); fLinkDataWithControlButton = new Button(urlGroup, SWT.CHECK); fLinkDataWithControlButton.setText(Messages.TraceControl_CreateSessionLinkButtonText); @@ -463,18 +416,21 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 1; fControlProtocolCombo.setLayoutData(data); + fControlProtocolCombo.addModifyListener(fUpdateEnablementModifyListener); fControlHostAddressText = new Text(urlGroup, SWT.NONE); fControlHostAddressText.setToolTipText(Messages.TraceControl_CreateSessionControlAddressTooltip); data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 4; fControlHostAddressText.setLayoutData(data); + fControlHostAddressText.addModifyListener(fUpdateEnablementModifyListener); fControlPortText = new Text(urlGroup, SWT.NONE); fControlPortText.setToolTipText(Messages.TraceControl_CreateSessionControlPortTooltip); data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 1; fControlPortText.setLayoutData(data); + fControlPortText.addModifyListener(fUpdateEnablementModifyListener); label = new Label(urlGroup, SWT.RIGHT); label.setText(Messages.TraceControl_CreateSessionDataUrlLabel); @@ -488,6 +444,7 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 1; fDataProtocolCombo.setLayoutData(data); + fDataProtocolCombo.addModifyListener(fUpdateEnablementModifyListener); String items[] = new String[StreamingProtocol.values().length]; for (int i = 0; i < items.length; i++) { @@ -502,6 +459,7 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 4; fDataHostAddressText.setLayoutData(data); + fDataHostAddressText.addModifyListener(fUpdateEnablementModifyListener); fDataPortText = new Text(urlGroup, SWT.NONE); fDataPortText.setEnabled(true); @@ -509,6 +467,7 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 1; fDataPortText.setLayoutData(data); + fDataPortText.addModifyListener(fUpdateEnablementModifyListener); fCopyProtocolSelectionListener = new ControlProtocolSelectionListener(); fControlProtocolSelectionListener = new ProtocolComboSelectionListener(fControlProtocolCombo, fControlPortText); @@ -616,25 +575,22 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog } } - /* - * (non-Javadoc) - * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) - */ @Override protected void createButtonsForButtonBar(Composite parent) { createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$ createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$ } - /* - * (non-Javadoc) - * @see org.eclipse.jface.dialogs.Dialog#okPressed() - */ - @Override - protected void okPressed() { + private void updateEnablement() { + validate(); + getButton(IDialogConstants.OK_ID).setEnabled(getErrorMessage() == null); + } + + private void validate() { // Validate input data fSessionName = fSessionNameText.getText(); fSessionPath = fSessionPathText.getText(); + setErrorMessage(null); if (!"".equals(fSessionPath)) { //$NON-NLS-1$ // validate sessionPath @@ -645,16 +601,18 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog if (fsss != null) { try { IRemoteFile remoteFolder = fsss.getRemoteFileObject(fSessionPath, new NullProgressMonitor()); + + if (remoteFolder == null) { + setErrorMessage(Messages.TraceControl_InvalidSessionPathError + " (" + fSessionPath + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ + return; + } + if (remoteFolder.exists()) { - MessageDialog.openError(getShell(), - Messages.TraceControl_CreateSessionDialogTitle, - Messages.TraceControl_SessionPathAlreadyExistsError + " (" + fSessionPath + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ + setErrorMessage(Messages.TraceControl_SessionPathAlreadyExistsError + " (" + fSessionPath + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ return; } } catch (SystemMessageException e) { - MessageDialog.openError(getShell(), - Messages.TraceControl_CreateSessionDialogTitle, - Messages.TraceControl_FileSubSystemError + "\n" + e); //$NON-NLS-1$ + setErrorMessage(Messages.TraceControl_FileSubSystemError + "\n" + e); //$NON-NLS-1$ return; } } @@ -662,40 +620,36 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog fIsDefaultPath = false; } + if (fParent.isSnapshotSupported()) { + fIsSnapshot = fSnapshotButton.getSelection(); + } + fNetworkUrl = null; fControlUrl = null; fDataUrl = null; - if (fIsStreamedTrace) { + if (fIsStreamedTrace && fStreamingComposite != null) { // Validate input data fTracePath = fTracePathText.getText(); if (fControlProtocolCombo.getSelectionIndex() < 0) { - MessageDialog.openError(getShell(), - Messages.TraceControl_CreateSessionDialogTitle, - "Control Protocol Text is empty\n"); //$NON-NLS-1$ + setErrorMessage("Control Protocol Text is empty\n"); //$NON-NLS-1$ return; } if ("".equals(fControlHostAddressText.getText())) { //$NON-NLS-1$ - MessageDialog.openError(getShell(), - Messages.TraceControl_CreateSessionDialogTitle, - "Control Address Text is empty\n"); //$NON-NLS-1$ + setErrorMessage("Control Address Text is empty\n"); //$NON-NLS-1$ return; } - if(!fLinkDataWithControlButton.getSelection()) { + if (!fLinkDataWithControlButton.getSelection()) { if (fDataProtocolCombo.getSelectionIndex() < 0) { - MessageDialog.openError(getShell(), - Messages.TraceControl_CreateSessionDialogTitle, - "Control Protocol Text is empty\n"); //$NON-NLS-1$ + setErrorMessage("Data Protocol Text is empty\n"); //$NON-NLS-1$ return; } if ("".equals(fDataHostAddressText.getText())) { //$NON-NLS-1$ - MessageDialog.openError(getShell(), - Messages.TraceControl_CreateSessionDialogTitle, - "Control Address Text is empty\n"); //$NON-NLS-1$ + setErrorMessage("Data Address Text is empty\n"); //$NON-NLS-1$ return; } @@ -705,13 +659,13 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog null, fTracePath); - fDataUrl = getUrlString(fControlProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()), + fDataUrl = getUrlString(fDataProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()), fDataHostAddressText.getText(), null, fDataPortText.getText(), fTracePath); } else { - fNetworkUrl = getUrlString(fControlProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()), + fNetworkUrl = getUrlString(fControlProtocolCombo.getItem(fControlProtocolCombo.getSelectionIndex()), fControlHostAddressText.getText(), fControlPortText.getText(), fDataPortText.getText(), @@ -721,22 +675,15 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog // Check for invalid names if (!"".equals(fSessionName) && !fSessionName.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$ - MessageDialog.openError(getShell(), - Messages.TraceControl_CreateSessionDialogTitle, - Messages.TraceControl_InvalidSessionNameError + " (" + fSessionName + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ + setErrorMessage(Messages.TraceControl_InvalidSessionNameError + " (" + fSessionName + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ return; } // Check if node with name already exists in parent if(fParent.containsChild(fSessionName)) { - MessageDialog.openError(getShell(), - Messages.TraceControl_CreateSessionDialogTitle, - Messages.TraceControl_SessionAlreadyExistsError + " (" + fSessionName + ")"); //$NON-NLS-1$ //$NON-NLS-2$ + setErrorMessage(Messages.TraceControl_SessionAlreadyExistsError + " (" + fSessionName + ")"); //$NON-NLS-1$ //$NON-NLS-2$ return; } - - // validation successful -> call super.okPressed() - super.okPressed(); } private static String getUrlString(String proto, String host, String ctrlPort, String dataPort, String sessionPath) { @@ -817,4 +764,28 @@ public class CreateSessionDialog extends Dialog implements ICreateSessionDialog } } + @Override + public ISessionInfo getParameters() { + ISessionInfo sessionInfo = new SessionInfo(fSessionName); + + if (fIsStreamedTrace) { + sessionInfo.setNetworkUrl(fNetworkUrl); + sessionInfo.setControlUrl(fControlUrl); + sessionInfo.setDataUrl(fDataUrl); + sessionInfo.setStreamedTrace(true); + } else if (!fIsDefaultPath) { + sessionInfo.setSessionPath(fSessionPath); + } + + sessionInfo.setSnapshot(fIsSnapshot); + + return sessionInfo; + } + + private final class UpdateEnablementModifyListener implements ModifyListener { + @Override + public void modifyText(ModifyEvent e) { + updateEnablement(); + } + } }