diff options
Diffstat (limited to 'org.tizen.common')
91 files changed, 7646 insertions, 0 deletions
diff --git a/org.tizen.common/.classpath b/org.tizen.common/.classpath new file mode 100644 index 000000000..c619f68c7 --- /dev/null +++ b/org.tizen.common/.classpath @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry exported="true" kind="lib" path="sdblib.jar"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/org.tizen.common/.project b/org.tizen.common/.project new file mode 100644 index 000000000..b4551d98a --- /dev/null +++ b/org.tizen.common/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.tizen.common</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/org.tizen.common/META-INF/MANIFEST.MF b/org.tizen.common/META-INF/MANIFEST.MF new file mode 100644 index 000000000..10823da4d --- /dev/null +++ b/org.tizen.common/META-INF/MANIFEST.MF @@ -0,0 +1,30 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Tizen Common +Bundle-SymbolicName: org.tizen.common;singleton:=true +Bundle-Version: 1.17.0.qualifier +Bundle-Vendor: Samsung +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.ui.ide, + org.eclipse.core.resources, + org.eclipse.core.filesystem +Export-Package: + org.tizen.sdblib, + org.tizen.common.cache, + org.tizen.common.console, + org.tizen.common.control, + org.tizen.common.log, + org.tizen.common.manager, + org.tizen.common.model, + org.tizen.common.properties, + org.tizen.common.swt, + org.tizen.common.util +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Import-Package: + org.eclipse.jface.text, + org.eclipse.ui.console +Bundle-Activator: org.tizen.common.CommonPlugin +Bundle-ActivationPolicy: lazy +Bundle-ClassPath: sdblib.jar, + . diff --git a/org.tizen.common/OSGI-INF/l10n/bundle.properties b/org.tizen.common/OSGI-INF/l10n/bundle.properties new file mode 100644 index 000000000..99ec9ad7c --- /dev/null +++ b/org.tizen.common/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,3 @@ +activity.name = newXsdDisabler +activity.name.0 = newDtdDisabler +activity.name.1 = ValidateMenuItemDisabler
\ No newline at end of file diff --git a/org.tizen.common/about.html b/org.tizen.common/about.html new file mode 100644 index 000000000..95bb5ff8f --- /dev/null +++ b/org.tizen.common/about.html @@ -0,0 +1,41 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> +<title>About</title> +</head> +<body lang="EN-US"> +<h2>About This Content</h2> + +<p>May, 2011</p> +<h3>Tizen SDK</h3> + +<p><a href="https://developer.tizen.org/" target="_blank">Tizen SDK</a> +is a set of Eclipse plug-ins that helps programmers to develop applications for +the mobile platform.</p> + +<h3>License</h3> + +<p>See <a href="about_files/LICENSE-2.0.htm">Apache License, Version 2.0</a>.</p> + +<h3>Third Party Content</h3> + +<p>The Content includes items that have been sourced from third parties as set out below. If you did not +receive this Content directly from the Eclipse Foundation, the following is provided for informational +purposes only, and you should look to the Redistributor's license for terms and conditions of use.</p> + +<h4>Notification Popup Widget</h4> +<p> +Custom widget that displays a popup notification dialog in the bottom right corner of your screen(usually above the toolbar on Windows). +</p> + +<p> +A copy of the license is included in <a href="about_files/epl-v10.html">about_files/epl-v10.html</a>. The home page is located at: +<ul> +<a href="http://www.hexapixel.com/">http://www.hexapixel.com/</a> +</ul> +</p> + +</body> +</html>
\ No newline at end of file diff --git a/org.tizen.common/about_files/LICENSE-2.0.htm b/org.tizen.common/about_files/LICENSE-2.0.htm new file mode 100644 index 000000000..f7ca65649 --- /dev/null +++ b/org.tizen.common/about_files/LICENSE-2.0.htm @@ -0,0 +1,191 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html lang="en"> + <head> + <title>Apache License, Version 2.0</title> + + <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> + <meta property="og:image" content="http://www.apache.org/images/asf_logo.gif" /> + + <link rel="stylesheet" type="text/css" media="screen" href="/css/style.css"> + <link rel="stylesheet" type="text/css" media="screen" href="/css/code.css"> + + <script type="text/javascript" src="/js/jquery.js"></script> + <script type="text/javascript" src="/js/apache_boot.js"></script> + + + + + <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you 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. --> + </head> + + <body> + <div id="page" class="container_16"> + <div id="header" class="grid_8"> + <h1>The Apache Software Foundation</h1> + <h2>Apache License, Version 2.0</h2> + </div> + + <div class="clear"></div> + <div id="content" class="grid_16"><div class="section-content"><p>Apache License<br></br>Version 2.0, January 2004<br></br> +<a href="http://www.apache.org/licenses/">http://www.apache.org/licenses/</a> </p> +<p>TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION</p> +<p><strong><a name="definitions">1. Definitions</a></strong>.</p> +<p>"License" shall mean the terms and conditions for use, reproduction, and +distribution as defined by Sections 1 through 9 of this document.</p> +<p>"Licensor" shall mean the copyright owner or entity authorized by the +copyright owner that is granting the License.</p> +<p>"Legal Entity" shall mean the union of the acting entity and all other +entities that control, are controlled by, or are under common control with +that entity. For the purposes of this definition, "control" means (i) the +power, direct or indirect, to cause the direction or management of such +entity, whether by contract or otherwise, or (ii) ownership of fifty +percent (50%) or more of the outstanding shares, or (iii) beneficial +ownership of such entity.</p> +<p>"You" (or "Your") shall mean an individual or Legal Entity exercising +permissions granted by this License.</p> +<p>"Source" form shall mean the preferred form for making modifications, +including but not limited to software source code, documentation source, +and configuration files.</p> +<p>"Object" form shall mean any form resulting from mechanical transformation +or translation of a Source form, including but not limited to compiled +object code, generated documentation, and conversions to other media types.</p> +<p>"Work" shall mean the work of authorship, whether in Source or Object form, +made available under the License, as indicated by a copyright notice that +is included in or attached to the work (an example is provided in the +Appendix below).</p> +<p>"Derivative Works" shall mean any work, whether in Source or Object form, +that is based on (or derived from) the Work and for which the editorial +revisions, annotations, elaborations, or other modifications represent, as +a whole, an original work of authorship. For the purposes of this License, +Derivative Works shall not include works that remain separable from, or +merely link (or bind by name) to the interfaces of, the Work and Derivative +Works thereof.</p> +<p>"Contribution" shall mean any work of authorship, including the original +version of the Work and any modifications or additions to that Work or +Derivative Works thereof, that is intentionally submitted to Licensor for +inclusion in the Work by the copyright owner or by an individual or Legal +Entity authorized to submit on behalf of the copyright owner. For the +purposes of this definition, "submitted" means any form of electronic, +verbal, or written communication sent to the Licensor or its +representatives, including but not limited to communication on electronic +mailing lists, source code control systems, and issue tracking systems that +are managed by, or on behalf of, the Licensor for the purpose of discussing +and improving the Work, but excluding communication that is conspicuously +marked or otherwise designated in writing by the copyright owner as "Not a +Contribution."</p> +<p>"Contributor" shall mean Licensor and any individual or Legal Entity on +behalf of whom a Contribution has been received by Licensor and +subsequently incorporated within the Work.</p> +<p><strong><a name="copyright">2. Grant of Copyright License</a></strong>. Subject to the +terms and conditions of this License, each Contributor hereby grants to You +a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable +copyright license to reproduce, prepare Derivative Works of, publicly +display, publicly perform, sublicense, and distribute the Work and such +Derivative Works in Source or Object form.</p> +<p><strong><a name="patent">3. Grant of Patent License</a></strong>. Subject to the terms +and conditions of this License, each Contributor hereby grants to You a +perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable +(except as stated in this section) patent license to make, have made, use, +offer to sell, sell, import, and otherwise transfer the Work, where such +license applies only to those patent claims licensable by such Contributor +that are necessarily infringed by their Contribution(s) alone or by +combination of their Contribution(s) with the Work to which such +Contribution(s) was submitted. If You institute patent litigation against +any entity (including a cross-claim or counterclaim in a lawsuit) alleging +that the Work or a Contribution incorporated within the Work constitutes +direct or contributory patent infringement, then any patent licenses +granted to You under this License for that Work shall terminate as of the +date such litigation is filed.</p> +<p><strong><a name="redistribution">4. Redistribution</a></strong>. You may reproduce and +distribute copies of the Work or Derivative Works thereof in any medium, +with or without modifications, and in Source or Object form, provided that +You meet the following conditions:</p> +<ol> +<li> +<p>You must give any other recipients of the Work or Derivative Works a +copy of this License; and</p> +</li> +<li> +<p>You must cause any modified files to carry prominent notices stating +that You changed the files; and</p> +</li> +<li> +<p>You must retain, in the Source form of any Derivative Works that You +distribute, all copyright, patent, trademark, and attribution notices from +the Source form of the Work, excluding those notices that do not pertain to +any part of the Derivative Works; and</p> +</li> +<li> +<p>If the Work includes a "NOTICE" text file as part of its distribution, +then any Derivative Works that You distribute must include a readable copy +of the attribution notices contained within such NOTICE file, excluding +those notices that do not pertain to any part of the Derivative Works, in +at least one of the following places: within a NOTICE text file distributed +as part of the Derivative Works; within the Source form or documentation, +if provided along with the Derivative Works; or, within a display generated +by the Derivative Works, if and wherever such third-party notices normally +appear. The contents of the NOTICE file are for informational purposes only +and do not modify the License. You may add Your own attribution notices +within Derivative Works that You distribute, alongside or as an addendum to +the NOTICE text from the Work, provided that such additional attribution +notices cannot be construed as modifying the License. +You may add Your own copyright statement to Your modifications and may +provide additional or different license terms and conditions for use, +reproduction, or distribution of Your modifications, or for any such +Derivative Works as a whole, provided Your use, reproduction, and +distribution of the Work otherwise complies with the conditions stated in +this License.</p> +</li> +</ol> +<p><strong><a name="contributions">5. Submission of Contributions</a></strong>. Unless You +explicitly state otherwise, any Contribution intentionally submitted for +inclusion in the Work by You to the Licensor shall be under the terms and +conditions of this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify the +terms of any separate license agreement you may have executed with Licensor +regarding such Contributions.</p> +<p><strong><a name="trademarks">6. Trademarks</a></strong>. This License does not grant +permission to use the trade names, trademarks, service marks, or product +names of the Licensor, except as required for reasonable and customary use +in describing the origin of the Work and reproducing the content of the +NOTICE file.</p> +<p><strong><a name="no-warranty">7. Disclaimer of Warranty</a></strong>. Unless required by +applicable law or agreed to in writing, Licensor provides the Work (and +each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT +WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, +without limitation, any warranties or conditions of TITLE, +NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You +are solely responsible for determining the appropriateness of using or +redistributing the Work and assume any risks associated with Your exercise +of permissions under this License.</p> +<p><strong><a name="no-liability">8. Limitation of Liability</a></strong>. In no event and +under no legal theory, whether in tort (including negligence), contract, or +otherwise, unless required by applicable law (such as deliberate and +grossly negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, +incidental, or consequential damages of any character arising as a result +of this License or out of the use or inability to use the Work (including +but not limited to damages for loss of goodwill, work stoppage, computer +failure or malfunction, or any and all other commercial damages or losses), +even if such Contributor has been advised of the possibility of such +damages.</p> +<p><strong><a name="additional">9. Accepting Warranty or Additional Liability</a></strong>. +While redistributing the Work or Derivative Works thereof, You may choose +to offer, and charge a fee for, acceptance of support, warranty, indemnity, +or other liability obligations and/or rights consistent with this License. +However, in accepting such obligations, You may act only on Your own behalf +and on Your sole responsibility, not on behalf of any other Contributor, +and only if You agree to indemnify, defend, and hold each Contributor +harmless for any liability incurred by, or claims asserted against, such +Contributor by reason of your accepting any such warranty or additional +liability.</p> +<p>END OF TERMS AND CONDITIONS</p> + + <div class="clear"></div> + + </div> + <div id="copyright" class="container_16"> + <p>Copyright © 2011 The Apache Software Foundation, Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.<br/>Apache and the Apache feather logo are trademarks of The Apache Software Foundation.</p> + </div> + </body> +</html> diff --git a/org.tizen.common/build.properties b/org.tizen.common/build.properties new file mode 100644 index 000000000..889acffc9 --- /dev/null +++ b/org.tizen.common/build.properties @@ -0,0 +1,11 @@ +source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ icons/,\
+ sdblib.jar,\
+ about.html,\
+ about_files/,\
+ plugin.xml
+javacSource = 1.6 +javacTarget = 1.6 diff --git a/org.tizen.common/icons/connected.png b/org.tizen.common/icons/connected.png Binary files differnew file mode 100644 index 000000000..f2ace41fe --- /dev/null +++ b/org.tizen.common/icons/connected.png diff --git a/org.tizen.common/icons/connecting.png b/org.tizen.common/icons/connecting.png Binary files differnew file mode 100644 index 000000000..77512c36f --- /dev/null +++ b/org.tizen.common/icons/connecting.png diff --git a/org.tizen.common/icons/delete.png b/org.tizen.common/icons/delete.png Binary files differnew file mode 100644 index 000000000..3e95caa6c --- /dev/null +++ b/org.tizen.common/icons/delete.png diff --git a/org.tizen.common/icons/disconnected.png b/org.tizen.common/icons/disconnected.png Binary files differnew file mode 100644 index 000000000..01c7d81a3 --- /dev/null +++ b/org.tizen.common/icons/disconnected.png diff --git a/org.tizen.common/icons/error.png b/org.tizen.common/icons/error.png Binary files differnew file mode 100644 index 000000000..d70328403 --- /dev/null +++ b/org.tizen.common/icons/error.png diff --git a/org.tizen.common/icons/folder.png b/org.tizen.common/icons/folder.png Binary files differnew file mode 100644 index 000000000..df0fca9d8 --- /dev/null +++ b/org.tizen.common/icons/folder.png diff --git a/org.tizen.common/icons/hint.png b/org.tizen.common/icons/hint.png Binary files differnew file mode 100644 index 000000000..c3c07e15d --- /dev/null +++ b/org.tizen.common/icons/hint.png diff --git a/org.tizen.common/icons/info.png b/org.tizen.common/icons/info.png Binary files differnew file mode 100644 index 000000000..97ee81dae --- /dev/null +++ b/org.tizen.common/icons/info.png diff --git a/org.tizen.common/icons/library.png b/org.tizen.common/icons/library.png Binary files differnew file mode 100644 index 000000000..13342dedc --- /dev/null +++ b/org.tizen.common/icons/library.png diff --git a/org.tizen.common/icons/ok.png b/org.tizen.common/icons/ok.png Binary files differnew file mode 100644 index 000000000..454cda50e --- /dev/null +++ b/org.tizen.common/icons/ok.png diff --git a/org.tizen.common/icons/printer.png b/org.tizen.common/icons/printer.png Binary files differnew file mode 100644 index 000000000..1a4e1d443 --- /dev/null +++ b/org.tizen.common/icons/printer.png diff --git a/org.tizen.common/icons/star.png b/org.tizen.common/icons/star.png Binary files differnew file mode 100644 index 000000000..87236ad17 --- /dev/null +++ b/org.tizen.common/icons/star.png diff --git a/org.tizen.common/icons/terminated.png b/org.tizen.common/icons/terminated.png Binary files differnew file mode 100644 index 000000000..c4f84505d --- /dev/null +++ b/org.tizen.common/icons/terminated.png diff --git a/org.tizen.common/icons/warn.png b/org.tizen.common/icons/warn.png Binary files differnew file mode 100644 index 000000000..be589b805 --- /dev/null +++ b/org.tizen.common/icons/warn.png diff --git a/org.tizen.common/icons/warn2.png b/org.tizen.common/icons/warn2.png Binary files differnew file mode 100644 index 000000000..42d053a9c --- /dev/null +++ b/org.tizen.common/icons/warn2.png diff --git a/org.tizen.common/plugin.xml b/org.tizen.common/plugin.xml new file mode 100644 index 000000000..bbe192e0d --- /dev/null +++ b/org.tizen.common/plugin.xml @@ -0,0 +1,335 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.ui.newWizards">
+ <category
+ id="org.tizen.nativeapp.newCategory"
+ name="Tizen">
+ </category>
+ </extension>
+ <extension
+ point="org.eclipse.ui.preferencePages">
+ <page
+ class="org.tizen.common.preferences.TizenBasePreferencePage"
+ id="org.tizen.common.preferences.tizencommon"
+ name="Tizen SDK">
+ </page>
+ </extension>
+ <extension
+ point="org.eclipse.ui.startup">
+ <startup
+ class="org.tizen.common.util.UpdateManager">
+ </startup>
+ </extension>
+ <!-- activities start -->
+ <extension
+ point="org.eclipse.ui.activities">
+ <!-- disable rhino lauch shortcuts & wst launch shortcut -->
+ <activity
+ name="Popup UI"
+ description="Popup UI"
+ id="org.tizen.web.launch.DisablePopupMenu">
+ <enabledWhen>
+ <with variable="activeWorkbenchWindow.activePerspective">
+ <and>
+ <not>
+ <equals value="org.tizen.web.ui.perspective.WACwidget"/>
+ </not>
+ <not>
+ <equals value="org.tizen.nativeapp.perspective"/>
+ </not>
+ </and>
+ </with>
+ </enabledWhen>
+ </activity>
+ <activityPatternBinding
+ activityId="org.tizen.web.launch.DisablePopupMenu"
+ pattern="org.eclipse.wst.server.ui/org.eclipse.wst.server.launchShortcut*">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.launch.DisablePopupMenu"
+ pattern="org.eclipse.wst.jsdt.debug.rhino.ui/org.eclipse.wst.jsdt.debug.rhino.ui.launch.shortcut*">
+ </activityPatternBinding>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.activities">
+ <!-- disable CDT launch ui -->
+ <category
+ name="CDT launch UI"
+ description="Disable CDT launch UI when Native App Perspective is activated."
+ id="org.tizen.nativeapp.CDTLaunchUICategory">
+ </category>
+
+ <activity
+ name="CDT Launch UI Elements"
+ description="Launch UI elements from CDT"
+ id="org.tizen.nativeapp.DisableCDTLaunchUIActivity">
+
+ <enabledWhen>
+ <with variable="activeWorkbenchWindow.activePerspective">
+ <and>
+ <not>
+ <equals value="org.tizen.web.ui.perspective.WACwidget"/>
+ </not>
+ <not>
+ <equals value="org.tizen.nativeapp.perspective"/>
+ </not>
+ </and>
+ </with>
+ </enabledWhen>
+ </activity>
+
+ <categoryActivityBinding
+ activityId="org.tizen.nativeapp.DisableCDTLaunchUIActivity"
+ categoryId="org.tizen.nativeapp.CDTLaunchUICategory">
+ </categoryActivityBinding>
+
+ <activityPatternBinding
+ activityId="org.tizen.nativeapp.DisableCDTLaunchUIActivity"
+ pattern="org\.eclipse\.cdt\.launch/org\.eclipse\.cdt\.launch\.launchGroup">
+ </activityPatternBinding>
+
+ <activityPatternBinding
+ activityId="org.tizen.nativeapp.DisableCDTLaunchUIActivity"
+ pattern="org\.eclipse\.cdt\.debug\.core/org\.eclipse\.cdt\.launch\.[a-zA-Z]*LaunchType">
+ </activityPatternBinding>
+
+ <activityPatternBinding
+ activityId="org.tizen.nativeapp.DisableCDTLaunchUIActivity"
+ pattern="org\.eclipse\.cdt\.debug\.ui/org\.eclipse\.cdt\.debug\.ui\.localCShortcut">
+ </activityPatternBinding>
+
+ <!-- disable CDT toolchain editor page -->
+ <category
+ description="Disable CDT Toolchain Editor Page when Tizen Perspective is activated."
+ id="org.tizen.nativeapp.CDTToolChainEditorPageCategory"
+ name="CDT ToolChain Editor Page">
+ </category>
+ <activity
+ description="ToolChain Editor Property Page"
+ id="org.tizen.nativeapp.DisableCDTToolChainEditorPageActivity"
+ name="CDT ToolChain Editor Page Elements">
+ <enabledWhen>
+ <with variable="activeWorkbenchWindow.activePerspective">
+ <and>
+ <not>
+ <equals value="org.tizen.web.ui.perspective.WACwidget"/>
+ </not>
+ <not>
+ <equals value="org.tizen.nativeapp.perspective"/>
+ </not>
+ </and>
+ </with>
+ </enabledWhen>
+ </activity>
+ <categoryActivityBinding
+ activityId="org.tizen.nativeapp.DisableCDTToolChainEditorPageActivity"
+ categoryId="org.tizen.nativeapp.CDTToolChainEditorPageCategory">
+ </categoryActivityBinding>
+ <activityPatternBinding
+ activityId="org.tizen.nativeapp.DisableCDTToolChainEditorPageActivity"
+ pattern="org\.eclipse\.cdt\.managedbuilder\.ui/org\.eclipse\.cdt\.managedbuilder\.ui\.properties\.Page_ToolChain">
+ </activityPatternBinding>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.activities">
+ <!-- disable other new wizards -->
+ <activity
+ id="org.tizen.web.ui.modification.newXsdDisabler"
+ name="%activity.name">
+ </activity>
+ <activityPatternBinding
+ activityId="org.tizen.web.ui.modification.newXsdDisabler"
+ pattern="org.eclipse.wst.xsd.ui/org.eclipse.wst.xsd.ui.internal.wizards.*">
+ </activityPatternBinding>
+
+ <activity
+ id="org.tizen.web.ui.modification.newDtdDisabler"
+ name="%activity.name.0">
+ </activity>
+ <activityPatternBinding
+ activityId="org.tizen.web.ui.modification.newDtdDisabler"
+ pattern="org.eclipse.wst.dtd.ui/org.eclipse.wst.dtd.ui.internal.wizard.*">
+ </activityPatternBinding>
+
+ <activity
+ id="org.tizen.web.ui.modification.ValidateMenuItemDisabler"
+ name="%activity.name.1">
+ </activity>
+ <activityPatternBinding
+ activityId="org.tizen.web.ui.modification.ValidateMenuItemDisabler"
+ pattern="org.eclipse.wst.validation.ui/ValidationAction">
+ </activityPatternBinding>
+
+
+ <activity
+ name="Wizard UI"
+ description="Wizard UI"
+ id="org.tizen.web.DisableWizardsActivity">
+ <enabledWhen>
+ <with variable="activeWorkbenchWindow.activePerspective">
+ <and>
+ <not>
+ <equals value="org.tizen.web.ui.perspective.WACwidget"/>
+ </not>
+ <not>
+ <equals value="org.tizen.nativeapp.perspective"/>
+ </not>
+ </and>
+ </with>
+ </enabledWhen>
+ </activity>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="com\.samsung\.tizen\.guibuilder/com\.samsung\.tizen\.guibuilder\.wizard\.newSgmWizard">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.jdt\.ui/org\.eclipse\.jdt\.ui\.wizards\.JavaProjectWizard">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.ant\.ui/org\.eclipse\.ant\.ui\.wizards\.JavaProjectWizard">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.emf\.importer/org\.eclipse\.emf\.importer\.ui\.EMFProjectWizard">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.emf\.codegen\.ecore\.ui/org\.eclipse\.emf\.codegen\.ecore\.ui\.EmptyProjectWizard">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.wst\.jsdt\.ui/org\.eclipse\.wst\.jsdt\.ui\.wizards\.JavaProjectWizard">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.wst\.xml\.ui/org\.eclipse\.wst\.xml\.ui\.XMLExampleProjectCreationWizard">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.wst\.web\.ui/org\.eclipse\.wst\.web\.ui\.internal\.wizards\.SimpleWebProjectWizard">
+ </activityPatternBinding>
+
+
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.emf\.ecore\.editor/org\.eclipse\.emf\.ecore\.presentation\.EcoreModelWizardID">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.emf\.mapping\.ecore2xml\.ui/org\.eclipse\.emf\.mapping\.ecore2xml\.presentation\.Ecore2XMLModelWizardID">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.emf\.mapping\.ecore2ecore\.editor/org\.eclipse\.emf\.mapping\.ecore2ecore\.presentation\.Ecore2EcoreModelWizardID">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.emf\.importer/org\.eclipse\.emf\.importer\.ui\.EMFModelWizard">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.emf\.importer/org\.eclipse\.emf\.importer\.ui\.EMFProjectWizard">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.jdt\.ui/org\.eclipse\.jdt\.ui\.wizards.*">
+ </activityPatternBinding>
+
+
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.jdt\.junit/org\.eclipse\.jdt\.junit\.wizards.*">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.jdt\.debug\.ui/org\.eclipse\.jdt\.debug\.ui\.snippetEditor\.NewSnippetFileCreationWizard">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.wst\.server\.ui/org\.eclipse\.wst\.server\.ui\.new\.server">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.wst\.jsdt\.ui/org\.eclipse\.wst\.jsdt\.ui\.wizards\.JavaProjectWizard">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.wst\.jsdt\.ui/org\.eclipse\.wst\.jsdt\.ui\.NewJSWizard">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.jst\.jsp\.ui/org\.eclipse\.jst\.jsp\.ui\.internal\.wizard.*">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.wst\.html\.ui/org\.eclipse\.wst\.html\.ui\.internal\.wizard\.NewHTMLWizard">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.wst\.css\.ui/org\.eclipse\.wst\.css\.ui\.internal\.wizard\.NewCSSWizard">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.emf\.codegen\.ui/org\.eclipse\.emf\.codegen\.ui\.ConvertToJETProjectWizard">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.wst\.xsd\.ui/org\.eclipse\.wst\.xsd\.ui\.internal\.wizards\.NewXSDWizard">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.wst\.dtd\.ui/org\.eclipse\.wst\.dtd\.ui\.internal\.wizard\.NewDTDWizard">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="json\.editor\.plugin/Json\.newFileWizard">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.wst\.xml\.ui/org\.eclipse\.wst\.xml\.ui\.internal\.wizards\.NewXMLWizard">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.DisableWizardsActivity"
+ pattern="org\.eclipse\.wst\.xml\.ui/org\.eclipse\.wst\.xml\.ui\.XMLExampleProjectCreationWizard">
+ </activityPatternBinding>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.activities">
+ <!-- PopupMenus Enabled when tizen Web IDE perspective -->
+ <activity
+ description="PopupMenus"
+ id="org.tizen.web.PopupMenusActivity"
+ name="PopupMenus">
+ <enabledWhen>
+ <with
+ variable="activeWorkbenchWindow.activePerspective">
+ <and>
+ <equals
+ value="org.tizen.web.ui.perspective.WACwidget">
+ </equals>
+ </and>
+ </with>
+ </enabledWhen>
+ </activity>
+ <activityPatternBinding
+ activityId="org.tizen.web.PopupMenusActivity"
+ pattern="org.tizen.web.sign/org.tizen.web.sign.signwidgetaction">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.tizen.web.PopupMenusActivity"
+ pattern="org.tizen.web.localization/org.tizen.web.localization.menus.popup.localizationMenu">
+ </activityPatternBinding>
+ </extension>
+ <!-- activities end -->
+</plugin> diff --git a/org.tizen.common/sdblib.jar b/org.tizen.common/sdblib.jar Binary files differnew file mode 100644 index 000000000..28a8a0434 --- /dev/null +++ b/org.tizen.common/sdblib.jar diff --git a/org.tizen.common/src/org/tizen/common/CommonPlugin.java b/org.tizen.common/src/org/tizen/common/CommonPlugin.java new file mode 100644 index 000000000..b337172d8 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/CommonPlugin.java @@ -0,0 +1,122 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Changhyun Lee <changhyun1.lee@samsung.com> +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common; + +import java.io.File; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; +import org.tizen.common.preferences.TizenBasePreferencePage; +import org.tizen.common.properties.InstallPathConfig; +import org.tizen.common.util.HostUtil; +import org.tizen.common.util.OSChecker; + +import org.tizen.sdblib.SmartDevelopmentBridge; + +/** + * Log. + * @author Changhyun Lee {@literal <changhyun1.lee@samsung.com>} (S-Core) + */ +public class CommonPlugin extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.tizen.common"; //$NON-NLS-1$ + private final static String SDKSUFFIX = File.separatorChar+".TizenSDK"+File.separatorChar+"tizensdkpath"; + // The shared instance + private static CommonPlugin plugin; + + /** + * The constructor + */ + public CommonPlugin() { + SmartDevelopmentBridge.init(); + String sdbPath = InstallPathConfig.getSDKPath() + File.separator + "SDK" + File.separator +"sdb" + File.separator + "sdb"; + SmartDevelopmentBridge.createBridge(sdbPath, true); + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static CommonPlugin getDefault() { + return plugin; + } + + @Override + + protected void initializeDefaultPreferences(IPreferenceStore store) { + if (loadSdkPath() != null) + store.setDefault(TizenBasePreferencePage.KEY_SDKLOCATION,loadSdkPath()); + store.setDefault(TizenBasePreferencePage.KEY_SDKUPDATE,TizenBasePreferencePage.VALUE_SDKUPDATE_DEFAULT); + + } + + + /** + * get sdk path + */ + private String loadSdkPath() { + String sdkConfig; + String sdkPath = null;; + if (OSChecker.isWindows()) + sdkConfig = System.getenv("localappdata") + File.separatorChar + SDKSUFFIX; + else + sdkConfig= System.getProperty("user.home") + File.separatorChar + SDKSUFFIX; + + if (HostUtil.exists(sdkConfig)) { + String contents = HostUtil.getContents(sdkConfig); + if (contents != null) { + String[] fileContent = contents.split("="); + if (fileContent.length == 2) { + if (HostUtil.exists(fileContent[1])) + sdkPath = fileContent[1]; + } + } + } + return sdkPath; + } + +} diff --git a/org.tizen.common/src/org/tizen/common/cache/ColorCache.java b/org.tizen.common/src/org/tizen/common/cache/ColorCache.java new file mode 100644 index 000000000..fbd1a3659 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/cache/ColorCache.java @@ -0,0 +1,106 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Changhyun Lee <changhyun1.lee@samsung.com>
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+package org.tizen.common.cache;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * Class for caching colors
+ *
+ * @author Emil
+ *
+ */
+public final class ColorCache {
+
+ public static final RGB BLACK = new RGB(0, 0, 0);
+ public static final RGB WHITE = new RGB(255, 255, 255);
+
+ private static Map<RGB, Color> _colorTable;
+ private static ColorCache _instance;
+
+ static {
+ _colorTable = new HashMap<RGB, Color>();
+ new ColorCache();
+ }
+
+ private ColorCache() {
+ _instance = this;
+ }
+
+ public static ColorCache getInstance() {
+ return _instance;
+ }
+
+ /**
+ * Disposes of all colors. DO ONLY CALL THIS WHEN YOU ARE SHUTTING DOWN YOUR
+ * APPLICATION!
+ */
+ public static void disposeColors() {
+ Iterator<Color> e = _colorTable.values().iterator();
+ while (e.hasNext())
+ e.next().dispose();
+
+ _colorTable.clear();
+ }
+
+ public static Color getWhite() {
+ return getColorFromRGB(new RGB(255, 255, 255));
+ }
+
+ public static Color getBlack() {
+ return getColorFromRGB(new RGB(0, 0, 0));
+ }
+
+ public static Color getColorFromRGB(RGB rgb) {
+ Color color = _colorTable.get(rgb);
+
+ if (color == null) {
+ color = new Color(Display.getCurrent(), rgb);
+ _colorTable.put(rgb, color);
+ }
+
+ return color;
+ }
+
+ public static Color getColor(int r, int g, int b) {
+ RGB rgb = new RGB(r, g, b);
+ Color color = _colorTable.get(rgb);
+
+ if (color == null) {
+ color = new Color(Display.getCurrent(), rgb);
+ _colorTable.put(rgb, color);
+ }
+
+ return color;
+ }
+
+}
\ No newline at end of file diff --git a/org.tizen.common/src/org/tizen/common/cache/FontCache.java b/org.tizen.common/src/org/tizen/common/cache/FontCache.java new file mode 100644 index 000000000..ec5b81a51 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/cache/FontCache.java @@ -0,0 +1,206 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Changhyun Lee <changhyun1.lee@samsung.com>
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+package org.tizen.common.cache;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * Caching class for fonts. Also deals with re-creating fonts should they have been disposed when the
+ * caller asks for a font.
+ *
+ * @author Emil
+ *
+ */
+public class FontCache {
+
+ private static List<OneFont> _existing = new ArrayList<OneFont>();
+
+ /**
+ * Disposes all fonts and clears out the cache. Never call this unless you are shutting down your
+ * code/client/etc.
+ */
+ public static void disposeAll() {
+ for (OneFont of : _existing) {
+ if (of.getFont() != null && !of.getFont().isDisposed()) {
+ of.getFont().dispose();
+ }
+ }
+
+ _existing.clear();
+ }
+
+ /**
+ * Gets a font from existing FontData
+ *
+ * @param fd FontData
+ * @return Font or null on error
+ */
+ public static Font getFont(FontData fd) {
+ try {
+ boolean disposed = false;
+ OneFont toRemove = null;
+ for (OneFont of : _existing) {
+ if (of.matches(fd)) {
+ if (of.getFont().isDisposed()) {
+ disposed = true;
+ toRemove = of;
+ break;
+ }
+
+ return of.getFont();
+ }
+ }
+ if (disposed) {
+ _existing.remove(toRemove);
+ }
+
+ OneFont of = new OneFont(fd);
+ _existing.add(of);
+ return of.getFont();
+ } catch (Exception err) {
+ err.printStackTrace();
+ }
+
+ return null;
+ }
+
+ public static int getCount() {
+ return _existing.size();
+ }
+
+ /**
+ * Gets a font from an existing fonts data.
+ *
+ * @param font Font
+ * @return Font or null on error
+ */
+ public static Font getFont(Font font) {
+ try {
+ if (font == null || font.isDisposed()) return null;
+
+ FontData fd = font.getFontData()[0];
+ return getFont(fd);
+
+ } catch (Exception err) {
+ err.printStackTrace();
+ }
+
+ return null;
+ }
+
+ /**
+ * Gets a font for a given font name and style.
+ *
+ * @param fontName Name of font
+ * @param height Height of font
+ * @param style Style of font
+ * @return Font or null on error
+ */
+ public static Font getFont(String fontName, int height, int style) {
+ try {
+ boolean disposed = false;
+ OneFont toRemove = null;
+ for (OneFont of : _existing) {
+ if (of.getName().equals(fontName) && of.getHeight() == height && of.getStyle() == style) {
+ if (of.getFont().isDisposed()) {
+ disposed = true;
+ toRemove = of;
+ break;
+ }
+ return of.getFont();
+ }
+ }
+ if (disposed) {
+ _existing.remove(toRemove);
+ }
+
+ OneFont of = new OneFont(fontName, height, style);
+ _existing.add(of);
+ return of.getFont();
+ }
+ catch (Exception err) {
+ err.printStackTrace();
+ }
+
+ return null;
+ }
+}
+
+class OneFont {
+
+ private String _name;
+ private int _height;
+ private int _style;
+ private Font _font;
+
+ public OneFont(String name, int height, int style) {
+ _name = name;
+ _height = height;
+ _style = style;
+ _font = new Font(Display.getDefault(), name, height, style);
+ }
+
+ public OneFont(FontData fd) {
+ _name = fd.getName();
+ _height = fd.getHeight();
+ _style = fd.getStyle();
+ _font = new Font(Display.getDefault(), fd);
+ }
+
+ public String getName() {
+ return _name;
+ }
+
+ public int getHeight() {
+ return _height;
+ }
+
+ public int getStyle() {
+ return _style;
+ }
+
+ public void setFont(Font font) {
+ _font = font;
+ }
+
+ public Font getFont() {
+ return _font;
+ }
+
+ public boolean matches(FontData fd) {
+ return (fd.getName().equals(_name) && fd.getHeight() == _height && fd.getStyle() == _style);
+ }
+
+ @Override
+ public String toString() {
+ return "Font: " + _name + " " + _height + " " + _style;
+ }
+}
diff --git a/org.tizen.common/src/org/tizen/common/cache/ImageCache.java b/org.tizen.common/src/org/tizen/common/cache/ImageCache.java new file mode 100644 index 000000000..639a79723 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/cache/ImageCache.java @@ -0,0 +1,105 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Changhyun Lee <changhyun1.lee@samsung.com>
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+package org.tizen.common.cache;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * Class for caching images
+ *
+ * @author Emil
+ */
+public class ImageCache {
+
+ private static HashMap<String, Image> _ImageMap;
+
+ // what path to get to the "icons" directory without actually including it
+ private static final String ICON_ROOT_PATH = "icons/";
+
+ static {
+ _ImageMap = new HashMap<String, Image>();
+ }
+
+ /**
+ * Returns an image that is also cached if it has to be created and does not already exist in the cache.
+ *
+ * @param fileName Filename of image to fetch
+ * @return Image null if it could not be found
+ */
+ public static Image getImage(String fileName) {
+ fileName = ICON_ROOT_PATH + fileName;
+ Image image = _ImageMap.get(fileName);
+ if (image == null) {
+ image = createImage(fileName);
+ _ImageMap.put(fileName, image);
+ }
+ return image;
+ }
+
+ // creates the image, and tries really hard to do so
+ private static Image createImage(String fileName) {
+ ClassLoader classLoader = ImageCache.class.getClassLoader();
+ InputStream is = classLoader.getResourceAsStream(fileName);
+ if (is == null) {
+ // the old way didn't have leading slash, so if we can't find the image stream,
+ // let's see if the old way works.
+ is = classLoader.getResourceAsStream(fileName.substring(1));
+
+ if (is == null) {
+ is = classLoader.getResourceAsStream(fileName);
+ if (is == null) {
+ is = classLoader.getResourceAsStream(fileName.substring(1));
+ if (is == null) { return null; }
+ }
+ }
+ }
+
+ Image img = new Image(Display.getDefault(), is);
+ try {
+ is.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ return img;
+ }
+
+ /**
+ * Disposes ALL images that have been cached.
+ */
+ public static void dispose() {
+ Iterator<Image> e = _ImageMap.values().iterator();
+ while (e.hasNext())
+ e.next().dispose();
+
+ }
+}
diff --git a/org.tizen.common/src/org/tizen/common/console/AnsicodeAdapter.java b/org.tizen.common/src/org/tizen/common/console/AnsicodeAdapter.java new file mode 100644 index 000000000..73a32ad3b --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/console/AnsicodeAdapter.java @@ -0,0 +1,225 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Yoonki Park <yoonki.park@samsung.com> +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.console; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.swt.graphics.Color; +import org.eclipse.ui.PlatformUI; + +public class AnsicodeAdapter { + public static final char ESCAPE = '\033'; // ANSI Escape Character that starts commands + + public static final Color BLACK = new Color(PlatformUI.getWorkbench().getDisplay(), 0, 0, 0); //Display.getCurrent().getSystemColor(SWT.COLOR_BLACK); + public static final Color RED = new Color(PlatformUI.getWorkbench().getDisplay(), 255, 0, 0); //Display.getCurrent().getSystemColor(SWT.COLOR_RED); + public static final Color GREEN = new Color(PlatformUI.getWorkbench().getDisplay(), 0, 255, 0); //Display.getCurrent().getSystemColor(SWT.COLOR_GREEN); + public static final Color YELLOW = new Color(PlatformUI.getWorkbench().getDisplay(), 255, 255, 0); //Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW); + public static final Color BLUE = new Color(PlatformUI.getWorkbench().getDisplay(), 0,0,255); //Display.getCurrent().getSystemColor(SWT.COLOR_BLUE); + public static final Color MAGENTA = new Color(PlatformUI.getWorkbench().getDisplay(), 255, 0, 255); //Display.getCurrent().getSystemColor(SWT.COLOR_MAGENTA); + public static final Color CYAN = new Color(PlatformUI.getWorkbench().getDisplay(), 0,255, 255); //Display.getCurrent().getSystemColor(SWT.COLOR_CYAN); + public static final Color WHITE = new Color(PlatformUI.getWorkbench().getDisplay(), 255, 255, 255); //Display.getCurrent().getSystemColor(SWT.COLOR_WHITE); + + public static final Color INTENSE_BLACK = new Color(PlatformUI.getWorkbench().getDisplay(), 0, 0, 0); //Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY); + public static final Color INTENSE_RED = new Color(PlatformUI.getWorkbench().getDisplay(), 139, 0, 0); //Display.getCurrent().getSystemColor(SWT.COLOR_DARK_RED); + public static final Color INTENSE_GREEN = new Color(PlatformUI.getWorkbench().getDisplay(), 0, 100, 0);//Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GREEN); + public static final Color INTENSE_YELLOW = new Color(PlatformUI.getWorkbench().getDisplay(), 250,250,210);//Display.getCurrent().getSystemColor(SWT.COLOR_DARK_YELLOW); + public static final Color INTENSE_BLUE = new Color(PlatformUI.getWorkbench().getDisplay(), 0,0,139);//Display.getCurrent().getSystemColor(SWT.COLOR_DARK_BLUE); + public static final Color INTENSE_MAGENTA = new Color(PlatformUI.getWorkbench().getDisplay(), 139,0,139);//Display.getCurrent().getSystemColor(SWT.COLOR_DARK_MAGENTA); + public static final Color INTENSE_CYAN = new Color(PlatformUI.getWorkbench().getDisplay(), 0, 139, 139);//Display.getCurrent().getSystemColor(SWT.COLOR_DARK_CYAN); + public static final Color INTENSE_WHITE = new Color(PlatformUI.getWorkbench().getDisplay(), 245, 245, 245);//Display.getCurrent().getSystemColor(SWT.COLOR_WHITE); + + private static int[] commands = {'m','n'}; //SGR , DSR + + private static List<TextStyle> parseAnsiString(String ansiString) { + char command = 0; + List<TextStyle> styles = new ArrayList<TextStyle>(); + int arrayIndex = 0; + StringBuilder sb = new StringBuilder(); + + for (int i=0; i<ansiString.length(); i++) { + if (ansiString.charAt(i) == ESCAPE) { + int min = ansiString.length() ; + int startCommand = 0; + + for (int j=0 ; j<commands.length ; j++) { + startCommand = ansiString.indexOf(commands[j], i); + if (min > startCommand && startCommand > -1) { + min = startCommand; + } + } + command=ansiString.charAt(min); + startCommand=min; + + if ( startCommand < ansiString.length()) { + + String colorCodes = ansiString.substring(i+2,startCommand); + String codes[] = colorCodes.split(";"); + Color[] colors = getColorAttribute(codes); + int styleStart = startCommand+1; + int styleEnd = 0; + int endEscape = ansiString.indexOf(ESCAPE,styleStart); + if (endEscape < 0 ) { + styleEnd = ansiString.length(); + i = ansiString.length(); + } else { + int endCommand = ansiString.indexOf(command,endEscape); + if (endCommand < 0 ) { + styleEnd = ansiString.length(); + i = ansiString.length(); + } else { + styleEnd = endEscape; + i = endCommand; + } + } + String styleString = null; + styleString = ansiString.substring(styleStart, styleEnd); + + TextStyle styleTs = new TextStyle(colors[0],colors[1],styleString); + + if (sb.length() > 0) { + TextStyle defaultTs = new TextStyle(BLACK,WHITE, sb.toString()); + styles.add(arrayIndex++,defaultTs); + sb.setLength(0); + } + styles.add(arrayIndex++,styleTs); + + } + }else { //nothing found! + + sb.append(ansiString.charAt(i)); + } + } + if (sb.length() > 0) { + TextStyle defaultTs = new TextStyle(BLACK,WHITE, sb.toString()); + styles.add(arrayIndex,defaultTs); + } + return styles; + } + private static Color[] getColorAttribute(String codes[]) { + boolean brighter = false; + Color[] color = {BLACK,WHITE}; //foreground&background + + for (int j = 0; j < codes.length; j++) { + + if (codes[j].length() > 0 && codes[j].matches("[\\d]*")) { + int code = Integer.parseInt(codes[j]); + if (code == 0) + brighter = false; + else if (code == 1) + brighter = true; + else if (code >= 30 && code <= 39) { + if (code == 39) + color[0] = BLACK; //default foreground color + else if (code >= 30 && code <= 37) { + color[0] = getColorFromANSICode(code, brighter); + brighter = false; + } + } else if (code >= 40 && code <= 49) { + if (code == 49) + color[1] = WHITE; //default background color + else if (code >= 40 && code <= 47) + color[1] = getColorFromANSICode(code, brighter); + } + } + } + return color; + } + private static Color getColorFromANSICode(int code, boolean brighter) { + switch (code) { + case 30: + case 40: + if (brighter) + return INTENSE_BLACK; + else + return BLACK; + case 31: + case 41: + if (brighter) + return INTENSE_RED; + else + return RED; + case 32: + case 42: + if (brighter) + return INTENSE_GREEN; + else + return GREEN; + case 33: + case 43: + if (brighter) + return INTENSE_YELLOW; + else + return YELLOW; + case 34: + case 44: + if (brighter) + return INTENSE_BLUE; + else + return BLUE; + case 35: + case 45: + if (brighter) + return INTENSE_MAGENTA; + else + return MAGENTA; + case 36: + case 46: + if (brighter) + return INTENSE_CYAN; + else + return CYAN; + case 37: + case 47: + if (brighter) + return INTENSE_WHITE; + else + return WHITE; + default: + return null; + } + } + public static String getStripAnsiString(String newLineStr) { + List<TextStyle> styles = parseAnsiString(newLineStr); + if (styles != null) { + StringBuilder sb = new StringBuilder(); + for (int i=0 ; i<styles.size(); i++) { + sb.append(styles.get(i).getStripString()); + } + return sb.toString(); + }else { + return newLineStr; + } + } + public static List<TextStyle> getStringStyles(String newLineStr) { + List<TextStyle> styles = parseAnsiString(newLineStr); + if (styles != null) { + return styles; + }else { + return null; + } + } +} diff --git a/org.tizen.common/src/org/tizen/common/console/ConsoleManager.java b/org.tizen.common/src/org/tizen/common/console/ConsoleManager.java new file mode 100644 index 000000000..ec4871d3b --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/console/ConsoleManager.java @@ -0,0 +1,271 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Yoonki Park <yoonki.park@samsung.com> +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.console; +import java.io.IOException; +import java.lang.reflect.Method; + +import org.eclipse.jface.text.IDocument; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.IConsoleConstants; +import org.eclipse.ui.console.IConsoleManager; +import org.eclipse.ui.console.IConsoleView; +import org.eclipse.ui.console.MessageConsole; +import org.eclipse.ui.console.MessageConsoleStream; + +/** + * ConsoleManager. + * @author YoonKi Park {@literal <yoonki.park@samsung.com>} (S-Core) + * @author GyeongSeok Seo {@literal <gyeongseok.seo@samsung.com>} (S-Core) + */ +public class ConsoleManager +{ + private IConsoleManager consoleManager; + private String consoleName; + private boolean consoleFocus; + private MessageConsole console; + private Display display = Display.getDefault(); + private MessageConsoleStream colorConsoleStream; + + /** + * Constructs a new console manager. + * + * @param consoleName - the key title + * @param focus - true if focus on console, false if not + */ + public ConsoleManager(String consoleName, boolean focus) { + this.consoleName = consoleName; + this.consoleFocus = focus; + this.consoleManager = ConsolePlugin.getDefault().getConsoleManager(); + this.console = getMessageConsole(); + } + + /** + * Change Console Name. + * + * @param newName - console Title. It shown console's tab bar. + * @author Gyeongseok.seo@samsung.com + */ + public void changeConsolName(String newName) throws NoSuchFieldException, IllegalAccessException { + this.consoleName = newName; + Runnable runnable = new Runnable() { + public void run() { + Class<?> cls; + Method method; + try { + cls = Class.forName("org.eclipse.ui.console.AbstractConsole"); + method = cls.getDeclaredMethod("setName", String.class); + method.setAccessible(true); + method.invoke(getConsole(), consoleName); + } catch (Exception e) { + ConsolePlugin.log(e); + } + } + }; + Display.getDefault().syncExec(runnable); + } + + private MessageConsole getMessageConsole(){ + boolean found = false; + + IConsole[] consoles = consoleManager.getConsoles(); + for (int i = 0; i < consoles.length; i++) { + if (this.consoleName.equals(consoles[i].getName())) { + console = (MessageConsole) consoles[i]; + consoleManager.removeConsoles(new IConsole[] { console }); + //found = true; + break; + } + } + + if (!found) { + console = new MessageConsole(this.consoleName, null); + consoleManager.addConsoles(new IConsole[] { console }); + } + + if(this.consoleFocus) + consoleManager.showConsoleView(console); + + return console; + } + public IConsole getConsole() { + return console; + } + /** + * Remove a MessageConsole instance specified key title from list, if it is present + * + * @param sessionId - a key title + */ + public void removeConsole(){ + MessageConsole console = null; + + IConsole[] consoles = consoleManager.getConsoles(); + for (int i = 0; i < consoles.length; i++) { + if (this.consoleName.equals(consoles[i].getName())) { + console = (MessageConsole) consoles[i]; + consoleManager.removeConsoles(new IConsole[] { console }); + break; + } + } + } + + /** + * Get the output stream of the MessageConsole + * @Deprecated + * @param isError - character's color is black if true or the color is red if false + * + * @return the MessageConsoleStream connected to MessageConsole + */ + @Deprecated + public MessageConsoleStream getMessageConsoleStream(boolean isError) { + final MessageConsoleStream output = this.console.newMessageStream(); + output.setActivateOnWrite(false); + + final int colorId; + if (!isError) { + colorId = SWT.COLOR_BLACK; + } else { + colorId = SWT.COLOR_RED; + } + + // we must set the color in the UI thread + Runnable runnable = new Runnable() { + public void run() { + Color color = Display.getCurrent().getSystemColor(colorId); + output.setColor(color); + } + }; + Display.getDefault().syncExec(runnable); + + return output; + } + /** + * Get the output stream of the MessageConsole + * + * @return the MessageConsoleStream connected to MessageConsole + */ + public MessageConsoleStream getMessageConsoleStream() { + return this.console.newMessageStream(); + } + public void println(String line) { + MessageConsoleStream output = this.console.newMessageStream(); + output.println(line); + try { + output.close(); + } catch (IOException e) { + ConsolePlugin.log(e); + } + } + public void printProcessStreams(Process process) { + + clear(); + // waitAndRead while process is running + ConsoleProcessClosure closure = new ConsoleProcessClosure(process, this); + closure.runBlocking(); // a blocking cal + } + private void setStringStyle(int fontStyle, Color color) { + // font setting + colorConsoleStream.setFontStyle(fontStyle); + + // color setting + colorConsoleStream.setColor(color); + } + + public void print(String line ,int fontStyle, Color color) { + colorConsoleStream = console.newMessageStream(); + display.syncExec(new ConsoleSettingThread(fontStyle, color)); + + colorConsoleStream.print(line); + try { + colorConsoleStream.close(); + } catch (IOException e) { + ConsolePlugin.log(e); + } + } + + public void println(String line ,int fontStyle, Color color) { + colorConsoleStream = console.newMessageStream(); + display.syncExec(new ConsoleSettingThread(fontStyle, color)); + + colorConsoleStream.println(line); + try { + colorConsoleStream.close(); + } catch (IOException e) { + ConsolePlugin.log(e); + } + } + + public void clear() + { + Runnable runnable = new Runnable() { + public void run() { + IDocument document = console.getDocument(); + if (document != null) { + document.set(""); + } + } + }; + Display.getDefault().syncExec(runnable); + } + public void show() { + Runnable runnable = new Runnable() { + public void run() { + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + String id = IConsoleConstants.ID_CONSOLE_VIEW; + IConsoleView view = null; + try { + view = (IConsoleView) page.showView(id); + } catch (PartInitException e) { + ConsolePlugin.log(e); + } + view.display(getConsole()); + } + }; + Display.getDefault().syncExec(runnable); + } + // setting thread. + class ConsoleSettingThread extends Thread { + // console text setting value + private int fontStyle; + private Color color; + + ConsoleSettingThread(int fontStyle, Color color) { + this.fontStyle = fontStyle; + this.color = color; + } + + public void run() { + setStringStyle(this.fontStyle, this.color); + } + } +} + diff --git a/org.tizen.common/src/org/tizen/common/console/ConsoleProcessClosure.java b/org.tizen.common/src/org/tizen/common/console/ConsoleProcessClosure.java new file mode 100644 index 000000000..a9fa6ed0f --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/console/ConsoleProcessClosure.java @@ -0,0 +1,250 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Changhyun Lee <changhyun1.lee@samsung.com> +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.console; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.List; + +import org.eclipse.swt.SWT; + + +/** + * Bundled state of a launched process including the threads linking the process + * in/output to console documents. + */ +public class ConsoleProcessClosure { + + /** + * Thread which continuously reads from a input stream and pushes the read + * data to an output stream which is immediately flushed afterwards. + */ + protected static class ReaderThread extends Thread { + + private InputStream fInputStream; + private ConsoleManager fConsole; + private boolean fFinished = false; + private String lineSeparator; + /* + * outputStream can be null + */ + public ReaderThread(ThreadGroup group, String name, InputStream in, ConsoleManager out) { + super(group, name); + fConsole = out; + fInputStream = in; + setDaemon(true); + lineSeparator = System.getProperty("line.separator"); //$NON-NLS-1$ + } + + @Override + public void run() { + try { + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(fInputStream)); + String line; + while ((line = reader.readLine()) != null) { + List<TextStyle> ts = AnsicodeAdapter.getStringStyles(line); + + if (ts != null) { + for (int i=0 ; i< ts.size() ; i++) { + fConsole.print(ts.get(i).getStripString(),SWT.NORMAL,ts.get(i).getForeground()); + } + } else { + fConsole.print(line,SWT.NORMAL,AnsicodeAdapter.BLACK); + } + fConsole.print(lineSeparator,SWT.NORMAL,AnsicodeAdapter.BLACK); + } + } catch (IOException x) { + // ignore + } finally { + try { + fInputStream.close(); + } catch (IOException e) { + // ignore + } + } + } finally { + complete(); + } + } + + public synchronized boolean finished() { + return fFinished; + } + + public synchronized void waitFor() { + while (!fFinished) { + try { + wait(); + } catch (InterruptedException e) { + } + } + } + + public synchronized void complete() { + fFinished = true; + notify(); + } + + public void close() { + //TODO : fix me! + /*try { + fOutputStream.close(); + } catch (IOException e) { + // ignore + }*/ + } + } + + protected static int fCounter = 0; + + protected Process fProcess; + protected ConsoleManager fConsole; + + protected ReaderThread fOutputReader; + protected ReaderThread fErrorReader; + + /** + * Creates a process closure and connects the launched process with a + * console document. + * + * @param outputStream + * prcess stdout is written to this stream. Can be + * <code>null</code>, if not interested in reading the output + * @param errorStream + * prcess stderr is written to this stream. Can be + * <code>null</code>, if not interested in reading the output + */ + public ConsoleProcessClosure(Process process, ConsoleManager console) { + fProcess = process; + fConsole = console; + } + + /** + * Live links the launched process with the configured in/out streams using + * reader threads. + */ + public void runNonBlocking() { + ThreadGroup group = new ThreadGroup("SRuncher" + fCounter++); //$NON-NLS-1$ + + InputStream stdin = fProcess.getInputStream(); + InputStream stderr = fProcess.getErrorStream(); + + fOutputReader = new ReaderThread(group, "OutputReader", stdin, fConsole); //$NON-NLS-1$ + fErrorReader = new ReaderThread(group, "ErrorReader", stderr, fConsole); //$NON-NLS-1$ + + fOutputReader.start(); + fErrorReader.start(); + } + + public void runBlocking() { + runNonBlocking(); + + boolean finished = false; + while (!finished) { + try { + fProcess.waitFor(); + } catch (InterruptedException e) { + //System.err.println("Closure exception " +e); + } + try { + fProcess.exitValue(); + finished = true; + } catch (IllegalThreadStateException e) { + //System.err.println("Closure exception " +e); + } + } + + // @@@FIXME: Windows 2000 is screwed; double-check using output threads + if (!fOutputReader.finished()) { + fOutputReader.waitFor(); + } + + if (!fErrorReader.finished()) { + fErrorReader.waitFor(); + } + + fOutputReader.close(); + fErrorReader.close(); + // it seems that thread termination and stream closing is working + // without + // any help + fProcess = null; + fOutputReader = null; + fErrorReader = null; + } + + public boolean isAlive() { + if (fProcess != null) { + if (fOutputReader.isAlive() || fErrorReader.isAlive()) { + return true; + } + fProcess = null; + fOutputReader.close(); + fErrorReader.close(); + fOutputReader = null; + fErrorReader = null; + } + return false; + } + + /** + * The same functionality as "isAlive()" + * but does not affect out streams, + * because they can be shared among processes + */ + public boolean isRunning() { + if (fProcess != null) { + if (fOutputReader.isAlive() || fErrorReader.isAlive()) { + return true; + } + fProcess = null; + } + return false; + } + /** + * Forces the termination the launched process + */ + public void terminate() { + if (fProcess != null) { + fProcess.destroy(); + fProcess = null; + } + if (!fOutputReader.finished()) { + fOutputReader.waitFor(); + } + if (!fErrorReader.finished()) { + fErrorReader.waitFor(); + } + fOutputReader.close(); + fErrorReader.close(); + fOutputReader = null; + fErrorReader = null; + } +} + diff --git a/org.tizen.common/src/org/tizen/common/console/TextStyle.java b/org.tizen.common/src/org/tizen/common/console/TextStyle.java new file mode 100644 index 000000000..d068ef8bf --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/console/TextStyle.java @@ -0,0 +1,53 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Changhyun Lee <changhyun1.lee@samsung.com> +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.console; + +import org.eclipse.swt.graphics.Color; + +public class TextStyle { + private Color foreground; + private Color background; + private String stripString; + + TextStyle(Color foreground,Color background,String stripString) { + this.foreground = foreground; + this.background = background; + this.stripString = stripString; + } + + public Color getForeground() { + return foreground; + } + + public Color getBackground() { + return background; + } + + public String getStripString() { + return stripString; + } + +} diff --git a/org.tizen.common/src/org/tizen/common/control/NotSupportedTypeException.java b/org.tizen.common/src/org/tizen/common/control/NotSupportedTypeException.java new file mode 100644 index 000000000..64cfa87c8 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/control/NotSupportedTypeException.java @@ -0,0 +1,35 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.control; + +public class NotSupportedTypeException extends Exception { + + public NotSupportedTypeException(){ + super(); + } + public NotSupportedTypeException(String message){ + super(message); + } +} diff --git a/org.tizen.common/src/org/tizen/common/control/TableViewCellModifier.java b/org.tizen.common/src/org/tizen/common/control/TableViewCellModifier.java new file mode 100644 index 000000000..6bbc54ede --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/control/TableViewCellModifier.java @@ -0,0 +1,136 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+
+package org.tizen.common.control;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ComboBoxCellEditor;
+import org.eclipse.jface.viewers.ICellModifier;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TextCellEditor;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.tizen.common.model.ITableVO;
+
+
+/**
+ * This class implements an ICellModifier
+ * An ICellModifier is called when the user modifes a cell in the
+ * tableViewer
+ */
+
+public class TableViewCellModifier implements ICellModifier {
+ private TableViewer viewer;
+ private String[] columnNames;
+ CellEditor[] cellEditors;
+ /**
+ * Constructor
+ * @param TableViewerExample an instance of a TableViewerExample
+ */
+ public TableViewCellModifier(TableViewer viewer) {
+ super();
+ this.viewer = viewer;
+ this.columnNames = getColumnNames();
+ this.viewer.setColumnProperties(columnNames);
+ }
+
+ private String[] getColumnNames() {
+ TableColumn[] columns = viewer.getTable().getColumns();
+ String[] columnNames = new String[columns.length];
+ for(int i=0;i<columnNames.length;i++){
+ columnNames[i] = columns[i].getText();
+ }
+
+ return columnNames;
+ }
+
+ /**
+ * @see org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object, java.lang.String)
+ */
+ public boolean canModify(Object element, String property) {
+ return true;
+ }
+
+ /**
+ * @see org.eclipse.jface.viewers.ICellModifier#getValue(java.lang.Object, java.lang.String)
+ */
+ public Object getValue(Object element, String property) {
+
+ Object result = null;
+ int idx = getColumnIndex(property);
+ ITableVO vo = (ITableVO)element;
+
+ CellEditor ce = getCellEditor(idx);
+
+ if(ce instanceof ComboBoxCellEditor){
+ result = vo.getColumnValue(idx);
+ }else if(ce instanceof TextCellEditor){
+ result = vo.getColumnValue(idx);
+ }else{
+ result = ""; //$NON-NLS-1$
+ }
+ return result;
+ }
+
+ private CellEditor getCellEditor(int idx) {
+ if(this.cellEditors==null)
+ this.cellEditors = viewer.getCellEditors();
+ return this.cellEditors[idx];
+ }
+
+ private int getColumnIndex(String property) {
+ for(int i=0;i<columnNames.length;i++){
+ if(columnNames[i].equals(property))
+ return i;
+ }
+ return 0;
+ }
+
+ private int getComboIndex(String[] items, Object str) {
+ for(int i=0;i<items.length;i++){
+ if(items[i].equals(str))
+ return i;
+ }
+ return 0;
+ }
+
+ /**
+ * @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object, java.lang.String, java.lang.Object)
+ */
+ public void modify(Object element, String property, Object value) {
+ int idx = getColumnIndex(property);
+ ITableVO vo = (ITableVO)((TableItem) element).getData();
+
+ if(cellEditors[idx] instanceof ComboBoxCellEditor){
+ if((Integer)value < 0)
+ return;
+ else
+ vo.setColumnValue(idx, value);
+ }else if(cellEditors[idx] instanceof TextCellEditor){
+ vo.setColumnValue(idx, value);
+ }
+
+ viewer.update(vo, null);
+ }
+}
diff --git a/org.tizen.common/src/org/tizen/common/control/TableViewColumnSorter.java b/org.tizen.common/src/org/tizen/common/control/TableViewColumnSorter.java new file mode 100644 index 000000000..b08a9bc46 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/control/TableViewColumnSorter.java @@ -0,0 +1,160 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+
+package org.tizen.common.control;
+
+import java.util.Comparator;
+
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Cursor;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.tizen.common.model.ITableVO;
+
+
+
+
+/**
+ * A viewer sorter is used by a structured viewer to reorder the elements
+ * provided by its content provider. In addition, the TableViewColumnSorter
+ * listens for mouse clicks in the column headers and resorts the table content
+ * based on the column that was selected. Clicking on a column a second time
+ * toggles the sort order.
+ */
+public class TableViewColumnSorter extends ViewerSorter {
+ private static final String COLUMN_INDEX_KEY = "COLUMN_INDEX"; //$NON-NLS-1$
+ private static final String HEADER_TEXT_KEY = "HEADER_TEXT"; //$NON-NLS-1$
+ private static final String TAG_DESCENDING = "â–²"; //$NON-NLS-1$
+ private static final String TAG_ASCENDING = "â–¼"; //$NON-NLS-1$
+
+ private TableViewer viewer;
+ private Table table;
+ private TableColumn[] columns;
+ Cursor waitCursor;
+
+ private Comparator<String> stringComparator = new Comparator<String>(){
+ @Override
+ public int compare(String str1, String str2) {
+ str1=str1==null?"":str1; //$NON-NLS-1$
+ str2=str2==null?"":str2; //$NON-NLS-1$
+ return str1.compareTo(str2);
+ }
+ };
+
+ private Comparator<Integer> numberComparator = new Comparator<Integer>(){
+ @Override
+ public int compare(Integer num1, Integer num2) {
+ return num1>num2?1:(num1==num2?0:-1);
+ }
+ };
+
+ public TableViewColumnSorter(TableViewer viewer) {
+ this.viewer = viewer;
+ this.table = viewer.getTable();
+ this.columns = viewer.getTable().getColumns();
+
+ createCursor();
+ createSelectionListener(columns);
+ }
+
+ private void createCursor(){
+ waitCursor = Display.getCurrent().getSystemCursor(SWT.CURSOR_WAIT);
+ }
+
+ public int compare(Viewer viewer, Object object1, Object object2) {
+ TableColumn column = table.getSortColumn();
+
+ int index = -1;
+ if(column==null){
+ return 0;
+ }else{
+ index = (Integer)column.getData(COLUMN_INDEX_KEY);
+ }
+
+ Object target1 = ((ITableVO)object1).getColumnValue(index);
+ Object target2 = ((ITableVO)object2).getColumnValue(index);
+
+ int result = compare(target1, target2);
+
+ if(table.getSortDirection()==SWT.UP)
+ return result;
+ else
+ return -result;
+ }
+
+ public int compare(Object object1, Object object2){
+ if(object1 instanceof Integer){
+ return numberComparator.compare((Integer)object1, (Integer)object2);
+ }else{
+ return stringComparator.compare(object1.toString(), object2.toString());
+ }
+ }
+
+ private void createSelectionListener(TableColumn[] columns) {
+ for (int i = 0; i < columns.length; i++) {
+ columns[i].setData(COLUMN_INDEX_KEY,i);
+ columns[i].setData(HEADER_TEXT_KEY,columns[i].getText());
+ columns[i].addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ TableColumn column = (TableColumn)e.getSource();
+ clearColumnHeader(column);
+ renderColumnHeader(column);
+
+ table.setCursor(waitCursor);
+ viewer.refresh();
+ table.setCursor(null);
+ }
+ });
+ }
+ }
+
+ private void renderColumnHeader(TableColumn column){
+ int direction = table.getSortDirection()==SWT.UP?SWT.DOWN:SWT.UP;
+ table.setSortDirection(direction);
+ table.setSortColumn(column);
+
+ String title = (String)column.getData(HEADER_TEXT_KEY);
+ String directionShape = direction==SWT.UP?TAG_DESCENDING:TAG_ASCENDING;
+ column.setText(title+" "+directionShape); //$NON-NLS-1$
+ }
+
+ private void clearColumnHeader(TableColumn column){
+ TableColumn prevColumn = table.getSortColumn();
+
+ if(prevColumn==null){
+ return;
+ }else{
+ prevColumn.setText((String)prevColumn.getData(HEADER_TEXT_KEY));
+ }
+ }
+
+}
\ No newline at end of file diff --git a/org.tizen.common/src/org/tizen/common/control/TableViewContentProvider.java b/org.tizen.common/src/org/tizen/common/control/TableViewContentProvider.java new file mode 100644 index 000000000..2d9038cac --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/control/TableViewContentProvider.java @@ -0,0 +1,50 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+
+package org.tizen.common.control;
+
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.tizen.common.model.ITableModel;
+
+
+public class TableViewContentProvider implements IStructuredContentProvider {
+
+ public TableViewContentProvider() {
+ }
+
+ public Object[] getElements(Object model) {
+ return ((ITableModel)model).getDatas();
+ }
+
+ public void dispose() {
+
+ }
+
+ public void inputChanged(Viewer viewer, Object obj, Object obj1) {
+
+ }
+
+}
diff --git a/org.tizen.common/src/org/tizen/common/control/TableViewLabelProvider.java b/org.tizen.common/src/org/tizen/common/control/TableViewLabelProvider.java new file mode 100644 index 000000000..12bfa05cb --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/control/TableViewLabelProvider.java @@ -0,0 +1,121 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+
+package org.tizen.common.control;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ComboBoxCellEditor;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.graphics.Image;
+import org.tizen.common.model.ITableVO;
+
+
+
+
+
+public class TableViewLabelProvider extends ColumnLabelProvider implements ITableLabelProvider {
+
+ public TableViewLabelProvider() {
+ }
+
+ private TableViewer viewer;
+ CellEditor[] cellEditors;
+
+ public TableViewLabelProvider(TableViewer viewer) {
+ this.viewer = viewer;
+ this.cellEditors = viewer.getCellEditors();
+ }
+
+ private Field[] fields;
+
+ private int getColumnIndex(int columnIndex){
+ return fields.length>columnIndex?columnIndex:fields.length;
+ }
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+
+// private void hasCellEditor(){
+// if(this.cellEditors==null)
+// this.cellEditors = viewer.getCellEditors();
+// }
+
+ private CellEditor getCellEditor(int idx) {
+ if(this.cellEditors==null)
+ return null;
+ else
+ return this.cellEditors[idx];
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ Object obj = null;
+
+ if(element instanceof ITableVO){
+ ITableVO data = (ITableVO)element;
+ if(this.cellEditors != null){
+ CellEditor ce = getCellEditor(columnIndex);
+ if(ce instanceof ComboBoxCellEditor){
+ ComboBoxCellEditor editor = (ComboBoxCellEditor)ce;
+ String items[] = editor.getItems();
+ int idx = (Integer) data.getColumnValue(columnIndex);
+ if(idx<0)
+ obj = null;
+ else if(idx>items.length)
+ obj = items[0];
+ else
+ obj = items[idx];
+ }else{
+ obj = data.getColumnValue(columnIndex);
+ }
+ }else{
+ obj = data.getColumnValue(columnIndex);
+ }
+ }else{
+ if(fields==null)
+ fields = element.getClass().getDeclaredFields();
+
+ int idx = getColumnIndex(columnIndex);
+ String fieldName = fields[idx].getName().substring(0, 1).toUpperCase()
+ + fields[idx].getName().substring(1,fields[idx].getName().length());
+
+ try{
+ Method method = element.getClass().getMethod("get" + fieldName, new Class[] {}); //$NON-NLS-1$
+ obj = method.invoke(element, new Object[] {});
+ }catch(Exception e){
+ return ""; //$NON-NLS-1$
+ }
+ }
+
+ return obj==null?"":String.valueOf(obj); //$NON-NLS-1$
+ }
+
+
+}
diff --git a/org.tizen.common/src/org/tizen/common/control/TreeViewContentProvider.java b/org.tizen.common/src/org/tizen/common/control/TreeViewContentProvider.java new file mode 100644 index 000000000..726fb9390 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/control/TreeViewContentProvider.java @@ -0,0 +1,69 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+
+package org.tizen.common.control;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.tizen.common.model.ITreeModel;
+import org.tizen.common.model.ITreeVO;
+
+
+public class TreeViewContentProvider implements ITreeContentProvider {
+
+ public Object[] getChildren(Object element) {
+ if(element instanceof ITreeModel)
+ return ((ITreeModel)element).getDatas();
+ else
+ return ((ITreeVO)element).getChildren();
+ }
+
+ public Object getParent(Object element) {
+ if(element instanceof ITreeModel)
+ return null;
+ else
+ return ((ITreeVO)element).getParent();
+
+ }
+
+ public boolean hasChildren(Object element) {
+ if(element instanceof ITreeModel)
+ return ((ITreeModel)element).size()>0;
+ else
+ return ((ITreeVO)element).hasChildren();
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return getChildren(inputElement);
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+
+}
diff --git a/org.tizen.common/src/org/tizen/common/control/TreeViewLabelProvider.java b/org.tizen.common/src/org/tizen/common/control/TreeViewLabelProvider.java new file mode 100644 index 000000000..77bb41387 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/control/TreeViewLabelProvider.java @@ -0,0 +1,32 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+
+package org.tizen.common.control;
+
+import org.eclipse.jface.viewers.LabelProvider;
+
+public class TreeViewLabelProvider extends LabelProvider {
+
+}
diff --git a/org.tizen.common/src/org/tizen/common/handler/ClearHandler.java b/org.tizen.common/src/org/tizen/common/handler/ClearHandler.java new file mode 100644 index 000000000..ba8c72731 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/handler/ClearHandler.java @@ -0,0 +1,65 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ + +package org.tizen.common.handler; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.handlers.HandlerUtil; +import org.tizen.common.manager.StatusLineMessageManager; +import org.tizen.common.model.ITableModel; + + + +public class ClearHandler extends AbstractHandler { + private IViewPart part; + private TableViewer viewer; + private StatusLineMessageManager statusLine; + + private String message = Messages.ClearHandler_0; + + public Object execute(ExecutionEvent event) throws ExecutionException { + + part = (IViewPart)HandlerUtil.getActivePart(event); + viewer = (TableViewer)part.getSite().getSelectionProvider(); + statusLine = new StatusLineMessageManager(part); + + clearData(); + return null; + } + + private void clearData() throws ExecutionException { + ITableModel model = (ITableModel)viewer.getInput(); + model.clear(); + viewer.refresh(); + statusLine.setMessage(message); + } + + +} + diff --git a/org.tizen.common/src/org/tizen/common/handler/ClipboardHandler.java b/org.tizen.common/src/org/tizen/common/handler/ClipboardHandler.java new file mode 100644 index 000000000..e31e5eed2 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/handler/ClipboardHandler.java @@ -0,0 +1,51 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+
+package org.tizen.common.handler;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * Superclass for clipboard related handlers providing safe creation and
+ * disposal of the {@link Clipboard}.
+ */
+public abstract class ClipboardHandler extends AbstractHandler {
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ Clipboard clipboard = new Clipboard(HandlerUtil.getActiveShell(event)
+ .getDisplay());
+ try {
+ return execute(event, clipboard);
+ } finally {
+ clipboard.dispose();
+ }
+ }
+
+ protected abstract Object execute(ExecutionEvent event, Clipboard clipboard)
+ throws ExecutionException;
+}
\ No newline at end of file diff --git a/org.tizen.common/src/org/tizen/common/handler/CopyHandler.java b/org.tizen.common/src/org/tizen/common/handler/CopyHandler.java new file mode 100644 index 000000000..54d604f79 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/handler/CopyHandler.java @@ -0,0 +1,101 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+
+package org.tizen.common.handler;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWTError;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.part.ResourceTransfer;
+
+/**
+ * Copy each currently selected object in the Favorites view to the clipboard.
+ */
+public class CopyHandler extends ClipboardHandler {
+ /**
+ * Called by the superclass {@link #execute(ExecutionEvent)} method so that
+ * this method can concentrate on the operation and does not have to manage
+ * clipboard creation and disposal.
+ */
+ public Object execute(ExecutionEvent event, Clipboard clipboard)
+ throws ExecutionException {
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ if (selection instanceof IStructuredSelection) {
+ Object[] objects = ((IStructuredSelection) selection).toArray();
+ if (objects.length > 0) {
+ try {
+ clipboard.setContents(new Object[] { asResources(objects),
+ asText(objects), }, new Transfer[] {
+ ResourceTransfer.getInstance(),
+ TextTransfer.getInstance(), });
+ } catch (SWTError error) {
+ // Copy to clipboard failed.
+ // This happens when another application
+ // is accessing the clipboard while we copy.
+ // Ignore the error.
+ }
+ }
+ }
+ return null;
+ }
+
+ public static IResource[] asResources(Object[] objects) {
+ Collection<IResource> resources = new ArrayList<IResource>(
+ objects.length);
+ for (int i = 0; i < objects.length; i++) {
+ Object each = objects[i];
+ if (each instanceof IAdaptable) {
+ IResource res = (IResource) ((IAdaptable) each)
+ .getAdapter(IResource.class);
+ if (res != null)
+ resources.add(res);
+ }
+ }
+ return resources.toArray(new IResource[resources.size()]);
+ }
+
+ public static String asText(Object[] objects) {
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < objects.length; i++) {
+ Object each = objects[i];
+ if (each != null) {
+ buf.append(each.toString());
+ }
+ buf.append(System.getProperty("line.separator")); //$NON-NLS-1$
+ }
+ return buf.toString();
+ }
+}
diff --git a/org.tizen.common/src/org/tizen/common/handler/Messages.java b/org.tizen.common/src/org/tizen/common/handler/Messages.java new file mode 100644 index 000000000..7cb9e48ae --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/handler/Messages.java @@ -0,0 +1,49 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ + +package org.tizen.common.handler; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.tizen.common.handler.messages"; //$NON-NLS-1$ + public static String ClearHandler_0; + public static String OpenFileHandler_0; + public static String OpenFileHandler_2; + public static String OpenFileHandler_3; + public static String SaveFileHandler_0; + public static String SaveFileHandler_1; + public static String SaveFileHandler_11; + public static String SaveFileHandler_12; + public static String SaveFileHandler_4; + public static String SaveFileHandler_5; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/org.tizen.common/src/org/tizen/common/handler/OpenFileHandler.java b/org.tizen.common/src/org/tizen/common/handler/OpenFileHandler.java new file mode 100644 index 000000000..f97b3e066 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/handler/OpenFileHandler.java @@ -0,0 +1,103 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ + +package org.tizen.common.handler; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileInfo; +import org.eclipse.core.filesystem.IFileStore; +import org.eclipse.core.runtime.Path; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.ide.IDE; +import org.tizen.common.manager.StatusLineMessageManager; + + + +public class OpenFileHandler extends AbstractHandler { + private IViewPart part; + private String fileName; + private Shell shell; + private IWorkbenchPage page; + private StatusLineMessageManager statusLine; + + private final String title = Messages.OpenFileHandler_0; + private final String PARAMETER_ID = "org.tizen.common.command.openFile.parameter"; //$NON-NLS-1$ + + public Object execute(ExecutionEvent event) throws ExecutionException { + + part = (IViewPart)HandlerUtil.getActivePart(event); + shell = part.getSite().getShell(); + page = part.getSite().getPage(); + statusLine = new StatusLineMessageManager(part); + + String extension = event.getParameter(PARAMETER_ID); + + openFile(extension); + return null; + } + + private void openFile(String extension) throws ExecutionException { + fileName = getLoadFileName(extension); + if(fileName==null) + return; + + IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(fileName)); + IFileInfo fileInfo = fileStore.fetchInfo(); + fileInfo.setAttribute(EFS.ATTRIBUTE_READ_ONLY, true); + + if( fileInfo.isDirectory()||!fileInfo.exists() ){ + statusLine.setErrorMessage(Messages.OpenFileHandler_2); + return; + } + + try { + IDE.openEditorOnFileStore(page, fileStore); + } catch (PartInitException e) { + statusLine.setErrorMessage(fileName+ Messages.OpenFileHandler_3); + return; + } + + } + + private String getLoadFileName(String extension) { + String[] extFilter = {"*."+extension}; //$NON-NLS-1$ + + FileDialog dialog = new FileDialog(shell, SWT.OPEN); + dialog.setFilterExtensions(extFilter); + dialog.setText(title); + return dialog.open(); + } + +} + diff --git a/org.tizen.common/src/org/tizen/common/handler/OpenPreferencesHandler.java b/org.tizen.common/src/org/tizen/common/handler/OpenPreferencesHandler.java new file mode 100644 index 000000000..32932b811 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/handler/OpenPreferencesHandler.java @@ -0,0 +1,61 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ + +package org.tizen.common.handler; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.preference.PreferenceDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.dialogs.PreferencesUtil; +import org.eclipse.ui.handlers.HandlerUtil; + +public class OpenPreferencesHandler extends AbstractHandler { + private IViewPart part; + private Shell shell; + private final String PARAMETER_ID = "org.tizen.common.command.setting.parameter"; //$NON-NLS-1$ + + public Object execute(ExecutionEvent event) throws ExecutionException { + + part = (IViewPart)HandlerUtil.getActivePart(event); + shell = part.getSite().getShell(); + + String preferenceId = event.getParameter(PARAMETER_ID); + openPreferences(preferenceId); + return null; + } + + private void openPreferences(String preferenceId) throws ExecutionException { + PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(shell, + preferenceId, null, null); + dialog.open(); + } + + + +} + diff --git a/org.tizen.common/src/org/tizen/common/handler/SaveFileHandler.java b/org.tizen.common/src/org/tizen/common/handler/SaveFileHandler.java new file mode 100644 index 000000000..c703e302d --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/handler/SaveFileHandler.java @@ -0,0 +1,139 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ + +package org.tizen.common.handler; + +import java.io.File; +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.handlers.HandlerUtil; +import org.tizen.common.manager.StatusLineMessageManager; +import org.tizen.common.model.ITableModel; +import org.tizen.common.util.DialogUtil; + + + +public class SaveFileHandler extends AbstractHandler { + private IViewPart part; + private TableViewer viewer; + private String fileName; + private Shell shell; + private StatusLineMessageManager statusLine; + + private final String title = Messages.SaveFileHandler_0; + private final String PARAMETER_ID = "org.tizen.common.command.saveFile.parameter"; //$NON-NLS-1$ + + + public Object execute(ExecutionEvent event) throws ExecutionException { + + part = (IViewPart)HandlerUtil.getActivePart(event); + shell = part.getSite().getShell(); + statusLine = new StatusLineMessageManager(part); + + viewer = (TableViewer)part.getSite().getSelectionProvider(); + String extension = event.getParameter(PARAMETER_ID); + + if(!hasRecord()) + return null; + + try { + saveFile(extension); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + + private void saveFile(String extension) throws InvocationTargetException, InterruptedException { + fileName = getSaveFileName(extension); + + if(fileName==null) + return; + + if(!fileName.endsWith("."+extension)) //$NON-NLS-1$ + fileName= fileName+"."+extension; //$NON-NLS-1$ + + if(!(new File(fileName).getParentFile().canWrite())){ + DialogUtil.openErrorDialog(Messages.SaveFileHandler_4); + return; + } + + part.getSite().getWorkbenchWindow().run(false, false, new IRunnableWithProgress(){ + public void run(IProgressMonitor monitor) { + monitor.beginTask(Messages.SaveFileHandler_5, 100); + writeRecord(); + monitor.done(); + } + }); + + showRecordCount(); + + } + + private String getSaveFileName(String extension) { + String[] extFilter = {"*."+extension,"*.*"}; //$NON-NLS-1$ //$NON-NLS-2$ + + FileDialog dialog = new FileDialog(shell, SWT.SAVE); + dialog.setFilterExtensions(extFilter); + dialog.setText(title); + dialog.setOverwrite(true); + dialog.setFileName("untitled."+extension); //$NON-NLS-1$ + dialog.setFilterPath(System.getProperty("user.home")); //$NON-NLS-1$ + + return dialog.open(); + } + + private void writeRecord() { + ITableModel model = (ITableModel) viewer.getInput(); + model.save(fileName); + } + + private void showRecordCount() { + int size = ((ITableModel) viewer.getInput()).size(); + statusLine.setMessage(Messages.SaveFileHandler_1+size+Messages.SaveFileHandler_11 + fileName); + } + + private boolean hasRecord() { + int size = ((ITableModel) viewer.getInput()).size(); + if(size==0){ + statusLine.setErrorMessage(Messages.SaveFileHandler_12); + return false; + }else + statusLine.setErrorMessage(""); //$NON-NLS-1$ + return true; + } +} + diff --git a/org.tizen.common/src/org/tizen/common/handler/messages.properties b/org.tizen.common/src/org/tizen/common/handler/messages.properties new file mode 100644 index 000000000..f9d98c9af --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/handler/messages.properties @@ -0,0 +1,10 @@ +ClearHandler_0=All data is cleared +OpenFileHandler_0=Load File +OpenFileHandler_2=Input file doesn't exist or isn't a file +OpenFileHandler_3=isn't opened for internal error +SaveFileHandler_0=Save File +SaveFileHandler_1=Total +SaveFileHandler_11=\ record is saved into +SaveFileHandler_12=There is no record. +SaveFileHandler_4=You can store a file into the directory that has write permission. please select another directory +SaveFileHandler_5=Save File diff --git a/org.tizen.common/src/org/tizen/common/log/Logger.java b/org.tizen.common/src/org/tizen/common/log/Logger.java new file mode 100644 index 000000000..6f09f7824 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/log/Logger.java @@ -0,0 +1,99 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ + +package org.tizen.common.log; + +import java.text.MessageFormat; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.tizen.common.CommonPlugin; +import org.tizen.common.console.ConsoleManager; + + +/** + * Logger. + * @author Changhyun Lee {@literal <changhyun1.lee@samsung.com>} (S-Core) + */ +public class Logger { + private static String loggerName = Logger.class.getName(); + + public static void log(IStatus status) { + CommonPlugin plugin = CommonPlugin.getDefault(); + if (plugin != null) { + plugin.getLog().log(status); + } else { + ConsoleManager conManager = new ConsoleManager("Error Log", false); + conManager.println(status.getPlugin() + " : " + status.getMessage()); + } + } + + private static String getCallerName() { + // Get the stack trace. + StackTraceElement stack[] = (new Throwable()).getStackTrace(); + int ix = 0; + // Now search for the first frame before the "Logger" class. + while (ix < stack.length) { + StackTraceElement frame = stack[ix]; + String cname = frame.getClassName(); + if (!cname.equals(loggerName)) { + return cname; + } + ix++; + } + return "noname"; + } + + public static void log(Throwable e) { + if (e instanceof CoreException) { + log(new Status(IStatus.ERROR, getCallerName(), ((CoreException) e).getStatus().getSeverity(), e.getMessage(), e.getCause())); + } else { + log(new Status(IStatus.ERROR, getCallerName(), e.toString(), e)); + } + } + + public static void info(String message, Object... arguments) { + log(new Status(Status.INFO, getCallerName(), getPossiblyFormattedString(message, arguments))); + } + + public static void error(Object message, Throwable t) { + log(new Status(Status.ERROR, getCallerName(), message.toString(), t)); + } + + public static void error(String message, Object... arguments) { + log(new Status(Status.ERROR, getCallerName(), getPossiblyFormattedString(message, arguments))); + } + + public static void warning(String message, Object... arguments) { + log(new Status(Status.WARNING, getCallerName(), getPossiblyFormattedString(message, arguments))); + } + + private static String getPossiblyFormattedString(String message, Object... arguments) { + return arguments.length > 0 ? MessageFormat.format(message, arguments) + : message; + } + +} diff --git a/org.tizen.common/src/org/tizen/common/manager/ColorCache.java b/org.tizen.common/src/org/tizen/common/manager/ColorCache.java new file mode 100644 index 000000000..3920db1d1 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/manager/ColorCache.java @@ -0,0 +1,88 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.manager; + +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Display; + +public class ColorCache { + private String[] keys; + private Color[] colors; + + public ColorCache(String[] keys){ + if(keys==null||keys.length==0) + throw new IllegalArgumentException(Messages.ColorCache_0); + + this.keys = keys; + this.colors = new Color[keys.length]; + } + + private int getIndex(String key){ + int index = -1; + for(int i=0;i<keys.length;i++){ + if(key!=null&&key.equals(keys[i])){ + index = i; + break; + } + } + return index; + } + + public Color getColor(String key){ + int index = getIndex(key); + if(index<0){ + return null; + }else{ + return colors[index]; + } + } + + public void setColor(String key, RGB rgb){ + int index = getIndex(key); + if(index<0) + return; + + Color color = colors[index]; + if(color!=null){ + color.dispose(); + color=null; + } + + colors[index] = new Color(Display.getCurrent(),rgb); + } + + public void dispose(){ + for(int i=0;i<colors.length;i++){ + Color color = colors[i]; + if(color!=null){ + color.dispose(); + color=null; + } + } + } + + +} diff --git a/org.tizen.common/src/org/tizen/common/manager/Messages.java b/org.tizen.common/src/org/tizen/common/manager/Messages.java new file mode 100644 index 000000000..f5fa5a835 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/manager/Messages.java @@ -0,0 +1,40 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ + +package org.tizen.common.manager; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.tizen.common.manager.messages"; //$NON-NLS-1$ + public static String ColorCache_0; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/org.tizen.common/src/org/tizen/common/manager/StatusLineMessageManager.java b/org.tizen.common/src/org/tizen/common/manager/StatusLineMessageManager.java new file mode 100644 index 000000000..77d279e10 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/manager/StatusLineMessageManager.java @@ -0,0 +1,47 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.manager; + +import org.eclipse.jface.action.IStatusLineManager; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchPart; + +public class StatusLineMessageManager{ + private IViewPart part; + private IStatusLineManager manager; + + public StatusLineMessageManager(IWorkbenchPart part){ + this.part = (IViewPart)part; + this.manager = this.part.getViewSite().getActionBars().getStatusLineManager(); + } + + public void setErrorMessage(String message){ + manager.setErrorMessage(message); + } + + public void setMessage(String message){ + manager.setMessage(message); + } +}
\ No newline at end of file diff --git a/org.tizen.common/src/org/tizen/common/manager/messages.properties b/org.tizen.common/src/org/tizen/common/manager/messages.properties new file mode 100644 index 000000000..19dbd56f4 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/manager/messages.properties @@ -0,0 +1 @@ +ColorCache_0=Argument must not be null diff --git a/org.tizen.common/src/org/tizen/common/model/AbstractTableModel.java b/org.tizen.common/src/org/tizen/common/model/AbstractTableModel.java new file mode 100644 index 000000000..97555e65e --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/model/AbstractTableModel.java @@ -0,0 +1,180 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+
+package org.tizen.common.model;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.XMLMemento;
+
+public abstract class AbstractTableModel implements ITableModel {
+ private static final String TAG_ROOT = "root"; //$NON-NLS-1$
+
+ private Collection<AbstractTableVO> inventory = new ArrayList<AbstractTableVO>();
+ protected AbstractTableVO source;
+ private boolean isDirty = false;
+
+ public AbstractTableModel(AbstractTableVO source) {
+ this.source = source;
+
+ }
+
+
+
+ public ITableVO[] getDatas() {
+ if (inventory == null)
+ return null;
+
+ return inventory.toArray(new AbstractTableVO[inventory.size()]);
+ }
+
+ public void add(Collection<AbstractTableVO> datas) {
+ if (datas == null)
+ return;
+
+ inventory.addAll(datas);
+ }
+
+ public int size(){
+ return inventory.size();
+ }
+
+ public void add(AbstractTableVO data) {
+ inventory.add(data);
+ }
+
+ public void remove(Collection<AbstractTableVO> datas) {
+ if (datas == null)
+ return;
+
+ inventory.removeAll(datas);
+ }
+
+ public void remove(AbstractTableVO data) {
+ inventory.remove(data);
+ }
+
+ public void clear() {
+ inventory.clear();
+ }
+
+ public void load(String fileName) {
+ if (inventory==null||source==null)
+ return;
+
+ FileReader reader = null;
+ try {
+ reader = new FileReader(new File(fileName));
+ load(XMLMemento.createReadRoot(reader));
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ if (reader != null)
+ reader.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private void load(XMLMemento memento) {
+ IMemento[] children = memento.getChildren(getSourceName());
+ AbstractTableVO data = null;
+ String[] fields = source.getColumnNames();
+ for (int i = 0; i < children.length; i++) {
+ data = source.clone();
+ for (int j = 0; j < fields.length; j++) {
+ data.setColumnValue(j, children[i].getString(fields[j]));
+ }
+ add(data);
+ }
+ }
+
+ public void save(String fileName) {
+ if (inventory == null || source == null)
+ return;
+
+ XMLMemento memento = XMLMemento.createWriteRoot(TAG_ROOT);
+ save(memento);
+ FileWriter writer = null;
+ try {
+ writer = new FileWriter(fileName);
+ memento.save(writer);
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ if (writer != null)
+ writer.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private void save(XMLMemento memento) {
+ Iterator<AbstractTableVO> iter = inventory.iterator();
+ AbstractTableVO data = null;
+ String[] fields = null;
+
+ while (iter.hasNext()) {
+ data = iter.next();
+ fields = data.getColumnNames();
+ IMemento child = memento.createChild(getSourceName());
+ for (int j = 0; j < fields.length; j++) {
+ child.putString(
+ fields[j],
+ String.valueOf(data.getColumnValue(j)));
+ }
+ }
+
+ }
+
+ public String getSourceName() {
+ return this.source.getClass().getSimpleName();
+ }
+
+ public boolean isDirty(){
+ return this.isDirty;
+ }
+
+ public synchronized void setDirty(boolean isDirty){
+ this.isDirty = isDirty;
+ }
+
+}
+
+
diff --git a/org.tizen.common/src/org/tizen/common/model/AbstractTableVO.java b/org.tizen.common/src/org/tizen/common/model/AbstractTableVO.java new file mode 100644 index 000000000..8f359a677 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/model/AbstractTableVO.java @@ -0,0 +1,80 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+
+package org.tizen.common.model;
+
+public abstract class AbstractTableVO implements ITableVO{
+ public abstract String[] getColumnNames();
+ public abstract Object getColumnValue(int index);
+ public abstract void setColumnValue(int index, Object value);
+
+ public AbstractTableVO clone(){
+ Object obj = null;
+ try{
+ obj = super.clone();
+ }catch(CloneNotSupportedException e){
+
+ }
+ return (AbstractTableVO)obj;
+ }
+
+ public Object getColumnValue(String columnName){
+ return getColumnValue(getColumnIndex(columnName));
+ }
+
+ public String getColumnName(int index){
+ String[] columnNames = getColumnNames();
+ if(index<0||index>columnNames.length)
+ return null;
+ else
+ return columnNames[index];
+ }
+
+ public int getColumnIndex(String columnName){
+ String[] columnNames = getColumnNames();
+ int index =-1;
+ for(int i=0;i<columnNames.length;i++){
+ if(columnName.equals(columnNames[i])){
+ index = i;
+ break;
+ }
+ }
+ return index;
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer buf = new StringBuffer();
+ String[] fields = getColumnNames();
+ for (int j = 0; j < fields.length; j++) {
+ Object obj = getColumnValue(j);
+ buf.append(obj==null?"":String.valueOf(obj)); //$NON-NLS-1$
+ if(j<fields.length-1)
+ buf.append(","); //$NON-NLS-1$
+ }
+ return buf.toString();
+ }
+
+}
diff --git a/org.tizen.common/src/org/tizen/common/model/AbstractTreeModel.java b/org.tizen.common/src/org/tizen/common/model/AbstractTreeModel.java new file mode 100644 index 000000000..0282ddf99 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/model/AbstractTreeModel.java @@ -0,0 +1,102 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+
+package org.tizen.common.model;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.ui.XMLMemento;
+
+public class AbstractTreeModel implements ITreeModel {
+ private static final String TAG_ROOT = "root"; //$NON-NLS-1$
+
+ private Collection<ITreeVO> inventory = new ArrayList<ITreeVO>();
+ protected ITreeVO source;
+ private boolean isDirty = false;
+
+ public AbstractTreeModel(ITreeVO source){
+// if(source.getSuperclass() != ITreeVO.class)
+ this.source = source;
+ }
+
+ public ITreeVO[] getDatas() {
+ if (inventory == null)
+ return null;
+
+ return inventory.toArray(new ITreeVO[inventory.size()]);
+ }
+
+ public void add(Collection<ITreeVO> datas) {
+ if (datas == null)
+ return;
+
+ inventory.addAll(datas);
+ }
+
+ public int size(){
+ return inventory.size();
+ }
+
+ public void add(ITreeVO data) {
+ inventory.add(data);
+ }
+
+ public void remove(Collection<ITreeVO> datas) {
+ if (datas == null)
+ return;
+
+ inventory.removeAll(datas);
+ }
+
+ public void remove(ITreeVO data) {
+ inventory.remove(data);
+ }
+
+ public void clear() {
+ inventory.clear();
+ }
+
+ public void load(String fileName) {
+ }
+
+ private void load(XMLMemento memento) {
+ }
+
+ public void save(String fileName) {
+ }
+
+ private void save(XMLMemento memento) {
+ }
+
+ public String getSourceName() {
+ return this.source.getClass().getSimpleName();
+ }
+
+
+
+}
+
+
diff --git a/org.tizen.common/src/org/tizen/common/model/AbstractTreeVO.java b/org.tizen.common/src/org/tizen/common/model/AbstractTreeVO.java new file mode 100644 index 000000000..8a7c0f050 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/model/AbstractTreeVO.java @@ -0,0 +1,109 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+
+package org.tizen.common.model;
+
+import java.util.ArrayList;
+
+public abstract class AbstractTreeVO implements ITreeVO{
+
+ private String text;
+ private String description;
+ private Object data = null;
+ private int level = 0;
+
+ private AbstractTreeVO parent;
+ private ArrayList<AbstractTreeVO> children;
+
+ public AbstractTreeVO(AbstractTreeVO parent,String text) {
+ this.parent = parent;
+ this.text = text;
+ this.level = parent==null?1:parent.getLevel()+1;
+ if(parent!=null)
+ parent.addChild(this);
+ children = new ArrayList<AbstractTreeVO>();
+ }
+
+ public AbstractTreeVO(AbstractTreeVO parent) {
+ this(parent,null);
+ }
+
+ public ITreeVO[] getChildren() {
+ return (ITreeVO[])children.toArray(new ITreeVO[children.size()]);
+ }
+
+ public ITreeVO getParent(){
+ return this.parent;
+ }
+
+ public boolean hasChildren() {
+ return children.size()>0;
+ }
+
+ public int size() {
+ return children.size();
+ }
+
+ public void addChild(ITreeVO child) {
+ children.add((AbstractTreeVO)child);
+ }
+
+ public void removeChild(Object child) {
+ children.remove(child);
+ }
+
+ public String toString() {
+ return getText();
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public void setData(Object data) {
+ this.data = data;
+ }
+
+ public Object getData(){
+ return this.data;
+ }
+
+ public int getLevel(){
+ return this.level;
+ }
+
+}
diff --git a/org.tizen.common/src/org/tizen/common/model/DefaultTableModel.java b/org.tizen.common/src/org/tizen/common/model/DefaultTableModel.java new file mode 100644 index 000000000..d50073748 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/model/DefaultTableModel.java @@ -0,0 +1,43 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+
+package org.tizen.common.model;
+
+
+public class DefaultTableModel extends AbstractTableModel {
+
+ public DefaultTableModel(AbstractTableVO source) {
+ super(source);
+ }
+
+ public String getSourceName() {
+ String str = this.source.getClass().getSimpleName();
+ if(str.endsWith("VO")) //$NON-NLS-1$
+ str = str.substring(0,str.length()-2);
+ return str;
+ }
+}
+
+
diff --git a/org.tizen.common/src/org/tizen/common/model/DefaultTreeModel.java b/org.tizen.common/src/org/tizen/common/model/DefaultTreeModel.java new file mode 100644 index 000000000..687c3089a --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/model/DefaultTreeModel.java @@ -0,0 +1,44 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+
+package org.tizen.common.model;
+
+
+
+public class DefaultTreeModel extends AbstractTreeModel {
+
+ public DefaultTreeModel(ITreeVO source){
+ super(source);
+ }
+
+ public String getSourceName() {
+ String str = this.source.getClass().getSimpleName();
+ if(str.endsWith("VO")) //$NON-NLS-1$
+ str = str.substring(0,str.length()-2);
+ return str;
+ }
+}
+
+
diff --git a/org.tizen.common/src/org/tizen/common/model/ITableModel.java b/org.tizen.common/src/org/tizen/common/model/ITableModel.java new file mode 100644 index 000000000..e21b41f51 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/model/ITableModel.java @@ -0,0 +1,45 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+
+package org.tizen.common.model;
+
+import java.util.Collection;
+
+
+public interface ITableModel
+{
+ public void add(AbstractTableVO datas);
+ public void add(Collection<AbstractTableVO> datas);
+ public void remove(AbstractTableVO datas);
+ public void remove(Collection<AbstractTableVO> datas);
+ public ITableVO[] getDatas();
+ public void load(String fileName);
+ public void save(String fileName);
+ public void clear();
+ public int size();
+ public String getSourceName();
+ public boolean isDirty();
+ public void setDirty(boolean isDirty);
+}
diff --git a/org.tizen.common/src/org/tizen/common/model/ITableVO.java b/org.tizen.common/src/org/tizen/common/model/ITableVO.java new file mode 100644 index 000000000..e8a4592f3 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/model/ITableVO.java @@ -0,0 +1,35 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+
+package org.tizen.common.model;
+
+public interface ITableVO extends IVO{
+ public String[] getColumnNames();
+ public Object getColumnValue(int index);
+ public Object getColumnValue(String columnName);
+ public int getColumnIndex(String columnName);
+ public String getColumnName(int index);
+ public void setColumnValue(int index, Object value);
+}
diff --git a/org.tizen.common/src/org/tizen/common/model/ITreeModel.java b/org.tizen.common/src/org/tizen/common/model/ITreeModel.java new file mode 100644 index 000000000..50a7a1373 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/model/ITreeModel.java @@ -0,0 +1,42 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+
+package org.tizen.common.model;
+
+import java.util.Collection;
+
+public interface ITreeModel
+{
+ public void add(ITreeVO datas);
+ public void add(Collection<ITreeVO> datas);
+ public void remove(ITreeVO datas);
+ public void remove(Collection<ITreeVO> datas);
+ public ITreeVO[] getDatas();
+ public void load(String fileName);
+ public void save(String fileName);
+ public void clear();
+ public int size();
+ public String getSourceName();
+}
diff --git a/org.tizen.common/src/org/tizen/common/model/ITreeVO.java b/org.tizen.common/src/org/tizen/common/model/ITreeVO.java new file mode 100644 index 000000000..b0968aaca --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/model/ITreeVO.java @@ -0,0 +1,42 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+
+package org.tizen.common.model;
+
+public interface ITreeVO extends IVO{
+ public ITreeVO[] getChildren();
+ public ITreeVO getParent();
+ public boolean hasChildren();
+ public int size();
+ public void addChild(ITreeVO child);
+ public void removeChild(Object child) ;
+ public String getText();
+ public void setText(String text);
+ public String getDescription();
+ public void setDescription(String description);
+ public void setData(Object data);
+ public Object getData();
+ public int getLevel();
+}
diff --git a/org.tizen.common/src/org/tizen/common/model/IVO.java b/org.tizen.common/src/org/tizen/common/model/IVO.java new file mode 100644 index 000000000..c49cf134c --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/model/IVO.java @@ -0,0 +1,29 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+
+package org.tizen.common.model;
+
+public interface IVO extends Cloneable{
+}
diff --git a/org.tizen.common/src/org/tizen/common/preferences/PreferenceMessages.java b/org.tizen.common/src/org/tizen/common/preferences/PreferenceMessages.java new file mode 100644 index 000000000..e095402de --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/preferences/PreferenceMessages.java @@ -0,0 +1,47 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.preferences; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class PreferenceMessages { + + private static final String BUNDLE_NAME = "org.tizen.common.preferences.PreferenceMessages";//$NON-NLS-1$ + + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( BUNDLE_NAME ); + + private PreferenceMessages() { + } + + public static String getString( String key ) { + try { + return RESOURCE_BUNDLE.getString( key ); + } + catch( MissingResourceException e ) { + return '!' + key + '!'; + } + } +} diff --git a/org.tizen.common/src/org/tizen/common/preferences/PreferenceMessages.properties b/org.tizen.common/src/org/tizen/common/preferences/PreferenceMessages.properties new file mode 100644 index 000000000..3609acb77 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/preferences/PreferenceMessages.properties @@ -0,0 +1,6 @@ +TizenPreferencePage.0=General settings for Tizen developement: +TizenPreferencePage.1=SDK Path settings +TizenPreferencePage.2=Location : +TizenPreferencePage.3=SDK Update +TizenPreferencePage.4=Automatically find new updates and notify me + diff --git a/org.tizen.common/src/org/tizen/common/preferences/TizenBasePreferencePage.java b/org.tizen.common/src/org/tizen/common/preferences/TizenBasePreferencePage.java new file mode 100644 index 000000000..c90b83721 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/preferences/TizenBasePreferencePage.java @@ -0,0 +1,125 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ + +package org.tizen.common.preferences; + +import org.eclipse.jface.preference.BooleanFieldEditor; +import org.eclipse.jface.preference.DirectoryFieldEditor; +import org.eclipse.jface.preference.FieldEditorPreferencePage; +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.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; +import org.tizen.common.CommonPlugin; + + +public class TizenBasePreferencePage extends FieldEditorPreferencePage implements + IWorkbenchPreferencePage { + + public final static String TIZENSDK_PATH = CommonPlugin.PLUGIN_ID + ".TizenSDKBasePreferencePage"; //$NON-NLS-1$ + + public static final String KEY_SDKLOCATION = "sdkpath"; //$NON-NLS-1$ + public static final String KEY_SDKUPDATE = "sdkupdate"; //$NON-NLS-1$ + public static final String VALUE_SDKLOCATION_DEFAULT = null;; + public static final boolean VALUE_SDKUPDATE_DEFAULT = true; + + public TizenBasePreferencePage() { + //super(GRID); + setPreferenceStore( CommonPlugin.getDefault().getPreferenceStore() ); + //getPreferenceStore().addPropertyChangeListener( getPropertyChangeListener() ); + setDescription( PreferenceMessages.getString( "TizenPreferencePage.0" ) ); + } + + + @Override + public void init(IWorkbench workbench) { + // TODO Auto-generated method stub + } + + @Override + protected void createFieldEditors() { + // TODO Auto-generated method stub + Composite composite = getFieldEditorParent(); + + GridLayout layout = new GridLayout(); + layout.numColumns = 1; + layout.marginHeight = 0; + layout.marginWidth = 0; + composite.setLayout( layout ); + GridData data = new GridData(GridData.FILL_BOTH); + data.verticalAlignment = GridData.FILL; + data.horizontalAlignment = GridData.FILL; + composite.setLayoutData( data ); + createSpacer( composite, 1 ); + createPathSettingPreferences( composite ); + createSpacer( composite, 1 ); + createUpdateSettingPreferences( composite ); + createSpacer( composite, 1 ); + } + protected void createSpacer( Composite composite, int columnSpan ) { + Label label = new Label( composite, SWT.NONE ); + GridData gd = new GridData(); + gd.horizontalSpan = columnSpan; + label.setLayoutData( gd ); + } + + private void createPathSettingPreferences( Composite parent ) { + Composite comp = createGroup( parent, PreferenceMessages.getString( "TizenPreferencePage.1" ),1 ); //$NON-NLS-1$ + Composite formatComposite = createCompositeEx( comp, 1, GridData.FILL_HORIZONTAL); + DirectoryFieldEditor mDirectoryField = new DirectoryFieldEditor(TizenBasePreferencePage.KEY_SDKLOCATION, PreferenceMessages.getString("TizenPreferencePage.2"), formatComposite); + addField(mDirectoryField); + } + + private void createUpdateSettingPreferences( Composite parent ) { + Composite comp = createGroup( parent, PreferenceMessages.getString( "TizenPreferencePage.3" ),1 ); //$NON-NLS-1$ + Composite formatComposite = createCompositeEx( comp, 1, GridData.FILL_HORIZONTAL); + BooleanFieldEditor startupCheckEditor = new BooleanFieldEditor(TizenBasePreferencePage.KEY_SDKUPDATE, PreferenceMessages.getString("TizenPreferencePage.4"), formatComposite); + addField(startupCheckEditor); + } + + private Composite createCompositeEx(Composite parent, int numColumns, int layoutMode) { + Composite composite = new Composite(parent, SWT.NULL); + composite.setFont(parent.getFont()); + + composite.setLayout(new GridLayout(numColumns, true)); + composite.setLayoutData(new GridData(layoutMode)); + return composite; + } + private Group createGroup(Composite parent, String label, int nColumns) { + Group group = new Group(parent, SWT.NONE); + group.setFont(parent.getFont()); + group.setText(label); + GridLayout layout = new GridLayout(); + layout.numColumns = nColumns; + group.setLayout(layout); + group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + return group; + } +} diff --git a/org.tizen.common/src/org/tizen/common/properties/InstallPathConfig.java b/org.tizen.common/src/org/tizen/common/properties/InstallPathConfig.java new file mode 100644 index 000000000..63f9d44c9 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/properties/InstallPathConfig.java @@ -0,0 +1,137 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ + +package org.tizen.common.properties; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; + +import org.tizen.common.util.DialogUtil; +import org.tizen.common.util.HostUtil; +import org.tizen.common.util.OSChecker; + + + +final public class InstallPathConfig { + + private static String sdkInstallPath; + private final static String SDKSUFFIX = ".TizenSDK"+File.separatorChar+"tizensdkpath"; + private final static String EMULATOR_PATH = "Emulator"; + private final static String INSTALLER_PATH = "InstallManager"; + + // Registry Key + private static final String REGISTRY_PATH_OF_SHELL_FOLDER = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"; + // public static final String REGISTRY_APP_DATA_OF_SHELL_FOLDER = "AppData"; + private static final String REGISTRY_LOCAL_APP_DATA_OF_SHELL_FOLDER = "\"Local AppData\""; + // Value Column + private static final String REG_SZ = "REG_SZ"; + + static { + // FIXME : don't need the following lines if using environment variable + String sdkPath; + + if (OSChecker.isWindows()) { + String appdataPath = getRegistryValue(REGISTRY_PATH_OF_SHELL_FOLDER,REGISTRY_LOCAL_APP_DATA_OF_SHELL_FOLDER) ; + sdkPath = appdataPath + File.separatorChar + SDKSUFFIX; + loadSdkPath(sdkPath); + } else if (OSChecker.isLinux() == true || OSChecker.isUnix() == true || OSChecker.isMAC() == true) { + sdkPath= System.getProperty("user.home") + File.separatorChar + SDKSUFFIX; + loadSdkPath(sdkPath); + } else { + DialogUtil.openMessageDialog(System.getProperty("os.name") + " is not supported currently."); + System.exit(0); + } + } + + public static String getEmulatorPath(){ + return sdkInstallPath + File.separatorChar + EMULATOR_PATH; + } + + public static String getIDEPath() { + // FIXME : can't help but putting the code due to the Web IDE path , It has to be removed soon. + return System.getProperty("user.dir"); + } + + public static String getSDKPath() { + return sdkInstallPath; + } + + public static String getInstallManagerPath() { + return sdkInstallPath + File.separatorChar + INSTALLER_PATH; + } + + private static void loadSdkPath(String sdkPath) { + if (HostUtil.exists(sdkPath)) { + String[] fileContent = HostUtil.getContents(sdkPath).split("="); + if (HostUtil.exists(fileContent[1])) + sdkInstallPath = fileContent[1]; + else { + DialogUtil.openMessageDialog("Tizen SDK is not installed propertly."); + System.exit(0); + } + } else { + DialogUtil.openMessageDialog("Tizen SDK is not installed propertly."); + System.exit(0); + } + } + private static String getRegistryValue(String node, String key) { + if (!OSChecker.isWindows()) + return null; + + BufferedReader br = null; + String value = ""; + + String query = "reg query " + "\"" + node + "\" /v " + key; + try { + Process process = Runtime.getRuntime().exec(query); + String encoding = System.getProperty("sun.jnu.encoding"); + br = new BufferedReader(new InputStreamReader(process.getInputStream(), encoding)); + + String line = null; + while((line = br.readLine()) != null) { + int index = line.indexOf(REG_SZ); + if (index >= 0) { + value = line.substring(index + REG_SZ.length()).trim(); + } + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + return value; + } +}
\ No newline at end of file diff --git a/org.tizen.common/src/org/tizen/common/queue/Queue.java b/org.tizen.common/src/org/tizen/common/queue/Queue.java new file mode 100644 index 000000000..366aba6dd --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/queue/Queue.java @@ -0,0 +1,71 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ + +package org.tizen.common.queue; + +import java.util.concurrent.ConcurrentLinkedQueue; + +public class Queue<T>{ + + private ConcurrentLinkedQueue<T> queue = new ConcurrentLinkedQueue<T>(); + private boolean waiting = false; + + public synchronized void add(T e){ + queue.add(e); + if(waiting) + notify(); + } + + public synchronized T poll(){ + while (isEmpty()) { + try { + waiting = true; + wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + waiting = false; + return queue.poll(); + } + + public synchronized void clear(){ + queue.clear(); + } + + public boolean isEmpty() { + return queue.isEmpty(); + } + + public int size() { + return queue.size(); + } + + public synchronized void stop() { + if (waiting) + notify(); + } + +} diff --git a/org.tizen.common/src/org/tizen/common/swt/ClosableTray.java b/org.tizen.common/src/org/tizen/common/swt/ClosableTray.java new file mode 100644 index 000000000..ec149654f --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/swt/ClosableTray.java @@ -0,0 +1,172 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ + +package org.tizen.common.swt; + +import org.eclipse.jface.action.ContributionItem; +import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.jface.dialogs.DialogTray; +import org.eclipse.jface.dialogs.TrayDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.PaletteData; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; + + +/** + * a extended DialogTray class that user can be closing + * + * @author Jihoon Song {@literal <jihoon80.song@samsung.com>} (S-Core) + */ +public abstract class ClosableTray extends DialogTray { + private Image closeNormal; + private Image closeHover; + private Shell shell; + + private void createImages() { + Display display = Display.getCurrent(); + int[] shape = new int[] { + 3, 3, 5, 3, 7, 5, 8, 5, 10, 3, 12, 3, 12, 5, 10, 7, 10, 8, 12, 10, + 12, 12, 10, 12, 8, 10, 7, 10, 5, 12, 3, 12, 3, 10, 5, 8, 5, 7, 3, 5 + }; + + // create image data + Color border = display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW); + Color background = display.getSystemColor(SWT.COLOR_LIST_BACKGROUND); + Color backgroundHot = new Color(display, new RGB(252, 160, 160)); + Color transparent = display.getSystemColor(SWT.COLOR_MAGENTA); + + PaletteData palette = new PaletteData(new RGB[] { + transparent.getRGB(), border.getRGB(), background.getRGB(), backgroundHot.getRGB() + }); + ImageData data = new ImageData(16, 16, 8, palette); + data.transparentPixel = 0; + + // create close image + closeNormal = new Image(display, data); + closeNormal.setBackground(transparent); + GC gc = new GC(closeNormal); + gc.setBackground(background); + gc.fillPolygon(shape); + gc.setForeground(border); + gc.drawPolygon(shape); + gc.dispose(); + + // create hovered close image + closeHover = new Image(display, data); + closeHover.setBackground(transparent); + gc = new GC(closeHover); + gc.setBackground(backgroundHot); + gc.fillPolygon(shape); + gc.setForeground(border); + gc.drawPolygon(shape); + gc.dispose(); + + backgroundHot.dispose(); + } + + @Override + protected Control createContents(Composite parent) { + shell = parent.getShell(); + + // appearence composite + Composite container = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.marginWidth = layout.marginHeight = 0; + layout.verticalSpacing = 0; + container.setLayout(layout); + container.addListener(SWT.Dispose, new Listener() { + @Override + public void handleEvent(Event event) { + dispose(); + } + }); + + // top toolbar composite + ToolBarManager tbm = new ToolBarManager(SWT.FLAT); + tbm.createControl(container); + GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_END); + gd.grabExcessHorizontalSpace = true; + tbm.getControl().setLayoutData(gd); + + // horizontal separator + Label separator = new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL); + gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + gd.heightHint = 1; + separator.setLayoutData(gd); + + // create external composite + createExternalControl(container); + + // create close button image + createImages(); + + // add close button + tbm.add(new ContributionItem() { + @Override + public void fill(ToolBar parent, int index) { + final ToolItem item = new ToolItem(parent, SWT.PUSH); + item.setImage(closeNormal); + item.setHotImage(closeHover); + item.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event event) { + TrayDialog dialog = (TrayDialog) shell.getData(); + dialog.closeTray(); + shell.setFocus(); + } + }); + } + }); + tbm.update(true); + + return container; + } + + public abstract void createExternalControl(Composite parent); + + protected void dispose() { + if (closeNormal != null) { + closeNormal.dispose(); + } + if (closeHover != null) { + closeHover.dispose(); + } + } +}
\ No newline at end of file diff --git a/org.tizen.common/src/org/tizen/common/swt/PictureLabel.java b/org.tizen.common/src/org/tizen/common/swt/PictureLabel.java new file mode 100644 index 000000000..1cda75f87 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/swt/PictureLabel.java @@ -0,0 +1,206 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+
+package org.tizen.common.swt;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.events.*;
+
+/**
+ * Reference to http://www.eclipse.org/articles/Article-Writing%20Your%20Own%20Widget/Writing%20Your%20Own%20Widget.htm
+ *
+ * @author Jihoon Song {@literal <jihoon80.song@samsung.com>} (S-Core)
+ */
+public class PictureLabel extends Canvas {
+ private Image image;
+ private String text;
+ private boolean selected;
+ private List<ImageClickedListener> imageClickedListeners = new ArrayList<ImageClickedListener>();
+
+ public PictureLabel(Composite parent, int style) {
+ super(parent, style);
+
+ // default background color
+ setBackground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
+
+ // add listener
+ addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {}
+ });
+ addPaintListener(new PaintListener() {
+ public void paintControl(PaintEvent e) {
+ PictureLabel.this.paintControl(e);
+ }
+ });
+ addMouseListener(new MouseAdapter() {
+ public void mouseDown(MouseEvent event) {
+ if (event.button == java.awt.event.MouseEvent.BUTTON1) {
+ PictureLabel.this.mouseDown(event);
+ }
+ }
+ });
+ addMouseTrackListener(new MouseTrackAdapter() {
+ public void mouseEnter(MouseEvent event) {
+ PictureLabel.this.mouseEnter(event);
+ }
+ public void mouseExit(MouseEvent event) {
+ PictureLabel.this.mouseExit(event);
+ }
+ });
+
+ setSelection(false);
+ }
+
+ public void mouseDown(MouseEvent event) {
+ ImageClickedEvent e = new ImageClickedEvent(this, event.x, event.y);
+ setSelection(!selected);
+ for (ImageClickedListener listener : imageClickedListeners) {
+ listener.imageClicked(e);
+ }
+ }
+
+ protected void mouseEnter(MouseEvent event) {
+ setBackground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
+ }
+
+ protected void mouseExit(MouseEvent event) {
+ setBackground(getDisplay().getSystemColor(selected ? SWT.COLOR_GRAY : SWT.COLOR_WHITE));
+ }
+
+ public void setSelection(boolean selected) {
+ this.selected = selected;
+ setBackground(getDisplay().getSystemColor(selected ? SWT.COLOR_GRAY : SWT.COLOR_WHITE));
+ }
+
+ public void addImageClickedListener(ImageClickedListener listener) {
+ imageClickedListeners.add(listener);
+ }
+
+ public void removeImageClickedListener(ImageClickedListener listener) {
+ imageClickedListeners.remove(listener);
+ }
+
+ void paintControl(PaintEvent e) {
+ GC gc = e.gc;
+ int x = 1;
+ int y = 1;
+ int clientAreaWidth = getClientArea().width;
+ int textWidth = gc.stringExtent(text).x;
+ int imageWidth = image.getBounds().width;
+ int imageHeght = image.getBounds().height;
+ int maxWidth = Math.max(Math.max(imageWidth, imageWidth), clientAreaWidth);
+
+ if ((image != null) & (text != null)) {
+ x = 1 + (maxWidth - imageWidth) / 2;
+ gc.drawImage(image, x, y);
+ y = y + imageHeght + 5;
+ x = 1 + (maxWidth - textWidth) / 2;
+ gc.drawText(text, x, y);
+ } else if (image != null) {
+ x = 1 + (maxWidth - imageWidth) / 2;
+ gc.drawImage(image, x, 1);
+ } else if (text != null) {
+ x = 1 + (maxWidth - textWidth) / 2;
+ gc.drawText(text, x, 1);
+ }
+ gc.dispose();
+ }
+
+ public Image getImage() {
+ return image;
+ }
+
+ public void setImage(Image image) {
+ this.image = image;
+ redraw();
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ redraw();
+ }
+
+ public Point computeSize(int wHint, int hHint, boolean changed) {
+ int width = 0;
+ int height = 0;
+ if (image != null && text != null) {
+ GC gc = new GC(this);
+ int textWidth = gc.stringExtent(text).x;
+ int textHeight = gc.stringExtent(text).y;
+ int imageWidth = image.getBounds().width;
+ int imageHeight = image.getBounds().height;
+ gc.dispose();
+ if (imageWidth >= textWidth)
+ width = imageWidth + 2;
+ else
+ width = textWidth + 2;
+ height = textHeight + imageHeight + 7;
+ } else if (image != null) {
+ Rectangle bounds = image.getBounds();
+ width = bounds.width + 2;
+ height = bounds.height + 2;
+ } else if (text != null) {
+ GC gc = new GC(this);
+ Point extent = gc.stringExtent(text);
+ gc.dispose();
+ width = extent.x + 2;
+ height = extent.y + 2;
+ }
+ if (wHint != -1)
+ width = wHint;
+ if (hHint != -1)
+ height = hHint;
+
+ return new Point(width + 2, height + 2);
+ }
+
+ public boolean isSelected() {
+ return selected;
+ }
+}
+
+class ImageClickedEvent extends java.util.EventObject {
+ public int x, y;
+
+ public ImageClickedEvent(Object source, int x, int y) {
+ super(source);
+
+ this.x = x;
+ this.y = y;
+ }
+}
+
+interface ImageClickedListener extends java.util.EventListener {
+ public void imageClicked(ImageClickedEvent event);
+}
diff --git a/org.tizen.common/src/org/tizen/common/swt/TrayWizardPage.java b/org.tizen.common/src/org/tizen/common/swt/TrayWizardPage.java new file mode 100644 index 000000000..c5c328c9f --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/swt/TrayWizardPage.java @@ -0,0 +1,108 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ + +package org.tizen.common.swt; + +import org.eclipse.jface.dialogs.DialogTray; +import org.eclipse.jface.dialogs.TrayDialog; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.wizard.IWizardContainer; +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.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + + +/** + * a extended WizardPage class using ClosableTray class + * + * @author Jihoon Song {@literal <jihoon80.song@samsung.com>} (S-Core) + */ +public abstract class TrayWizardPage extends WizardPage { + + protected TrayWizardPage(String pageName) { + super(pageName); + } + + protected TrayWizardPage(String pageName, String title, ImageDescriptor titleImage) { + super(pageName, title, titleImage); + } + + /** + * a extended WizardPage class using ClosableTray class + * + * @param parent a composite control which will be the parent of the new instance (cannot be null) + * @param buttonText the new text of Button control + * @param tray the ClosableTray to show in dialog + * @return <b>Control</b> - return created Button control + */ + protected Control createTrayButtonControl(Composite parent, String buttonText, final ClosableTray tray) { + Composite child = new Composite(parent, SWT.NONE); + child.setLayout(new GridLayout()); + child.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); + + Button expandButton = new Button(child, SWT.NONE); + expandButton.setText(buttonText); + expandButton.addSelectionListener(new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent e) { + openClosableTray(tray); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + + return expandButton; + } + + /** + * open a tray using ClosableTray class. If another tray was opened, open new tray after close the opened tray automatically + * + * @param tray the ClosableTray to show in dialog + * @return <b>Control</b> - return created Button control + */ + protected void openClosableTray(ClosableTray tray) { + IWizardContainer wc = getContainer(); + if (wc instanceof TrayDialog) { + TrayDialog wd = (TrayDialog) wc; + + // alreay opened + DialogTray currentTray = wd.getTray(); + if (! (currentTray instanceof ClosableTray)) { + if (currentTray != null) { + wd.closeTray(); + } + wd.openTray(tray); + } + } + } +}
\ No newline at end of file diff --git a/org.tizen.common/src/org/tizen/common/util/BrowserWrapper.java b/org.tizen.common/src/org/tizen/common/util/BrowserWrapper.java new file mode 100644 index 000000000..87c370476 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/BrowserWrapper.java @@ -0,0 +1,76 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ + +package org.tizen.common.util; + +import java.io.File; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.browser.Browser; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; + +/** + * @author Adam Kotwasinski, Samsung Electronics, Inc. + */ +public class BrowserWrapper { + private Browser browser; + + public BrowserWrapper(Composite composite) { + browser = new Browser(composite, SWT.NONE); + } + + public BrowserWrapper(Composite composite, GridData data) { + this(composite, data, SWT.NONE); + } + + public BrowserWrapper(Composite composite, GridData data, int style) { + browser = new Browser(composite, style); + browser.setLayoutData(data); + } + + public void setInput(final File f) { + browser.getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + if (!browser.isDisposed()) { + browser.setUrl(f.getAbsolutePath()); + } + } + } ); + } + + public void setText(String html) { + browser.setText(html); + } + + public void setFocus() { + browser.setFocus(); + } + + public Browser getBrowser() { + return browser; + } +} diff --git a/org.tizen.common/src/org/tizen/common/util/ControlFileConfig.java b/org.tizen.common/src/org/tizen/common/util/ControlFileConfig.java new file mode 100644 index 000000000..c0cb6f545 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/ControlFileConfig.java @@ -0,0 +1,87 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ + +package org.tizen.common.util; + +import java.io.File; +import java.util.Properties; + + +public class ControlFileConfig { + private String path; + private boolean isExist; + private Properties props; + + public ControlFileConfig(String path){ + this.path = path; + if(HostUtil.exists(path)){ + this.isExist = true; + this.props = PropertyUtil.loadProperties(path); + }else{ + this.props = new Properties(); + } + } + + public String getPath(){ + return this.path; + } + + public boolean exists(){ + return isExist; + } + + public String getValue(String key){ + return props.getProperty(key); + } + + public String getValue(String key, String defaultValue){ + return props.getProperty(key, defaultValue); + } + + public boolean getValue(String key, boolean defaultValue){ + String value = props.getProperty(key, Boolean.toString(defaultValue)); + return Boolean.parseBoolean(value); + } + + public void setValue(String key, String value){ + props.setProperty(key, value); + } + + public void setValue(String key, boolean value){ + props.setProperty(key, Boolean.toString(value)); + } + + public boolean store(){ + File folder = new File(this.path).getParentFile(); + if(folder==null||!folder.exists()) + folder.mkdirs(); + + this.isExist = PropertyUtil.storeProperties(path, props); + return this.isExist; + } + + + +}
\ No newline at end of file diff --git a/org.tizen.common/src/org/tizen/common/util/DialogUtil.java b/org.tizen.common/src/org/tizen/common/util/DialogUtil.java new file mode 100644 index 000000000..3335ba125 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/DialogUtil.java @@ -0,0 +1,120 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ + +package org.tizen.common.util; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Shell; + +public abstract class DialogUtil { + /** + * Open message dialog and show a message + * + * @param message + * a message that is shown in message dialog. + * @return none + * @exception none + */ + public static void openMessageDialog(String message) { + openMessageDialog(new Shell(), message); + } + + public static void openMessageDialog(final Shell shell, final String message) { + openMessageDialog(shell, "Info", message); + } + + public static void openMessageDialog(final Shell shell, final String title, final String message) { + Display.getDefault().syncExec(new Runnable() { + public void run() { + MessageBox dialog = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION); + dialog.setText(title); + dialog.setMessage(message); + dialog.open(); + } + }); + } + + public static void openProxyDialog(final String text, String message) { + final String msg = message; + Display.getDefault().syncExec(new Runnable() { + public void run() { + MessageBox dialog = new MessageBox(new Shell(), SWT.ERROR | SWT.ICON_INFORMATION); + dialog.setText(text); + dialog.setMessage(msg); + dialog.open(); + } + }); + } + + /** + * Open error message dialog and show a error message + * + * @param message + * a error message that is shown in error message dialog. + * @return none + * @exception none + */ + public static void openErrorDialog(String message) { + openErrorDialog(new Shell(), "Error", message); + } + + public static void openErrorDialog(final Shell shell, final String title, final String message) { + Display.getDefault().syncExec(new Runnable() { + public void run() { + MessageBox dialog = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR); + dialog.setText(title); + dialog.setMessage(message); + dialog.open(); + } + }); + } + + /** + * Open question dialog and return the selection of user. + * + * @param message + * a message that is shown in question dialog. + * @return int if user select 'yes', return SWT.YES. if user select 'no', + * return SWT.NO. + */ + protected static int retValue = 0; + private final static Object lockQuestion = new Object(); + public static int openQuestionDialog(String message) { + synchronized (lockQuestion) { + final String msg = message; + Display.getDefault().syncExec(new Runnable() { + public void run() { + MessageBox dialog = new MessageBox(new Shell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION); + dialog.setMessage(msg); + retValue = dialog.open(); + } + }); + + return retValue; + } + } +} diff --git a/org.tizen.common/src/org/tizen/common/util/FileUtil.java b/org.tizen.common/src/org/tizen/common/util/FileUtil.java new file mode 100644 index 000000000..d778247af --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/FileUtil.java @@ -0,0 +1,187 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.util; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.net.URI; + +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileSystem; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; + + +/** + * @author Changhyun Lee {@literal <changhyun1.lee@samsung.com>} (S-Core) + */ +public class FileUtil { + public static final String UTF_8 = "UTF-8"; //$NON-NLS-1$ + + private static final int BUFFER_SIZE = 8192; + + /** + * write text into given file + */ + public static void writeTextFile(File file, String text, String encoding) throws IOException { + BufferedWriter out = null; + + if (encoding == null) { // if encoding is not set then use default encoding + encoding = System.getProperty("file.encoding"); + } + + try { + out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), encoding), BUFFER_SIZE); + out.write(text.toCharArray(), 0, text.length()); + out.flush(); + } finally { + if (out != null) { + out.close(); + } + } + } + + /** + * read text from given file + */ + public static String readTextFile(File file, String encoding) throws IOException { + StringBuilder text = new StringBuilder(); + char[] buffer = new char[BUFFER_SIZE]; + BufferedReader in = null; + + if (encoding == null) { // if encoding is not set then use default encoding + encoding = System.getProperty("file.encoding"); + } + + try { + in = new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding), BUFFER_SIZE); + int nRead = 0; + while ((nRead = in.read(buffer, 0, buffer.length)) > 0) { + text.append(buffer, 0, nRead); + } + } finally { + if (in != null) { + in.close(); + } + } + + return text.toString(); + } + + /** + * return file extension from given full file name + * + * @author Jihoon Song {@literal <jihoon80.song@samsung.com>} (S-Core) + */ + public static String getFileExtension(String fullName) { + if (fullName == null) { + return null; + } + + int k = fullName.lastIndexOf("."); + + return (k != -1) ? fullName.substring(k + 1, fullName.length()) : null; + } + + /** + * return file name without file extension from given full file name + * + * @author Jihoon Song {@literal <jihoon80.song@samsung.com>} (S-Core) + */ + public static String getFileNameWithoutExtension(String fullName) { + if (fullName == null) { + return null; + } + + int k = fullName.lastIndexOf("."); + + return (k != -1) ? fullName.substring(0, k) : fullName; + } + + /** + * delete file and its children. + * + * @author Jihoon Song {@literal <jihoon80.song@samsung.com>} (S-Core) + */ + public static boolean recursiveDelete(File file) { + boolean result = true; + + if (file == null) { + return false; + } + + // delete child + if (file.isDirectory()) { + File[] children = file.listFiles(); + for (File child : children) { + result &= recursiveDelete(child); + } + } + + // delete self + result &= file.delete(); + + return result; + } + + /** + * copy file or directory using Eclipse File System + * + * @param source The source URI of the copy. + * @param destination The destination URI of the copy. + * @param options bit-wise or of option flag constants ({@link EFS#OVERWRITE} or {@link EFS#SHALLOW}). + * @param monitor a progress monitor, or <code>null</code> if progress reporting and cancellation are not desired + * + * @author Jihoon Song {@literal <jihoon80.song@samsung.com>} (S-Core) + */ + public static void copyUsingEFS(URI source, URI destination, int options, IProgressMonitor monitor) throws CoreException { + IFileSystem fileSystem = EFS.getLocalFileSystem(); + fileSystem.getStore(source).copy(fileSystem.getStore(destination), options, monitor); + } + + /** + * redirect input stream to output stream + */ + public static void redirectStream(InputStream is, OutputStream os) throws IOException { + byte[] buffer = new byte[BUFFER_SIZE]; + BufferedInputStream bin = new BufferedInputStream(is, BUFFER_SIZE); + BufferedOutputStream bout = new BufferedOutputStream(os, BUFFER_SIZE); + int n = 0; + while ((n = bin.read(buffer, 0, buffer.length)) >= 0) { + bout.write(buffer, 0, n); + } + bout.flush(); + } +} diff --git a/org.tizen.common/src/org/tizen/common/util/HostUtil.java b/org.tizen.common/src/org/tizen/common/util/HostUtil.java new file mode 100644 index 000000000..4e2330fc6 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/HostUtil.java @@ -0,0 +1,330 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.util; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.InetAddress; +import java.nio.channels.FileChannel; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; + +public abstract class HostUtil{ + +// public static final String USER = System.getenv("USER"); +// public static final String USER_HOME = System.getenv("HOME"); + public static final String LINE_SEPARATOR = System.getProperty("line.separator"); //$NON-NLS-1$ + public static final String FILE_SEPARATOR = System.getProperty("file.separator"); //$NON-NLS-1$ + + private static final String PROC_PATH = "/proc"; //$NON-NLS-1$ + private static final String SHELL_COMMAND_LINUX= "/bin/sh"; //$NON-NLS-1$ + private static final String SHELL_COMMAND_WINDOW= "cmd"; //$NON-NLS-1$ + + public static boolean hasProcFile(String pid) { + if(pid==null||pid.equals("")) //$NON-NLS-1$ + return false; + + String pidFile = PROC_PATH+Path.SEPARATOR+pid; + return exists(pidFile); + } + public static boolean isMenuReady(String pid) { + if(pid==null||pid.equals("")) //$NON-NLS-1$ + return false; + + String pidFile = PROC_PATH+Path.SEPARATOR+pid; + return exists(pidFile); + } + + + public static String getContents(String filePath) { + BufferedReader input = null; + StringBuilder contents = new StringBuilder(); + String line = null; + + try { + input = new BufferedReader(new FileReader(filePath)); + while((line=input.readLine())!=null){ + contents.append(line); + contents.append(LINE_SEPARATOR); + } + }catch(Exception e) { +// e.printStackTrace(); + return null; + }finally{ + if(input!=null) + try { + input.close(); + } catch (IOException e) { + } + } + + return contents.toString().trim(); + } + + public static boolean isReachable(String ip) { + try { + return InetAddress.getByName(ip).isReachable(100); + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + public static boolean exists(String path) { + if(path==null||path.equals("")) //$NON-NLS-1$ + return false; + + IPath ipath = new Path(path); + File file = ipath.toFile(); + + if(file!=null&&file.exists()) + return true; + else + return false; + } + + public static boolean execute(String command){ + Process proc = null; + Runtime runtime = Runtime.getRuntime(); + + String[] fullCommand = getCommand(command); + + int i = 0; + try { + proc= runtime.exec(fullCommand); + i = proc.waitFor(); + } catch (Exception e) { + e.printStackTrace(); + return false; + } finally{ + System.out.println("HostUtil execute - exit value : " + i); + if(proc!=null) + proc.destroy(); + } + + return i==0; + } + + public static boolean batchExecute(String command) + { + String[] fullCommand = getCommand(command); + + Runtime run = Runtime.getRuntime(); + Process p = null; + + try{ + p = run.exec(fullCommand); + StreamGobbler gb1 = new StreamGobbler(p.getInputStream()); + StreamGobbler gb2 = new StreamGobbler(p.getErrorStream()); + gb1.start(); + gb2.start(); + }catch(Exception e){ + e.printStackTrace(); + return false; + }finally{ + } + return true; + } + + /** + * Don't need for emultor install registration. + * using java.lang.Runtime.exec(String[] cmdarray, String[] envp, File dir) + * @param command - array containing the command to call and its arguments. + * @param envp - array of strings, each element of which has environment variable settings in format name=value. + * @param dir - Emultor path. + * @return success true, failed false. + */ + public static boolean batchExecute(String command, String[] envp, File dir) + { + String[] fullCommand = getCommand(command); + + Runtime run = Runtime.getRuntime(); + Process p = null; + + StreamGobbler gb1 = null; + StreamGobbler gb2 = null; + try{ + p = run.exec(fullCommand, envp, dir); + gb1 = new StreamGobbler(p.getInputStream()); + gb2 = new StreamGobbler(p.getErrorStream()); + gb1.start(); + gb2.start(); + }catch(Exception e){ + e.printStackTrace(); + return false; + }finally{ + System.out.println(gb1.getResult()); + System.out.println(gb2.getResult()); + } + return true; + } + + public static String returnExecute(String command, String workingDir) { + BufferedReader input = null; + StringBuilder contents = new StringBuilder(); + String line = null; + + Process proc = null; + + String[] fullCommand = getCommand(command); + + try { + ProcessBuilder pb = new ProcessBuilder(); + pb.command(fullCommand); + if(workingDir != null) { + pb.directory(new File(workingDir)); + } + proc = pb.start(); + input = new BufferedReader(new InputStreamReader(proc.getInputStream())); + while((line=input.readLine())!=null){ + contents.append(line); + contents.append(LINE_SEPARATOR); + } + } catch (Exception e) { + e.printStackTrace(); + return null; + } finally{ + if(proc!=null) + proc.destroy(); + if(input!=null) + try { + input.close(); + } catch (IOException e) { + } + } + + return contents.toString().trim(); + + } + public static String returnExecute(String command){ + + return returnExecute(command, null); + } + + public static String[] getCommand(String command){ + if(isLinux()){ + return new String[]{SHELL_COMMAND_LINUX,"-c",command}; //$NON-NLS-1$ + }else{ + return new String[]{SHELL_COMMAND_WINDOW,"/c",command}; //$NON-NLS-1$ + } + } + + + public static boolean createFile(String path, String contents) { + BufferedWriter output = null; + try { + File file = new File(path); + + File folder = file.getParentFile(); + if(folder!=null) + folder.mkdirs(); + + file.createNewFile(); + + output = new BufferedWriter(new FileWriter(file)); + output.write(contents); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + }finally{ + if(output!=null) + try { + output.close(); + } catch (IOException e) { + } + } + } + + public static boolean removeFile(String path) { + File file = new File(path); + if (!file.exists()) + return false; + return file.delete(); + } + + public static boolean copyFile(String src, String des) throws Exception { + boolean canExecute = false; + File srcFile=new File(src); + File desFile=null; + FileInputStream fis=null; + FileOutputStream fos=null; + FileChannel fcin=null; + FileChannel fcout=null; + + canExecute = srcFile.canExecute(); + + desFile= new File(des); + File paths = new File(desFile.getAbsolutePath().substring(0, desFile.getAbsolutePath().lastIndexOf("/"))); //$NON-NLS-1$ + if (!paths.exists()) { + paths.mkdirs(); + } + + try { + fis= new FileInputStream(srcFile); + fos= new FileOutputStream(desFile); + fcin= fis.getChannel(); + fcout= fos.getChannel(); + + long size= fcin.size(); + fcin.transferTo(0, size, fcout); + desFile.setExecutable(canExecute); + } catch (FileNotFoundException e) { + e.printStackTrace(); + throw e; + } catch (IOException e) { + e.printStackTrace(); + throw e; + }finally{ + try { + fcout.close(); + fcin.close(); + fos.close(); + fis.close(); + } catch (IOException e) { + e.printStackTrace(); + throw e; + } + } + + return true; + } + + public static boolean isLinux(){ + return Platform.getOS().equals(Platform.OS_LINUX); + } +} + + diff --git a/org.tizen.common/src/org/tizen/common/util/IOUtil.java b/org.tizen.common/src/org/tizen/common/util/IOUtil.java new file mode 100644 index 000000000..0dce62006 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/IOUtil.java @@ -0,0 +1,48 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.util; + +import java.io.Closeable; +import java.io.IOException; + +/** + * IOUtil + * @author Hyeongseok Heo {@literal<hyeongseok.heo@samsung.com>} + * @since Dec 9, 2011 + */ +public class IOUtil { + + public static void close(Closeable closable) { + if( null != closable) { + try { + closable.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + +} diff --git a/org.tizen.common/src/org/tizen/common/util/ImageUtils.java b/org.tizen.common/src/org/tizen/common/util/ImageUtils.java new file mode 100644 index 000000000..c22fd7828 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/ImageUtils.java @@ -0,0 +1,82 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.util; + +import java.net.URL; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Plugin; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; + + +public class ImageUtils { + // get ImageDescriptor from Plugin ID (ID -> ImageDescriptor) + public static ImageDescriptor getImageDescriptor(String pluginID, String filePath) { + URL url = Platform.getBundle(pluginID).getEntry(filePath); + return ImageDescriptor.createFromURL(url); + } + + // get ImageDescriptor from Activator Plugin (Activator -> ImageDescriptor) + public static ImageDescriptor getImageDescriptor(Plugin plugin, String filePath) { + URL url = plugin.getBundle().getEntry(filePath); // $NON-NLS-1$ + return ImageDescriptor.createFromURL(url); + } + + // get Image from ImageDescriptor (ImageDescriptor -> Image) + public static Image getImage(ImageDescriptor descriptor) { + return (descriptor != null) ? descriptor.createImage() : null; + } + + // get ImageData from ImageDescriptor (ImageDescriptor -> ImageData) + public static ImageData getImageData(ImageDescriptor descriptor) { + return (descriptor != null) ? descriptor.getImageData() : null; + } + + // get Image from Activator Plugin (Activator -> ImageDescriptor -> Image) + public static Image getImage(Plugin plugin, String filePath) { + ImageDescriptor descriptor = getImageDescriptor(plugin, filePath); + return getImage(descriptor); + } + + // get ImageData from Activator Plugin (Activator -> ImageDescriptor -> ImageData) + public static ImageData getImageData(Plugin plugin, String filePath) { + ImageDescriptor descriptor = getImageDescriptor(plugin, filePath); + return getImageData(descriptor); + } + + // get Image from Plugin ID (ID -> ImageDescriptor -> Image) + public static Image getImage(String pluginID, String filePath) { + ImageDescriptor descriptor = getImageDescriptor(pluginID, filePath); + return getImage(descriptor); + } + + // get Image from Plugin ID (ID -> ImageDescriptor -> ImageData) + public static ImageData getImageData(String pluginID, String filePath) { + ImageDescriptor descriptor = getImageDescriptor(pluginID, filePath); + return getImageData(descriptor); + } +}
\ No newline at end of file diff --git a/org.tizen.common/src/org/tizen/common/util/LocalPortChecker.java b/org.tizen.common/src/org/tizen/common/util/LocalPortChecker.java new file mode 100644 index 000000000..68c3337ed --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/LocalPortChecker.java @@ -0,0 +1,82 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.util; + +import java.io.IOException; +import java.net.ServerSocket; + +/** + * @author Joogwan Kim {@literal <joogwan.kim@samsung.com>} (S-Core) + * <ul> + * <li> initial creation + * <li> added isPortAvailable method. + * </ul> + * @author Gyeongseok Seo {@literal <gyeongseok.seo@samsung.com>} (S-Core) + * <ul> + * <li> added getAvailableLocalPort method. + * </ul> + */ +public class LocalPortChecker { + public static boolean isPortAvailable(int port) { + if ((port < 0) && (port > 65535)) + return false; + + ServerSocket socket = null; + try { + socket = new ServerSocket(port); + return true; + } catch (IOException e) { + return false; + } finally { + if (socket != null) { + try { + socket.close(); + } catch (IOException e) { + // do nothing + } + } + } + } + + public static int getAvailableLocalPort(int inc,int portBase) { + int port = portBase; + if (isPortAvailable(port)) { + return port; + } + + if ( (port+inc) > 65535) { + return -1; + } + + while ((port < 65535) && !isPortAvailable(port)) { + port += inc; + } + + if (isPortAvailable(port)) + return port; + else + return -1; + } +} diff --git a/org.tizen.common/src/org/tizen/common/util/NotificationType.java b/org.tizen.common/src/org/tizen/common/util/NotificationType.java new file mode 100644 index 000000000..37a6a9009 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/NotificationType.java @@ -0,0 +1,56 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+package org.tizen.common.util;
+
+import org.eclipse.swt.graphics.Image;
+import org.tizen.common.cache.ImageCache;
+
+
+public enum NotificationType {
+ ERROR(ImageCache.getImage("error.png")),
+ DELETE(ImageCache.getImage("delete.png")),
+ WARN(ImageCache.getImage("warn.png")),
+ SUCCESS(ImageCache.getImage("ok.png")),
+ INFO(ImageCache.getImage("info.png")),
+ LIBRARY(ImageCache.getImage("library.png")),
+ HINT(ImageCache.getImage("hint.png")),
+ PRINTED(ImageCache.getImage("printer.png")),
+ CONNECTION_TERMINATED(ImageCache.getImage("terminated.png")),
+ CONNECTION_FAILED(ImageCache.getImage("connecting.png")),
+ CONNECTED(ImageCache.getImage("connected.png")),
+ DISCONNECTED(ImageCache.getImage("disconnected.png")),
+ TRANSACTION_OK(ImageCache.getImage("ok.png")),
+ TRANSACTION_FAIL(ImageCache.getImage("error.png"));
+
+ private Image _image;
+
+ private NotificationType(Image img) {
+ _image = img;
+ }
+
+ public Image getImage() {
+ return _image;
+ }
+}
diff --git a/org.tizen.common/src/org/tizen/common/util/NotifierDialog.java b/org.tizen.common/src/org/tizen/common/util/NotifierDialog.java new file mode 100644 index 000000000..f76858cf7 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/NotifierDialog.java @@ -0,0 +1,316 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+package org.tizen.common.util;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CLabel;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FillLayout;
+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.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.tizen.common.cache.ColorCache;
+import org.tizen.common.cache.FontCache;
+
+
+public class NotifierDialog {
+
+ // how long the the tray popup is displayed after fading in (in milliseconds)
+ private static final int DISPLAY_TIME = 4500;
+ // how long each tick is when fading in (in ms)
+ private static final int FADE_TIMER = 50;
+ // how long each tick is when fading out (in ms)
+ private static final int FADE_IN_STEP = 30;
+ // how many tick steps we use when fading out
+ private static final int FADE_OUT_STEP = 8;
+
+ // how high the alpha value is when we have finished fading in
+ private static final int FINAL_ALPHA = 225;
+
+ // title foreground color
+ private static Color _titleFgColor = ColorCache.getColor(40, 73, 97);
+ // text foreground color
+ private static Color _fgColor = _titleFgColor;
+
+ // shell gradient background color - top
+ private static Color _bgFgGradient = ColorCache.getColor(226, 239, 249);
+ // shell gradient background color - bottom
+ private static Color _bgBgGradient = ColorCache.getColor(177, 211, 243);
+ // shell border color
+ private static Color _borderColor = ColorCache.getColor(40, 73, 97);
+
+ // contains list of all active popup shells
+ private static List<Shell> _activeShells = new ArrayList<Shell>();
+
+ // image used when drawing
+ private static Image _oldImage;
+
+ private static Shell _shell;
+
+ /**
+ * Creates and shows a notification dialog with a specific title, message and a
+ *
+ * @param title
+ * @param message
+ * @param type
+ */
+ public static void notify(String title, String message, NotificationType type) {
+ _shell = new Shell(Display.getDefault().getActiveShell(), SWT.NO_FOCUS | SWT.NO_TRIM);
+ _shell.setLayout(new FillLayout());
+ _shell.setForeground(_fgColor);
+ _shell.setBackgroundMode(SWT.INHERIT_DEFAULT);
+ _shell.addListener(SWT.Dispose, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ _activeShells.remove(_shell);
+ }
+ });
+
+ final Composite inner = new Composite(_shell, SWT.NONE);
+
+ GridLayout gl = new GridLayout(2, false);
+ gl.marginLeft = 5;
+ gl.marginTop = 0;
+ gl.marginRight = 5;
+ gl.marginBottom = 5;
+
+ inner.setLayout(gl);
+ _shell.addListener(SWT.Resize, new Listener() {
+
+ @Override
+ public void handleEvent(Event e) {
+ try {
+ // get the size of the drawing area
+ Rectangle rect = _shell.getClientArea();
+ // create a new image with that size
+ Image newImage = new Image(Display.getDefault(), Math.max(1, rect.width), rect.height);
+ // create a GC object we can use to draw with
+ GC gc = new GC(newImage);
+
+ // fill background
+ gc.setForeground(_bgFgGradient);
+ gc.setBackground(_bgBgGradient);
+ gc.fillGradientRectangle(rect.x, rect.y, rect.width, rect.height, true);
+
+ // draw shell edge
+ gc.setLineWidth(2);
+ gc.setForeground(_borderColor);
+ gc.drawRectangle(rect.x + 1, rect.y + 1, rect.width - 2, rect.height - 2);
+ // remember to dipose the GC object!
+ gc.dispose();
+
+ // now set the background image on the shell
+ _shell.setBackgroundImage(newImage);
+
+ // remember/dispose old used iamge
+ if (_oldImage != null) {
+ _oldImage.dispose();
+ }
+ _oldImage = newImage;
+ } catch (Exception err) {
+ err.printStackTrace();
+ }
+ }
+ });
+
+ GC gc = new GC(_shell);
+
+ String lines[] = message.split("\n");
+ Point longest = null;
+ int typicalHeight = gc.stringExtent("X").y;
+
+ for (String line : lines) {
+ Point extent = gc.stringExtent(line);
+ if (longest == null) {
+ longest = extent;
+ continue;
+ }
+
+ if (extent.x > longest.x) {
+ longest = extent;
+ }
+ }
+ gc.dispose();
+
+ int minHeight = typicalHeight * lines.length;
+
+ CLabel imgLabel = new CLabel(inner, SWT.NONE);
+ imgLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_BEGINNING));
+ imgLabel.setImage(type.getImage());
+
+ CLabel titleLabel = new CLabel(inner, SWT.NONE);
+ titleLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER));
+ titleLabel.setText(title);
+ titleLabel.setForeground(_titleFgColor);
+ Font f = titleLabel.getFont();
+ FontData fd = f.getFontData()[0];
+ fd.setStyle(SWT.BOLD);
+ fd.height = 11;
+ titleLabel.setFont(FontCache.getFont(fd));
+
+ Label text = new Label(inner, SWT.WRAP);
+ Font tf = text.getFont();
+ FontData tfd = tf.getFontData()[0];
+ tfd.setStyle(SWT.BOLD);
+ tfd.height = 8;
+ text.setFont(FontCache.getFont(tfd));
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ gd.horizontalSpan = 2;
+ text.setLayoutData(gd);
+ text.setForeground(_fgColor);
+ text.setText(message);
+
+ minHeight = 100;
+
+ _shell.setSize(350, minHeight);
+
+ if (Display.getDefault().getActiveShell() == null || Display.getDefault().getActiveShell().getMonitor() == null) { return; }
+
+ Rectangle clientArea = Display.getDefault().getActiveShell().getMonitor().getClientArea();
+
+ int startX = clientArea.x + clientArea.width - 352;
+ int startY = clientArea.y + clientArea.height - 102;
+
+ // move other shells up
+ if (!_activeShells.isEmpty()) {
+ List<Shell> modifiable = new ArrayList<Shell>(_activeShells);
+ Collections.reverse(modifiable);
+ for (Shell shell : modifiable) {
+ Point curLoc = shell.getLocation();
+ shell.setLocation(curLoc.x, curLoc.y - 100);
+ if (curLoc.y - 100 < 0) {
+ _activeShells.remove(shell);
+ shell.dispose();
+ }
+ }
+ }
+
+ _shell.setLocation(startX, startY);
+ _shell.setAlpha(0);
+ _shell.setVisible(true);
+
+ _activeShells.add(_shell);
+
+ fadeIn(_shell);
+ }
+
+ private static void fadeIn(final Shell _shell) {
+ Runnable run = new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ if (_shell == null || _shell.isDisposed()) { return; }
+
+ int cur = _shell.getAlpha();
+ cur += FADE_IN_STEP;
+
+ if (cur > FINAL_ALPHA) {
+ _shell.setAlpha(FINAL_ALPHA);
+ startTimer(_shell);
+ return;
+ }
+
+ _shell.setAlpha(cur);
+ Display.getDefault().timerExec(FADE_TIMER, this);
+ } catch (Exception err) {
+ err.printStackTrace();
+ }
+ }
+
+ };
+ Display.getDefault().timerExec(FADE_TIMER, run);
+ }
+
+ private static void startTimer(final Shell _shell) {
+ Runnable run = new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ if (_shell == null || _shell.isDisposed()) { return; }
+
+ fadeOut(_shell);
+ } catch (Exception err) {
+ err.printStackTrace();
+ }
+ }
+
+ };
+ Display.getDefault().timerExec(DISPLAY_TIME, run);
+
+ }
+
+ private static void fadeOut(final Shell _shell) {
+ final Runnable run = new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ if (_shell == null || _shell.isDisposed()) { return; }
+
+ int cur = _shell.getAlpha();
+ cur -= FADE_OUT_STEP;
+
+ if (cur <= 0) {
+ _shell.setAlpha(0);
+ if (_oldImage != null) {
+ _oldImage.dispose();
+ }
+ _shell.dispose();
+ _activeShells.remove(_shell);
+ return;
+ }
+
+ _shell.setAlpha(cur);
+
+ Display.getDefault().timerExec(FADE_TIMER, this);
+
+ } catch (Exception err) {
+ err.printStackTrace();
+ }
+ }
+
+ };
+ Display.getDefault().timerExec(FADE_TIMER, run);
+
+ }
+
+}
diff --git a/org.tizen.common/src/org/tizen/common/util/OSChecker.java b/org.tizen.common/src/org/tizen/common/util/OSChecker.java new file mode 100644 index 000000000..3331a46ac --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/OSChecker.java @@ -0,0 +1,160 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.util; + +/** + * @author Changhyun Lee {@literal <changhyun1.lee@samsung.com>} (S-Core) + * <ul> + * <li> initial creation + * <li> thanks to Yoon Kyung Koo + * </ul> + */ +public class OSChecker { + // + // OS ID constants + // + public final static int WINDOWS = 0x0001; + public final static int MAC = 0x0002; + public final static int LINUX = 0x0004; + public final static int UNIX = 0x0008; + public final static int AIX = 0x0010; + public final static int SOLARIS = 0x0020; + + // + // Vendor constants + // + public final static int SUN = 0x0001; + public final static int MICROSOFT = 0x0002; + public final static int APPLE = 0x0004; + public final static int IBM = 0x0008; + + static int osID = 0; + static int vendorID = 0; + + /* static initializer */ + static { + /* + * OS : arch name version + * solaris 7 : sparc Solaris 2.x + * redhat 6.2(black) : x86 Linux 2.2.15-2.5.0 + * redhat 6.2(ibm) : i686 Linux #1 Sat Feb 5 00:28:02 EST 2000.2.2.15-2.5.0 + * win2000(jdk1.1.8) : x86 Windows NT 5.0 + * win2000(jdk1.2.2) : x86 Windows NT 5.0 + * win2000(jdk1.3) : x86 Windows 2000 5.0 + * Mac OS 9 : PowerPC Mac OS 9 + * AIX 5.1 : ppc AIX 5.1 (vendor : IBM Corporation) + */ + osID = 0; + String osName = System.getProperty("os.name").toUpperCase(); + + if (osName.indexOf("WINDOWS") >= 0) { + osID |= OSChecker.WINDOWS; + } else if (osName.indexOf("MAC") >= 0) { + osID |= OSChecker.MAC; + } else if (osName.indexOf("LINUX") >= 0) { + osID |= OSChecker.LINUX; + } else if (osName.indexOf("AIX") >= 0) { + osID |= OSChecker.AIX; + osID |= OSChecker.UNIX; + } else if (osName.indexOf("SOLARIS") >= 0) { + osID |= OSChecker.SOLARIS; + osID |= OSChecker.UNIX; + } + + vendorID = 0; + String vendorName = System.getProperty("java.vendor").toUpperCase(); + + if (vendorName.indexOf("IBM") >= 0) { + vendorID |= OSChecker.IBM; + } else if (vendorName.indexOf("MICROSOFT") >= 0) { + vendorID |= OSChecker.MICROSOFT; + } else if (vendorName.indexOf("APPLE") >= 0) { + vendorID |= OSChecker.APPLE; + } else if (vendorName.indexOf("SUN") >= 0) { + // should check if the vendor is sun in last place + // 'cause other vendor can port Sun's VM + vendorID |= OSChecker.SUN; + } + } + + /* querying OS */ + public static int getOSID() { + return osID; + } + + public static boolean isWindows() { + return ((osID & OSChecker.WINDOWS) > 0); + } + + public static boolean isMAC() { + return ((osID & OSChecker.MAC) > 0); + } + + public static boolean isLinux() { + return ((osID & OSChecker.LINUX) > 0); + } + + public static boolean isAIX() { + return ((osID & OSChecker.AIX) > 0); + } + + public static boolean isSolaris() { + return ((osID & OSChecker.SOLARIS) > 0); + } + + public static boolean isUnix() { + return ((osID & OSChecker.UNIX) > 0); + } + + public static boolean isUnknownOS() { + return (osID == 0); + } + + /* querying Vendor */ + public static int getVendorID() { + return vendorID; + } + + public static boolean byMicrosoft() { + return ((vendorID & OSChecker.MICROSOFT) > 0); + } + + public static boolean byIBM() { + return ((vendorID & OSChecker.IBM) > 0); + } + + public static boolean byApple() { + return ((vendorID & OSChecker.APPLE) > 0); + } + + public static boolean bySun() { + return ((vendorID & OSChecker.SUN) > 0); + } + + public static boolean byUnknownVendor() { + return (vendorID == 0); + } + +} diff --git a/org.tizen.common/src/org/tizen/common/util/OpenBrowserUtil.java b/org.tizen.common/src/org/tizen/common/util/OpenBrowserUtil.java new file mode 100644 index 000000000..c1123ea78 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/OpenBrowserUtil.java @@ -0,0 +1,101 @@ +/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+*
+* 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+package org.tizen.common.util;
+
+import java.net.URL;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.custom.BusyIndicator;
+import org.eclipse.swt.widgets.Display;
+
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.browser.IWebBrowser;
+import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
+
+public class OpenBrowserUtil {
+
+ /**
+ * Opens the given url in the browser as choosen in the preferences.
+ *
+ * @param url the URL
+ * @param display the display
+ * @since 3.6
+ */
+ public static void open(final URL url, Display display) {
+ display.syncExec(new Runnable() {
+ public void run() {
+ internalOpen(url, false);
+ }
+ });
+ }
+
+ /**
+ * Opens the given URL in an external browser.
+ *
+ * @param url the URL
+ * @param display the display
+ * @since 3.6
+ */
+ public static void openExternal(final URL url, Display display) {
+ display.syncExec(new Runnable() {
+ public void run() {
+ internalOpen(url, true);
+ }
+ });
+ }
+
+ private static void internalOpen(final URL url, final boolean useExternalBrowser) {
+ BusyIndicator.showWhile(null, new Runnable() {
+ public void run() {
+ //URL helpSystemUrl= PlatformUI.getWorkbench().getHelpSystem().resolve(url.toExternalForm(), true);
+ try {
+ IWorkbenchBrowserSupport browserSupport= PlatformUI.getWorkbench().getBrowserSupport();
+ IWebBrowser browser;
+ if (useExternalBrowser)
+ browser= browserSupport.getExternalBrowser();
+ else
+ browser= browserSupport.createBrowser(null);
+ browser.openURL(url);
+ } catch (PartInitException ex) {
+ MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error", "Opening url failed: " + ex.getMessage());
+ }
+ }
+ });
+ }
+
+ /**
+ * DO NOT REMOVE, used in a product.
+ *
+ * @param url the URL
+ * @param display the display
+ * @param title the title
+ * @deprecated As of 3.6, replaced by {@link #open(URL, Display)}
+ */
+ public static void open(final URL url, Display display, String title) {
+ open(url, display);
+ }
+
+}
diff --git a/org.tizen.common/src/org/tizen/common/util/ProcessMonitorThread.java b/org.tizen.common/src/org/tizen/common/util/ProcessMonitorThread.java new file mode 100644 index 000000000..c36a71bee --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/ProcessMonitorThread.java @@ -0,0 +1,82 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.util; + +import org.eclipse.core.runtime.IProgressMonitor; + +public class ProcessMonitorThread extends Thread { + + private IProgressMonitor monitor; + private Process proc; + private boolean hasMoreWork; + + public ProcessMonitorThread() { + super(); + + this.monitor = null; + this.proc = null; + } + + public ProcessMonitorThread(Process proc, IProgressMonitor monitor) { + this(); + + this.monitor = monitor; + this.proc = proc; + } + + @Override + /* TODO : Have to need code review soon*/ + public void run() { + this.hasMoreWork = true; + + while(hasMoreWork) { + if(monitor.isCanceled()) { + if(proc != null) { + proc.destroy(); + } + monitor.setCanceled(false); + monitor.done(); + hasMoreWork = false; + break; + } + try { + Thread.sleep(100); + int exit = proc.exitValue(); + + if (exit <= 0 || exit >= 255) { + monitor.done(); + hasMoreWork = false; + } + } catch (IllegalThreadStateException e) { + // TODO Auto-generated catch block + hasMoreWork = true; + }catch (InterruptedException e) { + // TODO Auto-generated catch block + hasMoreWork = false; + } + } + } + +} diff --git a/org.tizen.common/src/org/tizen/common/util/PropertyUtil.java b/org.tizen.common/src/org/tizen/common/util/PropertyUtil.java new file mode 100644 index 000000000..2f7ac97b4 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/PropertyUtil.java @@ -0,0 +1,114 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.util; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Properties; + +public abstract class PropertyUtil { + public static Properties loadProperties(String fileName) { + Properties props = new Properties(); + BufferedReader reader = null; + try { + reader = new BufferedReader(new FileReader(fileName)); + String line = ""; + while((line=reader.readLine()) != null) { + if ("".equals(line.trim())) + continue; + int index = line.indexOf("="); + String key =line.substring(0,index); + String value = line.substring(index+1); + props.setProperty(key, value); + } + //props.load(reader); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (reader != null) + try { + reader.close(); + } catch (IOException e) { + } + } + return props; + } + + public static Properties loadProperties(InputStream inputStream) { + Properties props = new Properties(); + try { + props.load(inputStream); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (inputStream != null) + try { + inputStream.close(); + } catch (IOException e) { + } + } + return props; + } + + public static boolean storeProperties(OutputStream outputStream, Properties props) { + try { + props.store(outputStream, null); + } catch (Exception e) { + e.printStackTrace(); + return false; + } finally { + if (outputStream != null) + try { + outputStream.close(); + } catch (IOException e) { + } + } + return true; + } + + public static boolean storeProperties(String fileName, Properties props) { + BufferedWriter writer = null; + + try { + writer = new BufferedWriter(new FileWriter(fileName)); + props.store(writer, null); + } catch (Exception e) { + e.printStackTrace(); + return false; + } finally { + if (writer != null) + try { + writer.close(); + } catch (IOException e) { + } + } + return true; + } +} diff --git a/org.tizen.common/src/org/tizen/common/util/SWTUtil.java b/org.tizen.common/src/org/tizen/common/util/SWTUtil.java new file mode 100644 index 000000000..21c7dc9c7 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/SWTUtil.java @@ -0,0 +1,203 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.util; + +import java.awt.Dimension; +import java.awt.Toolkit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.events.VerifyEvent; +import org.eclipse.swt.events.VerifyListener; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorReference; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; + + +public class SWTUtil { + + public static final String HTML_EXTENSIONS[] = { "html", "htm", "shtml", "shtm", "xhtml"}; + + /** + * Creates SWT <code>Text</code> for input limited digit. + * + * @return <code>Text</code> + * @author jihoon80.song@samsung.com, S-Core Inc. + */ + public static Text createNumericText(Composite composite, int style, int limit) { + Text text = new Text(composite, style); + + text.setTextLimit(limit); + + text.addVerifyListener(new VerifyListener() { + final Pattern pattern = Pattern.compile("[0-9]*"); //$NON-NLS-1$ + public void verifyText(VerifyEvent e) { + Matcher m = pattern.matcher(e.text); + if (!m.matches()) { + e.doit = false; + } + } + }); + + return text; + } + + public static Text createNumericText(Composite composite, int limit) { + return createNumericText(composite, SWT.BORDER, limit); + } + + /** + * Creates SWT <code>ScrolledComposite</code>. + * @param width the minimum width or 0 for default width (0 is screen width) + * @param height the minimum height or 0 for default height (0 is screen height) + * @return <code>ScrolledComposite</code> + * @author Changhyun Lee {@literal <changhyun1.lee@samsung.com>} (S-Core) + */ + public static ScrolledComposite createScrolledComposite(Composite parent, int width, int height) { + ScrolledComposite sc = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL); + + Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); + if (width == 0) { + width = screen.width; + } + + if (height == 0) { + height = screen.height; + } + + sc.setMinSize(width, height); + sc.setExpandHorizontal(true); + sc.setExpandVertical(true); + + return sc; + } + + /** + * Get current active editor. + * + * @return <code>IEditorPart</code> + * @author Changhyun Lee {@literal <changhyun1.lee@samsung.com>} (S-Core) + */ + public static IEditorPart getActiveEditor() { + IWorkbenchWindow window = ViewUtil.getWorkbenchWindow(); + IWorkbenchPage page = window.getActivePage(); + + if(page == null){ + return null; + } + + IEditorPart editor = page.getActiveEditor(); + if(editor == null){ + return null; + } + + return editor; + } + + /** + * Get editor of file extension. + * + * @return <code>IEditorPart</code> + * @author Changhyun Lee {@literal <changhyun1.lee@samsung.com>} (S-Core) + */ + public static IEditorPart getCurrentEditor(String ext) { + if (ext == null) { + throw new IllegalArgumentException("extension can't be null"); + } + + IEditorPart editor = getActiveEditor(); + if(editor == null || editor.getEditorInput() == null){ + return null; + } + + if (ext.equalsIgnoreCase(FileUtil.getFileExtension(editor.getEditorInput().getName()))) { + return editor; + } + + return null; + } + + /** + * Get current HTML Editor. + * + * @return <code>IEditorPart</code> + * @author Changhyun Lee {@literal <changhyun1.lee@samsung.com>} (S-Core) + */ + public static IEditorPart getCurrentHtmlEditor() { + IEditorPart editor = getActiveEditor(); + if(editor == null || editor.getEditorInput() == null){ + return null; + } + + if (isHtmlFile(editor.getEditorInput().getName())) { + return editor; + } + + return null; + } + + /** + * Verify that html file. + * + * @return <code>boolean</code> + * @author Changhyun Lee {@literal <changhyun1.lee@samsung.com>} (S-Core) + */ + public static boolean isHtmlFile(String fullName) { + String fileExt = FileUtil.getFileExtension(fullName); + if (fileExt == null) { + return false; + } + + for (String htmlExt : HTML_EXTENSIONS) { + if (htmlExt.equalsIgnoreCase(fileExt)) { + return true; + } + } + return false; + } + + /** + * Get editorReferences. + * + * @return <code>IEditorReference[]</code> + * @author Changhyun Lee {@literal <changhyun1.lee@samsung.com>} (S-Core) + */ + public static IEditorReference[] getEditorReferences() { + IWorkbenchWindow window = ViewUtil.getWorkbenchWindow(); + IWorkbenchPage page = window.getActivePage(); + + if(page == null){ + return null; + } + + return page.getEditorReferences(); + } + +}
\ No newline at end of file diff --git a/org.tizen.common/src/org/tizen/common/util/ShellParser.java b/org.tizen.common/src/org/tizen/common/util/ShellParser.java new file mode 100644 index 000000000..5f868f59d --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/ShellParser.java @@ -0,0 +1,80 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.util; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class ShellParser{ + Process proc = null; + + public ShellParser(Process process) { + proc = process; + } + + public void setProcess(Process proc) { + this.proc = proc; + } + + public void parsing() { + final StringBuilder contents = new StringBuilder(); + + Thread inputThread = new Thread(){ + public void run() { + String line = null; + BufferedReader input = new BufferedReader(new InputStreamReader(proc.getInputStream())); + try { + while((line=input.readLine())!=null){ + contents.append(line); + contents.append(HostUtil.LINE_SEPARATOR); + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + }; + + Thread errorThread = new Thread(){ + public void run() { + String line = null; + BufferedReader input = new BufferedReader(new InputStreamReader(proc.getErrorStream())); + try { + while((line=input.readLine())!=null){ + contents.append(line); + contents.append(HostUtil.LINE_SEPARATOR); + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + }; + + inputThread.start(); + errorThread.start(); + } +} diff --git a/org.tizen.common/src/org/tizen/common/util/StreamGobbler.java b/org.tizen.common/src/org/tizen/common/util/StreamGobbler.java new file mode 100644 index 000000000..deae67722 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/StreamGobbler.java @@ -0,0 +1,75 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.util; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; + +public class StreamGobbler extends Thread +{ + InputStream is; + OutputStream os; + String result; + private static Object synchronizer = new Object(); + + public StreamGobbler(InputStream is) { + this.is = is; + this.os = null; + } + + public StreamGobbler(InputStream is, OutputStream os) { + this.is = is; + this.os = os; + } + + public void run() + { + StringBuffer buffer = new StringBuffer(); + try { + synchronized (synchronizer) { + BufferedReader br = new BufferedReader(new InputStreamReader(is)); + String line; + while ( (line = br.readLine()) != null) { + buffer.append(line); + buffer.append("\n"); + + if ( os != null ) + os.write( (line + "\n").getBytes()); + } + br.close(); + } + } catch (IOException ioe) { + ioe.printStackTrace(); + } finally { + result = buffer.toString(); + } + } + public String getResult() { + return result; + } +} diff --git a/org.tizen.common/src/org/tizen/common/util/StringUtil.java b/org.tizen.common/src/org/tizen/common/util/StringUtil.java new file mode 100644 index 000000000..c7ccee27e --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/StringUtil.java @@ -0,0 +1,128 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.util; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +/** + * @author Changhyun Lee {@literal <changhyun1.lee@samsung.com>} (S-Core) + * <ul> + * <li> initial creation + * <li> added trimToNull method. + * </ul> + * @author gyeongseok.seo@samsung.com, S-Core Inc. + * <ul> + * <li> added split method. + * </ul> + */ +public class StringUtil { + public static String trimToNull(String s) { + return trimToNull(s, null); + } + + public static String trimToNull(String s, String def) { + if (s == null) { + return def; + } + + String t = s.trim(); + if (t.length() == 0) { + return def; + } + + return t; + } + + public static InputStream stringToInputStream(String src) { + if (src == null) { + return null; + } + return new ByteArrayInputStream(src.getBytes()); + } + + public static String[] split(String s, String delim) { + List<String> list = new ArrayList<String>(); + StringTokenizer st = new StringTokenizer(s, delim); + while (st.hasMoreTokens()) { + list.add(st.nextToken()); + } + + return (String[]) list.toArray(new String[0]); + } + + public static String getOnlyNumerics(String str) { + if (str == null) { + return null; + } + + char c; + StringBuilder sb = new StringBuilder(); + + for (int i = 0; i < str.length() ; i++) { + c = str.charAt(i); + if (Character.isDigit(c)) { + sb.append(c); + } + } + return sb.toString(); + } + + public static String asString(Reader reader) throws IOException { + StringBuilder sb = new StringBuilder(); + int c; + while ((c = reader.read()) != -1) { + sb.append((char) c); + } + return sb.toString(); + } + public static String asString(InputStream is) throws IOException{ + StringBuffer out = new StringBuffer(); + byte[] b = new byte[4096]; + + for (int n; (n = is.read(b)) != -1;) + out.append(new String(b,0,n)); + return out.toString(); + } + + public static String removeEnd(String str, String remove) { + if (isEmpty(str) || isEmpty(remove)) { + return str; + } + if (str.endsWith(remove)) { + return str.substring(0, str.length() - remove.length()); + } + return str; + } + + public static boolean isEmpty(CharSequence cs) { + return cs == null || cs.length() == 0; + } +} diff --git a/org.tizen.common/src/org/tizen/common/util/UpdateManager.java b/org.tizen.common/src/org/tizen/common/util/UpdateManager.java new file mode 100644 index 000000000..7edaf7445 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/UpdateManager.java @@ -0,0 +1,146 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.util; + +import java.io.File; + +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IStartup; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.PlatformUI; +import org.tizen.common.CommonPlugin; +import org.tizen.common.preferences.TizenBasePreferencePage; +import org.tizen.common.properties.InstallPathConfig; + + +public class UpdateManager implements IStartup { + private static final String EXECUTE_INSTALLER_COMMAND = "java -jar InstallManager.jar"; + final IWorkbench workbench = PlatformUI.getWorkbench(); + + @Override + public void earlyStartup() { + // Check installable package exist. + IPreferenceStore prefStore = CommonPlugin.getDefault().getPreferenceStore(); + + if(prefStore.getBoolean(TizenBasePreferencePage.KEY_SDKUPDATE)) + { + boolean updatable = isExistUpdatablePackage(); + if(updatable) { + if(askExecuteInstallerDlg()) { + executeInstallManger(); + if (workbench != null) { + final Display display = workbench.getDisplay(); + display.syncExec(new Runnable() { + public void run() { + if (!display.isDisposed()) + workbench.close(); + } + }); + } + } + } + } + } + + private boolean isExistUpdatablePackage() { + String result = HostUtil.returnExecute(EXECUTE_INSTALLER_COMMAND + " -checkPackageUpdate", InstallPathConfig.getInstallManagerPath()); + if(result.equals("updatable")) + return true; + return false; + } + + private boolean askExecuteInstallerDlg() { + int ret = checkUpdate(); + if (ret == IDialogConstants.YES_ID) + return true; + return false; + } + + private void executeInstallManger() { + returnExecute(EXECUTE_INSTALLER_COMMAND, InstallPathConfig.getInstallManagerPath()); + } + + public static String returnExecute(String command, String workingDir) { + final StringBuilder contents = new StringBuilder(); + + Process proc = null; + + String[] fullCommand = HostUtil.getCommand(command); + + try { + ProcessBuilder pb = new ProcessBuilder(); + pb.command(fullCommand); + if(workingDir != null) { + pb.directory(new File(workingDir)); + } + proc = pb.start(); + + ShellParser parser = new ShellParser(proc); + parser.parsing(); + + } catch (Exception e) { + e.printStackTrace(); + return null; + } finally{ + } + + return contents.toString().trim(); + + } + public int checkUpdate() { + final int[] result = new int[1]; // using array since you can't change a final int + + Runnable query = new Runnable() { + public void run() { + int resultId[] = { + IDialogConstants.YES_ID, + IDialogConstants.NO_ID }; + + String labels[] = new String[] { + IDialogConstants.YES_LABEL, + IDialogConstants.NO_LABEL }; + + MessageDialog dialog = new MessageDialog( + PlatformUI.getWorkbench().getDisplay().getActiveShell(), + "Tizen SDK", + null,"Updates are available for Tizen SDK. Do you want to install them?" , MessageDialog.QUESTION, labels, 0); + dialog.open(); + if (dialog.getReturnCode() == SWT.DEFAULT) { + // A window close returns SWT.DEFAULT - mapped to a cancel + result[0] = IDialogConstants.NO_ID; + } else { + result[0] = resultId[dialog.getReturnCode()]; + } + } + }; + + PlatformUI.getWorkbench().getDisplay().syncExec(query); + return result[0]; + } +} diff --git a/org.tizen.common/src/org/tizen/common/util/ViewUtil.java b/org.tizen.common/src/org/tizen/common/util/ViewUtil.java new file mode 100644 index 000000000..05a3ae525 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/ViewUtil.java @@ -0,0 +1,108 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim <kh5325.kim@samsung.com> +* +* 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. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.util; + +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; + +/** + * @author Changhyun Lee {@literal <changhyun1.lee@samsung.com>} (S-Core) + */ +public class ViewUtil { + public static void showView(final String id, boolean sync) { + ViewRunnable runnable = new ViewRunnable(id); + + if (sync) { + Display.getDefault().syncExec(runnable); + } else { + Display.getDefault().asyncExec(runnable); + } + } + + static class ViewRunnable implements Runnable { + String id; + + public ViewRunnable(String id) { + this.id = id; + } + + @Override + public void run() { + IWorkbenchWindow window = getWorkbenchWindow(); + if (window == null) { + return; + } + + try { + window.getActivePage().showView(id); + } catch (PartInitException e) { + MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error", "showView failed: " + e.getMessage()); + } + } + } + + public static IViewPart getView(final String id) { + return getView(id, true); + } + + public static IViewPart getView(final String id, boolean show) { + IWorkbenchWindow window = getWorkbenchWindow(); + if (window == null) { + return null; + } + + IWorkbenchPage activeWorkbenchPage = window.getActivePage(); + if (activeWorkbenchPage == null) { + return null; + } + + IViewPart view = activeWorkbenchPage.findView(id); + + if (view != null && show) { + showView(id, true); + } + + return view; + } + + public static IWorkbenchWindow getWorkbenchWindow() { + IWorkbench workbench = PlatformUI.getWorkbench(); + IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); + if (window == null) { + if (workbench.getWorkbenchWindowCount() == 1) { + window = workbench.getWorkbenchWindows()[0]; + } + } + + return window; + } + +}
\ No newline at end of file |