Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Stieber2014-02-09 04:55:55 -0500
committerUwe Stieber2014-02-09 04:55:55 -0500
commitf49bcee890959b904bde8fd80b5b4435551ca53c (patch)
tree57602f66deddc20818da4daedb102c3c345251a4
parented5690be31553fe4a65cbcfd83062c58ed58b134 (diff)
downloadorg.eclipse.tcf-f49bcee890959b904bde8fd80b5b4435551ca53c.tar.gz
org.eclipse.tcf-f49bcee890959b904bde8fd80b5b4435551ca53c.tar.xz
org.eclipse.tcf-f49bcee890959b904bde8fd80b5b4435551ca53c.zip
Target Explorer: Don't log locator commands and events by default
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/interfaces/IPreferenceKeys.java7
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/PreferencesInitializer.java4
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/ChannelTraceListener.java7
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.java1
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.properties1
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/preferences/LoggingPreferencePage.java507
6 files changed, 273 insertions, 254 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/interfaces/IPreferenceKeys.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/interfaces/IPreferenceKeys.java
index d11a0e0df..8801b438e 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/interfaces/IPreferenceKeys.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/interfaces/IPreferenceKeys.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2011 - 2014 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
@@ -31,6 +31,11 @@ public interface IPreferenceKeys {
public final String PREF_MONITOR_ENABLED = PREFIX + "monitor.enabled"; //$NON-NLS-1$
/**
+ * If set to <code>true</code>, locator events are logged.
+ */
+ public final String PREF_SHOW_LOCATOR_EVENTS = PREFIX + "show.locatorEvents"; //$NON-NLS-1$
+
+ /**
* If set to <code>true</code>, locator heart beat events are logged.
*/
public final String PREF_SHOW_HEARTBEATS = PREFIX + "show.heartbeats"; //$NON-NLS-1$
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/PreferencesInitializer.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/PreferencesInitializer.java
index 4392b4858..45cd9c022 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/PreferencesInitializer.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/PreferencesInitializer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Wind River Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2011 - 2014 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
@@ -39,6 +39,8 @@ public class PreferencesInitializer extends AbstractPreferenceInitializer {
prefs.putDefaultBoolean(IPreferenceKeys.PREF_LOGGING_ENABLED, false);
// Enable back-end communication monitor: default off
prefs.putDefaultBoolean(IPreferenceKeys.PREF_MONITOR_ENABLED, false);
+ // Locator events: default off
+ prefs.putDefaultBoolean(IPreferenceKeys.PREF_SHOW_LOCATOR_EVENTS, false);
// Heat beat events: default off
prefs.putDefaultBoolean(IPreferenceKeys.PREF_SHOW_HEARTBEATS, false);
// Framework events: default off
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/ChannelTraceListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/ChannelTraceListener.java
index 316ca59e4..8b540330d 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/ChannelTraceListener.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/ChannelTraceListener.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2011 - 2014 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
@@ -123,6 +123,11 @@ public class ChannelTraceListener implements TraceListener {
* Helper method to output the message to the logger.
*/
private void doLogMessage(final char type, String token, String service, String name, byte[] data, boolean received) {
+ // Filter out the locator service messages
+ boolean locatorEvents = CoreBundleActivator.getScopedPreferences().getBoolean(IPreferenceKeys.PREF_SHOW_LOCATOR_EVENTS);
+ if (!locatorEvents && service != null && service.toLowerCase().equals("locator")) { //$NON-NLS-1$
+ return;
+ }
// Filter out the heart beat messages if not overwritten by the preferences
boolean showHeartbeats = CoreBundleActivator.getScopedPreferences().getBoolean(IPreferenceKeys.PREF_SHOW_HEARTBEATS);
if (!showHeartbeats && name != null && name.toLowerCase().contains("heartbeat")) { //$NON-NLS-1$
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.java
index ffd8e9749..58e72f717 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.java
@@ -199,6 +199,7 @@ public class Messages extends NLS {
public static String LoggingPreferencePage_enabled_label;
public static String LoggingPreferencePage_monitorEnabled_label;
public static String LoggingPreferencePage_filterGroup_label;
+ public static String LoggingPreferencePage_showLocatorEvents_label;
public static String LoggingPreferencePage_showHeartbeats_label;
public static String LoggingPreferencePage_showFrameworkEvents_label;
public static String LoggingPreferencePage_logfileGroup_label;
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.properties
index 444c233c8..a1e8dcb13 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.properties
@@ -158,6 +158,7 @@ LoggingPreferencePage_label=Logging settings for agent communication:
LoggingPreferencePage_enabled_label=Enable logging
LoggingPreferencePage_monitorEnabled_label=Enable agent communication monitor
LoggingPreferencePage_filterGroup_label=Event Filter Settings
+LoggingPreferencePage_showLocatorEvents_label=Log locator service commands and events
LoggingPreferencePage_showHeartbeats_label=Log target heart beat events
LoggingPreferencePage_showFrameworkEvents_label=Log low-level framework events
LoggingPreferencePage_logfileGroup_label=Log File Settings
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/preferences/LoggingPreferencePage.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/preferences/LoggingPreferencePage.java
index 268d24dc3..de440602e 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/preferences/LoggingPreferencePage.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/preferences/LoggingPreferencePage.java
@@ -1,251 +1,256 @@
-/*******************************************************************************
- * Copyright (c) 2011 Wind River Systems, Inc. and others. All rights reserved.
- * This program and the accompanying materials are made available under the terms
- * of the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.te.tcf.ui.preferences;
-
-import java.util.regex.Pattern;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.jface.preference.BooleanFieldEditor;
-import org.eclipse.jface.preference.FieldEditorPreferencePage;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.preference.IntegerFieldEditor;
-import org.eclipse.jface.preference.PreferenceStore;
-import org.eclipse.jface.preference.StringFieldEditor;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.tcf.te.runtime.preferences.ScopedEclipsePreferences;
-import org.eclipse.tcf.te.tcf.log.core.activator.CoreBundleActivator;
-import org.eclipse.tcf.te.tcf.log.core.interfaces.IPreferenceKeys;
-import org.eclipse.tcf.te.tcf.ui.nls.Messages;
-import org.eclipse.tcf.te.ui.swt.SWTControlUtil;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPreferencePage;
-
-/**
- * Agent communication logging preference page.
- */
-@SuppressWarnings("restriction")
-public class LoggingPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
- // References to the field editors
- private BooleanFieldEditor enabled;
- private BooleanFieldEditor monitorEnabled;
- private BooleanFieldEditor showHeartbeats;
- private BooleanFieldEditor showFrameworkEvents;
- private StringFieldEditor logfileSize;
- private IntegerFieldEditor filesInCycle;
-
- // The preference store used internally for the field editors
- private IPreferenceStore store;
-
- /**
- * Log file size field editor implementation.
- */
- private class LogfileSizeFieldEditor extends StringFieldEditor {
- private Pattern valid = Pattern.compile("0|[1-9][0-9]*[KMG]?"); //$NON-NLS-1$
-
- /**
- * Constructor.
- *
- * @param name The name of the preference this field editor works on.
- * @param labelText The label text.
- * @param parent the parent of the field editor's control
- */
- public LogfileSizeFieldEditor(String name, String labelText, Composite parent) {
- super(name, labelText, parent);
- this.setEmptyStringAllowed(false);
- this.setTextLimit(6);
- this.setErrorMessage(Messages.LoggingPreferencePage_maxFileSize_error);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.StringFieldEditor#doCheckState()
- */
- @Override
- protected boolean doCheckState() {
- if (valid.matcher(getStringValue()).matches()) {
- return true;
- }
- return false;
- }
- }
-
-
- /**
- * Constructor.
- */
- public LoggingPreferencePage() {
- super(FieldEditorPreferencePage.GRID);
-
- // The internal preference store never needs saving
- store = new PreferenceStore() {
- @Override
- public boolean needsSaving() {
- return false;
- }
- };
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
- */
- @Override
- public void init(IWorkbench workbench) {
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
- */
- @Override
- protected void createFieldEditors() {
- Composite parent = getFieldEditorParent();
- ((GridLayout)parent.getLayout()).makeColumnsEqualWidth = false;
-
- Composite panel = new Composite(parent, SWT.NONE);
- panel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
- GridLayout layout = new GridLayout(2, false);
- layout.marginHeight = 0; layout.marginWidth = 0;
- panel.setLayout(layout);
- panel.setFont(parent.getFont());
-
- Label label = new Label(panel, SWT.HORIZONTAL);
- label.setText(Messages.LoggingPreferencePage_label);
- GridData layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false);
- layoutData.horizontalSpan = 2;
- label.setLayoutData(layoutData);
-
- createSpacer(panel, 2);
-
- enabled = new BooleanFieldEditor(IPreferenceKeys.PREF_LOGGING_ENABLED,
- Messages.LoggingPreferencePage_enabled_label, panel);
- addField(enabled);
-
- monitorEnabled = new BooleanFieldEditor(IPreferenceKeys.PREF_MONITOR_ENABLED,
- Messages.LoggingPreferencePage_monitorEnabled_label, panel);
- addField(monitorEnabled);
-
- createSpacer(panel, 2);
-
- Group filterGroup = new Group(panel, SWT.NONE);
- filterGroup.setText(Messages.LoggingPreferencePage_filterGroup_label);
- filterGroup.setLayout(new GridLayout(2, false));
- filterGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
-
- // The composite is necessary to get the margins within the group right!
- Composite filterPanel = new Composite(filterGroup, SWT.NONE);
- filterPanel.setLayout(new GridLayout());
- filterPanel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
-
- showHeartbeats = new BooleanFieldEditor(IPreferenceKeys.PREF_SHOW_HEARTBEATS,
- Messages.LoggingPreferencePage_showHeartbeats_label, filterPanel);
- addField(showHeartbeats);
-
- showFrameworkEvents = new BooleanFieldEditor(IPreferenceKeys.PREF_SHOW_FRAMEWORK_EVENTS,
- Messages.LoggingPreferencePage_showFrameworkEvents_label, filterPanel);
- addField(showFrameworkEvents);
-
- createSpacer(panel, 2);
-
- Group logfileGroup = new Group(panel, SWT.NONE);
- logfileGroup.setText(Messages.LoggingPreferencePage_logfileGroup_label);
- logfileGroup.setLayout(new GridLayout(2, false));
- logfileGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
-
- // The composite is necessary to get the margins within the group right!
- Composite logfilePanel = new Composite(logfileGroup, SWT.NONE);
- logfilePanel.setLayout(new GridLayout());
- logfilePanel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
-
- logfileSize = new LogfileSizeFieldEditor(IPreferenceKeys.PREF_MAX_FILE_SIZE,
- Messages.LoggingPreferencePage_maxFileSize_label, logfilePanel);
- addField(logfileSize);
-
- filesInCycle = new IntegerFieldEditor(IPreferenceKeys.PREF_MAX_FILES_IN_CYCLE,
- Messages.LoggingPreferencePage_maxFilesInCycle_label, logfilePanel);
- addField(filesInCycle);
- }
-
- /**
- * Creates a empty space, 1/4 as high as a line.
- *
- * @param parent The parent composite. Must not be <code>null</code>.
- * @param columnSpan The horizontal span.
- */
- protected void createSpacer(Composite parent, int columnSpan) {
- Assert.isNotNull(parent);
- GridData gd = new GridData();
- gd.horizontalSpan = columnSpan;
- gd.heightHint = SWTControlUtil.convertHeightInCharsToPixels(parent, 1) / 4;
- new Label(parent, SWT.NONE).setLayoutData(gd);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.PreferencePage#getPreferenceStore()
- */
- @Override
- public IPreferenceStore getPreferenceStore() {
- return store;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.FieldEditorPreferencePage#initialize()
- */
- @Override
- protected void initialize() {
- ScopedEclipsePreferences prefs = CoreBundleActivator.getScopedPreferences();
-
- store.setDefault(IPreferenceKeys.PREF_LOGGING_ENABLED, prefs.getDefaultBoolean(IPreferenceKeys.PREF_LOGGING_ENABLED));
- store.setValue(IPreferenceKeys.PREF_LOGGING_ENABLED, prefs.getBoolean(IPreferenceKeys.PREF_LOGGING_ENABLED));
-
- store.setDefault(IPreferenceKeys.PREF_MONITOR_ENABLED, prefs.getDefaultBoolean(IPreferenceKeys.PREF_MONITOR_ENABLED));
- store.setValue(IPreferenceKeys.PREF_MONITOR_ENABLED, prefs.getBoolean(IPreferenceKeys.PREF_MONITOR_ENABLED));
-
- store.setDefault(IPreferenceKeys.PREF_SHOW_HEARTBEATS, prefs.getDefaultBoolean(IPreferenceKeys.PREF_SHOW_HEARTBEATS));
- store.setValue(IPreferenceKeys.PREF_SHOW_HEARTBEATS, prefs.getBoolean(IPreferenceKeys.PREF_SHOW_HEARTBEATS));
-
- store.setDefault(IPreferenceKeys.PREF_SHOW_FRAMEWORK_EVENTS, prefs.getDefaultBoolean(IPreferenceKeys.PREF_SHOW_FRAMEWORK_EVENTS));
- store.setValue(IPreferenceKeys.PREF_SHOW_FRAMEWORK_EVENTS, prefs.getBoolean(IPreferenceKeys.PREF_SHOW_FRAMEWORK_EVENTS));
-
- store.setDefault(IPreferenceKeys.PREF_MAX_FILE_SIZE, prefs.getDefaultString(IPreferenceKeys.PREF_MAX_FILE_SIZE));
- store.setValue(IPreferenceKeys.PREF_MAX_FILE_SIZE, prefs.getString(IPreferenceKeys.PREF_MAX_FILE_SIZE));
-
- store.setDefault(IPreferenceKeys.PREF_MAX_FILES_IN_CYCLE, prefs.getDefaultInt(IPreferenceKeys.PREF_MAX_FILES_IN_CYCLE));
- store.setValue(IPreferenceKeys.PREF_MAX_FILES_IN_CYCLE, prefs.getInt(IPreferenceKeys.PREF_MAX_FILES_IN_CYCLE));
-
- // Load values into field editors
- super.initialize();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.FieldEditorPreferencePage#performOk()
- */
- @Override
- public boolean performOk() {
- boolean success = super.performOk();
-
- if (success) {
- ScopedEclipsePreferences prefs = CoreBundleActivator.getScopedPreferences();
-
- prefs.putBoolean(IPreferenceKeys.PREF_LOGGING_ENABLED, store.getBoolean(IPreferenceKeys.PREF_LOGGING_ENABLED));
- prefs.putBoolean(IPreferenceKeys.PREF_MONITOR_ENABLED, store.getBoolean(IPreferenceKeys.PREF_MONITOR_ENABLED));
-
- prefs.putBoolean(IPreferenceKeys.PREF_SHOW_HEARTBEATS, store.getBoolean(IPreferenceKeys.PREF_SHOW_HEARTBEATS));
- prefs.putBoolean(IPreferenceKeys.PREF_SHOW_FRAMEWORK_EVENTS, store.getBoolean(IPreferenceKeys.PREF_SHOW_FRAMEWORK_EVENTS));
-
- prefs.putString(IPreferenceKeys.PREF_MAX_FILE_SIZE, store.getString(IPreferenceKeys.PREF_MAX_FILE_SIZE));
- prefs.putInt(IPreferenceKeys.PREF_MAX_FILES_IN_CYCLE, store.getInt(IPreferenceKeys.PREF_MAX_FILES_IN_CYCLE));
- }
-
- return success;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2011 - 2014 Wind River Systems, Inc. and others. All rights reserved.
+ * This program and the accompanying materials are made available under the terms
+ * of the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.tcf.ui.preferences;
+
+import java.util.regex.Pattern;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.preference.BooleanFieldEditor;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.IntegerFieldEditor;
+import org.eclipse.jface.preference.PreferenceStore;
+import org.eclipse.jface.preference.StringFieldEditor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.tcf.te.runtime.preferences.ScopedEclipsePreferences;
+import org.eclipse.tcf.te.tcf.log.core.activator.CoreBundleActivator;
+import org.eclipse.tcf.te.tcf.log.core.interfaces.IPreferenceKeys;
+import org.eclipse.tcf.te.tcf.ui.nls.Messages;
+import org.eclipse.tcf.te.ui.swt.SWTControlUtil;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+/**
+ * Agent communication logging preference page.
+ */
+@SuppressWarnings("restriction")
+public class LoggingPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
+ // References to the field editors
+ private BooleanFieldEditor enabled;
+ private BooleanFieldEditor monitorEnabled;
+ private BooleanFieldEditor showLocatorEvents;
+ private BooleanFieldEditor showHeartbeats;
+ private BooleanFieldEditor showFrameworkEvents;
+ private StringFieldEditor logfileSize;
+ private IntegerFieldEditor filesInCycle;
+
+ // The preference store used internally for the field editors
+ private IPreferenceStore store;
+
+ /**
+ * Log file size field editor implementation.
+ */
+ private class LogfileSizeFieldEditor extends StringFieldEditor {
+ private Pattern valid = Pattern.compile("0|[1-9][0-9]*[KMG]?"); //$NON-NLS-1$
+
+ /**
+ * Constructor.
+ *
+ * @param name The name of the preference this field editor works on.
+ * @param labelText The label text.
+ * @param parent the parent of the field editor's control
+ */
+ public LogfileSizeFieldEditor(String name, String labelText, Composite parent) {
+ super(name, labelText, parent);
+ this.setEmptyStringAllowed(false);
+ this.setTextLimit(6);
+ this.setErrorMessage(Messages.LoggingPreferencePage_maxFileSize_error);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.preference.StringFieldEditor#doCheckState()
+ */
+ @Override
+ protected boolean doCheckState() {
+ if (valid.matcher(getStringValue()).matches()) {
+ return true;
+ }
+ return false;
+ }
+ }
+
+
+ /**
+ * Constructor.
+ */
+ public LoggingPreferencePage() {
+ super(FieldEditorPreferencePage.GRID);
+
+ // The internal preference store never needs saving
+ store = new PreferenceStore() {
+ @Override
+ public boolean needsSaving() {
+ return false;
+ }
+ };
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
+ */
+ @Override
+ public void init(IWorkbench workbench) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
+ */
+ @Override
+ protected void createFieldEditors() {
+ Composite parent = getFieldEditorParent();
+ ((GridLayout)parent.getLayout()).makeColumnsEqualWidth = false;
+
+ Composite panel = new Composite(parent, SWT.NONE);
+ panel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ GridLayout layout = new GridLayout(2, false);
+ layout.marginHeight = 0; layout.marginWidth = 0;
+ panel.setLayout(layout);
+ panel.setFont(parent.getFont());
+
+ Label label = new Label(panel, SWT.HORIZONTAL);
+ label.setText(Messages.LoggingPreferencePage_label);
+ GridData layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ layoutData.horizontalSpan = 2;
+ label.setLayoutData(layoutData);
+
+ createSpacer(panel, 2);
+
+ enabled = new BooleanFieldEditor(IPreferenceKeys.PREF_LOGGING_ENABLED,
+ Messages.LoggingPreferencePage_enabled_label, panel);
+ addField(enabled);
+
+ monitorEnabled = new BooleanFieldEditor(IPreferenceKeys.PREF_MONITOR_ENABLED,
+ Messages.LoggingPreferencePage_monitorEnabled_label, panel);
+ addField(monitorEnabled);
+
+ createSpacer(panel, 2);
+
+ Group filterGroup = new Group(panel, SWT.NONE);
+ filterGroup.setText(Messages.LoggingPreferencePage_filterGroup_label);
+ filterGroup.setLayout(new GridLayout(2, false));
+ filterGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+
+ // The composite is necessary to get the margins within the group right!
+ Composite filterPanel = new Composite(filterGroup, SWT.NONE);
+ filterPanel.setLayout(new GridLayout());
+ filterPanel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+
+ showLocatorEvents = new BooleanFieldEditor(IPreferenceKeys.PREF_SHOW_LOCATOR_EVENTS,
+ Messages.LoggingPreferencePage_showLocatorEvents_label, filterPanel);
+ addField(showLocatorEvents);
+
+ showHeartbeats = new BooleanFieldEditor(IPreferenceKeys.PREF_SHOW_HEARTBEATS,
+ Messages.LoggingPreferencePage_showHeartbeats_label, filterPanel);
+ addField(showHeartbeats);
+
+ showFrameworkEvents = new BooleanFieldEditor(IPreferenceKeys.PREF_SHOW_FRAMEWORK_EVENTS,
+ Messages.LoggingPreferencePage_showFrameworkEvents_label, filterPanel);
+ addField(showFrameworkEvents);
+
+ createSpacer(panel, 2);
+
+ Group logfileGroup = new Group(panel, SWT.NONE);
+ logfileGroup.setText(Messages.LoggingPreferencePage_logfileGroup_label);
+ logfileGroup.setLayout(new GridLayout(2, false));
+ logfileGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+
+ // The composite is necessary to get the margins within the group right!
+ Composite logfilePanel = new Composite(logfileGroup, SWT.NONE);
+ logfilePanel.setLayout(new GridLayout());
+ logfilePanel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+
+ logfileSize = new LogfileSizeFieldEditor(IPreferenceKeys.PREF_MAX_FILE_SIZE,
+ Messages.LoggingPreferencePage_maxFileSize_label, logfilePanel);
+ addField(logfileSize);
+
+ filesInCycle = new IntegerFieldEditor(IPreferenceKeys.PREF_MAX_FILES_IN_CYCLE,
+ Messages.LoggingPreferencePage_maxFilesInCycle_label, logfilePanel);
+ addField(filesInCycle);
+ }
+
+ /**
+ * Creates a empty space, 1/4 as high as a line.
+ *
+ * @param parent The parent composite. Must not be <code>null</code>.
+ * @param columnSpan The horizontal span.
+ */
+ protected void createSpacer(Composite parent, int columnSpan) {
+ Assert.isNotNull(parent);
+ GridData gd = new GridData();
+ gd.horizontalSpan = columnSpan;
+ gd.heightHint = SWTControlUtil.convertHeightInCharsToPixels(parent, 1) / 4;
+ new Label(parent, SWT.NONE).setLayoutData(gd);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.preference.PreferencePage#getPreferenceStore()
+ */
+ @Override
+ public IPreferenceStore getPreferenceStore() {
+ return store;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.preference.FieldEditorPreferencePage#initialize()
+ */
+ @Override
+ protected void initialize() {
+ ScopedEclipsePreferences prefs = CoreBundleActivator.getScopedPreferences();
+
+ store.setDefault(IPreferenceKeys.PREF_LOGGING_ENABLED, prefs.getDefaultBoolean(IPreferenceKeys.PREF_LOGGING_ENABLED));
+ store.setValue(IPreferenceKeys.PREF_LOGGING_ENABLED, prefs.getBoolean(IPreferenceKeys.PREF_LOGGING_ENABLED));
+
+ store.setDefault(IPreferenceKeys.PREF_MONITOR_ENABLED, prefs.getDefaultBoolean(IPreferenceKeys.PREF_MONITOR_ENABLED));
+ store.setValue(IPreferenceKeys.PREF_MONITOR_ENABLED, prefs.getBoolean(IPreferenceKeys.PREF_MONITOR_ENABLED));
+
+ store.setDefault(IPreferenceKeys.PREF_SHOW_HEARTBEATS, prefs.getDefaultBoolean(IPreferenceKeys.PREF_SHOW_HEARTBEATS));
+ store.setValue(IPreferenceKeys.PREF_SHOW_HEARTBEATS, prefs.getBoolean(IPreferenceKeys.PREF_SHOW_HEARTBEATS));
+
+ store.setDefault(IPreferenceKeys.PREF_SHOW_FRAMEWORK_EVENTS, prefs.getDefaultBoolean(IPreferenceKeys.PREF_SHOW_FRAMEWORK_EVENTS));
+ store.setValue(IPreferenceKeys.PREF_SHOW_FRAMEWORK_EVENTS, prefs.getBoolean(IPreferenceKeys.PREF_SHOW_FRAMEWORK_EVENTS));
+
+ store.setDefault(IPreferenceKeys.PREF_MAX_FILE_SIZE, prefs.getDefaultString(IPreferenceKeys.PREF_MAX_FILE_SIZE));
+ store.setValue(IPreferenceKeys.PREF_MAX_FILE_SIZE, prefs.getString(IPreferenceKeys.PREF_MAX_FILE_SIZE));
+
+ store.setDefault(IPreferenceKeys.PREF_MAX_FILES_IN_CYCLE, prefs.getDefaultInt(IPreferenceKeys.PREF_MAX_FILES_IN_CYCLE));
+ store.setValue(IPreferenceKeys.PREF_MAX_FILES_IN_CYCLE, prefs.getInt(IPreferenceKeys.PREF_MAX_FILES_IN_CYCLE));
+
+ // Load values into field editors
+ super.initialize();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.preference.FieldEditorPreferencePage#performOk()
+ */
+ @Override
+ public boolean performOk() {
+ boolean success = super.performOk();
+
+ if (success) {
+ ScopedEclipsePreferences prefs = CoreBundleActivator.getScopedPreferences();
+
+ prefs.putBoolean(IPreferenceKeys.PREF_LOGGING_ENABLED, store.getBoolean(IPreferenceKeys.PREF_LOGGING_ENABLED));
+ prefs.putBoolean(IPreferenceKeys.PREF_MONITOR_ENABLED, store.getBoolean(IPreferenceKeys.PREF_MONITOR_ENABLED));
+
+ prefs.putBoolean(IPreferenceKeys.PREF_SHOW_HEARTBEATS, store.getBoolean(IPreferenceKeys.PREF_SHOW_HEARTBEATS));
+ prefs.putBoolean(IPreferenceKeys.PREF_SHOW_FRAMEWORK_EVENTS, store.getBoolean(IPreferenceKeys.PREF_SHOW_FRAMEWORK_EVENTS));
+
+ prefs.putString(IPreferenceKeys.PREF_MAX_FILE_SIZE, store.getString(IPreferenceKeys.PREF_MAX_FILE_SIZE));
+ prefs.putInt(IPreferenceKeys.PREF_MAX_FILES_IN_CYCLE, store.getInt(IPreferenceKeys.PREF_MAX_FILES_IN_CYCLE));
+ }
+
+ return success;
+ }
+}

Back to the top