summaryrefslogtreecommitdiff
path: root/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector')
-rw-r--r--src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/core/ILogFile.java48
-rw-r--r--src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/core/internal/CollectLogFile.java112
-rw-r--r--src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/core/internal/EclipseLogFile.java64
-rw-r--r--src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/core/internal/EnvironmentLogFile.java65
-rw-r--r--src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/core/internal/StudioLogFile.java83
-rw-r--r--src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/ui/LogFileColumn.java217
-rw-r--r--src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/ui/handler/LoggerCollectorHandler.java42
-rw-r--r--src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/ui/wizard/LoggerCollectorWizard.java111
-rw-r--r--src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/ui/wizard/LoggerCollectorWizardPage.java311
-rw-r--r--src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/LogCollectorExtensionLoader.java76
-rw-r--r--src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/LoggerCollectorConstants.java52
-rw-r--r--src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/LoggerCollectorMessages.java123
-rw-r--r--src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/PlatformException.java51
-rw-r--r--src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/PlatformLogger.java201
-rw-r--r--src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/WidgetsFactory.java445
-rw-r--r--src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/WidgetsUtil.java392
-rw-r--r--src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/ZipUtil.java260
17 files changed, 2653 insertions, 0 deletions
diff --git a/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/core/ILogFile.java b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/core/ILogFile.java
new file mode 100644
index 0000000..17063ac
--- /dev/null
+++ b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/core/ILogFile.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.motorola.studio.android.logger.collector.core;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.IPath;
+
+/**
+ * This interface is used by any features that wants to
+ * have a log file contribution within collect log files feature
+ */
+public interface ILogFile
+{
+ /**
+ * Get the name of
+ * @return the name that will be displayed by the user
+ */
+ public String getLogName();
+
+ /**
+ * Get the full path of the log file
+ * @return
+ */
+ public List<IPath> getLogFilePath();
+
+ /**
+ * Tell to the log collector where the log should be placed within
+ * log package
+ * @return the sub dir to put all declared log files
+ */
+ public String getOutputSubfolderName();
+
+}
diff --git a/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/core/internal/CollectLogFile.java b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/core/internal/CollectLogFile.java
new file mode 100644
index 0000000..96ac55e
--- /dev/null
+++ b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/core/internal/CollectLogFile.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.motorola.studio.android.logger.collector.core.internal;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.swt.widgets.TableItem;
+
+import com.motorola.studio.android.common.utilities.FileUtil;
+import com.motorola.studio.android.logger.collector.core.ILogFile;
+import com.motorola.studio.android.logger.collector.util.LogCollectorExtensionLoader;
+import com.motorola.studio.android.logger.collector.util.LoggerCollectorConstants;
+import com.motorola.studio.android.logger.collector.util.LoggerCollectorMessages;
+import com.motorola.studio.android.logger.collector.util.PlatformException;
+import com.motorola.studio.android.logger.collector.util.ZipUtil;
+
+/**
+ * This class is responsible to manage all collecting log files requirements.
+ */
+public class CollectLogFile
+{
+
+ private final ArrayList<ILogFile> logs = LogCollectorExtensionLoader.getLogFiles();
+
+ /**
+ * This method is responsible to retrieve files from informed path.
+ *
+ * @param path The path to be retrieved.
+ * @return The log files
+ */
+ public ArrayList<ILogFile> getLogFileList()
+ {
+ return logs;
+ }
+
+ /**
+ * This method is responsible to compact all log files selected by end-user.
+ *
+ * @param fileName The output compacted file name
+ * @param checkedItems The selected items
+ * @return if the selected files are compacted successfully
+ * @throws PlatformException
+ */
+ public boolean zipLogFiles(String fileName, List<TableItem> checkedItems)
+ throws PlatformException
+ {
+ boolean toReturn = true;
+ String nomalizedDirectory =
+ FileUtil.normalizePath(new Path(fileName).removeLastSegments(1).toOSString());
+ // Temporary folder path to store the log files while they are not
+ // compressed.
+ final String tempFolderPath = FileUtil.normalizePath(nomalizedDirectory) + "temp" //$NON-NLS-1$
+ + Double.toString((Math.random())).replaceAll("\\.", "0") + //$NON-NLS-1$ //$NON-NLS-2$
+ File.separator;
+ final IPath tempFolder = new Path(tempFolderPath);
+
+ try
+ {
+ // Creating the temporary folder.
+ FileUtil.mkdir(tempFolderPath);
+ // Copying the log files.
+ for (TableItem item : checkedItems)
+ {
+ ILogFile logFile = (ILogFile) item.getData();
+ IPath outputFolder = tempFolder.append(logFile.getOutputSubfolderName());
+ FileUtil.mkdir(outputFolder.toOSString());
+ for (IPath path : logFile.getLogFilePath())
+ {
+ FileUtil.copy(new File(path.toOSString()),
+ new File(outputFolder.append(path.lastSegment()).toOSString()));
+ }
+
+ }
+ // Compact all log files from temporary folder
+ new ZipUtil(fileName, tempFolderPath).zip();
+ }
+ catch (IOException e)
+ {
+ toReturn = false;
+ throw new PlatformException(new Status(IStatus.CANCEL,
+ LoggerCollectorConstants.PLUGIN_ID, LoggerCollectorMessages.getInstance()
+ .getString("error.logger.collector.zip"))); //$NON-NLS-1$
+ }
+ finally
+ {
+ // Deleting temporary folder an all files within it.
+ FileUtil.delete(tempFolderPath);
+ }
+ return toReturn;
+ }
+
+}
diff --git a/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/core/internal/EclipseLogFile.java b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/core/internal/EclipseLogFile.java
new file mode 100644
index 0000000..d5c9822
--- /dev/null
+++ b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/core/internal/EclipseLogFile.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.motorola.studio.android.logger.collector.core.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Platform;
+
+import com.motorola.studio.android.logger.collector.core.ILogFile;
+import com.motorola.studio.android.logger.collector.util.LoggerCollectorConstants;
+
+/**
+ * This class provides the Eclipse log file to the
+ * Log Files Collector feature
+ */
+public class EclipseLogFile implements ILogFile
+{
+ /*
+ * (non-Javadoc)
+ * @see com.motorola.studio.platform.logger.collector.core.ILogFile#getLogFilePath()
+ */
+ @Override
+ public List<IPath> getLogFilePath()
+ {
+ ArrayList<IPath> logs = new ArrayList<IPath>();
+ logs.add(Platform.getLogFileLocation());
+ return logs;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.motorola.studio.platform.logger.collector.core.ILogFile#getLogName()
+ */
+ @Override
+ public String getLogName()
+ {
+ return "Eclipse Log File";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.motorola.studio.platform.logger.collector.core.ILogFile#getOutputSubfolderName()
+ */
+ @Override
+ public String getOutputSubfolderName()
+ {
+ return LoggerCollectorConstants.PLATFORM_LOG_OUTPUT_FOLDER;
+ }
+}
diff --git a/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/core/internal/EnvironmentLogFile.java b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/core/internal/EnvironmentLogFile.java
new file mode 100644
index 0000000..000d703
--- /dev/null
+++ b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/core/internal/EnvironmentLogFile.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.motorola.studio.android.logger.collector.core.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+
+import com.motorola.studio.android.logger.collector.core.ILogFile;
+import com.motorola.studio.android.logger.collector.util.LoggerCollectorConstants;
+
+/**
+ * This class provides the environment log file
+ * to the log files collector feature
+ */
+public class EnvironmentLogFile implements ILogFile
+{
+ /*
+ * (non-Javadoc)
+ * @see com.motorola.studio.platform.logger.collector.core.ILogFile#getLogFilePath()
+ */
+ @Override
+ public List<IPath> getLogFilePath()
+ {
+ ArrayList<IPath> logs = new ArrayList<IPath>();
+ logs.add(new Path(LoggerCollectorConstants.LOG_PATH).append("environment.log"));
+ return logs;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.motorola.studio.platform.logger.collector.core.ILogFile#getLogName()
+ */
+ @Override
+ public String getLogName()
+ {
+ return "Environment Log File";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.motorola.studio.platform.logger.collector.core.ILogFile#getOutputSubfolderName()
+ */
+ @Override
+ public String getOutputSubfolderName()
+ {
+ return LoggerCollectorConstants.PLATFORM_LOG_OUTPUT_FOLDER;
+ }
+
+}
diff --git a/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/core/internal/StudioLogFile.java b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/core/internal/StudioLogFile.java
new file mode 100644
index 0000000..934455c
--- /dev/null
+++ b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/core/internal/StudioLogFile.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.motorola.studio.android.logger.collector.core.internal;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+
+import com.motorola.studio.android.logger.collector.core.ILogFile;
+import com.motorola.studio.android.logger.collector.util.LoggerCollectorConstants;
+
+/**
+ * This class provides the studio log files
+ * to the collect log files feature
+ */
+public class StudioLogFile implements ILogFile
+{
+ /*
+ * (non-Javadoc)
+ * @see com.motorola.studio.platform.logger.collector.core.ILogFile#getLogFilePath()
+ */
+ @Override
+ public List<IPath> getLogFilePath()
+ {
+ ArrayList<IPath> logs = new ArrayList<IPath>();
+ File rootLogDir = new File(LoggerCollectorConstants.LOG_PATH);
+ if (rootLogDir.exists() && rootLogDir.isDirectory())
+ {
+ File[] logFiles = rootLogDir.listFiles(new FileFilter()
+ {
+
+ @Override
+ public boolean accept(File pathname)
+ {
+ return pathname.getName().startsWith("studio");
+ }
+ });
+ for (File logFile : logFiles)
+ {
+ logs.add(new Path(logFile.getAbsolutePath()));
+ }
+ }
+
+ return logs;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.motorola.studio.platform.logger.collector.core.ILogFile#getLogName()
+ */
+ @Override
+ public String getLogName()
+ {
+ return "Studio Log File";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.motorola.studio.platform.logger.collector.core.ILogFile#getOutputSubfolderName()
+ */
+ @Override
+ public String getOutputSubfolderName()
+ {
+ return LoggerCollectorConstants.PLATFORM_LOG_OUTPUT_FOLDER;
+ }
+}
diff --git a/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/ui/LogFileColumn.java b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/ui/LogFileColumn.java
new file mode 100644
index 0000000..4541f32
--- /dev/null
+++ b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/ui/LogFileColumn.java
@@ -0,0 +1,217 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.motorola.studio.android.logger.collector.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jface.dialogs.MessageDialog;
+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.Display;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+
+import com.motorola.studio.android.logger.collector.core.ILogFile;
+import com.motorola.studio.android.logger.collector.core.internal.CollectLogFile;
+import com.motorola.studio.android.logger.collector.util.LoggerCollectorMessages;
+import com.motorola.studio.android.logger.collector.util.PlatformException;
+import com.motorola.studio.android.logger.collector.util.WidgetsUtil;
+
+/**
+ * This class visually represents a log file Table View.
+ */
+public class LogFileColumn extends Composite
+{
+
+ /**
+ * The table of log files.
+ */
+ private Table tableLogFile = null;
+
+ /**
+ *
+ */
+ CollectLogFile collectLogFile = null;
+
+ /**
+ * Public Constructor.
+ *
+ * @param parent Parent this Composite.
+ * @param style Composite Style.
+ */
+ public LogFileColumn(Composite parent, int style)
+ {
+ super(parent, style);
+ collectLogFile = new CollectLogFile();
+ initialize();
+ }
+
+ /**
+ * This method contains property of this composite.
+ */
+ private void initialize()
+ {
+ GridLayout gridLayoutTableView = new GridLayout();
+ gridLayoutTableView.horizontalSpacing = 0;
+ gridLayoutTableView.marginWidth = 0;
+ gridLayoutTableView.marginHeight = 0;
+ gridLayoutTableView.verticalSpacing = 0;
+ GridData gridDatagridLayout = new GridData(GridData.FILL_VERTICAL | SWT.TOP);
+ this.setBackgroundMode(SWT.NONE);
+ this.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
+ this.setLayoutData(gridDatagridLayout);
+ this.setLayout(gridLayoutTableView);
+
+ GridData gridData = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_BOTH);
+ gridData.widthHint = 230;
+ gridData.heightHint = 300;
+ this.setLayoutData(gridData);
+
+ refresh();
+ }
+
+ /**
+ * This is a callback that will allow us to create the viewer and initialize
+ * it.
+ */
+ public void refresh()
+ {
+ GridData gridDataTableView =
+ new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_BOTH);
+ gridDataTableView.widthHint = 236;
+ gridDataTableView.heightHint = 300;
+ if (tableLogFile == null)
+ {
+ tableLogFile = new Table(this, SWT.CHECK | SWT.BORDER);
+ tableLogFile.setLayoutData(gridDataTableView);
+ }
+ tableLogFile.removeAll();
+ try
+ {
+ for (ILogFile log : collectLogFile.getLogFileList())
+ {
+ TableItem tableItem = new TableItem(tableLogFile, SWT.NONE);
+ tableItem.setText(log.getLogName());
+ tableItem.setData(log);
+ }
+ }
+ catch (Exception e)
+ {
+ MessageDialog.openError(
+ getShell(),
+ LoggerCollectorMessages.getInstance().getString(
+ "logger.collector.wizard.page.title"), //$NON-NLS-1$
+ LoggerCollectorMessages.getInstance().getString(
+ "error.logger.collector.mount.tableview")); //$NON-NLS-1$
+ }
+ packTableColumns();
+ checkAll(true);
+ }
+
+ /**
+ * This method is responsible to pack tree columns
+ */
+ private void packTableColumns()
+ {
+ // Pack the columns
+ TableColumn[] columns = tableLogFile.getColumns();
+ for (int i = 0, n = columns.length; i < n; i++)
+ {
+ columns[i].pack();
+ }
+ }
+
+ /**
+ * This method collects and zips selected log files.
+ *
+ * @param directory The output directory
+ * @param filename The output file name
+ * @return if collects successfully
+ * @throws PlatformException
+ */
+ public boolean collect(String filename) throws PlatformException
+ {
+ return new CollectLogFile().zipLogFiles(filename,
+ WidgetsUtil.getCheckedLeafItems(this.tableLogFile));
+ }
+
+ /**
+ * This method tests if the table view has nodes and if there is selected
+ * nodes.
+ *
+ * @return true if the table view has nodes and if there is selected nodes.
+ */
+ public boolean hasNodeSelected()
+ {
+ return WidgetsUtil.getCheckedLeafItems(this.tableLogFile).size() > 0;
+ }
+
+ /**
+ * This method collects and compacts selected log files.
+ *
+ * @param directory The output directory
+ * @param filename The output file name
+ * @return if collects successfully
+ */
+ public ArrayList<String> selectedLogFilesExist()
+ {
+ List<TableItem> list = WidgetsUtil.getCheckedLeafItems(this.tableLogFile);
+ ArrayList<String> notFoundItems = new ArrayList<String>();
+ for (TableItem tableItem : list)
+ {
+ Object data = tableItem.getData();
+ if (data instanceof ILogFile)
+ {
+ ILogFile logFile = (ILogFile) data;
+ for (IPath path : logFile.getLogFilePath())
+ {
+ if (!WidgetsUtil.fileExist(path.toOSString()))
+ {
+ notFoundItems.add(logFile.getLogName());
+ }
+
+ }
+ }
+ }
+ return notFoundItems;
+ }
+
+ /**
+ * This method adds a TableListener
+ *
+ * @param eventType Type of event
+ * @param listener Listener
+ */
+ public void addTableListener(int eventType, Listener listener)
+ {
+ this.tableLogFile.addListener(eventType, listener);
+ }
+
+ public void checkAll(boolean selectionValue)
+ {
+ for (TableItem item : tableLogFile.getItems())
+ {
+ item.setChecked(selectionValue);
+ }
+
+ }
+}
diff --git a/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/ui/handler/LoggerCollectorHandler.java b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/ui/handler/LoggerCollectorHandler.java
new file mode 100644
index 0000000..2532582
--- /dev/null
+++ b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/ui/handler/LoggerCollectorHandler.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.motorola.studio.android.logger.collector.ui.handler;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+
+import com.motorola.studio.android.logger.collector.ui.wizard.LoggerCollectorWizard;
+import com.motorola.studio.android.logger.collector.util.WidgetsUtil;
+
+/**
+ * This class is responsible to handling action in menu collect log file item.
+ */
+public class LoggerCollectorHandler extends AbstractHandler
+{
+
+ /**
+ * This method is responsible to execute handler action
+ *
+ * @param event execute event
+ * @return handler action
+ */
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException
+ {
+ return WidgetsUtil.runWizard(new LoggerCollectorWizard());
+ }
+}
diff --git a/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/ui/wizard/LoggerCollectorWizard.java b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/ui/wizard/LoggerCollectorWizard.java
new file mode 100644
index 0000000..bdeb955
--- /dev/null
+++ b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/ui/wizard/LoggerCollectorWizard.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.motorola.studio.android.logger.collector.ui.wizard;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.wizard.Wizard;
+
+import com.motorola.studio.android.logger.collector.util.LoggerCollectorConstants;
+import com.motorola.studio.android.logger.collector.util.LoggerCollectorMessages;
+import com.motorola.studio.android.logger.collector.util.PlatformException;
+
+/**
+ * This class represents the logger collector wizard.
+ */
+public class LoggerCollectorWizard extends Wizard
+{
+
+ /**
+ * Initializing instance of wizard page
+ */
+ private final LoggerCollectorWizardPage loggerCollectorWizardPage =
+ new LoggerCollectorWizardPage("wizardPage"); //$NON-NLS-1$
+
+ /**
+ * The Constructor
+ */
+ public LoggerCollectorWizard()
+ {
+ setWindowTitle(LoggerCollectorMessages.getInstance().getString(
+ "logger.collector.wizard.page.title")); //$NON-NLS-1$
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.wizard.Wizard#canFinish()
+ */
+ @Override
+ public boolean canFinish()
+ {
+ return loggerCollectorWizardPage.isPageComplete();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.wizard.Wizard#addPages()
+ */
+ @Override
+ public void addPages()
+ {
+ super.addPages();
+ addPage(loggerCollectorWizardPage);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.wizard.Wizard#performFinish()
+ */
+ @Override
+ public boolean performFinish()
+ {
+ if (loggerCollectorWizardPage.getLogFileColumn() != null)
+ {
+ try
+ {
+
+ IPath filename = new Path(loggerCollectorWizardPage.getFilename());
+ if (filename.getFileExtension() == null
+ || !filename.getFileExtension().equalsIgnoreCase(
+ LoggerCollectorConstants.ZIP_FILE_EXTENSION))
+ {
+ filename =
+ filename.addFileExtension(LoggerCollectorConstants.ZIP_FILE_EXTENSION);
+ }
+ if (loggerCollectorWizardPage.getLogFileColumn().collect(filename.toOSString()))
+ {
+ MessageDialog.openInformation(
+ getShell(),
+ LoggerCollectorMessages.getInstance().getString(
+ "logger.collector.wizard.page.title"), //$NON-NLS-1$
+ LoggerCollectorMessages.getInstance().getString(
+ "logger.collector.wizard.success")); //$NON-NLS-1$
+ }
+ return true;
+ }
+ catch (PlatformException e)
+ {
+ MessageDialog.openError(getShell(), LoggerCollectorMessages.getInstance()
+ .getString("logger.collector.wizard.page.title"), //$NON-NLS-1$
+ e.getMessage());
+ return false;
+ }
+ }
+ return false;
+ }
+}
diff --git a/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/ui/wizard/LoggerCollectorWizardPage.java b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/ui/wizard/LoggerCollectorWizardPage.java
new file mode 100644
index 0000000..fc845b2
--- /dev/null
+++ b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/ui/wizard/LoggerCollectorWizardPage.java
@@ -0,0 +1,311 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.motorola.studio.android.logger.collector.ui.wizard;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.preference.DirectoryFieldEditor;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+
+import com.motorola.studio.android.logger.collector.ui.LogFileColumn;
+import com.motorola.studio.android.logger.collector.util.LoggerCollectorConstants;
+import com.motorola.studio.android.logger.collector.util.LoggerCollectorMessages;
+import com.motorola.studio.android.logger.collector.util.WidgetsFactory;
+import com.motorola.studio.android.logger.collector.util.WidgetsUtil;
+
+/**
+ * This class contains the design of collect log files wizard page.
+ */
+public class LoggerCollectorWizardPage extends WizardPage
+{
+
+ /**
+ * Directory field to output compacted file
+ */
+ private DirectoryFieldEditor logDirecotryField = null;
+
+ private Text filenameText = null;
+
+ public static final String LOGGER_COLLECTOR_HELP_ID =
+ "com.motorola.studio.platform.logger.collector.collectlogs";
+
+ /**
+ * Composite used to show the Log File TableColumn.
+ */
+ private LogFileColumn logFileColumn = null;
+
+ private Button selectAll = null;
+
+ private Button unselectAll = null;
+
+ /**
+ * Wizard composite
+ */
+ private Composite composite;
+
+ /**
+ * Field to check if user has changed the wizard
+ */
+ private boolean userChangedWizard = false;
+
+ /**
+ * The default constructor
+ *
+ * @param pageName The page name
+ */
+ protected LoggerCollectorWizardPage(String pageName)
+ {
+ super(pageName);
+ setTitle(LoggerCollectorMessages.getInstance().getString(
+ "logger.collector.wizard.page.title")); //$NON-NLS-1$
+ setDescription(LoggerCollectorMessages.getInstance().getString(
+ "logger.collector.wizard.page.description")); //$NON-NLS-1$
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
+ * .Composite)
+ */
+ @Override
+ public void createControl(Composite parent)
+ {
+ composite = getComposite(parent);
+ composite.setLayout(new GridLayout(1, false));
+ composite.setLayoutData(new GridData(GridData.FILL_VERTICAL | SWT.TOP));
+
+ Composite compositeTop = WidgetsFactory.createComposite(composite, 3);
+ logDirecotryField =
+ new DirectoryFieldEditor("logFileNameField", //$NON-NLS-1$
+ LoggerCollectorMessages.getInstance().getString(
+ "logger.collector.wizard.page.directory") + ":", //$NON-NLS-1$ //$NON-NLS-2$
+ compositeTop);
+
+ logDirecotryField.getTextControl(compositeTop).addListener(SWT.Modify, listener);
+ logDirecotryField.getTextControl(compositeTop).setTextLimit(200);
+
+ Label filenameLabel = new Label(compositeTop, SWT.NONE);
+ filenameLabel.setText(LoggerCollectorMessages.getInstance().getString(
+ "logger.collector.wizard.page.file"));//$NON-NLS-1$
+ GridData layoutData = new GridData(SWT.LEFT, SWT.CENTER, false, false);
+ filenameLabel.setLayoutData(layoutData);
+
+ filenameText = new Text(compositeTop, SWT.BORDER);
+
+ layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
+ filenameText.setLayoutData(layoutData);
+
+ Composite compositeBottom = WidgetsFactory.createComposite(composite, 2);
+
+ Label l = new Label(compositeBottom, SWT.NONE);
+ l.setText(LoggerCollectorMessages.getInstance()
+ .getString("logger.collector.tableview.root"));//$NON-NLS-1$
+ GridData d = new GridData(SWT.LEFT, SWT.NONE, true, false, 2, 1);
+ l.setLayoutData(d);
+ logFileColumn = new LogFileColumn(compositeBottom, SWT.NONE);
+ logFileColumn.addTableListener(SWT.Selection, listener);
+
+ Composite buttons = new Composite(compositeBottom, SWT.NONE);
+ d = new GridData(SWT.NONE, SWT.TOP, false, true, 1, 1);
+ buttons.setLayoutData(d);
+ FillLayout layout = new FillLayout(SWT.VERTICAL);
+ layout.spacing = 2;
+ buttons.setLayout(layout);
+
+ selectAll = new Button(buttons, SWT.PUSH);
+ selectAll.setText(LoggerCollectorMessages.getInstance().getString(
+ "logger.collector.wizard.page.selectAll"));
+ selectAll.addSelectionListener(new ButtonSelectionListener(true));
+ selectAll.addListener(SWT.Selection, listener);
+ unselectAll = new Button(buttons, SWT.PUSH);
+ unselectAll.setText(LoggerCollectorMessages.getInstance().getString(
+ "logger.collector.wizard.page.unselectAll"));
+ unselectAll.addSelectionListener(new ButtonSelectionListener(false));
+ unselectAll.addListener(SWT.Selection, listener);
+ setControl(composite);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), LOGGER_COLLECTOR_HELP_ID);
+
+ logDirecotryField.setStringValue(System.getProperty("user.home"));
+
+ Calendar c = Calendar.getInstance();
+ filenameText.setText("studio_andr_" + c.get(Calendar.YEAR) + c.get(Calendar.MONTH)
+ + c.get(Calendar.DAY_OF_MONTH) + c.get(Calendar.HOUR) + c.get(Calendar.MINUTE)
+ + "." + LoggerCollectorConstants.ZIP_FILE_EXTENSION);
+
+ setErrorMessage(null);
+ }
+
+ /**
+ * Listener of collect log files finish button
+ */
+ private final Listener listener = new Listener()
+ {
+
+ @Override
+ public void handleEvent(Event event)
+ {
+ userChangedWizard = true;
+ setPageComplete(isPageComplete());
+ setErrorMessage(getErrorMessage());
+ }
+ };
+
+ /**
+ * Return the composite used in the wizard.
+ *
+ * @param parent The parent content composite.
+ * @return The composite used in the wizard.
+ */
+ protected Composite getComposite(Composite parent)
+ {
+ if (this.composite == null)
+ {
+ this.composite = WidgetsFactory.createComposite(parent);
+ }
+ return this.composite;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.wizard.WizardPage#isPageComplete()
+ */
+ @Override
+ public boolean isPageComplete()
+ {
+ return (getErrorMessage() == null) && !WidgetsUtil.isNullOrEmpty(this.logDirecotryField)
+ && logFileColumn.hasNodeSelected();
+ }
+
+ /**
+ * Returns the error message, null if there is no error.
+ *
+ * @return an error message
+ */
+ @Override
+ public String getErrorMessage()
+ {
+ String message = null;
+ String outputDir = Path.fromOSString(this.logDirecotryField.getStringValue()).toOSString();
+ ArrayList<String> notFoundLogs = null;
+
+ if (userChangedWizard)
+ {
+ if (WidgetsUtil.isNullOrEmpty(this.logDirecotryField))
+ {
+ message =
+ LoggerCollectorMessages.getInstance().getString(
+ "error.logger.collector.directory.empty"); //$NON-NLS-1$
+ }
+ else if (!WidgetsUtil.fileExist(outputDir))
+ {
+ message =
+ LoggerCollectorMessages.getInstance().getString(
+ "error.logger.collector.directory.not.found"); //$NON-NLS-1$
+ }
+ else if ((logFileColumn != null) && !logFileColumn.hasNodeSelected())
+ {
+ message =
+ LoggerCollectorMessages.getInstance().getString(
+ "error.logger.collector.log.not.selected"); //$NON-NLS-1$
+ }
+ else if ((logFileColumn != null)
+ && ((notFoundLogs = logFileColumn.selectedLogFilesExist()).size() > 0))
+ {
+ StringBuilder messageBuilder =
+ new StringBuilder(LoggerCollectorMessages.getInstance().getString(
+ "error.logger.collector.log.not.found"));
+ messageBuilder.append(": ");
+ for (String log : notFoundLogs)
+ {
+ messageBuilder.append(log);
+ messageBuilder.append(",");
+ }
+ messageBuilder.deleteCharAt(messageBuilder.length() - 1);
+
+ message = messageBuilder.toString();
+ }
+ }
+ return message;
+ }
+
+ /**
+ * Gets the log file column (table view)
+ *
+ * @return log file column
+ */
+ public LogFileColumn getLogFileColumn()
+ {
+ return this.logFileColumn;
+ }
+
+ /**
+ * Gets the file name text
+ *
+ * @return the file name text
+ */
+ public String getFilename()
+ {
+ IPath fileName = new Path(filenameText.getText());
+ if ((fileName.getFileExtension() == null)
+ || !fileName.getFileExtension().equalsIgnoreCase(
+ LoggerCollectorConstants.ZIP_FILE_EXTENSION))
+ {
+ fileName.addFileExtension(LoggerCollectorConstants.ZIP_FILE_EXTENSION);
+ }
+
+ return new Path(this.logDirecotryField.getStringValue()).append(fileName).toOSString();
+ }
+
+ final class ButtonSelectionListener implements SelectionListener
+ {
+ private final boolean selectionValue;
+
+ public ButtonSelectionListener(boolean selectionValue)
+ {
+ this.selectionValue = selectionValue;
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e)
+ {
+ //do nothing
+ }
+
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ logFileColumn.checkAll(selectionValue);
+ }
+
+ };
+}
diff --git a/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/LogCollectorExtensionLoader.java b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/LogCollectorExtensionLoader.java
new file mode 100644
index 0000000..2bef177
--- /dev/null
+++ b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/LogCollectorExtensionLoader.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.motorola.studio.android.logger.collector.util;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.Platform;
+
+import com.motorola.studio.android.logger.collector.core.ILogFile;
+
+/**
+ * This class is responsible to load the log collector contributor
+ * extension point and read all needed information
+ */
+public class LogCollectorExtensionLoader
+{
+ private static final String LOGGER_EXTENSION_POINT_ID =
+ "com.motorola.studio.android.logger.collector.log";
+
+ private static final String LOG_FILE_ELEMENT = "logContribution";
+
+ private static final String LOG_FILE_ATTRIBUTE = "logFileImpl";
+
+ public static ArrayList<ILogFile> getLogFiles()
+ {
+ ArrayList<ILogFile> logs = new ArrayList<ILogFile>();
+ IExtensionPoint point =
+ Platform.getExtensionRegistry().getExtensionPoint(LOGGER_EXTENSION_POINT_ID);
+ if (point != null)
+ {
+ IExtension[] extensions = point.getExtensions();
+
+ for (IExtension ext : extensions)
+ {
+ for (IConfigurationElement element : ext.getConfigurationElements())
+ {
+ if (element.getName().equals(LOG_FILE_ELEMENT))
+ {
+ try
+ {
+ Object o = element.createExecutableExtension(LOG_FILE_ATTRIBUTE);
+ if (o instanceof ILogFile)
+ {
+ logs.add((ILogFile) o);
+ }
+ }
+ catch (CoreException e)
+ {
+ //do nothing
+ }
+ }
+ }
+ }
+
+ }
+
+ return logs;
+ }
+}
diff --git a/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/LoggerCollectorConstants.java b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/LoggerCollectorConstants.java
new file mode 100644
index 0000000..6415596
--- /dev/null
+++ b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/LoggerCollectorConstants.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.motorola.studio.android.logger.collector.util;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.Platform;
+
+/**
+ * Constant definitions for logger collector plug-in preferences
+ */
+public class LoggerCollectorConstants
+{
+
+ /**
+ * The constant contains a string representation of the regular expression
+ * to validate the file name format. The file name must follow the formats
+ * above: - Only alphanumeric characters and point must be supported
+ * ([A-Za-z0-9_.]). - The max length must be 60 characters;
+ */
+ public static final String FILE_NAME_REGEX = "[\\w.]{1,60}"; //$NON-NLS-1$
+
+ /**
+ * The plug-in ID
+ */
+ public static final String PLUGIN_ID = "com.motorolamobility.studio.android.logger.collector"; //$NON-NLS-1$
+
+ // The plugin path location
+ private static final String PLUGIN_LOCATION = File.separator + ".metadata" //$NON-NLS-1$
+ + File.separator + ".plugins" + File.separator //$NON-NLS-1$
+ + "com.motorolamobility.studio.android.logger"; //$NON-NLS-1$
+
+ // The absolute logger files path
+ public static final String LOG_PATH = Platform.getLocation() + PLUGIN_LOCATION;
+
+ public static final String PLATFORM_LOG_OUTPUT_FOLDER = "platform";
+
+ public static final String ZIP_FILE_EXTENSION = "zip";
+}
diff --git a/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/LoggerCollectorMessages.java b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/LoggerCollectorMessages.java
new file mode 100644
index 0000000..9311858
--- /dev/null
+++ b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/LoggerCollectorMessages.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.motorola.studio.android.logger.collector.util;
+
+import java.text.MessageFormat;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * Class to handle the messages. By default, all keys has the class name in its
+ * prefix, plus a sequential number.
+ */
+public class LoggerCollectorMessages
+{
+
+ /**
+ * The shared instance.
+ */
+ private static LoggerCollectorMessages instance = null;
+
+ /**
+ * Bundle to get messages from module (properties file).
+ */
+ private final ResourceBundle bundle;
+
+ /**
+ * Class used to get the message.
+ */
+ private Class<? extends Object> clazz;
+
+ /**
+ * Default constructor.
+ */
+ private LoggerCollectorMessages()
+ {
+ this.bundle = ResourceBundle.getBundle("loggerCollector"); //$NON-NLS-1$
+ }
+
+ /**
+ * Returns the single instance.
+ *
+ * @param clazz Class used to get the messages.
+ * @return The singleton instance.
+ */
+ public static synchronized LoggerCollectorMessages getInstance(Class<? extends Object> clazz)
+ {
+ if (instance == null)
+ {
+ instance = new LoggerCollectorMessages();
+ }
+ instance.clazz = clazz;
+ return instance;
+ }
+
+ /**
+ * Returns the single instance.
+ *
+ * @return The singleton instance.
+ */
+ public static synchronized LoggerCollectorMessages getInstance()
+ {
+ if (instance == null)
+ {
+ instance = new LoggerCollectorMessages();
+ }
+ instance.clazz = null;
+ return instance;
+ }
+
+ /**
+ * Returns the message of the given key.
+ *
+ * @param key The message key
+ * @return The message of the given key.
+ */
+ public String getString(String key)
+ {
+ try
+ {
+ return bundle
+ .getString(((this.clazz == null) ? "" : (this.clazz.getName() + ".")) + key); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ catch (MissingResourceException e)
+ {
+ return "!" + key + "!"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ /**
+ * Returns the message of the given key.
+ *
+ * @param key The message key
+ * @param arguments Arguments to replace the pattern in the corresponding
+ * message of the key.
+ * @return The message of the given key.
+ */
+ public String getString(String key, Object... arguments)
+ {
+ try
+ {
+ String message =
+ bundle.getString(((this.clazz == null) ? "" : (this.clazz.getName() + ".")) + key); //$NON-NLS-1$ //$NON-NLS-2$
+ return MessageFormat.format(message, arguments);
+ }
+ catch (MissingResourceException e)
+ {
+ return "!" + key + "!"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+}
diff --git a/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/PlatformException.java b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/PlatformException.java
new file mode 100644
index 0000000..b30ccba
--- /dev/null
+++ b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/PlatformException.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.motorola.studio.android.logger.collector.util;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+
+/**
+ * This class represents a basic platform exception that all Studios should
+ * extend and implement other functions. The error is logged when the status
+ * severity is <code>IStatus.CANCEL</code>.
+ *
+ * @see org.eclipse.core.runtime.CoreException
+ */
+
+public class PlatformException extends CoreException
+{
+
+ /**
+ * Universal version identifier for a Serializable object.
+ */
+ private static final long serialVersionUID = 5165818604668097411L;
+
+ /**
+ * Construct a platform exception with the given status.
+ *
+ * @param status The IStatus.
+ */
+ public PlatformException(final IStatus status)
+ {
+ super(status);
+ if (status.getSeverity() == IStatus.CANCEL)
+ {
+ PlatformLogger.getInstance(PlatformException.class).error(this.getMessage(), this);
+ }
+ }
+}
diff --git a/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/PlatformLogger.java b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/PlatformLogger.java
new file mode 100644
index 0000000..efdac2b
--- /dev/null
+++ b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/PlatformLogger.java
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.motorola.studio.android.logger.collector.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.motorola.studio.android.logger.Logger;
+
+/**
+ * Class with useful methods to log errors.
+ */
+public class PlatformLogger
+{
+
+ /**
+ * Logger for this class.
+ */
+ private final Logger logger;
+
+ /**
+ * Shared instances by Class
+ */
+ private static Map<Class<? extends Object>, PlatformLogger> instances =
+ new HashMap<Class<? extends Object>, PlatformLogger>();
+
+ /**
+ * Default constructor
+ *
+ * @param clazz Class to be logged.
+ */
+ private PlatformLogger(Class<? extends Object> clazz)
+ {
+ this.logger = Logger.getLogger(clazz.getName());
+ }
+
+ /**
+ * Returns an instance by a given class object.
+ *
+ * @param clazz The given class.
+ * @return an instance by a given class object.
+ */
+ public static synchronized PlatformLogger getInstance(Class<? extends Object> clazz)
+ {
+ PlatformLogger instance = instances.get(clazz);
+ if (instance == null)
+ {
+ instance = new PlatformLogger(clazz);
+ instances.put(clazz, instance);
+ }
+ return instance;
+ }
+
+ /**
+ * Log a message object with the DEBUG level.
+ *
+ * @param message The message to log.
+ */
+ public void debug(String message)
+ {
+ debug(message, null);
+ }
+
+ /**
+ * Log a message object with the DEBUG level.
+ *
+ * @param message The message to log.
+ * @param exception Exception whose stack will be logged.
+ */
+ public void debug(String message, Throwable exception)
+ {
+ if (null == exception)
+ {
+ logger.debug(message);
+ }
+ else
+ {
+ logger.debug(message, exception);
+ }
+ }
+
+ /**
+ * Log a message object with the WARN level.
+ *
+ * @param message The message to log.
+ */
+ public void warn(String message)
+ {
+ warn(message, null);
+ }
+
+ /**
+ * Log a message object with the WARN level.
+ *
+ * @param message The message to log.
+ * @param exception Exception whose stack will be logged.
+ */
+ public void warn(String message, Throwable exception)
+ {
+ if (null == exception)
+ {
+ logger.warn(message);
+ }
+ else
+ {
+ logger.warn(message, exception);
+ }
+ }
+
+ /**
+ * Log a message object with the FATAL level.
+ *
+ * @param message The message to log.
+ */
+ public void fatal(String message)
+ {
+ fatal(message, null);
+ }
+
+ /**
+ * Log a message object with the FATAL level.
+ *
+ * @param message The message to log.
+ * @param exception Exception whose stack will be logged.
+ */
+ public void fatal(String message, Throwable exception)
+ {
+ if (null == exception)
+ {
+ logger.fatal(message);
+ }
+ else
+ {
+ logger.fatal(message, exception);
+ }
+ }
+
+ /**
+ * Log a message object with the INFO level.
+ *
+ * @param message The message to log.
+ */
+ public void info(String message)
+ {
+ info(message, null);
+ }
+
+ /**
+ * Log a message object with the INFO level.
+ *
+ * @param message The message to log.
+ * @param exception Exception whose stack will be logged.
+ */
+ public void info(String message, Throwable exception)
+ {
+ if (null == exception)
+ {
+ logger.info(message);
+ }
+ else
+ {
+ logger.info(message, exception);
+ }
+ }
+
+ /**
+ * Log a message object with the ERROR level.
+ *
+ * @param message The message to log.
+ */
+ public void error(String message)
+ {
+ this.logger.error(message);
+ }
+
+ /**
+ * Log a message object with the ERROR level.
+ *
+ * @param message The message to log.
+ * @param exception Exception whose stack will be logged.
+ */
+ public void error(String message, Throwable exception)
+ {
+ this.logger.error(message, exception);
+ }
+
+}
diff --git a/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/WidgetsFactory.java b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/WidgetsFactory.java
new file mode 100644
index 0000000..40c679c
--- /dev/null
+++ b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/WidgetsFactory.java
@@ -0,0 +1,445 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.motorola.studio.android.logger.collector.util;
+
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.ToolBar;
+import org.eclipse.swt.widgets.ToolItem;
+import org.eclipse.swt.widgets.TreeItem;
+
+/**
+ * Class factory to create widgets.
+ */
+public class WidgetsFactory
+{
+
+ /**
+ * Create a new composite with two columns.
+ *
+ * @param parent The parent composite.
+ * @return A composite with two columns.
+ */
+ public static Composite createComposite(Composite parent)
+ {
+ Composite toReturn = new Composite(parent, SWT.NULL);
+ toReturn.setLayout(createGridLayout());
+ toReturn.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL));
+
+ return toReturn;
+ }
+
+ /**
+ * Create a new composite with the given column count.
+ *
+ * @param parent The parent composite.
+ * @param numColumns The column count for the new composite.
+ * @return A composite with the given column count.
+ */
+ public static Composite createComposite(Composite parent, int numColumns)
+ {
+ Composite toReturn = createComposite(parent);
+ ((GridLayout) toReturn.getLayout()).numColumns = numColumns;
+
+ return toReturn;
+ }
+
+ /**
+ * Creates a new line.
+ *
+ * @param parent The parent composite.
+ * @return A label with a line.
+ */
+ public static Label createLine(Composite parent)
+ {
+ Label toReturn = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.BOLD);
+ GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
+ gridData.horizontalSpan = ((GridLayout) parent.getLayout()).numColumns;
+ toReturn.setLayoutData(gridData);
+
+ return toReturn;
+ }
+
+ /**
+ * Creates a new GridLayout with two columns.
+ *
+ * @return A new GridLayout with two columns.
+ */
+ public static GridLayout createGridLayout()
+ {
+ GridLayout toReturn = new GridLayout();
+ toReturn.numColumns = 2;
+ toReturn.makeColumnsEqualWidth = false;
+ toReturn.marginWidth = 0;
+ toReturn.marginHeight = 0;
+
+ return toReturn;
+ }
+
+ /**
+ * Creates a new GridLayout with the given number of columns.
+ *
+ * @return A new GridLayout with the given number of columns.
+ */
+ public static GridLayout createGridLayout(int numColumns)
+ {
+ GridLayout toReturn = new GridLayout();
+ toReturn.numColumns = numColumns;
+ toReturn.makeColumnsEqualWidth = false;
+ toReturn.marginWidth = 0;
+ toReturn.marginHeight = 0;
+
+ return toReturn;
+ }
+
+ /**
+ * Creates a new GridLayout with the given number of columns for the given
+ * composite.
+ *
+ * @return A new GridLayout with the given number of columns for the given
+ * composite.
+ */
+ public static GridLayout createGridLayout(int numColumns, Composite composite)
+ {
+ GridLayout toReturn = new GridLayout();
+ toReturn.numColumns = numColumns;
+ toReturn.makeColumnsEqualWidth = false;
+ toReturn.marginWidth = 0;
+ toReturn.marginHeight = 0;
+
+ composite.setLayout(toReturn);
+ return toReturn;
+ }
+
+ /**
+ * Creates a new label.
+ *
+ * @param parent The parent composite.
+ * @param text Text used in label.
+ * @return A new label
+ */
+ public static Label createLabel(Composite parent, String text)
+ {
+ return createLabel(parent, text, SWT.NONE);
+ }
+
+ /**
+ * Creates a new label.
+ *
+ * @param parent The parent composite.
+ * @param text Text used in label.
+ * @param style The style used in label.
+ * @return A new label
+ */
+ public static Label createLabel(Composite parent, String text, int style)
+ {
+ Label toReturn = new Label(parent, style);
+ if (text != null)
+ {
+ toReturn.setText(text);
+ }
+ toReturn.setFont(parent.getFont());
+
+ return toReturn;
+ }
+
+ /**
+ * Creates a new combo.
+ *
+ * @param parent The parent composite.
+ * @return The new combo
+ */
+ public static Combo createCombo(Composite parent)
+ {
+ Combo toReturn = new Combo(parent, SWT.READ_ONLY);
+ GridData data = new GridData(GridData.FILL_HORIZONTAL);
+ data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
+ data.horizontalSpan = 1;
+ toReturn.setLayoutData(data);
+
+ return toReturn;
+ }
+
+ /**
+ * Creates two labels used to show a read only value in screens.
+ *
+ * @param parent The parent composite.
+ * @param text The text used in both labels.
+ * @return The label that will show a read only value.
+ */
+ public static Label createValueLabel(Composite parent, String text)
+ {
+ createLabel(parent, text);
+
+ return createLabel(parent, null);
+ }
+
+ /**
+ * Creates a new button.
+ *
+ * @param parent The parent composite.
+ * @param text The text of the button.
+ * @return A new button
+ */
+ public static Button createButton(Composite parent, String text)
+ {
+ Button toReturn = new Button(parent, SWT.PUSH);
+ toReturn.setFont(parent.getFont());
+ toReturn.setText(text);
+ toReturn.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ return toReturn;
+ }
+
+ /**
+ * Creates a new table widget.
+ *
+ * @param parent The parent composite.
+ * @return The new table
+ */
+ public static Table createTable(Composite parent)
+ {
+ Table toReturn =
+ new Table(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION
+ | SWT.BORDER);
+ GridData data = new GridData(GridData.FILL_BOTH);
+ data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
+ data.heightHint = toReturn.getItemHeight();
+ data.horizontalSpan = 1;
+ toReturn.setLayoutData(data);
+
+ return toReturn;
+ }
+
+ /**
+ * Creates a new table widget.
+ *
+ * @param parent The parent composite.
+ * @return The new table
+ */
+ public static Table createTableMultiSelection(Composite parent)
+ {
+ Table toReturn =
+ new Table(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER
+ | SWT.MULTI);
+ GridData data = new GridData(GridData.FILL_BOTH);
+ data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
+ data.heightHint = toReturn.getItemHeight();
+ data.horizontalSpan = 1;
+ toReturn.setLayoutData(data);
+
+ return toReturn;
+ }
+
+ /**
+ * Creates a new table column.
+ *
+ * @param table The table of the column.
+ * @param text The column text.
+ * @return A new table column
+ */
+ public static TableColumn createTableColumn(Table table, String text)
+ {
+ TableColumn toReturn = new TableColumn(table, SWT.NONE);
+ toReturn.setText(text);
+
+ return toReturn;
+ }
+
+ /**
+ * Creates a new table item.
+ *
+ * @param table The table of the table item.
+ * @param image The image of the item.
+ * @param s The text of the item.
+ * @return The new table item.
+ */
+ public static TableItem createTableItem(Table table, Image image, String s)
+ {
+ TableItem toReturn = new TableItem(table, SWT.NONE);
+ toReturn.setText(s);
+ if (image != null)
+ {
+ toReturn.setImage(image);
+ }
+
+ return toReturn;
+ }
+
+ /**
+ * Creates a collection of table items.
+ *
+ * @param table The table of the table item.
+ * @param image The image of the item.
+ * @param s The text of the item.
+ * @return The new table item.
+ */
+ public static TableItem createTableItem(Table table, Image image, String... s)
+ {
+ TableItem toReturn = new TableItem(table, SWT.NONE);
+ toReturn.setText(s);
+ if (image != null)
+ {
+ toReturn.setImage(image);
+ }
+
+ return toReturn;
+ }
+
+ /**
+ * Creates a new text.
+ *
+ * @param parent The parent composite.
+ * @return The new text.
+ */
+ public static Text createText(Composite parent)
+ {
+ Text toReturn = new Text(parent, SWT.BORDER);
+ GridData data = new GridData(GridData.FILL_HORIZONTAL);
+ data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
+ toReturn.setLayoutData(data);
+
+ return toReturn;
+ }
+
+ /**
+ * Creates a new tree item. If the text parameter is null, it will appear is
+ * after the field parameter.
+ *
+ * @param itemParent The parent tree item
+ * @param image The image of the tree item.
+ * @param field The field.
+ * @param text The text of the tree item.
+ * @return The new tree item.
+ */
+ public static TreeItem createTreeItem(TreeItem itemParent, Image image, String field,
+ String text)
+ {
+ TreeItem toReturn = new TreeItem(itemParent, 0);
+ toReturn.setText((text == null) ? field : field + " (" + text + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ toReturn.setImage(image);
+ toReturn.setExpanded(true);
+
+ return toReturn;
+ }
+
+ /**
+ * Creates a new horizontal tool bar.
+ *
+ * @param parent The parent tool bar item.
+ * @return A new tool bar item.
+ */
+ public static ToolBar createHorizontalToolBar(Composite parent)
+ {
+ return new ToolBar(parent, SWT.HORIZONTAL);
+ }
+
+ /**
+ * Creates a new tool item like a push button
+ *
+ * @param toolBar The parent tool bar item.
+ * @return A new tool item.
+ */
+ public static ToolItem createPushToolItem(ToolBar toolBar)
+ {
+ return new ToolItem(toolBar, SWT.PUSH);
+ }
+
+ /**
+ * Creates a titled group.
+ *
+ * @param parent The parent composite
+ * @param title The desired title.
+ * @return The titled group
+ */
+ public static Group createTitledGroup(Composite parent, String title)
+ {
+ Group toReturn = new Group(parent, SWT.SHADOW_NONE);
+ toReturn.setText(title);
+ toReturn.setLayout(new GridLayout());
+ toReturn.setLayoutData(new GridData(GridData.FILL_BOTH));
+ return toReturn;
+ }
+
+ /**
+ * Creates a titled group with the given number of columns.
+ *
+ * @param parent The parent composite.
+ * @param title The group title.
+ * @param numColumns The number of columns.
+ * @return The created group.
+ */
+ public static Group createTitledGroup(Composite parent, String title, int numColumns)
+ {
+ Group toReturn = new Group(parent, SWT.SHADOW_NONE);
+ toReturn.setText(title);
+ GridLayout layout = createGridLayout(numColumns);
+ toReturn.setLayout(layout);
+ return toReturn;
+ }
+
+ /**
+ * Creates a group
+ *
+ * @param parent The parent composite
+ * @return The group
+ */
+ public static Group createGroup(Composite parent)
+ {
+ Group toReturn = new Group(parent, SWT.SHADOW_NONE);
+ return toReturn;
+ }
+
+ /**
+ * Creates a radio button
+ *
+ * @param parent The parent composite
+ * @param text The given text.
+ * @return The radio button
+ */
+ public static Button createRadioButton(Composite parent, String text)
+ {
+ Button toReturn = new Button(parent, SWT.RADIO);
+ toReturn.setText(text);
+ toReturn.setLayoutData(new GridData(GridData.FILL_BOTH));
+ return toReturn;
+ }
+
+ /**
+ * Creates a list.
+ *
+ * @param parent The parent composite.
+ * @return The list.
+ */
+ public static List createList(Composite parent)
+ {
+ return new List(parent, SWT.BORDER | SWT.SINGLE);
+ }
+
+}
diff --git a/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/WidgetsUtil.java b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/WidgetsUtil.java
new file mode 100644
index 0000000..caa7f54
--- /dev/null
+++ b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/WidgetsUtil.java
@@ -0,0 +1,392 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.motorola.studio.android.logger.collector.util;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.preference.FileFieldEditor;
+import org.eclipse.jface.preference.PreferenceDialog;
+import org.eclipse.jface.preference.PreferenceManager;
+import org.eclipse.jface.preference.StringFieldEditor;
+import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Monitor;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Class with useful methods for widgets.
+ */
+public class WidgetsUtil
+{
+
+ /**
+ * This method test if a given String is null or empty.
+ *
+ * @param s The String
+ * @return <code>true</code> if the String is null or empty,
+ * <code>false</code> otherwise.
+ */
+ private static boolean isNullOrEmpty(String s)
+ {
+ return ((s != null) && s.trim().equals("")); //$NON-NLS-1$
+ }
+
+ /**
+ * The method verify if the file exist.
+ *
+ * @param fileName The full path for file.
+ * @return <code>true</code> if the file exist, <code>false</code>
+ * otherwise.
+ */
+ public static boolean fileExist(String fileName)
+ {
+ return !isNullOrEmpty(fileName) && new File(fileName).exists();
+ }
+
+ /**
+ * This method test if some StringFieldEditor value of the given collection
+ * is null or empty.
+ *
+ * @param editors
+ * @return <code>true</code> if some StringFieldEditor value is null or
+ * empty, <code>false</code> otherwise.
+ */
+ public static boolean isNullOrEmpty(StringFieldEditor... editors)
+ {
+ for (StringFieldEditor editor : editors)
+ {
+ if (isNullOrEmpty(editor))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * This method test if a StringFieldEditor value is null or empty.
+ *
+ * @param editor The StringFieldEditor
+ * @return <code>true</code> if the StringFieldEditor value is null or
+ * empty, <code>false</code> otherwise.
+ */
+ public static boolean isNullOrEmpty(StringFieldEditor editor)
+ {
+ return ((editor != null) && isNullOrEmpty(editor.getStringValue()));
+ }
+
+ /**
+ * This method test if a StringFieldEditor value contains a invalid
+ * character.
+ *
+ * @param editor The StringFieldEditor
+ * @return <code>true</code> if the StringFieldEditor value contains invalid
+ * character, <code>false</code> otherwise.
+ */
+ public static boolean checkExistInvalidCharacter(StringFieldEditor editor, String invalidChars)
+ {
+ for (int i = 0; i < invalidChars.length(); i++)
+ {
+ String invalidChar = invalidChars.substring(i, i + 1);
+ if (editor.getStringValue().contains(invalidChar))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * This method test if a Text value is null or empty.
+ *
+ * @param text The Text
+ * @return <code>true</code> if the Text value is null or empty,
+ * <code>false</code> otherwise.
+ */
+ public static boolean isNullOrEmpty(Text text)
+ {
+ return ((text != null) && isNullOrEmpty(text.getText()));
+ }
+
+ /**
+ * This method test if a FileFieldEditor value is null or empty.
+ *
+ * @param editor The FileFieldEditor
+ * @return <code>true</code> if the FileFieldEditor value is null or empty,
+ * <code>false</code> otherwise.
+ */
+ public static boolean isEmpty(FileFieldEditor editor)
+ {
+ return isNullOrEmpty(editor.getStringValue());
+ }
+
+ /**
+ * This method test if a Combo value is null or empty.
+ *
+ * @param combo The Combo
+ * @return <code>true</code> if the Combo value is null or not selected,
+ * <code>false</code> otherwise.
+ */
+ public static boolean isNullOrDeselected(Combo combo)
+ {
+ return ((combo != null) && (combo.getSelectionIndex() == -1));
+ }
+
+ /**
+ * Returns the size of file.
+ *
+ * @param fileName The file name.
+ * @return The size of file.
+ */
+ public static long fileSize(String fileName)
+ {
+ return new File(fileName).length();
+ }
+
+ /**
+ * This method test if a Table has one or more lines.
+ *
+ * @param table The table
+ * @return <code>true</code> if the Table has one or more lines,
+ * <code>false</code> otherwise.
+ */
+ public static boolean isNullOrEmpty(Table table)
+ {
+ return table.getItemCount() > 0;
+ }
+
+ /**
+ * Executes a wizard.
+ *
+ * @param wizard The wizard.
+ * @return <code>true</code> if the Wizard dialog has constant OK,
+ * <code>false</code> otherwise .
+ */
+ public static boolean runWizard(IWizard wizard)
+ {
+ Shell activeShell = Display.getCurrent().getActiveShell();
+ WizardDialog dialog = new WizardDialog(activeShell, wizard);
+
+ try
+ {
+ dialog.create();
+ }
+ catch (Throwable e)
+ {
+ e.printStackTrace();
+ }
+ centerDialog(dialog);
+ return dialog.open() == WizardDialog.OK;
+ }
+
+ /**
+ * Opens the Eclipse preferences dialog and selects the page of the given
+ * id.
+ *
+ * @param shell The shell.
+ * @param selectedNode The preferences page to selec.
+ * @return <code>true</code> if the Wizard dialog has constant OK,
+ * <code>false</code> otherwise .
+ */
+ public static boolean runPreferencePage(Shell shell, String selectedNode)
+ {
+ PreferenceManager manager = PlatformUI.getWorkbench().getPreferenceManager();
+ PreferenceDialog dialog = new PreferenceDialog(shell, manager);
+ dialog.setSelectedNode(selectedNode);
+ WidgetsUtil.centerDialog(shell);
+ return dialog.open() == PreferenceDialog.OK;
+ }
+
+ /**
+ * Center the dialog.
+ *
+ * @param shell The shell.
+ */
+ public static void centerDialog(Shell shell)
+ {
+ Monitor primary = shell.getDisplay().getPrimaryMonitor();
+ Rectangle bounds = primary.getBounds();
+ Rectangle rect = shell.getBounds();
+ int x = bounds.x + (bounds.width - rect.width) / 2;
+ int y = bounds.y + (bounds.height - rect.height) / 2;
+ shell.setLocation(x, y);
+ }
+
+ /**
+ * Center the dialog.
+ *
+ * @param dialog The dialog.
+ */
+ public static void centerDialog(Dialog dialog)
+ {
+ centerDialog(dialog.getShell());
+ }
+
+ /**
+ * Check the leaf items of the given tree.
+ *
+ * @param tree The tree.
+ * @return A collection containing the leaf tree items.
+ */
+ public static List<TreeItem> getCheckedLeafItems(Tree tree)
+ {
+ List<TreeItem> toReturn = new ArrayList<TreeItem>();
+ selectCheckedLeafItems(tree.getItems(), toReturn);
+ return toReturn;
+ }
+
+ /**
+ * Returns a list of the leaf nodes that are checked.
+ *
+ * @param items The parent items.
+ * @param list A list of the leaf nodes that are checked.
+ */
+ private static void selectCheckedLeafItems(TreeItem[] items, List<TreeItem> list)
+ {
+ int len = items.length;
+ for (int i = 0; i < len; i++)
+ {
+ if (items[i].getItemCount() > 0)
+ {
+ selectCheckedLeafItems(items[i].getItems(), list);
+ }
+ else if (items[i].getChecked())
+ {
+ list.add(items[i]);
+ }
+ }
+ }
+
+ /**
+ * Expand all the given tree items.
+ *
+ * @param items The tree items.
+ */
+ public static void expandAll(TreeItem[] items)
+ {
+ for (int i = 0; i < items.length; i++)
+ {
+ if (items[i].getItems().length > 0)
+ {
+ items[i].setExpanded(true);
+ expandAll(items[i].getItems());
+ }
+ }
+ }
+
+ /**
+ * Returns the full path of a given tree item.
+ *
+ * @param item The tree item.
+ * @return The full path of a given tree item.
+ */
+ public static String getFullPathTreeItem(TreeItem item)
+ {
+ String toReturn = item.getText();
+ if (item != null)
+ {
+ if (item.getParentItem() != null)
+ {
+ toReturn = getFullPathTreeItem(item.getParentItem()) + "." + toReturn; //$NON-NLS-1$
+ }
+ }
+ return toReturn;
+ }
+
+ /**
+ * This method verifies if a given file can be read.
+ *
+ * @param fileName the full file path.
+ * @return <code>true</code> if read permission is granted,
+ * <code>false</code> otherwise.
+ */
+ public static boolean canRead(String fileName)
+ {
+ return !isNullOrEmpty(fileName) && new File(fileName).canRead();
+ }
+
+ /**
+ * This method verifies if a given file has the read and write permissions
+ * granted.
+ *
+ * @param fileName The file
+ * @return <code>true</code> if permissions are granted, <code>false</code>
+ * otherwise.
+ */
+ public static boolean canReadWrite(String fileName)
+ {
+ File file = new File(fileName);
+ return file.canRead() && file.canWrite();
+ }
+
+ /**
+ * This method simulates a refresh in a Composite object.
+ *
+ * @param composite A composite object.
+ */
+ public static void refreshComposite(Composite composite)
+ {
+ for (Composite parent = composite.getParent(); parent != null; parent = parent.getParent())
+ {
+ parent.layout();
+ }
+ }
+
+ /**
+ * Check the leaf items of the given table.
+ *
+ * @param table The table.
+ * @return A collection containing the leaf table items.
+ */
+ public static List<TableItem> getCheckedLeafItems(Table table)
+ {
+ List<TableItem> toReturn = new ArrayList<TableItem>();
+ selectCheckedLeafItems(table.getItems(), toReturn);
+ return toReturn;
+ }
+
+ /**
+ * Returns a list of the leaf nodes that are checked.
+ *
+ * @param items The parent items.
+ * @param list A list of the leaf nodes that are checked.
+ */
+ private static void selectCheckedLeafItems(TableItem[] items, List<TableItem> list)
+ {
+ int len = items.length;
+ for (int i = 0; i < len; i++)
+ {
+ if (items[i].getChecked())
+ {
+ list.add(items[i]);
+ }
+ }
+ }
+}
diff --git a/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/ZipUtil.java b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/ZipUtil.java
new file mode 100644
index 0000000..f2c943c
--- /dev/null
+++ b/src/plugins/logger.collector/src/com/motorola/studio/android/logger/collector/util/ZipUtil.java
@@ -0,0 +1,260 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.motorola.studio.android.logger.collector.util;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.zip.CRC32;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import java.util.zip.ZipOutputStream;
+
+/**
+ * Class with useful method to compact (zip) files and directories.
+ */
+public class ZipUtil
+{
+
+ /**
+ * The default buffer.
+ */
+ private static final int BUFFER = 2048;
+
+ /**
+ * The output file.
+ */
+ private File outputFile = null;
+
+ /**
+ * This file represents the current directory.
+ */
+ private File directory = null;
+
+ /**
+ * A ZipOutputStream object.
+ */
+ private ZipOutputStream zos = null;
+
+ /**
+ * The path of current directory.
+ */
+ private final String currentDirectory;
+
+ /**
+ * Class constructor.
+ *
+ * @param outputFile The output to create the zip file.
+ * @param directory The directory that will be compacted.
+ * @throws IOException
+ */
+ public ZipUtil(String outputFile, String directory) throws IOException
+ {
+ this(new File(outputFile), new File(directory));
+ }
+
+ /**
+ * Class constructor.
+ *
+ * @param outputFile The file where the zip file will be created.
+ * @param directory The directory that will be compacted.
+ * @throws IOException
+ */
+ public ZipUtil(File outputFile, File directory) throws IOException
+ {
+ this.outputFile = outputFile;
+ this.directory = directory;
+ this.currentDirectory = directory.getAbsolutePath();
+ }
+
+ /**
+ * Compact the content.
+ *
+ * @throws IOException
+ */
+ public final void zip() throws IOException
+ {
+ FileOutputStream fos = null;
+ try
+ {
+ fos = new FileOutputStream(outputFile);
+ zos = new ZipOutputStream(fos);
+ zipDir(directory);
+ zos.flush();
+ }
+ finally
+ {
+ try
+ {
+ zos.close();
+ fos.close();
+ }
+ catch (IOException io)
+ {
+ io.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * Compact directory the content.
+ *
+ * @param dir The directory
+ * @throws IOException
+ */
+ private final void zipDir(File dir) throws IOException
+ {
+ if (!dir.getPath().equals(currentDirectory))
+ {
+ String entryName = dir.getPath().substring(currentDirectory.length() + 1);
+ entryName = entryName.replace('\\', '/'); //$NON-NLS-1$ //$NON-NLS-2$
+ ZipEntry ze = new ZipEntry(entryName + "/"); //$NON-NLS-1$
+ if ((dir != null) && dir.exists())
+ {
+ ze.setTime(dir.lastModified());
+ }
+ else
+ {
+ ze.setTime(System.currentTimeMillis());
+ }
+ ze.setSize(0);
+ ze.setMethod(ZipEntry.STORED);
+ ze.setCrc(new CRC32().getValue());
+ zos.putNextEntry(ze);
+ }
+
+ if (dir.exists() && dir.isDirectory())
+ {
+ File[] fileList = dir.listFiles();
+ for (int i = 0; i < fileList.length; i++)
+ {
+ if (fileList[i].isDirectory())
+ {
+ zipDir(fileList[i]);
+ }
+ if (fileList[i].isFile())
+ {
+ zipFile(fileList[i]);
+ }
+ }
+ }
+ }
+
+ /**
+ * Compact the file content.
+ *
+ * @param file The file
+ * @throws IOException
+ */
+ private void zipFile(File file) throws IOException
+ {
+ if (!file.equals(this.outputFile))
+ {
+ BufferedInputStream bis = null;
+ try
+ {
+ bis = new BufferedInputStream(new FileInputStream(file), BUFFER);
+
+ String entryName = file.getPath().substring(currentDirectory.length() + 1);
+ entryName = entryName.replace('\\', '/'); //$NON-NLS-1$ //$NON-NLS-2$
+ ZipEntry fileEntry = new ZipEntry(entryName);
+ zos.putNextEntry(fileEntry);
+
+ byte[] data = new byte[BUFFER];
+ int byteCount;
+ while ((byteCount = bis.read(data, 0, BUFFER)) != -1)
+ {
+ zos.write(data, 0, byteCount);
+ }
+
+ }
+ finally
+ {
+ bis.close();
+ }
+ }
+ }
+
+ /**
+ * Unpacks a zip file to the target directory.
+ *
+ * @param zipFilePath The zip file.
+ * @param destDirPath The destination directory.
+ * @throws IOException
+ */
+ public static void unzip(String zipFilePath, String destDirPath) throws IOException
+ {
+ try
+ {
+ File zipFile = new File(zipFilePath);
+ File folder = new File(destDirPath);
+ ZipFile zip = new ZipFile(zipFile);
+ Enumeration<? extends ZipEntry> entries = zip.entries();
+ while (entries.hasMoreElements())
+ {
+ ZipEntry entry = entries.nextElement();
+ unzipEntry(zip, entry, folder);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Error while trying to unzip jar file"); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Validate and write the stream of file.
+ *
+ * @param zipFile The zip file
+ * @param zipEntry The zip entry
+ * @param folder The folder
+ * @throws IOException
+ */
+ private static void unzipEntry(ZipFile zipFile, ZipEntry zipEntry, File folder)
+ throws IOException
+ {
+ if (zipEntry.isDirectory())
+ {
+ com.motorola.studio.android.common.utilities.FileUtil.mkdir(new File(folder, zipEntry
+ .getName()).getPath());
+ }
+ else
+ {
+ File outputFile = new File(folder, zipEntry.getName());
+ if (!outputFile.getParentFile().exists())
+ {
+ com.motorola.studio.android.common.utilities.FileUtil.mkdir(outputFile
+ .getParentFile().getPath());
+ }
+ BufferedInputStream is = new BufferedInputStream(zipFile.getInputStream(zipEntry));
+ BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(outputFile));
+ try
+ {
+ com.motorola.studio.android.common.utilities.FileUtil.copy(
+ new File(zipFile.getName()), outputFile);
+ }
+ finally
+ {
+ os.close();
+ is.close();
+ }
+ }
+ }
+}