From: sw83.shim Date: Fri, 17 Nov 2017 02:55:10 +0000 (+0900) Subject: Initial uib eplugin sources X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen_studio;p=sdk%2Ftools%2Fide-uib-efl-eplugin.git Initial uib eplugin sources Change-Id: I0d63551693133bf09d711a82245c65322b83eaed Signed-off-by: sw83.shim --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..acee03f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +bin +*.class diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..02f6e1c --- /dev/null +++ b/AUTHORS @@ -0,0 +1,7 @@ +Dongjo Hwang +Gyeongmin Ju +ByoungChang Son +Wonjune Choi +Jeonghwan Kim +Jaeyeol Lee +Hyeonsu Seo diff --git a/LICENSE.APLv2 b/LICENSE.APLv2 new file mode 100644 index 0000000..9fc6203 --- /dev/null +++ b/LICENSE.APLv2 @@ -0,0 +1,204 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "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. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "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. + + "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). + + "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. + + "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." + + "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. + + 2. Grant of Copyright License. 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. + + 3. Grant of Patent License. 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. + + 4. Redistribution. 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: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) 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 + + (d) 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. + + 5. Submission of Contributions. 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. + + 6. Trademarks. 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. + + 7. Disclaimer of Warranty. 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. + + 8. Limitation of Liability. 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. + + 9. Accepting Warranty or Additional Liability. 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. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. + + + diff --git a/LICENSE.EPL b/LICENSE.EPL new file mode 100644 index 0000000..3d967ae --- /dev/null +++ b/LICENSE.EPL @@ -0,0 +1,70 @@ +Eclipse Public License - v 1.0 + +THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. + +1. DEFINITIONS + +"Contribution" means: + +a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and +b) in the case of each subsequent Contributor: +i) changes to the Program, and +ii) additions to the Program; +where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. +"Contributor" means any person or entity that distributes the Program. + +"Licensed Patents" mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. + +"Program" means the Contributions distributed in accordance with this Agreement. + +"Recipient" means anyone who receives the Program under this Agreement, including all Contributors. + +2. GRANT OF RIGHTS + +a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form. +b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. +c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program. +d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. +3. REQUIREMENTS + +A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that: + +a) it complies with the terms and conditions of this Agreement; and +b) its license agreement: +i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; +ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; +iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and +iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange. +When the Program is made available in source code form: + +a) it must be made available under this Agreement; and +b) a copy of this Agreement must be included with each copy of the Program. +Contributors may not remove or alter any copyright notices contained within the Program. + +Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. + +4. COMMERCIAL DISTRIBUTION + +Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense. + +For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages. + +5. NO WARRANTY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED 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. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. + +6. DISCLAIMER OF LIABILITY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +7. GENERAL + +If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. + +If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. + +All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. + +Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved. + +This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation. \ No newline at end of file diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..2605c69 --- /dev/null +++ b/NOTICE @@ -0,0 +1,9 @@ +Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved. +Except as noted, this software is licensed under Apache License, Version 2. +Please, see the LICENSE.APLv2 file for Apache License terms and conditions. + +gson.jar licensed under Apache License, Version 2. +Please, see LICENSE.APLv2 file for Apache License, Version 2 terms and conditions. + +nebula.widgets.gallery_0.6.0.201307092147.jar licensed under Eclipse Public License, Version 1.0 +Please, see LICENSE.EPL file for Eclipse Public License, Version 1.0 terms and conditions. diff --git a/builder/build.properties.clean b/builder/build.properties.clean new file mode 100644 index 0000000..b345bb7 --- /dev/null +++ b/builder/build.properties.clean @@ -0,0 +1,259 @@ +############################################################################### +# Copyright (c) 2003, 2006 IBM Corporation and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### +##################### +# Parameters describing how and where to execute the build. +# Typical users need only update the following properties: +# baseLocation - where things you are building against are installed +# bootclasspath - The base jars to compile against (typicaly rt.jar) +# configs - the list of {os, ws, arch} configurations to build. +# +# Of course any of the settings here can be overridden by spec'ing +# them on the command line (e.g., -DbaseLocation=d:/eclipse + +#The type of the top level element we are building, generally "feature" +topLevelElementType=feature +#The id of the top level element we are building +topLevelElementId=org.tizen.efluibuilder.feature + +############# PRODUCT/PACKAGING CONTROL ############# +#runPackager=true + +#Set the name of the archive that will result from the product build. +#archiveNamePrefix= + +# The prefix that will be used in the generated archive. +archivePrefix="Do not touch here." + +# The location underwhich all of the build output will be collected. +collectingFolder=${archivePrefix} + +# The list of {os, ws, arch} configurations to build. This +# value is a '&' separated list of ',' separate triples. For example, +# configs=win32,win32,x86 & linux,motif,x86 +# By default the value is *,*,* +configs="Do not touch here." +#configs=win32, win32, x86 & \ +# win32,win32,x86_64 & \ +# win32,win32,wpf & \ +# linux, gtk, ppc & \ +# linux, gtk, x86 & \ +# linux, gtk, x86_64 & \ +# linux, motif, x86 & \ +# solaris, motif, sparc & \ +# solaris, gtk, sparc & \ +# aix, motif, ppc & \ +# hpux, motif, ia64_32 & \ +# macosx, carbon, ppc & \ +# macosx, carbon, x86 & \ +# macosx, cocoa, ppc & \ +# macosx, cocoa, x86 & \ +# macosx, cocoa, x86_64 + +# By default PDE creates one archive (result) per entry listed in the configs property. +# Setting this value to true will cause PDE to only create one output containing all +# artifacts for all the platforms listed in the configs property. +# To control the output format for the group, add a "group, group, group - " entry to the +# archivesFormat. +#groupConfigurations=true + +#The format of the archive. By default a zip is created using antZip. +#The list can only contain the configuration for which the desired format is different than zip. +#archivesFormat=win32, win32, x86 - antZip& \ +# linux, gtk, ppc - antZip &\ +# linux, gtk, x86 - antZip& \ +# linux, gtk, x86_64 - antZip& \ +# linux, motif, x86 - antZip& \ +# solaris, motif, sparc - antZip& \ +# solaris, gtk, sparc - antZip& \ +# aix, motif, ppc - antZip& \ +# hpux, motif, PA_RISC - antZip& \ +# macosx, carbon, ppc - antZip + +#Allow cycles involving at most one bundle that needs to be compiled with the rest being binary bundles. +allowBinaryCycles=true + +#Sort bundles depenedencies across all features instead of just within a given feature. +#flattenDependencies = true + +#Parallel compilation, requires flattenedDependencies=true +#parallelCompilation=true +#parallelThreadCount= +#parallelThreadsPerProcessor= + +#Set to true if you want the output to be ready for an update jar (no site.xml generated) +#outputUpdateJars = false + +#Set to true for Jnlp generation +#codebase should be a URL that will be used as the root of all relative URLs in the output. +#generateJnlp=false +#jnlp.codebase= +#jnlp.j2se= +#jnlp.locale= +#jnlp.generateOfflineAllowed=true or false generate attribute in the generated features +#jnlp.configs=${configs} #uncomment to filter the content of the generated jnlp files based on the configuration being built + +#Set to true if you want to sign jars +#signJars=false +#sign.alias= +#sign.keystore= +#sign.storepass= +#sign.keypass= + +#Arguments to send to the zip executable +#zipargs= + +#Arguments to send to the tar executable +#tarargs= + +#Control the creation of a file containing the version included in each configuration - on by default +#generateVersionsLists=false + +############## BUILD NAMING CONTROL ################ +# The directory into which the build elements are fetched and where +# the build takes place. +buildDirectory="Do not touch here" + +# Type of build. Used in naming the build output. Typically this value is +# one of I, N, M, S, ... +buildType="Do not touch here" + +# ID of the build. Used in naming the build output. +buildId="Do not touch here" + +# Label for the build. Used in naming the build output +buildLabel=${buildType}.${buildId} + +# Timestamp for the build. Used in naming the build output +timestamp=007 + +#The value to be used for the qualifier of a plugin or feature when you want to override the value computed by pde. +#The value will only be applied to plugin or features indicating build.properties, qualifier = context +#forceContextQualifier= + +#Enable / disable the generation of a suffix for the features that use .qualifier. +#The generated suffix is computed according to the content of the feature +#generateFeatureVersionSuffix=true + +############# BASE CONTROL ############# +# Settings for the base Eclipse components and Java class libraries +# against which you are building. +# Base location for anything the build needs to compile against. For example, +# in most RCP app or a plug-in, the baseLocation should be the location of a previously +# installed Eclipse against which the application or plug-in code will be compiled and the RCP delta pack. + +base="Do not touch here" +baseLocation="Do not touch here" + + +#Folder containing repositories whose content is needed to compile against +#repoBaseLocation=${base}/repos +#Folder where the content of the repositories from ${repoBaseLocation} will be made available as a form suitable to be compiled against +#transformedRepoLocation=${base}/transformedRepos + +#Os/Ws/Arch/nl of the eclipse specified by baseLocation +baseos=linux +basews=gtk +basearch=x86 + +#this property indicates whether you want the set of plug-ins and features to be considered during the build to be limited to the ones reachable from the features / plugins being built +filteredDependencyCheck=false + +#this property indicates whether the resolution should be done in development mode (i.e. ignore multiple bundles with singletons) +resolution.devMode=false + +#pluginPath is a list of locations in which to find plugins and features. This list is separated by the platform file separator (; or :) +#a location is one of: +#- the location of the jar or folder that is the plugin or feature : /path/to/foo.jar or /path/to/foo +#- a directory that contains a /plugins or /features subdirectory +#- the location of a feature.xml, or for 2.1 style plugins, the plugin.xml or fragment.xml +#pluginPath= + +skipBase=true +eclipseURL= +eclipseBuildId= +eclipseBaseURL=${eclipseURL}/eclipse-platform-${eclipseBuildId}-win32.zip + + +############# MAP FILE CONTROL ################ +# This section defines CVS tags to use when fetching the map files from the repository. +# If you want to fetch the map file from repository / location, change the getMapFiles target in the customTargets.xml + +skipMaps=true +mapsRepo=:pserver:anonymous@example.com/path/to/repo +mapsRoot=path/to/maps +mapsCheckoutTag=HEAD + +#tagMaps=true +mapsTagTag=v${buildId} + + +############ REPOSITORY CONTROL ############### +# This section defines properties parameterizing the repositories where plugins, fragments +# bundles and features are being obtained from. + +# The tags to use when fetching elements to build. +# By default thebuilder will use whatever is in the maps. +# This value takes the form of a comma separated list of repository identifier (like used in the map files) and the +# overriding value +# For example fetchTag=CVS=HEAD, SVN=v20050101 +# fetchTag=HEAD +skipFetch=true + + +############# P2 OPTIONS ############## +#p2.gathering = true +#p2.compress=true + +############# JAVA COMPILER OPTIONS ############## +# The location of the Java jars to compile against. Typically the rt.jar for your JDK/JRE +#bootclasspath=${java.home}/lib/rt.jar + +# specific JRE locations to compile against. These values are used to compile bundles specifying a +# Bundle-RequiredExecutionEnvironment. Uncomment and set values for environments that you support +#CDC-1.0/Foundation-1.0= /path/to/rt.jar +#CDC-1.1/Foundation-1.1= +#OSGi/Minimum-1.0= +#OSGi/Minimum-1.1= +#JRE-1.1= +#J2SE-1.2= +#J2SE-1.3= +#J2SE-1.4= +#J2SE-1.5= +#JavaSE-1.6= +#PersonalJava-1.1= +#PersonalJava-1.2= +#CDC-1.0/PersonalBasis-1.0= +#CDC-1.0/PersonalJava-1.0= +#CDC-1.1/PersonalBasis-1.1= +#CDC-1.1/PersonalJava-1.1= + +# Specify the output format of the compiler log when eclipse jdt is used +logExtension=.log + +# Whether or not to include debug info in the output jars +javacDebugInfo=true + +# Whether or not to fail the build if there are compiler errors +javacFailOnError=true + +# Enable or disable verbose mode of the compiler +javacVerbose=false + +# Extra arguments for the compiler. These are specific to the java compiler being used. +#compilerArg= + +# Default value for the version of the source code. This value is used when compiling plug-ins that do not set the Bundle-RequiredExecutionEnvironment or set javacSource in build.properties +javacSource=1.8 + +# Default value for the version of the byte code targeted. This value is used when compiling plug-ins that do not set the Bundle-RequiredExecutionEnvironment or set javacTarget in build.properties. +javacTarget=1.8 + + diff --git a/builder/customTargets.xml b/builder/customTargets.xml new file mode 100644 index 0000000..6a42e92 --- /dev/null +++ b/builder/customTargets.xml @@ -0,0 +1,187 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/Chagall_conventions.xml b/config/Chagall_conventions.xml new file mode 100644 index 0000000..4c8a062 --- /dev/null +++ b/config/Chagall_conventions.xml @@ -0,0 +1,291 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demo-27-03-2017/databinding_filter_demo.ogv b/demo-27-03-2017/databinding_filter_demo.ogv new file mode 100644 index 0000000..f261b18 Binary files /dev/null and b/demo-27-03-2017/databinding_filter_demo.ogv differ diff --git a/org.tizen.efluibuilder.codegenerator/.classpath b/org.tizen.efluibuilder.codegenerator/.classpath new file mode 100644 index 0000000..1fa3e68 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/.project b/org.tizen.efluibuilder.codegenerator/.project new file mode 100644 index 0000000..004b7ea --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/.project @@ -0,0 +1,28 @@ + + + org.tizen.efluibuilder.codegenerator + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/org.tizen.efluibuilder.codegenerator/.settings/org.eclipse.jdt.core.prefs b/org.tizen.efluibuilder.codegenerator/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..da318c2 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,90 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled +org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore +org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull +org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault +org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable +org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled +org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning +org.eclipse.jdt.core.compiler.problem.autoboxing=ignore +org.eclipse.jdt.core.compiler.problem.comparingIdentical=error +org.eclipse.jdt.core.compiler.problem.deadCode=error +org.eclipse.jdt.core.compiler.problem.deprecation=warning +org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled +org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled +org.eclipse.jdt.core.compiler.problem.discouragedReference=warning +org.eclipse.jdt.core.compiler.problem.emptyStatement=error +org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore +org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore +org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled +org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore +org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning +org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning +org.eclipse.jdt.core.compiler.problem.forbiddenReference=error +org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning +org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled +org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning +org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning +org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore +org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore +org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning +org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore +org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled +org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled +org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning +org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore +org.eclipse.jdt.core.compiler.problem.noEffectAssignment=error +org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=error +org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore +org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning +org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error +org.eclipse.jdt.core.compiler.problem.nullReference=error +org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error +org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning +org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning +org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore +org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=error +org.eclipse.jdt.core.compiler.problem.potentialNullReference=error +org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore +org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning +org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning +org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore +org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore +org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=error +org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore +org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore +org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled +org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning +org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled +org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled +org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore +org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning +org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled +org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.unclosedCloseable=error +org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore +org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning +org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore +org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=error +org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=error +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled +org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedImport=error +org.eclipse.jdt.core.compiler.problem.unusedLabel=error +org.eclipse.jdt.core.compiler.problem.unusedLocal=error +org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled +org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning +org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning +org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=error diff --git a/org.tizen.efluibuilder.codegenerator/META-INF/MANIFEST.MF b/org.tizen.efluibuilder.codegenerator/META-INF/MANIFEST.MF new file mode 100644 index 0000000..ea3d13f --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: org.tizen.efluibuilder.codegenerator +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.tizen.efluibuilder.codegenerator.Activator +Require-Bundle: org.eclipse.ui;bundle-version="3.105.0", + org.eclipse.core.runtime, + org.eclipse.core.resources, + org.tizen.common, + org.tizen.efluibuilder.common +Bundle-ActivationPolicy: lazy +Export-Package: org.tizen.efluibuilder.codegenerator, + org.tizen.efluibuilder.codegenerator.event +Bundle-Vendor: %Bundle-Vendor diff --git a/org.tizen.efluibuilder.codegenerator/OSGI-INF/l10n/bundle.properties b/org.tizen.efluibuilder.codegenerator/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..5475439 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,3 @@ +#Properties file for org.tizen.efluibuilder.codegenerator +Bundle-Vendor = The Linux Foundation +Bundle-Name = Tizen EFL UI Builder Codegenerator \ No newline at end of file diff --git a/org.tizen.efluibuilder.codegenerator/build.properties b/org.tizen.efluibuilder.codegenerator/build.properties new file mode 100644 index 0000000..0f0f7cc --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + res/,\ + OSGI-INF/ +src.excludes = test/ diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_common_header.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_common_header.xsl new file mode 100644 index 0000000..1663888 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_common_header.xsl @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + +#include + +typedef enum { + text, foreach, binding_type_end_proxy +} widget_binding_type; + +typedef enum { + uib_label, + uib_list, + uib_hoversel, + uib_hoverselitem, + uib_genlist, + uib_button, + uib_checkbox, + uib_listitem, + uib_radio, + uib_flipselector, + uib_flipselectoritem, + uib_widget_list_end_proxy +} widget_type; + +typedef enum { + UIB_XML, UIB_JSON +} UIB_DATASOURCE_CONTENT_TYPE; + +typedef void (*Databinding_callback)(Evas_Object* widget, + char* binding_element_path, widget_binding_type binding_type, + void** root_element, UIB_DATASOURCE_CONTENT_TYPE ds_content_type); +typedef void (*SetWidgetElementValue_callback)(Evas_Object* widget, + widget_binding_type binding_type, char* value_data); + +typedef struct { + bool is_init; + Databinding_callback binding_cb; +} widget_handler_st; + +char* get_json_data_from_builder(JsonBuilder*); +char* get_json_data_from_node(JsonNode*); +char* trim_quotes(char*); +bool data_contacts_common_disconnect(); +bool data_contacts_common_connect(); +char* get_xml_data_from_node(xmlDocPtr); +xmlDocPtr convert_json_to_xml(JsonNode*); + +/** + * + * @brief Bind data value to specified widget based on + * + * @remark + * + * @param[in] widget The widget on which databinding will be performed + * @param[in] binding_element_path The JSON path to extract data element(s) from JSON tree + * @param[in] binding_type The type of binding to be performed performed + * @param[in] root_element The root node of JSON from where data needs to be extracted + * @param[in] pre_db_cb The callback of type Databinding_callback to be called before value is set on widget. Can be used to reset or preserve old values + * @param[in] databind_cb The callback of SetWidgetElementValue_callback type to be used for setting data value onto widget + * @param[in] post_db_cb The callback of type Databinding_callback to be called after value is set on widget. Can be used to render updated widget elements + * @param[in] ds_content_type The datasource content type which calls respective parser for the attached data content + */ +void bind_data(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + Databinding_callback pre_db_cb, + SetWidgetElementValue_callback databind_cb, + Databinding_callback post_db_cb, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type); +#endif +]]> + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_common_source.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_common_source.xsl new file mode 100644 index 0000000..af7f264 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_common_source.xsl @@ -0,0 +1,372 @@ + + + + + + + + + + + + + + + + + + + + + +#include +#include +#include + +static void db_json_content_handler(Evas_Object*, char*, widget_binding_type, + JsonNode *, Databinding_callback, SetWidgetElementValue_callback, + Databinding_callback, UIB_DATASOURCE_CONTENT_TYPE); + +static void db_xml_content_handler(Evas_Object*, char*, widget_binding_type, + xmlDocPtr, Databinding_callback, SetWidgetElementValue_callback, + Databinding_callback, UIB_DATASOURCE_CONTENT_TYPE); + +static bool processNode(xmlNodePtr, JsonReader*, JsonNodeType); + +char* get_json_data_from_builder(JsonBuilder* jsonBuilder) { + //Verify generated Json + JsonGenerator* jsonGenerator = json_generator_new(); + JsonNode* rootNode = json_builder_get_root(jsonBuilder); + json_generator_set_root(jsonGenerator, rootNode); + json_generator_set_pretty(jsonGenerator, false); + char* json_string = json_generator_to_data(jsonGenerator, NULL); + //json_to_string(json_builder_get_root(jsonBuilder),true); + dlog_print(DLOG_INFO, LOG_TAG, "print generated json %s", json_string); + g_object_unref(rootNode); + g_object_unref(jsonGenerator); + return json_string; +} + +char* get_json_data_from_node(JsonNode* rootNode) { + //Verify generated Json + char* json_string = NULL; + if (rootNode != NULL) { + JsonGenerator* jsonGenerator = json_generator_new(); + json_generator_set_root(jsonGenerator, rootNode); + json_generator_set_pretty(jsonGenerator, false); + json_string = json_generator_to_data(jsonGenerator, NULL); + //json_to_string(json_builder_get_root(jsonBuilder),true); + dlog_print(DLOG_INFO, LOG_TAG, "print generated json %s", json_string); + g_object_unref(jsonGenerator); + } + return json_string; +} + +char* get_xml_data_from_node(xmlDocPtr rootNode) { + //Verify generated Json + char* xml_string = NULL; + int size; + xmlDocDumpFormatMemory(rootNode, &xml_string, &size, 1); + return xml_string; +} + +char* trim_quotes(char* str) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s trim quotes for %s", __func__, str); + if (str != NULL) { + unsigned int len = strlen(str); + if (len == 0) { + return str; + } + int begin = 0, end = len - 1; + if (str[0] == '"') + begin = 1; + if (str[end] == '"') + end--; + if ((begin != 0) || (end != len - 1)) { + int length = end + 1; + int j = 0; + for (int i = begin; i < length; ++i) { + str[j++] = str[i]; + } + str[j] = '\0'; + } + } + dlog_print(DLOG_DEBUG, LOG_TAG, + "%s trimmed string after removing quotes %s", __func__, str); + return str; +} + +/** + * @brief Function connects to the contacts database. + * @return This function returns 'true' if the function succeeds, + * otherwise 'false' is returned. + */ +bool data_contacts_common_connect() { + int ret = contacts_connect(); + if (ret != CONTACTS_ERROR_NONE) + dlog_print(DLOG_ERROR, LOG_TAG, "contacts_connect() failed. Err= %d.", + ret); + + return (ret == CONTACTS_ERROR_NONE); +} + +/** + * @brief Function disconnects from the contacts database. + * @return This function returns 'true' if the function succeeds, + * otherwise 'false' is returned. + */ +bool data_contacts_common_disconnect() { + int ret = contacts_disconnect(); + if (ret != CONTACTS_ERROR_NONE) + dlog_print(DLOG_ERROR, LOG_TAG, + "contacts_disconnect() failed. Err= %d.", ret); + + return (ret == CONTACTS_ERROR_NONE); +} + +void bind_data(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + Databinding_callback pre_db_cb, + SetWidgetElementValue_callback databind_cb, + Databinding_callback post_db_cb, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (root_element == NULL) + return; + + xmlDocPtr docPtr = (xmlDocPtr) root_element[0]; + db_xml_content_handler(widget, binding_element_path, binding_type, docPtr, + pre_db_cb, databind_cb, post_db_cb, ds_content_type); +} + +static void db_json_content_handler(Evas_Object* widget, + char* binding_element_path, widget_binding_type binding_type, + JsonNode * rootNode, Databinding_callback pre_db_cb, + SetWidgetElementValue_callback databind_cb, + Databinding_callback post_db_cb, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + + JsonParser *parser = json_parser_new(); + char* json_data = get_json_data_from_node(rootNode); + if (json_parser_load_from_data(parser, json_data, strlen(json_data), + NULL)) { + + JsonNode *result; + JsonPath *path = json_path_new(); + json_path_compile(path, binding_element_path, NULL); + result = json_path_match(path, json_parser_get_root(parser)); + + //TODO: Remove from generated code + //get_json_data_from_node(result); + if (pre_db_cb != NULL) { + pre_db_cb(widget, binding_element_path, binding_type, &rootNode, + ds_content_type); + } + JsonArray* resultArray = json_node_get_array(result); + if (databind_cb != NULL) { + if (binding_type == foreach) { + for (int i = 0; i < json_array_get_length(resultArray); ++i) { + JsonNode* element = json_array_get_element(resultArray, i); + char* element_data = trim_quotes( + get_json_data_from_node(element)); + databind_cb(widget, binding_type, element_data); + g_free(element_data); + } + } else if (binding_type == text) { + JsonNode* element = json_array_get_element(resultArray, 0); + char* element_data = trim_quotes( + get_json_data_from_node(element)); + databind_cb(widget, binding_type, element_data); + g_free(element_data); + } + } + g_object_unref(path); + //Frees up memory allocated to element & resultArray as well + json_node_free(result); + } + g_free(json_data); + g_object_unref(parser); + if (post_db_cb != NULL) { + post_db_cb(widget, binding_element_path, binding_type, &rootNode, + ds_content_type); + } +} + +static void db_xml_content_handler(Evas_Object* widget, + char* binding_element_path, widget_binding_type binding_type, + xmlDocPtr docPtr, Databinding_callback pre_db_cb, + SetWidgetElementValue_callback databind_cb, + Databinding_callback post_db_cb, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + xmlXPathContextPtr context; + xmlXPathObjectPtr result; + xmlNodeSetPtr nodeSet; + char * xml_data = get_xml_data_from_node(docPtr); + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - Received xml doc %s", __func__, + xml_data); + xmlFree(xml_data); + + context = xmlXPathNewContext(docPtr); + if (context == NULL) { + dlog_print(DLOG_ERROR, LOG_TAG, "%s - %s", __func__, + "Error found in xmlXPathNewContext"); + } + result = xmlXPathEvalExpression((const xmlChar*) binding_element_path, + context); + xmlXPathFreeContext(context); + if (result == NULL) { + dlog_print(DLOG_ERROR, LOG_TAG, "%s - %s", __func__, + "Error found in xmlXPathEvalExpression"); + return; + } + if (xmlXPathNodeSetIsEmpty(result->nodesetval)) { + xmlXPathFreeObject(result); + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - %s", __func__, + "No result found after xpath evaluation"); + return; + } + if (pre_db_cb != NULL) { + pre_db_cb(widget, binding_element_path, binding_type, &docPtr, + ds_content_type); + } + + nodeSet = result->nodesetval; + if (binding_type == foreach) { + for (int i = 0; i < nodeSet->nodeNr; i++) { + char* element_data = trim_quotes( + xmlNodeListGetString(docPtr, + nodeSet->nodeTab[i]->xmlChildrenNode, 1)); + databind_cb(widget, binding_type, element_data); + xmlFree(element_data); + } + } else if (binding_type == text) { + char* element_data = trim_quotes( + xmlNodeListGetString(docPtr, + nodeSet->nodeTab[0]->xmlChildrenNode, 1)); + databind_cb(widget, binding_type, element_data); + xmlFree(element_data); + } + xmlXPathFreeObject(result); + + if (post_db_cb != NULL) { + post_db_cb(widget, binding_element_path, binding_type, &docPtr, + ds_content_type); + } +} + +xmlDocPtr convert_json_to_xml(JsonNode* root_node) { + //Begin xml document + xmlDocPtr datasource_xmlDoc = xmlNewDoc(BAD_CAST "1.0"); + + JsonReader* reader = json_reader_new(root_node); + + xmlNodePtr xml_root_node = xmlNewNode(NULL, BAD_CAST "root"); + xmlDocSetRootElement(datasource_xmlDoc, xml_root_node); + + processNode(xml_root_node, reader, JSON_NODE_OBJECT); + + g_object_unref(reader); + + return datasource_xmlDoc; +} + +static bool processNode(xmlNodePtr parentXMLNodePtr, JsonReader* reader, JsonNodeType parentNodeType) { + + if (json_reader_is_array(reader)) { + const gchar* mem_name = json_reader_get_member_name(reader); + gchar* member_name = (gchar*) malloc(sizeof(gchar*) * strlen(mem_name)); + strcpy(member_name, mem_name); + int nElements = json_reader_count_elements(reader); + for (int i = 0; i < nElements; ++i) { + + if (!json_reader_read_element(reader, i)) { + const GError * error = json_reader_get_error(reader); + dlog_print(DLOG_ERROR, LOG_TAG, "%s - %s", __func__, + error->message); + return FALSE; + } + + if (json_reader_is_object(reader)) { + xmlNodePtr obj_arr_xml_node_ptr = xmlNewChild(parentXMLNodePtr, NULL, + (const xmlChar*) member_name, NULL); + if (!processNode(obj_arr_xml_node_ptr, reader, JSON_NODE_ARRAY)) { + return FALSE; + } + } else { + JsonNode* node = json_reader_get_value(reader); + if (node == NULL) { + const GError * error = json_reader_get_error(reader); + if (error != NULL) { + dlog_print(DLOG_ERROR, LOG_TAG, "%s - %s", __func__, + error->message); + } + return FALSE; + } + char * element_data = trim_quotes(get_json_data_from_node(node)); + xmlNewTextChild(parentXMLNodePtr, NULL, (const xmlChar*) member_name, + (const xmlChar*) element_data); + } + json_reader_end_element(reader); + } + free(member_name); + + } else if (json_reader_is_object(reader)) { + const gchar* member_name = json_reader_get_member_name(reader); + xmlNodePtr obj_node_ptr = NULL; + if ((member_name == NULL) || (parentNodeType == JSON_NODE_ARRAY)) { + //It's the root object, therefore using passed root node as parent + obj_node_ptr = parentXMLNodePtr; + } else { + obj_node_ptr = xmlNewChild(parentXMLNodePtr, NULL, + (const xmlChar*) member_name, NULL); + } + int nMembers = json_reader_count_members(reader); + gchar ** member_list = json_reader_list_members(reader); + for (int i = 0; i < nMembers; ++i) { + if (!json_reader_read_member(reader, member_list[i])) { + const GError * error = json_reader_get_error(reader); + dlog_print(DLOG_ERROR, LOG_TAG, "%s - %s", __func__, + error->message); + return FALSE; + } + if (!processNode(obj_node_ptr, reader, JSON_NODE_OBJECT)) { + return FALSE; + } + json_reader_end_member(reader); + } + + } else if (json_reader_is_value(reader)) { + const gchar* member_name = json_reader_get_member_name(reader); + JsonNode* node = json_reader_get_value(reader); + if (node == NULL) { + const GError * error = json_reader_get_error(reader); + if (error != NULL) { + dlog_print(DLOG_ERROR, LOG_TAG, "%s - %s", __func__, + error->message); + } + return FALSE; + } + char * element_data = trim_quotes(get_json_data_from_node(node)); + xmlNewTextChild(parentXMLNodePtr, NULL, (const xmlChar*) member_name, + (const xmlChar*) element_data); + } else { + //ERROR state + const GError * error = json_reader_get_error(reader); + dlog_print(DLOG_ERROR, LOG_TAG, "%s - %s", __func__, error->message); + return FALSE; + } + return TRUE; +} +]]> + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_datamodel_header.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_datamodel_header.xsl new file mode 100644 index 0000000..572ebe3 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_datamodel_header.xsl @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_datamodel_source.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_datamodel_source.xsl new file mode 100644 index 0000000..ad376ac --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_datamodel_source.xsl @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_datamodels_header.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_datamodels_header.xsl new file mode 100644 index 0000000..7e23259 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_datamodels_header.xsl @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_datamodels_source.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_datamodels_source.xsl new file mode 100644 index 0000000..5e5322b --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_datamodels_source.xsl @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_datasource_header.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_datasource_header.xsl new file mode 100644 index 0000000..b9ed487 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_datasource_header.xsl @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_datasource_source.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_datasource_source.xsl new file mode 100644 index 0000000..6fcc5a1 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_datasource_source.xsl @@ -0,0 +1,289 @@ + + + + + + + + + + + + ' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_datasources_header.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_datasources_header.xsl new file mode 100644 index 0000000..233a215 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_datasources_header.xsl @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_datasources_source.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_datasources_source.xsl new file mode 100644 index 0000000..f9b2852 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_datasources_source.xsl @@ -0,0 +1,221 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + register_datasource_update_callback(callback); + } +} +]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_ds_handler_call_history_header.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_ds_handler_call_history_header.xsl new file mode 100644 index 0000000..c84bcd2 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_ds_handler_call_history_header.xsl @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_ds_handler_call_history_source.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_ds_handler_call_history_source.xsl new file mode 100644 index 0000000..874091a --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_ds_handler_call_history_source.xsl @@ -0,0 +1,505 @@ + + + + + + + + + + + + + + + + + + + + + + +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_NUM_LENGTH 12 + +static xmlDocPtr* callHistoryDatasourceRootNode = NULL; +static uib_datasource_interface g_uib_call_history_datasource; +static bool isRefreshCallbackRegistered = false; +static bool is_callhistory_update_databinding_cb_registered = false; + +static void (*refresh_databinding_cb)(); +static void populate_call_log_entries(xmlNodePtr); +static xmlDocPtr prepare_datasource_XML_tree(); +static void refresh_call_history_datasource(const char * const, void*); +static void initialize_call_history_datasource(); +static xmlNodePtr getRemotePartyDetails(xmlNodePtr, int); +static void convertToDateFormat(int, char *); +static void getCallLogType(contacts_phone_log_type_e, char**, char**); +static void getFeatureDetails(xmlNodePtr, int); + +static void cleanup_datasource() { + data_contacts_common_disconnect(); + if (isRefreshCallbackRegistered) { + isRefreshCallbackRegistered = false; + //Un-register callback functions to be invoked when a record changes. + contacts_db_remove_changed_cb(_contacts_phone_log._uri, + refresh_call_history_datasource, NULL); + contacts_db_remove_changed_cb(_contacts_person_phone_log._uri, + refresh_call_history_datasource, NULL); + } + if (callHistoryDatasourceRootNode != NULL + && callHistoryDatasourceRootNode[0] != NULL) { + xmlFreeDoc(callHistoryDatasourceRootNode[0]); + callHistoryDatasourceRootNode = NULL; + } + is_callhistory_update_databinding_cb_registered = false; +} + +static bool populate_call_history_records() { + if (callHistoryDatasourceRootNode == NULL) { + callHistoryDatasourceRootNode = (xmlDocPtr*) malloc(sizeof(xmlDocPtr)); + if (!data_contacts_common_connect()) + return false; + } + callHistoryDatasourceRootNode[0] = prepare_datasource_XML_tree(); + return true; +} + +/* + * { + * + * "callhistory":{ + * "length":2, + * "entries":[ + * { + * "uid":"123", + * "type":"TEL", + * "features":[ + * ], + * "remoteParties":[ + * { + * "remoteParty":"", + * "personId":"3" + * } + * ], + * "startTime":"22/03/2001", + * "duration":100, + * "direction":"DIALED" + * } + * ] + * } + * } + * + * + * + * 2 + * + * 123 + * TEL + * + * + * 3 + * + * 22/03/2001 + * 100 + * DIALED + * + * + * + */ + +static xmlDocPtr prepare_datasource_XML_tree() { + + int call_log_count = 0; + int error_code; + + //Begin xml document + xmlDocPtr datasource_xmlDoc = xmlNewDoc(BAD_CAST "1.0"); + + error_code = contacts_db_get_count(_contacts_phone_log._uri, + &call_log_count); + if (error_code != CONTACTS_ERROR_NONE) { + dlog_print(DLOG_ERROR, LOG_TAG, "contacts_db_get_count() failed: %d", + error_code); + + } else { + //Start CallHistory root node + xmlNodePtr callhistory_root_node = xmlNewNode(NULL, + BAD_CAST "callhistory"); + xmlDocSetRootElement(datasource_xmlDoc, callhistory_root_node); + + //Accomodate 32 bit int highest value + char* call_log_count_str = (char*) malloc( + MAX_NUM_LENGTH * sizeof(char)); + snprintf(call_log_count_str, MAX_NUM_LENGTH, "%d", call_log_count); + xmlNewChild(callhistory_root_node, NULL, (const xmlChar*) "length", + (xmlChar*) call_log_count_str); + free(call_log_count_str); + + xmlNodePtr entriesNode = xmlNewChild(callhistory_root_node, NULL, + (const xmlChar*) "entries", NULL); + + populate_call_log_entries(entriesNode); + } + + //Verify generated xml + //get_xml_data_from_node(datasource_xmlDoc); + + return datasource_xmlDoc; +} + +static void getCallLogType(contacts_phone_log_type_e log_type, + char** call_log_type_str, char** direction) { + + switch (log_type) { + case 0/*CONTACTS_PLOG_TYPE_NONE*/: + *call_log_type_str = ""; + break; + case 1/*CONTACTS_PLOG_TYPE_VOICE_INCOMING*/: + *call_log_type_str = "Incoming call"; + *direction = "INCOMING"; + break; + case 2/*CONTACTS_PLOG_TYPE_VOICE_OUTGOING*/: + *call_log_type_str = "Outgoing call"; + *direction = "DIALED"; + break; + case 3/*CONTACTS_PLOG_TYPE_VIDEO_INCOMING*/: + *call_log_type_str = "Incoming video call"; + *direction = "INCOMING"; + break; + case 4/*CONTACTS_PLOG_TYPE_VIDEO_OUTGOING*/: + *call_log_type_str = "Outgoing video call"; + *direction = "DIALED"; + break; + case 5/*CONTACTS_PLOG_TYPE_VOICE_INCOMING_UNSEEN*/: + *call_log_type_str = "Not confirmed missed call"; + *direction = "INCOMING"; + break; + case 6/*CONTACTS_PLOG_TYPE_VOICE_INCOMING_SEEN*/: + *call_log_type_str = "Confirmed missed call"; + *direction = "INCOMING"; + break; + case 7/*CONTACTS_PLOG_TYPE_VIDEO_INCOMING_UNSEEN*/: + *call_log_type_str = "Not confirmed missed video call"; + *direction = "INCOMING"; + break; + case 8/*CONTACTS_PLOG_TYPE_VIDEO_INCOMING_SEEN*/: + *call_log_type_str = "Confirmed missed video call"; + *direction = "INCOMING"; + break; + case 9/*CONTACTS_PLOG_TYPE_VOICE_REJECT*/: + *call_log_type_str = "Rejected call"; + *direction = "INCOMING"; + break; + case 10/*CONTACTS_PLOG_TYPE_VIDEO_REJECT*/: + *call_log_type_str = "Rejected video call"; + *direction = "INCOMING"; + break; + case 11/*CONTACTS_PLOG_TYPE_VOICE_BLOCKED*/: + *call_log_type_str = "Blocked call"; + *direction = "INCOMING"; + break; + case 12/*CONTACTS_PLOG_TYPE_VIDEO_BLOCKED*/: + *call_log_type_str = "Blocked video call"; + *direction = "INCOMING"; + break; + case 101/*CONTACTS_PLOG_TYPE_MMS_INCOMING*/: + *call_log_type_str = "Incoming MMS"; + *direction = "INCOMING"; + break; + case 102/*CONTACTS_PLOG_TYPE_MMS_OUTGOING*/: + *call_log_type_str = "Outgoing MMS"; + *direction = "DIALED"; + break; + case 103/*CONTACTS_PLOG_TYPE_SMS_INCOMING*/: + *call_log_type_str = "Incoming SMS"; + *direction = "INCOMING"; + break; + case 104/*CONTACTS_PLOG_TYPE_SMS_OUTGOING*/: + *call_log_type_str = "Outgoing SMS"; + *direction = "DIALED"; + break; + case 105/*CONTACTS_PLOG_TYPE_SMS_BLOCKED*/: + *call_log_type_str = "Blocked SMS"; + *direction = "INCOMING"; + break; + case 106/*CONTACTS_PLOG_TYPE_MMS_BLOCKED*/: + *call_log_type_str = "Blocked MMS"; + *direction = "INCOMING"; + break; + case 201/*CONTACTS_PLOG_TYPE_EMAIL_RECEIVED*/: + *call_log_type_str = "Received email"; + *direction = "INCOMING"; + break; + case 202/*CONTACTS_PLOG_TYPE_EMAIL_SENT*/: + *call_log_type_str = "Sent email"; + *direction = "DIALED"; + break; + default: + *call_log_type_str = ""; + *direction = ""; + break; + } +} +/* + *{ + * "uid":"123", + * "type":"TEL", + * "features":[ + * ], + * "remoteParties":[ + * { + * "remoteParty":"", + * "personId":"3" + * } + * ], + * "startTime":"22/03/2001", + * "duration":100, + * "direction":"DIALED" + *} + + * 123 + * TEL + * + * + * 3 + * + * 22/03/2001 + * 100 + * DIALED + */ +static void populate_call_log_entries(xmlNodePtr entriesXMLNode) { + contacts_list_h call_history_list = NULL; + contacts_record_h call_log_record = NULL; + + int error_code; + error_code = contacts_list_create(&call_history_list); + if (error_code != CONTACTS_ERROR_NONE) { + dlog_print(DLOG_ERROR, LOG_TAG, "contacts_list_create() failed: %d", + error_code); + return; + } + + //first get call history list + error_code = contacts_db_get_all_records(_contacts_phone_log._uri, 0, 0, + &call_history_list); + if (error_code != CONTACTS_ERROR_NONE) { + dlog_print(DLOG_ERROR, LOG_TAG, + "contacts_db_get_all_records() failed: %d", error_code); + return; + } + char* startTime = (char*) malloc(100 * sizeof(char)); + int uid; + contacts_phone_log_type_e log_type; + char* type; + int unixTimestamp; + int duration; + char* direction; + while (contacts_list_get_current_record_p(call_history_list, + &call_log_record) == CONTACTS_ERROR_NONE) { + if (call_log_record != NULL) { + contacts_record_get_int(call_log_record, + _contacts_phone_log.log_time, &unixTimestamp); + convertToDateFormat(unixTimestamp, startTime); + + contacts_record_get_int(call_log_record, + _contacts_phone_log.log_type, &log_type); + getCallLogType(log_type, &type, &direction); + + contacts_record_get_int(call_log_record, + _contacts_phone_log.extra_data1, &duration); + + contacts_record_get_int(call_log_record, _contacts_phone_log.id, + &uid); + + //Accomodate 32 bit int highest value + char* uid_str = (char*) malloc(MAX_NUM_LENGTH * sizeof(char)); + snprintf(uid_str, MAX_NUM_LENGTH, "%d", uid); + xmlNewChild(entriesXMLNode, NULL, (const xmlChar*) "uid", + (xmlChar*) uid_str); + free(uid_str); + + xmlNewChild(entriesXMLNode, NULL, (const xmlChar*) "type", + (xmlChar*) type); + + xmlNewChild(entriesXMLNode, NULL, (const xmlChar*) "startTime", + (xmlChar*) startTime); + + //Accomodate 32 bit int highest value + char* duration_str = (char*) malloc(MAX_NUM_LENGTH * sizeof(char)); + snprintf(duration_str, MAX_NUM_LENGTH, "%d", duration); + xmlNewChild(entriesXMLNode, NULL, (const xmlChar*) "uid", + (xmlChar*) duration_str); + free(duration_str); + + xmlNewChild(entriesXMLNode, NULL, (const xmlChar*) "direction", + (xmlChar*) direction); + + xmlNodePtr remotePartiesNode = xmlNewChild(entriesXMLNode, NULL, + (const xmlChar*) "remoteParties", NULL); + getRemotePartyDetails(remotePartiesNode, uid); + + //TODO Look for features data + xmlNodePtr featuresNode = xmlNewChild(entriesXMLNode, NULL, + (const xmlChar*) "features", NULL); + getFeatureDetails(featuresNode, uid); + + } + error_code = contacts_list_next(call_history_list); + if (error_code != CONTACTS_ERROR_NONE) + break; + } + free(startTime); + contacts_list_destroy(call_history_list, true); +} + +/* + * { + * "remoteParty":"", + * "personId":"3" + * } + * + * buzz + * 3 + */ +static xmlNodePtr getRemotePartyDetails(xmlNodePtr remotePartiesXMLNode, + int callLogId) { + contacts_record_h call_log_record = NULL; + + int personId; + char * remoteParty = NULL; + int error_code; + + //query for all contacts with this address_book_id + contacts_filter_h filter = NULL; + contacts_list_h call_history_list = NULL; + contacts_query_h query = NULL; + + error_code = contacts_list_create(&call_history_list); + if (error_code != CONTACTS_ERROR_NONE) { + dlog_print(DLOG_ERROR, LOG_TAG, "contacts_list_create() failed: %d", + error_code); + return remotePartiesXMLNode; + } + + contacts_filter_create(_contacts_person_phone_log._uri, &filter); + contacts_filter_add_int(filter, _contacts_person_phone_log.log_id, + CONTACTS_MATCH_EQUAL, callLogId); + + contacts_query_create(_contacts_person_phone_log._uri, &query); + contacts_query_set_filter(query, filter); + + contacts_db_get_records_with_query(query, 0, 0, &call_history_list); + + do { + contacts_list_get_current_record_p(call_history_list, &call_log_record); + if (call_log_record != NULL) { + contacts_record_get_str(call_log_record, + _contacts_person_phone_log.display_name, &remoteParty); + contacts_record_get_int(call_log_record, + _contacts_person_phone_log.person_id, &personId); + + xmlNewChild(remotePartiesXMLNode, NULL, + (const xmlChar*) "remoteParty", (xmlChar*) remoteParty); + + //Accomodate 32 bit int highest value + char* personId_str = (char*) malloc(MAX_NUM_LENGTH * sizeof(char)); + snprintf(personId_str, MAX_NUM_LENGTH, "%d", personId); + xmlNewChild(remotePartiesXMLNode, NULL, (const xmlChar*) "personId", + (xmlChar*) personId_str); + free(personId_str); + } + } while (CONTACTS_ERROR_NONE == contacts_list_next(call_history_list)); + + contacts_query_destroy(query); + contacts_filter_destroy(filter); + contacts_list_destroy(call_history_list, true); + + return remotePartiesXMLNode; +} + +static void getFeatureDetails(xmlNodePtr jsonBuilder, int callLogId) { + +} + +static void convertToDateFormat(int unixTimestamp, char* startTime) { + + struct tm ts; + // Format time "ddd dd/mm/yyyy hh:mm:ss" + ts = *localtime(&unixTimestamp); + strftime(startTime, 100, "%a %d/%m/%Y %H:%M:%S", &ts); +} + +static void** get_datasource_root_element() { + if (callHistoryDatasourceRootNode == NULL) { + initialize_call_history_datasource(); + } + return callHistoryDatasourceRootNode; +} + +static void initialize_call_history_datasource() { + populate_call_history_records(); + + if (!isRefreshCallbackRegistered) { + isRefreshCallbackRegistered = true; + //Register callback functions to be invoked when a record changes. + contacts_db_add_changed_cb(_contacts_phone_log._uri, + refresh_call_history_datasource, _contacts_phone_log._uri); + contacts_db_add_changed_cb(_contacts_person_phone_log._uri, + refresh_call_history_datasource, + _contacts_person_phone_log._uri); + } +} + +static void refresh_call_history_datasource(const char * const view_uri, + void* user_data) { + xmlDocPtr oldContactsRootNode = callHistoryDatasourceRootNode[0]; + initialize_call_history_datasource(); + if ((refresh_databinding_cb != NULL) + && (is_callhistory_update_databinding_cb_registered)) { + (*refresh_databinding_cb)(); + } + xmlFreeDoc(oldContactsRootNode); +} + +static void register_datasource_update_callback(void (*func_ptr)()) { + if (!is_callhistory_update_databinding_cb_registered) { + refresh_databinding_cb = func_ptr; + is_callhistory_update_databinding_cb_registered = true; + } +} + +uib_datasource_interface* uib_call_history_datasource_get_instance() { + if (!g_uib_call_history_datasource._is_init) { + g_uib_call_history_datasource._is_init = true; + g_uib_call_history_datasource.ds_type = call_history_API; + g_uib_call_history_datasource.get_datasource_root_element = + &get_datasource_root_element; + g_uib_call_history_datasource.register_datasource_update_callback = + ®ister_datasource_update_callback; + g_uib_call_history_datasource.cleanup_datasource = &cleanup_datasource; + } + return &g_uib_call_history_datasource; +} +]]> + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_ds_handler_contacts_header.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_ds_handler_contacts_header.xsl new file mode 100644 index 0000000..5cde286 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_ds_handler_contacts_header.xsl @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_ds_handler_contacts_source.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_ds_handler_contacts_source.xsl new file mode 100644 index 0000000..e816565 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_ds_handler_contacts_source.xsl @@ -0,0 +1,877 @@ + + + + + + + + + + + + + + + + + + + + + + + +#include +#include + +#define MAX_NUM_LENGTH 12 + +static uib_datasource_interface g_uib_contacts_datasource; +static xmlDocPtr* contactsRootNode = NULL; +static bool is_contacts_update_databinding_cb_registered = false; +static bool isRefreshCallbackRegistered; + +static void (*refresh_databinding_cb)(); +static xmlDocPtr prepare_datasource_xml_tree(); +static void prepare_adressbook_filtered_contacts_list(xmlNodePtr, int); +static void get_name_object_details(xmlNodePtr, contacts_record_h*); +static void get_phone_numbers_details(xmlNodePtr, contacts_record_h*); +static void get_addresses_details(xmlNodePtr, contacts_record_h*); +static void get_anniversaries_details(xmlNodePtr, contacts_record_h*); +static void get_emails_details(xmlNodePtr, contacts_record_h*); +static void get_organizations_details(xmlNodePtr, contacts_record_h*); +static void get_urls_details(xmlNodePtr, contacts_record_h*); +static void refresh_contacts_datasource(const char*, void*); + +static bool populate_contact_records() { + if (contactsRootNode == NULL) { + contactsRootNode = (xmlDocPtr*) malloc(sizeof(xmlDocPtr)); + if (!data_contacts_common_connect()) + return false; + } + contactsRootNode[0] = prepare_datasource_xml_tree(); + return true; +} + +static void initialize_contacts_datasource() { + populate_contact_records(); + + if (!isRefreshCallbackRegistered) { + isRefreshCallbackRegistered = true; + //Register callback functions to be invoked when a record changes. + contacts_db_add_changed_cb(_contacts_address_book._uri, + refresh_contacts_datasource, NULL); + contacts_db_add_changed_cb(_contacts_contact._uri, + refresh_contacts_datasource, NULL); + contacts_db_add_changed_cb(_contacts_contact_number._uri, + refresh_contacts_datasource, NULL); + contacts_db_add_changed_cb(_contacts_contact_email._uri, + refresh_contacts_datasource, NULL); + contacts_db_add_changed_cb(_contacts_address._uri, + refresh_contacts_datasource, NULL); + contacts_db_add_changed_cb(_contacts_url._uri, + refresh_contacts_datasource, NULL); + contacts_db_add_changed_cb(_contacts_company._uri, + refresh_contacts_datasource, NULL); + } +} + +static xmlDocPtr prepare_datasource_xml_tree() { + contacts_list_h addressbook_list = NULL; + contacts_record_h address_record = NULL; + + //first get address books + int ret = contacts_db_get_all_records(_contacts_address_book._uri, 0, 0, + &addressbook_list); + + //Begin xml document + xmlDocPtr datasource_xmlDoc = xmlNewDoc(BAD_CAST "1.0"); + + //Start AddressBooks root node + xmlNodePtr addressbooks_root_node = xmlNewNode(NULL, + BAD_CAST "addressbooks"); + xmlDocSetRootElement(datasource_xmlDoc, addressbooks_root_node); + + //Iterate list of addressBooks + do { + contacts_list_get_current_record_p(addressbook_list, &address_record); + if (NULL == address_record) + break; + char *name = NULL; + bool readOnly = false; + int id; + int mode; + + contacts_record_get_int(address_record, _contacts_address_book.mode, + &mode); + readOnly = (mode == CONTACTS_ADDRESS_BOOK_MODE_READONLY); + contacts_record_get_int(address_record, + _contacts_address_book.account_id, &id); + contacts_record_get_str(address_record, _contacts_address_book.name, + &name); + + //Set id name & mode property of addressbooks property + + //Accomodate 32 bit int highest value + char* addressbookId_str = (char*) malloc(MAX_NUM_LENGTH * sizeof(char)); + snprintf(addressbookId_str, MAX_NUM_LENGTH, "%d", id); + xmlNewChild(addressbooks_root_node, NULL, (const xmlChar*) "id", + (xmlChar*) addressbookId_str); + free(addressbookId_str); + + xmlNewChild(addressbooks_root_node, NULL, (const xmlChar*) "name", + (xmlChar*) name); + + char* isReadOnlyStr = "false"; + if (readOnly) { + isReadOnlyStr = "true"; + } + xmlNewChild(addressbooks_root_node, NULL, (const xmlChar*) "readOnly", + (xmlChar*) isReadOnlyStr); + + prepare_adressbook_filtered_contacts_list(addressbooks_root_node, id); + + } while (CONTACTS_ERROR_NONE == contacts_list_next(addressbook_list)); + + ret = contacts_list_destroy(addressbook_list, true); + if (ret != 0) { + dlog_print(DLOG_ERROR, LOG_TAG, "Failed to delete addressbook_list %d", + &ret); + } + return datasource_xmlDoc; +} + +static void prepare_adressbook_filtered_contacts_list( + xmlNodePtr parent_addressbooks_root_node, int addressBookId) { + + //query for all contacts with this address_book_id + contacts_filter_h filter = NULL; + contacts_list_h contacts_list = NULL; + contacts_query_h query = NULL; + + contacts_filter_create(_contacts_contact._uri, &filter); + contacts_filter_add_int(filter, _contacts_contact.address_book_id, + CONTACTS_MATCH_EQUAL, addressBookId); + + contacts_query_create(_contacts_contact._uri, &query); + contacts_query_set_filter(query, filter); + + contacts_db_get_records_with_query(query, 0, 0, &contacts_list); + contacts_record_h contacts_record = NULL; + + int id; + do { + contacts_list_get_current_record_p(contacts_list, &contacts_record); + if (contacts_record != NULL) { + contacts_record_get_int(contacts_record, _contacts_contact.id, &id); + + //Add contacts array element to addressbooks + xmlNodePtr contacts_node = xmlNewChild( + parent_addressbooks_root_node, NULL, + (const xmlChar*) "contacts", NULL); + + //Start populating contact elements + + //Accomodate 32 bit int highest value + char* contact_id_str = (char*) malloc( + MAX_NUM_LENGTH * sizeof(char)); + snprintf(contact_id_str, MAX_NUM_LENGTH, "%d", id); + xmlNewChild(contacts_node, NULL, (const xmlChar*) "id", + (xmlChar*) contact_id_str); + free(contact_id_str); + + //Get name object details + get_name_object_details(contacts_node, &contacts_record); + + //Get phoneNumbers details + get_phone_numbers_details(contacts_node, &contacts_record); + + //Get addresses details + get_addresses_details(contacts_node, &contacts_record); + + //Get anniversaries details + get_anniversaries_details(contacts_node, &contacts_record); + + //Get emails details + get_emails_details(contacts_node, &contacts_record); + + //Get organizations details + get_organizations_details(contacts_node, &contacts_record); + + //Get Urls details + get_urls_details(contacts_node, &contacts_record); + + } + + } while (CONTACTS_ERROR_NONE == contacts_list_next(contacts_list)); + + int ret = contacts_list_destroy(contacts_list, true); + if (ret != 0) { + dlog_print(DLOG_ERROR, LOG_TAG, "Failed to delete contacts_list %d", + &ret); + } + contacts_query_destroy(query); + contacts_filter_destroy(filter); + +} + +static void get_name_object_details(xmlNodePtr parent_contact_node, + contacts_record_h* contacts_record) { + char * displayName = NULL; + char * phoneticName = NULL; + char * firstName, *lastname, *middleName, *phoneticFirstName, + *phoneticLastName, *phoneticMiddleName, *prefix, *suffix; + char * nickName = NULL; + + contacts_list_h nickname_list = NULL; + + int ret = contacts_list_create(&nickname_list); + if (ret != 0) { + dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create nickname_list %d", + &ret); + return; + } + + contacts_record_h name_record = NULL; + + contacts_record_h nickname_record = NULL; + + if (contacts_record_get_child_record_at_p((*contacts_record), + _contacts_contact.name, 0, &name_record) != 0) { + return; + } + + contacts_record_clone_child_record_list((*contacts_record), + _contacts_contact.nickname, &nickname_list); + + contacts_record_get_str(*contacts_record, _contacts_contact.display_name, + &displayName); + contacts_record_get_str(name_record, _contacts_name.first, &firstName); + contacts_record_get_str(name_record, _contacts_name.last, &lastname); + contacts_record_get_str(name_record, _contacts_name.addition, &middleName); + contacts_record_get_str(name_record, _contacts_name.suffix, &suffix); + contacts_record_get_str(name_record, _contacts_name.prefix, &prefix); + contacts_record_get_str(name_record, _contacts_name.phonetic_first, + &phoneticFirstName); + contacts_record_get_str(name_record, _contacts_name.phonetic_middle, + &phoneticMiddleName); + contacts_record_get_str(name_record, _contacts_name.phonetic_last, + &phoneticLastName); + + if (phoneticFirstName != NULL && phoneticMiddleName != NULL + && phoneticLastName != NULL) { + phoneticName = (char*) malloc( + (strlen(phoneticFirstName) + strlen(phoneticMiddleName) + + strlen(phoneticLastName) + 10) * sizeof(char)); + strcpy(phoneticName, (const char*) phoneticFirstName); + strcat(phoneticName, (const char*) phoneticMiddleName); + strcat(phoneticName, (const char*) phoneticLastName); + } + + //Begin contact.name object + xmlNodePtr name_node = xmlNewChild(parent_contact_node, NULL, + (const xmlChar*) "name", NULL); + + xmlNewChild(name_node, NULL, (const xmlChar*) "displayName", + (xmlChar*) displayName); + + xmlNewChild(name_node, NULL, (const xmlChar*) "firstName", + (xmlChar*) firstName); + + xmlNewChild(name_node, NULL, (const xmlChar*) "lastname", + (xmlChar*) lastname); + + xmlNewChild(name_node, NULL, (const xmlChar*) "middleName", + (xmlChar*) middleName); + + xmlNewChild(name_node, NULL, (const xmlChar*) "phoneticFirstName", + (xmlChar*) phoneticFirstName); + + xmlNewChild(name_node, NULL, (const xmlChar*) "phoneticLastName", + (xmlChar*) phoneticLastName); + + xmlNewChild(name_node, NULL, (const xmlChar*) "phoneticMiddleName", + (xmlChar*) phoneticMiddleName); + + xmlNewChild(name_node, NULL, (const xmlChar*) "phoneticName", + (xmlChar*) phoneticName); + + xmlNewChild(name_node, NULL, (const xmlChar*) "prefix", (xmlChar*) prefix); + + xmlNewChild(name_node, NULL, (const xmlChar*) "suffix", (xmlChar*) suffix); + + do { + + if (!contacts_list_get_current_record_p(nickname_list, + &nickname_record)) { + contacts_record_get_str(nickname_record, _contacts_nickname.name, + &nickName); + xmlNewChild(name_node, NULL, (const xmlChar*) "nickNames", + (xmlChar*) nickName); + } + } while (CONTACTS_ERROR_NONE == contacts_list_next(nickname_list)); + + contacts_list_destroy(nickname_list, true); + +} + +/** + * phoneNumbers:[ + * isDefault:"Boolean", + * label:"", + * number:"", + * types:[] + * ] + */ +static void get_phone_numbers_details(xmlNodePtr parent_contact_node, + contacts_record_h* contacts_record) { + + contacts_list_h phoneNumber_list = NULL; + int ret = contacts_list_create(&phoneNumber_list); + if (ret != 0) { + dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create phoneNumber_list %d", + &ret); + return; + } + + contacts_record_h phoneNumber_record = NULL; + + int count; + contacts_record_get_child_record_count((*contacts_record), + _contacts_contact.number, &count); + + contacts_record_clone_child_record_list((*contacts_record), + _contacts_contact.number, &phoneNumber_list); + + do { + + if (!contacts_list_get_current_record_p(phoneNumber_list, + &phoneNumber_record)) { + bool isDefault; + char* label = NULL; + char* number = NULL; + int type; + + contacts_record_get_bool(phoneNumber_record, + _contacts_contact_number.is_default, &isDefault); + + contacts_record_get_str(phoneNumber_record, + _contacts_contact_number.label, &label); + + contacts_record_get_str(phoneNumber_record, + _contacts_contact_number.number, &number); + + xmlNodePtr phoneNumbers_node = xmlNewChild(parent_contact_node, + NULL, (const xmlChar*) "phoneNumbers", NULL); + + char * isDefaultStr = "false"; + if (isDefault) { + isDefaultStr = "true"; + } + xmlNewChild(phoneNumbers_node, NULL, + (const xmlChar*) "phoneNumbers", (xmlChar*) isDefaultStr); + + xmlNewChild(phoneNumbers_node, NULL, + (const xmlChar*) "phoneNumbers", (xmlChar*) label); + + xmlNewChild(phoneNumbers_node, NULL, + (const xmlChar*) "phoneNumbers", (xmlChar*) number); + + contacts_record_get_int(phoneNumber_record, + _contacts_contact_number.type, &type); + for (int i = 0; i < 31; ++i) { + if ((type & 1 << i)) { + //Accomodate 32 bit int highest value + char* typeStr = (char*) malloc( + MAX_NUM_LENGTH * sizeof(char)); + snprintf(typeStr, MAX_NUM_LENGTH, "%d", 1 << i); + xmlNewChild(phoneNumbers_node, NULL, + (const xmlChar*) "types", (xmlChar*) typeStr); + free(typeStr); + } + if (type == 0) { + xmlNewChild(phoneNumbers_node, NULL, + (const xmlChar*) "types", (xmlChar*) "0"); + break; + } + } + } + + } while (CONTACTS_ERROR_NONE == contacts_list_next(phoneNumber_list)); + + contacts_list_destroy(phoneNumber_list, true); +} + +/** + * addresses:[ + * additionalInformation:"String", + * city:"String", + * country:"String", + * isDefault:"Boolean", + * label:"String", + * postalCode:"String", + * region:"String", + * streetAddress:"String", + * types:[ + * ] + * ] + */ +//TODO: Check correct record to map to +static void get_addresses_details(xmlNodePtr parent_contacts_node, + contacts_record_h* contacts_record) { + int address_num; + + contacts_record_get_child_record_count(*contacts_record, + _contacts_contact.address, &address_num); + contacts_record_h address_record = NULL; + + for (int i = 0; i < address_num; i++) { + + char * additionalInformation = NULL, *city = NULL, *country = NULL, + *label = NULL, *postalCode = NULL, *region = NULL, + *streetAddress = + NULL; + bool isDefault = false; + int type; + + contacts_record_get_child_record_at_p(*contacts_record, + _contacts_contact.address, i, &address_record); + if (address_record != NULL) { + contacts_record_get_bool(address_record, + _contacts_contact_number.is_default, &isDefault); + + contacts_record_get_str(address_record, _contacts_address.label, + &label); + + contacts_record_get_str(address_record, _contacts_address.country, + &country); + + contacts_record_get_str(address_record, _contacts_address.country, + &country); + + contacts_record_get_str(address_record, _contacts_address.street, + &streetAddress); + + contacts_record_get_str(address_record, _contacts_address.region, + ®ion); + + contacts_record_get_str(address_record, + _contacts_address.postal_code, &postalCode); + + contacts_record_get_str(address_record, _contacts_address.extended, + &additionalInformation); + + //TODO: For now locality is mapped to city. Look for accurate field to map to. + contacts_record_get_str(address_record, _contacts_address.locality, + &city); + + contacts_record_get_int(address_record, _contacts_address.type, + &type); + + xmlNodePtr addresses_node = xmlNewChild(parent_contacts_node, NULL, + (const xmlChar*) "addresses", NULL); + + contacts_record_get_child_record_at_p(*contacts_record, + _contacts_contact.address, i, &address_record); + + xmlNewChild(addresses_node, NULL, (const xmlChar*) "addresses", + (xmlChar*) additionalInformation); + + xmlNewChild(addresses_node, NULL, (const xmlChar*) "city", + (xmlChar*) city); + + xmlNewChild(addresses_node, NULL, (const xmlChar*) "country", + (xmlChar*) country); + + char * isDefaultStr = "false"; + if (isDefault) { + isDefaultStr = "true"; + } + xmlNewChild(addresses_node, NULL, (const xmlChar *) "isDefault", + (xmlChar*) isDefaultStr); + + xmlNewChild(addresses_node, NULL, (const xmlChar*) "label", + (xmlChar*) label); + + xmlNewChild(addresses_node, NULL, (const xmlChar*) "postalCode", + (xmlChar*) postalCode); + + xmlNewChild(addresses_node, NULL, (const xmlChar*) "region", + (xmlChar*) region); + + xmlNewChild(addresses_node, NULL, (const xmlChar*) "streetAddress", + (xmlChar*) streetAddress); + + contacts_record_get_int(address_record, _contacts_address.type, + &type); + //Only bits from 0 to 6 is used by contacts_address_type_e + for (int i = 0; i < 7; ++i) { + + if ((type & 1 << i)) { + char* typesStr = (char*) malloc( + MAX_NUM_LENGTH * sizeof(char)); + snprintf(typesStr, MAX_NUM_LENGTH, "%d", 1 << i); + xmlNewChild(addresses_node, NULL, (const xmlChar*) "types", + (xmlChar*) typesStr); + free(typesStr); + } + if (type == 0) { + xmlNewChild(addresses_node, NULL, (const xmlChar*) "types", + (xmlChar*) "0"); + break; + } + } + } + } + +} + +/** + * anniversaries:[ + * date:"String", + * label:"String" + * ] + */ +static void get_anniversaries_details(xmlNodePtr parent_contacts_node, + contacts_record_h* contacts_record) { + int anniversary_num; + + contacts_record_get_child_record_count(*contacts_record, + _contacts_contact.event, &anniversary_num); + contacts_record_h anniversary_record = NULL; + + for (int i = 0; i < anniversary_num; i++) { + //TODO: Handle calendar type for date conversion as well + char * label = NULL; + int date; + + contacts_record_get_child_record_at_p(*contacts_record, + _contacts_contact.event, i, &anniversary_record); + if (anniversary_record != NULL) { + contacts_record_get_int(anniversary_record, _contacts_event.date, + &date); + + contacts_record_get_str(anniversary_record, _contacts_event.label, + &label); + + xmlNodePtr anniversaries_node = xmlNewChild(parent_contacts_node, + NULL, (const xmlChar*) "anniversaries", NULL); + + contacts_record_get_child_record_at_p(*contacts_record, + _contacts_contact.event, i, &anniversary_record); + + char* dateStr = (char*) malloc( + MAX_NUM_LENGTH * sizeof(char)); + snprintf(dateStr, MAX_NUM_LENGTH, "%d", date); + xmlNewChild(anniversaries_node, NULL, (const xmlChar*) "date", + (xmlChar*) dateStr); + free(dateStr); + + xmlNewChild(anniversaries_node, NULL, (const xmlChar*) "label", + (xmlChar*) label); + } + } +} + +/** + * emails:[ + * email:"String", + * isDefault:"Boolean", + * label:"String", + * types:[] + * ], + */ +static void get_emails_details(xmlNodePtr parent_contacts_node, + contacts_record_h* contacts_record) { + int emails_num; + + contacts_record_get_child_record_count(*contacts_record, + _contacts_contact.email, &emails_num); + contacts_record_h email_record = NULL; + + for (int i = 0; i < emails_num; i++) { + + char * email = NULL, *label = NULL; + bool isDefault = false; + + int type; + + contacts_record_get_child_record_at_p(*contacts_record, + _contacts_contact.email, i, &email_record); + if (email_record != NULL) { + contacts_record_get_str(email_record, _contacts_contact_email.label, + &label); + contacts_record_get_str(email_record, _contacts_contact_email.email, + &email); + + xmlNodePtr email_node = xmlNewChild(parent_contacts_node, NULL, + (const xmlChar*) "emails", NULL); + + char * isDefaultStr = "false"; + if (isDefault) { + isDefaultStr = "true"; + } + xmlNewChild(email_node, NULL, (const xmlChar*) "isDefault", + (xmlChar*) isDefaultStr); + + xmlNewChild(email_node, NULL, (const xmlChar*) "email", + (xmlChar*) email); + + xmlNewChild(email_node, NULL, (const xmlChar*) "label", + (xmlChar*) label); + + contacts_record_get_int(email_record, _contacts_email.type, &type); + //Only bits from 0 to 4 is used by contacts_email_type_e + for (int i = 0; i < 4; ++i) { + + if ((type & 1 << i)) { + char* typesStr = (char*) malloc( + MAX_NUM_LENGTH * sizeof(char)); + snprintf(typesStr, MAX_NUM_LENGTH, "%d", 1 << i); + xmlNewChild(email_node, NULL, (const xmlChar*) "types", + (xmlChar*) typesStr); + free(typesStr); + } + if (type == 0) { + xmlNewChild(email_node, NULL, (const xmlChar*) "types", + (xmlChar*) "0"); + break; + } + } + } + } +} + +static void get_organizations_details(xmlNodePtr parent_contact_node, + contacts_record_h* contacts_record) { + int orgs_num; + + contacts_record_get_child_record_count(*contacts_record, + _contacts_contact.company, &orgs_num); + contacts_record_h org_record = NULL; + + for (int i = 0; i < orgs_num; i++) { + + char * description = NULL, *assistant = NULL, *label = NULL, + *department = + NULL, *location = NULL, *logoURI = NULL, *name = NULL, + *phoneticName = NULL, *role = NULL, *title = NULL; + + int type; + + contacts_record_get_child_record_at_p(*contacts_record, + _contacts_contact.company, i, &org_record); + if (org_record != NULL) { + + contacts_record_get_str(org_record, _contacts_company.label, + &label); + + contacts_record_get_str(org_record, + _contacts_company.assistant_name, &assistant); + + contacts_record_get_str(org_record, _contacts_company.department, + &department); + + contacts_record_get_str(org_record, _contacts_company.description, + &description); + + contacts_record_get_str(org_record, _contacts_company.location, + &location); + + contacts_record_get_str(org_record, _contacts_company.logo, + &logoURI); + + contacts_record_get_str(org_record, _contacts_company.name, &name); + + contacts_record_get_str(org_record, _contacts_company.phonetic_name, + &phoneticName); + + contacts_record_get_str(org_record, _contacts_company.role, &role); + + contacts_record_get_str(org_record, _contacts_company.job_title, + &title); + + contacts_record_get_int(org_record, _contacts_company.type, &type); + + xmlNodePtr organization_node = xmlNewChild(parent_contact_node, + NULL, (const xmlChar*) "organizations", NULL); + + + contacts_record_get_child_record_at_p(*contacts_record, + _contacts_contact.url, i, &org_record); + + xmlNewChild(organization_node, NULL, (const xmlChar*) "name", + (xmlChar*) name); + + xmlNewChild(organization_node, NULL, (const xmlChar*) "logoURI", + (xmlChar*) logoURI); + + xmlNewChild(organization_node, NULL, (const xmlChar*) "description", + (xmlChar*) description); + + xmlNewChild(organization_node, NULL, (const xmlChar*) "assistant", + (xmlChar*) assistant); + + xmlNewChild(organization_node, NULL, (const xmlChar*) "department", + (xmlChar*) department); + + xmlNewChild(organization_node, NULL, (const xmlChar*) "location", + (xmlChar*) location); + + xmlNewChild(organization_node, NULL, + (const xmlChar*) "phoneticName", (xmlChar*) phoneticName); + + xmlNewChild(organization_node, NULL, (const xmlChar*) "role", + (xmlChar*) role); + + xmlNewChild(organization_node, NULL, (const xmlChar*) "title", + (xmlChar*) title); + + char* typeStr = (char*) malloc( + MAX_NUM_LENGTH * sizeof(char)); + snprintf(typeStr, MAX_NUM_LENGTH, "%d", type); + xmlNewChild(organization_node, NULL, (const xmlChar*) "type", + (xmlChar*) typeStr); + free(typeStr); + + xmlNewChild(organization_node, NULL, (const xmlChar*) "label", + (xmlChar*) label); + } + } +} + +/** + * urls:[ + * label:"", + * type:"", + * url:"" + * ] + */ +static void get_urls_details(xmlNodePtr parent_contact_node, + contacts_record_h* contacts_record) { + int urls_num; + + contacts_record_get_child_record_count(*contacts_record, + _contacts_contact.url, &urls_num); + contacts_record_h url_record = NULL; + + for (int i = 0; i < urls_num; i++) { + + char * url = NULL, *label = NULL; + + int type; + + contacts_record_get_str(url_record, _contacts_url.label, &label); + + contacts_record_get_str(url_record, _contacts_url.url, &url); + + contacts_record_get_int(url_record, _contacts_url.type, &type); + contacts_record_get_child_record_at_p(*contacts_record, + _contacts_contact.url, i, &url_record); + if (url_record != NULL) { + + xmlNodePtr url_node = xmlNewChild(parent_contact_node, NULL, + (const xmlChar*) "urls", + NULL); + + xmlNewChild(url_node, NULL, (const xmlChar*) "url", (xmlChar*) url); + + char* typeStr = (char*) malloc( + MAX_NUM_LENGTH * sizeof(char)); + snprintf(typeStr, MAX_NUM_LENGTH, "%d", type); + xmlNewChild(url_node, NULL, (const xmlChar*) "type", + (xmlChar*) typeStr); + free(typeStr); + + xmlNewChild(url_node, NULL, (const xmlChar*) "label", + (xmlChar*) label); + } + } +} + +static void cleanup_datasource() { + data_contacts_common_disconnect(); + if (isRefreshCallbackRegistered) { + isRefreshCallbackRegistered = false; + //Un-register callback functions to be invoked when a record changes. + contacts_db_remove_changed_cb(_contacts_address_book._uri, + refresh_contacts_datasource, NULL); + contacts_db_remove_changed_cb(_contacts_contact._uri, + refresh_contacts_datasource, NULL); + contacts_db_remove_changed_cb(_contacts_contact_number._uri, + refresh_contacts_datasource, NULL); + contacts_db_remove_changed_cb(_contacts_contact_email._uri, + refresh_contacts_datasource, NULL); + contacts_db_remove_changed_cb(_contacts_address._uri, + refresh_contacts_datasource, NULL); + contacts_db_remove_changed_cb(_contacts_url._uri, + refresh_contacts_datasource, NULL); + contacts_db_remove_changed_cb(_contacts_company._uri, + refresh_contacts_datasource, NULL); + } + if (contactsRootNode != NULL && contactsRootNode[0] != NULL) { + xmlFreeDoc(contactsRootNode[0]); + contactsRootNode = NULL; + } + is_contacts_update_databinding_cb_registered = false; +} + +static void register_refresh_callback(void (*func_ptr)()) { + if (!is_contacts_update_databinding_cb_registered) { + refresh_databinding_cb = func_ptr; + is_contacts_update_databinding_cb_registered = true; + } +} + +static void** get_datasource_root_element() { + if (contactsRootNode == NULL) { + initialize_contacts_datasource(); + } + return contactsRootNode; +} + +static void refresh_contacts_datasource(const char* view_uri, void* user_data) { + xmlDocPtr oldContactsRootNode = contactsRootNode[0]; + initialize_contacts_datasource(); + if ((refresh_databinding_cb != NULL) + && (is_contacts_update_databinding_cb_registered)) { + (*refresh_databinding_cb)(); + } + xmlFreeDoc(oldContactsRootNode); +} + +uib_datasource_interface* uib_contacts_datasource_get_instance() { + if (!g_uib_contacts_datasource._is_init) { + g_uib_contacts_datasource._is_init = true; + g_uib_contacts_datasource.ds_type = contacts_API; + g_uib_contacts_datasource.get_datasource_root_element = + &get_datasource_root_element; + g_uib_contacts_datasource.register_datasource_update_callback = + ®ister_refresh_callback; + g_uib_contacts_datasource.cleanup_datasource = &cleanup_datasource; + } + return &g_uib_contacts_datasource; +} +]]> + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_ds_handler_remote_header.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_ds_handler_remote_header.xsl new file mode 100644 index 0000000..6e119bb --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_ds_handler_remote_header.xsl @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + +#include "uib_datasources.h" + + +#define BUFFER_SIZE 1024 +#define MAX_ALLOWED_SOURCES 20 + +typedef struct { + Ecore_Thread *thread; + CURL *curl; + char url[BUFFER_SIZE]; + double curl_filesize; + char filesize_buffer[BUFFER_SIZE]; + + Eina_Lock mutex; + bool downloading; + bool cancel_requested; + bool global_cleanup_needed; + bool cleanup_done; + bool exiting; + bool thread_running; + + char filename[BUFFER_SIZE]; + char filename_without_path[BUFFER_SIZE]; + FILE *stream; + char *response_data; + char *prev_response_data; + int internal_storage_id; + + int polling_interval; + long timeout_ms; + char *source_name; + int registry_id; + Ecore_Poller *poller; + UIB_DATASOURCE_CONTENT_TYPE content_type; +} remote_ds_s; + +uib_datasource_interface* uib_remote_datasource_get_instance(); +void set_remote_datasource(remote_ds_s *); + +#endif +]]> + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_ds_handler_remote_source.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_ds_handler_remote_source.xsl new file mode 100644 index 0000000..b57d4e6 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_ds_handler_remote_source.xsl @@ -0,0 +1,537 @@ + + + + + + + + + + + + + + + + + + + + + + + +#include +#include + +static uib_datasource_interface g_uib_remote_datasource; +static xmlDocPtr* remoteDatasourceRootNode = NULL; + +static bool is_remote_datasource_update_databinding_cb_registered = false; +static bool isRefreshCallbackRegistered[MAX_ALLOWED_SOURCES]; +static remote_ds_s *current_ds = NULL; +static remote_ds_s *registered_sources[MAX_ALLOWED_SOURCES]; +static int registered_source_count = 0; + +static size_t curl_write_cb(void *, size_t, size_t, void *); +static void (*refresh_databinding_cb)(); +static JsonNode* prepare_datasource_tree(); +static void refresh_remote_datasource(xmlDocPtr, remote_ds_s*); +static size_t curl_header_cb(void *, size_t, size_t, void *); +int curl_progress_cb(void *, double, double, double, double); +static Eina_Bool remotesource_call_job(void *); +bool parse_json_data(remote_ds_s*, xmlDocPtr*); +bool parse_xml_data(remote_ds_s*, xmlDocPtr*); + +static bool populate_remote_records() { + dlog_print(DLOG_DEBUG, LOG_TAG, "Entering %s - ", __func__); + if (remoteDatasourceRootNode == NULL) { + remoteDatasourceRootNode = (xmlDocPtr*) malloc( + sizeof(xmlDocPtr) * MAX_ALLOWED_SOURCES); + for (int i = 0; i < MAX_ALLOWED_SOURCES; ++i) { + remoteDatasourceRootNode[i] = NULL; + } + } + + JsonNode * datasource_root_node = prepare_datasource_tree(); + remoteDatasourceRootNode[current_ds->registry_id] = convert_json_to_xml( + datasource_root_node); + json_node_free(datasource_root_node); + dlog_print(DLOG_INFO, LOG_TAG, "%s - remote_source name %s rootnode %d", + __func__, current_ds->source_name, + remoteDatasourceRootNode[current_ds->registry_id]); + dlog_print(DLOG_DEBUG, LOG_TAG, "Exiting %s - ", __func__); + return true; +} + +static void initialize_remote_datasource() { + dlog_print(DLOG_DEBUG, LOG_TAG, "Entering %s - %s", __func__, + current_ds->source_name); + populate_remote_records(); + + if (!isRefreshCallbackRegistered[current_ds->registry_id]) { + isRefreshCallbackRegistered[current_ds->registry_id] = true; + //Register callback functions to be invoked when a record changes. + //Poller is not enabled if polling_interval is set to -1 + if (current_ds->polling_interval != -1) { + current_ds->poller = ecore_poller_add(ECORE_POLLER_CORE, + (current_ds->polling_interval / 1000), + remotesource_call_job, current_ds); //Or use ecore_timer for accurate timer. Though this one takes care of power conservation as well + ecore_poller_poll_interval_set(ECORE_POLLER_CORE, 1); + if (current_ds->poller == NULL) { + dlog_print(DLOG_ERROR, LOG_TAG, + "%s poller creation failed for remote datasource - %s", + __func__, current_ds->source_name); + } else { + dlog_print(DLOG_INFO, LOG_TAG, + "%s poller creation succeeded for remote datasource - %s", + __func__, current_ds->source_name); + } + } + } +} + +void curl_cleanup(remote_ds_s *ds) { + if (ds == NULL) { + dlog_print(DLOG_ERROR, LOG_TAG, "cleanup(): ad is NULL"); + return; + } + + if (ds->cleanup_done) + return; + + if (ds->curl != NULL) { + curl_easy_cleanup(ds->curl); + dlog_print(DLOG_DEBUG, LOG_TAG, "curl_easy_cleanup(curl_handler)"); + } else + dlog_print(DLOG_DEBUG, LOG_TAG, "cleanup(): curl_handler is NULL"); + + ds->cleanup_done = true; +} + +static void download_thread(void *data, Ecore_Thread *thread) { + dlog_print(DLOG_DEBUG, LOG_TAG, "Enter %s - ", __func__); + CURL *curl; + remote_ds_s *this_ds = (remote_ds_s*) data; + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - curl url%s", __func__, this_ds->url); + + // Start a libcurl easy session + curl = curl_easy_init(); + this_ds->curl = curl; + dlog_print(DLOG_DEBUG, LOG_TAG, "curl_easy_init()"); + this_ds->downloading = true; + this_ds->thread_running = true; + this_ds->cleanup_done = false; + //Reset response_data + strcpy(this_ds->response_data, ""); + // Downloading header + if (curl) { + // Set options for a curl easy handle + CURLcode error_code = curl_easy_setopt(curl, CURLOPT_URL, this_ds->url); + dlog_print(DLOG_DEBUG, LOG_TAG, + "curl_easy_setopt(curl, CURLOPT_URL, this_ds->url): %s (%d)", + curl_easy_strerror(error_code), error_code); + + error_code = curl_easy_setopt(curl, CURLOPT_FILETIME, 1L); + dlog_print(DLOG_DEBUG, LOG_TAG, + "curl_easy_setopt(curl, CURLOPT_FILETIME, 1L): %s (%d)", + curl_easy_strerror(error_code), error_code); + + error_code = curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); + dlog_print(DLOG_DEBUG, LOG_TAG, + "curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L): %s (%d)", + curl_easy_strerror(error_code), error_code); + + error_code = curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, + curl_header_cb); + dlog_print(DLOG_DEBUG, LOG_TAG, + "curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_cb): %s (%d)", + curl_easy_strerror(error_code), error_code); + + // Enable the built-in progress meter + error_code = curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); + dlog_print(DLOG_DEBUG, LOG_TAG, + "curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L): %s (%d)", + curl_easy_strerror(error_code), error_code); + + // Set the progress callback + error_code = curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, + curl_progress_cb); + dlog_print(DLOG_DEBUG, LOG_TAG, + "curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_cb): %s (%d)", + curl_easy_strerror(error_code), error_code); + + // Set progress callback data + error_code = curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, this_ds); + dlog_print(DLOG_DEBUG, LOG_TAG, + "curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, this_ds): %s (%d)", + curl_easy_strerror(error_code), error_code); + + // Set options for a curl easy handle + error_code = curl_easy_setopt(curl, CURLOPT_WRITEDATA, this_ds); + dlog_print(DLOG_DEBUG, LOG_TAG, + "curl_easy_setopt(curl, CURLOPT_WRITEDATA, this_ds): %s (%d)", + curl_easy_strerror(error_code), error_code); + + error_code = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, + curl_write_cb); + dlog_print(DLOG_DEBUG, LOG_TAG, + "curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb): %s (%d)", + curl_easy_strerror(error_code), error_code); + + // Set timeout option for curl easy handle + error_code = curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, + this_ds->timeout_ms); + dlog_print(DLOG_DEBUG, LOG_TAG, + "curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, this_ds): %s (%d)", + curl_easy_strerror(error_code), error_code); + + // Disable SSL verify for curl call + error_code = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE); + dlog_print(DLOG_DEBUG, LOG_TAG, + "curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE): %s (%d)", + curl_easy_strerror(error_code), error_code); + + // Perform a blocking file transfer + error_code = curl_easy_perform(curl); + dlog_print(DLOG_DEBUG, LOG_TAG, "curl_easy_perform(curl): %s (%d)", + curl_easy_strerror(error_code), error_code); + if (error_code == CURLE_ABORTED_BY_CALLBACK) { + curl_cleanup(this_ds); + this_ds->downloading = false; + return; + } else if (error_code != CURLE_OK) { + curl_cleanup(this_ds); + this_ds->downloading = false; + dlog_print(DLOG_DEBUG, LOG_TAG, "curl error: %s (%d)\n", + curl_easy_strerror(error_code), error_code); + return; + } + } else { + dlog_print(DLOG_ERROR, LOG_TAG, "curl initialization failed."); + } + dlog_print(DLOG_DEBUG, LOG_TAG, "Exit %s - %s", __func__); +} + +static void thread_end_cleanup(remote_ds_s *ds) { + ds->downloading = false; + ds->thread_running = false; + curl_cleanup(ds); + dlog_print(DLOG_DEBUG, LOG_TAG, "thread_end_cleanup(): freeing lock"); + eina_lock_release(&ds->mutex); +} + +static void download_thread_cancel_cb(void *data, Ecore_Thread *thread) { + dlog_print(DLOG_DEBUG, LOG_TAG, "Entering %s - ", __func__); + + if (data == NULL) { + dlog_print(DLOG_ERROR, LOG_TAG, "data is NULL"); + return; + } + + remote_ds_s *ds = (remote_ds_s *) data; + thread_end_cleanup(ds); + dlog_print(DLOG_DEBUG, LOG_TAG, "Exiting %s - ", __func__); +} + +bool parse_json_data(remote_ds_s* ds, xmlDocPtr* rootNode) { + JsonParser* parser = json_parser_new(); + bool is_data_parsing_successfull = false; + GError* error = NULL; + if (!json_parser_load_from_data(parser, ds->response_data, + strlen(ds->response_data), &error)) { + dlog_print(DLOG_ERROR, LOG_TAG, "JSON parser error:%s", error->message); + g_error_free(error); + } else { + JsonNode* response_root_node = json_node_copy( + json_parser_get_root(parser)); + *rootNode = convert_json_to_xml(response_root_node); + json_node_free(response_root_node); + g_object_unref(parser); + is_data_parsing_successfull = true; + } + return is_data_parsing_successfull; +} + +bool parse_xml_data(remote_ds_s* ds, xmlDocPtr* rootNode) { + bool is_data_parsing_successfull = false; + xmlDocPtr parsedXMLDoc = xmlReadMemory(ds->response_data, + strlen(ds->response_data), NULL, NULL, 0); + if (parsedXMLDoc != NULL) { + is_data_parsing_successfull = true; + *rootNode = parsedXMLDoc; + } else { + dlog_print(DLOG_ERROR, LOG_TAG, "XML parser error:"); + } + return is_data_parsing_successfull; +} + +static void download_thread_end_cb(void *data, Ecore_Thread *thread) { + remote_ds_s *ds = (remote_ds_s *) data; + dlog_print(DLOG_DEBUG, LOG_TAG, "Entering %s - for ", __func__, + ds->source_name); + + if (data == NULL) { + dlog_print(DLOG_ERROR, LOG_TAG, "%s - received curl data is NULL", + __func__); + return; + } + dlog_print(DLOG_DEBUG, LOG_TAG, "%s data received - %s", __func__, + ds->response_data); + if (strcmp(ds->response_data, ds->prev_response_data) != 0) { + dlog_print(DLOG_INFO, LOG_TAG, "%s New response data received for %s", + __func__, ds->source_name); + xmlDocPtr rootNode = NULL; + bool is_data_parsed = false; + if (ds->content_type == UIB_JSON) { + is_data_parsed = parse_json_data(ds, &rootNode); + } else if (ds->content_type == UIB_XML) { + is_data_parsed = parse_xml_data(ds, &rootNode); + } + if (is_data_parsed) { + //Copy this response for comparison + ds->prev_response_data = realloc(ds->prev_response_data, + strlen(ds->response_data)); + if (ds->prev_response_data == NULL) { + /* out of memory! */ + dlog_print(DLOG_ERROR, LOG_TAG, + "%s not enough memory (realloc returned NULL) for response caching\n"); + + } else { + memcpy(ds->prev_response_data, ds->response_data, + strlen(ds->response_data) * sizeof(char)); + } + //get_json_data_from_node(rootNode); + refresh_remote_datasource(rootNode, ds); + } + } else { + dlog_print(DLOG_INFO, LOG_TAG, + "%s Received same response. Skipping databinding refresh for %s", + __func__, ds->source_name); + } + ds->downloading = false; + thread_end_cleanup(ds); + dlog_print(DLOG_DEBUG, LOG_TAG, "Exiting %s - for ", __func__, + ds->source_name); +} + +static void download_feedback_cb(void *data, Ecore_Thread *thread, + void *msg_data) { + dlog_print(DLOG_DEBUG, LOG_TAG, "feedback received"); +} + +static Eina_Bool remotesource_call_job(void * datasource) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - for datasource %s", __func__, + ((remote_ds_s*) datasource)->source_name); + remote_ds_s * this_ds = (remote_ds_s *) datasource; + if (this_ds->thread_running == false) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s: taking lock", __func__); + eina_lock_take(&this_ds->mutex); + dlog_print(DLOG_DEBUG, LOG_TAG, "%s:: lock taken", __func__); + this_ds->thread = ecore_thread_feedback_run(download_thread, + download_feedback_cb, download_thread_end_cb, + download_thread_cancel_cb, this_ds, EINA_FALSE); + if (this_ds->thread != NULL) { + dlog_print(DLOG_DEBUG, LOG_TAG, + "%s - new curl thread started for %s", __func__, + this_ds->source_name); + } else { + dlog_print(DLOG_ERROR, LOG_TAG, + "%s - thread creation failed for %s", __func__, + this_ds->source_name); + } + + } else { + dlog_print(DLOG_INFO, LOG_TAG, + "%s - another curl thread running for %s", __func__, + this_ds->source_name); + } + + return ECORE_CALLBACK_RENEW; +} + +static JsonNode* prepare_datasource_tree() { + + remotesource_call_job(current_ds); + + return json_node_new(JSON_NODE_OBJECT); +} + +static size_t curl_write_cb(void *buffer, size_t size, size_t nitems, + void *data) { + dlog_print(DLOG_DEBUG, LOG_TAG, "Entering %s - ", __func__); + if (!data) { + dlog_print(DLOG_ERROR, LOG_TAG, "%s received curl data is NULL", + __func__); + return 0; + } + remote_ds_s * this_ds = (remote_ds_s *) data; + size_t realsize = size * nitems; + int existing_len = strlen(this_ds->response_data); + size_t existing_size = existing_len * sizeof(char); + + char * received_response = (char*) malloc(existing_size + 1); + strcpy(received_response, this_ds->response_data); + + this_ds->response_data = realloc(this_ds->response_data, + existing_size + realsize + 1); + if (this_ds->response_data == NULL) { + /* out of memory! */ + dlog_print(DLOG_ERROR, LOG_TAG, + "not enough memory (realloc returned NULL)\n"); + return 0; + } + strcpy(this_ds->response_data, received_response); + free(received_response); + memcpy(&(this_ds->response_data[existing_len]), buffer, realsize); + this_ds->response_data[existing_size + realsize] = '\0'; + + dlog_print(DLOG_DEBUG, LOG_TAG, "new chunk"); + + this_ds->downloading = false; + + dlog_print(DLOG_DEBUG, LOG_TAG, "Exiting %s - ", __func__); + + return realsize; +} + +int curl_progress_cb(void *data, double dltotal, double dlnow, double ultotal, + double ulnow) { + if (!data) { + dlog_print(DLOG_ERROR, LOG_TAG, "data is NULL"); + return 0; + } + + double progress = dlnow / dltotal; + char str_buffer[BUFFER_SIZE]; + + dlog_print(DLOG_DEBUG, LOG_TAG, "%s progress: dlnow - %d dltotal - %d", + __func__, (int) dlnow, (int) dltotal); +// Check whether the progress is 100% + if (dlnow == dltotal) { + //this_ds->downloading = false; + } else { + snprintf(str_buffer, BUFFER_SIZE, "Download progress: %d%%", + (int) (progress * 100)); + } +// Continue downloading + return 0; +} + +static size_t curl_header_cb(void *ptr, size_t size, size_t nitems, void *data) { + char buffer[(size * nitems) + 1]; // +1 for NULL-termination + + snprintf(buffer, sizeof(buffer), "%s", (char *) ptr); + dlog_print(DLOG_DEBUG, LOG_TAG, "Header: %s", buffer); + + return size * nitems; +} + +void set_remote_datasource(remote_ds_s *this_ds) { + dlog_print(DLOG_DEBUG, LOG_TAG, "Entering %s - for datasource %s", __func__, + this_ds->source_name); + current_ds = this_ds; + bool already_registered = false; + for (int i = 0; i < registered_source_count; ++i) { + if (!strcmp(this_ds->source_name, registered_sources[i]->source_name)) { + already_registered = true; + break; + } + } + if (!already_registered && registered_source_count < MAX_ALLOWED_SOURCES) { + this_ds->registry_id = registered_source_count; + registered_sources[registered_source_count++] = this_ds; + } + dlog_print(DLOG_DEBUG, LOG_TAG, + "Exiting %s - for datasource %s with registry id : %d", __func__, + this_ds->source_name, this_ds->registry_id); +} + +static void cleanup_datasource() { + + is_remote_datasource_update_databinding_cb_registered = false; + + //Delete pollers and cleanup datasource + for (int i = 0; i < registered_source_count; ++i) { + isRefreshCallbackRegistered[i] = false; + ecore_poller_del(registered_sources[i]->poller); + curl_cleanup(registered_sources[i]); + + if (remoteDatasourceRootNode != NULL + && remoteDatasourceRootNode[i] != NULL) { + xmlFreeDoc(remoteDatasourceRootNode[i]); + } + } + free(remoteDatasourceRootNode); + remoteDatasourceRootNode = NULL; + curl_global_cleanup(); +} + +static void register_refresh_callback(void (*func_ptr)()) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (!is_remote_datasource_update_databinding_cb_registered) { + refresh_databinding_cb = func_ptr; + is_remote_datasource_update_databinding_cb_registered = true; + } +} + +static void** get_datasource_root_element() { + dlog_print(DLOG_DEBUG, LOG_TAG, "Entering %s - for current datasource %s", + __func__, current_ds->source_name); + if ((remoteDatasourceRootNode == NULL) + || (remoteDatasourceRootNode[current_ds->registry_id] == NULL)) { + initialize_remote_datasource(); + } + dlog_print(DLOG_DEBUG, LOG_TAG, "Exiting %s - for current datasource %s", + __func__, current_ds->source_name); + return &remoteDatasourceRootNode[current_ds->registry_id]; +} + +static void refresh_remote_datasource(xmlDocPtr rootNode, remote_ds_s * ds) { + dlog_print(DLOG_DEBUG, LOG_TAG, "Entering %s - for %s", __func__, + ds->source_name); + xmlDocPtr oldRemoteRootNode = remoteDatasourceRootNode[ds->registry_id]; + remoteDatasourceRootNode[ds->registry_id] = rootNode; + if ((refresh_databinding_cb != NULL) + && (is_remote_datasource_update_databinding_cb_registered)) { + (*refresh_databinding_cb)(); + } + if (oldRemoteRootNode != NULL) { + xmlFreeDoc(oldRemoteRootNode); + } + dlog_print(DLOG_DEBUG, LOG_TAG, "Exiting %s - for %s", __func__, + ds->source_name); +} + +uib_datasource_interface* uib_remote_datasource_get_instance() { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (!g_uib_remote_datasource._is_init) { + g_uib_remote_datasource._is_init = true; + g_uib_remote_datasource.ds_type = remote_API; + g_uib_remote_datasource.get_datasource_root_element = + &get_datasource_root_element; + g_uib_remote_datasource.register_datasource_update_callback = + ®ister_refresh_callback; + g_uib_remote_datasource.cleanup_datasource = &cleanup_datasource; + CURLcode error_code = curl_global_init(CURL_GLOBAL_ALL); + if (CURLE_OK != error_code) { + dlog_print(DLOG_ERROR, LOG_TAG, "%s cURL initialization failed: %s", + __func__, curl_easy_strerror(error_code)); + } + } + return &g_uib_remote_datasource; +} +]]> + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_ds_handler_static_header.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_ds_handler_static_header.xsl new file mode 100644 index 0000000..9eb252f --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_ds_handler_static_header.xsl @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_ds_handler_static_source.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_ds_handler_static_source.xsl new file mode 100644 index 0000000..9ef46ae --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_ds_handler_static_source.xsl @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +static xmlDocPtr* staticDatasourceRootNode = NULL; + +static uib_datasource_interface g_uib_static_datasource; + +static void cleanup_datasource() { + +} + +void** get_datasource_root_element() { + + staticDatasourceRootNode = (xmlDocPtr*)malloc(sizeof(xmlDocPtr)); + + return staticDatasourceRootNode; +} + +static void register_datasource_update_callback(void (*func_ptr)()) { + //Empty as static source is immutable +} + +uib_datasource_interface* uib_static_datasource_get_instance() { + if (!g_uib_static_datasource._is_init) { + g_uib_static_datasource._is_init = true; + g_uib_static_datasource.ds_type = static_source; + g_uib_static_datasource.get_datasource_root_element = + &get_datasource_root_element; + g_uib_static_datasource.register_datasource_update_callback = + ®ister_datasource_update_callback; + g_uib_static_datasource.cleanup_datasource = &cleanup_datasource; + } + return &g_uib_static_datasource; +} +]]> + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_manager_header.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_manager_header.xsl new file mode 100644 index 0000000..28aba92 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_manager_header.xsl @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#include "uib_views_binding.h" +#include "uib_databinding_common.h" +#include "databinding/uib_widget_handler_hoverselitem.h" +#include "databinding/uib_widget_handler_hoversel.h" +#include "databinding/uib_widget_handler_button.h" +#include "databinding/uib_widget_handler_checkbox.h" +#include "databinding/uib_widget_handler_label.h" +#include "databinding/uib_widget_handler_list.h" +#include "databinding/uib_widget_handler_listitem.h" +#include "databinding/uib_widget_handler_radio.h" +#include "uib_views.h"]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_manager_source.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_manager_source.xsl new file mode 100644 index 0000000..933f498 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_manager_source.xsl @@ -0,0 +1,221 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +widgetType); + switch (binding_info->widgetType) { +]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +dataModelContext) { + widget_handler_st *widget_handler = NULL; + + Databinding_callback binding_cb = NULL; + + get_widget_handler(view_bindings[i], &widget_handler); + if (widget_handler != NULL) { + binding_cb = widget_handler->binding_cb; + if (binding_cb != NULL) { + binding_cb(view_bindings[i]->widget, + view_bindings[i]->binding_element_path, + view_bindings[i]->binding_type, + view_bindings[i]->dataModelContext->root_element, + view_bindings[i]->dataModelContext->datasource->ds_content_type); + } + } + } + } + } +} + + +static void refresh_databinding(){ + dlog_print(DLOG_DEBUG,LOG_TAG,"%s - ",__func__); + perform_databinding(currentViewContext); +} + +static void register_refresh_databinding_callback_to_bound_datamodels() { + uib_datamodels_get_instance()->register_attached_datasource_update_cb( + &refresh_databinding); +} + +static void cleanup_databinding() { + dlog_print(DLOG_DEBUG,LOG_TAG,"%s - ",__func__); + uib_databindings_get_instance()->free_all_databindings(); + uib_datamodels_get_instance()->free_all_datamodels(); + uib_datasource_manager_get_instance()->free_all_datasources(); +} + +uib_databinding_manager_st* uib_databinding_manager_get_instance() { + if (!g_uib_databinding_manager._is_init) { + g_uib_databinding_manager._is_init = true; + register_refresh_databinding_callback_to_bound_datamodels(); + g_uib_databinding_manager.free_all_databinding_resources = + &cleanup_databinding; + g_uib_databinding_manager.perform_databinding = &perform_databinding; + } + return &g_uib_databinding_manager; +} +]]> + + + \ No newline at end of file diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_view_bindings_header.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_view_bindings_header.xsl new file mode 100644 index 0000000..57d58db --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_view_bindings_header.xsl @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_view_bindings_source.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_view_bindings_source.xsl new file mode 100644 index 0000000..24bd402 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_view_bindings_source.xsl @@ -0,0 +1,192 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_views_binding_header.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_views_binding_header.xsl new file mode 100644 index 0000000..26a42d7 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_views_binding_header.xsl @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +typedef struct { + + Evas_Object* widget; + char* widgetPropertyId; + widget_type widgetType; + //Dot-separated path to bound element in data model + char* binding_element_path; + widget_binding_type binding_type; + uib_datamodel_context* dataModelContext; + +} uib_binding_info; + +typedef struct { + bool _is_init; + widget_binding_type (*get_binding_type)(const char* ); + void (*free_all_databindings)(); +} uib_databindings_st; + +uib_databindings_st* uib_databindings_get_instance(); +#endif +]]> + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_views_binding_source.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_views_binding_source.xsl new file mode 100644 index 0000000..3f6b8e3 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_views_binding_source.xsl @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_button_header.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_button_header.xsl new file mode 100644 index 0000000..5ae4d87 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_button_header.xsl @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_button_source.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_button_source.xsl new file mode 100644 index 0000000..f7f47d4 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_button_source.xsl @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#include + +static widget_handler_st button_widget_handler; + +static void pre_binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (binding_type == text) { + //Do nothing + } +} + +static void post_binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (binding_type == text) { + // Show the button + evas_object_show(widget); + } +} + +static void bind_data_callback(Evas_Object* widget, + widget_binding_type binding_type, char* value_data) { + if (binding_type == text) { + elm_object_text_set(widget, _UIB_LOCALE(value_data)); + } +} + +static void binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (root_element == NULL) { + return; + } + bind_data(widget, binding_element_path, binding_type, root_element, + pre_binding_cb, bind_data_callback, post_binding_cb, + ds_content_type); +} + +widget_handler_st* button_widget_handler_get_instance() { + if (button_widget_handler.is_init == false) { + button_widget_handler.is_init = true; + button_widget_handler.binding_cb = &binding_cb; + } + return &button_widget_handler; +} +]]> + + \ No newline at end of file diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_checkbox_header.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_checkbox_header.xsl new file mode 100644 index 0000000..67d1414 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_checkbox_header.xsl @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_checkbox_source.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_checkbox_source.xsl new file mode 100644 index 0000000..ed40b04 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_checkbox_source.xsl @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#include + +static widget_handler_st checkbox_widget_handler; + +static void pre_binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (binding_type == text) { + //Do nothing + } +} + +static void bind_data_callback(Evas_Object* widget, + widget_binding_type binding_type, char* value_data) { + if (binding_type == text) { + elm_object_text_set(widget, _UIB_LOCALE(value_data)); + } +} + +static void post_binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (binding_type == text) { + // Show the label + evas_object_show(widget); + } +} + +static void binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (root_element == NULL) { + return; + } + bind_data(widget, binding_element_path, binding_type, root_element, + pre_binding_cb, bind_data_callback, post_binding_cb, + ds_content_type); +} + +widget_handler_st* checkbox_widget_handler_get_instance() { + if (checkbox_widget_handler.is_init == false) { + checkbox_widget_handler.is_init = true; + checkbox_widget_handler.binding_cb = &binding_cb; + } + return &checkbox_widget_handler; +} +]]> + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_flipselector_header.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_flipselector_header.xsl new file mode 100644 index 0000000..2d0e21a --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_flipselector_header.xsl @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_flipselector_source.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_flipselector_source.xsl new file mode 100644 index 0000000..8d93854 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_flipselector_source.xsl @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#include + +static widget_handler_st flipselector_widget_handler; + +static void pre_binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (binding_type == text) { + //Do nothing + } +} + +static void bind_data_callback(Evas_Object* widget, + widget_binding_type binding_type, char* value_data) { + if (binding_type == foreach) { + elm_flipselector_item_append(widget, _UIB_LOCALE(value_data), + NULL, NULL); + } +} + +static void post_binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (binding_type == foreach) { + // Show the label + evas_object_show(widget); + } +} + +static void binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (root_element == NULL) { + return; + } + bind_data(widget, binding_element_path, binding_type, root_element, + pre_binding_cb, bind_data_callback, post_binding_cb, + ds_content_type); +} + +widget_handler_st* flipselector_widget_handler_get_instance() { + if (flipselector_widget_handler.is_init == false) { + flipselector_widget_handler.is_init = true; + flipselector_widget_handler.binding_cb = &binding_cb; + } + return &flipselector_widget_handler; +} +]]> + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_flipselectoritem_header.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_flipselectoritem_header.xsl new file mode 100644 index 0000000..98e9b96 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_flipselectoritem_header.xsl @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_flipselectoritem_source.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_flipselectoritem_source.xsl new file mode 100644 index 0000000..23832cc --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_flipselectoritem_source.xsl @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#include + +static widget_handler_st flipselectoritem_widget_handler; + +static void pre_binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (binding_type == text) { + //Do nothing + } +} + +static void bind_data_callback(Evas_Object* widget, + widget_binding_type binding_type, char* value_data) { + if (binding_type == text) { + elm_object_item_text_set(widget, _UIB_LOCALE(value_data)); + } +} + +static void post_binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (binding_type == text) { + // Show the label + evas_object_show(widget); + } +} + +static void binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (root_element == NULL) { + return; + } + bind_data(widget, binding_element_path, binding_type, root_element, + pre_binding_cb, bind_data_callback, post_binding_cb, + ds_content_type); +} + +widget_handler_st* flipselectoritem_widget_handler_get_instance() { + if (flipselectoritem_widget_handler.is_init == false) { + flipselectoritem_widget_handler.is_init = true; + flipselectoritem_widget_handler.binding_cb = &binding_cb; + } + return &flipselectoritem_widget_handler; +} +]]> + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_hoversel_header.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_hoversel_header.xsl new file mode 100644 index 0000000..287f8d4 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_hoversel_header.xsl @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +widget_handler_st* hoversel_widget_handler_get_instance(); + +#endif +]]> + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_hoversel_source.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_hoversel_source.xsl new file mode 100644 index 0000000..9bdd80e --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_hoversel_source.xsl @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +static widget_handler_st hoversel_widget_handler; + +static void pre_binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (binding_type == foreach) { + //Clear all hoversel Items + elm_hoversel_clear(widget); + } +} + +static void post_binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (binding_type == foreach) { + //Do Nothing + } +} + +static void bind_data_callback(Evas_Object* widget, + widget_binding_type binding_type, char* value_data) { + if (binding_type == foreach) { + elm_hoversel_item_add(widget, _UIB_LOCALE(value_data), + NULL, ELM_ICON_NONE, NULL, NULL); + } +} + +static void binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (root_element == NULL) { + return; + } + bind_data(widget, binding_element_path, binding_type, root_element, + pre_binding_cb, bind_data_callback, post_binding_cb, + ds_content_type); +} + +widget_handler_st* hoversel_widget_handler_get_instance() { + if (hoversel_widget_handler.is_init == false) { + hoversel_widget_handler.is_init = true; + hoversel_widget_handler.binding_cb = &binding_cb; + + } + return &hoversel_widget_handler; +} +]]> + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_hoverselitem_header.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_hoverselitem_header.xsl new file mode 100644 index 0000000..3d01248 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_hoverselitem_header.xsl @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#include + +widget_handler_st* hoverselitem_widget_handler_get_instance(); + +#endif +]]> + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_hoverselitem_source.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_hoverselitem_source.xsl new file mode 100644 index 0000000..7796200 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_hoverselitem_source.xsl @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +static widget_handler_st hoverselitem_widget_handler; + +static void pre_binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (binding_type == text) { + //Do nothing + } +} + +static void bind_data_callback(Evas_Object* widget, + widget_binding_type binding_type, char* value_data) { + if (binding_type == text) { + elm_object_item_text_set(widget, _UIB_LOCALE(value_data)); + } +} + +static void post_binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (binding_type == text) { + // Show the hoverlistitem + evas_object_show(widget); + } +} + +static void binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (root_element == NULL) { + return; + } + bind_data(widget, binding_element_path, binding_type, root_element, + pre_binding_cb, bind_data_callback, post_binding_cb, + ds_content_type); +} + +widget_handler_st* hoverselitem_widget_handler_get_instance() { + if (hoverselitem_widget_handler.is_init == false) { + hoverselitem_widget_handler.is_init = true; + hoverselitem_widget_handler.binding_cb = &binding_cb; + } + return &hoverselitem_widget_handler; +} +]]> + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_label_header.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_label_header.xsl new file mode 100644 index 0000000..7106e34 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_label_header.xsl @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +widget_handler_st* label_widget_handler_get_instance(); + +#endif +]]> + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_label_source.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_label_source.xsl new file mode 100644 index 0000000..eabc191 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_label_source.xsl @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +static widget_handler_st label_widget_handler; + +static void pre_binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (binding_type == text) { + //Do nothing + } +} + +static void bind_data_callback(Evas_Object* widget, + widget_binding_type binding_type, char* value_data) { + if (binding_type == text) { + elm_object_text_set(widget, _UIB_LOCALE(value_data)); + } +} + +static void post_binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (binding_type == text) { + // Show the label + evas_object_show(widget); + } +} + +static void binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (root_element == NULL) { + return; + } + bind_data(widget, binding_element_path, binding_type, root_element, + pre_binding_cb, bind_data_callback, post_binding_cb, + ds_content_type); +} + +widget_handler_st* label_widget_handler_get_instance() { + if (label_widget_handler.is_init == false) { + label_widget_handler.is_init = true; + label_widget_handler.binding_cb = &binding_cb; + } + return &label_widget_handler; +} +]]> + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_list_header.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_list_header.xsl new file mode 100644 index 0000000..4f3ba28 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_list_header.xsl @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +widget_handler_st* list_widget_handler_get_instance(); + +#endif +]]> + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_list_source.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_list_source.xsl new file mode 100644 index 0000000..44e6d98 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_list_source.xsl @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +static widget_handler_st list_widget_handler; + +static void pre_binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (binding_type == foreach) { + //Clear all list Items + elm_list_clear(widget); + } +} + +static void post_binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (binding_type == foreach) { + //show widget + elm_list_go(widget); + } +} + +static void bind_data_callback(Evas_Object* widget, + widget_binding_type binding_type, char* value_data) { + if (binding_type == foreach) { + elm_list_item_append(widget, _UIB_LOCALE(value_data), + NULL, NULL, NULL, NULL); + } +} + +static void binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (root_element == NULL) { + return; + } + bind_data(widget, binding_element_path, binding_type, root_element, + pre_binding_cb, bind_data_callback, post_binding_cb, + ds_content_type); +} + +widget_handler_st* list_widget_handler_get_instance() { + if (list_widget_handler.is_init == false) { + list_widget_handler.is_init = true; + list_widget_handler.binding_cb = &binding_cb; + } + return &list_widget_handler; +} +]]> + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_listitem_header.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_listitem_header.xsl new file mode 100644 index 0000000..bdb3b36 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_listitem_header.xsl @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +widget_handler_st* listitem_widget_handler_get_instance(); + +#endif +]]> + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_listitem_source.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_listitem_source.xsl new file mode 100644 index 0000000..6a2a3c5 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_listitem_source.xsl @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +static widget_handler_st listitem_widget_handler; + +static void pre_binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (binding_type == text) { + //Do nothing + } +} + +static void bind_data_callback(Evas_Object* widget, + widget_binding_type binding_type, char* value_data) { + if (binding_type == text) { + elm_object_item_text_set(widget, _UIB_LOCALE(value_data)); + } +} + +static void post_binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (binding_type == text) { + // Show the label + evas_object_show(widget); + } +} + +static void binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (root_element == NULL) { + return; + } + bind_data(widget, binding_element_path, binding_type, root_element, + pre_binding_cb, bind_data_callback, post_binding_cb, + ds_content_type); +} + +widget_handler_st* listitem_widget_handler_get_instance() { + if (listitem_widget_handler.is_init == false) { + listitem_widget_handler.is_init = true; + listitem_widget_handler.binding_cb = &binding_cb; + } + return &listitem_widget_handler; +} +]]> + + diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_radio_header.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_radio_header.xsl new file mode 100644 index 0000000..9481b70 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_radio_header.xsl @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_radio_source.xsl b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_radio_source.xsl new file mode 100644 index 0000000..4d0106f --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/databinding/db_widget_handler_radio_source.xsl @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#include + +static widget_handler_st radio_widget_handler; + +static void pre_binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (binding_type == text) { + //Do nothing + } +} + +static void post_binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (binding_type == text) { + // Show the radio + evas_object_show(widget); + } +} + +static void bind_data_callback(Evas_Object* widget, + widget_binding_type binding_type, char* value_data) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - Setting value %s to radio's label", __func__, value_data); + if (binding_type == text) { + elm_object_text_set(widget, _UIB_LOCALE(value_data)); + } +} + +static void binding_cb(Evas_Object* widget, char* binding_element_path, + widget_binding_type binding_type, void** root_element, + UIB_DATASOURCE_CONTENT_TYPE ds_content_type) { + dlog_print(DLOG_DEBUG, LOG_TAG, "%s - ", __func__); + if (root_element == NULL) { + return; + } + bind_data(widget, binding_element_path, binding_type, root_element, + pre_binding_cb, bind_data_callback, post_binding_cb, + ds_content_type); +} + +widget_handler_st* radio_widget_handler_get_instance() { + if (radio_widget_handler.is_init == false) { + radio_widget_handler.is_init = true; + radio_widget_handler.binding_cb = &binding_cb; + } + return &radio_widget_handler; +} +]]> + + \ No newline at end of file diff --git a/org.tizen.efluibuilder.codegenerator/res/inc/g_inc_uib_header.xsl b/org.tizen.efluibuilder.codegenerator/res/inc/g_inc_uib_header.xsl new file mode 100644 index 0000000..e5fbedd --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/inc/g_inc_uib_header.xsl @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + +#include +]]> + + + + + + +#include +#include + +#include +#include +#include +]]> + + + ]]> + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/inc/uib_app_manager_header.xsl b/org.tizen.efluibuilder.codegenerator/res/inc/uib_app_manager_header.xsl new file mode 100644 index 0000000..8eeeb8c --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/inc/uib_app_manager_header.xsl @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/inc/uib_util_header.xsl b/org.tizen.efluibuilder.codegenerator/res/inc/uib_util_header.xsl new file mode 100644 index 0000000..2aba41e --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/inc/uib_util_header.xsl @@ -0,0 +1,184 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/inc/uib_view_header.xsl b/org.tizen.efluibuilder.codegenerator/res/inc/uib_view_header.xsl new file mode 100644 index 0000000..367cba0 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/inc/uib_view_header.xsl @@ -0,0 +1,245 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +evas_object) like other EFL evas objects. +*/]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + uib_ + + + + _view_context + + + + + + + uib_ + + + + _control_context + + + + + + + + + + + + + + + + + + + +/******************************************************************************* +* This file was generated by UI Builder. +* This file will be auto-generated each and everytime you save your project. +* Do not hand edit this file. +********************************************************************************/ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/inc/uib_view_manager_header.xsl b/org.tizen.efluibuilder.codegenerator/res/inc/uib_view_manager_header.xsl new file mode 100644 index 0000000..49ed02f --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/inc/uib_view_manager_header.xsl @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/inc/uib_views_header.xsl b/org.tizen.efluibuilder.codegenerator/res/inc/uib_views_header.xsl new file mode 100644 index 0000000..eacfee2 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/inc/uib_views_header.xsl @@ -0,0 +1,214 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/inc/uib_views_inc_header.xsl b/org.tizen.efluibuilder.codegenerator/res/inc/uib_views_inc_header.xsl new file mode 100644 index 0000000..21537ca --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/inc/uib_views_inc_header.xsl @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + +/******************************************************************************* +* This file was generated by UI Builder. +* This file will be auto-generated each and everytime you save your project. +* Do not hand edit this file. +********************************************************************************/ + +#ifndef UIB_VIEWS_INC_H_ +#define UIB_VIEWS_INC_H_ + + + + + + +#endif /* UIB_VIEWS_INC_H_ */ + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/inc/view_data_header.xsl b/org.tizen.efluibuilder.codegenerator/res/inc/view_data_header.xsl new file mode 100644 index 0000000..60f7819 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/inc/view_data_header.xsl @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + +#include "uib_views.h" + +/** + * @brief Forward declaration of model + */ +typedef struct _uib_view_data { + Evas_Object* win; +]]> + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/background.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/background.xsl new file mode 100644 index 0000000..0ea59c5 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/background.xsl @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/box.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/box.xsl new file mode 100644 index 0000000..48e4965 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/box.xsl @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/button.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/button.xsl new file mode 100644 index 0000000..3cfdc57 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/button.xsl @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/calendar.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/calendar.xsl new file mode 100644 index 0000000..9f91dd9 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/calendar.xsl @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/check.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/check.xsl new file mode 100644 index 0000000..770e528 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/check.xsl @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/circledatetime.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/circledatetime.xsl new file mode 100644 index 0000000..09a2632 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/circledatetime.xsl @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/circlegenlist.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/circlegenlist.xsl new file mode 100644 index 0000000..86e3db8 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/circlegenlist.xsl @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/circlegenlistitem.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/circlegenlistitem.xsl new file mode 100644 index 0000000..3ec1c36 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/circlegenlistitem.xsl @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/circleprogressbar.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/circleprogressbar.xsl new file mode 100644 index 0000000..44d3abc --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/circleprogressbar.xsl @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/circlescroller.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/circlescroller.xsl new file mode 100644 index 0000000..764b0b7 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/circlescroller.xsl @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/circleslider.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/circleslider.xsl new file mode 100644 index 0000000..d132649 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/circleslider.xsl @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/colorselector.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/colorselector.xsl new file mode 100644 index 0000000..90a14f8 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/colorselector.xsl @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/ctxpopup.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/ctxpopup.xsl new file mode 100644 index 0000000..0499f20 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/ctxpopup.xsl @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/ctxpopupitem.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/ctxpopupitem.xsl new file mode 100644 index 0000000..2a8852a --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/ctxpopupitem.xsl @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/datetime.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/datetime.xsl new file mode 100644 index 0000000..a2b2c4e --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/datetime.xsl @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/entry.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/entry.xsl new file mode 100644 index 0000000..c8bc7a3 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/entry.xsl @@ -0,0 +1,160 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/flipselector.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/flipselector.xsl new file mode 100644 index 0000000..31d4dd1 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/flipselector.xsl @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/flipselectoritem.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/flipselectoritem.xsl new file mode 100644 index 0000000..728794f --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/flipselectoritem.xsl @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/gengrid.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/gengrid.xsl new file mode 100644 index 0000000..296837c --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/gengrid.xsl @@ -0,0 +1,121 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/gengriditem.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/gengriditem.xsl new file mode 100644 index 0000000..e642593 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/gengriditem.xsl @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/genlist.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/genlist.xsl new file mode 100644 index 0000000..6eed5bd --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/genlist.xsl @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/genlistitem.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/genlistitem.xsl new file mode 100644 index 0000000..fef19d5 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/genlistitem.xsl @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/grid.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/grid.xsl new file mode 100644 index 0000000..ece4079 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/grid.xsl @@ -0,0 +1,118 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/hoversel.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/hoversel.xsl new file mode 100644 index 0000000..689fb75 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/hoversel.xsl @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/hoverselitem.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/hoverselitem.xsl new file mode 100644 index 0000000..a304704 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/hoverselitem.xsl @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/icon.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/icon.xsl new file mode 100644 index 0000000..b2bce2a --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/icon.xsl @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/image.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/image.xsl new file mode 100644 index 0000000..0207d3b --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/image.xsl @@ -0,0 +1,156 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/index.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/index.xsl new file mode 100644 index 0000000..42903de --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/index.xsl @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/indexitem.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/indexitem.xsl new file mode 100644 index 0000000..5964fc9 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/indexitem.xsl @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/label.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/label.xsl new file mode 100644 index 0000000..d87fca1 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/label.xsl @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/layout.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/layout.xsl new file mode 100644 index 0000000..cdef1ba --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/layout.xsl @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/list.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/list.xsl new file mode 100644 index 0000000..f0ba2a1 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/list.xsl @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/listitem.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/listitem.xsl new file mode 100644 index 0000000..8b3e0eb --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/listitem.xsl @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/map.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/map.xsl new file mode 100644 index 0000000..6a13a5f --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/map.xsl @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/multibuttonentry.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/multibuttonentry.xsl new file mode 100644 index 0000000..9907b69 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/multibuttonentry.xsl @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/multibuttonentryitem.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/multibuttonentryitem.xsl new file mode 100644 index 0000000..dd3f02b --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/multibuttonentryitem.xsl @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/panel.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/panel.xsl new file mode 100644 index 0000000..4e592c3 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/panel.xsl @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/panes.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/panes.xsl new file mode 100644 index 0000000..982722a --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/panes.xsl @@ -0,0 +1,188 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/popup.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/popup.xsl new file mode 100644 index 0000000..cddb6e2 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/popup.xsl @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/progressbar.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/progressbar.xsl new file mode 100644 index 0000000..f19127e --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/progressbar.xsl @@ -0,0 +1,163 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/radio.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/radio.xsl new file mode 100644 index 0000000..4245954 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/radio.xsl @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/scroller.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/scroller.xsl new file mode 100644 index 0000000..58d4e55 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/scroller.xsl @@ -0,0 +1,191 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/slider.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/slider.xsl new file mode 100644 index 0000000..d64edfc --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/slider.xsl @@ -0,0 +1,145 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/spinner.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/spinner.xsl new file mode 100644 index 0000000..b576893 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/spinner.xsl @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/table.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/table.xsl new file mode 100644 index 0000000..14b5d4f --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/table.xsl @@ -0,0 +1,143 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/tizenPopup.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/tizenPopup.xsl new file mode 100644 index 0000000..9ff81f0 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/tizenPopup.xsl @@ -0,0 +1,159 @@ + + + + /******************************************************************************* + * This file was generated by UI Builder. + * This file will be auto-generated + each and everytime you save your project. + * Do not hand edit this file. + ********************************************************************************/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/toolbar.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/toolbar.xsl new file mode 100644 index 0000000..6b46be7 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/toolbar.xsl @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/toolbaritem.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/toolbaritem.xsl new file mode 100644 index 0000000..d4b53ae --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/toolbaritem.xsl @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/components/view.xsl b/org.tizen.efluibuilder.codegenerator/res/src/components/view.xsl new file mode 100644 index 0000000..3c1681f --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/components/view.xsl @@ -0,0 +1,323 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/connection.xsl b/org.tizen.efluibuilder.codegenerator/res/src/connection.xsl new file mode 100644 index 0000000..edf0355 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/connection.xsl @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/uib_app_manager_source.xsl b/org.tizen.efluibuilder.codegenerator/res/src/uib_app_manager_source.xsl new file mode 100644 index 0000000..3a69864 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/uib_app_manager_source.xsl @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + create_window_obj(context, w, h);]]> + + + create_window_obj();]]> + + + win, e_rotation_fullSensor); + if(use_user_view!=USE_USER_VIEW) { + prepare(); + } + return (win_obj)? true : false; +} + +void prepare() { + uib_view_context* vc = uib_views_get_instance()->create_startup_view(); + window_obj* win_obj = uib_views_get_instance()->get_window_obj(); + Evas_Object* nf = win_obj->app_naviframe; + Elm_Object_Item* nf_it = elm_naviframe_bottom_item_get(nf); + + eext_object_event_callback_add(nf, EEXT_CALLBACK_BACK, nf_hw_back_cb, vc); + evas_object_show(nf); + elm_naviframe_item_pop_cb_set(nf_it, nf_root_it_pop_cb, win_obj->win); + + elm_app_base_scale_set(g_uib_device_info.base_scale); + evas_object_smart_callback_add(win_obj->win, "delete,request", win_del_request_cb, NULL); +} + +const uib_device_info_st* get_uib_device_info() { + return &g_uib_device_info; +} + +uib_app_manager_st* uib_app_manager_get_instance() { + if(!g_uib_app_manager._is_init) { + g_uib_app_manager._is_init = true; + g_uib_app_manager.add_view_context = uib_view_manager_get_instance()->add_view_context; + g_uib_app_manager.find_view_context = uib_view_manager_get_instance()->find_view_context; + g_uib_app_manager.free_all_view_context = uib_view_manager_get_instance()->free_all_view_context; + g_uib_app_manager.initialize = initialize; + g_uib_app_manager.prepare = prepare; + g_uib_app_manager.get_uib_device_info = &get_uib_device_info; + } + return &g_uib_app_manager; +} +]]> + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/uib_connection_source.xsl b/org.tizen.efluibuilder.codegenerator/res/src/uib_connection_source.xsl new file mode 100644 index 0000000..570f166 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/uib_connection_source.xsl @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/uib_util_source.xsl b/org.tizen.efluibuilder.codegenerator/res/src/uib_util_source.xsl new file mode 100644 index 0000000..b4eb7ec --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/uib_util_source.xsl @@ -0,0 +1,287 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + profile_name, elm_config_profile_get()); + system_info_get_platform_int("tizen.org/feature/screen.width", &uib_device_info->w); + system_info_get_platform_int("tizen.org/feature/screen.height", &uib_device_info->h); + system_info_get_platform_int("tizen.org/feature/screen.dpi", &uib_device_info->dpi); + + double profile_factor = (!strcmp(uib_device_info->profile_name, "mobile"))? 0.7 : 0.4; + uib_device_info->base_scale = uib_device_info->dpi / 90 * profile_factor; + + uib_device_info->resolution_type = uib_util_get_resolution_type(uib_device_info->w, uib_device_info->h); + + return 0; +} + +Elm_Object_Item* uib_util_push_view(char *view_name) { + Evas_Object* app_nf = uib_views_get_instance()->get_window_obj()->app_naviframe; + uib_view_context* vc=NULL; + ]]> + + + + + + + + + + + + create_user_view(view_name); + } + if(!vc) { + return NULL; + } + Elm_Object_Item* elm_obj_item = elm_naviframe_item_push(app_nf, "", NULL, NULL, vc->root_container, NULL); + //TODO: Check for side-effects. This change prevents view refresh on naviframe popup + elm_naviframe_content_preserve_on_pop_set(app_nf, EINA_TRUE); + elm_naviframe_item_title_enabled_set (elm_obj_item, EINA_FALSE, EINA_FALSE); + return elm_obj_item; +} + +uib_popup_context* uib_create_popup(char *popup_name) { + uib_popup_context* vc=NULL;]]> + + +get_window_obj()->app_naviframe; +]]> + + + + + + + + + + + + + + + +root_container, x, y); + return vc; +} + +char* uib_util_get_current_config_name() { + return uib_views_get_instance()->get_current_config_name(); +} + +void uib_util_widget_hide_on_grid(Evas_Object* grid_evas_obj, Evas_Object* evas_sub_obj) { + elm_grid_pack(grid_evas_obj, evas_sub_obj, -100, -100, 0, 0); +} + +char* uib_util_rm_get_locale_string(char* src_string) { + char* locale_string=NULL; + if((src_string==NULL) || (strlen(src_string)<1)) { + return NULL; + } + if(!strncasecmp(RM_ANNOTATION_LOCALE, src_string, RM_ANNOTATION_LOCALE_LEN)) { // matching + locale_string = _(src_string+RM_ANNOTATION_LOCALE_LEN); // i18n_get_text + } + else { + locale_string = src_string; + } + + return locale_string; +} + +int uib_util_rm_get_resource_path(_APP_RESOURCE_E e_resource_type, const char* resource_path_in, char** resource_path_out) { + int ret=0; + if((resource_path_in==NULL) || (strlen(resource_path_in)<1)) { + return 0; + } +]]> + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/uib_view_manager_source.xsl b/org.tizen.efluibuilder.codegenerator/res/src/uib_view_manager_source.xsl new file mode 100644 index 0000000..f3042a6 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/uib_view_manager_source.xsl @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + + + +view_name)) + return i; + } + return -1; // find failed +} + +int add_view_context(uib_view_context* vc) { + // check conflict the view_name + if(uib_views_get_instance()->get_total_hit_num(vc) > 0) { + UIB_DLOG(DLOG_ERROR, LOG_TAG, "This view is already exists. Conflicted view name is '%s'\n", vc->view_name); + return -1; + } + + int i = find_view_index(vc->view_name); + + evas_object_data_set(vc->root_container, KEY_VIEW_VC_SAVE, vc); + if(i < 0) { + if(g_view_context_total_num < DEF_UIB_VIEW_MAX_NUM) { + g_uib_view_context_list[g_view_context_total_num] = vc; + g_view_context_total_num++; + return 0; + } + else { + UIB_DLOG(DLOG_ERROR, LOG_TAG, "It was failed to create the view. Too many views exist. '%d'\n", g_view_context_total_num); + return -1; + } + } + else { // overwrite + g_uib_view_context_list[i] = vc; + } + return 0; +} + +uib_view_context* find_view_context(char* view_name) { + int i=0; + + for(i=0; i < g_view_context_total_num; i++) { + if(!strcmp(view_name, g_uib_view_context_list[i]->view_name)) { + return g_uib_view_context_list[i]; + } + } + return NULL; // find failed +} + +void free_all_view_context() { + int i=0; + + for(i=0; i < g_view_context_total_num; i++) { + if(g_uib_view_context_list[i]) + free(g_uib_view_context_list[i]); + } +} +]]> + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/uib_view_source.xsl b/org.tizen.efluibuilder.codegenerator/res/src/uib_view_source.xsl new file mode 100644 index 0000000..ce7c0e9 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/uib_view_source.xsl @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/src/uib_views_source.xsl b/org.tizen.efluibuilder.codegenerator/res/src/uib_views_source.xsl new file mode 100644 index 0000000..e70df88 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/src/uib_views_source.xsl @@ -0,0 +1,1152 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + get_uib_device_info(); + switch(uib_device_info->resolution_type) { +]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + root_container, KEY_VIEW_VC_SAVE, g_uib_saved_vc); + g_uib_saved_vc = push_vc; +} + +// called by views_destroy_callback +void pop_from_stack_uib_vc(uib_view_context* pop_vc) { + uib_view_context* rollback_vc = evas_object_data_get(pop_vc->root_container, KEY_VIEW_VC_SAVE); + g_uib_saved_vc = rollback_vc; + if(g_uib_saved_vc) { + set_targeted_view(g_uib_saved_vc); + } +} + +int gi_cur_user_view_idx = 0; +void set_targeted_view(uib_view_context* vc) { + const char* view_name = vc->view_name; + gi_cur_user_view_idx = (vc->is_user_view)? find_user_view_idx((char*)view_name) : -1; + + if(gi_cur_user_view_idx < 0) { +]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + win); + elm_win_indicator_mode_set(g_win_obj->win, vc->indicator_state); + uib_views_get_instance()->uib_views_orientation_handler(orientation); +} + +void uib_ctxpopup_back_callback(void *data, Evas_Object *obj, void *event_info) { + eext_ctxpopup_back_cb(data, obj, event_info); + evas_object_del(obj); +} + +void uib_views_orientation_handler(int orient_status) { + if(gi_cur_user_view_idx < 0) { + switch(DEF_UIB_ORIENT_TYPE(orient_status)) { + case e_orientation_port: + uib_views_get_instance()->uib_view_target_config_portrait(); + g_views_current_config_name = g_views_config_delegate_name_portrait; + break; + case e_orientation_land: + uib_views_get_instance()->uib_view_target_config_landscape(); + g_views_current_config_name = g_views_config_delegate_name_landscape; + break; + default: + uib_views_get_instance()->uib_view_target_config_portrait(); + g_views_current_config_name = g_views_config_delegate_name_portrait; + break; + } + } + else { + uib_view_context* vc = uib_app_manager_get_instance()->find_view_context((char*) (gst_uib_user_views[gi_cur_user_view_idx].view_name)); + gst_uib_user_views[gi_cur_user_view_idx].draw_user_view_cb(g_win_obj, vc); + g_views_current_config_name = VIEWS_CONFIG_NAME_NONE; + } +} + +char* get_current_config_name() { + return g_views_current_config_name; +} + + +void uib_views_orientation_changed_cb(void *win, Evas_Object *obj, void *event_info) { + int orientation=elm_win_rotation_get(win); + uib_views_orientation_handler(orientation); +} + +void uib_views_current_view_redraw() { + uib_views_orientation_changed_cb(g_win_obj->win, NULL, NULL); +} + +void set_startup_view_name (const char* startup_view_name) { + gpsz_startup_view_name = (char*)startup_view_name; +} + +uib_view_context* create_startup_view() +{ + evas_object_smart_callback_add(g_win_obj->win, KEY_WM_ROTATION_CHANGED, uib_views_orientation_changed_cb, g_win_obj->win); + gpsz_startup_view_name = (gpsz_startup_view_name==NULL)? DEF_STARTUP_VIEW_NAME : gpsz_startup_view_name; + if(strlen(gpsz_startup_view_name) < 1) { + UIB_DLOG(DLOG_ERROR, LOG_TAG, "create_startup_view= (Invalid startup view name=%s)\n", gpsz_startup_view_name); + exit(0); + } + uib_util_push_view(gpsz_startup_view_name); + return uib_app_manager_get_instance()->find_view_context(gpsz_startup_view_name); +} + +int add_user_views (char* user_view_name, void (*draw_user_view_cb)(window_obj* win_obj, uib_view_context* vc)) { + if(gi_user_views_total_num < DEF_UIB_VIEW_MAX_NUM) { + gst_uib_user_views[gi_user_views_total_num].view_name = user_view_name; + gst_uib_user_views[gi_user_views_total_num].draw_user_view_cb = draw_user_view_cb; + gi_user_views_total_num++; + return 0; + } + return -1; +} + +int find_user_view_idx(char* view_name) { + int i=0; + + for(i=0; i < gi_user_views_total_num; i++) { + if(!strcmp(view_name, gst_uib_user_views[i].view_name)) + return i; + } + return -1; // find failed +} + +int get_total_hit_num (uib_view_context* vc) { + int i=0; + int same_name_count=0; + + for(i=0; i < gi_user_views_total_num; i++) { + if(!strcmp(vc->view_name, gst_uib_user_views[i].view_name)) { + same_name_count++; + } + } + return (vc->is_user_view)? same_name_count-1 : same_name_count; +} + +uib_view_context* create_user_view (char* user_view_name) { + + int error_state = 0; + + int idx = find_user_view_idx(user_view_name); + if (idx < 0) { + return NULL; + } + elm_win_indicator_mode_set(g_win_obj->win, ELM_WIN_INDICATOR_SHOW); + uib_view_context* vc = calloc(1, sizeof(uib_view_context)); + vc->parent = g_win_obj->app_naviframe; + vc->view_name = user_view_name; + vc->is_user_view = true; + error_state = uib_app_manager_get_instance()->add_view_context((uib_view_context*)vc); + + if(gst_uib_user_views[idx].draw_user_view_cb) { + set_targeted_view(vc); + } + + //bind event handler + evas_object_data_set(vc->root_container, KEY_VIEW_CONTEXT, vc); + evas_object_event_callback_add(vc->root_container, EVAS_CALLBACK_DEL, (Evas_Object_Event_Cb)uib_views_destroy_callback, vc); + uib_views_create_callback(vc, evas_object_evas_get(vc->root_container), vc->root_container, NULL); + return (uib_view_context*)vc; +} + +]]> + + + + + + + win = elm_win_add(NULL, NULL, ELM_WIN_BASIC); + elm_win_fullscreen_set(g_win_obj->win, EINA_TRUE); + elm_win_alpha_set(g_win_obj->win, EINA_TRUE); + + g_win_obj->bg = elm_bg_add(g_win_obj->win); + evas_object_size_hint_weight_set(g_win_obj->bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(g_win_obj->win, g_win_obj->bg); + evas_object_show(g_win_obj->bg); + + g_win_obj->conformant = elm_box_add(g_win_obj->win); + evas_object_size_hint_align_set(g_win_obj->conformant, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_size_hint_weight_set(g_win_obj->conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_show(g_win_obj->conformant); + elm_win_resize_object_add(g_win_obj->win, g_win_obj->conformant); + + g_win_obj->app_naviframe = elm_naviframe_add(g_win_obj->conformant); + evas_object_size_hint_weight_set(g_win_obj->app_naviframe, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(g_win_obj->app_naviframe, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(g_win_obj->app_naviframe); + elm_box_pack_end(g_win_obj->conformant, g_win_obj->app_naviframe); + + evas_object_data_set(g_win_obj->win, "root", g_win_obj); + + evas_object_show(g_win_obj->win); + return g_win_obj; +} + ]]> + + + + + + + win)); + if (ret != WIDGET_ERROR_NONE) { + UIB_DLOG(DLOG_ERROR, LOG_TAG, "failed to get window. err = %d", ret); + return NULL; + } + evas_object_resize(g_win_obj->win, w, h); + + elm_win_conformant_set(g_win_obj->win, EINA_TRUE); + evas_object_show(g_win_obj->win); + g_win_obj->bg = elm_bg_add(g_win_obj->win); + evas_object_size_hint_weight_set(g_win_obj->bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(g_win_obj->win, g_win_obj->bg); + evas_object_show(g_win_obj->bg); + + elm_win_indicator_mode_set(g_win_obj->win, ELM_WIN_INDICATOR_SHOW); + g_win_obj->conformant = elm_conformant_add(g_win_obj->win); + evas_object_size_hint_weight_set(g_win_obj->conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(g_win_obj->win, g_win_obj->conformant); + evas_object_show(g_win_obj->conformant); + + g_win_obj->app_naviframe = elm_naviframe_add(g_win_obj->conformant); + elm_object_content_set(g_win_obj->conformant, g_win_obj->app_naviframe);]]> + + win, "root", g_win_obj); + return g_win_obj; +}]]> + + + + + + + win = elm_win_add(NULL, NULL, ELM_WIN_BASIC); + elm_win_conformant_set(g_win_obj->win, EINA_TRUE); + evas_object_show(g_win_obj->win); + g_win_obj->bg = elm_bg_add(g_win_obj->win); + evas_object_size_hint_weight_set(g_win_obj->bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(g_win_obj->win, g_win_obj->bg); + evas_object_show(g_win_obj->bg); + + elm_win_indicator_mode_set(g_win_obj->win, ELM_WIN_INDICATOR_SHOW); + g_win_obj->conformant = elm_conformant_add(g_win_obj->win); + evas_object_size_hint_weight_set(g_win_obj->conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(g_win_obj->win, g_win_obj->conformant); + evas_object_show(g_win_obj->conformant); + + g_win_obj->app_naviframe = elm_naviframe_add(g_win_obj->conformant); + elm_object_content_set(g_win_obj->conformant, g_win_obj->app_naviframe);]]> + + win, "root", g_win_obj); + return g_win_obj; +} + ]]> + + + win); + free(g_win_obj); + g_win_obj = NULL; + } + destory_genlist_item_class();]]> + + + + + + win; +} + +Evas_Object* get_conformant() { + return gst_uib_views.get_window_obj()->conformant; +} + +/*********************************************************************************************** + * + * item class callbacks + * + ***********************************************************************************************/ +static Evas_Object* create_item_image(Evas_Object* parent, const char* path) { + Evas_Object *icon = elm_icon_add(parent); + char *resource_path = NULL; +]]> + + + + + + + + + label) { + return strdup(item->label); + } + } + else if (!strcmp(part, "elm.text.sub") || !strcmp(part, "elm.text.1")) { + if (item->sub_label) { + return strdup(item->sub_label); + } + } + return NULL; +} + +Evas_Object* uib_genlist_icon_get(void *data , Evas_Object *obj, const char *part) { + uib_genlist_item *item = (uib_genlist_item*) data; + if (!strcmp(part, "elm.swallow.icon")) { + if(item->icon_standard){ + Evas_Object *ic = elm_icon_add(obj); + elm_icon_standard_set(ic, item->icon_standard); + evas_object_size_hint_min_set(ic, ELM_SCALE_SIZE(ICON_MIN_SIZE),ELM_SCALE_SIZE(ICON_MIN_SIZE)); + return ic; + } else if(item->icon_path){ + return create_item_image(obj, item->icon_path); + } + } + + if (!strcmp(part, "elm.swallow.end")) { + if (item->end_icon_standard) { + Evas_Object *ic = elm_icon_add(obj); + elm_icon_standard_set(ic, item->end_icon_standard); + evas_object_size_hint_min_set(ic, ELM_SCALE_SIZE(ICON_MIN_SIZE),ELM_SCALE_SIZE(ICON_MIN_SIZE)); + return ic; + } else if (item->end_icon_path) { + return create_item_image(obj, item->end_icon_path); + } + } + + if (!strcmp(part, "elm.icon")) { + if(item->icon_path){ + Evas_Object *ic = create_item_image(obj, item->icon_path); + return ic; + } + } + return NULL; +} + +Eina_Bool uib_genlist_state_get(void *data , Evas_Object *obj , const char *part) { + return EINA_FALSE; +} + +void uib_genlist_del(void *data , Evas_Object *obj) { + uib_genlist_item *item = (uib_genlist_item*)data; + if (item) { + if (item->label) free(item->label); + if (item->sub_label) free(item->sub_label); + if (item->icon_path) free(item->icon_path); + if (item->icon_standard) free(item->icon_standard); + if (item->end_icon_path) free(item->end_icon_path); + if (item->end_icon_standard) free(item->end_icon_standard); + free(item); + } +} + + +Elm_Object_Item* create_genlist_item(Evas_Object* genlist, const char* style, const char* label, const char* sub_label, const char* icon_path, const char* icon_standard, const char* end_icon_path, const char* end_icon_standard, Elm_Object_Item* parent, Elm_Genlist_Item_Type type, Evas_Smart_Cb func, void* data){ + uib_genlist_item* item = malloc(sizeof(uib_genlist_item)); + memset(item, 0x0, sizeof(uib_genlist_item)); + + item->label = strdup(label); + item->sub_label = strdup(sub_label); + if(strlen(icon_path) != 0){ + item->icon_path = strdup(icon_path); + } else if(strlen(icon_standard) != 0){ + item->icon_standard = strdup(icon_standard); + } + + if(strlen(end_icon_path) != 0){ + item->end_icon_path = strdup(end_icon_path); + } else if(strlen(end_icon_standard) != 0){ + item->end_icon_standard = strdup(end_icon_standard); + } + + uib_genlist_item_style_e style_e = get_genlist_item_style_e(style); + if(style_e == UIB_GENLIST_ITEM_STYLE_GROUPINDEX) { + type = ELM_GENLIST_ITEM_TREE; + } + return elm_genlist_item_append(genlist, get_genlist_item_class(style), item, parent, type, func, data); +} + +static void destory_genlist_item_class() { + for(int i = 0; i< UIB_GENLIST_ITEM_STYLE_SIZE; i++) { + Elm_Genlist_Item_Class *itc = _gis[i]; + if(itc != NULL) { + elm_genlist_item_class_free(itc); + } + } +} + +static Elm_Genlist_Item_Class* get_genlist_item_class(const char* style) { + uib_genlist_item_style_e style_e = get_genlist_item_style_e(style); + Elm_Genlist_Item_Class *itc = _gis[style_e]; + if(itc == NULL) { + itc = create_genlist_item_class(style); + if(itc != NULL) { + _gis[style_e] = itc; + } + } + return itc; +} + +static Elm_Genlist_Item_Class* create_genlist_item_class(const char* style) { + Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new(); + itc->item_style = style; + itc->func.text_get = uib_genlist_label_get; + itc->func.content_get = uib_genlist_icon_get; + itc->func.state_get = uib_genlist_state_get; + itc->func.del = uib_genlist_del; + + return itc; +} +]]> + + + label) { + return strdup(item->label); + } else { + return NULL; + } +} + +Evas_Object* uib_gengrid_icon_get(void *data, Evas_Object *obj, const char *part) { + uib_gengrid_item *item = (uib_gengrid_item*) data; + if (!strcmp(part, "elm.swallow.icon") && item->icon_path) { + return create_item_image(obj, item->icon_path); + } else { + return NULL; + } +} + +Eina_Bool uib_gengrid_state_get(void *data, Evas_Object *obj, const char *part) { + return EINA_FALSE; +} + +void uib_gengrid_del(void *data, Evas_Object *obj) { + uib_gengrid_item *item = (uib_gengrid_item*)data; + if (item) { + if (item->label) free(item->label); + if (item->icon_path) free(item->icon_path); + free(item); + } +} + +static void destory_gengrid_item_class() { + for(int i = 0; i< UIB_GENGRID_ITEM_STYLE_SIZE; i++) { + Elm_Genlist_Item_Class *itc = _gic[i]; + if(itc != NULL) { + elm_gengrid_item_class_free(itc); + } + } +} + +static Elm_Gengrid_Item_Class* get_gengrid_item_class(const char* style) { + uib_gengrid_item_style_e style_e = get_gengrid_item_style_e(style); + Elm_Gengrid_Item_Class *itc = _gic[style_e]; + if(itc == NULL) { + itc = create_gengrid_item_class(style); + if(itc != NULL) { + _gic[style_e] = itc; + } + } + return itc; +} + +static Elm_Gengrid_Item_Class* create_gengrid_item_class(const char* style) { + Elm_Gengrid_Item_Class *itc = elm_gengrid_item_class_new(); + itc->item_style = style; + itc->func.text_get = uib_gengrid_label_get; + itc->func.content_get = uib_gengrid_icon_get; + itc->func.state_get = uib_gengrid_state_get; + itc->func.del = uib_gengrid_del; + + return itc; +} + +Elm_Object_Item* create_multibuttonentry_item(Evas_Object* multibuttonentry, const char* label, Evas_Smart_Cb func, void* data) { + Elm_Object_Item* item = elm_multibuttonentry_item_append(multibuttonentry, label, func, data); + return item; +} + +Elm_Object_Item* create_gengrid_item(Evas_Object* gengrid, const char* style, const char* label, const char* path, Evas_Smart_Cb func, void* data) { + uib_gengrid_item* item = malloc(sizeof(uib_gengrid_item)); + memset(item, 0x0, sizeof(uib_gengrid_item)); + item->label = strdup(label); + item->icon_path = strdup(path); + + return elm_gengrid_item_append(gengrid, get_gengrid_item_class(style), item, func, data); +} +]]> + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/util/common.xsl b/org.tizen.efluibuilder.codegenerator/res/util/common.xsl new file mode 100644 index 0000000..f69d5cc --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/util/common.xsl @@ -0,0 +1,287 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ( + + , + + , + + ); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/org.tizen.efluibuilder.codegenerator/res/util/event.xsl b/org.tizen.efluibuilder.codegenerator/res/util/event.xsl new file mode 100644 index 0000000..7eaa6c0 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/util/event.xsl @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/res/util/rconvert.xsl b/org.tizen.efluibuilder.codegenerator/res/util/rconvert.xsl new file mode 100644 index 0000000..4f406de --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/res/util/rconvert.xsl @@ -0,0 +1,107 @@ + + + + + + + + + + ELM_BG_OPTION_CENTER + ELM_BG_OPTION_SCALE + ELM_BG_OPTION_STRETCH + ELM_BG_OPTION_TILE + + true + false + + ELM_TEXT_FORMAT_PLAIN_UTF8 + ELM_TEXT_FORMAT_MARKUP_UTF8 + + true + false + + ELM_OBJECT_SELECT_MODE_DEFAULT + ELM_OBJECT_SELECT_MODE_ALWAYS + ELM_OBJECT_SELECT_MODE_NONE + ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY + + ELM_CALENDAR_SELECT_MODE_DEFAULT + ELM_CALENDAR_SELECT_MODE_ALWAYS + ELM_CALENDAR_SELECT_MODE_NONE + ELM_CALENDAR_SELECT_MODE_ONDEMAND + + ELM_SCROLLER_POLICY_AUTO + ELM_SCROLLER_POLICY_ON + ELM_SCROLLER_POLICY_OFF + + ELM_SCROLLER_POLICY_AUTO + ELM_SCROLLER_POLICY_ON + ELM_SCROLLER_POLICY_OFF + + true + false + + true + false + + ELM_IMAGE_ORIENT_NONE + ELM_IMAGE_ORIENT_0 + ELM_IMAGE_ORIENT_90 + ELM_IMAGE_ROTATE_90 + ELM_IMAGE_ORIENT_180 + ELM_IMAGE_ROTATE_180 + ELM_IMAGE_ORIENT_270 + ELM_IMAGE_ROTATE_270 + ELM_IMAGE_FLIP_HORIZONTAL + ELM_IMAGE_FLIP_VERTICAL + ELM_IMAGE_FLIP_TRANSPOSE + ELM_IMAGE_FLIP_TRANSVERSE + + ELM_PANEL_ORIENT_TOP + ELM_PANEL_ORIENT_BOTTOM + ELM_PANEL_ORIENT_LEFT + ELM_PANEL_ORIENT_RIGHT + + ELM_WRAP_NONE + ELM_WRAP_CHAR + ELM_WRAP_WORD + ELM_WRAP_MIXED + + ELM_LIST_COMPRESS + ELM_LIST_SCROLL + ELM_LIST_LIMIT + ELM_LIST_EXPAND + + ELM_TOOLBAR_SHRINK_NONE + ELM_TOOLBAR_SHRINK_HIDE + ELM_TOOLBAR_SHRINK_SCROLL + ELM_TOOLBAR_SHRINK_MENU + ELM_TOOLBAR_SHRINK_EXPAND + + ELM_GENLIST_ITEM_NONE + ELM_GENLIST_ITEM_TREE + ELM_GENLIST_ITEM_GROUP + + ELM_GENGRID_ITEM_SCROLLTO_NONE + ELM_GENGRID_ITEM_SCROLLTO_IN + ELM_GENGRID_ITEM_SCROLLTO_TOP + ELM_GENGRID_ITEM_SCROLLTO_MIDDLE + + + ELM_GENLIST_ITEM_SCROLLTO_NONE + ELM_GENLIST_ITEM_SCROLLTO_IN + ELM_GENLIST_ITEM_SCROLLTO_TOP + ELM_GENLIST_ITEM_SCROLLTO_MIDDLE + + + + + + + \ No newline at end of file diff --git a/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/Activator.java b/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/Activator.java new file mode 100644 index 0000000..1f9b3ec --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/Activator.java @@ -0,0 +1,76 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.tizen.efluibuilder.codegenerator"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (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 Activator getDefault() { + return plugin; + } + +} diff --git a/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/CodeGenerator.java b/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/CodeGenerator.java new file mode 100644 index 0000000..d29c839 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/CodeGenerator.java @@ -0,0 +1,51 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import org.eclipse.core.resources.IProject; + + +public final class CodeGenerator implements ICodeGenerator { + private IProject project = null; + + public CodeGenerator(IProject project) { + this.project = project; + } + + private IProject getProject() { + return project; + } + + @Override + public void generate() throws CodeGeneratorException { + ManagedCodeGenerator generator = new ManagedCodeGenerator(getProject()); + generator.generate(); + } + + @Override + public void clean() throws CodeGeneratorException { + ManagedCodeGenerator generator = new ManagedCodeGenerator(getProject()); + generator.clean(); + } +} diff --git a/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/CodeGeneratorConstants.java b/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/CodeGeneratorConstants.java new file mode 100644 index 0000000..f78422f --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/CodeGeneratorConstants.java @@ -0,0 +1,112 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +public final class CodeGeneratorConstants { + public static final String REPLACE_KEY_ID = "%id%"; //$NON-NLS-1$ + public static final String VIEW_NAME = REPLACE_KEY_ID; // $NON-NLS-1$ + public static final String BOILERPLATE = "/*******************************************************************************\n" //$NON-NLS-1$ + + "* This file was generated by UI Builder.\n" //$NON-NLS-1$ + + "* User should hand edit this file.\n" //$NON-NLS-1$ + + "********************************************************************************/\n\n" //$NON-NLS-1$ + + "#include \"app_main.h\"\n" //$NON-NLS-1$ + + "#include \"view_data.h\"\n" //$NON-NLS-1$ + + "#include \"uib_app_manager.h\"\n" //$NON-NLS-1$ + + "#include \"uib_views.h\"\n" //$NON-NLS-1$ + + "#include \"uib_views_inc.h\"\n" //$NON-NLS-1$ + + "\n" //$NON-NLS-1$ + + "typedef struct _uib_" + VIEW_NAME + "_control_context {\n" //$NON-NLS-1$ + + " /* add your variables here */\n" //$NON-NLS-1$ + + "\n" //$NON-NLS-1$ + + "} uib_" + VIEW_NAME + "_control_context;\n" //$NON-NLS-1$ + + "\n"; //$NON-NLS-1$ + public static final String BOILERPLATE_CIRCLE = "/*******************************************************************************\n" //$NON-NLS-1$ + + "* This file was generated by UI Builder.\n" //$NON-NLS-1$ + + "* User should hand edit this file.\n" //$NON-NLS-1$ + + "********************************************************************************/\n\n" //$NON-NLS-1$ + + "#include \"app_main.h\"\n" //$NON-NLS-1$ + + "#include \"uib_views.h\"\n" //$NON-NLS-1$ + + "#include \"uib_views_inc.h\"\n" //$NON-NLS-1$ + + "\n" //$NON-NLS-1$ + + "typedef struct _uib_" + VIEW_NAME + "_control_context {\n" //$NON-NLS-1$ + + " /* add your variables here */\n" //$NON-NLS-1$ + + "\n" //$NON-NLS-1$ + + "} uib_" + VIEW_NAME + "_control_context;\n" //$NON-NLS-1$ + + "\n"; //$NON-NLS-1$ + public static final String MANAGED_BOILERPLATE = "/*******************************************************************************\n" //$NON-NLS-1$ + + "* This file was generated by UI Builder.\n" //$NON-NLS-1$ + + "* This file will be auto-generated each and everytime you save your project.\n" //$NON-NLS-1$ + + "* Do not hand edit this file.\n" //$NON-NLS-1$ + + "********************************************************************************/\n\n"; //$NON-NLS-1$ + + public static final String FILE_PROJECT_META = ".uproject"; + public static final String FILE_LAYOUT_META = "layout/layout.xml"; + public static final String FILE_DATABINDING_META = "layout/.databinding"; + public static final String FILE_CUSTOM_THEME = "res/theme/custom_theme.edj"; + + public static final String DIRECTORY_SRC = "src/"; //$NON-NLS-1$ + public static final String DIRECTORY_MANAGED = DIRECTORY_SRC + "managed/"; //$NON-NLS-1$ + public static final String DIRECTORY_EVENT_HANDLER = DIRECTORY_SRC + "event_handler/"; //$NON-NLS-1$ + public static final String DIRECTORY_MANAGED_SRC = DIRECTORY_MANAGED + "src/"; //$NON-NLS-1$ + public static final String DIRECTORY_MANAGED_INC = DIRECTORY_MANAGED + "inc/"; //$NON-NLS-1$ + + public static final String DIRECTORY_MANAGER_SRC = DIRECTORY_MANAGED_SRC + "manager/"; //$NON-NLS-1$ + public static final String DIRECTORY_UTILS_SRC = DIRECTORY_MANAGED_SRC + "utils/"; //$NON-NLS-1$ + public static final String DIRECTORY_VIEW_SRC = DIRECTORY_MANAGED_SRC + "view/"; //$NON-NLS-1$ + public static final String DIRECTORY_CONNECTION_SRC = DIRECTORY_MANAGED_SRC + "connection/"; //$NON-NLS-1$ + public static final String DIRECTORY_MANAGED_DATABINDING_INC = DIRECTORY_MANAGED_INC + "databinding/"; //$NON-NLS-1$ + public static final String DIRECTORY_MANAGED_DATABINDING_SRC = DIRECTORY_MANAGED_SRC + "databinding/"; //$NON-NLS-1$; + + public static final String UIB_APP_MANAGER_HEADER = CodeGeneratorConstants.DIRECTORY_MANAGED_INC + "uib_app_manager.h"; //$NON-NLS-1$ + public static final String UIB_APP_MANAGER_SOURCE = CodeGeneratorConstants.DIRECTORY_MANAGER_SRC + "uib_app_manager.c"; //$NON-NLS-1$ + public static final String UIB_VIEW_MANAGER_HEADER = CodeGeneratorConstants.DIRECTORY_MANAGED_INC + "uib_view_manager.h"; //$NON-NLS-1$ + public static final String UIB_VIEW_MANAGER_SOURCE = CodeGeneratorConstants.DIRECTORY_MANAGER_SRC + "uib_view_manager.c"; //$NON-NLS-1$ + public static final String UIB_GLOBAL_INC_HEADER = CodeGeneratorConstants.DIRECTORY_MANAGED_INC + "g_inc_uib.h"; //$NON-NLS-1$ + public static final String UIB_UTIL_HEADER = CodeGeneratorConstants.DIRECTORY_MANAGED_INC + "uib_util.h"; //$NON-NLS-1$ + public static final String UIB_UTIL_SOURCE = CodeGeneratorConstants.DIRECTORY_UTILS_SRC + "uib_util.c"; //$NON-NLS-1$ + public static final String UIB_VIEWS_INC_HEADER = CodeGeneratorConstants.DIRECTORY_MANAGED_INC + "uib_views_inc.h"; //$NON-NLS-1$ + public static final String UIB_VIEWS_HEADER = CodeGeneratorConstants.DIRECTORY_MANAGED_INC + "uib_views.h"; //$NON-NLS-1$ + public static final String UIB_VIEWS_SOURCE = CodeGeneratorConstants.DIRECTORY_VIEW_SRC + "uib_views.c"; //$NON-NLS-1$ + public static final String UIB_VIEW_DATA = CodeGeneratorConstants.DIRECTORY_MANAGED_INC + "view_data.h"; //$NON-NLS-1$ + public static final String UIB_VIEW_HEADER = CodeGeneratorConstants.DIRECTORY_MANAGED_INC + "uib_%id%_view.h"; //$NON-NLS-1$ + public static final String UIB_VIEW_SOURCE = CodeGeneratorConstants.DIRECTORY_VIEW_SRC + "uib_%id%_view.c"; //$NON-NLS-1$ + public static final String UIB_CONNECTION_SOURCE = CodeGeneratorConstants.DIRECTORY_CONNECTION_SRC + "uib_%id%_connection.c"; //$NON-NLS-1$ + + public static final String DIRECTORY_RES = "res/"; //$NON-NLS-1$ + public static final String UIB_APP_MANAGER_HEADER_XSL = "inc/uib_app_manager_header.xsl"; //$NON-NLS-1$ + public static final String UIB_APP_MANAGER_SOURCE_XSL = "src/uib_app_manager_source.xsl"; //$NON-NLS-1$ + public static final String UIB_VIEW_MANAGER_HEADER_XSL = "inc/uib_view_manager_header.xsl"; //$NON-NLS-1$ + public static final String UIB_VIEW_MANAGER_SOURCE_XSL = "src/uib_view_manager_source.xsl"; //$NON-NLS-1$ + public static final String UIB_GLOBAL_INC_HEADER_XSL = "inc/g_inc_uib_header.xsl"; //$NON-NLS-1$ + public static final String UIB_UTIL_HEADER_XSL = "inc/uib_util_header.xsl"; //$NON-NLS-1$ + public static final String UIB_UTIL_SOURCE_XSL = "src/uib_util_source.xsl"; //$NON-NLS-1$ + public static final String UIB_VIEWS_INC_HEADER_XSL = "inc/uib_views_inc_header.xsl"; //$NON-NLS-1$ + public static final String UIB_VIEWS_HEADER_XSL = "inc/uib_views_header.xsl"; //$NON-NLS-1$ + public static final String UIB_VIEWS_SOURCE_XSL = "src/uib_views_source.xsl"; //$NON-NLS-1$ + public static final String UIB_VIEW_DATA_HEADER_XSL = "inc/view_data_header.xsl"; //$NON-NLS-1$ + public static final String UIB_VIEW_HEADER_XSL = "inc/uib_view_header.xsl"; //$NON-NLS-1$ + public static final String UIB_VIEW_SOURCE_XSL = "src/uib_view_source.xsl"; //$NON-NLS-1$ + public static final String UIB_CONNECTION_SOURCE_XSL = "src/uib_connection_source.xsl"; //$NON-NLS-1$ + +} diff --git a/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/CodeGeneratorException.java b/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/CodeGeneratorException.java new file mode 100644 index 0000000..542d4ae --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/CodeGeneratorException.java @@ -0,0 +1,51 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +public final class CodeGeneratorException extends Exception { + + private static final long serialVersionUID = -6163340800998223729L; + + /** + * Constructs an {@code CodeGeneratorException} with {@code null} as its error detail message. + */ + public CodeGeneratorException() { + super(); + } + + /** + * Constructs an {@code CodeGeneratorException} with the specified detail message. + * + * @param message + * The detail message (which is saved for later retrieval by the + * {@link #getMessage()} method) + */ + public CodeGeneratorException(String message) { + super(message); + } + + public CodeGeneratorException(String message, Throwable e) { + super(message, e); + } +} diff --git a/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/CodeGeneratorUtil.java b/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/CodeGeneratorUtil.java new file mode 100644 index 0000000..7a5226f --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/CodeGeneratorUtil.java @@ -0,0 +1,301 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.Writer; +import java.net.URL; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.URIResolver; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.Platform; +import org.osgi.framework.Bundle; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.common.core.application.TizenProjectDescription; +import org.tizen.common.util.Assert; +import org.tizen.common.util.ProjectUtil; +import org.tizen.efluibuilder.utility.XMLUtil; +import org.w3c.dom.Document; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + + +public final class CodeGeneratorUtil { + + private static Logger logger = LoggerFactory.getLogger(CodeGeneratorUtil.class); + + private static final float SUPPORT_RM_VERSION = 2.4F; + + public static String getProfile(IProject project) throws SAXException, IOException, ParserConfigurationException, XPathExpressionException { + // read file + IFile projectMetaFile = project.getFile(CodeGeneratorConstants.FILE_PROJECT_META); + File appFile = new File(projectMetaFile.getLocation().toString()); + Document document = loadXML(appFile); + Assert.notNull(document); + + // read shape element + String shape = XMLUtil.getValue(document, "/properties/shape"); + + TizenProjectDescription tizenProjectDescription = ProjectUtil.getTizenProjectDescription(project); + String profile = tizenProjectDescription.getProfileName(); + if (shape.equals("circle")) { + profile = "wearable-circle"; + } + return profile; + } + + public static String getProjectVersion(IProject project) throws SAXException, IOException, ParserConfigurationException, XPathExpressionException { + // read file + IFile projectMetaFile = project.getFile(CodeGeneratorConstants.FILE_PROJECT_META); + File appFile = new File(projectMetaFile.getLocation().toString()); + Document document = loadXML(appFile); + Assert.notNull(document); + + // read version + String version = null; + if (XMLUtil.isExistValue(document, "/properties/version")) { + version = XMLUtil.getValue(document, "/properties/version"); + } else { + version = "0.0"; + } + + return version; + } + + public static Document loadXML(File xml) throws SAXException, IOException, ParserConfigurationException { + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + documentBuilderFactory.setNamespaceAware(true); + DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder(); + Document doc = builder.parse(xml); + return doc; + } + + public static NodeList getViews(Document document) throws XPathExpressionException { + String pathExpression = "/document/views/view"; + NodeList nodeList = getNodes(document, pathExpression); + return nodeList; + } + + public static NodeList getNodes(Document document, String pathExpression) throws XPathExpressionException { + // start FIXME : following codes should be removed + // [MAC] Work Around for JDK 1.7 runtime environment + Thread thread = Thread.currentThread(); + ClassLoader cl = thread.getContextClassLoader(); + if (cl == null) { + cl = CodeGeneratorUtil.class.getClassLoader(); + thread.setContextClassLoader(cl); + } + // end [MAC] Work Around for JDK 1.7 runtime environment + + XPath xpath = XPathFactory.newInstance().newXPath(); + NodeList nodeList = (NodeList) xpath.evaluate(pathExpression, document, XPathConstants.NODESET); + return nodeList; + } + + public static Node getView(Document document, String id) throws XPathExpressionException { + if (id == null || id.isEmpty()) { + return null; + } + + NodeList views = getViews(document); + for (int i = 0; i < views.getLength(); i++) { + Node node = views.item(i); + String viewId = CodeGeneratorUtil.getViewId(node); + if (id.equals(viewId)) { + return node; + } + } + + return null; + } + + public static String getStartupView(Document document) throws XPathExpressionException { + // start FIXME : following codes should be removed + // [MAC] Work Around for JDK 1.7 runtime environment + Thread thread = Thread.currentThread(); + ClassLoader cl = thread.getContextClassLoader(); + if (cl == null) { + cl = CodeGeneratorUtil.class.getClassLoader(); + thread.setContextClassLoader(cl); + } + // end [MAC] Work Around for JDK 1.7 runtime environment + + XPath xpath = XPathFactory.newInstance().newXPath(); + String expression = "/document/views/@startup"; + Object object = xpath.evaluate(expression, document, XPathConstants.NODE); + Assert.notNull(object); + Assert.isTrue(object instanceof Node); + Node node = (Node) object; + String id = node.getTextContent(); + return id; + } + + public static Writer getDestinationWriter(File targetDirectory, String path) throws IOException { + File destination = new File(targetDirectory, path); + FileWriter out = new FileWriter(destination); + return out; + } + + public static InputStream openStream(String name) throws IOException { + Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID); + if (bundle == null) { + logger.error("Invalid bundle"); + return null; + } + URL url = bundle.getResource(name); + if (url == null) { + logger.error("Invalid resource"); + return null; + } + InputStream stream = url.openStream(); + if (stream == null) { + logger.error("Invalid stream"); + return null; + } + return stream; + } + + public static String getViewId(Node node) { + String name = null; + NamedNodeMap viewNodeAttributeMap = node.getAttributes(); + for (int i = 0; i < viewNodeAttributeMap.getLength(); i++) { + Node viewNodeAttribute = viewNodeAttributeMap.item(i); + if (viewNodeAttribute.getNodeName().equals("id")) { + name = viewNodeAttribute.getNodeValue(); + } + } + + return name; + } + + public static boolean isVersionRMSupport(String platformVersionString) { + platformVersionString = platformVersionString.substring(0, 3); // eg) 2.3.1 -> 2.3 + float platformVersionFloat = Float.parseFloat(platformVersionString); + if (platformVersionFloat >= SUPPORT_RM_VERSION) { + // The alternative resource support 2.4 platform upper + return true; + } else { + return false; + } + } + + public static void createDirectoy(File targetDirectory, String path) { + File directory = new File(targetDirectory, path); + if (!directory.exists()) { + boolean result = directory.mkdirs(); + if (result == false) { + logger.warn("It failed to create directory : " + directory.getPath()); + } + } + } + + /** + * @param node + * @param writer + * @param xslStream + * @param parameterKey + * @param parameterValue + * @param isRMSupportVersion + * @param profile + * @throws TransformerException + * @throws IOException + */ + public static void generateCode(Node node, Writer writer, StreamSource xslStream, String parameterKey, + String parameterValue, String isRMSupportVersion, String profile) + throws TransformerException, IOException { + // create Tranform + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + transformerFactory.setURIResolver(new URIResolver() { + @Override + public Source resolve(String href, String base) throws TransformerException { + String uri = "res/" + href; + try { + InputStream stream = openStream(uri); + return new StreamSource(stream); + } catch (IOException e) { + logger.error(e.getMessage()); + } + return null; + } + }); + // DOMSource xslDom = new DOMSource(xslDoc); + Transformer transformer = transformerFactory.newTransformer(xslStream); + transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + transformer.setOutputProperty(OutputKeys.METHOD, "text"); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + transformer.setParameter(parameterKey, parameterValue); + + if (isRMSupportVersion != null) { // for RM + transformer.setParameter("is_version_rm_support", isRMSupportVersion); + } + + if (profile != null) { + transformer.setParameter("profile", profile); + } + + // transform + DOMSource srcDom = new DOMSource(node); + + // Writer writer = new OutputStreamWriter(out); + StreamResult result = new StreamResult(writer); + transformer.transform(srcDom, result); + writer.close(); + } + + public static String getNodeId(Node node, final String id) { + String nodeId = null; + + Node node2 = node.getAttributes().getNamedItem(id); + if (node2 != null) { + nodeId = node2.getTextContent(); + } + + return nodeId; + } + +} diff --git a/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/DataBindingCodeGenerator.java b/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/DataBindingCodeGenerator.java new file mode 100644 index 0000000..2fcc5e1 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/DataBindingCodeGenerator.java @@ -0,0 +1,240 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.codegenerator; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.Writer; + +import javax.xml.transform.TransformerException; +import javax.xml.transform.stream.StreamSource; +import javax.xml.xpath.XPathExpressionException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public class DataBindingCodeGenerator { + private enum CODE_TYPE { + HEADER, SOURCE + } + + private enum DOCUMENT_TYPE { + LAYOUT_DOCUMENT, DATABINDING_DOCUMENT + } + + private enum CODE_MODULE { + DATABINDING_MANAGER("res/databinding/db_manager_", "uib_db_manager", DOCUMENT_TYPE.LAYOUT_DOCUMENT), + DATABINDING_VIEWX_BINDINGS("res/databinding/db_view_bindings_", "uib_views_binding", DOCUMENT_TYPE.LAYOUT_DOCUMENT), + DATABINDING_DATAMODELX("res/databinding/db_datamodel_", "", DOCUMENT_TYPE.DATABINDING_DOCUMENT), + DATABINDING_DATASOURCEX("res/databinding/db_datasource_", "", DOCUMENT_TYPE.DATABINDING_DOCUMENT), + DATABINDING_DATAMODELS("res/databinding/db_datamodels_","uib_datamodels", DOCUMENT_TYPE.DATABINDING_DOCUMENT), + DATABINDING_VIEWS_BINDING("res/databinding/db_views_binding_","uib_views_binding", DOCUMENT_TYPE.LAYOUT_DOCUMENT), + DATABINDING_DATASOURCES("res/databinding/db_datasources_","uib_datasources", DOCUMENT_TYPE.DATABINDING_DOCUMENT), + DATABINDING_DS_HANDLER_CONTACTS("res/databinding/db_ds_handler_contacts_","datasources/uib_datasource_handler_contacts", DOCUMENT_TYPE.DATABINDING_DOCUMENT), + DATABINDING_DS_HANDLER_STATIC("res/databinding/db_ds_handler_static_","datasources/uib_datasource_handler_static", DOCUMENT_TYPE.DATABINDING_DOCUMENT), + DATABINDING_DS_HANDLER_CALLHISTORY("res/databinding/db_ds_handler_call_history_","datasources/uib_datasource_handler_call_history", DOCUMENT_TYPE.DATABINDING_DOCUMENT), + DATABINDING_DS_HANDLER_REMOTE("res/databinding/db_ds_handler_remote_","datasources/uib_datasource_handler_remote", DOCUMENT_TYPE.DATABINDING_DOCUMENT), + DATABINDING_COMMON("res/databinding/db_common_","uib_databinding_common", DOCUMENT_TYPE.DATABINDING_DOCUMENT), + DATABINDING_LIST_WIDGET_HANDLER("res/databinding/db_widget_handler_list_","widgets/uib_widget_handler_list", DOCUMENT_TYPE.LAYOUT_DOCUMENT), + DATABINDING_LISTITEM_WIDGET_HANDLER("res/databinding/db_widget_handler_listitem_","widgets/uib_widget_handler_listitem", DOCUMENT_TYPE.LAYOUT_DOCUMENT), + DATABINDING_LABEL_WIDGET_HANDLER("res/databinding/db_widget_handler_label_","widgets/uib_widget_handler_label", DOCUMENT_TYPE.LAYOUT_DOCUMENT), + DATABINDING_BUTTON_WIDGET_HANDLER("res/databinding/db_widget_handler_button_","widgets/uib_widget_handler_button", DOCUMENT_TYPE.LAYOUT_DOCUMENT), + DATABINDING_CHECKBOX_WIDGET_HANDLER("res/databinding/db_widget_handler_checkbox_","widgets/uib_widget_handler_checkbox", DOCUMENT_TYPE.LAYOUT_DOCUMENT), + DATABINDING_RADIO_WIDGET_HANDLER("res/databinding/db_widget_handler_radio_","widgets/uib_widget_handler_radio", DOCUMENT_TYPE.LAYOUT_DOCUMENT), + DATABINDING_FLIPSELECTOR_WIDGET_HANDLER("res/databinding/db_widget_handler_flipselector_","widgets/uib_widget_handler_flipselector", DOCUMENT_TYPE.LAYOUT_DOCUMENT), + DATABINDING_FLIPSELECTORITEM_WIDGET_HANDLER("res/databinding/db_widget_handler_flipselectoritem_","widgets/uib_widget_handler_flipselectoritem", DOCUMENT_TYPE.LAYOUT_DOCUMENT), + DATABINDING_HOVERSEL_WIDGET_HANDLER("res/databinding/db_widget_handler_hoversel_","widgets/uib_widget_handler_hoversel", DOCUMENT_TYPE.LAYOUT_DOCUMENT), + DATABINDING_HOVERSELITEM_WIDGET_HANDLER("res/databinding/db_widget_handler_hoverselitem_","widgets/uib_widget_handler_hoverselitem", DOCUMENT_TYPE.LAYOUT_DOCUMENT); + + /** + * @return the XSLpath + */ + public String getXSLpath() { + return XSLpath; + } + + /** + * @return the generatedCodePath + */ + public String getGeneratedCodePath() { + return generatedCodePath; + } + + public DOCUMENT_TYPE getDocumentType() { + return documentType; + } + + private String XSLpath; + private String generatedCodePath; + private DOCUMENT_TYPE documentType; + + private CODE_MODULE(String XSLpath, String generatedCodePath, DOCUMENT_TYPE documentType) { + this.XSLpath = XSLpath; + this.generatedCodePath = generatedCodePath; + this.documentType = documentType; + } + + } + + private final File targetDirectory; + private final String isRMSupportVersion; + private final String profile; + private final Document tizenLayoutDocument; + private final Document databindingDocument; + private NodeList viewList; + private NodeList datamodelList; + private NodeList datasourceList; + private static final String UI_DATABINDING_VIEWX_BINDINGS = "res/databinding/db_view_bindings_"; //$NON-NLS-1$ + private static final String UI_DATABINDING_DATAMODELX = "res/databinding/db_datamodel_"; //$NON-NLS-1$ + private static final String UI_DATABINDING_DATASOURCEX = "res/databinding/db_datasource_"; //$NON-NLS-1$ + + /** + * @param targetDirectory + * @param tizenLayoutDocument + * @param databindingDocument + * @param isRMSupportVersion + * @param profile + */ + public DataBindingCodeGenerator(File targetDirectory, Document tizenLayoutDocument, Document databindingDocument, String isRMSupportVersion, + String profile) { + this.targetDirectory = targetDirectory; + this.tizenLayoutDocument = tizenLayoutDocument; + this.databindingDocument = databindingDocument; + this.isRMSupportVersion = isRMSupportVersion; + this.profile = profile; + try { + this.viewList = CodeGeneratorUtil.getNodes(tizenLayoutDocument, "/document/views/view"); + this.datamodelList = CodeGeneratorUtil.getNodes(databindingDocument, "/dataBinding/dataModel"); + this.datasourceList = CodeGeneratorUtil.getNodes(databindingDocument, "/dataBinding/dataSource"); + } catch (XPathExpressionException e) { + this.viewList = null; + this.datamodelList = null; + this.datasourceList = null; + } + } + + private static Logger logger = LoggerFactory.getLogger(DataBindingCodeGenerator.class); + + public void generate() throws TransformerException, IOException { + + for (CODE_MODULE module : CODE_MODULE.values()) { + if (!module.getGeneratedCodePath().isEmpty()) { + generateDataBindingCode(module.getXSLpath(), module.getGeneratedCodePath(), module.getDocumentType()); + } + } + + // create uib_dmX_datamodel.h & uib_dmX_datamodel.c + generateDataBindingForNodes(UI_DATABINDING_DATAMODELX,"datamodels/uib_", "_datamodel", datamodelList, "modelName", "datamodel_id", DOCUMENT_TYPE.DATABINDING_DOCUMENT); + + // create uib_dsX_datasource.h & uib_dsX_datasource.c + generateDataBindingForNodes(UI_DATABINDING_DATASOURCEX,"datasources/uib_", "_datasource", datasourceList, "dataSource", "datasource_id",DOCUMENT_TYPE.DATABINDING_DOCUMENT); + + // create uib_viewX_bindings.h & uib_viewX_bindings.c + generateDataBindingForNodes(UI_DATABINDING_VIEWX_BINDINGS,"viewbindings/uib_", "_bindings", viewList, "id", "current_view_name", DOCUMENT_TYPE.LAYOUT_DOCUMENT); + + } + + private void generateDataBindingForNodes(final String xslPath,final String fileNamePrefix, final String fileNameSuffix, NodeList nodeList, + String nodeKey, String XSLParameterKey, DOCUMENT_TYPE documentType) throws TransformerException, IOException { + String localXSLPath = null; + String generatedFileNamePrefix = null; + Document document = null; + if(documentType == DOCUMENT_TYPE.DATABINDING_DOCUMENT){ + document = databindingDocument; + }else{ + document = tizenLayoutDocument; + } + for (CODE_TYPE codeType : CODE_TYPE.values()) { + if (codeType == CODE_TYPE.HEADER) { + localXSLPath = xslPath.concat("header.xsl"); + // Pick the filename part from relative path for headers only. + String[] filePathSegments = fileNamePrefix.split("/"); + generatedFileNamePrefix = filePathSegments[filePathSegments.length - 1]; + } else { + localXSLPath = xslPath.concat("source.xsl"); + generatedFileNamePrefix= fileNamePrefix; + } + if (nodeList != null) { + for (int i = 0; i < nodeList.getLength(); i++) { + InputStream xslIs = CodeGeneratorUtil.openStream(localXSLPath); + StreamSource xslStream = new StreamSource(xslIs); + Node node = nodeList.item(i); + String nodeId = CodeGeneratorUtil.getNodeId(node, nodeKey); + Writer destinationWriter = getDestinationWriterForDataBinding( + generatedFileNamePrefix + nodeId + fileNameSuffix, codeType); + CodeGeneratorUtil.generateCode(document, destinationWriter, xslStream, XSLParameterKey, nodeId, + isRMSupportVersion, profile); + xslIs.close(); + } + } + } + } + + private void generateDataBindingCode(final String xslPath, final String fileNamePathSuffix, DOCUMENT_TYPE documentType) + throws TransformerException, IOException { + String localXSLPath = null; + String generatedCodeFilePath = null; + Document document = null; + + if(documentType == DOCUMENT_TYPE.DATABINDING_DOCUMENT){ + document = databindingDocument; + }else{ + document = tizenLayoutDocument; + } + + for (CODE_TYPE codeType : CODE_TYPE.values()) { + if (codeType == CODE_TYPE.HEADER) { + localXSLPath = xslPath.concat("header.xsl"); + // Pick the filename part from relative path for headers only. + String[] filePathSegments = fileNamePathSuffix.split("/"); + generatedCodeFilePath = filePathSegments[filePathSegments.length - 1]; + } else { + localXSLPath = xslPath.concat("source.xsl"); + generatedCodeFilePath = fileNamePathSuffix; + } + InputStream xslIs = CodeGeneratorUtil.openStream(localXSLPath); + StreamSource xslStream = new StreamSource(xslIs); + Writer destinationWriter = getDestinationWriterForDataBinding(generatedCodeFilePath, codeType); + CodeGeneratorUtil.generateCode(document, destinationWriter, xslStream, "", "", isRMSupportVersion, profile); + xslIs.close(); + } + } + + private Writer getDestinationWriterForDataBinding(final String fileNamePathSuffix, CODE_TYPE type) throws IOException { + String codePath = null; + if (type == CODE_TYPE.HEADER) { + codePath = CodeGeneratorConstants.DIRECTORY_MANAGED_DATABINDING_INC + fileNamePathSuffix + ".h"; + } else { + codePath = CodeGeneratorConstants.DIRECTORY_MANAGED_DATABINDING_SRC + fileNamePathSuffix + ".c"; + } + File destination = new File(targetDirectory, codePath); + FileWriter out = new FileWriter(destination); + return out; + } + +} diff --git a/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/ICodeGenerator.java b/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/ICodeGenerator.java new file mode 100644 index 0000000..ae264c3 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/ICodeGenerator.java @@ -0,0 +1,39 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +public interface ICodeGenerator { + + /** + * + * @throws CodeGeneratorException + */ + public void generate() throws CodeGeneratorException; + + /** + * + * @throws CodeGeneratorException + */ + public void clean() throws CodeGeneratorException; +} diff --git a/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/ManagedCodeGenerator.java b/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/ManagedCodeGenerator.java new file mode 100644 index 0000000..5fdeb21 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/ManagedCodeGenerator.java @@ -0,0 +1,276 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.Writer; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import javax.xml.xpath.XPathExpressionException; + +import org.apache.commons.io.FileUtils; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Path; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.common.TizenProjectType; +import org.tizen.common.core.application.TizenProjectDescription; +import org.tizen.common.util.Assert; +import org.tizen.common.util.ProjectUtil; +import org.tizen.efluibuilder.codegenerator.view.ViewCodeGenerator; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + + +public final class ManagedCodeGenerator { + protected static Logger logger = LoggerFactory.getLogger(ManagedCodeGenerator.class); + + public static Map managedCodeMap = initManagedCodeMap(); + + private IProject project = null; + private File targetDirectory = null; + private String startUpView = null; + private String profile = null; + private String isRMSupportVersion = null; + private boolean isWidgetProject = false; + private boolean hasCustomTheme = false; + private String platformVersion = null; + + private static Map initManagedCodeMap() { + Map files = new HashMap(); + String basePath = CodeGeneratorConstants.DIRECTORY_RES; + files.put(CodeGeneratorConstants.UIB_APP_MANAGER_HEADER, basePath + CodeGeneratorConstants.UIB_APP_MANAGER_HEADER_XSL); + files.put(CodeGeneratorConstants.UIB_APP_MANAGER_SOURCE, basePath + CodeGeneratorConstants.UIB_APP_MANAGER_SOURCE_XSL); + files.put(CodeGeneratorConstants.UIB_VIEW_MANAGER_HEADER, basePath + CodeGeneratorConstants.UIB_VIEW_MANAGER_HEADER_XSL); + files.put(CodeGeneratorConstants.UIB_VIEW_MANAGER_SOURCE, basePath + CodeGeneratorConstants.UIB_VIEW_MANAGER_SOURCE_XSL); + files.put(CodeGeneratorConstants.UIB_GLOBAL_INC_HEADER, basePath + CodeGeneratorConstants.UIB_GLOBAL_INC_HEADER_XSL); + files.put(CodeGeneratorConstants.UIB_UTIL_HEADER, basePath + CodeGeneratorConstants.UIB_UTIL_HEADER_XSL); + files.put(CodeGeneratorConstants.UIB_UTIL_SOURCE, basePath + CodeGeneratorConstants.UIB_UTIL_SOURCE_XSL); + files.put(CodeGeneratorConstants.UIB_VIEWS_INC_HEADER, basePath + CodeGeneratorConstants.UIB_VIEWS_INC_HEADER_XSL); + files.put(CodeGeneratorConstants.UIB_VIEWS_HEADER, basePath + CodeGeneratorConstants.UIB_VIEWS_HEADER_XSL); + files.put(CodeGeneratorConstants.UIB_VIEWS_SOURCE, basePath + CodeGeneratorConstants.UIB_VIEWS_SOURCE_XSL); + files.put(CodeGeneratorConstants.UIB_VIEW_DATA, basePath + CodeGeneratorConstants.UIB_VIEW_DATA_HEADER_XSL); + return Collections.unmodifiableMap(files); + } + + public ManagedCodeGenerator(IProject project) throws CodeGeneratorException { + this.project = project; + + try { + profile = CodeGeneratorUtil.getProfile(project); + } catch (XPathExpressionException e) { + throw new CodeGeneratorException(e.getMessage()); + } catch (SAXException e) { + throw new CodeGeneratorException(e.getMessage()); + } catch (IOException e) { + throw new CodeGeneratorException(e.getMessage()); + } catch (ParserConfigurationException e) { + throw new CodeGeneratorException(e.getMessage()); + } + + TizenProjectDescription tizenProjectDescription = ProjectUtil.getTizenProjectDescription(project); + platformVersion = tizenProjectDescription.getVersion(); + isRMSupportVersion = CodeGeneratorUtil.isVersionRMSupport(platformVersion) + ""; + targetDirectory = new File(project.getLocation().toString()); + TizenProjectType projectType = ProjectUtil.getTizenProjectType(project); + if (projectType != null) { + isWidgetProject = projectType.isNativeWidgetApplicationProject(); + } + hasCustomTheme = project.exists(new Path(CodeGeneratorConstants.FILE_CUSTOM_THEME)); + } + + public void generate() throws CodeGeneratorException { + IFile layoutMetaFile = project.getFile(CodeGeneratorConstants.FILE_LAYOUT_META); + File srcFile = new File(layoutMetaFile.getLocation().toString()); + + try { + Document document = CodeGeneratorUtil.loadXML(srcFile); + Assert.notNull(document); + this.startUpView = CodeGeneratorUtil.getStartupView(document); + + deleteOldFilesAndCreateDirectories(targetDirectory); + + Set keySet = managedCodeMap.keySet(); + Iterator iterator = keySet.iterator(); + while (iterator.hasNext()) { + String targetPath = iterator.next(); + String xsl = managedCodeMap.get(targetPath); + // get writer + Writer destinationWriter = CodeGeneratorUtil.getDestinationWriter(targetDirectory, targetPath); + + // get StreamSource + InputStream xslIs = CodeGeneratorUtil.openStream(xsl); + StreamSource xslStream = new StreamSource(xslIs); + + generateCode(document, destinationWriter, xslStream); + + // close + destinationWriter.close(); + xslIs.close(); + } + + NodeList list = CodeGeneratorUtil.getViews(document); + generateViewsFiles(list); + // create databinding related source and headers + generateDataBindingCode(list, document); + + refreshManaged(); + } catch (SAXException e) { + throw new CodeGeneratorException(e.getMessage()); + } catch (IOException e) { + throw new CodeGeneratorException(e.getMessage()); + } catch (ParserConfigurationException e) { + throw new CodeGeneratorException(e.getMessage()); + } catch (TransformerException e) { + throw new CodeGeneratorException(e.getMessage()); + } catch (XPathExpressionException e) { + throw new CodeGeneratorException(e.getMessage()); + } + } + + public void clean() throws CodeGeneratorException { + File directoryToBeDeleted = new File(this.targetDirectory, CodeGeneratorConstants.DIRECTORY_MANAGED); + if (directoryToBeDeleted.exists()) { + try { + FileUtils.deleteDirectory(directoryToBeDeleted); + } catch (IOException e) { + throw new CodeGeneratorException(e.getMessage()); + } + } + refreshManaged(); + } + + private void generateViewsFiles(NodeList list) throws CodeGeneratorException { + ViewCodeGenerator viewCodeGenerator = new ViewCodeGenerator(project); + for (int i = 0; i < list.getLength(); i++) { + Node node = list.item(i); + String viewId = CodeGeneratorUtil.getViewId(node); + viewCodeGenerator.generate(viewId); + } + } + + private void deleteOldFilesAndCreateDirectories(File directory) throws CodeGeneratorException { + clean(); + createDirectories(directory); + } + + private void createDirectories(File directory) { + CodeGeneratorUtil.createDirectoy(this.targetDirectory, CodeGeneratorConstants.DIRECTORY_MANAGED_INC); + CodeGeneratorUtil.createDirectoy(this.targetDirectory, CodeGeneratorConstants.DIRECTORY_VIEW_SRC); + CodeGeneratorUtil.createDirectoy(this.targetDirectory, CodeGeneratorConstants.DIRECTORY_UTILS_SRC); + CodeGeneratorUtil.createDirectoy(this.targetDirectory, CodeGeneratorConstants.DIRECTORY_MANAGER_SRC); + CodeGeneratorUtil.createDirectoy(this.targetDirectory, CodeGeneratorConstants.DIRECTORY_CONNECTION_SRC); + // Databinding directory creation + CodeGeneratorUtil.createDirectoy(this.targetDirectory, CodeGeneratorConstants.DIRECTORY_MANAGED_DATABINDING_INC); + CodeGeneratorUtil.createDirectoy(this.targetDirectory, CodeGeneratorConstants.DIRECTORY_MANAGED_DATABINDING_SRC); + CodeGeneratorUtil.createDirectoy(this.targetDirectory, CodeGeneratorConstants.DIRECTORY_MANAGED_DATABINDING_SRC + "/widgets"); + CodeGeneratorUtil.createDirectoy(this.targetDirectory, CodeGeneratorConstants.DIRECTORY_MANAGED_DATABINDING_SRC + "/datasources"); + CodeGeneratorUtil.createDirectoy(this.targetDirectory, CodeGeneratorConstants.DIRECTORY_MANAGED_DATABINDING_SRC + "/datamodels"); + CodeGeneratorUtil.createDirectoy(this.targetDirectory, CodeGeneratorConstants.DIRECTORY_MANAGED_DATABINDING_SRC + "/viewbindings"); + } + + private void generateCode(Node node, Writer writer, StreamSource xslStream) throws TransformerException { + // create Tranform + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + // DOMSource xslDom = new DOMSource(xslDoc); + Transformer transformer = transformerFactory.newTransformer(xslStream); + transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + transformer.setOutputProperty(OutputKeys.METHOD, "text"); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + if (startUpView != null) { + transformer.setParameter("startup_view", startUpView); + } + + if (profile != null) { + transformer.setParameter("profile", profile); + } + if (isRMSupportVersion != null) { + transformer.setParameter("is_version_rm_support", isRMSupportVersion); + } + + transformer.setParameter("is_widget_project", isWidgetProject); + transformer.setParameter("has_custom_theme", hasCustomTheme); + + if (platformVersion != null) { + transformer.setParameter("version", platformVersion); + } + + // transform + DOMSource srcDom = new DOMSource(node); + // Writer writer = new OutputStreamWriter(out); + StreamResult result = new StreamResult(writer); + transformer.transform(srcDom, result); + } + + private void refreshManaged() throws CodeGeneratorException { + IFolder folder = project.getFolder(CodeGeneratorConstants.DIRECTORY_MANAGED); + if (folder != null) { + try { + folder.refreshLocal(IResource.DEPTH_INFINITE, null); + } catch (CoreException e) { + throw new CodeGeneratorException(e.getMessage()); + } + } + } + + private void generateDataBindingCode(NodeList list, Document tizenLayoutDocument) throws TransformerException, IOException { + IFile databindingMetaFile = project.getFile(CodeGeneratorConstants.FILE_DATABINDING_META); + File srcFile = new File(databindingMetaFile.getLocation().toString()); + + Document databindingDocument = null; + try { + databindingDocument = CodeGeneratorUtil.loadXML(srcFile); + } catch (SAXException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ParserConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + DataBindingCodeGenerator generator = new DataBindingCodeGenerator(this.targetDirectory, tizenLayoutDocument, + databindingDocument, isRMSupportVersion, profile); + generator.generate(); + } +} diff --git a/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/event/EventCodeGenerator.java b/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/event/EventCodeGenerator.java new file mode 100644 index 0000000..6a907bb --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/event/EventCodeGenerator.java @@ -0,0 +1,118 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator.event; + +import java.io.ByteArrayInputStream; +import java.io.IOException; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPathExpressionException; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.tizen.common.util.Assert; +import org.tizen.efluibuilder.codegenerator.CodeGeneratorConstants; +import org.tizen.efluibuilder.codegenerator.CodeGeneratorException; +import org.tizen.efluibuilder.codegenerator.CodeGeneratorUtil; +import org.xml.sax.SAXException; + + +public class EventCodeGenerator implements IEventCodeGenerator { + private IProject project = null; + + public EventCodeGenerator(IProject project) { + this.project = project; + } + + private IProject getProject() { + return project; + } + + @Override + public void addView(String id) throws CodeGeneratorException { + // check FOLDER_EVENT_HANDLER folder + IProgressMonitor monitor = new NullProgressMonitor(); + IFolder folder = EventCodeGeneratorUtil.getEventHandlerFolder(getProject()); + if (!folder.exists()) { + try { + folder.create(false, true, new NullProgressMonitor()); + folder.refreshLocal(IResource.DEPTH_ZERO, monitor); + } catch (CoreException e) { + throw new CodeGeneratorException(e.getMessage()); + } + } + IFile file = EventCodeGeneratorUtil.getEventHandlerFile(getProject(), id); + if (file.exists()) { + return; + } + + // FIXME : start for wearable circle + String profile; + try { + profile = CodeGeneratorUtil.getProfile(getProject()); + } catch (XPathExpressionException e) { + throw new CodeGeneratorException(e.getMessage()); + } catch (SAXException e) { + throw new CodeGeneratorException(e.getMessage()); + } catch (IOException e) { + throw new CodeGeneratorException(e.getMessage()); + } catch (ParserConfigurationException e) { + throw new CodeGeneratorException(e.getMessage()); + } + + Assert.notNull(profile); + String handlerCode; + if (profile != null && profile.equals("wearable-circle")) { + handlerCode = CodeGeneratorConstants.BOILERPLATE_CIRCLE; + } else { + handlerCode = CodeGeneratorConstants.BOILERPLATE; + } + // FIXME : end for wearable circle + + handlerCode = handlerCode.replace(CodeGeneratorConstants.REPLACE_KEY_ID, id); + try { + file.create(new ByteArrayInputStream(handlerCode.getBytes()), true, monitor); + } catch (CoreException e) { + throw new CodeGeneratorException(e.getMessage()); + } + } + + @Override + public void removeView(String id) throws CodeGeneratorException { + IFile file = EventCodeGeneratorUtil.getEventHandlerFile(getProject(), id); + if (!file.exists()) { + return; + } + try { + file.delete(true, new NullProgressMonitor()); + } catch (CoreException e) { + throw new CodeGeneratorException(e.getMessage()); + } + } +} diff --git a/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/event/EventCodeGeneratorUtil.java b/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/event/EventCodeGeneratorUtil.java new file mode 100644 index 0000000..f4252d2 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/event/EventCodeGeneratorUtil.java @@ -0,0 +1,51 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator.event; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.tizen.efluibuilder.codegenerator.CodeGeneratorConstants; + + +public final class EventCodeGeneratorUtil { + + public static IFolder getEventHandlerFolder(IProject project) { + IFolder folder = project.getFolder(CodeGeneratorConstants.DIRECTORY_EVENT_HANDLER); + return folder; + } + + public static IFile getEventHandlerFile(IProject project, String id) { + IFolder folder = getEventHandlerFolder(project); + // make file name + String fileName = createFileName(id); + IFile file = folder.getFile(fileName); + return file; + } + + private static String createFileName(String id) { + String fileName = "uib_" + id + "_event_handler.c"; + return fileName; + } +} diff --git a/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/event/IEventCodeGenerator.java b/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/event/IEventCodeGenerator.java new file mode 100644 index 0000000..28df34b --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/event/IEventCodeGenerator.java @@ -0,0 +1,42 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator.event; + +import org.tizen.efluibuilder.codegenerator.CodeGeneratorException; + + +public interface IEventCodeGenerator { + + /** + * + * @throws CodeGeneratorException + */ + public void addView(String id) throws CodeGeneratorException; + + /** + * + * @throws CodeGeneratorException + */ + public void removeView(String id) throws CodeGeneratorException; +} diff --git a/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/view/ViewCodeGenerator.java b/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/view/ViewCodeGenerator.java new file mode 100644 index 0000000..430fb0a --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/src/org/tizen/efluibuilder/codegenerator/view/ViewCodeGenerator.java @@ -0,0 +1,216 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator.view; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.Writer; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.URIResolver; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import javax.xml.xpath.XPathExpressionException; +import org.apache.commons.io.FileUtils; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.common.core.application.TizenProjectDescription; +import org.tizen.common.util.ProjectUtil; +import org.tizen.efluibuilder.codegenerator.CodeGeneratorConstants; +import org.tizen.efluibuilder.codegenerator.CodeGeneratorException; +import org.tizen.efluibuilder.codegenerator.CodeGeneratorUtil; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.xml.sax.SAXException; + + +public final class ViewCodeGenerator { + private static Logger logger = LoggerFactory.getLogger(ViewCodeGenerator.class); + + private static Map viewCodeMap = initViewCodeMap(); + private IProject project = null; + private File targetDirectory = null; + private String profile = null; + private String isRMSupportVersion = null; + private String platformVersion = null; + + private static Map initViewCodeMap() { + Map files = new HashMap(); + String basePath = CodeGeneratorConstants.DIRECTORY_RES; + files.put(CodeGeneratorConstants.UIB_VIEW_HEADER, basePath + CodeGeneratorConstants.UIB_VIEW_HEADER_XSL); + files.put(CodeGeneratorConstants.UIB_VIEW_SOURCE, basePath + CodeGeneratorConstants.UIB_VIEW_SOURCE_XSL); + files.put(CodeGeneratorConstants.UIB_CONNECTION_SOURCE, basePath + CodeGeneratorConstants.UIB_CONNECTION_SOURCE_XSL); + return Collections.unmodifiableMap(files); + } + + public ViewCodeGenerator(IProject project) throws CodeGeneratorException { + this.project = project; + + try { + profile = CodeGeneratorUtil.getProfile(project); + } catch (XPathExpressionException e) { + throw new CodeGeneratorException(e.getMessage()); + } catch (SAXException e) { + throw new CodeGeneratorException(e.getMessage()); + } catch (IOException e) { + throw new CodeGeneratorException(e.getMessage()); + } catch (ParserConfigurationException e) { + throw new CodeGeneratorException(e.getMessage()); + } + + TizenProjectDescription tizenProjectDescription = ProjectUtil.getTizenProjectDescription(project); + platformVersion = tizenProjectDescription.getVersion(); + isRMSupportVersion = CodeGeneratorUtil.isVersionRMSupport(platformVersion) + ""; + targetDirectory = new File(project.getLocation().toString()); + } + + public void generate(String viewId) throws CodeGeneratorException { + IFile layoutMetaFile = project.getFile(CodeGeneratorConstants.FILE_LAYOUT_META); + File srcFile = new File(layoutMetaFile.getLocation().toString()); + + try { + Document document = CodeGeneratorUtil.loadXML(srcFile); + + clean(viewId); + createDirectories(); + + Set keySet = viewCodeMap.keySet(); + Iterator iterator = keySet.iterator(); + while (iterator.hasNext()) { + String targetPath = iterator.next(); + String xsl = viewCodeMap.get(targetPath); + // get writer + targetPath = targetPath.replace(CodeGeneratorConstants.REPLACE_KEY_ID, viewId); + Writer destinationWriter = CodeGeneratorUtil.getDestinationWriter(targetDirectory, targetPath); + + // get StreamSource + InputStream xslIs = CodeGeneratorUtil.openStream(xsl); + StreamSource xslStream = new StreamSource(xslIs); + + generateCode(document, destinationWriter, xslStream, viewId); + + // close + destinationWriter.close(); + xslIs.close(); + + refresh(targetPath); + } + + } catch (SAXException e) { + throw new CodeGeneratorException(e.getMessage()); + } catch (ParserConfigurationException e) { + throw new CodeGeneratorException(e.getMessage()); + } catch (IOException e) { + throw new CodeGeneratorException(e.getMessage()); + } catch (TransformerException e) { + throw new CodeGeneratorException(e.getMessage()); + } + } + + public void clean(String viewId) throws CodeGeneratorException { + Set keySet = viewCodeMap.keySet(); + Iterator iterator = keySet.iterator(); + while (iterator.hasNext()) { + String targetPath = iterator.next(); + targetPath = targetPath.replace(CodeGeneratorConstants.REPLACE_KEY_ID, viewId); + File file = new File(this.targetDirectory, targetPath); + if (file.exists()) { + FileUtils.deleteQuietly(file); + refresh(targetPath); + } + } + } + + private void createDirectories() { + CodeGeneratorUtil.createDirectoy(this.targetDirectory, CodeGeneratorConstants.DIRECTORY_MANAGED_INC); + CodeGeneratorUtil.createDirectoy(this.targetDirectory, CodeGeneratorConstants.DIRECTORY_VIEW_SRC); + CodeGeneratorUtil.createDirectoy(this.targetDirectory, CodeGeneratorConstants.DIRECTORY_CONNECTION_SRC); + } + + private void refresh(String targetPath) throws CodeGeneratorException { + IFile file = project.getFile(targetPath); + if (file != null) { + try { + file.refreshLocal(IResource.DEPTH_INFINITE, null); + } catch (CoreException e) { + throw new CodeGeneratorException(e.getMessage()); + } + } + } + + private void generateCode(Node document, Writer writer, StreamSource xslStream, String viewName) throws TransformerException { + // create Tranform + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + transformerFactory.setURIResolver(new URIResolver() { + @Override + public Source resolve(String href, String base) throws TransformerException { + String uri = "res/" + href; + try { + InputStream stream = CodeGeneratorUtil.openStream(uri); + return new StreamSource(stream); + } catch (IOException e) { + logger.error(e.getMessage()); + } + return null; + } + }); + // DOMSource xslDom = new DOMSource(xslDoc); + Transformer transformer = transformerFactory.newTransformer(xslStream); + transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + transformer.setOutputProperty(OutputKeys.METHOD, "text"); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + transformer.setParameter("current_view_name", viewName); + + if (this.isRMSupportVersion != null) { // for RM + transformer.setParameter("is_version_rm_support", this.isRMSupportVersion); + } + + if (this.profile != null) { + transformer.setParameter("profile", this.profile); + } + + // transform + DOMSource srcDom = new DOMSource(document); + + // Writer writer = new OutputStreamWriter(out); + StreamResult result = new StreamResult(writer); + transformer.transform(srcDom, result); + } +} diff --git a/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/AbstractPageCodeGeneratorTest.java b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/AbstractPageCodeGeneratorTest.java new file mode 100644 index 0000000..aa102ba --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/AbstractPageCodeGeneratorTest.java @@ -0,0 +1,130 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import static org.junit.Assert.assertEquals; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.StringWriter; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.junit.Before; +import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + + +abstract public class AbstractPageCodeGeneratorTest { + private File xslDirectory = new File("./res/"); + private File targetDirectory = new File("."); + protected File tumlFile = new File("test01/page01.tvdm"); + protected Document loadedDocument; + protected Node node; + ViewCodeGenerator generator; + + abstract protected void loadPage() throws Exception; + + abstract protected String getExpectedCode() throws IOException; + + @Before + public void setUp() throws Exception { +// generator = new ViewCodeGenerator(xslDirectory, targetDirectory); + } + + @Test + public void testPageSourceGeneration() throws Exception { + loadPage(); + StringWriter writer = new StringWriter(); + // for avoid of build error, This function should be updated or deleted. + // generator.generateViewCode(node, new OutputStreamWriter(System.out), null, null); + // generator.generateViewCode(node, writer, null, null); + + String expectedCode = getExpectedCode(); + System.out.println(); + System.out.println(toStringForComparison(expectedCode)); + System.out.println(toStringForComparison(writer.getBuffer().toString())); + // assertEquals(toStringForComparison(expectedCode), + // toStringForComparison(writer.getBuffer().toString())); + String string1 = toStringForComparison(expectedCode); + String string2 = toStringForComparison(writer.getBuffer().toString()); + System.out.println("----" + string1.length()); + System.out.println("----" + string2.length()); + assertEquals(string1, string2); + assertEquals(string1.length(), string2.length()); + } + + @Test + public void testPageHeaderGeneration() throws Exception { + loadPage(); + // for avoid of build error, This function should be updated or deleted. + // generator.generateViewHeader(node, new OutputStreamWriter(System.out), null, null); + + String expectedCode = getStringFromFile(new File("testcases/test01_grid_button/expected/managed/inc/uib_page1_view.h")); + System.out.println(); + System.out.println(toStringForComparison(expectedCode)); + } + + protected Document loadTuml(File tuml) throws Exception { + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + documentBuilderFactory.setNamespaceAware(true); + DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder(); + Document doc = builder.parse(tuml); + return doc; + } + + protected String getStringFromFile(File file) throws IOException { + StringBuffer buffer = new StringBuffer(); + BufferedReader reader = new BufferedReader(new FileReader(file)); + char[] buf = new char[1024]; + int numRead = 0; + while ((numRead = reader.read(buf)) != -1) { + String readData = String.valueOf(buf, 0, numRead); + buffer.append(readData); + } + reader.close(); + return buffer.toString(); + } + + protected NodeList getViews(Document document) throws XPathExpressionException { + XPath xpath = XPathFactory.newInstance().newXPath(); + String expression = "/tizenFile/document/documentData/tizen.doc/tizen.view"; + NodeList nodeList = (NodeList) xpath.evaluate(expression, document, XPathConstants.NODESET); + return nodeList; + } + + protected String toStringForComparison(String string) { + return string.replaceAll("\n|\r|\\s", ""); + } + +} diff --git a/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/AllTests.java b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/AllTests.java new file mode 100644 index 0000000..6a08e03 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/AllTests.java @@ -0,0 +1,36 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + + + +//@RunWith(Suite.class) +//@SuiteClasses({ CodeGeneratorTest.class, Page01PageCodeGeneratorTest.class, Page02PageCodeGeneratorTest.class, Page03PageCodeGeneratorTest.class, +// Page04PageCodeGeneratorTest.class, Page05PageCodeGeneratorTest.class, Page06PageCodeGeneratorTest.class, Page07PageCodeGeneratorTest.class, +// Page08_CheckTest.class, Page09_RadioTest.class, Page10_ColorselectorTest.class, Page11_LabelTest.class, Page12_MultibuttonentryTest.class, +// Page13_GenGridTest.class, Page14_GenListTest.class, Page15_EntryTest.class, Page16_SliderTest.class, Page17_LayoutTest.class, Page18_PanesTest.class, +// Page19_GenGridTreeTest.class, Page20_TableTest.class, Page98_EventTest.class }) +//public class AllTests { +// +// } diff --git a/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/CodeGeneratorTest.java b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/CodeGeneratorTest.java new file mode 100644 index 0000000..8e07951 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/CodeGeneratorTest.java @@ -0,0 +1,95 @@ +///* +// * UI Builder +// * +// * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. +// * +// * 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.efluibuilder.codegenerator; +// +//import static org.junit.Assert.assertFalse; +//import static org.junit.Assert.assertTrue; +// +//import java.io.File; +//import java.io.IOException; +// +//import javax.xml.parsers.DocumentBuilder; +//import javax.xml.parsers.DocumentBuilderFactory; +//import javax.xml.parsers.ParserConfigurationException; +//import javax.xml.transform.TransformerException; +//import javax.xml.xpath.XPathExpressionException; +// +//import org.junit.Before; +//import org.junit.Test; +//import org.w3c.dom.Document; +//import org.xml.sax.SAXException; +// +// +//public class CodeGeneratorTest { +// private CodeGenerator generator; +// private File xslDirectory = new File("./res"); +// private File targetDirectory = new File("./cogen_test"); +// File tumlFile = new File("test01_grid_button/layout.tuml"); +// File appXmlFile = new File("test01_grid_button/.app.xml"); +// private Document tuml; +// private Document appXml; +// +// @Before +// public void setUp() throws SAXException, IOException, ParserConfigurationException { +// // this.generator = new CodeGenerator(xslDirectory, targetDirectory); // for avoid of build +// // error, This function should be updated or deleted. +// // this.tuml = this.loadXML(tumlFile); +// // this.appXml = this.loadXML(appXmlFile); +// // generator = new CodeGenerator(xslDirectory, targetDirectory); +// } +// +// @Test +// public void testGenerateAndCleanFiles() throws IOException, CodeGeneratorException { +// this.generator.generate(tumlFile, appXmlFile); +// assertTrue(new File(targetDirectory, "src/managed").exists()); +// this.generator.clean(); +// assertFalse(new File(targetDirectory, "src/managed").exists()); +// } +// +// @Test +// public void testGenerateCommonHeader() throws IOException, TransformerException { +// // generator.generateViewsHeader(appXml, new OutputStreamWriter(System.out), null); // for +// // avoid of build error, This function should be updated or deleted. +// } +// +// @Test +// public void testGenerateCommonSource() throws TransformerException, IOException, XPathExpressionException { +// // generator.generateViewsSource(tuml, tuml, new OutputStreamWriter(System.out), null); // +// // for avoid of build error, This function should be updated or deleted. +// } +// +// @Test +// public void testGenerateViewsHeader() throws TransformerException, IOException { +// // generator.generateViewsIncHeader(tuml, new OutputStreamWriter(System.out), null); // for +// // avoid of build error, This function should be updated or deleted. +// } +// +// private Document loadXML(File tuml) throws SAXException, IOException, ParserConfigurationException { +// DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); +// documentBuilderFactory.setNamespaceAware(true); +// DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder(); +// Document doc = builder.parse(tuml); +// return doc; +// } +// } diff --git a/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page01PageCodeGeneratorTest.java b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page01PageCodeGeneratorTest.java new file mode 100644 index 0000000..e4d3d2c --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page01PageCodeGeneratorTest.java @@ -0,0 +1,54 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + + +public class Page01PageCodeGeneratorTest extends AbstractPageCodeGeneratorTest { + protected void loadPage() throws Exception { + tumlFile = new File("testcases/test01_grid_button/layout.tuml"); + loadedDocument = loadTuml(tumlFile); + node = getViews(loadedDocument).item(0); + assertTrue(node != null); + } + + protected String getExpectedCode() throws IOException { + return getStringFromFile(new File("testcases/test01_grid_button/expected/managed/src/uib_page1_view.c")); + } + + @Test + public void testFileName() throws Exception { + loadPage(); + assertEquals("uib_page1_view.c", generator.getSourceFileName(node)); + assertEquals("uib_page1_view.h", generator.getHeaderFileName(node)); + } + +} diff --git a/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page02PageCodeGeneratorTest.java b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page02PageCodeGeneratorTest.java new file mode 100644 index 0000000..827ea84 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page02PageCodeGeneratorTest.java @@ -0,0 +1,54 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + + +public class Page02PageCodeGeneratorTest extends AbstractPageCodeGeneratorTest { + protected void loadPage() throws Exception { + tumlFile = new File("testcases/est02_panel/layout.tuml"); + loadedDocument = loadTuml(tumlFile); + node = getViews(loadedDocument).item(0); + assertTrue(node != null); + } + + protected String getExpectedCode() throws IOException { + return getStringFromFile(new File("testcases/test02_panel/expected/managed/src/uib_page1_view.c")); + } + + @Test + public void testFileName() throws Exception { + loadPage(); + assertEquals("uib_page1_view.c", generator.getSourceFileName(node)); + assertEquals("uib_page1_view.h", generator.getHeaderFileName(node)); + } + +} diff --git a/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page03PageCodeGeneratorTest.java b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page03PageCodeGeneratorTest.java new file mode 100644 index 0000000..3ff8d0d --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page03PageCodeGeneratorTest.java @@ -0,0 +1,54 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + + +public class Page03PageCodeGeneratorTest extends AbstractPageCodeGeneratorTest { + protected void loadPage() throws Exception { + tumlFile = new File("testcases/test03_background/layout.tuml"); + loadedDocument = loadTuml(tumlFile); + node = getViews(loadedDocument).item(0); + assertTrue(node != null); + } + + protected String getExpectedCode() throws IOException { + return getStringFromFile(new File("testcases/test03_background/expected/managed/src/uib_page1_view.c")); + } + + @Test + public void testFileName() throws Exception { + loadPage(); + assertEquals("uib_page1_view.c", generator.getSourceFileName(node)); + assertEquals("uib_page1_view.h", generator.getHeaderFileName(node)); + } + +} diff --git a/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page04PageCodeGeneratorTest.java b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page04PageCodeGeneratorTest.java new file mode 100644 index 0000000..7a52ee4 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page04PageCodeGeneratorTest.java @@ -0,0 +1,54 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + + +public class Page04PageCodeGeneratorTest extends AbstractPageCodeGeneratorTest { + protected void loadPage() throws Exception { + tumlFile = new File("testcases/test04_scroller/layout.tuml"); + loadedDocument = loadTuml(tumlFile); + node = getViews(loadedDocument).item(0); + assertTrue(node != null); + } + + protected String getExpectedCode() throws IOException { + return getStringFromFile(new File("testcases/test04_scroller/expected/managed/src/uib_page1_view.c")); + } + + @Test + public void testFileName() throws Exception { + loadPage(); + assertEquals("uib_page1_view.c", generator.getSourceFileName(node)); + assertEquals("uib_page1_view.h", generator.getHeaderFileName(node)); + } + +} diff --git a/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page05PageCodeGeneratorTest.java b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page05PageCodeGeneratorTest.java new file mode 100644 index 0000000..6c16758 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page05PageCodeGeneratorTest.java @@ -0,0 +1,54 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + + +public class Page05PageCodeGeneratorTest extends AbstractPageCodeGeneratorTest { + protected void loadPage() throws Exception { + tumlFile = new File("testcases/test05_spinner/layout.tuml"); + loadedDocument = loadTuml(tumlFile); + node = getViews(loadedDocument).item(0); + assertTrue(node != null); + } + + protected String getExpectedCode() throws IOException { + return getStringFromFile(new File("testcases/test05_spinner/expected/managed/src/uib_page1_view.c")); + } + + @Test + public void testFileName() throws Exception { + loadPage(); + assertEquals("uib_page1_view.c", generator.getSourceFileName(node)); + assertEquals("uib_page1_view.h", generator.getHeaderFileName(node)); + } + +} diff --git a/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page06PageCodeGeneratorTest.java b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page06PageCodeGeneratorTest.java new file mode 100644 index 0000000..7a18956 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page06PageCodeGeneratorTest.java @@ -0,0 +1,54 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + + +public class Page06PageCodeGeneratorTest extends AbstractPageCodeGeneratorTest { + protected void loadPage() throws Exception { + tumlFile = new File("testcases/test06_progressbar/layout.tuml"); + loadedDocument = loadTuml(tumlFile); + node = getViews(loadedDocument).item(0); + assertTrue(node != null); + } + + protected String getExpectedCode() throws IOException { + return getStringFromFile(new File("testcases/test06_progressbar/expected/managed/src/uib_page1_view.c")); + } + + @Test + public void testFileName() throws Exception { + loadPage(); + assertEquals("uib_page1_view.c", generator.getSourceFileName(node)); + assertEquals("uib_page1_view.h", generator.getHeaderFileName(node)); + } + +} diff --git a/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page07PageCodeGeneratorTest.java b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page07PageCodeGeneratorTest.java new file mode 100644 index 0000000..8b7a978 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page07PageCodeGeneratorTest.java @@ -0,0 +1,54 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + + +public class Page07PageCodeGeneratorTest extends AbstractPageCodeGeneratorTest { + protected void loadPage() throws Exception { + tumlFile = new File("testcases/test07_grid_in_grid/layout.tuml"); + loadedDocument = loadTuml(tumlFile); + node = getViews(loadedDocument).item(0); + assertTrue(node != null); + } + + protected String getExpectedCode() throws IOException { + return getStringFromFile(new File("testcases/test07_grid_in_grid/expected/managed/src/uib_page1_view.c")); + } + + @Test + public void testFileName() throws Exception { + loadPage(); + assertEquals("uib_page1_view.c", generator.getSourceFileName(node)); + assertEquals("uib_page1_view.h", generator.getHeaderFileName(node)); + } + +} diff --git a/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page08_CheckTest.java b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page08_CheckTest.java new file mode 100644 index 0000000..8292195 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page08_CheckTest.java @@ -0,0 +1,54 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + + +public class Page08_CheckTest extends AbstractPageCodeGeneratorTest { + protected void loadPage() throws Exception { + tumlFile = new File("testcases/test08_check/layout.tuml"); + loadedDocument = loadTuml(tumlFile); + node = getViews(loadedDocument).item(0); + assertTrue(node != null); + } + + protected String getExpectedCode() throws IOException { + return getStringFromFile(new File("testcases/test08_check/expected/managed/src/uib_page1_view.c")); + } + + @Test + public void testFileName() throws Exception { + loadPage(); + assertEquals("uib_page1_view.c", generator.getSourceFileName(node)); + assertEquals("uib_page1_view.h", generator.getHeaderFileName(node)); + } + +} diff --git a/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page09_RadioTest.java b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page09_RadioTest.java new file mode 100644 index 0000000..9fc28b9 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page09_RadioTest.java @@ -0,0 +1,54 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + + +public class Page09_RadioTest extends AbstractPageCodeGeneratorTest { + protected void loadPage() throws Exception { + tumlFile = new File("testcases/test09_radio/layout.tuml"); + loadedDocument = loadTuml(tumlFile); + node = getViews(loadedDocument).item(0); + assertTrue(node != null); + } + + protected String getExpectedCode() throws IOException { + return getStringFromFile(new File("testcases/test09_radio/expected/managed/src/uib_page1_view.c")); + } + + @Test + public void testFileName() throws Exception { + loadPage(); + assertEquals("uib_page1_view.c", generator.getSourceFileName(node)); + assertEquals("uib_page1_view.h", generator.getHeaderFileName(node)); + } + +} diff --git a/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page10_ColorselectorTest.java b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page10_ColorselectorTest.java new file mode 100644 index 0000000..cf4d32a --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page10_ColorselectorTest.java @@ -0,0 +1,54 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + + +public class Page10_ColorselectorTest extends AbstractPageCodeGeneratorTest { + protected void loadPage() throws Exception { + tumlFile = new File("testcases/test10_colorselector/layout.tuml"); + loadedDocument = loadTuml(tumlFile); + node = getViews(loadedDocument).item(0); + assertTrue(node != null); + } + + protected String getExpectedCode() throws IOException { + return getStringFromFile(new File("testcases/test10_colorselector/expected/managed/src/uib_page1_view.c")); + } + + @Test + public void testFileName() throws Exception { + loadPage(); + assertEquals("uib_page1_view.c", generator.getSourceFileName(node)); + assertEquals("uib_page1_view.h", generator.getHeaderFileName(node)); + } + +} diff --git a/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page11_LabelTest.java b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page11_LabelTest.java new file mode 100644 index 0000000..a96aa25 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page11_LabelTest.java @@ -0,0 +1,54 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + + +public class Page11_LabelTest extends AbstractPageCodeGeneratorTest { + protected void loadPage() throws Exception { + tumlFile = new File("testcases/test11_label/layout.tuml"); + loadedDocument = loadTuml(tumlFile); + node = getViews(loadedDocument).item(0); + assertTrue(node != null); + } + + protected String getExpectedCode() throws IOException { + return getStringFromFile(new File("testcases/test11_label/expected/managed/src/uib_page1_view.c")); + } + + @Test + public void testFileName() throws Exception { + loadPage(); + assertEquals("uib_page1_view.c", generator.getSourceFileName(node)); + assertEquals("uib_page1_view.h", generator.getHeaderFileName(node)); + } + +} diff --git a/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page12_MultibuttonentryTest.java b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page12_MultibuttonentryTest.java new file mode 100644 index 0000000..af721fb --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page12_MultibuttonentryTest.java @@ -0,0 +1,54 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + + +public class Page12_MultibuttonentryTest extends AbstractPageCodeGeneratorTest { + protected void loadPage() throws Exception { + tumlFile = new File("testcases/test12_multibuttonentry/layout.tuml"); + loadedDocument = loadTuml(tumlFile); + node = getViews(loadedDocument).item(0); + assertTrue(node != null); + } + + protected String getExpectedCode() throws IOException { + return getStringFromFile(new File("testcases/test12_multibuttonentry/expected/managed/src/uib_page1_view.c")); + } + + @Test + public void testFileName() throws Exception { + loadPage(); + assertEquals("uib_page1_view.c", generator.getSourceFileName(node)); + assertEquals("uib_page1_view.h", generator.getHeaderFileName(node)); + } + +} diff --git a/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page13_GenGridTest.java b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page13_GenGridTest.java new file mode 100644 index 0000000..f280fe6 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page13_GenGridTest.java @@ -0,0 +1,54 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + + +public class Page13_GenGridTest extends AbstractPageCodeGeneratorTest { + protected void loadPage() throws Exception { + tumlFile = new File("testcases/test13_gengrid/layout.tuml"); + loadedDocument = loadTuml(tumlFile); + node = getViews(loadedDocument).item(0); + assertTrue(node != null); + } + + protected String getExpectedCode() throws IOException { + return getStringFromFile(new File("testcases/test13_gengrid/expected/managed/src/uib_page1_view.c")); + } + + @Test + public void testFileName() throws Exception { + loadPage(); + assertEquals("uib_page1_view.c", generator.getSourceFileName(node)); + assertEquals("uib_page1_view.h", generator.getHeaderFileName(node)); + } + +} diff --git a/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page14_GenListTest.java b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page14_GenListTest.java new file mode 100644 index 0000000..2bae505 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page14_GenListTest.java @@ -0,0 +1,54 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + + +public class Page14_GenListTest extends AbstractPageCodeGeneratorTest { + protected void loadPage() throws Exception { + tumlFile = new File("testcases/test14_genlist/layout.tuml"); + loadedDocument = loadTuml(tumlFile); + node = getViews(loadedDocument).item(0); + assertTrue(node != null); + } + + protected String getExpectedCode() throws IOException { + return getStringFromFile(new File("testcases/test14_genlist/expected/managed/src/uib_page1_view.c")); + } + + @Test + public void testFileName() throws Exception { + loadPage(); + assertEquals("uib_page1_view.c", generator.getSourceFileName(node)); + assertEquals("uib_page1_view.h", generator.getHeaderFileName(node)); + } + +} diff --git a/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page15_EntryTest.java b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page15_EntryTest.java new file mode 100644 index 0000000..2b6f1ff --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page15_EntryTest.java @@ -0,0 +1,53 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + + +public class Page15_EntryTest extends AbstractPageCodeGeneratorTest { + protected void loadPage() throws Exception { + tumlFile = new File("testcases/test15_entry/layout.tuml"); + loadedDocument = loadTuml(tumlFile); + node = getViews(loadedDocument).item(0); + assertTrue(node != null); + } + + protected String getExpectedCode() throws IOException { + return getStringFromFile(new File("testcases/test15_entry/expected/managed/src/uib_view1_view.c")); + } + + @Test + public void testFileName() throws Exception { + loadPage(); + assertEquals("uib_view1_view.c", generator.getSourceFileName(node)); + assertEquals("uib_view1_view.h", generator.getHeaderFileName(node)); + } +} diff --git a/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page16_SliderTest.java b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page16_SliderTest.java new file mode 100644 index 0000000..8f75b47 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page16_SliderTest.java @@ -0,0 +1,53 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + + +public class Page16_SliderTest extends AbstractPageCodeGeneratorTest { + protected void loadPage() throws Exception { + tumlFile = new File("testcases/test16_slider/layout.tuml"); + loadedDocument = loadTuml(tumlFile); + node = getViews(loadedDocument).item(0); + assertTrue(node != null); + } + + protected String getExpectedCode() throws IOException { + return getStringFromFile(new File("testcases/test16_slider/expected/managed/src/uib_view1_view.c")); + } + + @Test + public void testFileName() throws Exception { + loadPage(); + assertEquals("uib_view1_view.c", generator.getSourceFileName(node)); + assertEquals("uib_view1_view.h", generator.getHeaderFileName(node)); + } +} diff --git a/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page17_LayoutTest.java b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page17_LayoutTest.java new file mode 100644 index 0000000..493ab37 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page17_LayoutTest.java @@ -0,0 +1,53 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + + +public class Page17_LayoutTest extends AbstractPageCodeGeneratorTest { + protected void loadPage() throws Exception { + tumlFile = new File("testcases/test17_layout/layout.tuml"); + loadedDocument = loadTuml(tumlFile); + node = getViews(loadedDocument).item(0); + assertTrue(node != null); + } + + protected String getExpectedCode() throws IOException { + return getStringFromFile(new File("testcases/test17_layout/expected/managed/src/uib_view1_view.c")); + } + + @Test + public void testFileName() throws Exception { + loadPage(); + assertEquals("uib_view1_view.c", generator.getSourceFileName(node)); + assertEquals("uib_view1_view.h", generator.getHeaderFileName(node)); + } +} diff --git a/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page18_PanesTest.java b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page18_PanesTest.java new file mode 100644 index 0000000..e104fa7 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page18_PanesTest.java @@ -0,0 +1,53 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + + +public class Page18_PanesTest extends AbstractPageCodeGeneratorTest { + protected void loadPage() throws Exception { + tumlFile = new File("testcases/test18_panes/layout.tuml"); + loadedDocument = loadTuml(tumlFile); + node = getViews(loadedDocument).item(0); + assertTrue(node != null); + } + + protected String getExpectedCode() throws IOException { + return getStringFromFile(new File("testcases/test18_panes/expected/managed/src/uib_view1_view.c")); + } + + @Test + public void testFileName() throws Exception { + loadPage(); + assertEquals("uib_view1_view.c", generator.getSourceFileName(node)); + assertEquals("uib_view1_view.h", generator.getHeaderFileName(node)); + } +} diff --git a/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page19_GenGridTreeTest.java b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page19_GenGridTreeTest.java new file mode 100644 index 0000000..3fdaa2a --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page19_GenGridTreeTest.java @@ -0,0 +1,53 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + + +public class Page19_GenGridTreeTest extends AbstractPageCodeGeneratorTest { + protected void loadPage() throws Exception { + tumlFile = new File("testcases/test19_genlist_treeitem/layout.tuml"); + loadedDocument = loadTuml(tumlFile); + node = getViews(loadedDocument).item(0); + assertTrue(node != null); + } + + protected String getExpectedCode() throws IOException { + return getStringFromFile(new File("testcases/test19_genlist_treeitem/expected/managed/src/uib_view1_view.c")); + } + + @Test + public void testFileName() throws Exception { + loadPage(); + assertEquals("uib_view1_view.c", generator.getSourceFileName(node)); + assertEquals("uib_view1_view.h", generator.getHeaderFileName(node)); + } +} diff --git a/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page20_TableTest.java b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page20_TableTest.java new file mode 100644 index 0000000..3cb5dee --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page20_TableTest.java @@ -0,0 +1,53 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + + +public class Page20_TableTest extends AbstractPageCodeGeneratorTest { + protected void loadPage() throws Exception { + tumlFile = new File("testcases/test20_table/layout.tuml"); + loadedDocument = loadTuml(tumlFile); + node = getViews(loadedDocument).item(0); + assertTrue(node != null); + } + + protected String getExpectedCode() throws IOException { + return getStringFromFile(new File("testcases/test20_table/expected/managed/src/uib_view1_view.c")); + } + + @Test + public void testFileName() throws Exception { + loadPage(); + assertEquals("uib_view1_view.c", generator.getSourceFileName(node)); + assertEquals("uib_view1_view.h", generator.getHeaderFileName(node)); + } +} diff --git a/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page21_BoxTest.java b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page21_BoxTest.java new file mode 100644 index 0000000..a243e95 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page21_BoxTest.java @@ -0,0 +1,53 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + + +public class Page21_BoxTest extends AbstractPageCodeGeneratorTest { + protected void loadPage() throws Exception { + tumlFile = new File("testcases/test21_box/layout.tuml"); + loadedDocument = loadTuml(tumlFile); + node = getViews(loadedDocument).item(0); + assertTrue(node != null); + } + + protected String getExpectedCode() throws IOException { + return getStringFromFile(new File("testcases/test21_box/expected/managed/src/uib_view1_view.c")); + } + + @Test + public void testFileName() throws Exception { + loadPage(); + assertEquals("uib_view1_view.c", generator.getSourceFileName(node)); + assertEquals("uib_view1_view.h", generator.getHeaderFileName(node)); + } +} diff --git a/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page98_EventTest.java b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page98_EventTest.java new file mode 100644 index 0000000..4934f73 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/test/org/tizen/efluibuilder/codegenerator/Page98_EventTest.java @@ -0,0 +1,54 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.codegenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + + +public class Page98_EventTest extends AbstractPageCodeGeneratorTest { + protected void loadPage() throws Exception { + tumlFile = new File("testcases/test98_event/layout.tuml"); + loadedDocument = loadTuml(tumlFile); + node = getViews(loadedDocument).item(0); + assertTrue(node != null); + } + + protected String getExpectedCode() throws IOException { + return getStringFromFile(new File("testcases/test98_event/expected/managed/src/uib_page1_view.c")); + } + + @Test + public void testFileName() throws Exception { + loadPage(); + assertEquals("uib_page1_view.c", generator.getSourceFileName(node)); + assertEquals("uib_page1_view.h", generator.getHeaderFileName(node)); + } + +} diff --git a/org.tizen.efluibuilder.codegenerator/testcases/test01_grid_button/app.xml b/org.tizen.efluibuilder.codegenerator/testcases/test01_grid_button/app.xml new file mode 100644 index 0000000..e5ad148 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/testcases/test01_grid_button/app.xml @@ -0,0 +1,58 @@ + + + + + tizen-project + 3 + Tizen Web UI Builder Project + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder.codegenerator/testcases/test01_grid_button/expected/managed/inc/uib_common.h b/org.tizen.efluibuilder.codegenerator/testcases/test01_grid_button/expected/managed/inc/uib_common.h new file mode 100644 index 0000000..7032de9 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/testcases/test01_grid_button/expected/managed/inc/uib_common.h @@ -0,0 +1,70 @@ +/* + * Copyright 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +#ifndef __UIB_COMMON_H__ +#define __UIB_COMMON_H__ + +#define APP_NAME "calc" +#define KEY_VIEW_CONTEXT "uib,view,context" +#define KEY_VIEW_CREATE "uib,view,create" +#define KEY_VIEW_DESTROY "uib,view,destroy" + +typedef struct +{ + Evas_Object *win; + Evas_Object *bg; + Evas_Object *conformant; + Evas_Object *layout; +} window_obj; + +typedef struct _uib_view_context +{ + Evas_Object* parent; + Evas_Object* root_container; + const char* view_name; +} uib_view_context; + + +/** + * @brief Create startup view + * @param[in] win EFL Window + * @return uib_view_context + */ +uib_view_context * startup_view_create(window_obj* win); + + +/** + * @brief Call a callback on view creation + * @param[in] vc view context + * @param[in] obj The root container widget of this view + * @param[in] event_info pointer to an event specific struct or information to pass to the callback functions registered on this event + */ +void uib_view_create_callback(void* vc, Evas* e, Evas_Object* obj, void* event_info) ; + + +/** + * @brief Call a callback on view termination + * @param[in] vc view context + * @param[in] obj The root container widget of this view + * @param[in] event_info pointer to an event specific struct or information to pass to the callback functions registered on this event + */ +void uib_view_destroy_callback(void* vc, Evas* e, Evas_Object* obj, void* event_info) ; + +window_obj* win_create(); +void win_destroy(window_obj *win_obj); + +#endif /* __UIB_COMMON_H__ */ + diff --git a/org.tizen.efluibuilder.codegenerator/testcases/test01_grid_button/expected/managed/inc/uib_page1_view.h b/org.tizen.efluibuilder.codegenerator/testcases/test01_grid_button/expected/managed/inc/uib_page1_view.h new file mode 100644 index 0000000..6e834d5 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/testcases/test01_grid_button/expected/managed/inc/uib_page1_view.h @@ -0,0 +1,27 @@ +/* + * uib_page1_view.h + * + * Created on: Nov 27, 2014 + * Author: djhwang + */ + +#ifndef UIB_PAGE1_VIEW_H_ +#define UIB_PAGE1_VIEW_H_ + +//#include + +typedef struct _uib_page1_view_context +{ + Evas_Object* parent; + Evas_Object* root_container; + const char* view_name; + struct uib_page1_control_context* cc; + Evas_Object* grid1; + Evas_Object* button1; +} uib_page1_view_context; + +uib_view_context* uib_page1_view_create(Evas_Object* parent, void* create_callback_param); +uib_view_context* uib_page1_view_destroy(Evas_Object* parent, void* create_callback_param); + + +#endif /* UIB_PAGE1_VIEW_H_ */ diff --git a/org.tizen.efluibuilder.codegenerator/testcases/test01_grid_button/expected/managed/inc/uib_views.h b/org.tizen.efluibuilder.codegenerator/testcases/test01_grid_button/expected/managed/inc/uib_views.h new file mode 100644 index 0000000..c1cc611 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/testcases/test01_grid_button/expected/managed/inc/uib_views.h @@ -0,0 +1,15 @@ +/* + * uib_views.h + * + * Created on: Nov 27, 2014 + * Author: djhwang + */ + +#ifndef UIB_VIEWS_H_ +#define UIB_VIEWS_H_ + + +#include "uib_page1_view.h" + + +#endif /* UIB_VIEWS_H_ */ diff --git a/org.tizen.efluibuilder.codegenerator/testcases/test01_grid_button/expected/managed/src/uib_common.c b/org.tizen.efluibuilder.codegenerator/testcases/test01_grid_button/expected/managed/src/uib_common.c new file mode 100644 index 0000000..e393774 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/testcases/test01_grid_button/expected/managed/src/uib_common.c @@ -0,0 +1,73 @@ +/* + * Copyright 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +#include +#include "uib_common.h" +#include "uib_views.h" + + +void uib_view_create_callback(void* vc, Evas* e, Evas_Object* obj, void* event_info) { + evas_object_smart_callback_call(obj, KEY_VIEW_CREATE, event_info); +} + +void uib_view_destroy_callback(void* vc, Evas* e, Evas_Object* obj, void* event_info) { + evas_object_smart_callback_call(obj, KEY_VIEW_DESTROY, event_info); + if (vc) { + free(vc); + } +} + +uib_view_context* startup_view_create(window_obj* win) +{ + uib_view_context* vc = uib_main_view_create(win->conformant, NULL); + if (vc) { + elm_object_part_content_set(win->conformant, "elm.swallow.content", vc->root_container); + } + + return vc; +} + +window_obj* win_create() +{ + window_obj* obj = calloc(1, sizeof(window_obj)); + if (!obj) + return NULL; + + obj->win = elm_win_add(NULL, APP_NAME, ELM_WIN_BASIC); + elm_win_conformant_set(obj->win, EINA_TRUE); + evas_object_show(obj->win); + + elm_win_indicator_mode_set(obj->win, ELM_WIN_INDICATOR_SHOW); + obj->conformant = elm_conformant_add(obj->win); + evas_object_size_hint_weight_set(obj->conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(obj->win, obj->conformant); + evas_object_show(obj->conformant); + + obj->bg = elm_bg_add(obj->conformant); + evas_object_size_hint_weight_set(obj->bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_show(obj->bg); + + elm_object_part_content_set(obj->conformant, "elm.swallow.bg", obj->bg); + return obj; +} + +void win_destroy(window_obj *obj) +{ + if (obj) { + evas_object_del(obj->win); + free(obj); + } +} diff --git a/org.tizen.efluibuilder.codegenerator/testcases/test01_grid_button/expected/managed/src/uib_page1_view.c b/org.tizen.efluibuilder.codegenerator/testcases/test01_grid_button/expected/managed/src/uib_page1_view.c new file mode 100644 index 0000000..072566a --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/testcases/test01_grid_button/expected/managed/src/uib_page1_view.c @@ -0,0 +1,68 @@ +/******************************************************************************* + * This file was generated by UI Builder. + * This file will be auto-generated each and everytime you save your project. + * Do not hand edit this file. + ********************************************************************************/ +#include "app_main.h" + + +/* event handler declarations */ + + + + +uib_view_context* uib_page1_view_create(Evas_Object* parent, void* create_callback_param) +{ + uib_page1_view_context* vc = calloc(1, sizeof(uib_page1_view_context)); + vc->parent = parent; + vc->view_name = "page1"; + vc->content1 = elm_grid_add(parent); + vc->root_container = vc->content1; + + if (vc->content1) { + + evas_object_size_hint_align_set(vc->content1, -1.0, -1.0); + evas_object_size_hint_weight_set(vc->content1, 1, 1); + elm_grid_size_set(vc->content1, 480, 800); + + vc->button1 = elm_button_add(vc->content1); + if (vc->button1) { + evas_object_size_hint_align_set(vc->button1, -1.0, -1.0); + evas_object_size_hint_weight_set(vc->button1, 1, 1); + elm_object_text_set(vc->button1, "버튼123"); + elm_button_autorepeat_set(vc->button1, EINA_TRUE); + elm_button_autorepeat_initial_timeout_set(vc->button1,100); + elm_button_autorepeat_gap_timeout_set(vc->button1,120); + evas_object_show(vc->button1); + } + vc->button2 = elm_button_add(vc->content1); + if (vc->button2) { + evas_object_size_hint_align_set(vc->button2, -1.0, -1.0); + evas_object_size_hint_weight_set(vc->button2, 1, 1); + elm_object_text_set(vc->button2, "Button"); + evas_object_show(vc->button2); + } + vc->button3 = elm_button_add(vc->content1); + if (vc->button3) { + evas_object_size_hint_align_set(vc->button3, -1.0, -1.0); + evas_object_size_hint_weight_set(vc->button3, 1, 1); + elm_object_text_set(vc->button3, "Button"); + evas_object_show(vc->button3); + } + elm_grid_pack(vc->content1, vc->button1, 48, 36, 193, 50); + elm_grid_pack(vc->content1, vc->button2, 48, 108, 193, 50); + elm_grid_pack(vc->content1, vc->button3, 48, 180, 193, 50); + evas_object_show(vc->content1); + } + + //bind event handler + + + evas_object_data_set(vc->root_container, KEY_VIEW_CONTEXT, vc); + evas_object_event_callback_add(vc->root_container, EVAS_CALLBACK_DEL, (Evas_Object_Event_Cb)uib_view_destroy_callback, vc); + uib_view_create_callback(vc, evas_object_evas_get(vc->root_container), vc->root_container, create_callback_param); + + return (uib_view_context*)vc; +} + + diff --git a/org.tizen.efluibuilder.codegenerator/testcases/test01_grid_button/layout.tuml b/org.tizen.efluibuilder.codegenerator/testcases/test01_grid_button/layout.tuml new file mode 100644 index 0000000..1aabca4 --- /dev/null +++ b/org.tizen.efluibuilder.codegenerator/testcases/test01_grid_button/layout.tuml @@ -0,0 +1,79 @@ + + + + tizen-page + 1 + Tizen Web UI Builder Project + + + + test + noname + 0.1.1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder/src/edjResourceSyncManager/DirectoryWatchService.java b/org.tizen.efluibuilder/src/edjResourceSyncManager/DirectoryWatchService.java new file mode 100644 index 0000000..3ed5a04 --- /dev/null +++ b/org.tizen.efluibuilder/src/edjResourceSyncManager/DirectoryWatchService.java @@ -0,0 +1,149 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 edjResourceSyncManager; + +import java.io.File; +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.LinkOption; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardWatchEventKinds; +import java.nio.file.WatchEvent; +import java.nio.file.WatchKey; +import java.nio.file.WatchService; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class DirectoryWatchService extends Thread { + private static Logger logger = LoggerFactory.getLogger(DirectoryWatchService.class); + String rootPath = null; + List changedList = null; + List listeners = new ArrayList(); + WatchService watchService = null; + ConcurrentHashMap keys = new ConcurrentHashMap(); + + DirectoryWatchService() { + + } + + public void init(String rootPath) { + this.rootPath = rootPath; + try { + watchService = FileSystems.getDefault().newWatchService(); + register(Paths.get(rootPath), true); + } catch (IOException e) { + logger.error(e.getMessage()); + } + } + + private void register(Path dir, boolean bRecursive) throws IOException { + WatchKey key = + dir.register(watchService, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY); + keys.put(key, dir); + if (bRecursive) { + String nextPath = null; + String[] dirList = dir.toFile().list(); + if (dirList != null) + for (String name : dirList) { + nextPath = dir.toString() + "/" + name; + if (new File(nextPath).isDirectory()) { + register(Paths.get(nextPath), bRecursive); + } + } + } + } + + private void fireEvents(List events) { + for (IWatchServiceListener listener : listeners) { + listener.contentChanged(events); + } + } + + @Override + public void run() { + while (Thread.interrupted() == false && watchService != null) { + WatchKey key = null; + try { + key = watchService.take(); + } catch (InterruptedException e) { + break; + } + if (keys.containsKey(key) == false) { + continue; + } + Path dir = keys.get(key); + List> keys = key.pollEvents(); + List changedEvents = new ArrayList(); + for (WatchEvent event : keys) { + WatchEvent.Kind kind = event.kind(); + Path name = (Path) event.context(); + if (kind == StandardWatchEventKinds.OVERFLOW) { + continue; + } + if (kind == StandardWatchEventKinds.ENTRY_CREATE) { + Path child = dir.resolve(name); + changedEvents.add(new ResourceChangedEvent(ResourceChangedEvent.TYPE_ADDED, dir.resolve(name).toString())); + + if (Files.isDirectory(child, LinkOption.NOFOLLOW_LINKS) == true) { + try { + register(child, true); + } catch (IOException e) { + logger.error(e.getMessage()); + } + } + } else if (kind == StandardWatchEventKinds.ENTRY_DELETE) { + changedEvents.add(new ResourceChangedEvent(ResourceChangedEvent.TYPE_REMOVED, dir.resolve(name).toString())); + } else if (kind == StandardWatchEventKinds.ENTRY_MODIFY) { + changedEvents.add(new ResourceChangedEvent(ResourceChangedEvent.TYPE_CHANGED, dir.resolve(name).toString())); + } + key.reset(); + } + if (changedEvents.size() > 0) { + fireEvents(changedEvents); + } + } + try { + if (watchService != null) + watchService.close(); + } catch (IOException e) { + logger.error(e.getMessage()); + } + } + + public void addListener(IWatchServiceListener listener) { + this.listeners.add(listener); + } + + public void removeListener(IWatchServiceListener listener) { + this.listeners.remove(listener); + } + +} diff --git a/org.tizen.efluibuilder/src/edjResourceSyncManager/EdjResourceChangedEvent.java b/org.tizen.efluibuilder/src/edjResourceSyncManager/EdjResourceChangedEvent.java new file mode 100644 index 0000000..1fab6c6 --- /dev/null +++ b/org.tizen.efluibuilder/src/edjResourceSyncManager/EdjResourceChangedEvent.java @@ -0,0 +1,50 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 edjResourceSyncManager; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + + +public class EdjResourceChangedEvent extends ResourceChangedEvent { + public ArrayList groupNames = null; + public Map>> styleNames = null; + + EdjResourceChangedEvent(final String type, final String path, final ArrayList groupNames) { + this(type, path); + this.groupNames = groupNames; + } + + EdjResourceChangedEvent(final String type, final String path, final Map>> styleNames) { + this(type, path); + this.styleNames = styleNames; + } + + EdjResourceChangedEvent(final String type, final String path) { + super(type, path); + this.type = type; + this.path = path; + } +} diff --git a/org.tizen.efluibuilder/src/edjResourceSyncManager/EdjResourceSyncManager.java b/org.tizen.efluibuilder/src/edjResourceSyncManager/EdjResourceSyncManager.java new file mode 100644 index 0000000..594dfe5 --- /dev/null +++ b/org.tizen.efluibuilder/src/edjResourceSyncManager/EdjResourceSyncManager.java @@ -0,0 +1,295 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 edjResourceSyncManager; + +import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.renderer.IArguments; +import org.tizen.efluibuilder.renderer.IRenderer; +import org.tizen.efluibuilder.renderer.IRendererListener; +import org.tizen.efluibuilder.renderer.RendererConstants; +import org.tizen.efluibuilder.renderer.RendererFactory; +import org.tizen.efluibuilder.renderer.event.RenderEvent; +import org.tizen.efluibuilder.ui.views.properties.style.StyleEDJManager; +import org.tizen.efluibuilder.utility.PlatformUtil; + + +public class EdjResourceSyncManager extends ResourceChangedObserver implements IRendererListener, IWatchServiceListener { + private static Logger logger = LoggerFactory.getLogger(EdjResourceSyncManager.class); + final static String PATH_RESOURCE = "res"; + final static String EXT_EDJ = "edj"; + private Path resRootPath; + public final static String CUSTOM_STYLE_EDJ = "theme" + File.separator + "custom_theme.edj"; + + private HashMap> groupMap = new HashMap>(); + + private ArrayList listeners = new ArrayList(); + IProject project = null; + IContainer rootContainer = null; + IRenderer renderer = null; + boolean isRendererInitialized = false; + private DirectoryWatchService watchService = null; + private ResourceFileDuplicator resFileDuplicator = null; + private StyleEDJManager styleEDJManager; + + public EdjResourceSyncManager() { + super(); + } + + private void initRenderer(String version, String profile, String projectPath) { + int width = 100; + int height = 100; + RendererFactory factory = RendererFactory.getDefault(); + renderer = factory.create(version, profile, projectPath); + if (renderer != null) { + renderer.setName(""); + renderer.addRendererListener(this); + renderer.create(width, height, styleEDJManager.getDefaultThemePathForEflRenderer(), styleEDJManager.getCustomThemePathForEflRenderer()); + } + } + + public void addObserveTarget(String filePath) { + if (groupMap.containsKey(filePath) == false) { + groupMap.put(filePath, new ArrayList()); + reqEdjInfo(filePath); + } + } + + public void removeObserveTarget(String filePath) { + groupMap.remove(filePath); + } + + public ArrayList getGroupNames(String filePath) { + return groupMap.get(filePath); + } + + private void processAllTargetFiles() throws CoreException { + ArrayDeque queue = new ArrayDeque(); + queue.add(this.rootContainer); + + while (!queue.isEmpty()) { + IContainer parentContainer = queue.getFirst(); + queue.remove(); + for (IResource member : parentContainer.members()) { + if (member instanceof IContainer) { + queue.add((IContainer) member); + } else if (member instanceof IFile && this.observeTargetExts.contains(member.getLocation().getFileExtension())) { + addObserveTarget(member.getFullPath().makeRelativeTo(rootContainer.getFullPath()).toOSString()); + } + } + } + } + + public void initContents(IProject project, String version, String profile, ResourceFileDuplicator resFileDuplicator, StyleEDJManager styleEDJManager) { + this.project = project; + this.styleEDJManager = styleEDJManager; + this.resFileDuplicator = resFileDuplicator; + resRootPath = Paths.get(project.getLocation().append(PATH_RESOURCE).toString()); + initRenderer(version, profile, project.getLocation().toString()); + try { + for (IResource member : project.members()) { + if (member instanceof IContainer && member.getProjectRelativePath().toString().equals(PATH_RESOURCE)) { + this.rootContainer = (IContainer) member; + break; + } + } + + if (this.rootContainer != null) { + this.addObserveExt(EXT_EDJ); + this.setRootPath(this.rootContainer.getFullPath().toString()); + this.processAllTargetFiles(); + + // FIXED: Deletion failure problem. + // http://stackoverflow.com/questions/12322143/java-watch-service-appears-to-recreate-deleted-files-what-is-going-on + // watchService = new DirectoryWatchService(); + // watchService.init(project.getLocation().toString() + "/" + PATH_RESOURCE); + // watchService.addListener(this); + // watchService.start(); + } + + } catch (CoreException e) { + logger.error(e.getMessage()); + } + } + + @Override + public void replyRender(RenderEvent event) { + // do nothing + + } + + private Path getResRootRelativePath(String path) { + Path relPath = Paths.get(path); + return this.resRootPath.relativize(relPath).normalize(); + } + + private Path getAbsolutePathFromResRelativePath(String path) { + return this.resRootPath.resolve(path).normalize(); + } + + @Override + public void reply(final IArguments message) { + if (message.getId().equals(RendererConstants.EVENT_GET_GROUP_NAMES)) { + String path = (String) message.getArg(0); + if (PlatformUtil.getOS().equals(PlatformUtil.OS_WIN32)) { + path = resFileDuplicator.getSrcPathFromClonedPath(path); + } + @SuppressWarnings("unchecked") + ArrayList groups = (ArrayList) message.getArg(1); + Path relativePath = this.getResRootRelativePath(path); + this.groupMap.put(relativePath.toString(), groups); + fireEvent(new EdjResourceChangedEvent(EdjResourceChangedEvent.TYPE_GROUP_NAMES_CHANGED, relativePath.toString(), groups)); + } else if (message.getId().equals(RendererConstants.EVENT_GET_STYLE_NAMES)) { + String path = (String) message.getArg(0); + if (PlatformUtil.getOS().equals(PlatformUtil.OS_WIN32)) { + path = resFileDuplicator.getSrcPathFromClonedPath(path); + } + if (path.equals(styleEDJManager.getCustomThemePath())) { + @SuppressWarnings("unchecked") + Map>> styleMap = (Map>>) message.getArg(1); + styleEDJManager.setCustomStyleInfo(styleMap); + fireEvent(new EdjResourceChangedEvent(EdjResourceChangedEvent.TYPE_STYLE_LIST_CHANGED, path, styleMap)); + } + } else if (message.getId().equals(RendererConstants.EVENT_CREATE)) { + this.isRendererInitialized = true; + reqAllEdjInfo(); + } + } + + public void fireEvent(EdjResourceChangedEvent event) { + for (IEdjResourceChangeListener listener : listeners) { + listener.edjResourceChanged(event); + } + } + + private void reqAllEdjInfo() { + for (String path : groupMap.keySet()) { + reqEdjInfo(path); + } + } + + private void reqEdjInfo(String path) { + if (renderer != null && isRendererInitialized) { + Path absPath = this.getAbsolutePathFromResRelativePath(path); + if (PlatformUtil.getOS().equals(PlatformUtil.OS_WIN32)) { + if (path.equals(CUSTOM_STYLE_EDJ)) { + renderer.requestGetStyleNames(styleEDJManager.getCustomThemePathForEflRenderer()); + } else { + String clonedPath = resFileDuplicator.copyFileToTempFolder(absPath.toString()); + if (clonedPath != null) { + renderer.requestGetGroupNames(clonedPath); + } + } + } else { + renderer.requestGetGroupNames(absPath.toString()); + if (path.equals(CUSTOM_STYLE_EDJ)) { + renderer.requestGetStyleNames(styleEDJManager.getCustomThemePath()); + } + } + } + } + + @Override + protected void fireResourceChanged(ArrayList addedList, ArrayList removedList, ArrayList changedList) { + HashMap reqList = new HashMap(); + for (String path : addedList) { + addObserveTarget(path); + reqList.put(path, path); + fireEvent(new EdjResourceChangedEvent(EdjResourceChangedEvent.TYPE_ADDED, path)); + } + for (String path : removedList) { + removeObserveTarget(path); + fireEvent(new EdjResourceChangedEvent(EdjResourceChangedEvent.TYPE_REMOVED, path)); + } + + for (String path : changedList) { + reqList.put(path, path); + } + + for (String path : reqList.keySet()) { + reqEdjInfo(path); + } + + } + + public void addListener(IEdjResourceChangeListener listener) { + if (listeners.contains(listener)) { + return; + } + listeners.add(listener); + } + + public void removeListener(IEdjResourceChangeListener listener) { + listeners.remove(listener); + } + + public ArrayList getAllEdjFiles() { + ArrayList files = new ArrayList(); + files.addAll(groupMap.keySet()); + return files; + } + + @Override + public void contentChanged(List events) { + boolean isEdjChanged = false; + for (ResourceChangedEvent event : events) { + if (event.path.endsWith(EXT_EDJ)) { + isEdjChanged = true; + break; + } + } + if (this.project != null && isEdjChanged && project.getFolder(PATH_RESOURCE) != null) { + try { + this.project.getFolder(PATH_RESOURCE).refreshLocal(IResource.DEPTH_INFINITE, null); + } catch (CoreException e) { + logger.error(e.getMessage()); + } + } + + } + + public void dispose() { + if (watchService != null) { + watchService.interrupt(); + watchService = null; + } + super.dispose(); + + } + +} diff --git a/org.tizen.efluibuilder/src/edjResourceSyncManager/FileDuplicator.java b/org.tizen.efluibuilder/src/edjResourceSyncManager/FileDuplicator.java new file mode 100644 index 0000000..0d9982e --- /dev/null +++ b/org.tizen.efluibuilder/src/edjResourceSyncManager/FileDuplicator.java @@ -0,0 +1,86 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 edjResourceSyncManager; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.channels.FileChannel; + + +public class FileDuplicator { + + public static boolean duplicateFile(String srcPath, String dstPath) { + FileInputStream inputStream = null; + FileOutputStream outputStream = null; + FileChannel fcin = null; + FileChannel fcout = null; + long transferCheck = 0; + try { + inputStream = new FileInputStream(srcPath); + outputStream = new FileOutputStream(dstPath); + fcin = inputStream.getChannel(); + fcout = outputStream.getChannel(); + long size = fcin.size(); + transferCheck = fcin.transferTo(0, size, fcout); + if (transferCheck < 0) { + return false; + } + } catch (IOException e) { + return false; + } finally { + if (fcin != null) { + try { + fcin.close(); + } catch (IOException e) { + // do nothing + } + } + if (fcout != null) { + try { + fcout.close(); + } catch (IOException e) { + // do nothing + } + } + + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e) { + // do nothing + } + } + + if (outputStream != null) { + try { + outputStream.close(); + } catch (IOException e) { + // do nothing + } + } + } + return true; + } +} diff --git a/org.tizen.efluibuilder/src/edjResourceSyncManager/IEdjResourceChangeListener.java b/org.tizen.efluibuilder/src/edjResourceSyncManager/IEdjResourceChangeListener.java new file mode 100644 index 0000000..c9b9562 --- /dev/null +++ b/org.tizen.efluibuilder/src/edjResourceSyncManager/IEdjResourceChangeListener.java @@ -0,0 +1,28 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 edjResourceSyncManager; + +public interface IEdjResourceChangeListener { + public void edjResourceChanged(EdjResourceChangedEvent event); +} diff --git a/org.tizen.efluibuilder/src/edjResourceSyncManager/IWatchServiceListener.java b/org.tizen.efluibuilder/src/edjResourceSyncManager/IWatchServiceListener.java new file mode 100644 index 0000000..8de6dd6 --- /dev/null +++ b/org.tizen.efluibuilder/src/edjResourceSyncManager/IWatchServiceListener.java @@ -0,0 +1,31 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 edjResourceSyncManager; + +import java.util.List; + + +public interface IWatchServiceListener { + public void contentChanged(List events); +} diff --git a/org.tizen.efluibuilder/src/edjResourceSyncManager/ResourceChangedEvent.java b/org.tizen.efluibuilder/src/edjResourceSyncManager/ResourceChangedEvent.java new file mode 100644 index 0000000..34fed3b --- /dev/null +++ b/org.tizen.efluibuilder/src/edjResourceSyncManager/ResourceChangedEvent.java @@ -0,0 +1,40 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 edjResourceSyncManager; + +public class ResourceChangedEvent { + public final static String TYPE_ADDED = "added"; + public final static String TYPE_REMOVED = "removed"; + public final static String TYPE_CHANGED = "changed"; + public final static String TYPE_GROUP_NAMES_CHANGED = "changed"; + public final static String TYPE_STYLE_LIST_CHANGED = "changed"; + + public String type = null; + public String path = null; + + ResourceChangedEvent(final String type, final String path) { + this.type = type; + this.path = path; + } +} diff --git a/org.tizen.efluibuilder/src/edjResourceSyncManager/ResourceChangedObserver.java b/org.tizen.efluibuilder/src/edjResourceSyncManager/ResourceChangedObserver.java new file mode 100644 index 0000000..f515bee --- /dev/null +++ b/org.tizen.efluibuilder/src/edjResourceSyncManager/ResourceChangedObserver.java @@ -0,0 +1,128 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 edjResourceSyncManager; + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; + +import org.apache.commons.io.FilenameUtils; +import org.eclipse.core.resources.IResourceChangeEvent; +import org.eclipse.core.resources.IResourceChangeListener; +import org.eclipse.core.resources.IResourceDelta; +import org.eclipse.core.resources.IResourceDeltaVisitor; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; + + +public class ResourceChangedObserver implements IResourceChangeListener { + private Path rootPath = null; + protected ArrayList observeTargetExts = new ArrayList(); + protected HashMap observeTargetPathMap = new HashMap(); + + ResourceChangedObserver() { + ResourcesPlugin.getWorkspace().addResourceChangeListener(this); + } + + public void setRootPath(String rootPath) { + this.rootPath = Paths.get(rootPath); + } + + public void addObserveExt(String ext) { + if (observeTargetExts.contains(ext) == false) { + observeTargetExts.add(ext); + } + } + + public void removeObserveExt(String ext) { + if (observeTargetExts.contains(ext) == true) { + observeTargetExts.remove(ext); + } + } + + public void addObserveTargetPath(String path) { + if (path != null && !observeTargetPathMap.containsKey(path)) { + // TODO : impl + // observeTargetPathMap.put(path, ""); + } + } + + public void removeObserveTargetPath(String path) { + if (path != null) { + observeTargetPathMap.remove(path); + } + } + + protected void fireResourceChanged(ArrayList addedList, ArrayList removedList, ArrayList changedList) { + + } + + @Override + public void resourceChanged(IResourceChangeEvent event) { + final ArrayList addedList = new ArrayList(); + final ArrayList removedList = new ArrayList(); + final ArrayList changedList = new ArrayList(); + IResourceDelta rootDelta = event.getDelta(); + if (rootDelta == null) { // res folder, extension EDJ; + return; + } + + try { + rootDelta.accept(new IResourceDeltaVisitor() { + @Override + public boolean visit(IResourceDelta delta) throws CoreException { + String fullPath = delta.getFullPath().toString(); + String ext = FilenameUtils.getExtension(fullPath); + Path targetPath = Paths.get(fullPath); + if (rootPath != null && targetPath.startsWith(rootPath)) { + Path relativePath = rootPath.relativize(targetPath).normalize(); + if ((ext != null && observeTargetExts.contains(ext)) || (observeTargetPathMap.containsKey(relativePath.toString()))) { + if (delta.getKind() == IResourceDelta.ADDED) { + addedList.add(relativePath.toString()); + } else if (delta.getKind() == IResourceDelta.REMOVED) { + removedList.add(relativePath.toString()); + } else if (delta.getKind() == IResourceDelta.CHANGED) { + changedList.add(relativePath.toString()); + } + } + } + return true; + } + }); + } catch (CoreException e) { + e.printStackTrace(); + } + + if (addedList.size() > 0 || removedList.size() > 0 || changedList.size() > 0) { + fireResourceChanged(addedList, removedList, changedList); + } + + } + + public void dispose() { + ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); + } + +} diff --git a/org.tizen.efluibuilder/src/edjResourceSyncManager/ResourceFileDuplicator.java b/org.tizen.efluibuilder/src/edjResourceSyncManager/ResourceFileDuplicator.java new file mode 100644 index 0000000..5144347 --- /dev/null +++ b/org.tizen.efluibuilder/src/edjResourceSyncManager/ResourceFileDuplicator.java @@ -0,0 +1,166 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 edjResourceSyncManager; + +import java.io.File; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.net.URLEncoder; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.utility.PlatformUtil; + + +public class ResourceFileDuplicator extends FileDuplicator { + private static Logger logger = LoggerFactory.getLogger(ResourceFileDuplicator.class); + private String prefix; + private HashMap resMap = new HashMap(); + private HashMap requiredResMap = new HashMap(); + static int modifyTimeLength = 15; + static String ENCODING_FORMAT = "UTF-8"; + + public ResourceFileDuplicator(String rootPath) { + File rootDir = new File(rootPath); + if (rootDir.exists() == false) { + boolean result = rootDir.mkdirs(); + if (result == false) { + logger.error("It failed to make directory : " + rootPath); + } + } + this.prefix = rootPath; + removeTmpFiles(); + } + + private long getLastModifiedTime(String srcPath) { + if (srcPath != null) { + File file = new File(srcPath); + if (file.exists() == true) { + return file.lastModified(); + } + } + return 0; + } + + String getDstPath(String srcPath) { + String dstPath = null; + long modifiedTime = getLastModifiedTime(srcPath); + if (modifiedTime > 0) { + try { + dstPath = URLEncoder.encode(srcPath, ENCODING_FORMAT); + } catch (UnsupportedEncodingException e) { + dstPath = null; + } + + if (dstPath != null) { + dstPath = Paths.get(this.prefix).resolve(dstPath).toString() + String.format("%015d", modifiedTime); + } + } + return dstPath; + } + + String getSrcPathFromClonedPath(String clonedPath) { + String srcPath = null; + if (clonedPath.length() > this.prefix.length() + modifyTimeLength) { + String filePath = clonedPath.substring(this.prefix.length(), clonedPath.length() - modifyTimeLength); + try { + srcPath = URLDecoder.decode(filePath, ENCODING_FORMAT); + } catch (UnsupportedEncodingException e) { + srcPath = null; + } + } + + return srcPath; + } + + public String copyFileToTempFolder(String srcPath) { + String copiedPath = null; + if (PlatformUtil.getOS().equals(PlatformUtil.OS_WIN32)) { + File srcFile = new File(srcPath); + String dstPath = getDstPath(srcPath); + if (srcFile.exists() == true) { + if (resMap.get(srcPath) != null && resMap.get(srcPath).equals(dstPath)) { + copiedPath = resMap.get(srcPath); + } else if (dstPath != null) { + File file = new File(dstPath); + if (file.exists()) { + resMap.put(srcPath, dstPath); + copiedPath = dstPath; + } else if (duplicateFile(srcPath, dstPath)) { + resMap.put(srcPath, dstPath); + copiedPath = dstPath; + } + } + } else { + resMap.remove(dstPath); // remove cached file + } + } + return copiedPath; + } + + void removeTmpFiles() { + final File folder = new File(this.prefix); + ArrayList subFiles = new ArrayList(); + ArrayList removedFiles = new ArrayList(); + if (folder.exists()) { + File[] files = folder.listFiles(); + if (files != null) { + for (File file : files) { + if (file.isFile() == true) { + subFiles.add(file); + } + } + } + } + Collections.sort(subFiles); + String previousParts = null; + String path, fileName; + for (int i = 0; i < subFiles.size(); i++) { + path = subFiles.get(i).toString(); + if (path.length() > modifyTimeLength) { + fileName = path.substring(0, path.length() - modifyTimeLength); + if (previousParts == null) { + previousParts = fileName; + } else if (previousParts.equals(fileName)) { + removedFiles.add(subFiles.get(i - 1)); + } + } + } + + for (File removePath : removedFiles) { + boolean result = removePath.delete(); + if (result == false) { + logger.error("It failed to delete the file"); + } + } + } + + public HashMap getRequiredResMap() { + return this.requiredResMap; + } +} diff --git a/org.tizen.efluibuilder/src/graphicalDataManager/ComponentGraphicalData.java b/org.tizen.efluibuilder/src/graphicalDataManager/ComponentGraphicalData.java new file mode 100644 index 0000000..4414870 --- /dev/null +++ b/org.tizen.efluibuilder/src/graphicalDataManager/ComponentGraphicalData.java @@ -0,0 +1,49 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 graphicalDataManager; + +import java.util.List; +import java.util.Map; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.tizen.efluibuilder.renderer.PlaceholderPosition; +import org.tizen.efluibuilder.renderer.Position; + + +public class ComponentGraphicalData { + public Map> placeholderPositionMap = null; + public Map componentPositionMap = null; + public ImageDescriptor imageDescriptor = null; + + public ComponentGraphicalData(ImageDescriptor imageDescriptor, Map componentPositionMap, + Map> placeholderPositionMap) { + this.imageDescriptor = imageDescriptor; + this.componentPositionMap = componentPositionMap; + this.placeholderPositionMap = placeholderPositionMap; + } + + public ComponentGraphicalData() { + } + +} diff --git a/org.tizen.efluibuilder/src/graphicalDataManager/GraphicalDataChangedEvent.java b/org.tizen.efluibuilder/src/graphicalDataManager/GraphicalDataChangedEvent.java new file mode 100644 index 0000000..a9dae62 --- /dev/null +++ b/org.tizen.efluibuilder/src/graphicalDataManager/GraphicalDataChangedEvent.java @@ -0,0 +1,45 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 graphicalDataManager; + +public final class GraphicalDataChangedEvent { + public static final String TYPE_IMAGE_CHANGED = "image_changed"; + public static final String TYPE_COMPONENT_POSITION_CHANGED = "component_position_changed"; + public static final String TYPE_PALCEHOLDER_POSITION_CHANGED = "placeholder_position_changed"; + public String type = ""; + public String viewId = ""; + public String deviceName = ""; + public String orientation; + public String locale = ""; + public ComponentGraphicalData graphicData = null; + + public GraphicalDataChangedEvent(String type, String viewId, String deviceName, String orientation, String locale, ComponentGraphicalData graphicData) { + this.type = type; + this.viewId = viewId; + this.deviceName = deviceName; + this.orientation = orientation; + this.locale = locale; + this.graphicData = graphicData; + } +} diff --git a/org.tizen.efluibuilder/src/graphicalDataManager/GraphicalDataInitializeFailedException.java b/org.tizen.efluibuilder/src/graphicalDataManager/GraphicalDataInitializeFailedException.java new file mode 100644 index 0000000..cc65fd5 --- /dev/null +++ b/org.tizen.efluibuilder/src/graphicalDataManager/GraphicalDataInitializeFailedException.java @@ -0,0 +1,35 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 graphicalDataManager; + +public class GraphicalDataInitializeFailedException extends RuntimeException { + /** + * + */ + private static final long serialVersionUID = 2513526304957313836L; + + public GraphicalDataInitializeFailedException() { + super("Renderer initailize failed"); + } +} diff --git a/org.tizen.efluibuilder/src/graphicalDataManager/GraphicalDataManager.java b/org.tizen.efluibuilder/src/graphicalDataManager/GraphicalDataManager.java new file mode 100644 index 0000000..1ffbbb0 --- /dev/null +++ b/org.tizen.efluibuilder/src/graphicalDataManager/GraphicalDataManager.java @@ -0,0 +1,404 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 graphicalDataManager; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IEditorInput; +import org.tizen.efluibuilder.core.configuration.device.Device; +import org.tizen.efluibuilder.gef.policies.containers.DesignEditorUtil; +import org.tizen.efluibuilder.model.app.AppManager; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.IPartChangedListener; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartMutation; +import org.tizen.efluibuilder.model.part.PartObserver; +import org.tizen.efluibuilder.model.part.ViewsPart; +import org.tizen.efluibuilder.model.renderDataGenerator.RenderDataGenerator; +import org.tizen.efluibuilder.mscreen.configurator.MscreenConstants; +import org.tizen.efluibuilder.renderer.IArguments; +import org.tizen.efluibuilder.renderer.IRenderer; +import org.tizen.efluibuilder.renderer.IRendererListener; +import org.tizen.efluibuilder.renderer.PlaceholderPosition; +import org.tizen.efluibuilder.renderer.Position; +import org.tizen.efluibuilder.renderer.RendererConstants; +import org.tizen.efluibuilder.renderer.RendererFactory; +import org.tizen.efluibuilder.renderer.event.RenderEvent; +import org.tizen.efluibuilder.ui.views.properties.style.StyleEDJManager; + +import edjResourceSyncManager.EdjResourceSyncManager; +import edjResourceSyncManager.ResourceFileDuplicator; + + +public class GraphicalDataManager implements IRendererListener, IPartChangedListener { + + @Override + public void replyRender(RenderEvent event) { + rendererImageChangedHandler(event); + } + + @Override + public void reply(IArguments message) { + handleReply(message); + } + + private void handleReply(final IArguments message) { + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + if (message.getId().equals(RendererConstants.EVENT_CREATE)) { + rendererCreatedHander(message); + } else if (message.getId().equals(RendererConstants.EVENT_GET_ALL_WIDGET_POSITIONS)) { + rendererComponentPositionChangedHandler(message); + } else if (message.getId().equals(RendererConstants.EVENT_GET_PLACEHOLDER_POSITIONS)) { + rendererPlaceholderPositionChangedHandler(message); + } + } + }); + } + + private void fireEvent(final GraphicalDataChangedEvent event) { + final ArrayList listeners = this.listeners; + int size = listeners.size(); + IGraphicalDataChangedListener listener = null; + for (int i = 0; i < size; i++) { + listener = listeners.get(i); + if (event.type.equals(GraphicalDataChangedEvent.TYPE_IMAGE_CHANGED)) { + listener.componentImageDataChanged(event); + } else if (event.type.equals(GraphicalDataChangedEvent.TYPE_COMPONENT_POSITION_CHANGED)) { + listener.componentPositionDataChanged(event); + } else if (event.type.equals(GraphicalDataChangedEvent.TYPE_PALCEHOLDER_POSITION_CHANGED)) { + listener.placeholderPositionDataChanged(event); + } + } + } + + private void rendererCreatedHander(IArguments message) { + // do nothing + } + + private void rendererImageChangedHandler(RenderEvent renderEvent) { + String id = renderEvent.renderer.getName(); + ScreenDataRealizer screenDataRealizer = this.getScreenDataRealizerById(id); + if (screenDataRealizer != null) { + screenDataRealizer.setImageDescriptor(renderEvent.imageDescriptor); + GraphicalDataChangedEvent event = + new GraphicalDataChangedEvent(GraphicalDataChangedEvent.TYPE_IMAGE_CHANGED, screenDataRealizer.screenPart.getUniqueId(), + screenDataRealizer.device.getName(), screenDataRealizer.orientation, screenDataRealizer.locale, + screenDataRealizer.getGraphicalData()); + this.fireEvent(event); + } + } + + private void rendererComponentPositionChangedHandler(IArguments message) { + Map componentPositions = (Map) message.getArg(0); + IRenderer replyRenderer = (IRenderer) message.getArg(1); + String id = replyRenderer.getName(); + + ScreenDataRealizer screenDataRealizer = getScreenDataRealizerById(id); + if (screenDataRealizer != null) { + screenDataRealizer.setComponentPositionMap(componentPositions); + GraphicalDataChangedEvent event = + new GraphicalDataChangedEvent(GraphicalDataChangedEvent.TYPE_COMPONENT_POSITION_CHANGED, screenDataRealizer.screenPart.getUniqueId(), + screenDataRealizer.device.getName(), screenDataRealizer.orientation, screenDataRealizer.locale, + screenDataRealizer.getGraphicalData()); + this.fireEvent(event); + } + } + + private void rendererPlaceholderPositionChangedHandler(IArguments message) { + Map> placeholderPositions = (Map>) message.getArg(0); + IRenderer replyRenderer = (IRenderer) message.getArg(1); + String id = replyRenderer.getName(); + ScreenDataRealizer screenDataRealizer = getScreenDataRealizerById(id); + if (screenDataRealizer != null) { + screenDataRealizer.setPlaceholderPositionMap(placeholderPositions); + GraphicalDataChangedEvent event = + new GraphicalDataChangedEvent(GraphicalDataChangedEvent.TYPE_PALCEHOLDER_POSITION_CHANGED, screenDataRealizer.screenPart.getUniqueId(), + screenDataRealizer.device.getName(), screenDataRealizer.orientation, screenDataRealizer.locale, + screenDataRealizer.getGraphicalData()); + this.fireEvent(event); + } + } + + private ArrayList screenGraphicDataList = new ArrayList(); + private ArrayList listeners = new ArrayList(); + private Part documentPart = null; + private ViewsPart viewsPart = null; + private PartObserver observer = null; + private AppManager appManager = null; + private StyleEDJManager styleEDJManager = null; + private RenderDataGenerator dataGenerator = null; + + private void init(ResourceFileDuplicator resFileDuplicator, EdjResourceSyncManager edjResSyncMgr) { + screenGraphicDataList = new ArrayList(); + listeners = new ArrayList(); + observer = new PartObserver(this); + dataGenerator = new RenderDataGenerator(appManager.getProject(), appManager.getProfile(), appManager.getVersion(), resFileDuplicator, edjResSyncMgr); + observer.observe(documentPart); + } + + public GraphicalDataManager(IEditorInput editorInput, Part documentPart, ResourceFileDuplicator resFileDuplicator, EdjResourceSyncManager edjResSyncMgr, + StyleEDJManager styleEDJManager) { + this.documentPart = documentPart; + if (this.documentPart != null) { + for (Part part : this.documentPart.getChildren()) + if (part instanceof ViewsPart) { + this.viewsPart = (ViewsPart) part; + break; + } + } + + appManager = AppManager.getAppManager(editorInput); + this.styleEDJManager = styleEDJManager; + + this.init(resFileDuplicator, edjResSyncMgr); + } + + private String generateRendererId() { + String id = UUID.randomUUID().toString().replace("-", ""); + return id; + } + + private Part getViewPartByUniqueId(String viewPartUniqueId) { + if (viewsPart != null) { + for (Part part : viewsPart.getChildren()) { + if (part.getUniqueId().equals(viewPartUniqueId)) { + return part; + } + } + } + return null; + } + + private ScreenDataRealizer createScreenGraphicData(String viewPartUniqueId, Device device, String orientation, String locale) { + ScreenDataRealizer screenData = null; + int width = device.getWidth(); + int height = device.getHeight(); + + Part viewPart = this.getViewPartByUniqueId(viewPartUniqueId); + if (viewPart != null) { + String id = this.generateRendererId(); + RendererFactory factory = RendererFactory.getDefault(); + IRenderer renderer = factory.create(appManager.getVersion(), appManager.getProfile(), appManager.getProject().getLocation().toString()); + if (renderer != null) { + renderer.setName(id); + renderer.addRendererListener(this); + if (orientation.equals(MscreenConstants.ORIENTATION_PORTRAIT)) { + renderer.create(width, height, styleEDJManager.getDefaultThemePathForEflRenderer(), styleEDJManager.getCustomThemePathForEflRenderer()); + } else { + renderer.create(height, width, styleEDJManager.getDefaultThemePathForEflRenderer(), styleEDJManager.getCustomThemePathForEflRenderer()); + } + screenData = new ScreenDataRealizer(renderer, id, viewPart, device, orientation, locale); + } + } + return screenData; + } + + private ScreenDataRealizer getScreenDataRealizer(String viewPartUniqueId, Device device, String orientation, String locale) { + int size = screenGraphicDataList.size(); + ScreenDataRealizer dataRealizer = null; + for (int i = 0; i < size; i++) { + dataRealizer = screenGraphicDataList.get(i); + if (dataRealizer.screenPart.getUniqueId().equals(viewPartUniqueId) && dataRealizer.device.getName().equals(device.getName()) + && dataRealizer.orientation.equals(orientation) && dataRealizer.locale.equals(locale)) { + return dataRealizer; + } + } + return null; + } + + public boolean addEventListener(IGraphicalDataChangedListener listener) { + if (this.listeners.contains(listener) == false) { + return this.listeners.add(listener); + } + return false; + } + + public boolean removeEventListener(IGraphicalDataChangedListener listener) { + if (this.listeners.contains(listener) == true) { + return this.listeners.remove(listener); + } + return false; + } + + public ComponentGraphicalData getGraphicalData(String viewId, Device device, String orientation, String locale, boolean bForce) + throws GraphicalDataInitializeFailedException { + + ScreenDataRealizer screenData = this.getScreenDataRealizer(viewId, device, orientation, locale); + if (screenData == null) { + screenData = this.createScreenGraphicData(viewId, device, orientation, locale); + if (screenData != null) { + this.screenGraphicDataList.add(screenData); + } + } + + if (screenData == null) { + throw new GraphicalDataInitializeFailedException(); + } + + if (screenData.isDirty() || bForce == true) { + screenData.cleanDirty(); + if (screenData.renderer != null && screenData.renderer.isRenderable() == false) { + throw new GraphicalDataInitializeFailedException(); + } else { + screenData.render(dataGenerator); + } + } else { + return screenData.getGraphicalData(); + } + return null; + } + + public ComponentGraphicalData getGraphicalData(String viewId, Device device, String orientation, String locale) { + return getGraphicalData(viewId, device, orientation, locale, false); + } + + private ScreenDataRealizer getScreenDataRealizerById(String Id) { + ScreenDataRealizer graphicData = null; + int size = this.screenGraphicDataList.size(); + for (int i = 0; i < size; i++) { + graphicData = this.screenGraphicDataList.get(i); + if (graphicData.getId().equals(Id)) { + return graphicData; + } + } + return null; + } + + private ArrayList getScreenDataRealizerByViewId(String viewId) { + ArrayList dataList = new ArrayList(); + ScreenDataRealizer graphicData = null; + + int size = this.screenGraphicDataList.size(); + for (int i = 0; i < size; i++) { + graphicData = this.screenGraphicDataList.get(i); + if (graphicData.screenPart.getUniqueId().equals(viewId)) { + dataList.add(graphicData); + } + } + return dataList; + } + + private void removeScreenDataRealizerByViewId(String viewId) { + ArrayList removeTargets = getScreenDataRealizerByViewId(viewId); + for (ScreenDataRealizer screenDataRealizer : removeTargets) { + screenDataRealizer.destroy(); + } + screenGraphicDataList.removeAll(removeTargets); + } + + public void partsChanged(List mutations, PartObserver observer, String sender) { + int size = mutations.size(); + PartMutation mutation = null; + + Map changedViewsMap = new HashMap(); + Map removedViewsMap = new HashMap(); + Map changedConfsMap = new HashMap(); + Map removedConfsMap = new HashMap(); + + Part changedViewPart = null; + + for (int i = 0; i < size; i++) { + changedViewPart = null; + mutation = mutations.get(i); + if (mutation.getType().equals(PartMutation.PARTS_ADDED) || mutation.getType().equals(PartMutation.PARTS_ORDER_CHANGED)) { + if (mutation.getTargetPart() instanceof ComponentPart) { + changedViewPart = ((ComponentPart) mutation.getTargetPart()).getOwnerViewPart(); + } + } else if (mutation.getType().equals(PartMutation.PARTS_REMOVED)) { + if (mutation.getTargetPart() instanceof ComponentPart) { + changedViewPart = ((ComponentPart) mutation.getTargetPart()).getOwnerViewPart(); + } else if (mutation.getTargetPart() instanceof ViewsPart) { + for (Part removedView : mutation.getRemovedParts()) { + removedViewsMap.put(removedView.getUniqueId(), removedView); + } + } + } else if (mutation.getType().equals(PartMutation.PROPERTY_CHANGED) && mutation.getTargetPart() instanceof ComponentPart && DesignEditorUtil.isUIProperty(mutation.getPropertyName())) { + changedViewPart = ((ComponentPart) mutation.getTargetPart()).getOwnerViewPart(); + } else if (mutation.getType().equals(PartMutation.CONFIGURES_ADDED)) { + // do nothing + } else if (mutation.getType().equals(PartMutation.CONFIGURES_REMOVED)) { + removedConfsMap.put(mutation.getTargetPart().getUniqueId(), mutation.getTargetPart()); + } else if (mutation.getType().equals(PartMutation.CONFIGURE_PROPERTY_CHANGED)) { + changedConfsMap.put(mutation.getTargetPart().getUniqueId(), mutation.getTargetPart()); + } + if (changedViewPart != null) { + changedViewsMap.put(changedViewPart.getUniqueId(), changedViewPart); + } + } + this.handleViewRemoved(removedViewsMap); + this.handleViewChanged(changedViewsMap); + this.handleConfigureRemoved(removedConfsMap); + this.handleConfigureChanged(changedConfsMap); + + } + + private void handleViewChanged(Map views) { + for (Part part : views.values()) { + this.setDirty(part.getUniqueId()); + } + } + + private void handleViewRemoved(Map views) { + for (Part part : views.values()) { + this.removeScreenDataRealizerByViewId(part.getUniqueId()); + } + } + + private void handleConfigureChanged(Map configures) { + // do nothing + } + + private void handleConfigureRemoved(Map configures) { + // for (Part part : configures.values()) { + // this.removeScreenDataRealizerByConfigureId(part.getUniqueId()); + // } + } + + private void setDirty(String viewId) { + List dataRealizerList = this.getScreenDataRealizerByViewId(viewId); + for (ScreenDataRealizer dataRealizer : dataRealizerList) { + dataRealizer.setDirty(); + } + } + + public RenderDataGenerator getRenderDataGenerator() { + return this.dataGenerator; + } + + public void destroy() { + for (ScreenDataRealizer screenDataRealizer : this.screenGraphicDataList) { + screenDataRealizer.destroy(); + } + screenGraphicDataList.clear(); + listeners.clear(); + } + +} diff --git a/org.tizen.efluibuilder/src/graphicalDataManager/IGraphicalDataChangedListener.java b/org.tizen.efluibuilder/src/graphicalDataManager/IGraphicalDataChangedListener.java new file mode 100644 index 0000000..101f05d --- /dev/null +++ b/org.tizen.efluibuilder/src/graphicalDataManager/IGraphicalDataChangedListener.java @@ -0,0 +1,48 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 graphicalDataManager; + +public interface IGraphicalDataChangedListener { + + public void componentImageDataChanged(GraphicalDataChangedEvent event); + + public void componentPositionDataChanged(GraphicalDataChangedEvent event); + + public void placeholderPositionDataChanged(GraphicalDataChangedEvent event); + + public class GraphicalDataChangedListenerStub implements IGraphicalDataChangedListener { + + @Override + public void componentImageDataChanged(GraphicalDataChangedEvent event) { + } + + @Override + public void componentPositionDataChanged(GraphicalDataChangedEvent event) { + } + + @Override + public void placeholderPositionDataChanged(GraphicalDataChangedEvent event) { + } + } +} diff --git a/org.tizen.efluibuilder/src/graphicalDataManager/ScreenDataRealizer.java b/org.tizen.efluibuilder/src/graphicalDataManager/ScreenDataRealizer.java new file mode 100644 index 0000000..ba4a277 --- /dev/null +++ b/org.tizen.efluibuilder/src/graphicalDataManager/ScreenDataRealizer.java @@ -0,0 +1,119 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 graphicalDataManager; + +import java.util.List; +import java.util.Map; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.tizen.efluibuilder.core.configuration.device.Device; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.renderDataGenerator.RenderDataGenerator; +import org.tizen.efluibuilder.renderer.IRenderer; +import org.tizen.efluibuilder.renderer.PlaceholderPosition; +import org.tizen.efluibuilder.renderer.Position; + + +public class ScreenDataRealizer { + public Part screenPart = null; + public Device device = null; + public String orientation = null; + public String locale = null; + private String id = null; + public IRenderer renderer = null; + private boolean isDirty = true; + private ComponentGraphicalData componentGraphicalData = null; + + public ScreenDataRealizer(IRenderer renderer, String screenId, Part screenPart, Device device, String orientation, String locale) { + this.id = screenId; + this.screenPart = screenPart; + this.device = device; + this.orientation = orientation; + this.locale = locale; + this.componentGraphicalData = new ComponentGraphicalData(); + this.renderer = renderer; + this.isDirty = true; + } + + public void setImageDescriptor(ImageDescriptor imageDesc) { + this.componentGraphicalData.imageDescriptor = imageDesc; + } + + public ImageDescriptor getImageDescriptor() { + return this.componentGraphicalData.imageDescriptor; + } + + public void setComponentPositionMap(Map positionMap) { + this.componentGraphicalData.componentPositionMap = positionMap; + } + + public Map getComponentPositionMap() { + return this.componentGraphicalData.componentPositionMap; + } + + public void setPlaceholderPositionMap(Map> positionMap) { + this.componentGraphicalData.placeholderPositionMap = positionMap; + } + + public Map> getPlaceholderPositionMap() { + return this.componentGraphicalData.placeholderPositionMap; + } + + public void render(RenderDataGenerator dataGenerator) { + if (this.renderer != null) { + String genData = dataGenerator.getJsonDataFromPart(this.screenPart, this.locale, this.device, this.orientation); + if (genData != null) { + renderer.render(IRenderer.RENDER_TYPE_DESIGN, genData); + } + } + } + + public void setDirty() { + this.isDirty = true; + } + + public void cleanDirty() { + this.isDirty = false; + } + + public boolean isDirty() { + return this.isDirty; + } + + public final ComponentGraphicalData getGraphicalData() { + return this.componentGraphicalData; + } + + public String getId() { + return this.id; + } + + public void destroy() { + if (this.renderer != null) { + this.renderer.destroy(); + this.renderer = null; + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/BuilderConstants.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/BuilderConstants.java new file mode 100644 index 0000000..9f9536b --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/BuilderConstants.java @@ -0,0 +1,70 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder; + +public final class BuilderConstants { + // Special character + public static final String EMPTY = ""; //$NON-NLS-1$ + public static final String SPACE = " "; //$NON-NLS-1$ + public static final String TAB = "\t"; //$NON-NLS-1$ + public static final String SLASH = "/"; //$NON-NLS-1$ + public static final String COMMENT = "//"; //$NON-NLS-1$ + public static final String BSLASH = "\\"; //$NON-NLS-1$ + public static final String NEW_LINE = "\n"; //$NON-NLS-1$ + public static final String COMMA = ","; //$NON-NLS-1$ + public static final String COLON = ":"; //$NON-NLS-1$ + public static final String SEMICOLON = ";"; //$NON-NLS-1$ + public static final String UNDERSCORE = "_"; //$NON-NLS-1$ + public static final String OPEN_BRACKET = "("; //$NON-NLS-1$ + public static final String CLOSE_BRACKET = ")"; //$NON-NLS-1$ + public static final String OPEN_TRI_BRACKET = "<"; //$NON-NLS-1$ + public static final String CLOSE_TRI_BRACKET = ">"; //$NON-NLS-1$ + public static final String SHARP = "#"; //$NON-NLS-1$ + public static final String AUTO = "auto"; //$NON-NLS-1$ + + // Path + public static final String ICON_DIR = "res/icons/"; //$NON-NLS-1$ + + // Designer and Preview + public static final String PROPERTY_DOCK_LOCATION = "org.tizen.efluibuilder.ui.editor.components.dock"; //$NON-NLS-1$ + public static final String PROPERTY_STATE = "org.tizen.efluibuilder.ui.editor.components.state"; //$NON-NLS-1$ + public static final String PROPERTY_PALETTE_WIDTH = "org.tizen.efluibuilder.ui.editor.components.paletteWidth"; //$NON-NLS-1$ + + // Project file attribute value + public static final String TRUE = "true"; //$NON-NLS-1$ + public static final String FALSE = "false"; //$NON-NLS-1$ + + // Property + public static final String PROPERTY_ID = "id"; //$NON-NLS-1$ + public static final String REGULAREXPRESSION = "^[a-zA-Z]+[a-zA-Z0-9_]*$"; //$NON-NLS-1$ + public static final String INTEGERVALUE = "^[0-9-]?+[0-9]*$"; //$NON-NLS-1$ + public static final String FLOATVALUE = "^[0-9-]?+[.?0-9]*$"; //$NON-NLS-1$ + + // HandlerCodeWriter + public static final String UNBINDEDFUNCNAME = "unbinded_function"; //$NON-NLS-1$ + + // mouse action count per pixel + public static final int countPerPx = 10; + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/BuilderPlugin.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/BuilderPlugin.java new file mode 100644 index 0000000..6859a72 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/BuilderPlugin.java @@ -0,0 +1,82 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + + +/** + * The activator class controls the plug-in life cycle. + */ +public class BuilderPlugin extends AbstractUIPlugin { + + /** + * The plug-in id. + */ + public static final String PLUGIN_ID = "org.tizen.efluibuilder"; //$NON-NLS-1$ + + /** + * The shared instance. + */ + private static BuilderPlugin plugin; + + /** + * The constructor. + */ + public BuilderPlugin() { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext ) + */ + @Override + 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 ) + */ + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance. + * + * @return the shared instance. + */ + public static BuilderPlugin getDefault() { + return plugin; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AddEmptyViewAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AddEmptyViewAction.java new file mode 100644 index 0000000..a8c83ba --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AddEmptyViewAction.java @@ -0,0 +1,134 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import java.util.List; + +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.tizen.efluibuilder.BuilderPlugin; +import org.tizen.efluibuilder.gef.commands.CommandUtil; +import org.tizen.efluibuilder.gef.editparts.DesignEditPart; +import org.tizen.efluibuilder.gef.policies.containers.DesignEditorUtil; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.part.DocumentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.part.ViewPart; +import org.tizen.efluibuilder.model.part.ViewsPart; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.actions.ActionConstants; +import org.tizen.efluibuilder.ui.views.outline.Messages; + + +public class AddEmptyViewAction extends PartAction { + + /** + * Creates a {@link AddEmptyViewAction} and associates it with the given workbench part. + * + * @param part + * the workbench part + * @param rootEditPart + * a root {@link EditPart} + */ + public AddEmptyViewAction(IWorkbenchPart part, EditPart rootEditPart) { + super(part, rootEditPart); + } + + @Override + protected boolean calculateEnabled() { + if (rootEditPart != null && rootEditPart.getChildren().isEmpty() == false) { + Part part = (Part) ((DesignEditPart) rootEditPart.getChildren().get(0)).getModel(); + DocumentPart documentPart = part.getOwnerDocumentPart(); + if (documentPart.isValidDocument()) { + return true; + } else { + return false; + } + } else { + return false; + } + } + + @Override + protected void init() { + super.init(); + + setText(Messages.ACTION_ADD_VIEW_EMPTY_TITLE); + setId(ActionConstants.ADD_VIEW_EMPTY); + + ImageDescriptor imgDesc = null; + + imgDesc = AbstractUIPlugin.imageDescriptorFromPlugin(BuilderPlugin.PLUGIN_ID, Messages.ACTION_ADD_VIEW_EMPTY_ICON_NOR); + setImageDescriptor(imgDesc); + + // setDisabledImageDescriptor(imgDesc); + // imgDesc = AbstractUIPlugin.imageDescriptorFromPlugin(BuilderPlugin.PLUGIN_ID, + // Messages.ACTION_ADD_VIEW_EMPTY_ICON_MV); + // imgDesc = AbstractUIPlugin.imageDescriptorFromPlugin(BuilderPlugin.PLUGIN_ID, + // Messages.ACTION_ADD_VIEW_EMPTY_ICON_SEL); + // setHoverImageDescriptor(imgDesc); + + setEnabled(true); + } + + @Override + public void run() { + List partList = CommandUtil.getWidgetPartsFromSelectedObjects(getSelectedObjects()); + Part nextSibling = null; + Part selectedPart = null; + Part viewsPart = null; + if (partList.size() == 1) { + selectedPart = partList.get(0); + if (selectedPart instanceof ViewPart) { + nextSibling = selectedPart.getNextSibling(); + } + } + + if (this.rootEditPart.getViewer().getContents().getModel() instanceof ViewsPart) { + viewsPart = (Part) this.rootEditPart.getViewer().getContents().getModel(); + Part newPart = PartUtil.createPartWithInitValue(viewsPart.getOwnerDocumentPart(), PartType.VIEW, viewsPart, LayoutSchemaConstants.VIEW); + if (newPart == null) { + return; + } + Point screenSzie = ((DesignViewer) rootEditPart.getViewer()).getMScreenQualifierManager().getScreenSize(); + Point viewPosition = DesignEditorUtil.getNextViewPosition(viewsPart, screenSzie.x, screenSzie.y); + newPart.setPropertyValue(LayoutSchemaConstants.PAGE_LOCATION_X, Integer.toString(viewPosition.x)); + newPart.setPropertyValue(LayoutSchemaConstants.PAGE_LOCATION_Y, Integer.toString(viewPosition.y)); + + Command command = PartUtil.createAddPartCommand(viewsPart, newPart, nextSibling); + if (command != null) { + CommandStack cmdStack = rootEditPart.getViewer().getEditDomain().getCommandStack(); + cmdStack.execute(command); + } + } + + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartAction.java new file mode 100644 index 0000000..45c6ab5 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartAction.java @@ -0,0 +1,314 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.gef.commands.CompoundCommand; +import org.eclipse.ui.IWorkbenchPart; +import org.tizen.efluibuilder.gef.commands.CommandUtil; +import org.tizen.efluibuilder.gef.policies.containers.DesignEditorUtil; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.ViewPart; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.actions.ActionConstants; + + +public class AlignPartAction extends PartAction { + + private String type; + + public final static String TYPE_LEFT = "align_left"; + public final static String TYPE_TOP = "align_top"; + public final static String TYPE_RIGHT = "action_align_right"; + public final static String TYPE_BOTTOM = "action_align_bottom"; + public final static String TYPE_VERTICAL_CENTER = "action_vertical_center"; + public final static String TYPE_HORIZONTAL_CENTER = "action_horizontal_center"; + public final static String TYPE_DISTRIBUTE_VERTICAL_SPACING = "action_same_vertical_spacing"; + public final static String TYPE_DISTRIBUTE_HORIZONTAL_SPACING = "action_same_horizontal_spacing"; + public final static String TYPE_LAYOUT_VERTICALLY = "action_layout_vertically"; + public final static String TYPE_LAYOUT_HORIZONTALLY = "action_layout_horizontally"; + + public AlignPartAction(IWorkbenchPart part, EditPart rootEditPart, String type) { + super(part, rootEditPart); + this.type = type; + } + + protected Command getCommand(List selectedParts) { + CompoundCommand compCmd = null; + List alignedBoundSet = this.getAlignedBoundList(selectedParts, this.type); + if ((alignedBoundSet != null) && (alignedBoundSet.size() > 0)) { + PartBoundSet boundSet = null; + for (int i = 0; i < alignedBoundSet.size(); i++) { + boundSet = alignedBoundSet.get(i); + if (!(boundSet.part instanceof ComponentPart)) { + continue; + } + ComponentPart part = (ComponentPart) boundSet.part; + Part parent = part.getParent(); + if (compCmd == null) { + compCmd = new CompoundCommand(); + } + if (part instanceof ViewPart) { + compCmd.add(PartUtil.createSetPropertyCommand(part, LayoutSchemaConstants.PAGE_LOCATION_X, Integer.toString(boundSet.bound.x))); + compCmd.add(PartUtil.createSetPropertyCommand(part, LayoutSchemaConstants.PAGE_LOCATION_Y, Integer.toString(boundSet.bound.y))); + } else { + compCmd.add(PartUtil.createPackCommandWithVariation(part, parent, getCurrentConfiguration(), boundSet.bound)); + } + // compCmd.add(PartUtil.createPackCommand(boundSet.part, null, boundSet.bound)); + } + } + + return compCmd; + } + + @Override + protected boolean calculateEnabled() { + List orderedParts = CommandUtil.getWidgetPartsFromSelectedObjects(getSelectedObjects()); + if (orderedParts.size() > 1 && DesignEditorUtil.isSameParent(orderedParts) + && (orderedParts.get(0).getParent().getDescriptorId().equals(LayoutSchemaConstants.GRID) + || orderedParts.get(0).getDescriptorId().equals(LayoutSchemaConstants.VIEW)) + && + hasEventPart(orderedParts) == false) { + return true; + } + return false; + } + + @Override + public void run() { + List orderedParts = CommandUtil.getWidgetPartsFromSelectedObjects(getSelectedObjects()); + Command command = getCommand(orderedParts); + CommandStack cmdStack = rootEditPart.getViewer().getEditDomain().getCommandStack(); + if (command != null && command.canExecute() && (cmdStack != null)) { + cmdStack.execute(command); + } + } + + @Override + protected void init() { + super.init(); + setId(ActionConstants.ALIGN); + setEnabled(false); + } + + private Rectangle getOuterPackBound(List partList) { + Rectangle outerBound = new Rectangle(); + Rectangle partBound; + int x1 = 0, y1 = 0, x2 = 0, y2 = 0; + if (partList.size() == 0) { + return null; + } + + for (int i = 0; i < partList.size(); i++) { + Part part = partList.get(i); + if (!(part instanceof ComponentPart)) { + continue; + } + ComponentPart componentPart = (ComponentPart) part; + partBound = DesignEditorUtil.getPackBound(componentPart, getCurrentConfigurationID()); + if (i == 0) { + x1 = partBound.x; + y1 = partBound.y; + x2 = x1 + partBound.width; + y2 = y1 + partBound.height; + continue; + } + if (x1 > partBound.x) { + x1 = partBound.x; + } + if (y1 > partBound.y) { + y1 = partBound.y; + } + if (x2 < (partBound.x + partBound.width)) { + x2 = partBound.x + partBound.width; + } + if (y2 < (partBound.y + partBound.height)) { + y2 = partBound.y + partBound.height; + } + } + outerBound.x = x1; + outerBound.y = y1; + outerBound.width = x2 - x1; + outerBound.height = y2 - y1; + return outerBound; + } + + private List getSortedBoundsetByEdge(List partBoundSetList, String edge) { + List sortedBoundSetList = new ArrayList(); + int val1, val2; + PartBoundSet temp; + + for (int i = 0; i < partBoundSetList.size(); i++) { + sortedBoundSetList.add(partBoundSetList.get(i)); + } + + for (int i = 0; i < sortedBoundSetList.size(); i++) { + for (int j = sortedBoundSetList.size() - 1; j > i; j--) { + if (edge.equals("left")) { + val1 = sortedBoundSetList.get(i).bound.x; + val2 = sortedBoundSetList.get(j).bound.x; + } else if (edge.equals("top")) { + val1 = sortedBoundSetList.get(i).bound.y; + val2 = sortedBoundSetList.get(j).bound.y; + } else if (edge.equals("right")) { + val1 = sortedBoundSetList.get(i).bound.x + sortedBoundSetList.get(i).bound.width; + val2 = sortedBoundSetList.get(j).bound.x + sortedBoundSetList.get(j).bound.width; + } else if (edge.equals("bottom")) { + val1 = sortedBoundSetList.get(i).bound.y + sortedBoundSetList.get(i).bound.height; + val2 = sortedBoundSetList.get(j).bound.y + sortedBoundSetList.get(j).bound.height; + } else { + break; + } + if (val1 > val2) { + temp = sortedBoundSetList.get(i); + sortedBoundSetList.set(i, sortedBoundSetList.get(j)); + sortedBoundSetList.set(j, temp); + } + } + } + return sortedBoundSetList; + + } + + protected List getAlignedBoundList(List partList, String type) { + + List alignedBoundList = new ArrayList(); + List sortedBoundList = null; + List baseBoundList = new ArrayList(); + List bounds = new ArrayList(); + DesignViewer viewer = (DesignViewer) this.rootEditPart.getViewer(); + + boolean boundChanged = true; + + for (int i = 0; i < partList.size(); i++) { + Part part = partList.get(i); + if (!(part instanceof ComponentPart)) { + continue; + } + + ComponentPart componentPart = (ComponentPart) part; + Rectangle bound; + if (part instanceof ViewPart) { + Point viewSize = viewer.getMScreenQualifierManager().getScreenSize(); + Point viewPosition = DesignEditorUtil.getPageLocation(part); + bound = new Rectangle(viewPosition.x, viewPosition.y, viewSize.x, viewSize.y); + } else { + bound = DesignEditorUtil.getPackBound(componentPart, getCurrentConfigurationID());// part.getWidgetBounds(); + } + baseBoundList.add(new PartBoundSet(part, bound)); + bounds.add(bound); + } + + + Rectangle outerBound = DesignEditorUtil.getOuterBound(bounds); + if (null == outerBound) { + return null; + } + + PartBoundSet boundSet; + + for (int i = 0; i < baseBoundList.size(); i++) { + boundSet = baseBoundList.get(i); + if (type.equals(AlignPartAction.TYPE_LEFT)) { + boundSet.bound.x = outerBound.x; + } else if (type.equals(AlignPartAction.TYPE_TOP)) { + boundSet.bound.y = outerBound.y; + } else if (type.equals(AlignPartAction.TYPE_RIGHT)) { + boundSet.bound.x = outerBound.x + outerBound.width - boundSet.bound.width; + } else if (type.equals(AlignPartAction.TYPE_BOTTOM)) { + boundSet.bound.y = outerBound.y + outerBound.height - boundSet.bound.height; + } else if (type.equals(AlignPartAction.TYPE_HORIZONTAL_CENTER)) { + boundSet.bound.x = ((outerBound.x * 2 + outerBound.width) - boundSet.bound.width) / 2; + } else if (type.equals(AlignPartAction.TYPE_VERTICAL_CENTER)) { + boundSet.bound.y = ((outerBound.y * 2 + outerBound.height) - boundSet.bound.height) / 2; + } else { + boundChanged = false; + } + + if (boundChanged) { + alignedBoundList.add(boundSet); + } + } + + if (type.equals(AlignPartAction.TYPE_DISTRIBUTE_HORIZONTAL_SPACING)) { + sortedBoundList = this.getSortedBoundsetByEdge(baseBoundList, "left"); + int totDist = 0; + int margin = 0; + int prevPos = 0; + if (sortedBoundList.size() > 2) { + for (int i = 0; i < sortedBoundList.size(); i++) { + totDist += sortedBoundList.get(i).bound.width; + } + + margin = (outerBound.width - totDist) / (sortedBoundList.size() - 1); + + for (int i = 0; i < sortedBoundList.size() - 1; i++) { + if (i == 0) { + prevPos = sortedBoundList.get(i).bound.x; + } else { + sortedBoundList.get(i).bound.x = prevPos; + } + prevPos += sortedBoundList.get(i).bound.width + margin; + } + alignedBoundList = sortedBoundList; + } + } else if (type.equals(AlignPartAction.TYPE_DISTRIBUTE_VERTICAL_SPACING)) { + sortedBoundList = this.getSortedBoundsetByEdge(baseBoundList, "top"); + int totDist = 0; + int margin = 0; + int prevPos = 0; + if (sortedBoundList.size() > 2) { + totDist = 0; + for (int i = 0; i < sortedBoundList.size(); i++) { + totDist += sortedBoundList.get(i).bound.height; + } + margin = (outerBound.height - totDist) / (sortedBoundList.size() - 1); + + for (int i = 0; i < sortedBoundList.size() - 1; i++) { + if (i == 0) { + prevPos = sortedBoundList.get(i).bound.y; + } else { + sortedBoundList.get(i).bound.y = prevPos; + } + prevPos += sortedBoundList.get(i).bound.height + margin; + } + alignedBoundList = sortedBoundList; + } + } + + return alignedBoundList; + + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartActionBottom.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartActionBottom.java new file mode 100644 index 0000000..64891b4 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartActionBottom.java @@ -0,0 +1,51 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.internal.GEFMessages; +import org.eclipse.ui.IWorkbenchPart; +import org.tizen.efluibuilder.ui.actions.ActionConstants; +import org.tizen.efluibuilder.ui.resources.ImageResources; + + +@SuppressWarnings("restriction") +public class AlignPartActionBottom extends AlignPartAction { + public AlignPartActionBottom(IWorkbenchPart part, EditPart rootEditPart) { + super(part, rootEditPart, AlignPartAction.TYPE_BOTTOM); + } + + protected void init() { + super.init(); + setId(ActionConstants.ALIGN_BOTTOM); + setText(GEFMessages.AlignBottomAction_Label); + setToolTipText(GEFMessages.AlignBottomAction_Tooltip); + // setImageDescriptor(InternalImages.DESC_VERT_ALIGN_BOTTOM); + // setDisabledImageDescriptor(InternalImages.DESC_VERT_ALIGN_BOTTOM_DIS); + setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_BOTTOM_NOR)); + setDisabledImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_BOTTOM_DIM)); + setHoverImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_BOTTOM_MV)); + setEnabled(false); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartActionHCenter.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartActionHCenter.java new file mode 100644 index 0000000..710c59b --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartActionHCenter.java @@ -0,0 +1,52 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.internal.GEFMessages; +import org.eclipse.ui.IWorkbenchPart; +import org.tizen.efluibuilder.ui.actions.ActionConstants; +import org.tizen.efluibuilder.ui.resources.ImageResources; + + +@SuppressWarnings("restriction") +public class AlignPartActionHCenter extends AlignPartAction { + public AlignPartActionHCenter(IWorkbenchPart part, EditPart rootEditPart) { + super(part, rootEditPart, AlignPartAction.TYPE_HORIZONTAL_CENTER); + } + + protected void init() { + super.init(); + + setText(GEFMessages.AlignCenterAction_Label); + setToolTipText(GEFMessages.AlignCenterAction_Tooltip); + // setImageDescriptor(InternalImages.DESC_HORZ_ALIGN_CENTER); + // setDisabledImageDescriptor(InternalImages.DESC_HORZ_ALIGN_CENTER_DIS); + setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_CENTER_NOR)); + setDisabledImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_CENTER_DIM)); + setHoverImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_CENTER_MV)); + setId(ActionConstants.ALIGN_HORIZONTAL_CENTER); + setEnabled(false); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartActionHDistribute.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartActionHDistribute.java new file mode 100644 index 0000000..6e5dfae --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartActionHDistribute.java @@ -0,0 +1,63 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import java.util.List; + +import org.eclipse.gef.EditPart; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PlatformUI; +import org.tizen.efluibuilder.gef.commands.CommandUtil; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.ui.actions.ActionConstants; + + +public class AlignPartActionHDistribute extends AlignPartAction { + public AlignPartActionHDistribute(IWorkbenchPart part, EditPart rootEditPart) { + super(part, rootEditPart, AlignPartAction.TYPE_DISTRIBUTE_HORIZONTAL_SPACING); + } + + protected boolean calculateEnabled() { + if (super.calculateEnabled()) { + List orderedParts = CommandUtil.getWidgetPartsFromSelectedObjects(getSelectedObjects()); + if (orderedParts.size() > 2) { + return true; + } + } + return false; + } + + protected void init() { + super.init(); + + ISharedImages images = PlatformUI.getWorkbench().getSharedImages(); + setText(Messages.ACTION_ALIGN_DISTRIBUTE_HORIZONTALLY); + setId(ActionConstants.ALIGN_DISTRIBUTE_HORIZONTAL_SPACING); + setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); + setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); + setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED)); + setEnabled(false); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartActionLeft.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartActionLeft.java new file mode 100644 index 0000000..500c245 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartActionLeft.java @@ -0,0 +1,50 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.internal.GEFMessages; +import org.eclipse.ui.IWorkbenchPart; +import org.tizen.efluibuilder.ui.actions.ActionConstants; +import org.tizen.efluibuilder.ui.resources.ImageResources; + + +@SuppressWarnings("restriction") +public class AlignPartActionLeft extends AlignPartAction { + public AlignPartActionLeft(IWorkbenchPart part, EditPart rootEditPart) { + super(part, rootEditPart, AlignPartAction.TYPE_LEFT); + } + + protected void init() { + super.init(); + setText(GEFMessages.AlignLeftAction_Label); + setToolTipText(GEFMessages.AlignLeftAction_Tooltip); + + setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_LEFT_NOR)); + setDisabledImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_LEFT_DIM)); + setHoverImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_LEFT_MV)); + setId(ActionConstants.ALIGN_LEFT); + setEnabled(false); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartActionRight.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartActionRight.java new file mode 100644 index 0000000..b811810 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartActionRight.java @@ -0,0 +1,51 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.internal.GEFMessages; +import org.eclipse.ui.IWorkbenchPart; +import org.tizen.efluibuilder.ui.actions.ActionConstants; +import org.tizen.efluibuilder.ui.resources.ImageResources; + + +@SuppressWarnings("restriction") +public class AlignPartActionRight extends AlignPartAction { + public AlignPartActionRight(IWorkbenchPart part, EditPart rootEditPart) { + super(part, rootEditPart, AlignPartAction.TYPE_RIGHT); + } + + protected void init() { + super.init(); + setId(ActionConstants.ALIGN_RIGHT); + setText(GEFMessages.AlignRightAction_Label); + setToolTipText(GEFMessages.AlignRightAction_Tooltip); + // setImageDescriptor(InternalImages.DESC_HORZ_ALIGN_RIGHT); + // setDisabledImageDescriptor(InternalImages.DESC_HORZ_ALIGN_RIGHT_DIS); + setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_RIGHT_NOR)); + setDisabledImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_RIGHT_DIM)); + setHoverImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_RIGHT_MV)); + setEnabled(false); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartActionTop.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartActionTop.java new file mode 100644 index 0000000..d72e51e --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartActionTop.java @@ -0,0 +1,52 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.internal.GEFMessages; +import org.eclipse.ui.IWorkbenchPart; +import org.tizen.efluibuilder.ui.actions.ActionConstants; +import org.tizen.efluibuilder.ui.resources.ImageResources; + + +@SuppressWarnings("restriction") +public class AlignPartActionTop extends AlignPartAction { + public AlignPartActionTop(IWorkbenchPart part, EditPart rootEditPart) { + super(part, rootEditPart, AlignPartAction.TYPE_TOP); + } + + protected void init() { + super.init(); + + setText(GEFMessages.AlignTopAction_Label); + setToolTipText(GEFMessages.AlignTopAction_Tooltip); + // setImageDescriptor(InternalImages.DESC_VERT_ALIGN_TOP); + // setDisabledImageDescriptor(InternalImages.DESC_VERT_ALIGN_TOP_DIS); + setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_TOP_NOR)); + setDisabledImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_TOP_DIM)); + setHoverImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_TOP_MV)); + setId(ActionConstants.ALIGN_TOP); + setEnabled(false); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartActionVCenter.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartActionVCenter.java new file mode 100644 index 0000000..fe291a8 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartActionVCenter.java @@ -0,0 +1,52 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.internal.GEFMessages; +import org.eclipse.ui.IWorkbenchPart; +import org.tizen.efluibuilder.ui.actions.ActionConstants; +import org.tizen.efluibuilder.ui.resources.ImageResources; + + +@SuppressWarnings("restriction") +public class AlignPartActionVCenter extends AlignPartAction { + public AlignPartActionVCenter(IWorkbenchPart part, EditPart rootEditPart) { + super(part, rootEditPart, AlignPartAction.TYPE_VERTICAL_CENTER); + } + + protected void init() { + super.init(); + + setText(GEFMessages.AlignMiddleAction_Label); + setToolTipText(GEFMessages.AlignMiddleAction_Tooltip); + // setImageDescriptor(InternalImages.DESC_VERT_ALIGN_MIDDLE); + // setDisabledImageDescriptor(InternalImages.DESC_VERT_ALIGN_MIDDLE_DIS); + setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_MIDDLE_NOR)); + setDisabledImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_MIDDLE_DIM)); + setHoverImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_MIDDLE_MV)); + setId(ActionConstants.ALIGN_VERTICAL_CENTER); + setEnabled(false); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartActionVDistribute.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartActionVDistribute.java new file mode 100644 index 0000000..7d17e73 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartActionVDistribute.java @@ -0,0 +1,63 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import java.util.List; + +import org.eclipse.gef.EditPart; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PlatformUI; +import org.tizen.efluibuilder.gef.commands.CommandUtil; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.ui.actions.ActionConstants; + + +public class AlignPartActionVDistribute extends AlignPartAction { + public AlignPartActionVDistribute(IWorkbenchPart part, EditPart rootEditPart) { + super(part, rootEditPart, AlignPartAction.TYPE_DISTRIBUTE_VERTICAL_SPACING); + } + + protected boolean calculateEnabled() { + if (super.calculateEnabled()) { + List orderedParts = CommandUtil.getWidgetPartsFromSelectedObjects(getSelectedObjects()); + if (orderedParts.size() > 2) { + return true; + } + } + return false; + } + + protected void init() { + super.init(); + + ISharedImages images = PlatformUI.getWorkbench().getSharedImages(); + setText(Messages.ACTION_ALIGN_DISTRIBUTE_VERTICALLY); + setId(ActionConstants.ALIGN_DISTRIBUTE_VERTICAL_SPACING); + setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); + setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); + setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED)); + setEnabled(false); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartRetargetAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartRetargetAction.java new file mode 100644 index 0000000..b9869df --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/AlignPartRetargetAction.java @@ -0,0 +1,104 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import org.eclipse.gef.internal.GEFMessages; +import org.eclipse.ui.actions.LabelRetargetAction; +import org.tizen.efluibuilder.ui.actions.ActionConstants; +import org.tizen.efluibuilder.ui.resources.ImageResources; + + +@SuppressWarnings("restriction") +public class AlignPartRetargetAction extends LabelRetargetAction { + public AlignPartRetargetAction(String align) { + super(null, null); + if (align.equals(AlignPartAction.TYPE_LEFT)) { + setId(ActionConstants.ALIGN_LEFT); + setText(GEFMessages.AlignLeftAction_Label); + setToolTipText(GEFMessages.AlignLeftAction_Tooltip); + // setImageDescriptor(InternalImages.DESC_HORZ_ALIGN_LEFT); + // setDisabledImageDescriptor(InternalImages.DESC_HORZ_ALIGN_LEFT_DIS); + setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_LEFT_NOR)); + setDisabledImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_LEFT_DIM)); + setHoverImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_LEFT_MV)); + } else if (align.equals(AlignPartAction.TYPE_TOP)) { + setId(ActionConstants.ALIGN_TOP); + setText(GEFMessages.AlignTopAction_Label); + setToolTipText(GEFMessages.AlignTopAction_Tooltip); + // setImageDescriptor(InternalImages.DESC_VERT_ALIGN_TOP); + // setDisabledImageDescriptor(InternalImages.DESC_VERT_ALIGN_TOP_DIS); + setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_TOP_NOR)); + setDisabledImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_TOP_DIM)); + setHoverImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_TOP_MV)); + } else if (align.equals(AlignPartAction.TYPE_RIGHT)) { + setId(ActionConstants.ALIGN_RIGHT); + setText(GEFMessages.AlignRightAction_Label); + setToolTipText(GEFMessages.AlignRightAction_Tooltip); + // setImageDescriptor(InternalImages.DESC_HORZ_ALIGN_RIGHT); + // setDisabledImageDescriptor(InternalImages.DESC_HORZ_ALIGN_RIGHT_DIS); + setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_RIGHT_NOR)); + setDisabledImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_RIGHT_DIM)); + setHoverImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_RIGHT_MV)); + } else if (align.equals(AlignPartAction.TYPE_BOTTOM)) { + setId(ActionConstants.ALIGN_BOTTOM); + setText(GEFMessages.AlignBottomAction_Label); + setToolTipText(GEFMessages.AlignBottomAction_Tooltip); + // setImageDescriptor(InternalImages.DESC_VERT_ALIGN_BOTTOM); + // setDisabledImageDescriptor(InternalImages.DESC_VERT_ALIGN_BOTTOM_DIS); + setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_BOTTOM_NOR)); + setDisabledImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_BOTTOM_DIM)); + setHoverImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_BOTTOM_MV)); + } else if (align.equals(AlignPartAction.TYPE_HORIZONTAL_CENTER)) { + setId(ActionConstants.ALIGN_HORIZONTAL_CENTER); + setText(GEFMessages.AlignCenterAction_Label); + setToolTipText(GEFMessages.AlignCenterAction_Tooltip); + // setImageDescriptor(InternalImages.DESC_HORZ_ALIGN_CENTER); + // setDisabledImageDescriptor(InternalImages.DESC_HORZ_ALIGN_CENTER_DIS); + setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_CENTER_NOR)); + setDisabledImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_CENTER_DIM)); + setHoverImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_CENTER_MV)); + } else if (align.equals(AlignPartAction.TYPE_VERTICAL_CENTER)) { + setId(ActionConstants.ALIGN_VERTICAL_CENTER); + setText(GEFMessages.AlignMiddleAction_Label); + setToolTipText(GEFMessages.AlignMiddleAction_Tooltip); + // setImageDescriptor(InternalImages.DESC_VERT_ALIGN_MIDDLE); + // setDisabledImageDescriptor(InternalImages.DESC_VERT_ALIGN_MIDDLE_DIS); + setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_MIDDLE_NOR)); + setDisabledImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_MIDDLE_DIM)); + setHoverImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_MIDDLE_MV)); + } else if (align.equals(AlignPartAction.TYPE_DISTRIBUTE_HORIZONTAL_SPACING)) { + setId(ActionConstants.ALIGN_DISTRIBUTE_HORIZONTAL_SPACING); + // setText(GEFMessages.AlignMiddleAction_Label); + // setToolTipText(GEFMessages.AlignMiddleAction_Tooltip); + // setImageDescriptor(InternalImages.DESC_VERT_ALIGN_MIDDLE); + // setDisabledImageDescriptor(InternalImages.DESC_VERT_ALIGN_MIDDLE_DIS); + } else if (align.equals(AlignPartAction.TYPE_DISTRIBUTE_VERTICAL_SPACING)) { + setId(ActionConstants.ALIGN_DISTRIBUTE_VERTICAL_SPACING); + // setText(GEFMessages.AlignMiddleAction_Label); + // setToolTipText(GEFMessages.AlignMiddleAction_Tooltip); + // setImageDescriptor(InternalImages.DESC_VERT_ALIGN_MIDDLE); + // setDisabledImageDescriptor(InternalImages.DESC_VERT_ALIGN_MIDDLE_DIS); + } + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/ChangePartSelectionAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/ChangePartSelectionAction.java new file mode 100644 index 0000000..afe88cc --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/ChangePartSelectionAction.java @@ -0,0 +1,157 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import java.util.List; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.SelectionRequest; +import org.eclipse.gef.ui.actions.SelectionAction; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.actions.ActionFactory; +import org.tizen.efluibuilder.gef.commands.CommandUtil; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.ui.actions.ActionConstants; + + +public class ChangePartSelectionAction extends SelectionAction { + + protected EditPart rootEditPart; + private String type; + Request req = null; + + public final static String TYPE_PARENT = "parent"; + public final static String TYPE_CHILD = "child"; + public final static String TYPE_PREV_SIBLING = "prev_sibling"; + public final static String TYPE_NEXT_SIBLING = "next_sibling"; + + public ChangePartSelectionAction(IWorkbenchPart part, EditPart rootEditPart, String type) { + super(part); + this.type = type; + this.rootEditPart = rootEditPart; + req = null; + } + + protected boolean isSelectable(EditPart editpart) { + return true; + } + + protected Request getRequest() { + if (this.req == null) { + this.req = new SelectionRequest(); + } + return this.req; + } + + protected EditPart getSelectTarget() { + List editparts = CommandUtil.getEditPartsFromSelectedObjects(getSelectedObjects()); + List children; + List siblings; + Part part; + EditPart editpart, sibling, selectTarget = null, parentEditPart = null; + + if (editparts.size() == 1) { + editpart = editparts.get(0); + part = (Part) editpart.getModel(); + children = editpart.getChildren(); + parentEditPart = editpart.getParent(); + if (parentEditPart == null) { + return null; + } + siblings = editpart.getParent().getChildren(); + if (type.equals(ChangePartSelectionAction.TYPE_PARENT)) { + if ((part.getParent() != null) && (part.getParent() instanceof ComponentPart)) { + selectTarget = editpart.getParent(); + } + } else if (type.equals(ChangePartSelectionAction.TYPE_CHILD)) { + if (children.size() > 0) { + selectTarget = (EditPart) editpart.getChildren().get(0); + } + } else if (type.equals(ChangePartSelectionAction.TYPE_PREV_SIBLING)) { + if (siblings.size() > 1) { + for (int i = 0; i < siblings.size(); i++) { + sibling = siblings.get(i); + if (sibling.equals(editpart)) { + if (i == 0) { + selectTarget = siblings.get(siblings.size() - 1); + } else { + selectTarget = siblings.get(i - 1); + } + break; + } + } + } + } else if (type.equals(ChangePartSelectionAction.TYPE_NEXT_SIBLING)) { + if (siblings.size() > 1) { + for (int i = 0; i < siblings.size(); i++) { + sibling = siblings.get(i); + if (sibling.equals(editpart)) { + if (i == (siblings.size() - 1)) { + selectTarget = siblings.get(0); + } else { + selectTarget = siblings.get(i + 1); + } + break; + } + } + } + } + if (selectTarget != null) { + if (this.isSelectable(selectTarget)) { + return selectTarget; + } + } + + } + + return null; + } + + @Override + protected boolean calculateEnabled() { + if (this.getSelectTarget() != null) { + return true; + } + return false; + } + + @Override + public void run() { + EditPart selectEditPart = this.getSelectTarget(); + if (null != selectEditPart) { + rootEditPart.getViewer().select(selectEditPart); + } + } + + @Override + protected void init() { + super.init(); + setId(ActionConstants.CHANGE_SELECTION); + setId(ActionFactory.COPY.getId()); + setEnabled(false); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/CopyPartAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/CopyPartAction.java new file mode 100644 index 0000000..b543845 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/CopyPartAction.java @@ -0,0 +1,83 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import org.eclipse.gef.EditPart; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PlatformUI; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.ui.actions.ActionConstants; + + +/** + * An action to copy selected {@link Part}s. + */ +public class CopyPartAction extends CutPartAction { + + /** + * Creates a {@link CopyPartAction} and associates it with the given workbench part. + * + * @param part + * the workbench part + * @param rootEditPart + * a root {@link EditPart} + */ + public CopyPartAction(IWorkbenchPart part, EditPart rootEditPart, PartAction updateTarget) { + super(part, rootEditPart, updateTarget); + } + + /** + * Returns true if the selected objects can be copied. + * + * @return true if the command should be enabled, and false otherwise + */ + @Override + protected boolean calculateEnabled() { + return isCopyEnabled(); + } + + /** + * Initializes the copy action's text and images. + */ + @Override + protected void init() { + super.init(); + + ISharedImages images = PlatformUI.getWorkbench().getSharedImages(); + setText(Messages.getCopyShortCut()); + setId(ActionConstants.COPY_PART); + + setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); + setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); + setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED)); + setEnabled(false); + } + + @Override + public void run() { + setCopyDataToClipboard(); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/CutPartAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/CutPartAction.java new file mode 100644 index 0000000..a3a0130 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/CutPartAction.java @@ -0,0 +1,448 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.gef.commands.CompoundCommand; +import org.eclipse.gef.ui.actions.Clipboard; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PlatformUI; +import org.tizen.efluibuilder.gef.commands.CommandUtil; +import org.tizen.efluibuilder.gef.commands.ComponentCopyData; +import org.tizen.efluibuilder.gef.editparts.DesignEditPart; +import org.tizen.efluibuilder.gef.policies.containers.DesignEditorUtil; +import org.tizen.efluibuilder.gef.viewer.DesignStoryboardRouter; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.EventPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.ViewPart; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.actions.ActionConstants; + + +/** + * An action to copy selected {@link Part}s. + */ +public class CutPartAction extends PartAction { + + static class PartSet { + List viewParts; + List componentParts; + List eventParts; + + public PartSet(List viewParts, List componentParts, List eventParts) { + this.viewParts = viewParts; + this.componentParts = componentParts; + this.eventParts = eventParts; + } + } + + protected PartAction updateTarget = null; + + /** + * Creates a {@link CutPartAction} and associates it with the given workbench part. + * + * @param part + * the workbench part + * @param rootEditPart + * a root {@link EditPart} + */ + private List copyData = null; + + public CutPartAction(IWorkbenchPart part, EditPart rootEditPart, PartAction updateTarget) { + super(part, rootEditPart); + this.updateTarget = updateTarget; + } + + private boolean isStartUpView(Part part) { + if (part instanceof ViewPart) { + String startupStr = part.getParent().getPropertyValue(LayoutSchemaConstants.STARTUP); + if ((startupStr != null) && startupStr.equals(part.getPropertyValue(LayoutSchemaConstants.ID))) { + return true; + } + } + return false; + } + + private Command getComponentsRemoveCommand(List selectedParts) { + CompoundCommand compCmd = new CompoundCommand(); + for (int i = 0; i < selectedParts.size(); i++) { + compCmd.add(PartUtil.createRemovePartCommand(selectedParts.get(i).getParent(), selectedParts.get(i))); + } + return compCmd; + } + + private HashMap getTargetConnectionMapFromViews(List selectedParts) { + HashMap eventMap = new HashMap(); + DesignStoryboardRouter router = ((DesignViewer) this.rootEditPart.getViewer()).getStoryBoardRouter(); + for (Part targetPart : selectedParts) { + List targetEvents = router.getTargetConnectionPartFromView(targetPart); + for (Part eventPart : targetEvents) { + eventMap.put(eventPart.getUniqueId(), eventPart); + } + } + + return eventMap; + } + + private Command getViewsRemoveCommnad(List selectedParts) { + CompoundCommand compCmd = new CompoundCommand(); + Part targetPart; + // for (int i = 0; i < selectedParts.size(); i++) { //remove event + // targetPart = selectedParts.get(i); + // List targetEvents = + // ((DesignViewer)this.rootEditPart.getViewer()).getStoryBoardRouter().getTargetConnectionPartFromView(targetPart); + // for (Part eventPart : targetEvents) { + // compCmd.add(PartUtil.createRemovePartCommand(eventPart.getParent(), eventPart)); + // } + // } + + for (int i = 0; i < selectedParts.size(); i++) { // remove view + targetPart = selectedParts.get(i); + // List targetEvents = + // ((DesignViewer)this.rootEditPart.getViewer()).getStoryBoardRouter().getTargetConnectionPartFromView(targetPart); + // for (Part eventPart : targetEvents) { + // compCmd.add(PartUtil.createRemovePartCommand(eventPart.getParent(), eventPart)); + // } + compCmd.add(PartUtil.createRemovePartCommand(targetPart.getParent(), targetPart)); + if (isStartUpView(targetPart)) { + for (Part part : getUnselectedSiblings(selectedParts)) { + if (part.getPropertyValue(LayoutSchemaConstants.TYPE).equals(LayoutSchemaConstants.VIEW)) { + compCmd.add(PartUtil.createSetPropertyCommand(targetPart.getParent(), LayoutSchemaConstants.STARTUP, + part.getPropertyValue(LayoutSchemaConstants.ID))); + break; + } + } + } + } + return compCmd; + } + + private boolean hasMainView(List parts) { + for (Part part : parts) { + if (part.getPropertyValue(LayoutSchemaConstants.TYPE) != null + && part.getPropertyValue(LayoutSchemaConstants.TYPE).equals(LayoutSchemaConstants.VIEW)) { + return true; + } + } + return false; + } + + private List getUnselectedSiblings(List siblings) { + List unselectedParts = new ArrayList(); + for (Part part : siblings.get(0).getParent().getComponentChildren()) + if (siblings.contains(part) == false) { + unselectedParts.add(part); + } + return unselectedParts; + } + + protected List getViewPartsFromParts(List parts) { + List viewParts = new ArrayList(); + for (Part part : parts) { + if (part instanceof ViewPart) { + viewParts.add(part); + } + } + return viewParts; + } + + protected List getEventPartsFromParts(List parts) { + List eventParts = new ArrayList(); + for (Part part : parts) { + if (part instanceof EventPart) { + eventParts.add(part); + } + } + return eventParts; + } + + protected Command getDeleteCommand() { + PartSet deletePartSet = getDeleteTargetPartSet(); + + CompoundCommand compCmd = null; + + if (deletePartSet.eventParts.isEmpty() == false) { // remove event + compCmd = (CompoundCommand) getComponentsRemoveCommand(deletePartSet.eventParts); + } + + if (deletePartSet.componentParts.isEmpty() == false) { // remove component + if (compCmd == null) { + compCmd = (CompoundCommand) getComponentsRemoveCommand(deletePartSet.componentParts); + } else { + compCmd.add(getComponentsRemoveCommand(deletePartSet.componentParts)); + } + } + + if (deletePartSet.viewParts.isEmpty() == false) { // remove view + if (compCmd == null) { + compCmd = (CompoundCommand) getViewsRemoveCommnad(deletePartSet.viewParts); + } else { + compCmd.add(getViewsRemoveCommnad(deletePartSet.viewParts)); + } + } + + return compCmd; + } + + protected boolean isCopyEnabled() { + List partList = CommandUtil.getWidgetPartsFromSelectedObjects(getSelectedObjects()); + if (partList == null || partList.isEmpty() || (isSameParent(partList) != true) || (hasEventPart(partList)) == true) { + return false; + } + + this.copyData = getCopyData(partList); + if (this.copyData != null) { + return true; + } + return false; + } + + private boolean isChildOfPart(Part parentPart, Part childPart) { + Part parent = childPart; + while (parent instanceof ComponentPart) { + if (parent == parentPart) { + return true; + } + parent = parent.getParent(); + } + return false; + } + + protected List getDeleteTargetPartsWithoutDependancy(ArrayList targets) { + List deleteTargets = new ArrayList(); + return deleteTargets; + + } + + protected PartSet getDeleteTargetPartSet() { + List danglingParts = new ArrayList(); + List selectedParts = CommandUtil.getWidgetPartsFromSelectedObjects(getSelectedObjects()); + + List viewParts = new ArrayList(); + List componentParts = new ArrayList(); + List eventParts = new ArrayList(); + + for (Part part : selectedParts) { + if (part instanceof ViewPart) { + viewParts.add(part); + } else if (part instanceof EventPart) { + eventParts.add(part); + } else { + componentParts.add(part); + } + } + + HashMap targetConnectionMap = getTargetConnectionMapFromViews(viewParts); + for (Part event : eventParts) { + targetConnectionMap.put(event.getUniqueId(), event); + } + eventParts.clear(); + for (Part event : targetConnectionMap.values()) { + eventParts.add(event); + } + + for (Part view : viewParts) { // remove dangling component + for (Part component : componentParts) { + if (isChildOfPart(view, component)) { + danglingParts.add(component); + } + } + } + componentParts.removeAll(danglingParts); + + danglingParts.clear(); + for (Part view : viewParts) { // remove dangling event + for (Part event : eventParts) { + if (isChildOfPart(view, event)) { + danglingParts.add(event); + } + } + } + + for (Part component : componentParts) { // remove dangling event + for (Part event : eventParts) { + if (isChildOfPart(component, event)) { + danglingParts.add(event); + } + } + } + eventParts.removeAll(danglingParts); + + return new PartSet(viewParts, componentParts, eventParts); + } + + protected boolean isDeleteEnabled() { + PartSet deletePartSet = getDeleteTargetPartSet(); + if (deletePartSet.viewParts.isEmpty() == false || + deletePartSet.componentParts.isEmpty() == false || + deletePartSet.eventParts.isEmpty() == false) { + if (deletePartSet.viewParts.isEmpty() == false) { // remove views + List unselectedParts = getUnselectedSiblings(deletePartSet.viewParts); + if (hasMainView(unselectedParts) == false) { + return false; + } + } + return true; + } + return false; + } + + protected List getCopyData(List partList) { + Part part, parentPart, clonedPart, ownerViewPart, clonedParentPart = null; + Rectangle partBound, parentBound; + ComponentCopyData copyData; + List copyDataList = new ArrayList(); + + EditPart parentEditPart = null; + EditPart editPart = null; + DesignEditPart viewEditPart = null; + Rectangle absoluteBound = null; + Rectangle relativeBound = null; + Rectangle viewBound = null; + String layoutType = null; + + for (int i = 0; i < partList.size(); i++) { + part = partList.get(i); + parentPart = part.getParent(); + + if (part instanceof ViewPart) { + parentPart = null; + parentEditPart = null; + partBound = null; + parentBound = null; + absoluteBound = null; + relativeBound = null; + clonedParentPart = null; + layoutType = ""; + } else + // if (part instanceof ComponentPart) + { + editPart = DesignEditorUtil.getEditPart(rootEditPart, part); + if (editPart == null) { + continue; + } + ownerViewPart = ((ComponentPart) part).getOwnerViewPart(); + parentEditPart = DesignEditorUtil.getEditPart(rootEditPart, part.getParent()); + viewEditPart = (DesignEditPart) DesignEditorUtil.getEditPart(rootEditPart, ownerViewPart); + if (parentEditPart != null && viewEditPart != null) { + viewBound = viewEditPart.getPosition().getBounds(); + partBound = ((DesignEditPart) editPart).getPosition().getBounds(); + parentBound = ((DesignEditPart) parentEditPart).getPosition().getBounds().getCopy(); + absoluteBound = new Rectangle(); + relativeBound = new Rectangle(); + absoluteBound.setBounds(partBound); + relativeBound.setBounds(partBound); + absoluteBound.x -= viewBound.x; + absoluteBound.y -= (viewBound.y + DesignEditorUtil.VIEW_TITLEBAR_HEIGHT); + relativeBound.x -= parentBound.x; + relativeBound.y -= parentBound.y; + if (parentPart instanceof ViewPart == false) { + parentBound.x -= viewBound.x; + parentBound.y -= (viewBound.y + DesignEditorUtil.VIEW_TITLEBAR_HEIGHT); + } + ComponentDescriptor componentDescriptor = part.getOwnerDocumentPart().getComponentDescriptor(); + layoutType = componentDescriptor.getLayoutType((ComponentPart) parentPart); + clonedParentPart = PartUtil.clone(parentPart); + } + + } + String configuration = null; + if (this.rootEditPart.getViewer() instanceof DesignViewer) { + DesignViewer designViewer = (DesignViewer) this.rootEditPart.getViewer(); + if (designViewer.getMScreenQualifierManager().getCurrentConfigurePart() != null) { + configuration = designViewer.getMScreenQualifierManager().getCurrentConfigurePart().getPropertyValue(LayoutSchemaConstants.ID); + } + } + clonedPart = PartUtil.clone(part, true, configuration, true); + copyData = new ComponentCopyData(clonedPart, absoluteBound, relativeBound, layoutType, clonedParentPart); + copyDataList.add(copyData); + } + return copyDataList; + // Sets a content of clip board. + + } + + /** + * Returns true if the selected objects can be copied. + * + * @return true if the command should be enabled, and false otherwise + */ + @Override + protected boolean calculateEnabled() { + if (isCopyEnabled() && isDeleteEnabled()) { + return true; + } + return false; + } + + /** + * Initializes the copy action's text and images. + */ + @Override + protected void init() { + ISharedImages images = PlatformUI.getWorkbench().getSharedImages(); + setText(Messages.getCutShortCut()); + setId(ActionConstants.CUT_PART); + setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_CUT)); + setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_CUT)); + setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_CUT_DISABLED)); + setEnabled(false); + } + + protected void setCopyDataToClipboard() { + if (copyData.size() > 0) { + Clipboard.getDefault().setContents(copyData); + if (updateTarget != null) { + updateTarget.updateEnabled(); + } + } + } + + /** + * Performs the copy action on the selected objects. + */ + @Override + public void run() { + setCopyDataToClipboard(); + Command command = this.getDeleteCommand(); + if (command != null) { + super.run(); + CommandStack cmdStack = rootEditPart.getViewer().getEditDomain().getCommandStack(); + cmdStack.execute(command); + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/DeletePartAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/DeletePartAction.java new file mode 100644 index 0000000..b1af2bb --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/DeletePartAction.java @@ -0,0 +1,90 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PlatformUI; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.ui.actions.ActionConstants; + + +/** + * An action to delete selected {@link Part}s. + */ +public class DeletePartAction extends CutPartAction { + + /** + * Creates a {@link DeletePartAction} and associates it with the given workbench part. + * + * @param part + * the workbench part + */ + public DeletePartAction(IWorkbenchPart part, EditPart rootEditPart) { + super(part, rootEditPart, null); + setLazyEnablementCalculation(false); + } + + /** + * Returns true if the selected objects can be deleted. + * + * @return true if the command should be enabled, and false otherwise + */ + @Override + protected boolean calculateEnabled() { + return isDeleteEnabled(); + } + + /** + * Initializes the delete action's text and images. + */ + @Override + protected void init() { + super.init(); + + ISharedImages images = PlatformUI.getWorkbench().getSharedImages(); + setText(Messages.ACTION_DELETE); + setId(ActionConstants.DELETE_PART); + setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE)); + setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE)); + setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED)); + setEnabled(false); + } + + /** + * Performs the delete action on the selected objects. + */ + @Override + public void run() { + Command command = this.getDeleteCommand(); + CommandStack cmdStack = rootEditPart.getViewer().getEditDomain().getCommandStack(); + if (command != null && command.canExecute() && (cmdStack != null)) { + cmdStack.execute(command); + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/MatchSizeAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/MatchSizeAction.java new file mode 100644 index 0000000..7bbe630 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/MatchSizeAction.java @@ -0,0 +1,141 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import java.util.List; + +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.gef.commands.CompoundCommand; +import org.eclipse.gef.internal.GEFMessages; +import org.eclipse.ui.IWorkbenchPart; +import org.tizen.efluibuilder.gef.commands.CommandUtil; +import org.tizen.efluibuilder.gef.policies.containers.DesignEditorUtil; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.actions.ActionConstants; +import org.tizen.efluibuilder.ui.resources.ImageResources; + + +@SuppressWarnings("restriction") +public class MatchSizeAction extends PartAction { + + public final static String TYPE_WIDTH = "width"; + public final static String TYPE_HEIGHT = "height"; + String type = ""; + + public MatchSizeAction(IWorkbenchPart part, EditPart rootEditPart, String type) { + super(part, rootEditPart); + this.type = type; + this.initUi(); + } + + @Override + protected boolean calculateEnabled() { + List orderedParts = CommandUtil.getWidgetPartsFromSelectedObjects(getSelectedObjects()); + if (orderedParts.size() > 1 && DesignEditorUtil.isSameParent(orderedParts) + && orderedParts.get(0).getParent().getDescriptorId().equals(LayoutSchemaConstants.GRID)) { + return true; + } + return false; + } + + private void initUi() { + if (this.type.equals(MatchSizeAction.TYPE_WIDTH)) { + setId(ActionConstants.MATCH_WIDTH); + setText(GEFMessages.MatchWidthAction_Label); + // setImageDescriptor(InternalImages.DESC_MATCH_WIDTH); + // setDisabledImageDescriptor(InternalImages.DESC_MATCH_WIDTH_DIS); + setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_WIDTH_NOR)); + setDisabledImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_WIDTH_DIM)); + setHoverImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_WIDTH_MV)); + setToolTipText(Messages.ACTION_MATCH_WIDTH); + } else if (this.type.equals(MatchSizeAction.TYPE_HEIGHT)) { + // setText(Messages.ACTION_MATCH_HEIGHT); + setId(ActionConstants.MATCH_HEIGHT); + setText(GEFMessages.MatchHeightAction_Label); + // setImageDescriptor(InternalImages.DESC_MATCH_HEIGHT); + // setDisabledImageDescriptor(InternalImages.DESC_MATCH_HEIGHT_DIS); + setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_HEIGHT_NOR)); + setDisabledImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_HEIGHT_DIM)); + setHoverImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_HEIGHT_MV)); + setToolTipText(Messages.ACTION_MATCH_HEIGHT); + } + } + + @Override + protected void init() { + super.init(); + + setEnabled(false); + } + + protected Command getCommand(List selectedParts) { + if (selectedParts == null) { + throw new IllegalArgumentException(); + } + if (selectedParts.isEmpty()) { + return null; + } + + CompoundCommand command = new CompoundCommand(); + Part part = selectedParts.get(0); + if (!(part instanceof ComponentPart)) { + return command; + } + + ComponentPart componentPart = (ComponentPart) part; + Rectangle primarySelectionBound = DesignEditorUtil.getPackBound(componentPart, getCurrentConfigurationID()); + for (int i = 1; i < selectedParts.size(); i++) { + part = selectedParts.get(i); + if (!(part instanceof ComponentPart)) { + continue; + } + componentPart = (ComponentPart) part; + Rectangle partPackBound = DesignEditorUtil.getPackBound(componentPart, getCurrentConfigurationID()); + if (type.equals(MatchSizeAction.TYPE_WIDTH)) { + partPackBound.width = primarySelectionBound.width; + } else if (this.type.equals(MatchSizeAction.TYPE_HEIGHT)) { + partPackBound.height = primarySelectionBound.height; + } + command.add(PartUtil.createPackCommand(part, null, partPackBound)); + } + return command; + } + + @Override + public void run() { + List orderedParts = CommandUtil.getWidgetPartsFromSelectedObjects(getSelectedObjects()); + Command command = getCommand(orderedParts); + CommandStack cmdStack = rootEditPart.getViewer().getEditDomain().getCommandStack(); + if (command != null && command.canExecute() && (cmdStack != null)) { + cmdStack.execute(command); + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/Messages.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/Messages.java new file mode 100644 index 0000000..31e1b7f --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/Messages.java @@ -0,0 +1,112 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import org.eclipse.osgi.util.NLS; +import org.tizen.efluibuilder.utility.PlatformUtil; + + +public class Messages extends NLS { + + private static final String BUNDLE_NAME = Messages.class.getName(); + + public static String ACTION_COPY; + public static String ACTION_CUT; + public static String ACTION_PASTE; + public static String ACTION_DELETE; + public static String ACTION_MOVE_LEFT; + public static String ACTION_MOVE_RIGHT; + public static String ACTION_MOVE_UP; + public static String ACTION_MOVE_DOWN; + public static String ACTION_MOVE_LEFT_DETAIL; + public static String ACTION_MOVE_RIGHT_DETAIL; + public static String ACTION_MOVE_UP_DETAIL; + public static String ACTION_MOVE_DOWN_DETAIL; + public static String ACTION_INC_WIDTH; + public static String ACTION_DEC_WIDTH; + public static String ACTION_INC_HEIGHT; + public static String ACTION_DEC_HEIGHT; + public static String ACTION_INC_WIDTH_DETAIL; + public static String ACTION_DEC_WIDTH_DETAIL; + public static String ACTION_INC_HEIGHT_DETAIL; + public static String ACTION_DEC_HEIGHT_DETAIL; + public static String ACTION_SET_STARTUP_PAGE; + public static String ACTION_SHOW_INSPECTOR; + public static String ACTION_PASTE_COLOR; + public static String ACTION_COPY_MAC; + public static String ACTION_CUT_MAC; + public static String ACTION_PASTE_MAC; + + public static String ACTION_ALIGN_LEFT; + public static String ACTION_ALIGN_TOP; + public static String ACTION_ALIGN_RIGHT; + public static String ACTION_ALIGN_BOTTOM; + public static String ACTION_ALIGN_HORIZONTAL_CENTER; + public static String ACTION_ALIGN_VERTICAL_CENTER; + public static String ACTION_ALIGN_DISTRIBUTE_HORIZONTALLY; + public static String ACTION_ALIGN_DISTRIBUTE_VERTICALLY; + + public static String ACTION_SELECT_PARENT; + public static String ACTION_SELECT_CHILD; + public static String ACTION_SELECT_PREV_SIBLING; + public static String ACTION_SELECT_NEXT_SIBLING; + + public static String ACTION_MATCH_WIDTH; + public static String ACTION_MATCH_HEIGHT; + + public static String ACTION_ZORDER_FRONT; + public static String ACTION_ZORDER_BACK; + public static String ACTION_ZORDER_FRONTWARD; + public static String ACTION_ZORDER_BACKWARD; + + public static String ACTION_ALIGN_STORYBOARD; + + static { + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } + + public static String getCopyShortCut() { + if (PlatformUtil.getOS().equals(PlatformUtil.OS_MACOSX)) { + return ACTION_COPY_MAC; + } + return ACTION_COPY; + } + + public static String getCutShortCut() { + if (PlatformUtil.getOS().equals(PlatformUtil.OS_MACOSX)) { + return ACTION_CUT_MAC; + } + return ACTION_CUT; + } + + public static String getPasteShortCut() { + if (PlatformUtil.getOS().equals(PlatformUtil.OS_MACOSX)) { + return ACTION_PASTE_MAC; + } + return ACTION_PASTE; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/Messages.properties b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/Messages.properties new file mode 100644 index 0000000..bdac135 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/Messages.properties @@ -0,0 +1,49 @@ +ACTION_COPY=&Copy\tCtrl+C +ACTION_CUT=Cut\tCtrl+X +ACTION_PASTE=&Paste\tCtrl+V +ACTION_DELETE=&Delete\tDelete +ACTION_ALIGN_LEFT=Left\tCtrl+Left +ACTION_ALIGN_TOP=Top\tCtrl+Up +ACTION_ALIGN_RIGHT=Right\tCtrl+Right +ACTION_ALIGN_BOTTOM=Bottom\tCtrl+Down +ACTION_ALIGN_HORIZONTAL_CENTER=Horizontal Center\tAlt+Shift+Left +ACTION_ALIGN_VERTICAL_CENTER=Vertical Center\tAlt+Shift+Right +ACTION_ALIGN_DISTRIBUTE_HORIZONTALLY=Distribute Horizontally\tAlt+Shift+Up +ACTION_ALIGN_DISTRIBUTE_VERTICALLY=Distribute Vertically\tAlt+Shift+Down +ACTION_MATCH_WIDTH=Match Width +ACTION_MATCH_HEIGHT=Match Height +ACTION_SELECT_PARENT=Parent\tShift+Up +ACTION_SELECT_CHILD=Child\tShift+Down +ACTION_SELECT_PREV_SIBLING=Previous Sibling\tShift+Left +ACTION_SELECT_NEXT_SIBLING=Next Sibling\tShift+Right +ACTION_MOVE_LEFT=MoveLeft\tLeft +ACTION_MOVE_RIGHT=MoveRight\tRight +ACTION_MOVE_UP=MoveUp\tUp +ACTION_MOVE_DOWN=MoveDown\tDown +ACTION_MOVE_LEFT_DETAIL=MoveLeftDetail\tCtrl+Left +ACTION_MOVE_RIGHT_DETAIL=MoveRightDetail\tCtrl+Right +ACTION_MOVE_UP_DETAIL=MoveUpDetail\tCtrl+Up +ACTION_MOVE_DOWN_DETAIL=MoveDownDetail\tCtrl+Down +ACTION_INC_WIDTH=IncWidth\tShift+Right +ACTION_DEC_WIDTH=DecWidth\tShift+Left +ACTION_INC_HEIGHT=IncHeight\tShift+Down +ACTION_DEC_HEIGHT=DecHeight\tShift+Up +ACTION_INC_WIDTH_DETAIL=IncWidthDetail\tCtrl+Shift+Right +ACTION_DEC_WIDTH_DETAIL=DecWidthDetail\tCtrl+Shift+Left +ACTION_INC_HEIGHT_DETAIL=IncHeightDetail\tCtrl+Shift+Down +ACTION_DEC_HEIGHT_DETAIL=DecHeightDetail\tCtrl+Shift+Up +ACTION_SET_STARTUP_PAGE=Set Startup View +ACTION_SHOW_INSPECTOR=ShowInspector\tCtrl+Shift+Alt+I +ACTION_PASTE_COLOR=PasteColor + +ACTION_COPY_MAC=&Copy\tCmd+C +ACTION_CUT_MAC=Cut\tCmd+X +ACTION_PASTE_MAC=&Paste\tCmd+V + +ACTION_ZORDER_FRONT=Bring to Front +ACTION_ZORDER_BACK=Send to Back +ACTION_ZORDER_FRONTWARD=Bring Forward\tCtrl+Shift+F +ACTION_ZORDER_BACKWARD=Send Backward\tCtrl+Shift+B + +ACTION_ALIGN_STORYBOARD=Align Storyboard + diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/MoveAbsolutePartAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/MoveAbsolutePartAction.java new file mode 100644 index 0000000..508a457 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/MoveAbsolutePartAction.java @@ -0,0 +1,251 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import java.util.List; + +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.gef.commands.CompoundCommand; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PlatformUI; +import org.tizen.efluibuilder.gef.commands.CommandUtil; +import org.tizen.efluibuilder.gef.policies.containers.DesignEditorUtil; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.ModelConstants; +import org.tizen.efluibuilder.model.util.PartUtil; + + +public class MoveAbsolutePartAction extends PartAction { + + public static int MOVE_DIST = 5; + public static int MOVE_DIST_DETAIL = 1; + + private int direction = 0; + private int dist = 0; + private boolean overflow = false; + private boolean pixelBase = false; + + public MoveAbsolutePartAction(IWorkbenchPart part, int direct, int dist, EditPart rootEditPart, boolean overflow, boolean pixelBase) { + super(part, rootEditPart); + this.direction = direct; + this.dist = dist; + this.overflow = overflow; + this.pixelBase = pixelBase; + setLazyEnablementCalculation(false); + initUi(); + } + + @Override + protected boolean calculateEnabled() { + List partList = CommandUtil.getWidgetPartsFromSelectedObjects(getSelectedObjects()); + if ((partList.size() > 0) && DesignEditorUtil.isSameParent(partList) && (partList.get(0).getParent() != null) + && partList.get(0).getParent().getDescriptorId().equals(LayoutSchemaConstants.GRID)) { + return true; + } + return false; + } + + private void initUi() { + switch (direction) { + case PositionConstants.LEFT: + if (dist == MOVE_DIST) { + setId(Messages.ACTION_MOVE_LEFT); + } else if (dist == 1) { + setId(Messages.ACTION_MOVE_LEFT_DETAIL); + } + break; + case PositionConstants.RIGHT: + if (dist == MOVE_DIST) { + setId(Messages.ACTION_MOVE_RIGHT); + } else if (dist == 1) { + setId(Messages.ACTION_MOVE_RIGHT_DETAIL); + } + break; + case PositionConstants.TOP: + if (dist == MOVE_DIST) { + setId(Messages.ACTION_MOVE_UP); + } else if (dist == 1) { + setId(Messages.ACTION_MOVE_UP_DETAIL); + } + break; + case PositionConstants.BOTTOM: + if (dist == MOVE_DIST) { + setId(Messages.ACTION_MOVE_DOWN); + } else if (dist == 1) { + setId(Messages.ACTION_MOVE_DOWN_DETAIL); + } + break; + } + } + + @Override + protected void init() { + super.init(); + + ISharedImages images = PlatformUI.getWorkbench().getSharedImages(); + switch (direction) { + case PositionConstants.LEFT: + setText(Messages.ACTION_MOVE_LEFT + " (" + dist + ")"); + break; + case PositionConstants.RIGHT: + setText(Messages.ACTION_MOVE_RIGHT + " (" + dist + ")"); + break; + case PositionConstants.TOP: + setText(Messages.ACTION_MOVE_UP + " (" + dist + ")"); + break; + case PositionConstants.BOTTOM: + setText(Messages.ACTION_MOVE_DOWN + " (" + dist + ")"); + break; + } + setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE)); + setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE)); + setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED)); + setEnabled(false); + } + + protected Command getCommand() { + List partList = CommandUtil.getWidgetPartsFromSelectedObjects(getSelectedObjects()); + Part parent = partList.get(0).getParent(); + EditPart parentEditPart = DesignEditorUtil.getEditPart(rootEditPart, parent); + + Rectangle newOuterBound = new Rectangle(); + Rectangle parentBound = null; + + if (this.pixelBase == true) { + parentBound = DesignEditorUtil.getPartRelatvieBound(parentEditPart); + parentBound.x = parentBound.y = 0; + } else { + parentBound = new Rectangle(0, 0, Integer.parseInt(parent.getPropertyValue(ModelConstants.PROPERTY_VSIZE_W)), + Integer.parseInt(parent.getPropertyValue(ModelConstants.PROPERTY_VSIZE_H))); + } + + // FIXME : this logic is temporary + Rectangle outerBound = null; + for (int i = 0; i < partList.size(); i++) { + Part part = partList.get(i); + if (!(part instanceof ComponentPart)) { + continue; + } + ComponentPart componentPart = (ComponentPart) part; + EditPart editPart = parentEditPart != null ? DesignEditorUtil.getEditPart(parentEditPart, part) : null; + Rectangle bound = null; + if (this.pixelBase) { + bound = DesignEditorUtil.getPartRelatvieBound(editPart); + } else { + bound = DesignEditorUtil.getPackBound(componentPart, getCurrentConfigurationID()); + } + + if (i == 0) { + outerBound = bound; + } else { + if (outerBound == null) { + break; + } + outerBound = outerBound.union(bound); + } + } + + // TODO : temporary implementation + if (outerBound == null) { + return null; + } + + newOuterBound.setBounds(outerBound); + if (this.overflow == false) { + if (parentBound.contains(outerBound) == false) { + return null; + } + } + + switch (direction) { + case PositionConstants.LEFT: + newOuterBound.x -= dist; + if ((this.overflow == false) && (newOuterBound.x < 0)) { + newOuterBound.x = 0; + } + break; + case PositionConstants.RIGHT: + newOuterBound.x += dist; + if ((this.overflow == false) && ((newOuterBound.x + newOuterBound.width) > parentBound.width)) { + newOuterBound.x = parentBound.width - newOuterBound.width; + } + break; + case PositionConstants.TOP: + newOuterBound.y -= dist; + if ((this.overflow == false) && (newOuterBound.y < 0)) { + newOuterBound.y = 0; + } + break; + case PositionConstants.BOTTOM: + newOuterBound.y += dist; + if ((this.overflow == false) && ((newOuterBound.y + newOuterBound.height) > parentBound.height)) { + newOuterBound.y = parentBound.height - newOuterBound.height; + } + break; + } + + CompoundCommand compCmd = new CompoundCommand(); + for (int i = 0; i < partList.size(); i++) { + Part part = partList.get(i); + if (!(part instanceof ComponentPart)) { + continue; + } + ComponentPart componentPart = (ComponentPart) part; + EditPart editPart = parentEditPart != null ? DesignEditorUtil.getEditPart(parentEditPart, part) : null; + Rectangle bound = null; + if (this.pixelBase) { + bound = DesignEditorUtil.getPartRelatvieBound(editPart); + } else { + bound = DesignEditorUtil.getPackBound(componentPart, getCurrentConfigurationID()); + } + + bound.x += (newOuterBound.x - outerBound.x); + bound.y += (newOuterBound.y - outerBound.y); + + if (this.pixelBase) { + bound = DesignEditorUtil.pixelBoundToGridBound(parentEditPart, bound); + } + + compCmd.add(PartUtil.createPackCommand(part, null, bound)); + } + + return compCmd; + } + + @Override + public void run() { + Command command = getCommand(); + CommandStack cmdStack = rootEditPart.getViewer().getEditDomain().getCommandStack(); + if (command != null && command.canExecute() && (cmdStack != null)) { + cmdStack.execute(command); + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/PartAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/PartAction.java new file mode 100644 index 0000000..5a567a3 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/PartAction.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.gef.actions; + +import java.util.List; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.ui.actions.SelectionAction; +import org.eclipse.ui.IWorkbenchPart; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.part.ConfigurationPart; +import org.tizen.efluibuilder.model.part.EventPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.mscreen.configurator.MScreenQualifierManager; + + +public abstract class PartAction extends SelectionAction { + + protected EditPart rootEditPart; + + public PartAction(IWorkbenchPart part, EditPart rootEditPart) { + super(part); + this.rootEditPart = rootEditPart; + } + + protected boolean isSameParent(List partList) { + if (partList.size() > 1) { + Part previousParent = partList.get(0).getParent(); + for (int i = 1; i < partList.size(); i++) { + if (previousParent != partList.get(i).getParent()) { + return false; + } + } + + } + return true; + } + + protected boolean hasEventPart(List partList) { + for(Part part : partList) { + if (part instanceof EventPart) { + return true; + } + } + return false; + } + + protected ConfigurationPart getCurrentConfiguration() { + DesignViewer viewer = (DesignViewer) rootEditPart.getViewer(); + if (viewer == null) { + return null; + } + return viewer.getMScreenQualifierManager().getCurrentConfigurePart(); + } + + protected MScreenQualifierManager getMScreenQualifierManager() { + DesignViewer viewer = (DesignViewer) rootEditPart.getViewer(); + if (viewer == null) { + return null; + } + return viewer.getMScreenQualifierManager(); + } + + protected String getCurrentConfigurationID() { + ConfigurationPart configPart = getCurrentConfiguration(); + if (configPart == null) { + return null; + } + return configPart.getPropertyValue(LayoutSchemaConstants.ID); + } + + public void updateEnabled() { + setEnabled(calculateEnabled()); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/PartBoundSet.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/PartBoundSet.java new file mode 100644 index 0000000..d6c1ac2 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/PartBoundSet.java @@ -0,0 +1,45 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import org.eclipse.draw2d.geometry.Rectangle; +import org.tizen.efluibuilder.model.part.Part; + + +public class PartBoundSet implements Cloneable { + public Part part; + public Rectangle bound; + + public PartBoundSet(Part part, Rectangle bound) { + this.part = part; + this.bound = bound; + } + + public Object clone() throws CloneNotSupportedException { + PartBoundSet obj = (PartBoundSet) super.clone(); + obj.part = part; + obj.bound = new Rectangle(this.bound); + return obj; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/PastePartAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/PastePartAction.java new file mode 100644 index 0000000..6789af3 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/PastePartAction.java @@ -0,0 +1,409 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.gef.commands.CompoundCommand; +import org.eclipse.gef.ui.actions.Clipboard; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PlatformUI; +import org.tizen.efluibuilder.gef.commands.CommandUtil; +import org.tizen.efluibuilder.gef.commands.ComponentCopyData; +import org.tizen.efluibuilder.gef.policies.containers.DesignEditorUtil; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.DocumentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.ViewPart; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.actions.ActionConstants; + + +/** + * An action to paste {@link Part}s. + */ +public class PastePartAction extends PartAction { + + /** + * A root {@link EditPart}. + */ + static final int BASE_PASTE_MARGIN = 30; + static final int BASE_PASTE_POX_X = 0; + static final int BASE_PASTE_POX_Y = 0; + Part pasteTarget = null; + + /** + * Creates a {@link PastePartAction} and associates it with the given workbench part. + * + * @param part + * the workbench part + * @param rootEditPart + * a root {@link EditPart} + */ + public PastePartAction(IWorkbenchPart part, EditPart rootEditPart) { + super(part, rootEditPart); + setLazyEnablementCalculation(true); + } + + /** + * Returns true if the selected objects can be pasted. + * + * @return true if the command should be enabled, and false otherwise + */ + @Override + protected boolean calculateEnabled() { + pasteTarget = getPasteTarget(); + if (pasteTarget != null) { + return true; + } + return false; + } + + @Override + protected void init() { + super.init(); + + ISharedImages images = PlatformUI.getWorkbench().getSharedImages(); + setText(Messages.getPasteShortCut()); + setId(ActionConstants.PASTE_PART); + setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE)); + setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE)); + setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED)); + setEnabled(false); + } + + /** + * Performs the paste action. + */ + @Override + public void run() { + Command command = getCommand(); + if (command != null) { + CommandStack cmdStack = rootEditPart.getViewer().getEditDomain().getCommandStack(); + cmdStack.execute(command); + } + } + + @SuppressWarnings("unchecked") + private List getCopiedDataList() { + Object clipboardContents = Clipboard.getDefault().getContents(); + if (clipboardContents == null) { + return null; + } + + List componentCopiedData = null; + if (clipboardContents instanceof List) { + componentCopiedData = (List) clipboardContents; + if (componentCopiedData.get(0) instanceof ComponentCopyData) { + return (List) componentCopiedData; + } + } + return null; + } + + private Rectangle adjustedGridPasteBound(Rectangle parentBound, Rectangle pasteBound) { + Rectangle adjustedBound = new Rectangle().setBounds(pasteBound); + adjustedBound.x = BASE_PASTE_POX_X; + adjustedBound.y = BASE_PASTE_POX_Y; + + if (parentBound.width < pasteBound.width) { + adjustedBound.width = parentBound.width; + } + if (parentBound.height < pasteBound.height) { + adjustedBound.height = parentBound.height; + } + + double ratioW = adjustedBound.width / (double) pasteBound.width; + double ratioH = adjustedBound.height / (double) pasteBound.height; + + double minRatio = Math.min(ratioW, ratioH); + + adjustedBound.width = (int) (pasteBound.width * minRatio); + adjustedBound.height = (int) (pasteBound.height * minRatio); + + return adjustedBound; + } + + private List getPastableBounds(Rectangle parentBound, Rectangle baseBound) { + List boundList = new ArrayList(); + if (((baseBound.x + baseBound.width <= parentBound.width) && (baseBound.y + baseBound.height <= parentBound.height)) == false) { + baseBound = adjustedGridPasteBound(parentBound, baseBound); + } + boolean boundChanged = false; + boundList.add(new Rectangle(baseBound)); + + Rectangle pasteBound = new Rectangle(baseBound); + boolean initBaseBound = false; + while (true) { + + boundChanged = false; + if ((pasteBound.x + pasteBound.width + BASE_PASTE_MARGIN) <= parentBound.width) { + pasteBound.x += BASE_PASTE_MARGIN; + boundChanged = true; + } + if ((pasteBound.y + pasteBound.height + BASE_PASTE_MARGIN) <= parentBound.height) { + pasteBound.y += BASE_PASTE_MARGIN; + boundChanged = true; + } + + if (pasteBound.equals(baseBound.x, baseBound.y, baseBound.width, baseBound.height)) { + break; + } + + if (boundChanged) { + boundList.add(new Rectangle(pasteBound)); + } else { + if (initBaseBound == false) { + initBaseBound = true; + pasteBound.setBounds(BASE_PASTE_POX_X, BASE_PASTE_POX_Y, baseBound.width, baseBound.height); + } else { + break; + } + } + } + + return boundList; + } + + // this method for grid container + private Rectangle getPastePackBound(Part targetParent, ComponentPart newPart, Rectangle absoluteBound) { + + Rectangle parentBound = new Rectangle(0, 0, Integer.parseInt(targetParent.getPropertyValue(LayoutSchemaConstants.GRID_VSIZE_W)), + Integer.parseInt(targetParent.getPropertyValue(LayoutSchemaConstants.GRID_VSIZE_H))); + List siblings = targetParent.getComponentChildren(); + List pasteBoundList = + getPastableBounds(parentBound, + DesignEditorUtil + .pixelBoundToGridBound((EditPart) this.rootEditPart.getViewer().getEditPartRegistry().get(targetParent.getUniqueId()), + absoluteBound)); + // pasteBoundList = getPastableBounds(parentBound, + // DesignEditorUtil.getPackBound(LayoutSchemaConstants.GRID, newPart, + // getCurrentConfigurationID())); + + if (pasteBoundList.size() > 0) { + Rectangle siblingPackBound = null; + Rectangle pastePackBound = null; + boolean found = false; + boolean exist = false; + for (int i = 0; i < pasteBoundList.size(); i++) { + pastePackBound = pasteBoundList.get(i); + + exist = false; + for (int j = 0; j < siblings.size(); j++) { + Part part = siblings.get(j); + if (!(part instanceof ComponentPart)) { + continue; + } + siblingPackBound = DesignEditorUtil.getPackBound((ComponentPart) part, getCurrentConfigurationID()); + if ((siblings.get(j).getDescriptorId().equals(newPart.getDescriptorId())) && siblingPackBound.equals(pastePackBound)) { + exist = true; + break; + } + } + if (exist == false) { + found = true; + break; + } + } + if (found) { + return pastePackBound; + } else { + EditPart editPart = DesignEditorUtil.getEditPart(rootEditPart, targetParent); + if (editPart != null) { + return DesignEditorUtil.pixelBoundToGridBound(editPart.getParent(), pasteBoundList.get(0)); + } else { + return null; + } + } + } else { + return null; + } + + } + + private Part getPasteTarget() { + List copiedDataList = this.getCopiedDataList(); + List selection = CommandUtil.getWidgetPartsFromSelectedObjects(getSelectedObjects()); + Part parent = null; + Part baseSourcePart = null; + Part baseSourceParentPart = null; + Part baseTargetPart = null; + // String containerType = ""; + + if ((selection.size() == 0) || (isSameParent(selection) == false) || (copiedDataList == null) || (copiedDataList.size() < 1)) { + return null; + } + + baseTargetPart = selection.get(0); + baseSourcePart = copiedDataList.get(0).clonedPart; + baseSourceParentPart = copiedDataList.get(0).clonedParentPart; + + if (baseTargetPart.getOwnerDocumentPart() == null) { // check removed + return null; + } + + ComponentDescriptor componentDescriptor = baseTargetPart.getOwnerDocumentPart().getComponentDescriptor(); + if (baseSourcePart instanceof ViewPart) { + if (baseTargetPart instanceof ViewPart) { + parent = baseTargetPart.getParent(); + } else { + return null; + } + } else if (baseTargetPart instanceof ComponentPart) { + if ((copiedDataList.size() == 1) && (baseSourcePart.getUniqueId() == baseTargetPart.getUniqueId())) { + parent = baseTargetPart.getParent(); + } else if (DesignEditorUtil.isItemPart(baseSourcePart)) { + // item component + if (selection.size() == 1 && DesignEditorUtil.isItemContainerPart(baseTargetPart) + && baseSourceParentPart.getDescriptorId().equals(baseTargetPart.getDescriptorId())) { + parent = baseTargetPart; + } else if (DesignEditorUtil.isItemPart(baseTargetPart) + && baseSourcePart.getDescriptorId().equals(baseTargetPart.getDescriptorId())) { + parent = baseTargetPart.getParent(); + } + } else { + // component + if (baseTargetPart instanceof ViewPart) { + if (baseTargetPart.getComponentChildren().isEmpty() && componentDescriptor.isContainer((ComponentPart) baseSourcePart) == true) { + + } + } else if (selection.size() == 1 && componentDescriptor.isContainer((ComponentPart) baseTargetPart)) { + parent = baseTargetPart; + } + } + } + + if ((parent != null) && (parent.getDescriptorId() != null)) { + return parent; + } + + return null; + } + + protected Command getCommand() { + List copiedDataList = this.getCopiedDataList(); + List selection = CommandUtil.getPartsFromSelectedObjects(getSelectedObjects()); + Part parent = pasteTarget; + Part nextSibling = null; + Part baseTargetPart = null; + ComponentPart newPart = null; + String containerType = ""; + CompoundCommand compCmd = null; + boolean bUseNextSibling = false; + baseTargetPart = selection.get(0); + + if (null == parent || null == copiedDataList) { + return null; + } + DocumentPart documentPart = parent.getOwnerDocumentPart(); + List emptyCellPosList = null; + containerType = parent.getDescriptorId(); + + if (DesignEditorUtil.isItemContainerPart(parent)) { + if (selection.size() == 1 && DesignEditorUtil.isItemPart(baseTargetPart)) { + bUseNextSibling = true; + } + } else if (containerType != null) { + if (containerType.equals(LayoutSchemaConstants.BOX) && ((selection.size() == 1) && (selection.get(0) != parent))) { + bUseNextSibling = true; + } else if (containerType.equals(LayoutSchemaConstants.BOX) && (selection.size() == 1) && (selection.get(0) != parent)) { + bUseNextSibling = true; + } else if (containerType.equals(LayoutSchemaConstants.VIEWS)) { + bUseNextSibling = true; + } + } else { + return null; + } + + if (bUseNextSibling == true) { + nextSibling = baseTargetPart.getNextSibling(); + } + + for (int i = 0; i < copiedDataList.size(); i++) { + ComponentCopyData copiedData = copiedDataList.get(i); + Part clonedPart = copiedData.clonedPart; + if (!(clonedPart instanceof ComponentPart)) { + continue; + } + newPart = (ComponentPart) PartUtil.clone(copiedData.clonedPart); + copiedData.clonedPart = newPart; + // set position + boolean appendable = true; + if (containerType != null) { + if (containerType.equals(LayoutSchemaConstants.GRID)) { + Rectangle pasteBound = this.getPastePackBound(parent, newPart, copiedData.absoluteBound); + if (pasteBound == null) { + return null; + } + DesignEditorUtil.setGridPackBound(newPart, pasteBound); + } else if (containerType.equals(LayoutSchemaConstants.BOX)) { + + } else if (containerType.equals(LayoutSchemaConstants.TABLE)) { + if (emptyCellPosList == null) { + emptyCellPosList = DesignEditorUtil.getEmptyTableCellPosList(parent, getCurrentConfigurationID()); + } + Rectangle packBound = new Rectangle(0, 0, 1, 1); + if (emptyCellPosList.size() > 0) { + packBound.x = emptyCellPosList.get(0).x; + packBound.y = emptyCellPosList.get(0).y; + emptyCellPosList.remove(0); + } else { + packBound.x = 0; + packBound.y = 0; + } + DesignEditorUtil.setTablePackBound(newPart, packBound); + } else if (containerType.equals(LayoutSchemaConstants.PANES)) { + if (emptyCellPosList == null) { + emptyCellPosList = DesignEditorUtil.getEmptyPaneCellPosList(parent, getCurrentConfigurationID()); + } + Rectangle packBound = new Rectangle(0, 0, 0, 0); + if (emptyCellPosList.size() > 0) { + packBound.x = emptyCellPosList.get(0).x; + emptyCellPosList.remove(0); + } else { + appendable = false; + } + DesignEditorUtil.setPanesPackBound(newPart, packBound); + } + } + if (appendable) { + if (compCmd == null) { + compCmd = new CompoundCommand(); + } + documentPart.setPartPropertyIdRecursive(newPart); + compCmd.add(PartUtil.createAddPartCommand(parent, newPart, nextSibling)); + } + } + return compCmd; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/PastePartColorAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/PastePartColorAction.java new file mode 100644 index 0000000..df948d7 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/PastePartColorAction.java @@ -0,0 +1,159 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import java.util.List; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.gef.commands.CompoundCommand; +import org.eclipse.gef.ui.actions.Clipboard; +import org.eclipse.ui.IWorkbenchPart; +import org.tizen.efluibuilder.gef.commands.CommandUtil; +import org.tizen.efluibuilder.gef.commands.ComponentCopyData; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.actions.ActionConstants; + + +/** + * An action to paste {@link Part}s. + */ +public class PastePartColorAction extends PartAction { + + /** + * Creates a {@link PastePartColorAction} and associates it with the given workbench part. + * + * @param part + * the workbench part + * @param rootEditPart + * a root {@link EditPart} + */ + public PastePartColorAction(IWorkbenchPart part, EditPart rootEditPart) { + super(part, rootEditPart); + setLazyEnablementCalculation(true); + } + + /** + * Returns true if the selected objects can be pasted. + * + * @return true if the command should be enabled, and false otherwise + */ + @Override + protected boolean calculateEnabled() { + Part srcPart = this.getSourcePart(); + List targetParts = this.getTargetParts(); + if (srcPart != null && targetParts != null && !targetParts.isEmpty()) { + return true; + } + return false; + } + + @Override + protected void init() { + super.init(); + + // ISharedImages images = PlatformUI.getWorkbench().getSharedImages(); + setText(Messages.ACTION_PASTE_COLOR); + setId(ActionConstants.PASTE_PART_COLOR); + // setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE)); + // setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE)); + // setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED)); + setEnabled(false); + } + + /** + * Performs the paste action. + */ + @Override + public void run() { + Command command = getCommand(); + if (command != null) { + CommandStack cmdStack = rootEditPart.getViewer().getEditDomain().getCommandStack(); + cmdStack.execute(command); + } + } + + @SuppressWarnings("unchecked") + private List getCopiedDataList() { + Object clipboardContents = Clipboard.getDefault().getContents(); + if (clipboardContents == null) { + return null; + } + + List componentCopiedData = null; + if (clipboardContents instanceof List) { + componentCopiedData = (List) clipboardContents; + if (componentCopiedData.get(0) instanceof ComponentCopyData) { + return (List) componentCopiedData; + } + } + return null; + } + + private Part getSourcePart() { + List copiedDataList = getCopiedDataList(); + if ((copiedDataList != null) && (copiedDataList.size() == 1)) { + return copiedDataList.get(0).clonedPart; + } + return null; + } + + private List getTargetParts() { + List selection = CommandUtil.getWidgetPartsFromSelectedObjects(getSelectedObjects()); + if (selection.size() >= 1 && getSourcePart() != null && + getSourcePart().getDescriptorId().equals(selection.get(0).getDescriptorId())) { + for (int i = 1; i < selection.size(); i++) { + if (!selection.get(i).getDescriptorId().equals(selection.get(i - 1).getDescriptorId())) { + return null; + } + } + return selection; + } + return null; + } + + private Command getColorCopyCommand(Part srcPart, Part targetPart) { + if (srcPart.hasProperty(LayoutSchemaConstants.COLORS) == true) { + return PartUtil.createSetPropertyCommand(targetPart, LayoutSchemaConstants.COLORS, srcPart.getPropertyValue(LayoutSchemaConstants.COLORS)); + } else { + // FIX ME : use remove propery command + return PartUtil.createSetPropertyCommand(targetPart, LayoutSchemaConstants.COLORS, ""); + } + } + + protected Command getCommand() { + Part srcPart = getSourcePart(); + List targetParts = getTargetParts(); + CompoundCommand cmd = new CompoundCommand(); + if (srcPart != null) { + for (int i = 0; i < targetParts.size(); i++) { + cmd.add(getColorCopyCommand(srcPart, targetParts.get(i))); + } + } + return cmd; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/SelectChildPartAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/SelectChildPartAction.java new file mode 100644 index 0000000..87ed9fc --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/SelectChildPartAction.java @@ -0,0 +1,48 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import org.eclipse.gef.EditPart; +import org.eclipse.ui.IWorkbenchPart; +import org.tizen.efluibuilder.ui.actions.ActionConstants; + + +public class SelectChildPartAction extends ChangePartSelectionAction { + + public SelectChildPartAction(IWorkbenchPart part, EditPart rootEditPart) { + super(part, rootEditPart, ChangePartSelectionAction.TYPE_CHILD); + } + + protected void init() { + super.init(); + setText(Messages.ACTION_SELECT_CHILD); + setId(ActionConstants.SELECT_CHILD); + // ISharedImages images = PlatformUI.getWorkbench().getSharedImages(); + // setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); + // setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); + // setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED)); + setEnabled(false); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/SelectNextSiblingPartAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/SelectNextSiblingPartAction.java new file mode 100644 index 0000000..250ec12 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/SelectNextSiblingPartAction.java @@ -0,0 +1,48 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import org.eclipse.gef.EditPart; +import org.eclipse.ui.IWorkbenchPart; +import org.tizen.efluibuilder.ui.actions.ActionConstants; + + +public class SelectNextSiblingPartAction extends ChangePartSelectionAction { + + public SelectNextSiblingPartAction(IWorkbenchPart part, EditPart rootEditPart) { + super(part, rootEditPart, ChangePartSelectionAction.TYPE_PREV_SIBLING); + } + + protected void init() { + super.init(); + setText(Messages.ACTION_SELECT_PREV_SIBLING); + setId(ActionConstants.SELECT_PREV_SIBLING); + // ISharedImages images = PlatformUI.getWorkbench().getSharedImages(); + // setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); + // setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); + // setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED)); + setEnabled(false); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/SelectParentPartAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/SelectParentPartAction.java new file mode 100644 index 0000000..853f6b7 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/SelectParentPartAction.java @@ -0,0 +1,49 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import org.eclipse.gef.EditPart; +import org.eclipse.ui.IWorkbenchPart; +import org.tizen.efluibuilder.ui.actions.ActionConstants; + + +public class SelectParentPartAction extends ChangePartSelectionAction { + + public SelectParentPartAction(IWorkbenchPart part, EditPart rootEditPart) { + super(part, rootEditPart, ChangePartSelectionAction.TYPE_PARENT); + } + + protected void init() { + super.init(); + + setText(Messages.ACTION_SELECT_PARENT); + setId(ActionConstants.SELECT_PARENT); + // ISharedImages images = PlatformUI.getWorkbench().getSharedImages(); + // setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); + // setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); + // setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED)); + setEnabled(false); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/SelectPreviousSiblingPartAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/SelectPreviousSiblingPartAction.java new file mode 100644 index 0000000..05c73fb --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/SelectPreviousSiblingPartAction.java @@ -0,0 +1,48 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import org.eclipse.gef.EditPart; +import org.eclipse.ui.IWorkbenchPart; +import org.tizen.efluibuilder.ui.actions.ActionConstants; + + +public class SelectPreviousSiblingPartAction extends ChangePartSelectionAction { + + public SelectPreviousSiblingPartAction(IWorkbenchPart part, EditPart rootEditPart) { + super(part, rootEditPart, ChangePartSelectionAction.TYPE_NEXT_SIBLING); + } + + protected void init() { + super.init(); + setText(Messages.ACTION_SELECT_NEXT_SIBLING); + setId(ActionConstants.SELECT_NEXT_SIBLING); + // ISharedImages images = PlatformUI.getWorkbench().getSharedImages(); + // setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); + // setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); + // setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED)); + setEnabled(false); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/SetStartupViewAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/SetStartupViewAction.java new file mode 100644 index 0000000..b4692bb --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/SetStartupViewAction.java @@ -0,0 +1,119 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import java.util.List; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PlatformUI; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.gef.commands.CommandUtil; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.ViewPart; +import org.tizen.efluibuilder.ui.actions.ActionConstants; +import org.tizen.efluibuilder.ui.views.outline.Messages; + + +/** + * An action to paste {@link Part}s. + */ +public class SetStartupViewAction extends PartAction { + + /** + * A root {@link EditPart}. + */ + static final int BASE_PASTE_MARGIN = 10; + static final int BASE_PASTE_POX_X = 0; + static final int BASE_PASTE_POX_Y = 0; + + /** + * Creates a {@link SetStartupViewAction} and associates it with the given workbench part. + * + * @param part + * the workbench part + * @param rootEditPart + * a root {@link EditPart} + */ + public SetStartupViewAction(IWorkbenchPart part, EditPart rootEditPart) { + super(part, rootEditPart); + setLazyEnablementCalculation(true); + } + + /** + * Returns true if the selected objects can be pasted. + * + * @return true if the command should be enabled, and false otherwise + */ + @Override + protected boolean calculateEnabled() { + List selection = CommandUtil.getPartsFromSelectedObjects(getSelectedObjects()); + Part parent = null; + Part part = null; + if (selection.size() == 1 && selection.get(0) instanceof ViewPart + && LayoutSchemaConstants.VIEW.equals(selection.get(0).getPropertyValue(LayoutSchemaConstants.TYPE))) { + part = selection.get(0); + parent = part.getParent(); + if (parent != null && !parent.getPropertyValue(LayoutSchemaConstants.STARTUP).equals(part.getPropertyValue(LayoutSchemaConstants.ID))) { + return true; + } + } + return false; + } + + @Override + protected void init() { + super.init(); + + ISharedImages images = PlatformUI.getWorkbench().getSharedImages(); + setText(Messages.ACTION_SET_MAIN_VIEW_TITLE); + setId(ActionConstants.SET_STARTUP_VIEW); + setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE)); + setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE)); + setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED)); + } + + /** + * Performs the paste action. + */ + @Override + public void run() { + Command command = getCommand(); + if (command != null) { + CommandStack cmdStack = rootEditPart.getViewer().getEditDomain().getCommandStack(); + cmdStack.execute(command); + } + } + + protected Command getCommand() { + List selection = CommandUtil.getPartsFromSelectedObjects(getSelectedObjects()); + Part part = selection.get(0); + Part parent = part.getParent(); + return PartUtil.createSetPropertyCommand(parent, LayoutSchemaConstants.STARTUP, part.getPropertyValue(LayoutSchemaConstants.ID)); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/StoryboardAutoLayoutAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/StoryboardAutoLayoutAction.java new file mode 100644 index 0000000..a0942c6 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/StoryboardAutoLayoutAction.java @@ -0,0 +1,89 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.ui.IWorkbenchPart; +import org.tizen.efluibuilder.gef.editparts.DesignRootEditPart; +import org.tizen.efluibuilder.gef.viewer.DesignStoryboardUtil; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.mscreen.configurator.MScreenQualifierManager; +import org.tizen.efluibuilder.ui.actions.ActionConstants; + + +public class StoryboardAutoLayoutAction extends PartAction { + + /** + * Creates a {@link StoryboardAutoLayoutAction} and associates it with the given workbench part. + * + * @param part + * the workbench part + * @param rootEditPart + * a root {@link EditPart} + */ + public StoryboardAutoLayoutAction(IWorkbenchPart part, EditPart rootEditPart) { + super(part, rootEditPart); + } + + @Override + protected boolean calculateEnabled() { + if (((DesignRootEditPart) rootEditPart).getContents().getChildren().size() > 0) { + return true; + } + return false; + } + + @Override + protected void init() { + super.init(); + + setText(Messages.ACTION_ALIGN_STORYBOARD); + setId(ActionConstants.ALIGN_STORYBOARD); + + setEnabled(true); + } + + @Override + public void run() { + if (((DesignRootEditPart) rootEditPart).getContents().getChildren().size() > 0) { + MScreenQualifierManager mscreenManager = getMScreenQualifierManager(); + if (mscreenManager == null) { + return; + } + Command cmd = + DesignStoryboardUtil.getStoryboardReconstructCommand((Part) ((DesignRootEditPart) rootEditPart).getContents().getModel(), + mscreenManager.getScreenSize()); + if (cmd != null) { + CommandStack cmdStack = rootEditPart.getViewer().getEditDomain().getCommandStack(); + cmdStack.execute(cmd); + } + if (rootEditPart.getViewer() instanceof DesignViewer) { + ((DesignViewer) rootEditPart.getViewer()).setFitMode(true); + } + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/ZorderAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/ZorderAction.java new file mode 100644 index 0000000..7f54182 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/ZorderAction.java @@ -0,0 +1,226 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.gef.commands.CompoundCommand; +import org.eclipse.ui.IWorkbenchPart; +import org.tizen.efluibuilder.gef.commands.CommandUtil; +import org.tizen.efluibuilder.gef.policies.containers.DesignEditorUtil; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; + + +public abstract class ZorderAction extends PartAction { + + protected PriorityAction actionType; + + public enum PriorityAction { + BACK, BACKWARD, FRONT, FRONTWARD + } + + static class OrderAscCompare implements Comparator, Serializable { + private static final long serialVersionUID = 8629981561917621767L; + + @Override + public int compare(Part arg0, Part arg1) { + Part parentPart = arg0.getParent(); + int arg0Idx = parentPart.getChildren().indexOf(arg0); + int arg1Idx = parentPart.getChildren().indexOf(arg1); + if (arg0Idx < arg1Idx) { + return -1; + } else if (arg0Idx == arg1Idx) { + return 0; + } + return 1; + } + + } + + static class OrderDescCompare implements Comparator, Serializable { + private static final long serialVersionUID = 4820256546568763383L; + + @Override + public int compare(Part arg0, Part arg1) { + Part parentPart = arg0.getParent(); + int arg0Idx = parentPart.getChildren().indexOf(arg0); + int arg1Idx = parentPart.getChildren().indexOf(arg1); + if (arg0Idx > arg1Idx) { + return -1; + } else if (arg0Idx == arg1Idx) { + return 0; + } + return 1; + } + + } + + public ZorderAction(IWorkbenchPart part, EditPart rootEditPart) { + super(part, rootEditPart); + } + + protected void setPriorityType(PriorityAction action) { + this.actionType = action; + } + + @Override + protected boolean calculateEnabled() { + List orderedParts = CommandUtil.getWidgetPartsFromSelectedObjects(getSelectedObjects()); + if ((orderedParts.size() <= 0) || (orderedParts.get(0).getParent() == null) || (DesignEditorUtil.isSameParent(orderedParts) == false) + || !(orderedParts.get(0).getParent().getDescriptorId().equals(LayoutSchemaConstants.GRID) +// || orderedParts.get(0).getDescriptorId().equals(LayoutSchemaConstants.VIEW) + || orderedParts.get(0).getDescriptorId().equals(LayoutSchemaConstants.TABLE) || orderedParts.get(0).getDescriptorId().equals(LayoutSchemaConstants.BOX))) { + return false; + } + + for (Part sibling : orderedParts.get(0).getParent().getComponentChildren()) { + for (Part target : orderedParts) { + if (orderedParts.contains(sibling)) { + continue; + } + if (actionType == PriorityAction.BACK || actionType == PriorityAction.BACKWARD) { + if (sibling.getIndex() < target.getIndex()) { + return true; + } + } else if (actionType == PriorityAction.FRONT || actionType == PriorityAction.FRONTWARD) { + if (sibling.getIndex() > target.getIndex()) { + return true; + } + } + + } + } + return false; + } + + @Override + public void run() { + List orderedParts = CommandUtil.getWidgetPartsFromSelectedObjects(getSelectedObjects()); + Collections.sort(orderedParts, new OrderAscCompare()); + + CompoundCommand cmdCompound = new CompoundCommand(); + List unselectedParts = orderedParts.get(0).getParent().getChildren(); + for (Part part : orderedParts) { + unselectedParts.remove(part); + } + + Part target = null; + Part nextSibling = null; + int lastMovedIndex = 0; + Part parent = orderedParts.get(0).getParent(); + Part remainsPart = null; + ArrayList remainsUnselectedParts = new ArrayList(); + int targetIndex = 0; + List reOrderedChildren = parent.getChildren(); + + if (actionType == PriorityAction.BACK) { + nextSibling = unselectedParts.get(0); + for (int i = 0; i < orderedParts.size(); i++) { + target = orderedParts.get(i); + cmdCompound.add(PartUtil.createChangePartOrderCommand(target, nextSibling)); + } + } else if (actionType == PriorityAction.BACKWARD) { + remainsUnselectedParts.clear(); + remainsUnselectedParts.addAll(unselectedParts); + lastMovedIndex = parent.getChildren().size(); + Part temp = null; + + for (int i = orderedParts.size() - 1; i >= 0; i--) { + target = orderedParts.get(i); + if (target.getIndex() >= lastMovedIndex) { + continue; + } + for (int j = remainsUnselectedParts.size() - 1; j >= 0; j--) { + remainsPart = remainsUnselectedParts.get(j); + if (remainsPart.getIndex() < target.getIndex()) { + temp = reOrderedChildren.get(remainsPart.getIndex()); + if (target.getIndex() < reOrderedChildren.size() - 1) { + nextSibling = reOrderedChildren.get(target.getIndex() + 1); + } else { + nextSibling = null; + } + + targetIndex = target.getIndex(); + reOrderedChildren.remove(temp); + reOrderedChildren.add(targetIndex, temp); + cmdCompound.add(PartUtil.createChangePartOrderCommand(remainsPart, nextSibling)); + lastMovedIndex = remainsPart.getIndex(); + remainsUnselectedParts.remove(remainsPart); + break; + } + } + } + } else if (actionType == PriorityAction.FRONT) { + nextSibling = null; + for (int i = 0; i < orderedParts.size(); i++) { + target = orderedParts.get(i); + cmdCompound.add(PartUtil.createChangePartOrderCommand(target, nextSibling)); + } + } else if (actionType == PriorityAction.FRONTWARD) { + remainsUnselectedParts.clear(); + remainsUnselectedParts.addAll(unselectedParts); + lastMovedIndex = -1; + Part temp; + for (int i = 0; i < orderedParts.size(); i++) { + target = orderedParts.get(i); + if (target.getIndex() <= lastMovedIndex) { + continue; + } + for (int j = 0; j < remainsUnselectedParts.size(); j++) { + remainsPart = remainsUnselectedParts.get(j); + if (remainsPart.getIndex() > target.getIndex()) { + temp = reOrderedChildren.get(remainsPart.getIndex()); + if (target.getIndex() < reOrderedChildren.size() - 1) { + nextSibling = reOrderedChildren.get(target.getIndex()); + } else { + nextSibling = null; + } + + targetIndex = target.getIndex(); + reOrderedChildren.remove(temp); + reOrderedChildren.add(targetIndex, temp); + + cmdCompound.add(PartUtil.createChangePartOrderCommand(remainsPart, target)); + lastMovedIndex = remainsPart.getIndex(); + remainsUnselectedParts.remove(remainsPart); + break; + } + } + } + } + + CommandStack cmdStack = rootEditPart.getViewer().getEditDomain().getCommandStack(); + if (cmdCompound != null && cmdCompound.size() > 0 && cmdCompound.canExecute() && (cmdStack != null)) { + cmdStack.execute(cmdCompound); + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/ZorderBackAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/ZorderBackAction.java new file mode 100644 index 0000000..18dc94f --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/ZorderBackAction.java @@ -0,0 +1,46 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import org.eclipse.gef.EditPart; +import org.eclipse.ui.IWorkbenchPart; +import org.tizen.efluibuilder.ui.actions.ActionConstants; + + +public class ZorderBackAction extends ZorderAction { + public ZorderBackAction(IWorkbenchPart part, EditPart rootEditPart) { + super(part, rootEditPart); + } + + protected void init() { + super.init(); + setId(ActionConstants.ZORDER_BACK); + setText(Messages.ACTION_ZORDER_BACK); + // setToolTipText(); + // setImageDescriptor(InternalImages.DESC_VERT_ALIGN_BOTTOM); + // setDisabledImageDescriptor(InternalImages.DESC_VERT_ALIGN_BOTTOM_DIS); + setEnabled(false); + setPriorityType(PriorityAction.BACK); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/ZorderBackwardAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/ZorderBackwardAction.java new file mode 100644 index 0000000..6055706 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/ZorderBackwardAction.java @@ -0,0 +1,46 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import org.eclipse.gef.EditPart; +import org.eclipse.ui.IWorkbenchPart; +import org.tizen.efluibuilder.ui.actions.ActionConstants; + + +public class ZorderBackwardAction extends ZorderAction { + public ZorderBackwardAction(IWorkbenchPart part, EditPart rootEditPart) { + super(part, rootEditPart); + } + + protected void init() { + super.init(); + setId(ActionConstants.ZORDER_BACKWARD); + setText(Messages.ACTION_ZORDER_BACKWARD); + // setToolTipText(); + // setImageDescriptor(InternalImages.DESC_VERT_ALIGN_BOTTOM); + // setDisabledImageDescriptor(InternalImages.DESC_VERT_ALIGN_BOTTOM_DIS); + setEnabled(false); + setPriorityType(PriorityAction.BACKWARD); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/ZorderFrontAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/ZorderFrontAction.java new file mode 100644 index 0000000..dd92fde --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/ZorderFrontAction.java @@ -0,0 +1,47 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import org.eclipse.gef.EditPart; +import org.eclipse.ui.IWorkbenchPart; +import org.tizen.efluibuilder.ui.actions.ActionConstants; + + +public class ZorderFrontAction extends ZorderAction { + public ZorderFrontAction(IWorkbenchPart part, EditPart rootEditPart) { + super(part, rootEditPart); + } + + protected void init() { + super.init(); + setId(ActionConstants.ZORDER_FRONT); + setText(Messages.ACTION_ZORDER_FRONT); + // setToolTipText(); + // setImageDescriptor(InternalImages.DESC_VERT_ALIGN_BOTTOM); + // setDisabledImageDescriptor(InternalImages.DESC_VERT_ALIGN_BOTTOM_DIS); + setEnabled(false); + setPriorityType(PriorityAction.FRONT); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/ZorderFrontwardAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/ZorderFrontwardAction.java new file mode 100644 index 0000000..3c6ce3b --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/actions/ZorderFrontwardAction.java @@ -0,0 +1,46 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.actions; + +import org.eclipse.gef.EditPart; +import org.eclipse.ui.IWorkbenchPart; +import org.tizen.efluibuilder.ui.actions.ActionConstants; + + +public class ZorderFrontwardAction extends ZorderAction { + public ZorderFrontwardAction(IWorkbenchPart part, EditPart rootEditPart) { + super(part, rootEditPart); + } + + protected void init() { + super.init(); + setId(ActionConstants.ZORDER_FRONTWARD); + setText(Messages.ACTION_ZORDER_FRONTWARD); + // setToolTipText(); + // setImageDescriptor(InternalImages.DESC_VERT_ALIGN_BOTTOM); + // setDisabledImageDescriptor(InternalImages.DESC_VERT_ALIGN_BOTTOM_DIS); + setEnabled(false); + setPriorityType(PriorityAction.FRONTWARD); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/commands/CommandUtil.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/commands/CommandUtil.java new file mode 100644 index 0000000..c704e94 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/commands/CommandUtil.java @@ -0,0 +1,168 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.commands; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.gef.EditPart; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.EventPart; +import org.tizen.efluibuilder.model.part.Part; + + +/** + * An utility class of commands. + */ +public class CommandUtil { + + /** + * Constructor. + */ + public CommandUtil() { + } + + /** + * Gets the last located {@link Part} of selected {@link Part}. + * + * @param rootEditPart + * a root edit part + * @param selectedObjects + * a List containing selected object + * @return the last located {@link Part} if it is exist, and null otherwise + */ + public static Part getLastPart(EditPart rootEditPart, List selectedObjects) { + List orderedParts = getOrderedParts(rootEditPart, selectedObjects); + + if (orderedParts.size() > 0) { + return orderedParts.get(orderedParts.size() - 1); + } else { + return null; + } + } + + /** + * Gets a List containing ordered selected {@link Part}. + * + * @param rootEditPart + * a root edit part + * @param selectedObjects + * a List containing selected object + * @return List containing ordered selected {@link Part} + */ + public static List getOrderedParts(EditPart rootEditPart, List selectedObjects) { + List selectedParts = new ArrayList(); + for (Object obj : selectedObjects) { + if (obj instanceof EditPart && ((EditPart) obj).getModel() instanceof Part) { + Part part = (Part) (((EditPart) obj).getModel()); + selectedParts.add(part); + } + } + + List orderedParts = new ArrayList(); + + sortPart(rootEditPart, selectedParts, orderedParts); + + return orderedParts; + } + + public static List getPartsFromSelectedObjects(List selectedObjects) { + List selectedParts = new ArrayList(); + for (Object obj : selectedObjects) { + if (obj instanceof EditPart && ((EditPart) obj).getModel() instanceof Part) { + EditPart editpart = (EditPart) obj; + Part part = (Part) (((EditPart) obj).getModel()); + if (editpart.getSelected() == EditPart.SELECTED_PRIMARY) { + selectedParts.add(0, part); + } else { + selectedParts.add(part); + } + } + } + return selectedParts; + } + + public static List getWidgetPartsFromSelectedObjects(List selectedObjects) { + List selectedParts = new ArrayList(); + for (Object obj : selectedObjects) { + if (obj instanceof EditPart && ((EditPart) obj).getModel() instanceof Part) { + Part part = (Part) (((EditPart) obj).getModel()); + EditPart editpart = (EditPart) obj; + // TODO : FIXME part.getParent() != null + if ((part instanceof ComponentPart || part instanceof EventPart) && (part.getParent() != null) && part.getOwnerDocumentPart() != null) { + if (editpart.getSelected() == EditPart.SELECTED_PRIMARY) { + selectedParts.add(0, part); + } else { + selectedParts.add(part); + } + } + } + } + return selectedParts; + } + + public static List getEditPartsFromSelectedObjects(List selectedObjects) { + List editParts = new ArrayList(); + for (Object obj : selectedObjects) { + if (obj instanceof EditPart && ((EditPart) obj).getModel() instanceof Part) { + editParts.add((EditPart) obj); + } + } + return editParts; + } + + /** + * Sorts selected {@link Part} into location order. + * + * @param parentEditPart + * a parent edit part + * @param selectedParts + * a List containing selected {@link Part} + * @param orderedParts + * a List containing ordered {@link Part} + */ + private static void sortPart(EditPart parentEditPart, List selectedParts, List orderedParts) { + if (parentEditPart == null || selectedParts == null || orderedParts == null) { + return; + } + + List editParts = parentEditPart.getChildren(); + int size = editParts.size(); + for (int i = 0; i < size; i++) { + EditPart editPart = (EditPart) editParts.get(i); + if (editPart.getModel() instanceof Part) { + int selectedPartsSize = selectedParts.size(); + for (int j = 0; j < selectedPartsSize; j++) { + Part selectedPart = selectedParts.get(j); + if (((Part) editPart.getModel()).equals(selectedPart)) { + orderedParts.add(selectedPart); + } + } + } + + sortPart(editPart, selectedParts, orderedParts); + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/commands/ComponentCopyData.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/commands/ComponentCopyData.java new file mode 100644 index 0000000..aa03a1b --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/commands/ComponentCopyData.java @@ -0,0 +1,49 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.commands; + +import org.eclipse.draw2d.geometry.Rectangle; +import org.tizen.efluibuilder.model.part.Part; + + +public class ComponentCopyData { + public Rectangle absoluteBound; + public Part clonedPart; + public Part clonedParentPart; + + public ComponentCopyData(Part clonedPart, Rectangle absoluteBound, Rectangle relativeBound, String layoutType, Part clonedParentPart) { + this.clonedPart = clonedPart; + if (absoluteBound != null) { + this.absoluteBound = absoluteBound; + } else { + this.absoluteBound = null; + } + + if (clonedParentPart != null) { + this.clonedParentPart = clonedParentPart; + } else { + this.clonedParentPart = null; + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/commands/CopyPartCommand.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/commands/CopyPartCommand.java new file mode 100644 index 0000000..6f999e5 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/commands/CopyPartCommand.java @@ -0,0 +1,53 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.commands; + +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.ui.actions.Clipboard; + + +public class CopyPartCommand extends Command { + Object clipboardData = null; + + public CopyPartCommand(Object clipboardData) { + this.clipboardData = clipboardData; + } + + public boolean canExecute() { + return true; + } + + public boolean canUndo() { + return true; + } + + public void undo() { + Clipboard.getDefault().setContents(""); + } + + public void execute() { + Clipboard.getDefault().setContents(this.clipboardData); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/commands/WidgetRelation.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/commands/WidgetRelation.java new file mode 100644 index 0000000..75fa709 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/commands/WidgetRelation.java @@ -0,0 +1,122 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.commands; + +import org.tizen.efluibuilder.model.part.Part; + + +/** + * A widget relation class. + */ +public class WidgetRelation { + + /** + * A horizontal cursor option. + */ + public static final int HORIZONTAL_CURSOR = 0; + + /** + * A vertical cursor option. + */ + public static final int VERTICAL_CURSOR = 1; + + /** + * A widget relation. + */ + public enum Relation { + NONE, FREE, PREV_SIBLING, // A is prev_sibling of B <=> A comes before B + NEXT_SIBLING, // A is next_sibling of B <=> A comes after B + CHILD, // A is the last child of B + // CHILD_FIRST, // A is the first child of B + // CHILD_LAST, // A is the last child of B + DENY, // deny + } + + /** + * A target {@link Part} to be related. + */ + private Object target; + + /** + * A {@link Relation}. + */ + private Relation relation; + + /** + * A cursor option. + */ + private int option; + + /** + * Constructor. + * + * @param target + * a target {@link Part} to be related + * @param rel + * a {@link Relation} + * @param cursorOption + * a cursor option. {@link #HORIZONTAL_CURSOR} or {@link #VERTICAL_CURSOR} + */ + public WidgetRelation(Object target, Relation rel, int cursorOption) { + this.target = target; + this.relation = rel; + this.option = cursorOption; + } + + /** + * Gets a target {@link Part} to be related. + * + * @return target {@link Part} to be related + */ + public Object getTarget() { + return this.target; + } + + public void setTarget(Object target) { + this.target = target; + } + + /** + * Gets a {@link Relation}. + * + * @return {@link Relation} + */ + public Relation getRelation() { + return relation; + } + + public void setRelation(Relation relation) { + this.relation = relation; + } + + /** + * Gets a cursor option. + * + * @return cursor option + */ + public int getOption() { + return option; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/dnd/model/AbstractTemplate.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/dnd/model/AbstractTemplate.java new file mode 100644 index 0000000..2ba98a2 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/dnd/model/AbstractTemplate.java @@ -0,0 +1,53 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.dnd.model; + +import org.eclipse.gef.requests.CreationFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public abstract class AbstractTemplate implements ITemplate { + protected static Logger logger = LoggerFactory.getLogger(AbstractTemplate.class); + private Object type = null; + private CreationFactory factory = null; + + @Override + public Object getType() { + return type; + } + + protected void setType(Object type) { + this.type = type; + } + + @Override + public CreationFactory getFactory() { + return factory; + } + + protected void setFactory(CreationFactory factory) { + this.factory = factory; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/dnd/model/ComponentTemplate.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/dnd/model/ComponentTemplate.java new file mode 100644 index 0000000..7ca7b6a --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/dnd/model/ComponentTemplate.java @@ -0,0 +1,61 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.dnd.model; + +import org.eclipse.gef.requests.CreationFactory; +import org.tizen.efluibuilder.model.part.DocumentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.util.PartUtil; + + +public final class ComponentTemplate extends AbstractTemplate { + private String descriptorId = null; + private DocumentPart documentPart = null; + + public ComponentTemplate(DocumentPart documentPart, String descriptorId) { + this.documentPart = documentPart; + this.descriptorId = descriptorId; + + setType(COMPONENT); + PartCreationFactory factory = new PartCreationFactory(); + setFactory(factory); + } + + public class PartCreationFactory implements CreationFactory { + @Override + public Object getNewObject() { + Part part = PartUtil.createPartWithInitValue(documentPart, PartType.COMPONENT, documentPart, descriptorId); + if (part != null) { + part.setParent(documentPart); + } + return part; + } + + @Override + public Object getObjectType() { + return getType(); + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/dnd/model/DataBindingTemplate.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/dnd/model/DataBindingTemplate.java new file mode 100644 index 0000000..3a36cf7 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/dnd/model/DataBindingTemplate.java @@ -0,0 +1,90 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.gef.dnd.model; + +import org.eclipse.gef.requests.CreationFactory; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.ui.view.databinding.model.DataBindingPartProperty; + +public class DataBindingTemplate extends AbstractTemplate { + private String modelName; + private String viewName; + private Part targetWidget; + private String dataType; + private String allowedBindingType; + private String sourceType; + + public DataBindingTemplate(String modelName, String viewName, String dataType, String allowedBindingType, String sourceType) { + this.modelName = modelName; + this.viewName = viewName; + this.dataType = dataType; + this.allowedBindingType = allowedBindingType; + this.sourceType = sourceType; + setType(DATABINDING); + DataBindingPropertyCreationFactory factory = new DataBindingPropertyCreationFactory(); + setFactory(factory); + } + + public DataBindingTemplate(String modelName, String value, String dataType, Part targetWidget, String allowedBindingType, String sourceType) { + this.modelName = modelName; + this.viewName = value; + this.targetWidget = targetWidget; + this.dataType = dataType; + this.allowedBindingType = allowedBindingType; + this.sourceType = sourceType; + setType(DATABINDING); + DataBindingPropertyCreationFactory factory = new DataBindingPropertyCreationFactory(); + setFactory(factory); + } + + public Part getTargetWidget() { + return targetWidget; + } + + public String getDataType() { + return dataType; + } + + private class DataBindingPropertyCreationFactory implements CreationFactory { + + /* + * (non-Javadoc) + * + * @see org.eclipse.gef.requests.CreationFactory#getNewObject() + */ + @Override + public Object getNewObject() { + return new DataBindingPartProperty(modelName, viewName, dataType, allowedBindingType, sourceType); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.gef.requests.CreationFactory#getObjectType() + */ + @Override + public Object getObjectType() { + return getType(); + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/dnd/model/ITemplate.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/dnd/model/ITemplate.java new file mode 100644 index 0000000..5fad76f --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/dnd/model/ITemplate.java @@ -0,0 +1,51 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.dnd.model; + +import org.eclipse.gef.requests.CreationFactory; + + +public interface ITemplate { + public static int DUMMY = 0; + public static int COMPONENT = 1; + public static int SNIPPET = 2; + public static int PROPERTY = 3; + public static int DATABINDING = 4; + /** + * Returns type of this template. + * + * @return a type of this template. + */ + public Object getType(); + + /** + * Returns CreationFactory of this template. + * + * @return a creation factory of this template. + * + * @see org.eclipse.gef.requests.CreationFactory + * @see org.eclipse.gef.requests.CreateRequest + */ + public CreationFactory getFactory(); +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/dnd/model/RMResource.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/dnd/model/RMResource.java new file mode 100644 index 0000000..f59bce5 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/dnd/model/RMResource.java @@ -0,0 +1,161 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.dnd.model; + +import org.tizen.efluibuilder.mscreen.configurator.MscreenConstants; +import org.tizen.efluibuilder.utility.PlatformUtil; + + +public class RMResource { + + // == for test == start + public static final int INVALID = 0; + public static final int FOLDER = 1; + public static final int IMAGE = 2; + public static final int SOUND = 3; + public static final int MOVIE = 4; + public static final int LAYOUT = 5; + public static final int TXT = 6; // for elm.entry.widget & TextResourceMethod + + private int type = INVALID; + private String resKey = null; + private String resPath = null; + private String projectPath = null; + + public static final String[] audioFileExtention = { ".mp3", ".mp2", ".wma", ".aac", ".wav", ".wave", ".ogg", ".flac" }; + public static final String[] videoFileExtention = { ".wmv", ".avi", ".mp4", }; + public static final String[] imageFileExtention = { ".png", ".jpg", ".jpeg", ".bmp", ".gif", ".mjpeg" }; + public static final String[] layoutFileExtention = { ".edj" }; + public static final String[] textFileExtention = { ".txt" }; + + public RMResource() { + this.resPath = ""; + this.projectPath = ""; + this.resKey = ""; + this.type = INVALID; + } + + public void setPath(String path, String projectPath) { + this.resPath = path; + this.projectPath = projectPath; + parsePath(); + } + + public void setResKey(String resKey) { + this.resKey = resKey; + parseResKey(); + } + + public boolean isCurrentProjectResource() { + return resPath.startsWith(projectPath + PlatformUtil.getCorrectedPath(MscreenConstants.RESOURCE_DIRECTORY)); + } + + private boolean isEmptyString(String src) { + if ((src == null) || (src.trim().length() < 1)) { + return true; + } else { + return false; + } + } + + public void createResKey() { + if (resPath.length() > 0) { + resKey = resPath.substring(projectPath.length() + MscreenConstants.RESOURCE_DIRECTORY.length()); + } else { + resKey = MscreenConstants.RESOURCE_KEY + resKey; + } + + } + + private void parsePath() { + if (isEmptyString(resPath)) { + + } else { + if (resPath.startsWith(projectPath)) { + createResKey(); + parseMediaType(); + } + } + } + + private void parseResKey() { + if (isEmptyString(resKey)) { + + } else { + createResKey(); + parseMediaType(); + } + } + + public int getType() { + return type; + } + + public String getResKey() { + return resKey; + } + + public void parseMediaType() { + if (isMediaType(imageFileExtention)) { + type = IMAGE; + } else if (isMediaType(audioFileExtention)) { + type = SOUND; + } else if (isMediaType(videoFileExtention)) { + type = MOVIE; + } else if (isMediaType(layoutFileExtention)) { + type = LAYOUT; + } else if (isMediaType(textFileExtention)) { // for RM - efl.entry.widget + type = TXT; + } else { + type = INVALID; + } + } + + // for RM + public static String[] getResourceFileExtentionsByType(int resourceType) { + switch (resourceType) { + case IMAGE: + return imageFileExtention; + case SOUND: + return audioFileExtention; + case MOVIE: + return videoFileExtention; + case LAYOUT: + return layoutFileExtention; + case TXT: // for RM - efl.entry.widget + return textFileExtention; + default: + return null; + } + } + + private boolean isMediaType(String[] fileExtentions) { + for (int i = 0; i < fileExtentions.length; i++) { + if (resKey.toLowerCase().endsWith(fileExtentions[i])) { + return true; + } + } + return false; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/dnd/model/RMResourceTemplate.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/dnd/model/RMResourceTemplate.java new file mode 100644 index 0000000..ffce159 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/dnd/model/RMResourceTemplate.java @@ -0,0 +1,123 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.dnd.model; + +import org.eclipse.core.resources.IProject; +import org.eclipse.gef.requests.CreationFactory; +import org.eclipse.ui.PlatformUI; +import org.tizen.efluibuilder.mscreen.configurator.MscreenConstants; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; + + +public class RMResourceTemplate extends AbstractTemplate { + private static final String PROPERTY_NAME_RES_SRC = "src"; //$NON-NLS-1$ + + private static final String PROPERTY_TYPE_IMAGE = "image"; //$NON-NLS-1$ + private static final String PROPERTY_TYPE_LAYOUT = "layout-resource"; //$NON-NLS-1$ + private static final String PROPERTY_TYPE_ENTRY = "text-resource"; //$NON-NLS-1$ + + private RMResource rmResource = null; + + public RMResourceTemplate() { + setType(PROPERTY); + ResourceCreationFactory factory = new ResourceCreationFactory(); + setFactory(factory); + } + + public RMResourceTemplate(String transferData, boolean isResKey) { + rmResource = new RMResource(); + + if (isResKey) { // Data of DnD is resource Key. + rmResource.setResKey(transferData); + } else { // Data of DnD is resource file_full_path. + CombineEditorPart combineEditorPart = (CombineEditorPart) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); + IProject project = combineEditorPart.getProject(); + rmResource.setPath(transferData, project.getLocation().toOSString()); + } + setType(PROPERTY); + ResourceCreationFactory factory = new ResourceCreationFactory(); + setFactory(factory); + } + + public boolean isValidRMResource() { + return (rmResource.getResKey().length() > MscreenConstants.RESOURCE_KEY.length()) ? true : false; + } + + public boolean isCurrentProjectResource() { + return rmResource.isCurrentProjectResource(); + } + + private class ResourceCreationFactory implements CreationFactory { + private String getPropertyName(int type) { + switch (type) { + case RMResource.IMAGE: + case RMResource.LAYOUT: + case RMResource.TXT: // for RM - text file resource of efl.entry.widget + return PROPERTY_NAME_RES_SRC; + + case RMResource.SOUND: + return null; + case RMResource.MOVIE: + return null; + default: + return null; + } + } + + @Override + public Object getNewObject() { + + String propertyName = getPropertyName(rmResource.getType()); + if (propertyName == null) { + return null; + } + + switch (rmResource.getType()) { // for RM - updated text-resource of efl.entry.widget + case RMResource.IMAGE: + if (propertyName.equals(PROPERTY_NAME_RES_SRC)) { + return new ResourceTemplateProperty(propertyName, PROPERTY_TYPE_IMAGE, rmResource.getResKey()); + } + break; + case RMResource.LAYOUT: + if (propertyName.equals(PROPERTY_NAME_RES_SRC)) { + return new ResourceTemplateProperty(propertyName, PROPERTY_TYPE_LAYOUT, rmResource.getResKey()); + } + break; + case RMResource.TXT: + if (propertyName.equals(PROPERTY_NAME_RES_SRC)) { + return new ResourceTemplateProperty(propertyName, PROPERTY_TYPE_ENTRY, rmResource.getResKey()); + } + break; + default: + break; + } + return null; + } + + @Override + public Object getObjectType() { + return getType(); + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/dnd/model/ResourceTemplateProperty.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/dnd/model/ResourceTemplateProperty.java new file mode 100644 index 0000000..2c72276 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/dnd/model/ResourceTemplateProperty.java @@ -0,0 +1,61 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.dnd.model; + +public final class ResourceTemplateProperty { + + private String name; + private String type; + private String value; + + ResourceTemplateProperty(String name, String type, String value) { + this.name = name; + this.type = type; + this.value = value; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/dnd/model/SnippetTemplate.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/dnd/model/SnippetTemplate.java new file mode 100644 index 0000000..77bf9a0 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/dnd/model/SnippetTemplate.java @@ -0,0 +1,75 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.dnd.model; + +import org.eclipse.gef.requests.CreationFactory; +import org.tizen.efluibuilder.model.part.DocumentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.snippet.ISnippet; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUnmarshaller; +import org.w3c.dom.Document; + + +public final class SnippetTemplate extends AbstractTemplate { + + private ISnippet snippet = null; + private DocumentPart documentPart = null; + + public SnippetTemplate(ISnippet snippet, DocumentPart documentPart) { + this.snippet = snippet; + this.documentPart = documentPart; + setType(SNIPPET); + SnippetCreationFactory factory = new SnippetCreationFactory(); + setFactory(factory); + } + + public ISnippet getSnippet() { + return snippet; + } + + private class SnippetCreationFactory implements CreationFactory { + @Override + public Object getNewObject() { + Document document = snippet.getModel(); + PartUnmarshaller unmarshaller = new PartUnmarshaller(); + Part part = unmarshaller.unmarshall(documentPart, document, false); + resetID(part); + return part; + } + + @Override + public Object getObjectType() { + return getType(); + } + + private void resetID(Part part) { + part.removeProperty(LayoutSchemaConstants.ID); + for (Part child : part.getChildren()) { + child.removeProperty(LayoutSchemaConstants.ID); + resetID(child); + } + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/ComponentEditPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/ComponentEditPart.java new file mode 100644 index 0000000..9ed27cc --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/ComponentEditPart.java @@ -0,0 +1,170 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.editparts; + +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.gef.DragTracker; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.RequestConstants; +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.jface.viewers.TextCellEditor; +import org.tizen.efluibuilder.gef.editparts.utility.directedit.ComponentCellEditorLocator; +import org.tizen.efluibuilder.gef.editparts.utility.directedit.ComponentDirectEditManager; +import org.tizen.efluibuilder.gef.editparts.utility.directedit.ComponentNameCellEditorValidator; +import org.tizen.efluibuilder.gef.figure.ComponentFigure; +import org.tizen.efluibuilder.gef.policies.ComponentDataBindingEditPolicy; +import org.tizen.efluibuilder.gef.policies.ComponentDirectEditPolicy; +import org.tizen.efluibuilder.gef.policies.ContentContainerOutlineFeedbackPolicy; +import org.tizen.efluibuilder.gef.policies.CustomSnapFeedbackPolicy; +import org.tizen.efluibuilder.gef.policies.DesignSelectionEditPolicy; +import org.tizen.efluibuilder.gef.policies.ItemOutlineFeedbackPolicy; +import org.tizen.efluibuilder.gef.policies.OpenEdcEditorPolicy; +import org.tizen.efluibuilder.gef.policies.OutlineFeedbackPolicy; +import org.tizen.efluibuilder.gef.policies.containers.CommonChildResizablePolicy; +import org.tizen.efluibuilder.gef.policies.containers.DesignEditorUtil; +import org.tizen.efluibuilder.gef.policies.containers.EditPolicyConstants; +import org.tizen.efluibuilder.gef.tools.DesignDragEditPartsTracker; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.storyboard.gef.policies.NodeGraphicalNodeEditPolicy; + + +public class ComponentEditPart extends DesignEditPart { + + private ComponentDirectEditManager manager; + + @Override + public DragTracker getDragTracker(Request request) { + return new DesignDragEditPartsTracker(this); + } + + @Override + protected void createEditPolicies() { + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new DesignSelectionEditPolicy()); + installEditPolicy(EditPolicyConstants.ROLE_SNAP_FEEDBACK, new CustomSnapFeedbackPolicy()); + installEditPolicy(EditPolicy.COMPONENT_ROLE, new ComponentDataBindingEditPolicy()); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new ComponentDirectEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new CommonChildResizablePolicy()); + installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new NodeGraphicalNodeEditPolicy()); +// installEditPolicy(EditPolicy.COMPONENT_ROLE, new NodeComponentEditPolicy()); + if (this.getModel() instanceof Part) { + Part part = (Part) (this.getModel()); + if (LayoutSchemaConstants.LAYOUT.equals(part.getDescriptorId())) { + installEditPolicy(EditPolicyConstants.ROLE_OPEN_EDITOR, new OpenEdcEditorPolicy()); + } + if (DesignEditorUtil.isContentContainerPart(part)) { + installEditPolicy(EditPolicyConstants.ROLE_CONTAINER_OUTLINE_FEEDBACK, new ContentContainerOutlineFeedbackPolicy()); + } else if (DesignEditorUtil.isItemContainerPart(part)) { + installEditPolicy(EditPolicyConstants.ROLE_CONTAINER_OUTLINE_FEEDBACK, new OutlineFeedbackPolicy()); + } else if (DesignEditorUtil.isItemPart(part)) { + installEditPolicy(EditPolicyConstants.ROLE_CONTAINER_OUTLINE_FEEDBACK, new ItemOutlineFeedbackPolicy()); + } + + } + // installEditPolicy("Double Click", new ComponentDoubleClickEditPolicy()); + // installEditPolicy("Outline Editpolicy", new OutlineFeedbackPolicy()); + } + + @Override + protected IFigure precreateFigure() { + ComponentFigure figure = null; + figure = new ComponentFigure(); + Part model = ((Part) getModel()); + + // This code must have to modify to be used by model's descriptor!!!! + if (model.getDescriptorId().equals(LayoutSchemaConstants.ICON) || model.getDescriptorId().equals(LayoutSchemaConstants.LIST) + || model.getDescriptorId().equals(LayoutSchemaConstants.LISTITEM) || model.getDescriptorId().equals(LayoutSchemaConstants.MULTIBUTTONENTRY) + || model.getDescriptorId().equals(LayoutSchemaConstants.MULTIBUTTONENTRYITEM) || model.getDescriptorId().equals(LayoutSchemaConstants.GENLIST) + || model.getDescriptorId().equals(LayoutSchemaConstants.GENLISTITEM) || model.getDescriptorId().equals(LayoutSchemaConstants.GENGRID) + || model.getDescriptorId().equals(LayoutSchemaConstants.GENGRIDITEM) || model.getDescriptorId().equals(LayoutSchemaConstants.LABEL) + || model.getDescriptorId().equals(LayoutSchemaConstants.INDEX) || model.getDescriptorId().equals(LayoutSchemaConstants.LAYOUT) + || model.getDescriptorId().equals(LayoutSchemaConstants.ENTRY) || model.getDescriptorId().equals(LayoutSchemaConstants.IMAGE)) { + figure.setEnableOutline(true); + } + figure.setSelectionColor(ColorConstants.blue); + return figure; + } + + @Override + public void performRequest(Request request) { + if (request.getType() == RequestConstants.REQ_DIRECT_EDIT) { + if (request instanceof DirectEditRequest && !directEditHitTest(((DirectEditRequest) request).getLocation().getCopy())) + return; + performDirectEdit(); + } else if (request.getType() == RequestConstants.REQ_OPEN) { + CommandStack stack = getViewer().getEditDomain().getCommandStack(); + stack.execute(getCommand(request)); + } + } + + private boolean directEditHitTest(Point requestLoc) { + if (!(getFigure() instanceof ComponentFigure)) + return false; + + IFigure figure = getFigure(); + figure.translateToRelative(requestLoc); + if (figure.containsPoint(requestLoc)) + return true; + return false; + } + + private void setupDirectEdit() { + if (manager == null) { + Part model = (Part) getModel(); + String targetProperty = null; + if (model.getPropertyValue(LayoutSchemaConstants.TEXT) != null) { + targetProperty = LayoutSchemaConstants.TEXT; + } else if (model.getPropertyValue(LayoutSchemaConstants.LABEL) != null) { + targetProperty = LayoutSchemaConstants.LABEL; + } else if (model.getPropertyValue(LayoutSchemaConstants.SUB_LABEL) != null) { + targetProperty = LayoutSchemaConstants.SUB_LABEL; + } + + if (targetProperty != null) { + ComponentFigure figure = (ComponentFigure) getFigure(); + ComponentNameCellEditorValidator validator = new ComponentNameCellEditorValidator(); + manager = new ComponentDirectEditManager(this, TextCellEditor.class, new ComponentCellEditorLocator(figure), model, targetProperty, validator); + } + } + } + + private void performDirectEdit() { + setupDirectEdit(); + if (manager != null) { + manager.show(); + } + } + + public String getPropertyNameDirectEdit() { + if (manager == null) + return null; + + return manager.getPropertyName(); + } + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/ContainerEditPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/ContainerEditPart.java new file mode 100644 index 0000000..a37d2b0 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/ContainerEditPart.java @@ -0,0 +1,184 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.editparts; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.DragTracker; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.tizen.efluibuilder.gef.editparts.utility.CellManager; +import org.tizen.efluibuilder.gef.figure.ContainerFigure; +import org.tizen.efluibuilder.gef.policies.CustomSnapFeedbackPolicy; +import org.tizen.efluibuilder.gef.policies.DesignSelectionEditPolicy; +import org.tizen.efluibuilder.gef.policies.OutlineFeedbackPolicy; +import org.tizen.efluibuilder.gef.policies.containers.BoxLayoutPolicy; +import org.tizen.efluibuilder.gef.policies.containers.CommonLayoutPolicy; +import org.tizen.efluibuilder.gef.policies.containers.ContentLayoutPolicy; +import org.tizen.efluibuilder.gef.policies.containers.EditPolicyConstants; +import org.tizen.efluibuilder.gef.policies.containers.GridLayoutPolicy; +import org.tizen.efluibuilder.gef.policies.containers.PanePlaceholderOutlineFeedbackPolicy; +import org.tizen.efluibuilder.gef.policies.containers.PanesLayoutPolicy; +import org.tizen.efluibuilder.gef.policies.containers.TableLayoutPolicy; +import org.tizen.efluibuilder.gef.policies.containers.TablePlaceholderOutlineFeedbackPolicy; +import org.tizen.efluibuilder.gef.policies.containers.ViewLayoutPolicy; +import org.tizen.efluibuilder.gef.tools.DesignDragEditPartsTracker; +import org.tizen.efluibuilder.gef.tools.DesignMarqueeDragTracker; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.storyboard.gef.policies.NodeComponentEditPolicy; +import org.tizen.efluibuilder.storyboard.gef.policies.NodeGraphicalNodeEditPolicy; + + +public class ContainerEditPart extends DesignEditPart { + + private CellManager cellManager = null; + + @Override + public DragTracker getDragTracker(Request request) { + if (getSelected() == 0) { + return new DesignMarqueeDragTracker(this); + } + + return new DesignDragEditPartsTracker(this); + } + + @Override + protected void createEditPolicies() { + Part part = (Part) getModel(); + if (part instanceof ComponentPart) { + + installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new NodeGraphicalNodeEditPolicy()); + installEditPolicy(EditPolicy.COMPONENT_ROLE, new NodeComponentEditPolicy()); + /* common policy */ + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new DesignSelectionEditPolicy()); + installEditPolicy(EditPolicyConstants.ROLE_SNAP_FEEDBACK, new CustomSnapFeedbackPolicy()); + /* layout policy */ + EditPolicy targetLayoutPolicy = null; + EditPolicy outlineEditPolicy = null; + + if (part.getDescriptorId().equals(LayoutSchemaConstants.GRID)) { + targetLayoutPolicy = new GridLayoutPolicy(); + outlineEditPolicy = new OutlineFeedbackPolicy(); + } else if (part.getDescriptorId().equals(LayoutSchemaConstants.BOX)) { + targetLayoutPolicy = new BoxLayoutPolicy(); + outlineEditPolicy = new OutlineFeedbackPolicy(); + } else if (part.getDescriptorId().equals(LayoutSchemaConstants.TABLE)) { + targetLayoutPolicy = new TableLayoutPolicy(); + outlineEditPolicy = new OutlineFeedbackPolicy(); + installEditPolicy(EditPolicyConstants.ROLE_PLACEHOLDER_FEEDBACK, new TablePlaceholderOutlineFeedbackPolicy()); + } else if (part.getDescriptorId().equals(LayoutSchemaConstants.PANES)) { + targetLayoutPolicy = new PanesLayoutPolicy(); + installEditPolicy(EditPolicyConstants.ROLE_PLACEHOLDER_FEEDBACK, new PanePlaceholderOutlineFeedbackPolicy()); + } else if (part.getDescriptorId().equals(LayoutSchemaConstants.SCROLLER)) { + outlineEditPolicy = new OutlineFeedbackPolicy(); + targetLayoutPolicy = new ContentLayoutPolicy(); + } else if (part.getDescriptorId().equals(LayoutSchemaConstants.PANEL)) { + targetLayoutPolicy = new ContentLayoutPolicy(); + } else if (part.getDescriptorId().equals(LayoutSchemaConstants.VIEW)) { + // targetLayoutPolicy = new ViewLayoutPolicy(); + } else if (part.getDescriptorId().equals(LayoutSchemaConstants.POPUP)) { + targetLayoutPolicy = new ViewLayoutPolicy(); + } else { + targetLayoutPolicy = new CommonLayoutPolicy(); + } + + if (null != targetLayoutPolicy) { + installEditPolicy(EditPolicy.LAYOUT_ROLE, targetLayoutPolicy); + } + + if (null != outlineEditPolicy) { + installEditPolicy(EditPolicyConstants.ROLE_CONTAINER_OUTLINE_FEEDBACK, outlineEditPolicy); + } + } + } + + @Override + protected IFigure precreateFigure() { + Part model = (Part) getModel(); + ContainerFigure figure = null; + if (model instanceof ComponentPart) { + if (null == cellManager) { + cellManager = new CellManager(); + } else { + cellManager.clean(); + } + + figure = new ContainerFigure(cellManager); + // figure.setSelectionColor(ColorConstants.blue); + } + return figure; + } + + public CellManager getCellManager() { + return cellManager; + } + + public int findIndexOfCellByPT(final int x, final int y) { + return cellManager.findIndexOfCellByPT(x, y); + } + + public int findIndexOfCellByPTwithoutWID(final int x, final int y) { + return cellManager.findIndexOfCellByPTwithoutWID(x, y); + } + + public Rectangle getCellByIdx(final int idx) { + return cellManager.getCellByIdx(idx).getBounds(); + } + + public Rectangle getPackByIdx(int i, int colCount) { + int listCnt = cellManager.getCellCount(); + if (i > listCnt) { + return null; + } + // PlaceHolder ph = placeholders.get(i); + int left = i % colCount; + int top = i / colCount; + int width = 1; + int height = 1; + + Rectangle relativePosition = new Rectangle(left, top, width, height); + return relativePosition; + } + + public void refreshCells() { + + if (null != cellManager) { + ((ContainerFigure) (figure)).repaint(); + } + + return; + } + + public int getCellColumCount() { + Part part = (Part) getModel(); + String colcountStr = part.getPropertyValue(LayoutSchemaConstants.TABLE_COLS); + if (null != colcountStr) { + return Integer.parseInt(colcountStr); + } + return 1; + } + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/DesignConnectionEditPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/DesignConnectionEditPart.java new file mode 100644 index 0000000..77ec059 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/DesignConnectionEditPart.java @@ -0,0 +1,87 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.editparts; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.editparts.AbstractConnectionEditPart; +import org.tizen.efluibuilder.gef.policies.DesignConnectionEndpointEditPolicy; +import org.tizen.efluibuilder.gef.viewer.DesignStoryboardRouter; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.ui.resources.ColorResources; + + +public class DesignConnectionEditPart extends AbstractConnectionEditPart { + + private DesignStoryboardPolylineConnection polyline; + private DesignStoryboardRouter router; + + public DesignConnectionEditPart() { + super(); + } + + public String getId() { + Part part = ((Part) getModel()); + if (part != null) { + return part.getUniqueId(); + } else { + return null; + } + } + + protected IFigure createFigure() { + // polyline = new + // StoryBoardPolylineConnection(1.0((DesignViewer)this.getViewer()).getZoomScale()); + polyline = new DesignStoryboardPolylineConnection(this, 1.0); + router = ((DesignViewer) this.getViewer()).getStoryBoardRouter(); + polyline.setConnectionRouter(router); + return polyline; + } + + @Override + protected void createEditPolicies() { + installEditPolicy(EditPolicy.CONNECTION_ENDPOINTS_ROLE, new DesignConnectionEndpointEditPolicy()); + } + + @SuppressWarnings("unchecked") + protected void registerModel() { + getViewer().getEditPartRegistry().put(getId(), this); + } + + @Override + public void setSelected(int selected) { + super.setSelected(selected); + this.refreshFigure(); + } + + public void refreshFigure() { + if (this.getSelected() > 0) { + polyline.setForegroundColor(ColorResources.DESIGN_EDITOR_CONNECTION_SELECTED_COLOR); + } else { + polyline.setForegroundColor(ColorResources.DESIGN_EDITOR_CONNECTION_UNSELECTED_COLOR); + } + this.polyline.layout(); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/DesignEditPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/DesignEditPart.java new file mode 100644 index 0000000..0a28490 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/DesignEditPart.java @@ -0,0 +1,353 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.editparts; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.draw2d.ChopboxAnchor; +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.IClippingStrategy; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.ConnectionEditPart; +import org.eclipse.gef.Disposable; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.NodeEditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.RequestConstants; +import org.eclipse.gef.SnapToHelper; +import org.eclipse.gef.editparts.AbstractGraphicalEditPart; +import org.eclipse.swt.graphics.Color; +import org.tizen.efluibuilder.gef.figure.CommonFigure; +import org.tizen.efluibuilder.gef.figure.DocFigure; +import org.tizen.efluibuilder.gef.policies.CustomSnapFeedbackPolicy; +import org.tizen.efluibuilder.gef.policies.DesignSelectionEditPolicy; +import org.tizen.efluibuilder.gef.policies.OpenEdcEditorPolicy; +import org.tizen.efluibuilder.gef.policies.OutlineFeedbackPolicy; +import org.tizen.efluibuilder.gef.policies.containers.EditPolicyConstants; +import org.tizen.efluibuilder.gef.policies.containers.PlaceholderOutlineFeedbackPolicy; +import org.tizen.efluibuilder.gef.policies.containers.ViewLayoutPolicy; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.DocumentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.ViewPart; +import org.tizen.efluibuilder.model.part.ViewsPart; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.renderer.Position; +import org.tizen.efluibuilder.ui.editor.ruler.DesignerGuide; + + +public class DesignEditPart extends AbstractGraphicalEditPart implements NodeEditPart { + + public static final String VIRTUAL_SCREEN_LAYER = DesignRootEditPart.VIRTUAL_SCREEN_LAYER; + + private DesignerGuide verticalGuide, horizontalGuide; + protected Color selectionColor = ColorConstants.blue; + private Position position = new Position(); + private boolean binded = false; + private boolean flagReveal = false; + + public String getId() { + Part part = ((Part) getModel()); + if (part != null) { + return part.getUniqueId(); + } else { + return null; + } + } + + @Override + protected List getModelChildren() { + if (getModel() instanceof Part) { + return ((Part) getModel()).getComponentChildren(); + } + return new ArrayList(); + } + + @SuppressWarnings("unchecked") + @Override + protected void registerModel() { + getViewer().getEditPartRegistry().put(getId(), this); + } + + @Override + public void activate() { + super.activate(); + } + + @Override + public void deactivate() { + IFigure iFigure = getFigure(); + if (iFigure instanceof Disposable) { + ((Disposable) iFigure).dispose(); + } + + super.deactivate(); + } + + @SuppressWarnings("rawtypes") + @Override + public Object getAdapter(Class key) { + if (key == SnapToHelper.class) { + return null; + } + + return super.getAdapter(key); + } + + public DesignerGuide getVerticalGuide() { + return verticalGuide; + } + + public void setVerticalGuide(DesignerGuide verticalGuide) { + this.verticalGuide = verticalGuide; + } + + public DesignerGuide getHorizontalGuide() { + return horizontalGuide; + } + + public void setHorizontalGuide(DesignerGuide horizontalGuide) { + this.horizontalGuide = horizontalGuide; + } + + public Color getSelectionColor() { + return selectionColor; + } + + public void setSelectionColor(Color color) { + this.selectionColor = color; + } + + public Position getPosition() { + return position; + } + + public boolean setPosition(Position position) { + if (position.equals(this.position)) { + return false; + } + this.position = position; + return true; + } + + protected IFigure precreateFigure() { + Part model = (Part) getModel(); + IFigure figure = null; + if (model instanceof ViewsPart) { + figure = new DocFigure(); + } + return figure; + } + + @Override + protected IFigure createFigure() { + IFigure figure = null; + figure = precreateFigure(); + + // Clipping own area + { + figure.setClippingStrategy(new IClippingStrategy() { + @Override + public Rectangle[] getClip(IFigure childFigure) { + return new Rectangle[] { getChildrenBound(childFigure) }; + } + + private Rectangle getChildrenBound(IFigure f) { + @SuppressWarnings("rawtypes") + List figures = f.getChildren(); + Rectangle rc = f.getBounds().getCopy(); + if (figures != null) { + for (int i = 0; i < figures.size(); i++) { + IFigure child = (IFigure) figures.get(i); + rc.union(getChildrenBound(child)); + } + } + return rc; + } + }); + } + + return figure; + } + + @Override + protected void refreshVisuals() { + Part model = ((Part) getModel()); + if (!(model instanceof ViewsPart)) { + CommonFigure figure = (CommonFigure) getFigure(); + Position position = getPosition(); + if (position != null) { + if (this.getEditPolicy(EditPolicyConstants.ROLE_CONTAINER_OUTLINE_FEEDBACK) instanceof OutlineFeedbackPolicy) { + OutlineFeedbackPolicy policy = (OutlineFeedbackPolicy) this.getEditPolicy(EditPolicyConstants.ROLE_CONTAINER_OUTLINE_FEEDBACK); + policy.setBound(position.getBounds()); + policy.refresh(); + } + if (this.getEditPolicy(EditPolicyConstants.ROLE_PLACEHOLDER_FEEDBACK) instanceof PlaceholderOutlineFeedbackPolicy) { + PlaceholderOutlineFeedbackPolicy policy = + (PlaceholderOutlineFeedbackPolicy) this.getEditPolicy(EditPolicyConstants.ROLE_PLACEHOLDER_FEEDBACK); + policy.refresh(); + } + + if (this.getEditPolicy(EditPolicyConstants.ROLE_OPEN_EDITOR) instanceof OpenEdcEditorPolicy) { + OpenEdcEditorPolicy policy = + (OpenEdcEditorPolicy) this.getEditPolicy(EditPolicyConstants.ROLE_OPEN_EDITOR); + policy.refresh(); + } + + figure.setLayout(position.getBounds()); + } else { + figure.setLayout(new Rectangle(0, 0, 0, 0)); + } + DocumentPart documentPart = model.getOwnerDocumentPart(); + if (documentPart == null) { // check is removed; + return; + } + ComponentDescriptor componentDescriptor = documentPart.getComponentDescriptor(); + if (model instanceof ComponentPart) { + figure.setBorder(componentDescriptor.canBeVisibleBorder((ComponentPart) model)); + } + } + } + + public void refreshUI() { + this.refreshVisuals(); + } + + public void reorderChildren() { + List modelChildren = this.getModelChildren(); + List children = this.getChildren(); + int childIndex; + for (int j = modelChildren.size() - 1; j >= 0; j--) { + childIndex = children.indexOf(modelChildren.get(j)); + if (childIndex >= 0 && childIndex != j) { + this.reorderChild(children.get(childIndex), j); + } + } + } + + public void refreshChildren2() { + List children = this.getChildren(); + List modelChildren = this.getModelChildren(); + List removedList = new ArrayList(); + boolean isExist = false; + for (int i = 0; i < children.size(); i++) { + isExist = false; + for (int j = 0; j < modelChildren.size(); j++) { + if (children.get(i).getModel() == modelChildren.get(j)) { + isExist = true; + break; + } + if (isExist == false) { + removedList.add(children.get(i)); + } + } + } + for (EditPart editpart : removedList) { + if (editpart.getParent() != null && (editpart.getParent() instanceof DesignEditPart)) { + DesignEditPart parent = (DesignEditPart) editpart.getParent(); + // parent.removeChildVisual(editpart); + parent.removeChild(editpart); + } + } + super.refreshChildren(); + } + + @Override + protected void createEditPolicies() { + Part part = (Part) getModel(); + if (part instanceof ViewPart) { + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new DesignSelectionEditPolicy()); + installEditPolicy(EditPolicyConstants.ROLE_SNAP_FEEDBACK, new CustomSnapFeedbackPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new ViewLayoutPolicy()); + } + } + + @Override + public void setSelected(int value) { + super.setSelected(value); + if (this.getEditPolicy(EditPolicyConstants.ROLE_CONTAINER_OUTLINE_FEEDBACK) instanceof OutlineFeedbackPolicy) { + OutlineFeedbackPolicy policy = (OutlineFeedbackPolicy) this.getEditPolicy(EditPolicyConstants.ROLE_CONTAINER_OUTLINE_FEEDBACK); + policy.refresh(); + } + + if (this.getEditPolicy(EditPolicyConstants.ROLE_OPEN_EDITOR) instanceof OpenEdcEditorPolicy) { + OpenEdcEditorPolicy policy = (OpenEdcEditorPolicy) this.getEditPolicy(EditPolicyConstants.ROLE_OPEN_EDITOR); + policy.refresh(); + } + } + + @Override + public boolean isSelectable() { + return true; + } + + public boolean isBinded() { + return binded; + } + + public void setBinded(boolean binded) { + this.binded = binded; + } + + @Override + public ChopboxAnchor getSourceConnectionAnchor(ConnectionEditPart arg0) { + IFigure ifigure = getFigure(); + return new ChopboxAnchor(ifigure); + } + + @Override + public ChopboxAnchor getSourceConnectionAnchor(Request arg0) { + IFigure ifigure = getFigure(); + return new ChopboxAnchor(ifigure); + } + + @Override + public ChopboxAnchor getTargetConnectionAnchor(ConnectionEditPart arg0) { + return null; + } + + @Override + public ChopboxAnchor getTargetConnectionAnchor(Request arg0) { + IFigure ifigure = getFigure(); + return new ChopboxAnchor(ifigure); + } + + public EditPart getTargetEditPart(Request request) { + if (request.getType().equals(RequestConstants.REQ_CONNECTION_END)) { + return getParent().getTargetEditPart(request); + } + return super.getTargetEditPart(request); + } + + public boolean getFlagReveal() { + return flagReveal; + } + + public void setFlagReveal(boolean bReveal) { + flagReveal = bReveal; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/DesignEditPartFactory.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/DesignEditPartFactory.java new file mode 100644 index 0000000..67ad1ad --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/DesignEditPartFactory.java @@ -0,0 +1,66 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.editparts; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPartFactory; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; + + +public class DesignEditPartFactory implements EditPartFactory { + + @Override + public EditPart createEditPart(EditPart context, Object model) { + EditPart retValue = null; + if (model instanceof Part) { + Part partModel = (Part) model; + + if (partModel.getType() == PartType.VIEWS) { + retValue = new DesignEditPart(); + retValue.setModel(model); + } else if (partModel.getType() == PartType.VIEW) { + retValue = new ViewEditPart(); + retValue.setModel(model); + } else if (partModel.getType() == PartType.COMPONENT) { + ComponentDescriptor componentDescriptor = partModel.getOwnerDocumentPart().getComponentDescriptor(); + if (componentDescriptor.isContainer((ComponentPart) partModel)) { + retValue = new ContainerEditPart(); + } else { + retValue = new ComponentEditPart(); + } + retValue.setModel(model); + } else if (partModel.getType() == PartType.EVENT && partModel.hasProperty(LayoutSchemaConstants.EVENT_CONNECTION)) { + retValue = new DesignConnectionEditPart(); + retValue.setModel(model); + } + + } + + return retValue; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/DesignRootEditPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/DesignRootEditPart.java new file mode 100644 index 0000000..3e4a835 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/DesignRootEditPart.java @@ -0,0 +1,120 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.editparts; + +import org.eclipse.draw2d.ConnectionLayer; +import org.eclipse.draw2d.DelegatingLayout; +import org.eclipse.draw2d.FreeformLayer; +import org.eclipse.draw2d.Layer; +import org.eclipse.draw2d.LayeredPane; +import org.eclipse.draw2d.ScalableFreeformLayeredPane; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.DragTracker; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.editparts.GuideLayer; +import org.eclipse.gef.editparts.ScalableFreeformRootEditPart; +import org.tizen.efluibuilder.gef.editparts.utility.VirtualLayer; +import org.tizen.efluibuilder.gef.layers.BlockLayer; +import org.tizen.efluibuilder.gef.layers.CustomLayerConstants; +import org.tizen.efluibuilder.gef.layers.OutlineLayer; +import org.tizen.efluibuilder.gef.policies.containers.ViewTemplateLayoutPolicy; +import org.tizen.efluibuilder.gef.tools.DesignRootMarqueeDragTracker; +import org.tizen.efluibuilder.ui.editor.ZoomUtil; + + +public class DesignRootEditPart extends ScalableFreeformRootEditPart { + + public static final String VIRTUAL_SCREEN_LAYER = "virtual"; + + public DesignRootEditPart() { + super(); + getZoomManager().setZoomLevels(ZoomUtil.zoomLevels); + ((BlockLayer) getLayer(CustomLayerConstants.BLOCK_LAYER)).setViewPort(getZoomManager().getViewport()); + createEditPolicies(); + } + + @Override + protected void createLayers(LayeredPane layeredPane) { + layeredPane.add(new ConnectionLayer(), CONNECTION_LAYER); + layeredPane.add(getScaledLayers(), SCALABLE_LAYERS); + layeredPane.add(new OutlineLayer(), CustomLayerConstants.OUTLINE_LAYER); + layeredPane.add(new OutlineLayer(), FEEDBACK_LAYER); + layeredPane.add(new GuideLayer(), GUIDE_LAYER); + layeredPane.add(new FreeformLayer(), HANDLE_LAYER); + Layer layer = (Layer) getLayer(HANDLE_LAYER); +// layeredPane.add(new ConnectionLayer(), EditPartConstants.SECOND_CONNECTION_LAYER); + BlockLayer blockLayer = new BlockLayer(); + blockLayer.setVisible(false); + layeredPane.add(blockLayer, CustomLayerConstants.BLOCK_LAYER); + layer.setLayoutManager(new DelegatingLayout()); + } + + @Override + protected ScalableFreeformLayeredPane createScaledLayers() { + ScalableFreeformLayeredPane layers = super.createScaledLayers(); + + VirtualLayer layer = new VirtualLayer(); + layer.setZoomManager(getZoomManager()); + layers.add(layer, VIRTUAL_SCREEN_LAYER); + + return layers; + } + + public Rectangle getVirtualLayerSize() { + VirtualLayer virtualLayer = (VirtualLayer) getLayer(VIRTUAL_SCREEN_LAYER); + return virtualLayer.getVirtualSize(); + } + + public void setVirtualLayerSize(Rectangle bound, float scale) { + VirtualLayer virtualLayer = (VirtualLayer) getLayer(VIRTUAL_SCREEN_LAYER); + virtualLayer.setVirtualSize(bound); + virtualLayer.invalidate(); + } + + @Override + protected void createEditPolicies() { + installEditPolicy(EditPolicy.LAYOUT_ROLE, new ViewTemplateLayoutPolicy()); + } + + @Override + public DragTracker getDragTracker(Request request) { + return new DesignRootMarqueeDragTracker(this); + } + + @Override + public Command getCommand(Request request) { + Command command = null; + EditPolicyIterator i = getEditPolicyIterator(); + while (i.hasNext()) { + if (command != null) + command = command.chain(i.next().getCommand(request)); + else + command = i.next().getCommand(request); + } + return command; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/DesignStoryboardPolylineConnection.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/DesignStoryboardPolylineConnection.java new file mode 100644 index 0000000..01b4aa2 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/DesignStoryboardPolylineConnection.java @@ -0,0 +1,104 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.editparts; + +import org.eclipse.draw2d.ImageFigure; +import org.eclipse.draw2d.PolylineConnection; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.gef.EditPart; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.ui.resources.ColorResources; +import org.tizen.efluibuilder.ui.resources.ImageResources; + + +public class DesignStoryboardPolylineConnection extends PolylineConnection { + + EditPart editPart = null; + Part part = null; + private ImageFigure endPointIcon; + private final static int EndPointIconSize = 18; + + public DesignStoryboardPolylineConnection(EditPart editpart, double scale) { + this.editPart = editpart; + this.part = (Part) editpart.getModel(); + updateLineWidth(scale); + setAntialias(SWT.ON); + setLineWidth(3); + endPointIcon = new ImageFigure(ImageResources.getImage(ImageResources.EDITOR_CONNECTION_END_POINT_NOR_H)); + endPointIcon.setSize(EndPointIconSize, EndPointIconSize); + setForegroundColor(ColorResources.DESIGN_EDITOR_CONNECTION_UNSELECTED_COLOR); + add(endPointIcon); + } + + public void updateLineWidth(double scale) { + if (scale <= 0.5) { + setLineWidth(2); + } else { + setLineWidth(3); + } + } + + public Part getOwnerPart() { + return this.part; + } + + public void decorate(boolean isVertical, boolean isCtxPopupTarget, double zoomScale) { + Point pos; + if (isVertical) { + pos = new Point(getPoints().getLastPoint().x - EndPointIconSize / 2, getPoints().getLastPoint().y - EndPointIconSize); + } else { + pos = new Point(getPoints().getLastPoint().x - EndPointIconSize, getPoints().getLastPoint().y - EndPointIconSize / 2); + } + + endPointIcon.setLocation(pos); + + Image img = null; + if (editPart.getSelected() > 0) { + if (isVertical) { + img = ImageResources.getImage(ImageResources.EDITOR_CONNECTION_END_POINT_SEL_V); + } else { + img = ImageResources.getImage(ImageResources.EDITOR_CONNECTION_END_POINT_SEL_H); + } + } else { + if (isVertical) { + img = ImageResources.getImage(ImageResources.EDITOR_CONNECTION_END_POINT_NOR_V); + } else { + img = ImageResources.getImage(ImageResources.EDITOR_CONNECTION_END_POINT_NOR_H); + } + } + + if (img != endPointIcon.getImage()) { + endPointIcon.setImage(img); + } + + if (isCtxPopupTarget) { + this.setLineStyle(SWT.LINE_DASH); + } + + updateLineWidth(zoomScale); + + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/ViewEditPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/ViewEditPart.java new file mode 100644 index 0000000..34959fb --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/ViewEditPart.java @@ -0,0 +1,179 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.editparts; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.draw2d.ChopboxAnchor; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.ConnectionEditPart; +import org.eclipse.gef.DragTracker; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.RequestConstants; +import org.eclipse.gef.requests.CreateConnectionRequest; +import org.tizen.efluibuilder.gef.figure.CommonFigure; +import org.tizen.efluibuilder.gef.figure.ViewFigure; +import org.tizen.efluibuilder.gef.policies.FitSingleViewPolicy; +import org.tizen.efluibuilder.gef.policies.containers.EditPolicyConstants; +import org.tizen.efluibuilder.gef.policies.containers.ViewMovePolicy; +import org.tizen.efluibuilder.gef.tools.DesignDragViewEditPartTracker; +import org.tizen.efluibuilder.gef.viewer.DesignStoryboardUtil; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.renderer.Position; +import org.tizen.efluibuilder.storyboard.gef.policies.NodeComponentEditPolicy; +import org.tizen.efluibuilder.storyboard.gef.policies.NodeGraphicalNodeEditPolicy; + + +public class ViewEditPart extends DesignEditPart { + @Override + public DragTracker getDragTracker(Request request) { + return new DesignDragViewEditPartTracker(this); + } + + protected void createEditPolicies() { + super.createEditPolicies(); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ViewMovePolicy()); + installEditPolicy(EditPolicyConstants.ROLE_OPEN_EDITOR, new FitSingleViewPolicy()); + installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new NodeGraphicalNodeEditPolicy()); + installEditPolicy(EditPolicy.COMPONENT_ROLE, new NodeComponentEditPolicy()); + // installEditPolicy(EditPolicyConstants.ROLE_CONTAINER_OUTLINE_FEEDBACK, new + // OutlineFeedbackPolicy()); + } + + public void update() { + refreshSourceConnections(); + refreshTargetConnections(); + refreshVisuals(); + } + + @Override + public ChopboxAnchor getSourceConnectionAnchor(ConnectionEditPart arg0) { + IFigure ifigure = getFigure(); + return new ChopboxAnchor(ifigure); + } + + @Override + public ChopboxAnchor getSourceConnectionAnchor(Request arg0) { + IFigure ifigure = getFigure(); + return new ChopboxAnchor(ifigure); + } + + @Override + public ChopboxAnchor getTargetConnectionAnchor(ConnectionEditPart arg0) { + IFigure ifigure = getFigure(); + if (ifigure instanceof ViewFigure) { + return new ChopboxAnchor(ifigure); + } + return null; + } + + @Override + public ChopboxAnchor getTargetConnectionAnchor(Request arg0) { + IFigure ifigure = getFigure(); + if (ifigure instanceof ViewFigure) { + return new ChopboxAnchor(ifigure); + } + return null; + } + + protected List getModelSourceConnections() { + return DesignStoryboardUtil.getConnectionPart((Part) this.getModel()); + } + + protected List getModelTargetConnections() { + return new ArrayList(); + // return ((ComponentPart) getModel()).getTargetConnections(); + } + + protected void refreshVisuals() { + refreshSourceConnections(); + refreshTargetConnections(); + ViewFigure figure = (ViewFigure) getFigure(); + Position position = getPosition(); + if (position != null) { + figure.setLayout(position.getBounds()); + } else { + figure.setLayout(new Rectangle(0, 0, 0, 0)); + } + figure.repaintTitle(); + } + + @Override + public void setSelected(int value) { + super.setSelected(value); + ViewFigure figure = (ViewFigure) getFigure(); + figure.repaintTitle(); + } + + public void moveFigure(Point delta) { + CommonFigure figure = (CommonFigure) getFigure(); + Position position = getPosition(); + if (position != null) { + Rectangle deltaRect = new Rectangle(position.getBounds()); + deltaRect.x += delta.x; + deltaRect.y += delta.y; + figure.setLayout(deltaRect); + } + } + + public EditPart getTargetEditPart(Request request) { + if (request.getType().equals(RequestConstants.REQ_CONNECTION_END)) { + CreateConnectionRequest req = (CreateConnectionRequest) request; + EditPart sourceEditpart = req.getSourceEditPart(); + while (sourceEditpart != null && sourceEditpart instanceof ViewEditPart == false) { + sourceEditpart = sourceEditpart.getParent(); + } + + if (this == sourceEditpart) { + return null; + } + + return this; + } + return super.getTargetEditPart(request); + } + + protected IFigure precreateFigure() { + IFigure figure = null; + figure = new ViewFigure(getViewer().getControl().getDisplay().getSystemFont(), this, + ((DesignRootEditPart) getViewer().getRootEditPart()).getZoomManager()); + ((ViewFigure) figure).setProfile(((DesignViewer) getViewer()).getProfile()); + ((ViewFigure) figure).setSelectionColor(selectionColor); + + return figure; + } + + public void performRequest(Request request) { + if (request.getType() == RequestConstants.REQ_OPEN) { + getCommand(request); + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/utility/CellManager.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/utility/CellManager.java new file mode 100644 index 0000000..0102eb7 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/utility/CellManager.java @@ -0,0 +1,97 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.editparts.utility; + +import java.util.LinkedList; +import java.util.List; + +import org.tizen.efluibuilder.renderer.PlaceholderPosition; + + +public class CellManager { + + private List cellList = new LinkedList(); + + public void clean() { + cellList.clear(); + } + + public void addCell(final int wid, final int x, final int y, final int w, final int h) { + PlaceholderPosition position = new PlaceholderPosition(); + position.wid = wid; + position.x = x; + position.y = y; + position.width = w; + position.height = h; + cellList.add(position); + } + + public int getCellCount() { + return cellList.size(); + } + + public List getCells() { + return cellList; + } + + public PlaceholderPosition getCellByIdx(final int _index) { + return cellList.get(_index); + } + + public int findIndexOfCellByPT(final int x, final int y) { + + if (null != cellList) { + + int reval = 0; + + for (PlaceholderPosition cell : cellList) { + if (cell.getBounds().contains(x, y) && cell.wid == -1) { + return reval; + } + reval++; + + } + } + + return -1; + } + + public int findIndexOfCellByPTwithoutWID(final int x, final int y) { + + if (null != cellList) { + + int reval = 0; + + for (PlaceholderPosition cell : cellList) { + if (cell.getBounds().contains(x, y)) { + return reval; + } + reval++; + + } + } + + return -1; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/utility/VirtualLayer.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/utility/VirtualLayer.java new file mode 100644 index 0000000..530442c --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/utility/VirtualLayer.java @@ -0,0 +1,65 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.editparts.utility; + +import org.eclipse.draw2d.Layer; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.editparts.ZoomManager; + + +public class VirtualLayer extends Layer { + + private Rectangle virtualSize; + private ZoomManager zoomManager = null; + + /* + * (non-Javadoc) + * + * @see org.eclipse.draw2d.Figure#getBounds() + */ + @Override + public Rectangle getBounds() { + if (virtualSize != null) { + Rectangle r = virtualSize.getCopy(); + if (zoomManager != null) { + double zoom = zoomManager.getZoom(); + r.scale(zoom, zoom); + } + return r; + } + return Rectangle.SINGLETON; + } + + public void setZoomManager(ZoomManager zoomManager) { + this.zoomManager = zoomManager; + } + + public Rectangle getVirtualSize() { + return virtualSize; + } + + public void setVirtualSize(Rectangle virtualSize) { + this.virtualSize = virtualSize; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/utility/directedit/ComponentCellEditorLocator.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/utility/directedit/ComponentCellEditorLocator.java new file mode 100644 index 0000000..2539c4a --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/utility/directedit/ComponentCellEditorLocator.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.gef.editparts.utility.directedit; + +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.tools.CellEditorLocator; +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Text; +import org.tizen.efluibuilder.gef.figure.ComponentFigure; + + +/** + * A CellEditorLocator for a specified label + * + * @author Phil Zoio + */ +public class ComponentCellEditorLocator implements CellEditorLocator { + + private ComponentFigure widgetFigure; + + public ComponentCellEditorLocator(ComponentFigure widgetFigure) { + this.widgetFigure = widgetFigure; + } + + public void relocate(CellEditor celleditor) { + Text textCtrl = (Text) celleditor.getControl(); + Point pref = textCtrl.computeSize(SWT.DEFAULT, SWT.DEFAULT); + Rectangle rect = widgetFigure.getBounds().getCopy(); + widgetFigure.translateToAbsolute(rect); + textCtrl.setBounds(rect.x - 1, rect.y - 1, pref.x + 1, pref.y + 1); + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/utility/directedit/ComponentDirectEditManager.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/utility/directedit/ComponentDirectEditManager.java new file mode 100644 index 0000000..1fabe43 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/utility/directedit/ComponentDirectEditManager.java @@ -0,0 +1,84 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.editparts.utility.directedit; + +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.tools.CellEditorLocator; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.swt.events.VerifyEvent; +import org.eclipse.swt.events.VerifyListener; +import org.eclipse.swt.widgets.Text; +import org.tizen.efluibuilder.model.part.Part; + + +public class ComponentDirectEditManager extends DirectEditManager { + + private VerifyListener verifyListener; + private Part model; + private String originalValue; + private String propertyName; + + public ComponentDirectEditManager(GraphicalEditPart source, Class editorType, CellEditorLocator locator, Part model, String propertyName, + ICellEditorValidator validator) { + super(source, editorType, locator); + this.model = model; + this.originalValue = ""; + this.propertyName = propertyName; + } + + protected void initCellEditor() { + verifyListener = new VerifyListener() { + public void verifyText(VerifyEvent event) { + // Text text = (Text) getCellEditor().getControl(); + // String oldText = text.getText(); + } + + }; + + Text textCtrl = (Text) getCellEditor().getControl(); + textCtrl.addVerifyListener(verifyListener); + + // set the initial value of the + originalValue = model.getPropertyValue(propertyName); + if (null != originalValue) { + getCellEditor().setValue(originalValue); + } + textCtrl.selectAll(); + } + + protected void unhookListeners() { + super.unhookListeners(); + + if (verifyListener != null) { + Text textCtrl = (Text) getCellEditor().getControl(); + textCtrl.removeVerifyListener(verifyListener); + verifyListener = null; + } + } + + public String getPropertyName() { + return this.propertyName; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/utility/directedit/ComponentNameCellEditorValidator.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/utility/directedit/ComponentNameCellEditorValidator.java new file mode 100644 index 0000000..6c2d4e7 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/editparts/utility/directedit/ComponentNameCellEditorValidator.java @@ -0,0 +1,41 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.editparts.utility.directedit; + +import org.eclipse.jface.viewers.ICellEditorValidator; + + +public class ComponentNameCellEditorValidator implements ICellEditorValidator { + + public ComponentNameCellEditorValidator() { + } + + public String isValid(Object value) { + String text = (String) value; + // if (text.isEmpty()) { + // N/A + // } + return text; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/ActionRunnableLable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/ActionRunnableLable.java new file mode 100644 index 0000000..c9a9101 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/ActionRunnableLable.java @@ -0,0 +1,26 @@ + + +package org.tizen.efluibuilder.gef.figure; + +import org.eclipse.draw2d.Label; + + +public class ActionRunnableLable extends Label implements IActionTriggerable { + + private String triggerString = ""; + + public ActionRunnableLable(String triggerString) { + super(); + this.triggerString = triggerString; + } + + @Override + public String getTriggerString() { + return triggerString; + } + + public void setTriggerString(String triggerString) { + this.triggerString = triggerString; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/CommonFigure.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/CommonFigure.java new file mode 100644 index 0000000..e8b140e --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/CommonFigure.java @@ -0,0 +1,186 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.figure; + +import java.util.List; + +import org.eclipse.draw2d.AbstractBackground; +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.Figure; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.LineBorder; +import org.eclipse.draw2d.XYLayout; +import org.eclipse.draw2d.geometry.Insets; +import org.eclipse.draw2d.geometry.PointList; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.swt.graphics.Color; + + +public class CommonFigure extends Figure { + + private static final int LINEWIDTH = 1; + private static final int BORDER_ALPHA = 60; + + private XYLayout layout; + private boolean borderVisible = false; + private Color selectionColor = ColorConstants.blue; + private PointList polygonPoints; + + @SuppressWarnings("unchecked") + protected boolean containtsInChidren(IFigure f, int x, int y) { + List children = f.getChildren(); + if (children != null) { + for (int i = 0; i < children.size(); i++) { + if (containtsInChidren(children.get(i), x, y)) { + return true; + } + if (children.get(i).containsPoint(x, y)) + return true; + } + } + return false; + } + + @SuppressWarnings("rawtypes") + protected Rectangle getChildrenBound(IFigure f) { + List figures = f.getChildren(); + Rectangle bounds = f.getBounds().getCopy(); + if (figures != null) { + for (int i = 0; i < figures.size(); i++) { + IFigure child = (IFigure) figures.get(i); + bounds.union(getChildrenBound(child)); + } + } + return bounds; + } + + protected void drawRectangle(Graphics graphics, int lineWidth, int style, Rectangle bounds) { + graphics.setLineWidth(lineWidth); + graphics.setLineStyle(style); + graphics.drawRectangle(bounds); + } + + public CommonFigure() { + layout = new XYLayout(); + setLayoutManager(layout); + + setForegroundColor(ColorConstants.blue); + setBorder(new LineBorder(2)); + } + + @Override + public boolean containsPoint(int x, int y) { + if (containtsInChidren(this, x, y)) { + return true; + } else { + if (polygonPoints != null) { + return polygonPoints.polygonContainsPoint(x, y); + } else { + return super.containsPoint(x, y); + } + } + } + + @Override + public Rectangle getClientArea(Rectangle rect) { + rect.setBounds(getChildrenBound(this)); + if (useLocalCoordinates()) + rect.setLocation(0, 0); + return rect; + } + + @Override + protected void paintFigure(Graphics graphics) { + if (isOpaque()) { + if (polygonPoints != null) { + graphics.drawPolygon(polygonPoints); + } else { + graphics.fillRectangle(getBounds()); + } + } + + if (getBorder() instanceof AbstractBackground) { + ((AbstractBackground) getBorder()).paintBackground(this, graphics, NO_INSETS); + } + } + + @Override + protected void paintBorder(Graphics graphics) { + + boolean isBoarderOutsider = false; + Rectangle edgeBounds = bounds.getShrinked(new Insets(0, 0, 1, 1)); + + if (getParent() != null) { + if (!getParent().getBounds().intersects(edgeBounds)) { + isBoarderOutsider = true; + } + } + + if (isBoarderOutsider) { + graphics.pushState(); + graphics.setAlpha(BORDER_ALPHA); + graphics.setForegroundColor(ColorConstants.black); + drawRectangle(graphics, LINEWIDTH, Graphics.LINE_DOT, edgeBounds); + graphics.drawLine(edgeBounds.getBottomLeft(), edgeBounds.getTopRight()); + graphics.drawLine(edgeBounds.getBottomRight(), edgeBounds.getTopLeft()); + graphics.popState(); + } else { + if (borderVisible) { + graphics.pushState(); + graphics.setAlpha(BORDER_ALPHA); + graphics.setForegroundColor(ColorConstants.blue); + drawRectangle(graphics, LINEWIDTH, Graphics.LINE_SOLID, edgeBounds); + graphics.popState(); + } + } + } + + public void setLayout(Rectangle bounds) { + if (bounds == null) { + return; + } + this.polygonPoints = null; + setBounds(bounds); + } + + public void setLayout(PointList polygonPoints) { + if (polygonPoints != null) { + this.polygonPoints = polygonPoints; + setBounds(polygonPoints.getBounds()); + } + } + + public void setBorder(boolean visible) { + this.borderVisible = visible; + } + + public void setSelectionColor(Color color) { + selectionColor = color; + } + + public Color getSelectionColor() { + return selectionColor; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/CommonRectangleFigure.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/CommonRectangleFigure.java new file mode 100644 index 0000000..b3ffc17 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/CommonRectangleFigure.java @@ -0,0 +1,60 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.figure; + +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.RectangleFigure; +import org.eclipse.swt.graphics.Color; + + +public class CommonRectangleFigure extends RectangleFigure { + private int alphaBgColor = -1; + private int alphaFgColor = -1; + + @Override + protected void fillShape(Graphics graphics) { + if (this.alphaBgColor >= 0) { + graphics.setAlpha(this.alphaBgColor); + } + super.fillShape(graphics); + } + + @Override + protected void outlineShape(Graphics graphics) { + if (this.alphaFgColor >= 0) { + graphics.setAlpha(this.alphaFgColor); + } + super.outlineShape(graphics); + } + + public void setForegroundColor(Color color, int alpha) { + this.alphaFgColor = alpha; + super.setForegroundColor(color); + } + + public void setBackgroundColor(Color color, int alpha) { + this.alphaBgColor = alpha; + super.setForegroundColor(color); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/ComponentFigure.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/ComponentFigure.java new file mode 100644 index 0000000..628710b --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/ComponentFigure.java @@ -0,0 +1,84 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.figure; + +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.swt.graphics.Image; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; +import org.tizen.efluibuilder.ui.view.databinding.utils.ResourceManager; + + +public class ComponentFigure extends CommonFigure { + + private static final int LINEWIDTH = 1; + + private boolean bOutline = false; + + private boolean isBinded = false; + + public ComponentFigure() { + super(); + setBackgroundColor(ColorConstants.lightGreen); + setOpaque(false); + } + + @Override + protected void paintFigure(Graphics graphics) { + if (bOutline) { + // graphics.pushState(); + // Rectangle drawBounds = getBounds().getCopy(); + // drawBounds.width -= LINEWIDTH; + // drawBounds.height -= LINEWIDTH; + // graphics.setForegroundColor(ColorConstants.gray); + // drawRectangle(graphics, LINEWIDTH, Graphics.LINE_DASH, drawBounds); + // graphics.popState(); + } + // data binding icon check + if (isBinded) { + Image img = + ResourceManager.getImage(BuilderConstants.ICON_DIR, + BuilderConstants.DATABINDING_BINDING_IMAGE); + if (null == img) { + Rectangle r = new Rectangle(getBounds().x + 5, getBounds().y + 5, 10, 15); + graphics.setAlpha(90); + graphics.setForegroundColor(ColorConstants.blue); + graphics.setBackgroundColor(ColorConstants.red); + graphics.fillRectangle(r); + graphics.drawText("B", getBounds().x + 5, getBounds().y + 5); + } else { + graphics.drawImage(img, getBounds().x + 5, getBounds().y + 5); + } + } + } + + public void setBinded(boolean isBinded) { + this.isBinded = isBinded; + } + + public void setEnableOutline(boolean value) { + this.bOutline = value; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/ContainerFigure.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/ContainerFigure.java new file mode 100644 index 0000000..db7da23 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/ContainerFigure.java @@ -0,0 +1,83 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.figure; + +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.Graphics; +import org.tizen.efluibuilder.gef.editparts.utility.CellManager; + + +public class ContainerFigure extends CommonFigure { + + public ContainerFigure(CellManager cellManagerHandle) { + super(); + setBackgroundColor(ColorConstants.blue); + setOpaque(false); + } + + @Override + protected void paintFigure(Graphics graphics) { + // graphics.pushState(); + // + // // draw edge-line + // { + // Rectangle edgeBounds = getBounds().getCopy(); + // // edgeBounds.width -= LINEWIDTH; + // // edgeBounds.height -= LINEWIDTH; + // + // graphics.setLineWidth(LINEWIDTH); + // graphics.setLineStyle(Graphics.LINE_DASH); + // graphics.setForegroundColor(ColorResources.DESIGN_EDITOR_PLACEHOLDER_LINE_COLOR); + // graphics.setForegroundColor(ColorResources.DESIGN_EDITOR_CHANGE_BOUND_FEEDBACK_LINE_COLOR); + // graphics.setLineDash(dashStyle); + // graphics.drawRectangle(edgeBounds); + // } + // // draw figure + // if (null != cellManagerHandle) { + // // graphics.setAlpha(HOVER_ALPHA); + // + // int listCnt = cellManagerHandle.getCellCount(); + // for (int i = 0; i < listCnt; i++) { + // + // PlaceholderPosition cell = cellManagerHandle.getCellByIdx(i); + // + // if (null != cell) { + // Rectangle areaRect = new Rectangle(cell.getBounds()); + // // areaRect.x += LINEWIDTH; + // // areaRect.y += LINEWIDTH; + // // areaRect.width -= LINEWIDTH * PADDING; + // // areaRect.height -= LINEWIDTH * PADDING; + // + // graphics.setLineWidth(LINEWIDTH); + // graphics.setLineStyle(Graphics.LINE_CUSTOM); + // graphics.setLineDash(dashStyle); + // graphics.setForegroundColor(ColorResources.DESIGN_EDITOR_PLACEHOLDER_LINE_COLOR); + // graphics.drawRectangle(areaRect); + // } + // } + // } + // + // graphics.popState(); + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/DocFigure.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/DocFigure.java new file mode 100644 index 0000000..1ae3d5c --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/DocFigure.java @@ -0,0 +1,34 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.figure; + +import org.eclipse.draw2d.FreeformLayer; + + +public class DocFigure extends FreeformLayer { + + public DocFigure() { + super(); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/IActionTriggerable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/IActionTriggerable.java new file mode 100644 index 0000000..e1f2a81 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/IActionTriggerable.java @@ -0,0 +1,5 @@ +package org.tizen.efluibuilder.gef.figure; + +public interface IActionTriggerable { + public String getTriggerString(); +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/PolygonFigure.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/PolygonFigure.java new file mode 100644 index 0000000..09fda58 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/PolygonFigure.java @@ -0,0 +1,108 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.figure; + +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.RectangleFigure; +import org.eclipse.draw2d.geometry.PointList; +import org.eclipse.draw2d.geometry.Rectangle; + + +/** + * The Class PolygonFigure. + */ +public class PolygonFigure extends RectangleFigure { + + private PointList polygonPoints = null; + + /* + * (non-Javadoc) + * + * @see org.eclipse.draw2d.Figure#getBounds() + */ + @Override + public Rectangle getBounds() { + if (polygonPoints != null) { + return polygonPoints.getBounds(); + } + return super.getBounds(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.draw2d.RectangleFigure#fillShape(org.eclipse.draw2d.Graphics) + */ + @Override + protected void fillShape(Graphics graphics) { + if (polygonPoints != null) { + graphics.fillPolygon(polygonPoints); + } + super.fillShape(graphics); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.draw2d.RectangleFigure#outlineShape(org.eclipse.draw2d.Graphics) + */ + @Override + protected void outlineShape(Graphics graphics) { + if (polygonPoints != null) { + graphics.fillPolygon(polygonPoints); + } + super.outlineShape(graphics); + } + + /** + * Gets the polygon points. + * + * @return the polygon points + */ + public PointList getPolygonPoints() { + return polygonPoints; + } + + /** + * Sets the polygon points. + * + * @param polygonPoints + * the new polygon points + */ + public void setPolygonPoints(PointList polygonPoints) { + this.polygonPoints = polygonPoints; + } + + @Override + public void paintFigure(Graphics graphics) { + // super.paintFigure(graphics); + + if (getPolygonPoints() != null) { + graphics.pushState(); + graphics.setAlpha(this.getAlpha()); + graphics.fillPolygon(getPolygonPoints()); + graphics.popState(); + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/ViewFigure.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/ViewFigure.java new file mode 100644 index 0000000..65cb3c4 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/ViewFigure.java @@ -0,0 +1,190 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.figure; + +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.Disposable; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.editparts.ZoomManager; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Path; +import org.eclipse.swt.widgets.Display; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.core.configurator.ConfiguratorConstants; +import org.tizen.efluibuilder.gef.policies.containers.DesignEditorUtil; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.ui.resources.ColorResources; +import org.tizen.efluibuilder.utility.CachedImage; +import org.tizen.efluibuilder.utility.ImageUtil; + + +/** + * It MUST be disposed explicitly by deactivate method of EditPart. + */ +public class ViewFigure extends CommonFigure implements Disposable { + + private Logger logger = LoggerFactory.getLogger(this.getClass()); + + private ImageDescriptor imageDescriptor = null; + private String profile = null; + + private final CachedImage cache = new CachedImage(); + + Part ownerPart = null; + EditPart ownerEditpart = null; + private ViewTitleFigure titleFigure = null; + + private boolean isSelected() { + if (ownerEditpart != null && ownerEditpart.getSelected() > 0) { + return true; + } + return false; + } + + @Override + public boolean containsPoint(int x, int y) { + if (containtsInChidren(this, x, y)) { + return true; + } else { + return super.containsPoint(x, y); + } + } + + public ViewFigure() { + super(); + } + + public ViewFigure(Font font, EditPart editpart, ZoomManager zoomManager) { + super(); + ownerEditpart = editpart; + ownerPart = (Part) editpart.getModel(); + titleFigure = new ViewTitleFigure(font, editpart); + add(titleFigure); + } + + @Override + public void setBounds(Rectangle rect) { + super.setBounds(rect); + if (titleFigure != null) { + titleFigure.setBounds(new Rectangle(rect.x, rect.y, rect.width, 36)); + titleFigure.setChildConstraint(new Rectangle(0, 0, rect.width, 36)); + } + } + + public ImageDescriptor getImageDescriptor() { + return imageDescriptor; + } + + public void setImageDescriptor(ImageDescriptor imageDescriptor) { + ImageDescriptor prevImageDescriptor = this.imageDescriptor; + this.imageDescriptor = imageDescriptor; + if ((prevImageDescriptor == null) || (imageDescriptor == null) || prevImageDescriptor.hashCode() != imageDescriptor.hashCode()) { + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + repaint(); + } + }); + } + } + + public void setProfile(String profile) { + this.profile = profile; + } + + private String getProfile() { + return profile; + } + + @Override + protected void paintFigure(Graphics graphics) { + if (imageDescriptor == null) { + return; + } + + // FIXED: Image creation is heavy. use a cache. + Image image = this.cache.get(this.imageDescriptor); + if (image == null) { + logger.error(this.getClass().getName() + " image is not created."); + return; + } + + graphics.setAntialias(SWT.ON); + Rectangle imgDstBound = DesignEditorUtil.getPageImageBoundFromPageBound(getBounds()); + + if (getProfile().equals(ConfiguratorConstants.PROFILE_WEARABLE_CIRCLE)) { + Path circlePath = ImageUtil.createCirclePath(imgDstBound.x, imgDstBound.y, imgDstBound.width(), imgDstBound.height()); + graphics.clipPath(circlePath); + } else { + if (isSelected() == true) { + graphics.setBackgroundColor(ColorResources.DESIGN_EDITOR_VIEW_FIGURE_BG_SELECTED_COLOR); + } else { + graphics.setBackgroundColor(ColorResources.DESIGN_EDITOR_VIEW_FIGURE_BG_NORMAL_COLOR); + } + graphics.fillRectangle(getBounds()); + } + + graphics.drawImage(image, image.getBounds().x, image.getBounds().y, image.getBounds().width, image.getBounds().height, imgDstBound.x, imgDstBound.y, + imgDstBound.width, imgDstBound.height); + + } + + public void repaintTitle() { + if (titleFigure != null) { + titleFigure.repaint(); + } + } + + public void repaint() { + super.repaint(); + if (titleFigure != null) { +// titleFigure.repaint(); + } + + /* + * Note : This logic is about repainting a object out of its parent. + */ + { + Rectangle dirtyBounds = getChildrenBound(this); + this.translateToAbsolute(dirtyBounds); + this.getUpdateManager().performUpdate(dirtyBounds); + } + } + + @Override + public void dispose() { + this.cache.dispose(); + } + + public boolean containsPointInTitle(Point pt) { + return titleFigure.containsPoint(pt); + } + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/ViewTitleFigure.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/ViewTitleFigure.java new file mode 100644 index 0000000..b903d35 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/ViewTitleFigure.java @@ -0,0 +1,148 @@ +/* + * UI Builder - StoryBoard + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + + +package org.tizen.efluibuilder.gef.figure; + +import org.eclipse.draw2d.Figure; +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.draw2d.XYLayout; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.Disposable; +import org.eclipse.gef.EditPart; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.nl.BuilderMessages; +import org.tizen.efluibuilder.ui.actions.ActionConstants; +import org.tizen.efluibuilder.ui.resources.ColorResources; +import org.tizen.efluibuilder.ui.resources.ImageResources; + + +public class ViewTitleFigure extends Figure implements Disposable { + + private ActionRunnableLable viewNameLabel = null; + private String labelText; + private Image iconW = null; + private EditPart ownerEditpart = null; + private Part ownerPart = null; + + private boolean isSelected() { + if (ownerEditpart != null && ownerEditpart.getSelected() > 0) { + return true; + } + return false; + } + + private boolean isStartup() { + if (ownerPart != null && ownerPart.getPropertyValue(LayoutSchemaConstants.ID) != null + && ownerPart.getParent() != null + && ownerPart.getPropertyValue(LayoutSchemaConstants.ID).equals(ownerPart.getParent().getPropertyValue(LayoutSchemaConstants.STARTUP))) { + return true; + } + + return false; + } + + public ViewTitleFigure(Font font, EditPart editPart) { + setLayoutManager(new XYLayout()); + this.ownerEditpart = editPart; + this.ownerPart = (Part) ownerEditpart.getModel(); + + viewNameLabel = new ActionRunnableLable(ActionConstants.FIT_TO_SINGLE_VIEW); + viewNameLabel.setLabelAlignment(PositionConstants.BOTTOM); + iconW = ImageResources.getImage(ImageResources.EDITOR_STARTUP_VIEW_HOME_W); + + FontData[] fontData = font.getFontData(); + fontData[0].setHeight(24); + fontData[0].setStyle(SWT.BOLD); + viewNameLabel.setFont(new Font(null, fontData[0])); + add(viewNameLabel); + } + + public void setChildConstraint(Rectangle constraint) { + setConstraint(viewNameLabel, constraint); + } + + public void refreshIcon(boolean isStartup) { + viewNameLabel.setText(labelText); + if (isStartup) { + viewNameLabel.setIcon(iconW); + } else { + viewNameLabel.setIcon(null); + } + } + + public void refreshText(String pageName, boolean isStartup) { + this.labelText = pageName; + refreshIcon(isStartup); + } + + private String getTitleString() { + String title = null; + if (viewNameLabel != null && ownerPart != null) { + title = ownerPart.getPropertyValue(LayoutSchemaConstants.ID); + if (ownerPart != null && ownerPart.getChildren().size() > 0) { + if (ownerPart.getChildren().get(0).getDescriptorId().equals(LayoutSchemaConstants.POPUP)) { + return title + BuilderMessages.POPUP_VIEW_TITLE; + } else if (ownerPart.getChildren().get(0).getDescriptorId().equals(LayoutSchemaConstants.CTXPOPUP)) { + return title + BuilderMessages.CTX_POPUP_VIEW_TITLE; + } + } + } + return title; + } + + @Override + public void repaint() { + if (viewNameLabel == null || ownerPart == null) { + return; + } + viewNameLabel.setText(getTitleString()); + if (isSelected()) { + viewNameLabel.setForegroundColor(ColorResources.DESIGN_EDITOR_VIEW_FIGURE_FONT_SELECTED_COLOR); + } else { + viewNameLabel.setForegroundColor(ColorResources.DESIGN_EDITOR_VIEW_FIGURE_FONT_NORMAL_COLOR); + } + + Image curIcon = iconW; + + if (isStartup() && viewNameLabel.getIcon() != curIcon) { + viewNameLabel.setIcon(curIcon); + } else if (isStartup() == false && viewNameLabel.getIcon() != null) { + viewNameLabel.setIcon(null); + } + super.repaint(); + } + + @Override + public void dispose() { + if (iconW != null) { + iconW.dispose(); + iconW = null; + } + + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/border/ContainerSelectionBorder.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/border/ContainerSelectionBorder.java new file mode 100644 index 0000000..b4efee0 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/border/ContainerSelectionBorder.java @@ -0,0 +1,79 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.figure.border; + +import org.eclipse.draw2d.AbstractBorder; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.geometry.Insets; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.swt.graphics.Color; + + +public class ContainerSelectionBorder extends AbstractBorder { + + private Color borderColor; + + public ContainerSelectionBorder(Color borderColor) { + this.borderColor = borderColor; + } + + @Override + public boolean isOpaque() { + return true; + } + + @Override + public Insets getInsets(IFigure figure) { + return new Insets(0); + } + + @Override + public void paint(IFigure figure, Graphics graphics, Insets insets) { + + int width = 1; + int edgeSize = 7; + + Rectangle tempRect = new Rectangle(getPaintRectangle(figure, insets)); + Rectangle clipRect = graphics.getClip(new Rectangle(0, 0, 9999, 9999)); + clipRect.expand(edgeSize, edgeSize); + tempRect = clipRect.getIntersection(tempRect); + if (width % 2 == 1) { + tempRect.width--; + tempRect.height--; + } + + graphics.setLineWidth(width); + graphics.setLineStyle(Graphics.LINE_DASH); + graphics.setForegroundColor(borderColor); + + // It's disable until fixed scroll issue + // graphics.setFont(labelFont); + // graphics.drawText(((Part) part.getModel()).getWidgetDescriptor().getDisplayName(), + // tempRect.x + labelPadding, tempRect.y + labelPadding); + graphics.drawRectangle(tempRect); + + return; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/border/WidgetSelectionBorder.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/border/WidgetSelectionBorder.java new file mode 100644 index 0000000..1ea3510 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/figure/border/WidgetSelectionBorder.java @@ -0,0 +1,83 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.figure.border; + +import org.eclipse.draw2d.AbstractBorder; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.geometry.Insets; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.editparts.ScalableFreeformRootEditPart; +import org.eclipse.swt.graphics.Color; +import org.tizen.efluibuilder.gef.editparts.DesignEditPart; + + +public class WidgetSelectionBorder extends AbstractBorder { + + private Color borderColor; + private DesignEditPart host; + + public WidgetSelectionBorder(Color borderColor) { + this(borderColor, null); + } + + public WidgetSelectionBorder(Color borderColor, DesignEditPart host) { + this.borderColor = borderColor; + this.host = host; + } + + @Override + public boolean isOpaque() { + return true; + } + + @Override + public Insets getInsets(IFigure figure) { + return new Insets(0); + } + + @Override + public void paint(IFigure figure, Graphics graphics, Insets insets) { + graphics.pushState(); + int width = 2; + + if (host != null) { + ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart) host.getViewer().getRootEditPart(); + double scale = rootEditPart.getZoomManager().getZoom(); + Rectangle bounds = host.getPosition().getBounds().getCopy(); + bounds.performScale(scale); + tempRect.setBounds(bounds); + } else { + tempRect.setBounds(getPaintRectangle(figure, insets)); + } + + graphics.setLineWidth(width); + graphics.setLineStyle(Graphics.LINE_SOLID); + graphics.setForegroundColor(borderColor); + graphics.drawRectangle(tempRect); + graphics.popState(); + + return; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/handles/CustomResizeHandle.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/handles/CustomResizeHandle.java new file mode 100644 index 0000000..6c449aa --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/handles/CustomResizeHandle.java @@ -0,0 +1,55 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.handles; + +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.handles.ResizeHandle; +import org.eclipse.swt.graphics.Color; +import org.tizen.efluibuilder.ui.resources.ColorResources; + + +public class CustomResizeHandle extends ResizeHandle { + + public CustomResizeHandle(GraphicalEditPart owner, int direction) { + super(owner, direction); + } + + /** + * Returns the color for the outside of the handle. + * + * @return the color for the border + */ + protected Color getBorderColor() { + return ColorResources.DESIGN_EDITOR_REISIZE_HANDLE_LINE_COLOR; + } + + /** + * Returns the color for the inside of the handle. + * + * @return the color of the handle + */ + protected Color getFillColor() { + return ColorResources.DESIGN_EDITOR_REISIZE_HANDLE_FILL_COLOR; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/layers/BlockLayer.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/layers/BlockLayer.java new file mode 100644 index 0000000..f3c3817 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/layers/BlockLayer.java @@ -0,0 +1,92 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.layers; + +import org.eclipse.draw2d.FreeformLayer; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.Viewport; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.tizen.efluibuilder.nl.BuilderMessages; +import org.tizen.efluibuilder.ui.resources.ColorResources; +import org.tizen.efluibuilder.ui.resources.FontResources; +import org.tizen.efluibuilder.ui.resources.ImageResources; + + +public class BlockLayer extends FreeformLayer { + private Viewport viewPort; + + @Override + public void paintFigure(Graphics graphics) { + Rectangle rect = this.getBounds(); + graphics.setAlpha(30); + graphics.setBackgroundColor(ColorResources.EDITOR_INVALID_XML_BG); + graphics.fillRectangle(rect); + + if (viewPort != null) { + Rectangle viewPortArea = viewPort.getClientArea(); + + Image errorImage = ImageResources.getImage(ImageResources.INVALID_XML_ERROR); + if (errorImage == null) { + return; + } + int imageWidth = errorImage.getBounds().width; + + GC gc = new GC(Display.getDefault()); + int dialogWidth = 40 + imageWidth + 14 + gc.textExtent(BuilderMessages.ERROR_INVALID_XML_DESCRIPTION_02).x + 40; + int dialogHeight = 104; + int dialogX = (viewPortArea.x + viewPortArea.x + viewPortArea.width) / 2 - (dialogWidth / 2); + int dialogY = (viewPortArea.y + viewPortArea.y + viewPortArea.height) / 2 - (dialogHeight / 2); + + graphics.setBackgroundColor(ColorResources.DIALOG_INVALID_XML_BG); + graphics.setAlpha(120); + graphics.setAntialias(255); + graphics.fillRoundRectangle(new Rectangle(dialogX, dialogY, dialogWidth, dialogHeight), 12, 12); + + graphics.setAlpha(255); + int imageX = dialogX + 40; + int imageY = dialogY + (dialogHeight / 2) - 14; + graphics.drawImage(ImageResources.getImage(ImageResources.INVALID_XML_ERROR), imageX, imageY); + + int textX = imageX + imageWidth + 14; + int textY = dialogY + 26; + graphics.setForegroundColor(ColorResources.DIALOG_INVALID_XML_LABEL); + graphics.setFont(FontResources.WYSIWYG_INVALID_XML_TITLE); + graphics.drawText(BuilderMessages.ERROR_INVALID_XML_TITLE, textX, textY); + + textY = textY + 26; + graphics.setFont(FontResources.WYSIWYG_INVALID_XML_TITLE_DESCRIPTION); + graphics.drawText(BuilderMessages.ERROR_INVALID_XML_DESCRIPTION_01, textX, textY); + graphics.drawText(BuilderMessages.ERROR_INVALID_XML_DESCRIPTION_02, textX, textY + 16); + + gc.dispose(); + } + } + + public void setViewPort(Viewport viewPort) { + this.viewPort = viewPort; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/layers/CustomLayerConstants.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/layers/CustomLayerConstants.java new file mode 100644 index 0000000..2235350 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/layers/CustomLayerConstants.java @@ -0,0 +1,29 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.layers; + +public class CustomLayerConstants { + public static final String OUTLINE_LAYER = "outline_layer"; + public static final String BLOCK_LAYER = "block_layer"; +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/layers/FeedbackLayer.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/layers/FeedbackLayer.java new file mode 100644 index 0000000..309dd5c --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/layers/FeedbackLayer.java @@ -0,0 +1,33 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.layers; + +import org.eclipse.draw2d.FreeformLayer; + + +public class FeedbackLayer extends FreeformLayer { + public FeedbackLayer() { + setEnabled(false); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/layers/OutlineLayer.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/layers/OutlineLayer.java new file mode 100644 index 0000000..c2932cb --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/layers/OutlineLayer.java @@ -0,0 +1,33 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.layers; + +import org.eclipse.draw2d.FreeformLayer; + + +public class OutlineLayer extends FreeformLayer { + public OutlineLayer() { + setEnabled(false); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/ComponentDataBindingEditPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/ComponentDataBindingEditPolicy.java new file mode 100644 index 0000000..90fa6ca --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/ComponentDataBindingEditPolicy.java @@ -0,0 +1,92 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + + +package org.tizen.efluibuilder.gef.policies; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.RequestConstants; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.editpolicies.ComponentEditPolicy; +import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.swt.widgets.Display; +import org.tizen.efluibuilder.gef.dnd.model.ITemplate; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.ui.view.databinding.model.DataBindingPartProperty; +import org.tizen.efluibuilder.ui.view.databinding.model.command.DataBindingCommandFactory; + +public class ComponentDataBindingEditPolicy extends ComponentEditPolicy { + + Request lastHandledRequest = null; + Command cmd = null; + + @Override + public EditPart getTargetEditPart(Request request) { + if (REQ_CREATE.equals(request.getType())) + return getHost(); + return null; + } + + @Override + public Command getCommand(Request request) { + if (REQ_CREATE.equals(request.getType()) && request instanceof CreateRequest) + return getCreateCommand((CreateRequest) request); + return null; + } + + private Command getCreateCommand(CreateRequest request) { + Object object = request.getNewObjectType(); + int objtype = (Integer) object; + if (ITemplate.DATABINDING == objtype && lastHandledRequest != request) { + lastHandledRequest = request; + Object ob = request.getNewObject(); + if (ob == null) { + return null; + } + if (!(ob instanceof DataBindingPartProperty)) + return null; + + DataBindingPartProperty property = (DataBindingPartProperty) ob; + // Point dropPoint = new Point(getDropLocation().x, + // getDropLocation().y); + EditPart targetEditPart = getTargetEditPart(request); + if (targetEditPart == null) { + return null; + } + Object targetModel = targetEditPart.getModel(); + if (!(targetModel instanceof ComponentPart)) { + return null; + } + ComponentPart part = (ComponentPart) targetModel; + cmd = DataBindingCommandFactory.createDropCommand(part, property, Display.getDefault().getActiveShell(), null); + } + return cmd; + } + + @Override + public boolean understandsRequest(Request request) { + if (RequestConstants.REQ_CREATE.equals(request.getType())) + return true; + return super.understandsRequest(request); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/ComponentDirectEditPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/ComponentDirectEditPolicy.java new file mode 100644 index 0000000..533664c --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/ComponentDirectEditPolicy.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.gef.policies; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.editpolicies.DirectEditPolicy; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.jface.viewers.CellEditor; +import org.tizen.efluibuilder.gef.editparts.ComponentEditPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.PartUtil; + + +/** + * EditPolicy for the direct editing of Column names + * + * @author Phil Zoio + */ +public class ComponentDirectEditPolicy extends DirectEditPolicy { + + public ComponentDirectEditPolicy() { + super(); + } + + protected Command getDirectEditCommand(DirectEditRequest request) { + + EditPart editPart = getHost(); + Command command = null; + if (editPart instanceof ComponentEditPart) { + Part model = (Part) editPart.getModel(); + CellEditor cellEditor = request.getCellEditor(); + String propertyName = ((ComponentEditPart) editPart).getPropertyNameDirectEdit(); + command = PartUtil.createSetPropertyCommand(model, propertyName, (String) cellEditor.getValue()); + } + return command; + } + + @Override + protected void showCurrentEditValue(DirectEditRequest request) { + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/ComponentDoubleClickEditPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/ComponentDoubleClickEditPolicy.java new file mode 100644 index 0000000..a82126f --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/ComponentDoubleClickEditPolicy.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.gef.policies; + +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.RequestConstants; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.editpolicies.GraphicalEditPolicy; +import org.tizen.efluibuilder.gef.editparts.ComponentEditPart; +import org.tizen.efluibuilder.gef.editparts.DesignEditPart; +import org.tizen.efluibuilder.gef.policies.containers.DesignEditorUtil; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; + + +public class ComponentDoubleClickEditPolicy extends GraphicalEditPolicy { + + public Command getCommand(Request request) { + if (RequestConstants.REQ_OPEN == request.getType()) { + EditPart editPart = getHost(); + if (editPart instanceof ComponentEditPart) { + DesignEditPart parentEditPart = (DesignEditPart) editPart.getParent(); + Part model = (Part) editPart.getModel(); + if (model != null) { + Part parentModel = model.getParent(); + + if (parentModel != null && parentModel.getDescriptorId().equals(LayoutSchemaConstants.GRID)) { + Rectangle parentBounds = new Rectangle(0, 0, parentEditPart.getPosition().width, parentEditPart.getPosition().height); + parentBounds = DesignEditorUtil.pixelBoundToGridBound(parentEditPart, parentBounds); + Command newCommand = PartUtil.createPackCommand(model, parentModel, parentBounds); + return newCommand; + } + } + + } + } + + return null; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/ContentContainerOutlineFeedbackPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/ContentContainerOutlineFeedbackPolicy.java new file mode 100644 index 0000000..5901a35 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/ContentContainerOutlineFeedbackPolicy.java @@ -0,0 +1,39 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies; + +import org.eclipse.gef.EditPart; +import org.tizen.efluibuilder.gef.policies.containers.DesignEditorUtil; +import org.tizen.efluibuilder.model.part.Part; + + +public class ContentContainerOutlineFeedbackPolicy extends OutlineFeedbackPolicy { + protected boolean needToShow() { + if ((this.getHost().getSelected() != EditPart.SELECTED_NONE) + || (this.getHost().getModel() instanceof Part && DesignEditorUtil.hasContent((Part) (getHost().getModel())) == true)) { + return false; + } + return true; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/CustomSnapFeedbackPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/CustomSnapFeedbackPolicy.java new file mode 100644 index 0000000..ce35ed2 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/CustomSnapFeedbackPolicy.java @@ -0,0 +1,217 @@ +/******************************************************************************* + * Copyright (c) 2003, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - change feedback line color + *******************************************************************************/ + + +package org.tizen.efluibuilder.gef.policies; + +import org.eclipse.draw2d.Figure; +import org.eclipse.draw2d.FigureUtilities; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.geometry.PrecisionPoint; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.SnapToGeometry; +import org.eclipse.gef.SnapToGuides; +import org.eclipse.gef.editpolicies.GraphicalEditPolicy; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.PaletteData; +import org.eclipse.swt.widgets.Display; +import org.tizen.efluibuilder.ui.resources.ColorResources; + + +public class CustomSnapFeedbackPolicy extends GraphicalEditPolicy { + + IFigure guide[] = new IFigure[6]; + Integer location[] = new Integer[6]; + + /** + * @see org.eclipse.gef.EditPolicy#eraseTargetFeedback(org.eclipse.gef.Request) + */ + public void eraseTargetFeedback(Request request) { + for (int i = 0; i < guide.length; i++) { + if (guide[i] != null) + removeFeedback(guide[i]); + guide[i] = null; + location[i] = null; + } + } + + static class FadeIn extends Figure { + int opacity = 0; + static final int FRAMES = 6; + Image image; + static int count; + + FadeIn(Color bg) { + setBackgroundColor(bg); + super.setOpaque(true); + } + + private Color createMixedColor() { + return FigureUtilities + .mixColors(getLocalBackgroundColor(), getParent() + .getBackgroundColor(), (double) opacity / FRAMES); + } + + /** + * @see org.eclipse.draw2d.Figure#paintFigure(org.eclipse.draw2d.Graphics) + */ + protected void paintFigure(Graphics graphics) { + if (opacity != FRAMES) { + if (image != null) { + image.dispose(); + count--; + image = null; + } + if (opacity != FRAMES - 1) { + Display display = Display.getCurrent(); + PaletteData pData = new PaletteData(0xFF, 0xFF00, 0xFF0000); + Color localBackgroundColor = createMixedColor(); + int fillColor = pData.getPixel(localBackgroundColor + .getRGB()); + localBackgroundColor.dispose(); + ImageData iData = new ImageData(1, 1, 24, pData); + iData.setPixel(0, 0, fillColor); + iData.setAlpha(0, 0, 255 * opacity / FRAMES); + image = new Image(display, iData); + count++; + } + Display.getCurrent().timerExec(100, new Runnable() { + public void run() { + opacity = Math.min(FRAMES, opacity + 1); + repaint(); + } + }); + } + Rectangle r = getBounds(); + if (image != null) + graphics.drawImage(image, 0, 0, 1, 1, r.x, r.y, r.width, + r.height); + else + super.paintFigure(graphics); + } + + /** + * @see org.eclipse.draw2d.Figure#removeNotify() + */ + public void removeNotify() { + if (image != null) { + image.dispose(); + count--; + image = null; + } + } + } + + // Even offset indicates a vertical feedback line; odd, horizontal. + void highlightGuide(Integer pos, Color color, int offset) { + if (pos == null) { + if (guide[offset] != null) { + removeFeedback(guide[offset]); + guide[offset] = null; + } + location[offset] = pos; + return; + } + + // pos is an integer relative to target's client area. + // translate pos to absolute, and then make it relative to fig. + int position = pos.intValue(); + PrecisionPoint loc = new PrecisionPoint(position, position); + IFigure contentPane = ((GraphicalEditPart) getHost()).getContentPane(); + contentPane.translateToParent(loc); + contentPane.translateToAbsolute(loc); + + if (location[offset] == null || !location[offset].equals(pos)) { + location[offset] = pos; + if (guide[offset] != null) { + removeFeedback(guide[offset]); + guide[offset] = null; + } + + IFigure fig = new FadeIn(color); + guide[offset] = fig; + addFeedback(fig); + fig.translateToRelative(loc); + position = offset % 2 == 0 ? (int) Math.round(loc.preciseX()) + : (int) Math.round(loc.preciseY()); + Rectangle figBounds = getFeedbackLayer().getBounds().getCopy(); + if ((offset % 2) == 1) { + figBounds.height = 1; + figBounds.y = position; + } else { + figBounds.x = position; + figBounds.width = 1; + } + fig.setBounds(figBounds); + } else { + // The feedback layer could have grown (if auto-scrolling), so + // resize the fade-in + // line. + IFigure fig = guide[offset]; + Rectangle figBounds = fig.getBounds().getCopy(); + Rectangle feedbackBounds = getFeedbackLayer().getBounds(); + if ((offset % 2) == 1) { + figBounds.x = feedbackBounds.x; + figBounds.width = feedbackBounds.width; + } else { + figBounds.y = feedbackBounds.y; + figBounds.height = feedbackBounds.height; + } + fig.setBounds(figBounds); + } + } + + /** + * @see org.eclipse.gef.EditPolicy#showTargetFeedback(org.eclipse.gef.Request) + */ + public void showTargetFeedback(Request req) { + if (req.getType().equals(REQ_MOVE) || req.getType().equals(REQ_RESIZE) + || req.getType().equals(REQ_CLONE) + || req.getType().equals(REQ_ADD) + || req.getType().equals(REQ_CREATE)) { + + // modified by Tizen SDK [start] + Integer value; + value = (Integer) req.getExtendedData().get( + SnapToGeometry.KEY_WEST_ANCHOR); + highlightGuide(value, ColorResources.DESIGN_EDITOR_SNAP_FEEDBACK_LINE_COLOR, 0); + + value = (Integer) req.getExtendedData().get( + SnapToGeometry.KEY_NORTH_ANCHOR); + highlightGuide(value, ColorResources.DESIGN_EDITOR_SNAP_FEEDBACK_LINE_COLOR, 1); + + value = (Integer) req.getExtendedData().get( + SnapToGeometry.KEY_EAST_ANCHOR); + highlightGuide(value, ColorResources.DESIGN_EDITOR_SNAP_FEEDBACK_LINE_COLOR, 2); + + value = (Integer) req.getExtendedData().get( + SnapToGeometry.KEY_SOUTH_ANCHOR); + highlightGuide(value, ColorResources.DESIGN_EDITOR_SNAP_FEEDBACK_LINE_COLOR, 3); + + value = (Integer) req.getExtendedData().get( + SnapToGuides.KEY_VERTICAL_GUIDE); + highlightGuide(value, ColorResources.DESIGN_EDITOR_SNAP_FEEDBACK_LINE_COLOR, 4); + + value = (Integer) req.getExtendedData().get( + SnapToGuides.KEY_HORIZONTAL_GUIDE); + highlightGuide(value, ColorResources.DESIGN_EDITOR_SNAP_FEEDBACK_LINE_COLOR, 5); + // modified by Tizen SDK [end] + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/DesignConnectionEndpointEditPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/DesignConnectionEndpointEditPolicy.java new file mode 100644 index 0000000..03debaa --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/DesignConnectionEndpointEditPolicy.java @@ -0,0 +1,17 @@ +package org.tizen.efluibuilder.gef.policies; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.gef.editpolicies.ConnectionEndpointEditPolicy; + +public class DesignConnectionEndpointEditPolicy extends ConnectionEndpointEditPolicy{ + protected List createSelectionHandles() { + List list = new ArrayList(); +// list.add(new ConnectionEndpointHandle((ConnectionEditPart) getHost(), +// ConnectionLocator.SOURCE)); +// list.add(new ConnectionEndpointHandle((ConnectionEditPart) getHost(), +// ConnectionLocator.TARGET)); + return list; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/DesignSelectionEditPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/DesignSelectionEditPolicy.java new file mode 100644 index 0000000..ccb7998 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/DesignSelectionEditPolicy.java @@ -0,0 +1,94 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies; + +import org.eclipse.gef.Request; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.editpolicies.SelectionEditPolicy; + + +public class DesignSelectionEditPolicy extends SelectionEditPolicy { + + /* + * (non-Javadoc) + * + * @see org.eclipse.gef.editpolicies.SelectionEditPolicy#activate() + */ + @Override + public void activate() { + super.activate(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.gef.editpolicies.SelectionEditPolicy#deactivate() + */ + @Override + public void deactivate() { + super.deactivate(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#getCommand(org.eclipse .gef.Request) + */ + @Override + public Command getCommand(Request request) { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.gef.editpolicies.SelectionEditPolicy#hideSelection() + */ + @Override + protected void hideSelection() { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.gef.editpolicies.SelectionEditPolicy#showSelection() + */ + @Override + protected void showSelection() { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#showTargetFeedback(org + * .eclipse.gef.Request) + */ + @Override + public void showTargetFeedback(Request request) { + if (request == null) { + return; + } + super.showTargetFeedback(request); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/DesignerSelectionEditPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/DesignerSelectionEditPolicy.java new file mode 100644 index 0000000..693ea35 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/DesignerSelectionEditPolicy.java @@ -0,0 +1,94 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies; + +import org.eclipse.gef.Request; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.editpolicies.SelectionEditPolicy; + + +public class DesignerSelectionEditPolicy extends SelectionEditPolicy { + + /* + * (non-Javadoc) + * + * @see org.eclipse.gef.editpolicies.SelectionEditPolicy#activate() + */ + @Override + public void activate() { + super.activate(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.gef.editpolicies.SelectionEditPolicy#deactivate() + */ + @Override + public void deactivate() { + super.deactivate(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#getCommand(org.eclipse .gef.Request) + */ + @Override + public Command getCommand(Request request) { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.gef.editpolicies.SelectionEditPolicy#hideSelection() + */ + @Override + protected void hideSelection() { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.gef.editpolicies.SelectionEditPolicy#showSelection() + */ + @Override + protected void showSelection() { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#showTargetFeedback(org + * .eclipse.gef.Request) + */ + @Override + public void showTargetFeedback(Request request) { + if (request == null) { + return; + } + super.showTargetFeedback(request); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/FitSingleViewPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/FitSingleViewPolicy.java new file mode 100644 index 0000000..0986393 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/FitSingleViewPolicy.java @@ -0,0 +1,86 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.gef.Request; +import org.eclipse.gef.RequestConstants; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.editparts.ZoomManager; +import org.eclipse.gef.editpolicies.GraphicalEditPolicy; +import org.eclipse.gef.requests.SelectionRequest; +import org.tizen.efluibuilder.gef.figure.IActionTriggerable; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.ui.actions.ActionConstants; + + + +public class FitSingleViewPolicy extends GraphicalEditPolicy { + + protected ZoomManager zoomMgr = null; + + public FitSingleViewPolicy() { + super(); + } + + @Override + public void deactivate() { + super.activate(); + } + + @Override + public void activate() { + super.activate(); + } + + @Override + public boolean understandsRequest(Request req) { + if (req.getType().equals(RequestConstants.REQ_OPEN)) { + return true; + } + return false; + } + + public Command getCommand(Request request) { + if (RequestConstants.REQ_OPEN == request.getType()) { + if (this.getHost().getViewer() instanceof DesignViewer) { + DesignViewer viewer = (DesignViewer) (this.getHost().getViewer()); + + if (viewer.getSelectedEditParts().size() != 1) { + return null; + } + SelectionRequest selReq = (SelectionRequest)request; + IFigure figure = viewer.findFigureAt(selReq.getLocation()); + if (figure instanceof IActionTriggerable && + ActionConstants.FIT_TO_SINGLE_VIEW.equals(((IActionTriggerable)figure).getTriggerString())) { + viewer.fitToSingleView((Part) this.getHost().getModel()); + } + + } + } + return null; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/ItemOutlineFeedbackPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/ItemOutlineFeedbackPolicy.java new file mode 100644 index 0000000..1c90797 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/ItemOutlineFeedbackPolicy.java @@ -0,0 +1,47 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies; + +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.geometry.Rectangle; +import org.tizen.efluibuilder.ui.resources.ColorResources; + + +public class ItemOutlineFeedbackPolicy extends OutlineFeedbackPolicy { + @Override + protected boolean needToShow() { + return true; + } + + @Override + protected void decorateFeedback() { + if (outlineFeedback != null) { + outlineFeedback.setBackgroundColor(ColorResources.DESIGN_EDITOR_CHANGE_BOUND_FEEDBACK_FILL_COLOR, 0); + outlineFeedback.setOutline(true); + outlineFeedback.setLineStyle(Graphics.LINE_SOLID); + outlineFeedback.setForegroundColor(ColorResources.DESIGN_EDITOR_PLACEHOLDER_LINE_COLOR, 255); + outlineFeedback.setBounds(new Rectangle(0, 0, 0, 0)); + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/OpenEdcEditorPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/OpenEdcEditorPolicy.java new file mode 100644 index 0000000..5968e20 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/OpenEdcEditorPolicy.java @@ -0,0 +1,232 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies; + +import java.io.File; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IPath; +import org.eclipse.draw2d.ImageFigure; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.RequestConstants; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.editparts.ScalableFreeformRootEditPart; +import org.eclipse.gef.editparts.ZoomListener; +import org.eclipse.gef.editparts.ZoomManager; +import org.eclipse.gef.editpolicies.GraphicalEditPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.tizen.efluibuilder.gef.editparts.DesignEditPart; +import org.tizen.efluibuilder.gef.policies.containers.DesignEditorUtil; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.renderer.Position; +import org.tizen.efluibuilder.ui.resources.ImageResources; +import org.tizen.efluibuilder.ui.wizard.newfile.EdcFileWizard; +import org.tizen.nativecore.enventor.executer.EDCEditorExecuter; + + +public class OpenEdcEditorPolicy extends GraphicalEditPolicy implements ZoomListener { + + public final static String PATH_RES = "res"; + public final static String EXTENSTION_EDJ = "edj"; + public final static String EXTENSTION_EDC = "edc"; + private final static int figureSize = 26; + private final static int rightTopMargin = 6; + + private ImageFigure figure = null; + protected ZoomManager zoomMgr = null; + + public OpenEdcEditorPolicy() { + super(); + } + + @Override + public void deactivate() { + super.activate(); + if (figure != null) { + getFeedbackLayer().remove(figure); + figure = null; + } + } + + @Override + public void activate() { + super.activate(); + + if (figure == null) { + Image img = ImageResources.getImage(ImageResources.EDITOR_OPEN_EDC_EDITOR); + figure = new ImageFigure(img); + figure.setSize(figureSize, figureSize); + figure.setLocation(new Point(0, 0)); + figure.setVisible(false); + getFeedbackLayer().add(figure); + } + + if (getHost().getViewer().getRootEditPart() instanceof ScalableFreeformRootEditPart) { + ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart) getHost().getViewer().getRootEditPart(); + this.zoomMgr = rootEditPart.getZoomManager(); + zoomMgr.addZoomListener(this); + } + } + + @Override + public boolean understandsRequest(Request req) { + if (req.getType().equals(RequestConstants.REQ_OPEN)) { + return true; + } + return false; + } + + private Point getIconLocation() { + Point location = new Point(); + if (this.getHost() instanceof DesignEditPart) { + DesignEditPart editpart = (DesignEditPart) getHost(); + Position position = editpart.getPosition(); + boolean hasContent = DesignEditorUtil.hasContent((Part) (this.getHost().getModel())); + double zoom = zoomMgr.getZoom(); + + if (position.width > 0 && position.height > 0) { + if (hasContent == false) { + location.x = (int) ((position.x + position.width / 2) * zoom + 0.5 - figureSize / 2); + location.y = (int) ((position.y + position.height / 2) * zoom + 0.5 - figureSize / 2); + } else { + location.x = (int) ((position.x + position.width) * zoom + 0.5 - (figureSize + rightTopMargin)); + location.y = (int) (position.y * zoom + 0.5) + rightTopMargin; + } + } + } + return location; + } + + public void refresh() { + if (zoomMgr == null || figure == null) { + return; + } + + if (this.getHost() instanceof DesignEditPart) { + DesignEditPart editpart = (DesignEditPart) getHost(); + Position position = editpart.getPosition(); + boolean hasContent = DesignEditorUtil.hasContent((Part) (this.getHost().getModel())); + if (position.width > 0 && position.height > 0) { + figure.setLocation(getIconLocation()); + if (hasContent && editpart.getSelected() == EditPart.SELECTED_NONE || editpart.getViewer().getSelectedEditParts().size() > 1) { + figure.setVisible(false); + } else { + figure.setVisible(true); + } + } + } + } + + private String getRealPath() { + DesignViewer viewer = (DesignViewer) (this.getHost().getViewer()); + Part part = (Part) (this.getHost().getModel()); + String realPath = viewer.getGraphicalDataMgr().getRenderDataGenerator().getRealPathFromResourceProperty(part, LayoutSchemaConstants.SRC, + viewer.getMScreenQualifierManager() + .getCurrentDevice(), + viewer.getMScreenQualifierManager() + .getCurrentLocale()); + return realPath; + } + + public Command getCommand(Request request) { + Command cmd = null; + if (RequestConstants.REQ_OPEN == request.getType()) { + if (this.getHost().getViewer() instanceof DesignViewer) { + DesignViewer viewer = (DesignViewer) (this.getHost().getViewer()); + String realPath = getRealPath(); + IProject project = viewer.getProject(); + IFolder resFolder = project.getFolder(PATH_RES); + String edcFilePath = null; + boolean bOpenWithTemplate = false; + + if (viewer.getSelectedEditParts().size() != 1 || resFolder == null || !resFolder.exists()) { + return null; + } + + // LocationRequest req = (LocationRequest) request; + // Point location = req.getLocation(); + // Point iconLocation = this.getIconLocation(); + // + // if (location.x < iconLocation.x || location.x > iconLocation.x + figureSize || + // location.y < iconLocation.y || location.y > iconLocation.y + figureSize) { + // return null; + // } + + if (realPath == null || realPath.isEmpty()) { + Object[] projectsToSelect = new Object[] { resFolder }; + EdcFileWizard wizard = new EdcFileWizard(); + try { + wizard.setSelection(new StructuredSelection(projectsToSelect)); + WizardDialog wd = new WizardDialog(Display.getDefault().getActiveShell(), wizard); + wd.setTitle(wizard.getWindowTitle()); + if (wd.open() == Dialog.OK) { + IFile createdFile = wizard.getCreatedFile(); + IPath filePath = createdFile.getFullPath(); + IPath relPath = filePath.makeRelativeTo(resFolder.getFullPath()); + relPath = relPath.removeFileExtension(); + relPath = relPath.addFileExtension(EXTENSTION_EDJ); + if (relPath != null) { + cmd = PartUtil.createSetPropertyCommand((Part) (this.getHost().getModel()), LayoutSchemaConstants.SRC, relPath.toString()); + edcFilePath = relPath.toString(); + bOpenWithTemplate = true; + } + } + + } finally { + wizard.dispose(); + } + } else { + edcFilePath = realPath; + } + if (edcFilePath != null && !edcFilePath.isEmpty()) { + if (EDCEditorExecuter.checkTool().isEmpty()) { + IPath path = project.getLocation().append(PATH_RES).append(edcFilePath); + path = path.removeFileExtension().addFileExtension(EXTENSTION_EDC); + File file = path.toFile(); + if (file.exists() == true) { + EDCEditorExecuter.executeTool(path, bOpenWithTemplate); + } + } + } + } + } + return cmd; + } + + @Override + public void zoomChanged(double zoom) { + this.refresh(); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/OutlineFeedbackPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/OutlineFeedbackPolicy.java new file mode 100644 index 0000000..5830f36 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/OutlineFeedbackPolicy.java @@ -0,0 +1,141 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies; + +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.editparts.ScalableFreeformRootEditPart; +import org.eclipse.gef.editparts.ZoomListener; +import org.eclipse.gef.editparts.ZoomManager; +import org.eclipse.gef.editpolicies.GraphicalEditPolicy; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.LineAttributes; +import org.tizen.efluibuilder.gef.editparts.DesignEditPart; +import org.tizen.efluibuilder.gef.figure.CommonRectangleFigure; +import org.tizen.efluibuilder.gef.layers.CustomLayerConstants; +import org.tizen.efluibuilder.gef.policies.containers.DesignEditorUtil; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.ui.resources.ColorResources; + + +public class OutlineFeedbackPolicy extends GraphicalEditPolicy implements ZoomListener { + protected CommonRectangleFigure outlineFeedback; + protected ZoomManager zoomMgr = null; + protected Rectangle bounds = null; + + protected boolean needToShow() { + if (this.getHost().getModel() instanceof ComponentPart && this.getHost().getViewer() instanceof DesignViewer) { + ComponentPart model = (ComponentPart) this.getHost().getModel(); + DesignViewer viewer = (DesignViewer) this.getHost().getViewer(); + + if ((viewer.getMScreenQualifierManager().getCurrentConfigurePart() != null) && + DesignEditorUtil.isHided(model, viewer.getMScreenQualifierManager().getCurrentConfigurePart().getPropertyValue(LayoutSchemaConstants.ID))) { + return false; + } + } + if (this.getHost().getSelected() == EditPart.SELECTED_NONE) { + return true; + } + return false; + } + + protected void decorateFeedback() { + if (outlineFeedback != null) { + outlineFeedback.setBackgroundColor(ColorResources.DESIGN_EDITOR_CHANGE_BOUND_FEEDBACK_FILL_COLOR, 0); + outlineFeedback.setOutline(true); + outlineFeedback.setLineStyle(Graphics.LINE_DASH); + outlineFeedback.setLineAttributes(new LineAttributes(1, SWT.CAP_ROUND, SWT.JOIN_ROUND, SWT.LINE_CUSTOM, new float[] { 5 }, 3, 0)); + outlineFeedback.setForegroundColor(ColorResources.DESIGN_EDITOR_PLACEHOLDER_LINE_COLOR, 255); + outlineFeedback.setBounds(new Rectangle(0, 0, 0, 0)); + } + } + + public void refresh() { + if (zoomMgr != null && outlineFeedback != null && bounds != null) { + outlineFeedback.setVisible(needToShow()); + double zoom = zoomMgr.getZoom(); + Rectangle rect = ((DesignEditPart) this.getHost()).getPosition().getBounds().getCopy(); + DesignEditorUtil.scaleRect(rect, zoom); + outlineFeedback.setBounds(rect); + } + } + + @Override + public void activate() { + super.activate(); + + if (outlineFeedback == null) { + outlineFeedback = new CommonRectangleFigure(); + // outlineFeedback.setVisible(true); + getFeedbackLayer().add(outlineFeedback); + decorateFeedback(); + } + + if (getHost().getViewer().getRootEditPart() instanceof ScalableFreeformRootEditPart) { + ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart) getHost().getViewer().getRootEditPart(); + this.zoomMgr = rootEditPart.getZoomManager(); + zoomMgr.addZoomListener(this); + } + } + + public void setBound(Rectangle r) { + this.bounds = r; + this.refresh(); + } + + public void setVisible(boolean bVisible) { + if (outlineFeedback != null) { + outlineFeedback.setVisible(bVisible); + } + } + + @Override + public void deactivate() { + if (outlineFeedback != null) { + getFeedbackLayer().remove(outlineFeedback); + outlineFeedback = null; + } + + if (zoomMgr != null) { + zoomMgr.removeZoomListener(this); + zoomMgr = null; + } + + super.deactivate(); + } + + @Override + protected IFigure getFeedbackLayer() { + return getLayer(CustomLayerConstants.OUTLINE_LAYER); + } + + @Override + public void zoomChanged(double zoom) { + this.refresh(); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/BoxChildResizablePolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/BoxChildResizablePolicy.java new file mode 100644 index 0000000..3f60fc4 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/BoxChildResizablePolicy.java @@ -0,0 +1,445 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies.containers; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.PointList; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.Handle; +import org.eclipse.gef.Request; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.eclipse.gef.requests.CreateRequest; +import org.tizen.efluibuilder.gef.commands.WidgetRelation; +import org.tizen.efluibuilder.gef.commands.WidgetRelation.Relation; +import org.tizen.efluibuilder.gef.dnd.model.ITemplate; +import org.tizen.efluibuilder.gef.editparts.ContainerEditPart; +import org.tizen.efluibuilder.gef.editparts.DesignEditPart; +import org.tizen.efluibuilder.gef.figure.PolygonFigure; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.resources.ColorResources; + + +public class BoxChildResizablePolicy extends CommonChildResizablePolicy { + private static final String EXTENSION_FLAG = "relation"; //$NON-NLS-1$ + + private enum PAD { + NONE, LEFT, TOP, RIGHT, BOTTOM; + } + + private PolygonFigure siblingHoverFeedback; + + public BoxChildResizablePolicy() { + super(); + setDragAllowed(true); + } + + @Override + public void activate() { + super.activate(); + + if (null == siblingHoverFeedback) { + siblingHoverFeedback = new PolygonFigure(); + siblingHoverFeedback.setAlpha(127); + siblingHoverFeedback.setFill(true); + siblingHoverFeedback.setOutline(false); + siblingHoverFeedback.setBackgroundColor(ColorResources.DESIGN_EDITOR_CREATION_BOUND_FEEDBACK_COLOR); + siblingHoverFeedback.setVisible(false); + getFeedbackLayer().add(siblingHoverFeedback); + } + } + + @Override + public void deactivate() { + if (siblingHoverFeedback != null) { + getFeedbackLayer().remove(siblingHoverFeedback); + siblingHoverFeedback = null; + } + + super.deactivate(); + } + + @Override + protected Command getCreateCommand(Request request) { + if (!(request instanceof CreateRequest)) { + return null; + } + + CreateRequest createRequest = (CreateRequest) request; + Object object = createRequest.getNewObjectType(); + int type = (Integer) object; + if (ITemplate.COMPONENT == type || ITemplate.SNIPPET == type) { + + WidgetRelation relation = this.getWidgetRelation(request); + + if (null != relation) { + + Part parentModel = (Part) getHost().getParent().getModel(); + Part selfModel = (Part) createRequest.getNewObject(); + Part hostModel = (Part) getHost().getModel(); + if (relation.getRelation() == Relation.NEXT_SIBLING) { + hostModel = hostModel.getNextSibling(); + } + + if (ITemplate.COMPONENT == type) { + initProperties(selfModel); + } + + return PartUtil.createAddPartCommand(parentModel, selfModel, hostModel); + } else { + return null; + } + } + + return super.getCreateCommand(request); + } + + // workaround code for initproperties + protected void initProperties(Part part) { + Part parentModel = (Part) getHost().getModel(); + ComponentDescriptor componentDescriptor = parentModel.getOwnerDocumentPart().getComponentDescriptor(); + Map initValues = componentDescriptor.getInitValues((ComponentPart) parentModel, (ComponentPart) part); + // FIXME need to clear widget properties? + part.getProperties().clear(); + PartUtil.setInitValues(part, initValues); + } + + @Override + protected Command getMoveCommand(Request request) { + + WidgetRelation relation = (WidgetRelation) request.getExtendedData().get(EXTENSION_FLAG); + if (null != relation) { + + DesignEditPart targetEditpart = (DesignEditPart) relation.getTarget(); + Part parent = ((Part) getHost().getModel()).getParent(); + + Part newParent = parent; + Part part = (Part) getHost().getModel(); + Part nextSibling = null; + + WidgetRelation.Relation relationType = relation.getRelation(); + if (relationType == WidgetRelation.Relation.PREV_SIBLING) { + nextSibling = (Part) targetEditpart.getModel(); + } else if (relationType == WidgetRelation.Relation.NEXT_SIBLING) { + nextSibling = ((Part) targetEditpart.getModel()).getNextSibling(); + } else { + return null; + } + + if ((nextSibling == part) || (nextSibling == part.getNextSibling())) { + return null; + } + + return PartUtil.createMovePartCommand(part, parent, newParent, nextSibling); + } + + return null; + } + + @Override + protected Command getAlignCommand(Request request) { + return null; + } + + @SuppressWarnings("rawtypes") + @Override + protected List createSelectionHandles() { + + List list = new ArrayList(); + createMoveHandle(list); + + setBorderSelectionHandles(list); + + return list; + } + + @Override + public void showTargetFeedback(Request request) { + + boolean bSiblingHover = true; + + if ((getHost() instanceof ContainerEditPart) || REQ_SELECTION.equals(request.getType()) || REQ_SELECTION_HOVER.equals(request.getType())) { + bSiblingHover = false; + } else { + if (REQ_CREATE.equals(request.getType()) && request instanceof CreateRequest) { + int nType = (Integer) ((CreateRequest) request).getNewObjectType(); + if (ITemplate.PROPERTY == nType) { + bSiblingHover = false; + } + } + } + + if (bSiblingHover) { + showTargetSiblingFeedback(request); + + } else { + super.showTargetFeedback(request); + } + } + + @Override + public void eraseTargetFeedback(Request request) { + super.eraseTargetFeedback(request); + + if (null == siblingHoverFeedback) + return; + + siblingHoverFeedback.setVisible(false); + + } + + @Override + public void showSourceFeedback(Request request) { + + super.showSourceFeedback(request); + + return; + } + + @Override + public void eraseSourceFeedback(Request request) { + + super.eraseSourceFeedback(request); + + return; + } + + private boolean isHorizontalBoxType(Part boxPart) { + String direction = boxPart.getPropertyValue(LayoutSchemaConstants.DIRECTION); + if (direction != null && !direction.isEmpty()) { + if (direction.equals(LayoutSchemaConstants.BOX_DIRECTION_HORIZONTAL)) + return true; + } + return false; + } + + private PointList makePolygonHoverArea(Rectangle srcR, PAD pad) { + PointList polygonHover = new PointList(); + final int boundIncre = this.getHostFigure().getParent().getBounds().width / 10; + int boundSlope = (int) (((float) srcR.width / (float) srcR.height) * boundIncre); + + switch (pad) { + case LEFT: { + polygonHover.addPoint(srcR.x, srcR.y); + polygonHover.addPoint(srcR.x + boundSlope, srcR.y + boundIncre); + polygonHover.addPoint(srcR.x + boundSlope, srcR.y + srcR.height - boundIncre); + polygonHover.addPoint(srcR.x, srcR.y + srcR.height); + } + break; + case TOP: { + polygonHover.addPoint(srcR.x, srcR.y); + polygonHover.addPoint(srcR.x + srcR.width, srcR.y); + polygonHover.addPoint(srcR.x + srcR.width - boundSlope, srcR.y + boundIncre); + polygonHover.addPoint(srcR.x + boundSlope, srcR.y + boundIncre); + } + break; + case RIGHT: { + polygonHover.addPoint(srcR.x + srcR.width - boundSlope, srcR.y + boundIncre); + polygonHover.addPoint(srcR.x + srcR.width, srcR.y); + polygonHover.addPoint(srcR.x + srcR.width, srcR.y + srcR.height); + polygonHover.addPoint(srcR.x + srcR.width - boundSlope, srcR.y + srcR.height - boundIncre); + } + break; + case BOTTOM: { + polygonHover.addPoint(srcR.x, srcR.y + srcR.height); + polygonHover.addPoint(srcR.x + srcR.width, srcR.y + srcR.height); + polygonHover.addPoint(srcR.x + srcR.width - boundSlope, srcR.y + srcR.height - boundIncre); + polygonHover.addPoint(srcR.x + boundSlope, srcR.y + srcR.height - boundIncre); + + } + break; + default: + break; + } + + return polygonHover; + } + + private PAD getHoverPadByPoint(final Rectangle targetArea, final Point sourcePt, final boolean bhorizontal) { + + PAD revalPad = PAD.NONE; + PointList polygonHover = null; + + do { + if (bhorizontal) { + + polygonHover = makePolygonHoverArea(targetArea, PAD.LEFT); + + if (polygonHover.polygonContainsPoint(sourcePt.x, sourcePt.y)) { + revalPad = PAD.LEFT; + break; + } else { + + polygonHover = makePolygonHoverArea(targetArea, PAD.RIGHT); + if (polygonHover.polygonContainsPoint(sourcePt.x, sourcePt.y)) { + revalPad = PAD.RIGHT; + break; + } + } + + } else { + + polygonHover = makePolygonHoverArea(targetArea, PAD.TOP); + + if (polygonHover.polygonContainsPoint(sourcePt.x, sourcePt.y)) { + revalPad = PAD.TOP; + break; + } else { + + polygonHover = makePolygonHoverArea(targetArea, PAD.BOTTOM); + if (polygonHover.polygonContainsPoint(sourcePt.x, sourcePt.y)) { + revalPad = PAD.BOTTOM; + break; + } + } + } + + } while (false); + + return revalPad; + } + + private WidgetRelation getWidgetRelation(Request request) { + if (null != getHost()) { + Part part = (Part) getHost().getModel(); + if (null == part) { + return null; + } + Rectangle area = ((DesignEditPart) getHost()).getFigure().getBounds(); + if (null == area) { + return null; + } + Point mousePt = DesignEditorUtil.getLocationByRequest(request).getCopy(); + if (null == mousePt) { + return null; + } + + translateToCustom(mousePt); + + boolean bHorizontal = isHorizontalBoxType(part.getParent()); + PAD pad = getHoverPadByPoint(area, mousePt, bHorizontal); + + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + // WORKAROUND !!!!!!!! + // It's not feedback's logic + if ((null != request)) { + + WidgetRelation.Relation relationType = WidgetRelation.Relation.DENY; + if ((PAD.TOP == pad) || (PAD.LEFT == pad)) { + relationType = WidgetRelation.Relation.PREV_SIBLING; + } else if ((PAD.RIGHT == pad) || (PAD.BOTTOM == pad)) { + relationType = WidgetRelation.Relation.NEXT_SIBLING; + } + + WidgetRelation relation = new WidgetRelation(getHost(), relationType, 0); + return relation; + } + + } + return null; + + } + + @SuppressWarnings("unchecked") + public void showTargetSiblingFeedback(Request request) { + if (request == null) { + throw new NullPointerException(); + } + + PointList polygonHover = null; + do { + if (null == siblingHoverFeedback) { + break; + } + + if (REQ_MOVE.equals(request.getType()) || REQ_RESIZE.equals(request.getType())) { + DesignEditPart targetEditPart = (DesignEditPart) getHost().getParent(); + + if (request instanceof ChangeBoundsRequest) { + + List childParts = ((ChangeBoundsRequest) request).getEditParts(); + for (EditPart part : childParts) { + DesignEditPart parentPart = (DesignEditPart) part.getParent(); + if (parentPart != targetEditPart) { + return; + } + } + } + } + + Part part = (Part) getHost().getModel(); + if (null == part) { + break; + } + Rectangle area = ((DesignEditPart) getHost()).getFigure().getBounds(); + if (null == area) { + break; + } + Point mousePt = DesignEditorUtil.getLocationByRequest(request).getCopy(); + if (null == mousePt) { + break; + } + + translateToCustom(mousePt); + + boolean bHorizontal = isHorizontalBoxType(part.getParent()); + PAD pad = getHoverPadByPoint(area, mousePt, bHorizontal); + if (PAD.NONE != pad) { + polygonHover = makePolygonHoverArea(area, pad); + } + + { + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + // WORKAROUND !!!!!!!! + // It's not feedback's logic + WidgetRelation relation = getWidgetRelation(request); + request.getExtendedData().put(EXTENSION_FLAG, relation); + + } + + } while (false); + + if (siblingHoverFeedback == null) { + return; + } + + if (null != polygonHover) { + siblingHoverFeedback.setPolygonPoints(polygonHover); + siblingHoverFeedback.setVisible(true); + } else { + siblingHoverFeedback.setVisible(false); + } + + return; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/BoxLayoutPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/BoxLayoutPolicy.java new file mode 100644 index 0000000..d2fc950 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/BoxLayoutPolicy.java @@ -0,0 +1,67 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies.containers; + +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPolicy; +import org.tizen.efluibuilder.gef.dnd.model.ITemplate; +import org.tizen.efluibuilder.gef.editparts.DesignEditPart; +import org.tizen.efluibuilder.model.part.ComponentPart; + + +public class BoxLayoutPolicy extends CommonLayoutPolicy { + + @Override + protected EditPolicy createChildEditPolicy(EditPart child) { + if (child instanceof DesignEditPart) { + return new BoxChildResizablePolicy(); + } + return null; + } + + @Override + protected Rectangle getComponentPack(int objtype, Point srcLoc, Point srcSize, ComponentPart srcModel) { + switch (objtype) { + + case ITemplate.COMPONENT: + case ITemplate.SNIPPET: { + /* + * Create a child widget on a box if there's no child. otherwise, + * BoxChildResizablePolicy + */ + if (getHost().getChildren().size() == 0) { + + return new Rectangle(0, 0, 1, 1); + } + } + break; + default: + break; + } + + return null; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/CommonChildResizablePolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/CommonChildResizablePolicy.java new file mode 100644 index 0000000..ab9a3d2 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/CommonChildResizablePolicy.java @@ -0,0 +1,423 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies.containers; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.draw2d.AbstractBorder; +import org.eclipse.draw2d.Cursors; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.RectangleFigure; +import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.Handle; +import org.eclipse.gef.LayerConstants; +import org.eclipse.gef.Request; +import org.eclipse.gef.SharedCursors; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CompoundCommand; +import org.eclipse.gef.editpolicies.ResizableEditPolicy; +import org.eclipse.gef.handles.MoveHandle; +import org.eclipse.gef.handles.ResizableHandleKit; +import org.eclipse.gef.handles.ResizeHandle; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gef.requests.SelectionRequest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.gef.dnd.model.ITemplate; +import org.tizen.efluibuilder.gef.dnd.model.ResourceTemplateProperty; +import org.tizen.efluibuilder.gef.editparts.DesignRootEditPart; +import org.tizen.efluibuilder.gef.figure.border.WidgetSelectionBorder; +import org.tizen.efluibuilder.gef.handles.CustomResizeHandle; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.descriptors.PropertyDescriptor; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.ConfigurationPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.resources.ColorResources; + +import edjResourceSyncManager.EdjResourceSyncManager; + + +public class CommonChildResizablePolicy extends ResizableEditPolicy { + private static Logger logger = LoggerFactory.getLogger(CommonChildResizablePolicy.class); + + final protected String REQ_KEY_CHANGETARGET = "change-target"; + + private RectangleFigure hoverFeedback; + + @Override + public void activate() { + super.activate(); + + if (hoverFeedback == null) { + hoverFeedback = new RectangleFigure(); + hoverFeedback.setAlpha(75); + hoverFeedback.setFill(true); + hoverFeedback.setOutline(true); + hoverFeedback.setLineWidth(1); + hoverFeedback.setBackgroundColor(ColorResources.DESIGN_EDITOR_COMPONENT_HOVER_COLOR); + hoverFeedback.setForegroundColor(ColorResources.DESIGN_EDITOR_COMPONENT_HOVER_COLOR); + // hoverFeedback.setLineStyle(Graphics.LINE_DOT); + hoverFeedback.setBounds(new Rectangle(0, 0, 0, 0)); + hoverFeedback.setVisible(true); + getFeedbackLayer().add(hoverFeedback); + } + } + + @Override + public void deactivate() { + if (hoverFeedback != null) { + getFeedbackLayer().remove(hoverFeedback); + hoverFeedback = null; + } + super.deactivate(); + } + + @Override + protected void createResizeHandle(List handles, int direction) { + ResizeHandle handle = new CustomResizeHandle((GraphicalEditPart) this.getHost(), direction); + handle.setDragTracker(getResizeTracker(direction)); + handle.setCursor(Cursors.getDirectionalCursor(direction, getHostFigure().isMirrored())); + handles.add(handle); + } + + private Command getCreateCommand(CreateRequest request, int type) { + Command command = null; + switch (type) { + case ITemplate.COMPONENT: + case ITemplate.SNIPPET: { + break; + } + case ITemplate.PROPERTY: + EditPart hostPart = getHost(); + if (hostPart == null) { + return null; + } + + Part model = (Part) hostPart.getModel(); + ResourceTemplateProperty property = (ResourceTemplateProperty) request.getNewObject(); + + if (property == null) { + return null; + } + + if (!model.hasProperty(property.getName())) { + return null; + } + + ComponentDescriptor componentDescriptor = model.getOwnerDocumentPart().getComponentDescriptor(); + PropertyDescriptor propertyDescriptor = componentDescriptor.getPropertyDescriptor(model.getParent(), (ComponentPart) model, property.getName()); + if (!(propertyDescriptor.getPropertyType()).equals(property.getType())) { + return null; + } + + String propertyName = property.getName(); + String propertyValue = property.getValue(); + command = PartUtil.createSetPropertyCommand(model, propertyName, propertyValue); + /* + * In case of "layout" component, When "src" attribute is changed, "group" attribute + * also should be changed. + */ + if (LayoutSchemaConstants.LAYOUT.equals(model.getDescriptorId()) && LayoutSchemaConstants.SRC.equals(propertyName)) { + if (propertyValue != null) { + if (getHost() != null && getHost().getViewer() instanceof DesignViewer) { + EdjResourceSyncManager edjResSyncMgr = ((DesignViewer) (this.getHost().getViewer())).getEdjResourceSyncManager(); + ArrayList groupNames = edjResSyncMgr.getGroupNames(propertyValue); + if (groupNames != null && groupNames.size() > 0) { + CompoundCommand compCmd = new CompoundCommand(); + compCmd.add(command); + compCmd.add(PartUtil.createSetPropertyCommand(model, LayoutSchemaConstants.GROUP, groupNames.get(0))); + return compCmd; + } + } + } + } + break; + default: + break; + } + return command; + } + + protected Command getCreateCommand(Request request) { + if (!(request instanceof CreateRequest)) { + logger.error("request type does not matched"); + return null; + } + CreateRequest createRequest = (CreateRequest) request; + Object object = createRequest.getNewObjectType(); + int type = (Integer) object; + return getCreateCommand(createRequest, type); + } + + protected Command getCommand(Rectangle packBound) { + CompoundCommand command = new CompoundCommand(); + if (packBound == null) { + return command; + } + + ComponentPart part = (ComponentPart) getHost().getModel(); + Part parent = part.getParent(); + + return PartUtil.createPackCommandWithVariation(part, parent, getCurrentConfiguration(), packBound); + } + + protected Command getMoveCommand(Request request) { + return null; + } + + protected Command getAlignCommand(Request request) { + return null; + } + + protected Rectangle getMoveComponentBound(Request request) { + return null; + } + + protected Rectangle getResizeComponentBound(Request request) { + return null; + } + + @Override + public Command getCommand(Request request) { + if (REQ_CREATE.equals(request.getType())) { + return getCreateCommand(request); + } else if (REQ_RESIZE.equals(request.getType())) { + return getCommand(getResizeComponentBound(request)); + } else if (REQ_MOVE.equals(request.getType())) { + if (this instanceof BoxChildResizablePolicy) { + return getMoveCommand(request); + } else { + return getCommand(getMoveComponentBound(request)); + } + } else if (REQ_ALIGN.equals(request.getType())) { + return getAlignCommand(request); + } + + return null; + } + + @SuppressWarnings("rawtypes") + @Override + protected List createSelectionHandles() { + + List list = new ArrayList(); + createMoveHandle(list); + + setBorderSelectionHandles(list); + + return list; + } + + @SuppressWarnings("rawtypes") + @Override + protected void createMoveHandle(List handles) { + if (isDragAllowed()) { + // display 'move' handle to allow dragging + ResizableHandleKit.addMoveHandle((GraphicalEditPart) getHost(), handles, getDragTracker(), SharedCursors.CURSOR_TREE_MOVE); + } else { + // display 'move' handle only to indicate selection + ResizableHandleKit.addMoveHandle((GraphicalEditPart) getHost(), handles, getSelectTracker(), SharedCursors.ARROW); + } + } + + @Override + protected IFigure getFeedbackLayer() { + return getLayer(LayerConstants.SCALED_FEEDBACK_LAYER); + } + + protected IFigure getNoneScalableFeedbackLayer() { + return getLayer(LayerConstants.FEEDBACK_LAYER); + } + + @Override + public EditPart getTargetEditPart(Request request) { + return this.getHost(); + } + + @Override + public void showTargetFeedback(Request request) { + + if (REQ_CREATE.equals(request.getType())) { + // N/A + } else { + showDefaultRequestFeedback(request); + } + + return; + } + + @Override + public void eraseTargetFeedback(Request request) { + + if (null == hoverFeedback) + return; + + hoverFeedback.setVisible(false); + } + + private void showDefaultRequestFeedback(Request request) { + + if (null == hoverFeedback) + return; + + if (!(request instanceof SelectionRequest)) + return; + + if (REQ_MOVE.equals(request.getType()) || REQ_RESIZE.equals(request.getType())) { + return; + } + + IFigure figure = ((GraphicalEditPart) getHost()).getFigure(); + if (figure == null) { + return; + } + + boolean isPrintBorder = false; + Rectangle bounds = figure.getBounds().getCopy(); + Object extendData = request.getExtendedData().get(REQ_KEY_CHANGETARGET); + if (null != extendData) { + isPrintBorder = (Boolean) extendData; + } + + if (isPrintBorder) { + // hoverFeedback.setAlpha(150); + hoverFeedback.setFill(false); + hoverFeedback.setOutline(true); + hoverFeedback.setLineWidth(10); + hoverFeedback.setLineStyle(Graphics.LINE_SOLID); + } else { + // hoverFeedback.setAlpha(30); + hoverFeedback.setFill(true); + hoverFeedback.setOutline(false); + hoverFeedback.setLineWidth(0); + // hoverFeedback.setLineStyle(Graphics.LINE_DOT); + } + + hoverFeedback.setBounds(bounds); + hoverFeedback.setVisible(true); + } + + protected void translateToZoom(Point srcPt) { + if (null == srcPt) + return; + + double zoomSize = ((DesignRootEditPart) getHost().getRoot()).getZoomManager().getZoom(); + srcPt.x /= zoomSize; + srcPt.y /= zoomSize; + } + + protected void translateToCustom(Point srcPt) { + + if (null == srcPt) + return; + + if (getHost().getParent() instanceof GraphicalEditPart) { + IFigure parentFigure = ((GraphicalEditPart) getHost().getParent()).getFigure(); + parentFigure.translateToRelative(srcPt); + } + + return; + } + + protected Point getMoveDeltaByRequest(Request request) { + + if (!(request instanceof ChangeBoundsRequest)) { + return null; + } + + ChangeBoundsRequest moveReq = (ChangeBoundsRequest) request; + + Point realDelta = moveReq.getMoveDelta(); + Point sizeDelta = new Point(); + sizeDelta.x = realDelta.x; + sizeDelta.y = realDelta.y; + + translateToZoom(sizeDelta); + + return sizeDelta; + } + + protected Point getResizeDeltaByRequest(Request request) { + + if (!(request instanceof ChangeBoundsRequest)) { + return null; + } + + ChangeBoundsRequest resizeReq = (ChangeBoundsRequest) request; + + Dimension realDelta = resizeReq.getSizeDelta(); + Point sizeDelta = new Point(); + sizeDelta.x = realDelta.width; + sizeDelta.y = realDelta.height; + + translateToZoom(sizeDelta); + + return sizeDelta; + } + + protected void setBorderSelectionHandles(List list) { + + AbstractBorder selectionBorder = null; + selectionBorder = new WidgetSelectionBorder(ColorResources.DESIGN_EDITOR_SELECTION_LINE_COLOR); + + for (Handle handle : list) { + if (handle instanceof MoveHandle) { + ((MoveHandle) handle).setBorder(selectionBorder); + } + } + + return; + } + + public boolean isChangeTargetForParent() { + return false; + } + + protected ConfigurationPart getCurrentConfiguration() { + DesignViewer viewer = (DesignViewer) getHost().getViewer(); + if (viewer == null) { + return null; + } + return viewer.getMScreenQualifierManager().getCurrentConfigurePart(); + } + + protected String getCurrentConfigurationID() { + ConfigurationPart configPart = getCurrentConfiguration(); + if (configPart == null) { + return null; + } + return configPart.getPropertyValue(LayoutSchemaConstants.ID); + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/CommonLayoutPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/CommonLayoutPolicy.java new file mode 100644 index 0000000..b73ad2b --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/CommonLayoutPolicy.java @@ -0,0 +1,256 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies.containers; + +import java.util.Map; + +import org.eclipse.draw2d.RectangleFigure; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CompoundCommand; +import org.eclipse.gef.editpolicies.XYLayoutEditPolicy; +import org.eclipse.gef.requests.CreateRequest; +import org.tizen.efluibuilder.gef.dnd.model.ITemplate; +import org.tizen.efluibuilder.gef.editparts.DesignEditPart; +import org.tizen.efluibuilder.gef.editparts.DesignRootEditPart; +import org.tizen.efluibuilder.gef.figure.CommonRectangleFigure; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.ConfigurationPart; +import org.tizen.efluibuilder.model.part.DocumentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.resources.ColorResources; + + +public class CommonLayoutPolicy extends XYLayoutEditPolicy { + + protected RectangleFigure hoverFeedback; + protected CommonRectangleFigure outlineFeedback; + + private static int OUTLINE_WIDTH = 2; + + public CommonLayoutPolicy() { + super(); + } + + protected CommonRectangleFigure createHoverFeedback() { + CommonRectangleFigure rectangle = new CommonRectangleFigure(); + rectangle.setBackgroundColor(ColorResources.DESIGN_EDITOR_COMPONENT_HOVER_COLOR, 75); + rectangle.setForegroundColor(ColorResources.DESIGN_EDITOR_COMPONENT_HOVER_COLOR); + rectangle.setOutline(false); + rectangle.setFill(true); + rectangle.setVisible(false); + getFeedbackLayer().add(rectangle); + return rectangle; + } + + protected CommonRectangleFigure createOutlineFeedback() { + CommonRectangleFigure rectangle = new CommonRectangleFigure(); + rectangle.setForegroundColor(ColorResources.DESIGN_EDITOR_CONTAINER_LINE_COLOR); + rectangle.setOutline(true); + rectangle.setFill(false); + rectangle.setLineWidth(OUTLINE_WIDTH); + rectangle.setVisible(false); + getFeedbackLayer().add(rectangle); + return rectangle; + } + + @Override + public void activate() { + super.activate(); + + if (outlineFeedback == null) { + outlineFeedback = createOutlineFeedback(); + } + + if (hoverFeedback == null) { + hoverFeedback = createHoverFeedback(); + } + + } + + @Override + public void deactivate() { + if (hoverFeedback != null) { + getFeedbackLayer().remove(hoverFeedback); + hoverFeedback = null; + } + + if (outlineFeedback != null) { + getFeedbackLayer().remove(outlineFeedback); + outlineFeedback = null; + } + + super.deactivate(); + } + + @Override + protected Command getCreateCommand(CreateRequest request) { + Command cmd = null; + Object object = request.getNewObjectType(); + int objtype = (Integer) object; + if ((ITemplate.COMPONENT == objtype || ITemplate.SNIPPET == objtype) && request.getNewObject() instanceof ComponentPart) { + ComponentPart part = (ComponentPart) request.getNewObject(); + // NOTE : snippet does not need this process + if (isViewTemplate(part)) { + return null; + } + if (objtype == ITemplate.COMPONENT) { + initProperties(part); + } + Point srcLoc = request.getLocation(); + Point srcSize = null; + if (null != request.getSize()) { + srcSize = new Point(request.getSize().width, request.getSize().height); + } + + Rectangle bounds = getComponentPack(objtype, srcLoc, srcSize, part); + if (null != bounds) { + cmd = getCommand(part, bounds); + } + } + return cmd; + } + + // workaround code for initproperties + protected void initProperties(Part part) { + Part parentModel = (Part) getHost().getModel(); + ComponentDescriptor componentDescriptor = parentModel.getOwnerDocumentPart().getComponentDescriptor(); + Map initValues = componentDescriptor.getInitValues((ComponentPart) parentModel, (ComponentPart) part); + // FIXME need to clear widget properties? + part.getProperties().clear(); + PartUtil.setInitValues(part, initValues); + } + + @Override + protected EditPolicy createChildEditPolicy(EditPart child) { + if (child instanceof DesignEditPart) { + return new CommonChildResizablePolicy(); + } + return null; + } + + protected Command getCommand(Part part, Rectangle bounds) { + if (!(part instanceof ComponentPart)) { + return null; + } + + Part parentPart = (Part) getHost().getModel(); + + // create part pack command + CompoundCommand compCmd = new CompoundCommand(); + compCmd.add(PartUtil.createAddPartCommand(parentPart, part, null)); + + compCmd.add(PartUtil.createPackCommand(part, parentPart, bounds)); + + ConfigurationPart configPart = getCurrentConfiguration(); + if (configPart != null) { + String type = configPart.getPropertyValue(LayoutSchemaConstants.TYPE); + + if (!type.equals(LayoutSchemaConstants.CONFIGURATION_TYPE_COMMON)) { + DocumentPart documentPart = parentPart.getOwnerDocumentPart(); + Part variationPart = PartUtil.createPartWithInitValue(documentPart, + PartType.VARIATION, part, null); + compCmd.add(PartUtil.createVariationPartCommand(part, variationPart, + configPart.getPropertyValue(LayoutSchemaConstants.ID), + LayoutSchemaConstants.TRUE)); + compCmd.add(PartUtil.createPackCommand(variationPart, parentPart, bounds)); + + // set visible = false to part + compCmd.add(PartUtil.createSetPropertyCommand(part, LayoutSchemaConstants.VISIBLE, + LayoutSchemaConstants.FALSE)); + } + } + + return compCmd; + } + + protected Rectangle getComponentPack(int objtype, Point srcLoc, Point srcSize, ComponentPart srcModel) { + return null; + } + + @Override + public void showTargetFeedback(Request request) { + super.showTargetFeedback(request); + + if (REQ_CREATE.equals(request.getType())) { + DesignEditPart targetEditPart = (DesignEditPart) getHost(); + if (targetEditPart == null) { + return; + } + + double zoomSize = ((DesignRootEditPart) getHost().getRoot()).getZoomManager().getZoom(); + Rectangle bounds = targetEditPart.getPosition().getBounds().getCopy(); + bounds.performScale(zoomSize); + + hoverFeedback.setBounds(bounds); + hoverFeedback.setVisible(true); + + outlineFeedback.setBounds(bounds); + outlineFeedback.setVisible(true); + + } + } + + @Override + public void eraseTargetFeedback(Request request) { + super.eraseTargetFeedback(request); + + hoverFeedback.setVisible(false); + outlineFeedback.setVisible(false); + } + + protected ConfigurationPart getCurrentConfiguration() { + DesignViewer viewer = (DesignViewer) getHost().getViewer(); + if (viewer == null) { + return null; + } + return viewer.getMScreenQualifierManager().getCurrentConfigurePart(); + } + + protected String getCurrentConfigurationID() { + ConfigurationPart configPart = getCurrentConfiguration(); + if (configPart == null) { + return null; + } + return configPart.getPropertyValue(LayoutSchemaConstants.ID); + } + + protected boolean isViewTemplate(Part part) { + if (LayoutSchemaConstants.VIEW.equals(part.getDescriptorId()) || + LayoutSchemaConstants.POPUP.equals(part.getDescriptorId()) || + LayoutSchemaConstants.CTXPOPUP.equals(part.getDescriptorId())) { + return true; + } + return false; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/ContentLayoutPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/ContentLayoutPolicy.java new file mode 100644 index 0000000..6de622f --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/ContentLayoutPolicy.java @@ -0,0 +1,66 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies.containers; + +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPolicy; +import org.tizen.efluibuilder.gef.dnd.model.ITemplate; +import org.tizen.efluibuilder.model.part.ComponentPart; + + +public class ContentLayoutPolicy extends CommonLayoutPolicy { + + @Override + protected EditPolicy createChildEditPolicy(EditPart child) { +// if (child instanceof DesignEditPart) { +// return new BoxChildResizablePolicy(); +// } + return null; + } + + @Override + protected Rectangle getComponentPack(int objtype, Point srcLoc, Point srcSize, ComponentPart srcModel) { + switch (objtype) { + + case ITemplate.COMPONENT: + case ITemplate.SNIPPET: { + /* + * Create a child widget on a box if there's no child. otherwise, + * BoxChildResizablePolicy + */ + if (getHost().getChildren().size() == 0) { + + return new Rectangle(0, 0, 1, 1); + } + } + break; + default: + break; + } + + return null; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/DesignEditorUtil.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/DesignEditorUtil.java new file mode 100644 index 0000000..ac3bef0 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/DesignEditorUtil.java @@ -0,0 +1,508 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies.containers; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gef.requests.LocationRequest; +import org.tizen.efluibuilder.gef.editparts.DesignEditPart; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.renderer.Position; + + +public class DesignEditorUtil { + public static int VIEW_OUTLINE_WIDTH = 2; + public static int VIEW_TITLEBAR_HEIGHT = 42; + + public static Rectangle pixelBoundToGridBound(EditPart editPart, Rectangle pixelBound) { + if (editPart == null) { + return new Rectangle(); + } + Rectangle gridBound = new Rectangle(); + Part part = (Part) editPart.getModel(); + int gridPropWidth = Integer.parseInt(part.getPropertyValue(LayoutSchemaConstants.GRID_VSIZE_W)); + int gridPropHeight = Integer.parseInt(part.getPropertyValue(LayoutSchemaConstants.GRID_VSIZE_H)); + Rectangle gridPixelBound = DesignEditorUtil.getPartRelatvieBound(editPart); + // if ((pixelBound.width > 0) (pixelBound.height > 0)) { + gridBound.width = (pixelBound.width > 0) ? Math.round((float) (pixelBound.width * gridPropWidth) / (float) gridPixelBound.width) : 0; + gridBound.height = (pixelBound.height > 0) ? Math.round((float) (pixelBound.height * gridPropHeight) / (float) gridPixelBound.height) : 0; + gridBound.x = (pixelBound.x > 0) ? Math.round((float) (pixelBound.x * gridPropWidth) / (float) gridPixelBound.width) : 0; + gridBound.y = (pixelBound.y > 0) ? Math.round((float) (pixelBound.y * gridPropHeight) / (float) gridPixelBound.height) : 0; + // } + return gridBound; + } + + public static boolean isSameParent(List partList) { + for (int i = 1; i < partList.size(); i++) { + if (partList.get(i).getParent() != partList.get(0).getParent()) { + return false; + } + } + return true; + } + + public static Rectangle getPartRelatvieBound(EditPart editpart) { + if (editpart == null) { + return new Rectangle(-1, -1, -1, -1); + } + Position partposition = ((DesignEditPart) editpart).getPosition(); + if (partposition == null) { + return new Rectangle(-1, -1, -1, -1); + } + if (editpart.getParent() == null) { + return partposition.getBounds(); + } + Position parentPosition = ((DesignEditPart) editpart.getParent()).getPosition(); + if (parentPosition == null) { + return partposition.getBounds(); + } + Rectangle bound = partposition.getBounds(); + Rectangle parentBound = parentPosition.getBounds(); + bound.x -= parentBound.x; + bound.y -= parentBound.y; + + return bound; + } + + public static void setGridPackBound(Part part, Rectangle bound) { + if (bound.x >= 0) { + part.setPropertyValue(LayoutSchemaConstants.GRID_PACK_X, Integer.toString(bound.x)); + } + if (bound.y >= 0) { + part.setPropertyValue(LayoutSchemaConstants.GRID_PACK_Y, Integer.toString(bound.y)); + } + if (bound.width > 0) { + part.setPropertyValue(LayoutSchemaConstants.GRID_PACK_W, Integer.toString(bound.width)); + } + if (bound.height > 0) { + part.setPropertyValue(LayoutSchemaConstants.GRID_PACK_H, Integer.toString(bound.height)); + } + } + + public static void setTablePackBound(Part part, Rectangle bound) { + if (bound.x >= 0) { + part.setPropertyValue(LayoutSchemaConstants.TABLE_PACK_COL, Integer.toString(bound.x)); + } + if (bound.y >= 0) { + part.setPropertyValue(LayoutSchemaConstants.TABLE_PACK_ROW, Integer.toString(bound.y)); + } + if (bound.width > 0) { + part.setPropertyValue(LayoutSchemaConstants.TABLE_COL_SPAN, Integer.toString(bound.width)); + } + if (bound.height > 0) { + part.setPropertyValue(LayoutSchemaConstants.TABLE_ROW_SPAN, Integer.toString(bound.height)); + } + } + + public static void setPanesPackBound(Part part, Rectangle bound) { + if (bound.x == 0) { + part.setPropertyValue(LayoutSchemaConstants.PANES_PACK, LayoutSchemaConstants.PANES_PACK_LEFT); + } else if (bound.x == 1) { + part.setPropertyValue(LayoutSchemaConstants.PANES_PACK, LayoutSchemaConstants.PANES_PACK_RIGHT); + } + } + + public static Rectangle getPackBound(ComponentPart part, String configID) { + Part parent = part.getParent(); + if (parent == null) { + return new Rectangle(-1, -1, -1, -1); + } + + return getPackBound(parent.getDescriptorId(), part, configID); + } + + public static Rectangle getPackBound(String parent, ComponentPart part, String configID) { + if (parent == null) { + return new Rectangle(-1, -1, -1, -1); + } + Rectangle results = null; + if (parent.equals(LayoutSchemaConstants.GRID)) { + results = getGridPackBound(part, configID); + } else if (parent.equals(LayoutSchemaConstants.TABLE)) { + results = getTablePackBound(part, configID); + } else if (parent.equals(LayoutSchemaConstants.PANES)) { + results = getPanesPackBound(part, configID); + } else { + results = new Rectangle(-1, -1, -1, -1); + } + + return results; + } + + private static Rectangle getGridPackBound(ComponentPart part, String configurationID) { + Rectangle packBound = new Rectangle(-1, -1, -1, -1); + + String value = part.getPropertyValue(configurationID, LayoutSchemaConstants.GRID_PACK_X); + if (value != null && !value.isEmpty()) { + packBound.x = Integer.parseInt(value); + } + value = part.getPropertyValue(configurationID, LayoutSchemaConstants.GRID_PACK_Y); + if (value != null && !value.isEmpty()) { + packBound.y = Integer.parseInt(value); + } + value = part.getPropertyValue(configurationID, LayoutSchemaConstants.GRID_PACK_W); + if (value != null && !value.isEmpty()) { + packBound.width = Integer.parseInt(value); + } + value = part.getPropertyValue(configurationID, LayoutSchemaConstants.GRID_PACK_H); + if (value != null && !value.isEmpty()) { + packBound.height = Integer.parseInt(value); + } + return packBound; + } + + private static Rectangle getTablePackBound(ComponentPart part, String configurationID) { + Rectangle packBound = new Rectangle(-1, -1, -1, -1); + String value = part.getPropertyValue(configurationID, LayoutSchemaConstants.TABLE_PACK_COL); + if (value != null && !value.isEmpty()) { + packBound.x = Integer.parseInt(value); + } + value = part.getPropertyValue(configurationID, LayoutSchemaConstants.TABLE_PACK_ROW); + if (value != null && !value.isEmpty()) { + packBound.y = Integer.parseInt(value); + } + value = part.getPropertyValue(configurationID, LayoutSchemaConstants.TABLE_COL_SPAN); + if (value != null && !value.isEmpty()) { + packBound.width = Integer.parseInt(value); + } + value = part.getPropertyValue(configurationID, LayoutSchemaConstants.TABLE_ROW_SPAN); + if (value != null && !value.isEmpty()) { + packBound.height = Integer.parseInt(value); + } + return packBound; + } + + private static Rectangle getPanesPackBound(ComponentPart part, String configurationID) { + Rectangle packBound = new Rectangle(-1, -1, -1, -1); + String value = part.getPropertyValue(configurationID, LayoutSchemaConstants.PANES_PACK); + if (value != null && !value.isEmpty()) { + if (value.equals(LayoutSchemaConstants.PANES_PACK_LEFT)) { + packBound.x = 0; + } else { + packBound.x = 1; + } + } + return packBound; + } + + public static List getEmptyTableCellPosList(Part tablePart, String configurationID) { + List children = tablePart.getComponentChildren(); + int rowCnt = Integer.parseInt(tablePart.getPropertyValue(LayoutSchemaConstants.TABLE_ROWS)); + int colCnt = Integer.parseInt(tablePart.getPropertyValue(LayoutSchemaConstants.TABLE_COLS)); + List emptyCellList = new ArrayList(); + + boolean[] cellStatusMap = new boolean[rowCnt * colCnt]; + Rectangle bound; + int stPos, edPos; + int occupiedWidth, occupiedHeight; + for (int i = 0; i < children.size(); i++) { + if (children.get(i) instanceof ComponentPart) { + bound = DesignEditorUtil.getTablePackBound((ComponentPart) children.get(i), configurationID); + occupiedWidth = Math.min(colCnt, bound.x + bound.width) - bound.x; + occupiedHeight = Math.min(rowCnt, bound.y + bound.height) - bound.y; + if (occupiedWidth <= 0 || occupiedHeight <= 0) { + continue; + } + for (int j = 0; j < occupiedHeight; j++) { + stPos = ((bound.y + j) * colCnt) + bound.x; + edPos = stPos + occupiedWidth; + for (int k = stPos; k < edPos; k++) { + cellStatusMap[k] = true; + } + } + } + } + + for (int i = 0; i < rowCnt; i++) { + for (int j = 0; j < colCnt; j++) { + if (cellStatusMap[i * colCnt + j] == false) { + emptyCellList.add(new Point(j, i)); + } + } + } + return emptyCellList; + } + + public static List getEmptyPaneCellPosList(Part panePart, String configurationID) { + List children = panePart.getComponentChildren(); + List emptyCellList = new ArrayList(); + boolean[] cellStatusMap = new boolean[2]; + + Rectangle bound; + for (int i = 0; i < children.size(); i++) { + if (children.get(i) instanceof ComponentPart) { + bound = DesignEditorUtil.getPanesPackBound((ComponentPart) children.get(i), configurationID); + if (bound.x >= 0 && bound.x <= 1) { + cellStatusMap[bound.x] = true; + } + } + } + + for (int i = 0; i < cellStatusMap.length; i++) { + if (cellStatusMap[i] != true) { + emptyCellList.add(new Point(i, 0)); + } + } + return emptyCellList; + } + + public static Point getLocationByRequest(Request request) { + Point mousePt = null; + if (request instanceof LocationRequest) { + mousePt = ((LocationRequest) request).getLocation(); + } else if (request instanceof ChangeBoundsRequest) { + mousePt = ((ChangeBoundsRequest) request).getLocation(); + } else if (request instanceof CreateRequest) { + mousePt = ((CreateRequest) request).getLocation(); + } + + return mousePt; + } + + // TODO Consider about location of this method and name + public static EditPart getEditPart(EditPart editPart, Part part) { + List children = editPart.getChildren(); + for (int i = 0; i < children.size(); i++) { + EditPart childEditPart = (EditPart) children.get(i); + Part childPart = (Part) childEditPart.getModel(); + if (childPart.getUniqueId().equals(part.getUniqueId())) { + return childEditPart; + } + EditPart results = getEditPart(childEditPart, part); + if (results != null) { + return results; + } + } + return null; + } + + public static boolean isContentContainerPart(Part part) { + if (LayoutSchemaConstants.IMAGE.equals(part.getDescriptorId()) || LayoutSchemaConstants.LAYOUT.equals(part.getDescriptorId())) { + return true; + } + return false; + } + + public static boolean isItemContainerPart(Part part) { + if (LayoutSchemaConstants.GENGRID.equals(part.getDescriptorId()) || + LayoutSchemaConstants.GENLIST.equals(part.getDescriptorId()) || + LayoutSchemaConstants.MULTIBUTTONENTRY.equals(part.getDescriptorId()) || + LayoutSchemaConstants.FLIPSELECTOR.equals(part.getDescriptorId()) || + LayoutSchemaConstants.INDEX.equals(part.getDescriptorId()) || + LayoutSchemaConstants.LIST.equals(part.getDescriptorId()) || + LayoutSchemaConstants.TOOLBAR.equals(part.getDescriptorId()) || + LayoutSchemaConstants.HOVERSEL.equals(part.getDescriptorId())) { + return true; + } + return false; + } + + public static boolean isItemPart(Part part) { + if (LayoutSchemaConstants.GENGRIDITEM.equals(part.getDescriptorId()) || + LayoutSchemaConstants.GENLISTITEM.equals(part.getDescriptorId()) || + LayoutSchemaConstants.MULTIBUTTONENTRYITEM.equals(part.getDescriptorId()) || + LayoutSchemaConstants.FLIPSELECTORITEM.equals(part.getDescriptorId()) || + LayoutSchemaConstants.INDEXITEM.equals(part.getDescriptorId()) || + LayoutSchemaConstants.LISTITEM.equals(part.getDescriptorId()) || + LayoutSchemaConstants.TOOLBARITEM.equals(part.getDescriptorId()) || + LayoutSchemaConstants.HOVERSELITEM.equals(part.getDescriptorId())) { + return true; + } + return false; + } + + public static boolean hasContent(Part part) { + if (LayoutSchemaConstants.IMAGE.equals(part.getDescriptorId()) && + !part.getPropertyValue(LayoutSchemaConstants.SRC).isEmpty()) { + return true; + } else if (LayoutSchemaConstants.LAYOUT.equals(part.getDescriptorId()) && + !part.getPropertyValue(LayoutSchemaConstants.SRC).isEmpty()) { + return true; + } + return false; + } + + public static boolean hasPlaceholder(Part part) { + if (LayoutSchemaConstants.TABLE.equals(part.getDescriptorId()) || + LayoutSchemaConstants.PANES.equals(part.getDescriptorId())) { + return true; + } + return false; + } + + public static boolean isHided(Part part, String configurationID) { + if (part instanceof ComponentPart) { + ComponentPart parent = (ComponentPart) part; + while (parent != null && (parent.getParent() instanceof ComponentPart)) { + if (parent.getPropertyValue(configurationID, LayoutSchemaConstants.VISIBLE).equals(LayoutSchemaConstants.FALSE)) { + return true; + } + parent = (ComponentPart) parent.getParent(); + } + } + return false; + } + + public static String getPropertyId(Part part) { + String value = part.getPropertyValue(LayoutSchemaConstants.ID); + if (value != null) { + return value; + } + return ""; + } + + public static String getPropertyId(EditPart editpart) { + if (editpart.getModel() instanceof Part) { + return getPropertyId((Part) editpart.getModel()); + } + return ""; + } + + public static Rectangle getOuterBound(List bounds) { + Rectangle outerBound; + Point p1 = new Point(0, 0); + Point p2 = new Point(1, 1); + Rectangle rect; + for (int i = 0; i < bounds.size(); i++) { + rect = bounds.get(i); + if (i == 0) { + p1.x = rect.x; + p1.y = rect.y; + p2.x = rect.x + rect.width; + p2.y = rect.y + rect.height; + continue; + } + p1.x = Math.min(p1.x, rect.x); + p1.y = Math.min(p1.y, rect.y); + p2.x = Math.max(p2.x, rect.x + rect.width); + p2.y = Math.max(p2.y, rect.y + rect.height); + } + outerBound = new Rectangle(p1.x, p1.y, p2.x - p1.x, p2.y - p1.y); + return outerBound; + } + + public static Point getNextViewPosition(Part viewsPart, int pageWidth, int pageHeight) { + Rectangle outerBound = getPagesOuterBound(viewsPart, pageWidth, pageHeight); + return new Point(outerBound.x + outerBound.width + pageWidth/2, outerBound.y + VIEW_TITLEBAR_HEIGHT); + } + + public static Rectangle getPagesOuterBound(Part viewsPart, int pageWidth, int pageHeight) { + Rectangle outerBound = new Rectangle(0, 0, 1, 1); + Rectangle pageBound = null; + List boundSet = new ArrayList(); + for (int i = 0; i < viewsPart.getChildren().size(); i++) { + pageBound = DesignEditorUtil.getPageBound(viewsPart.getChildren().get(i), pageWidth, pageHeight); + boundSet.add(pageBound); + if (i == 0) { + outerBound = pageBound; + outerBound.width += outerBound.x; + outerBound.height += outerBound.y; + } else { + outerBound.x = Math.min(outerBound.x, pageBound.x); + outerBound.width = Math.max(outerBound.width, pageBound.x + pageBound.width); + outerBound.y = Math.min(outerBound.y, pageBound.y); + outerBound.height = Math.max(outerBound.height, pageBound.y + pageBound.height); + } + } + outerBound.width -= outerBound.x; + outerBound.height -= outerBound.y; + return outerBound; + } + + public static Point getPageLocation(Part viewPart) { + Point location = new Point(0, 0); + try { + location.x = Integer.parseInt(viewPart.getPropertyValue(LayoutSchemaConstants.PAGE_LOCATION_X)); + location.y = Integer.parseInt(viewPart.getPropertyValue(LayoutSchemaConstants.PAGE_LOCATION_Y)); + } catch (NumberFormatException e) { + location.x = location.y = 0; + } + return location; + } + + public static Rectangle getPageBound(Part viewPart, int imgWidth, int imgHeight) { + Point location = getPageLocation(viewPart); + Rectangle bound = new Rectangle(location.x, location.y, imgWidth, imgHeight); + bound.expand(VIEW_OUTLINE_WIDTH, VIEW_OUTLINE_WIDTH); + bound.y -= VIEW_TITLEBAR_HEIGHT; + bound.height += VIEW_TITLEBAR_HEIGHT; + return bound; + } + + public static Rectangle getPageImageBoundFromPageBound(Rectangle pageBound) { + Rectangle imageBound = pageBound.getCopy().expand(-VIEW_OUTLINE_WIDTH, -VIEW_OUTLINE_WIDTH); + imageBound.y += VIEW_TITLEBAR_HEIGHT; + imageBound.height -= VIEW_TITLEBAR_HEIGHT; + return imageBound; + } + + public static Rectangle getTitleBoundFromPageBound(Rectangle pageBound) { + Rectangle imageBound = pageBound.getCopy().expand(-VIEW_OUTLINE_WIDTH, -VIEW_OUTLINE_WIDTH); + imageBound.height = VIEW_TITLEBAR_HEIGHT; + return imageBound; + } + + public static Rectangle getPageBoundFromImageBound(Rectangle imgBound) { + Rectangle pageBound = imgBound.getCopy().expand(VIEW_OUTLINE_WIDTH, VIEW_OUTLINE_WIDTH); + pageBound.y -= VIEW_TITLEBAR_HEIGHT; + pageBound.height += VIEW_TITLEBAR_HEIGHT; + return pageBound; + } + + public static Position getPagePositionFromComponentPosition(Position pagePosition) { + return new Position(pagePosition.x - VIEW_OUTLINE_WIDTH, pagePosition.y - VIEW_OUTLINE_WIDTH - VIEW_TITLEBAR_HEIGHT, + pagePosition.width + VIEW_OUTLINE_WIDTH * 2, pagePosition.height + VIEW_OUTLINE_WIDTH * 2 + VIEW_TITLEBAR_HEIGHT); + } + + public static void scaleRect(Rectangle rect, double scale) { + rect.x = (int) (Math.floor((rect.x * scale))); + rect.y = (int) (Math.floor((rect.y * scale))); + rect.width = (int) (Math.floor((rect.width * scale))); + rect.height = (int) (Math.floor((rect.height * scale))); + } + + public static boolean isCtxpopupView(Part viewPart) { + if (viewPart != null && viewPart.getChildren().size() == 1 && viewPart.getChildren().get(0).getDescriptorId().equals(LayoutSchemaConstants.CTXPOPUP)) { + return true; + } + return false; + } + + public static boolean isUIProperty(String name) { + if (LayoutSchemaConstants.ID.equals(name) || LayoutSchemaConstants.PAGE_LOCATION_X.equals(name) || LayoutSchemaConstants.PAGE_LOCATION_Y.equals(name)) { + return false; + } + return true; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/EditPolicyConstants.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/EditPolicyConstants.java new file mode 100644 index 0000000..d46f6e9 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/EditPolicyConstants.java @@ -0,0 +1,40 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies.containers; + +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.swt.graphics.Color; + + +public final class EditPolicyConstants { + public static final Color HoverGoodColor = ColorConstants.blue; + public static final Color HoverBadColor = ColorConstants.red; + public static final Color HoverSpecialColor = ColorConstants.green; + public static final Color ContainerSelectionBorderColor = ColorConstants.red; + public static final Color WidgetSelectionBorderColor = ContainerSelectionBorderColor; + public static String ROLE_SNAP_FEEDBACK = "Snap Feedback"; + public static String ROLE_CONTAINER_OUTLINE_FEEDBACK = "Container Outline Feedback"; + public static String ROLE_PLACEHOLDER_FEEDBACK = "Placeholder Feedback"; + public static String ROLE_OPEN_EDITOR = "Open Editor"; +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/GridChildResizablePolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/GridChildResizablePolicy.java new file mode 100644 index 0000000..320acea --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/GridChildResizablePolicy.java @@ -0,0 +1,362 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies.containers; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.Handle; +import org.eclipse.gef.Request; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.editparts.ScalableFreeformRootEditPart; +import org.eclipse.gef.handles.ResizeHandle; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.LineAttributes; +import org.tizen.efluibuilder.gef.editparts.DesignEditPart; +import org.tizen.efluibuilder.gef.editparts.DesignRootEditPart; +import org.tizen.efluibuilder.gef.figure.CommonRectangleFigure; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.renderer.Position; +import org.tizen.efluibuilder.ui.resources.ColorResources; + + +public class GridChildResizablePolicy extends CommonChildResizablePolicy { + + private Label infoFeedback; + private static int INFO_FONT_SIZE = 8; + private static int INFO_AREA_W = 100; + private static int INFO_AREA_H = 12; + + public GridChildResizablePolicy() { + super(); + setDragAllowed(true); + } + + @Override + public void activate() { + super.activate(); + + if (infoFeedback == null) { + infoFeedback = new Label(); + infoFeedback.setBounds(new Rectangle(0, 0, 0, 0)); + infoFeedback.setText(""); + infoFeedback.setLabelAlignment(PositionConstants.RIGHT); + infoFeedback.setFont(new Font(null, "default", INFO_FONT_SIZE, SWT.BOLD)); + infoFeedback.setForegroundColor(ColorResources.POLICY_INFO_FEEDBACK); + infoFeedback.setVisible(false); + getNoneScalableFeedbackLayer().add(infoFeedback); + } + } + + @Override + public void deactivate() { + if (infoFeedback != null) { + getNoneScalableFeedbackLayer().remove(infoFeedback); + infoFeedback = null; + } + super.deactivate(); + } + + @Override + protected Rectangle getResizeComponentBound(Request request) { + DesignEditPart editPart = (DesignEditPart) getHost(); + Part part = (Part) editPart.getModel(); + if (!(part instanceof ComponentPart)) { + return new Rectangle(-1, -1, -1, -1); + } + ComponentPart componentPart = (ComponentPart) part; + Dimension realDelta = ((ChangeBoundsRequest) request).getSizeDelta().getCopy(); + int resizeDirection = ((ChangeBoundsRequest) request).getResizeDirection(); + boolean isCentered = ((ChangeBoundsRequest) request).isCenteredResize(); + double zoomValue = 0; + if (editPart.getRoot() != null && editPart.getRoot() instanceof DesignRootEditPart) { + zoomValue = ((DesignRootEditPart) editPart.getRoot()).getZoomManager().getZoom(); + realDelta.width /= zoomValue; + realDelta.height /= zoomValue; + } + if (isCentered == true) { + // realDelta.width /= 2; + // realDelta.height /= 2; + } + Position position = editPart.getPosition(); + + // check min size + { + ComponentDescriptor componentDescriptor = part.getOwnerDocumentPart().getComponentDescriptor(); + String minWidthStr = componentDescriptor.getMinWidth(componentPart); + String minHeightStr = componentDescriptor.getMinHeight(componentPart); + int minWidth = 1; + int minHeight = 1; + + if ((null != minWidthStr) && (null != minHeightStr)) { + minWidth = Integer.valueOf(minWidthStr); + minHeight = Integer.valueOf(minHeightStr); + } + + if (position.width + realDelta.width < minWidth) { + realDelta.width = minWidth - position.width; + } + if (position.height + realDelta.height < minHeight) { + realDelta.height = minHeight - position.height; + } + } + + Rectangle deltea = new Rectangle(0, 0, Math.abs(realDelta.width), Math.abs(realDelta.height)); + Rectangle packDelta = DesignEditorUtil.pixelBoundToGridBound(editPart.getParent(), deltea); + Rectangle packBound = DesignEditorUtil.getPackBound(componentPart, getCurrentConfigurationID()); + if (realDelta.width < 0) { + packBound.width -= packDelta.width; + if ((resizeDirection & PositionConstants.WEST) != 0) { + if (isCentered == true) { + packBound.x += packDelta.width / 2; + } else { + packBound.x += packDelta.width; + } + } else if ((resizeDirection & PositionConstants.EAST) != 0) { + if (isCentered == true) { + packBound.x += packDelta.width / 2; + } + } + } else { + packBound.width += packDelta.width; + if ((resizeDirection & PositionConstants.WEST) != 0) { + if (isCentered == true) { + packBound.x -= packDelta.width / 2; + } else { + packBound.x -= packDelta.width; + } + } else if ((resizeDirection & PositionConstants.EAST) != 0) { + if (isCentered == true) { + packBound.x -= packDelta.width / 2; + } + } + + } + if (realDelta.height < 0) { + packBound.height -= packDelta.height; + if ((resizeDirection & PositionConstants.NORTH) != 0) { + if (isCentered == true) { + packBound.y += packDelta.height / 2; + } else { + packBound.y += packDelta.height; + } + } else if ((resizeDirection & PositionConstants.SOUTH) != 0) { + if (isCentered == true) { + packBound.y += packDelta.height / 2; + } + } + } else { + packBound.height += packDelta.height; + if ((resizeDirection & PositionConstants.NORTH) != 0) { + if (isCentered == true) { + packBound.y -= packDelta.height / 2; + } else { + packBound.y -= packDelta.height; + } + } else if ((resizeDirection & PositionConstants.SOUTH) != 0) { + if (isCentered == true) { + packBound.y -= packDelta.height / 2; + } + } + } + return packBound; + } + + @Override + protected Rectangle getMoveComponentBound(Request request) { + + EditPart editPart = getHost(); + Part part = (Part) editPart.getModel(); + if (!(part instanceof ComponentPart)) { + return new Rectangle(-1, -1, -1, -1); + } + ComponentPart componentPart = (ComponentPart) part; + + Point moveDelta = ((ChangeBoundsRequest) request).getMoveDelta().getCopy(); + + double zoomValue = ((DesignRootEditPart) editPart.getRoot()).getZoomManager().getZoom(); + moveDelta.x /= zoomValue; + moveDelta.y /= zoomValue; + + Rectangle deltea = new Rectangle(0, 0, Math.abs(moveDelta.x), Math.abs(moveDelta.y)); + Rectangle packDelta = DesignEditorUtil.pixelBoundToGridBound(editPart.getParent(), deltea); + Rectangle packBound = DesignEditorUtil.getPackBound(componentPart, getCurrentConfigurationID()); + if (moveDelta.x < 0) { + packBound.x -= packDelta.width; + } else { + packBound.x += packDelta.width; + } + if (moveDelta.y < 0) { + packBound.y -= packDelta.height; + } else { + packBound.y += packDelta.height; + } + return packBound; + } + + @Override + protected Command getAlignCommand(Request request) { + return null; + } + + protected void decoreateResizeHandles(List handles) { + ResizeHandle resizeHandle = null; + + for (Handle handle : handles) { + if (handle instanceof ResizeHandle) { + resizeHandle = (ResizeHandle) handle; + resizeHandle.setBackgroundColor(EditPolicyConstants.WidgetSelectionBorderColor); + resizeHandle.setForegroundColor(EditPolicyConstants.HoverBadColor); + } + } + } + + @SuppressWarnings({ "rawtypes" }) + @Override + protected List createSelectionHandles() { + + List list = new ArrayList(); + createMoveHandle(list); + decoreateResizeHandles(list); + createResizeHandle(list, PositionConstants.NORTH); + createResizeHandle(list, PositionConstants.EAST); + createResizeHandle(list, PositionConstants.SOUTH); + createResizeHandle(list, PositionConstants.WEST); + createResizeHandle(list, PositionConstants.NORTH_EAST); + createResizeHandle(list, PositionConstants.NORTH_WEST); + createResizeHandle(list, PositionConstants.SOUTH_EAST); + createResizeHandle(list, PositionConstants.SOUTH_WEST); + decoreateResizeHandles(list); + + setBorderSelectionHandles(list); + + return list; + } + + private void showInfomationFeedback(final int deltaX, final int deltaY, final int deltaW, final int deltaH) { + DesignEditPart editPart = (DesignEditPart) getHost(); + Position pos = editPart.getPosition(); + + do { + if (null == infoFeedback) + break; + + int moveX = pos.x + deltaX; + int moveY = pos.y + deltaY; + + double viewerZoomScale = getViewerZoomScale(); + if (viewerZoomScale != 0) { + moveX *= viewerZoomScale; + moveY *= viewerZoomScale; + } + String infoText = "(" + moveX + "," + moveY + ")"; + infoFeedback.setBounds(new Rectangle(moveX - INFO_AREA_W, moveY - INFO_AREA_H, INFO_AREA_W, INFO_AREA_H)); + infoFeedback.setText(infoText); + infoFeedback.setVisible(true); + } while (false); + + return; + } + + private void showMoveRequestFeedback(Request request) { + + Point sizeDelta = getMoveDeltaByRequest(request); + if (null != sizeDelta) { + showInfomationFeedback(sizeDelta.x, sizeDelta.y, 0, 0); + } + + return; + } + + private void showResizeRequestFeedback(Request request) { + + Point sizeDelta = getResizeDeltaByRequest(request); + if (null != sizeDelta) { + showInfomationFeedback(0, 0, sizeDelta.x, sizeDelta.y); + } + return; + } + + @Override + public void showSourceFeedback(Request request) { + + if (REQ_MOVE.equals(request.getType())) { + showMoveRequestFeedback(request); + } else if (REQ_RESIZE.equals(request.getType())) { + showResizeRequestFeedback(request); + } + + super.showSourceFeedback(request); + + return; + } + + @Override + protected IFigure createDragSourceFeedbackFigure() { + CommonRectangleFigure r = new CommonRectangleFigure(); + r.setBackgroundColor(ColorResources.DESIGN_EDITOR_CHANGE_BOUND_FEEDBACK_FILL_COLOR, 83); + r.setOutline(true); + r.setLineStyle(Graphics.LINE_DASH); + r.setLineAttributes(new LineAttributes(2, SWT.CAP_ROUND, SWT.JOIN_ROUND, SWT.LINE_CUSTOM, new float[] { 5 }, 10, 20)); + r.setForegroundColor(ColorResources.DESIGN_EDITOR_CHANGE_BOUND_FEEDBACK_LINE_COLOR, 255); + r.setBounds(getInitialFeedbackBounds()); + addFeedback(r); + return r; + } + + @Override + public void eraseSourceFeedback(Request request) { + super.eraseSourceFeedback(request); + + if (null == infoFeedback) + return; + + infoFeedback.setVisible(false); + } + + @Override + public boolean isChangeTargetForParent() { + return true; + } + + private double getViewerZoomScale() { + if (getHost().getViewer().getRootEditPart() instanceof ScalableFreeformRootEditPart) { + ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart) getHost().getViewer().getRootEditPart(); + return rootEditPart.getZoomManager().getZoom(); + } + return 0; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/GridLayoutPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/GridLayoutPolicy.java new file mode 100644 index 0000000..b83d7de --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/GridLayoutPolicy.java @@ -0,0 +1,168 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies.containers; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; +import org.tizen.efluibuilder.gef.dnd.model.ITemplate; +import org.tizen.efluibuilder.gef.editparts.DesignEditPart; +import org.tizen.efluibuilder.gef.editparts.DesignRootEditPart; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; + + +public class GridLayoutPolicy extends CommonLayoutPolicy { + + @Override + protected EditPolicy createChildEditPolicy(EditPart child) { + if (child instanceof DesignEditPart) { + return new GridChildResizablePolicy(); + } + return null; + } + + @Override + protected Rectangle getComponentPack(int objtype, Point srcLoc, Point srcSize, ComponentPart srcModel) { + if ((null == srcLoc) || (null == srcModel)) { + return null; + } + + switch (objtype) { + case ITemplate.COMPONENT: + case ITemplate.SNIPPET: { + double zoomSize = ((DesignRootEditPart) getHost().getRoot()).getZoomManager().getZoom(); + Rectangle pixelPack = getDefaultPixelPack(srcLoc, srcSize, srcModel, zoomSize); + + if (getHost() instanceof GraphicalEditPart) { + IFigure parentFigure = ((GraphicalEditPart) getHost()).getFigure(); + parentFigure.translateToRelative(pixelPack); + } + + // if a widget make to a sub grid + { + pixelPack.x -= ((GraphicalEditPart) getHost()).getFigure().getBounds().x; + pixelPack.y -= ((GraphicalEditPart) getHost()).getFigure().getBounds().y; + } + Rectangle pixelBoundToGridBound = DesignEditorUtil.pixelBoundToGridBound(getHost(), pixelPack); + if (srcSize != null) { + return pixelBoundToGridBound; + } else { + return applySnippetPack(objtype, pixelBoundToGridBound, srcModel, zoomSize); + } + } + default: + break; + } + + return null; + } + + private Rectangle getDefaultPixelPack(Point srcLoc, Point srcSize, Part srcModel, double zoomSize) { + Rectangle pixelPack = new Rectangle(srcLoc.x, srcLoc.y, 100, 100); + + if (null != srcSize) { + pixelPack.width = srcSize.x; + pixelPack.height = srcSize.y; + } else { + Part parent = (Part) getHost().getModel(); + ComponentDescriptor componentDescriptor = parent.getOwnerDocumentPart().getComponentDescriptor(); + String feedbackWidth = componentDescriptor.getFeedbackWidth((ComponentPart) srcModel); + String feedbackHeight = componentDescriptor.getFeedbackHeight((ComponentPart) srcModel); + if ((null != feedbackWidth) && (null != feedbackHeight)) { + pixelPack.width = Integer.valueOf(feedbackWidth); + pixelPack.height = Integer.valueOf(feedbackHeight); + } + + pixelPack.width *= zoomSize; + pixelPack.height *= zoomSize; + } + + // check min size + { + Rectangle minPixelSize = getMinPackSize(srcModel, zoomSize); + int minWidth = minPixelSize.width; + int minHeight = minPixelSize.height; + + if (pixelPack.width < minWidth) { + pixelPack.width = minWidth; + } + if (pixelPack.height < minHeight) { + pixelPack.height = minHeight; + } + } + + return pixelPack; + } + + private Rectangle getMinPackSize(Part srcModel, double zoomSize) { + Part parent = (Part) getHost().getModel(); + ComponentDescriptor componentDescriptor = parent.getOwnerDocumentPart().getComponentDescriptor(); + String minWidthStr = componentDescriptor.getMinWidth((ComponentPart) srcModel); + String minHeightStr = componentDescriptor.getMinHeight((ComponentPart) srcModel); + int minWidth = 1; + int minHeight = 1; + + if ((null != minWidthStr) && (null != minHeightStr)) { + minWidth = Integer.valueOf(minWidthStr); + minHeight = Integer.valueOf(minHeightStr); + } + minWidth *= zoomSize; + minHeight *= zoomSize; + + return new Rectangle(-1, -1, minWidth, minHeight); + } + + private Rectangle applySnippetPack(int objtype, Rectangle gridPack, ComponentPart srcModel, double zoomSize) { + if (ITemplate.SNIPPET == objtype) { + Part parent = (Part) getHost().getModel(); + Rectangle packBound = DesignEditorUtil.getPackBound(LayoutSchemaConstants.GRID, srcModel, getCurrentConfigurationID()); + Rectangle minPackSize = DesignEditorUtil.pixelBoundToGridBound(getHost(), getMinPackSize(srcModel, zoomSize)); + ComponentDescriptor componentDescriptor = parent.getOwnerDocumentPart().getComponentDescriptor(); + if (!componentDescriptor.isContainer(srcModel)) { + if (packBound.height < minPackSize.height) { + gridPack.height = minPackSize.height; + } else { + gridPack.height = packBound.height; + } + + if (packBound.width < minPackSize.width) { + gridPack.width = minPackSize.width; + } else { + gridPack.width = packBound.width; + } + } else { + gridPack.width = packBound.width; + gridPack.height = packBound.height; + } + } + + return gridPack; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/PanePlaceholderOutlineFeedbackPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/PanePlaceholderOutlineFeedbackPolicy.java new file mode 100644 index 0000000..c1b8614 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/PanePlaceholderOutlineFeedbackPolicy.java @@ -0,0 +1,102 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies.containers; + +import java.util.List; + +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.EditPart; +import org.tizen.efluibuilder.gef.editparts.ContainerEditPart; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; + + +public class PanePlaceholderOutlineFeedbackPolicy extends PlaceholderOutlineFeedbackPolicy { + + public static Rectangle getPlaceholderFeedbackBound(EditPart panesEditPart, int index) { + int MARGIN = 2; + DesignViewer viewer; + Part configPart; + ContainerEditPart editPart; + double zoom; + + if ((panesEditPart instanceof ContainerEditPart == false) || + (panesEditPart.getViewer() instanceof DesignViewer == false)) { + return null; + } + viewer = (DesignViewer) panesEditPart.getViewer(); + configPart = viewer.getMScreenQualifierManager().getCurrentConfigurePart(); + if (configPart == null) { + return null; + } + + editPart = (ContainerEditPart) panesEditPart; + zoom = viewer.getZoomScale(); + + int cellCnt = editPart.getCellManager().getCellCount(); + + if (cellCnt > index) { + Rectangle cell = editPart.getCellByIdx(index); + Rectangle bound = new Rectangle((int) (zoom * cell.x + MARGIN), + (int) (zoom * cell.y + MARGIN), + (int) (zoom * cell.width - MARGIN * 2), + (int) (zoom * cell.height - MARGIN * 2)); + return bound; + } + + return null; + } + + public void refresh() { + if (zoomMgr == null) { + return; + } + + if (this.getHost() instanceof ContainerEditPart && this.getHost().getViewer() instanceof DesignViewer) { + ContainerEditPart editPart = (ContainerEditPart) this.getHost(); + Part part = (Part) editPart.getModel(); + DesignViewer viewer = (DesignViewer) editPart.getViewer(); + Part configPart = viewer.getMScreenQualifierManager().getCurrentConfigurePart(); + if (configPart == null) { + return; + } + + String configurationID = configPart.getPropertyValue(LayoutSchemaConstants.ID); + List emptyCells = DesignEditorUtil.getEmptyPaneCellPosList(part, configurationID); + + setPlaceholder(emptyCells.size()); + + for (int idx = 0; idx < emptyCells.size(); idx++) { + Rectangle bounds = getPlaceholderFeedbackBound(editPart, emptyCells.get(idx).x); + if (bounds != null) { + getPlaceholder(idx).setBounds(bounds); + getPlaceholder(idx).setVisible(this.needToShow()); + } + + } + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/PanesChildResizablePolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/PanesChildResizablePolicy.java new file mode 100644 index 0000000..144613c --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/PanesChildResizablePolicy.java @@ -0,0 +1,101 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies.containers; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.Handle; +import org.eclipse.gef.Request; +import org.eclipse.gef.commands.Command; +import org.tizen.efluibuilder.gef.editparts.ContainerEditPart; + + +public class PanesChildResizablePolicy extends CommonChildResizablePolicy { + + public PanesChildResizablePolicy() { + super(); + setDragAllowed(true); + } + + @Override + public void activate() { + super.activate(); + } + + @Override + public void deactivate() { + super.deactivate(); + } + + @Override + protected Rectangle getMoveComponentBound(Request request) { + ContainerEditPart targetEditPart = (ContainerEditPart) getHost().getParent(); + if (null == targetEditPart) { + return null; + } + + Point location = DesignEditorUtil.getLocationByRequest(request).getCopy(); + if (null == location) { + return null; + } + + translateToCustom(location); + int cursorIdx = targetEditPart.findIndexOfCellByPT(location.x, location.y); + if (cursorIdx >= 0) { + Rectangle newPackInfo = targetEditPart.getPackByIdx(cursorIdx, PanesLayoutPolicy.MaxCellCount); + + return newPackInfo; + } + + return null; + } + + protected Command getAlignCommand(Request request) { + return null; + } + + @SuppressWarnings("rawtypes") + @Override + protected List createSelectionHandles() { + + List list = new ArrayList(); + createMoveHandle(list); + + setBorderSelectionHandles(list); + return list; + } + + @Override + public void showTargetFeedback(Request request) { + super.showTargetFeedback(request); + } + + @Override + public void eraseTargetFeedback(Request request) { + super.eraseTargetFeedback(request); + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/PanesLayoutPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/PanesLayoutPolicy.java new file mode 100644 index 0000000..ee2f82e --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/PanesLayoutPolicy.java @@ -0,0 +1,161 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies.containers; + +import java.util.List; + +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.RectangleFigure; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.tizen.efluibuilder.gef.dnd.model.ITemplate; +import org.tizen.efluibuilder.gef.editparts.ContainerEditPart; +import org.tizen.efluibuilder.gef.editparts.DesignEditPart; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.ui.resources.ColorResources; + + +public class PanesLayoutPolicy extends CommonLayoutPolicy { + + public static final int MaxCellCount = 2; + private RectangleFigure hoverFeedback; + + @Override + public void activate() { + super.activate(); + if (hoverFeedback == null) { + hoverFeedback = new RectangleFigure(); + hoverFeedback.setAlpha(127); + hoverFeedback.setFill(true); + hoverFeedback.setOutline(false); + hoverFeedback.setLineWidth(2); + hoverFeedback.setBackgroundColor(ColorResources.DESIGN_EDITOR_CREATION_BOUND_FEEDBACK_COLOR); + hoverFeedback.setLineStyle(Graphics.LINE_SOLID); + hoverFeedback.setBounds(new Rectangle(0, 0, 0, 0)); + hoverFeedback.setVisible(false); + getFeedbackLayer().add(hoverFeedback); + } + } + + @Override + public void showTargetFeedback(Request request) { + super.showTargetFeedback(request); + + Object type = request.getType(); + + if (type.equals(REQ_CREATE) || type.equals(REQ_MOVE)) { + ContainerEditPart targetEditPart = (ContainerEditPart) getHost(); + + if (type.equals(REQ_RESIZE) || type.equals(REQ_MOVE)) { + if (request instanceof ChangeBoundsRequest) { + + @SuppressWarnings("unchecked") + List childParts = ((ChangeBoundsRequest) request).getEditParts(); + for (EditPart part : childParts) { + DesignEditPart parentPart = (DesignEditPart) part.getParent(); + if (parentPart != targetEditPart) { + return; + } + } + } + } + + Point location = DesignEditorUtil.getLocationByRequest(request).getCopy(); + if (null == location) { + return; + } + + if (getHost().getParent() instanceof GraphicalEditPart) { + IFigure parentFigure = ((GraphicalEditPart) getHost().getParent()).getFigure(); + parentFigure.translateToRelative(location); + } + + int cursorIdx = targetEditPart.findIndexOfCellByPT(location.x, location.y); + if (cursorIdx >= 0) { + Rectangle cursorArea = PanePlaceholderOutlineFeedbackPolicy.getPlaceholderFeedbackBound(targetEditPart, cursorIdx); + if (null != cursorArea) { + hoverFeedback.setBounds(cursorArea); + hoverFeedback.setVisible(true); + } + } + } + + return; + } + + @Override + public void eraseTargetFeedback(Request request) { + super.eraseTargetFeedback(request); + + if (null == hoverFeedback) + return; + + hoverFeedback.setVisible(false); + } + + @Override + protected EditPolicy createChildEditPolicy(EditPart child) { + if (child instanceof DesignEditPart) { + return new PanesChildResizablePolicy(); + } + return null; + } + + @Override + protected Rectangle getComponentPack(int objtype, Point srcLoc, Point srcSize, ComponentPart srcModel) { + switch (objtype) { + + case ITemplate.COMPONENT: + case ITemplate.SNIPPET: { + + ContainerEditPart hostEditPart = (ContainerEditPart) getHost(); + Point cursorPt = new Point(srcLoc); + + if (getHost().getParent() instanceof GraphicalEditPart) { + IFigure parentFigure = ((GraphicalEditPart) getHost().getParent()).getFigure(); + parentFigure.translateToRelative(cursorPt); + } + + int placeHolderIdx = hostEditPart.findIndexOfCellByPT(cursorPt.x, cursorPt.y); + int childCntOfHost = ((Part) hostEditPart.getModel()).getComponentChildren().size(); + if ((0 <= placeHolderIdx) && (childCntOfHost < MaxCellCount)) { + return hostEditPart.getPackByIdx(placeHolderIdx, MaxCellCount); + } + + } + break; + default: + break; + } + + return null; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/PlaceholderOutlineFeedbackPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/PlaceholderOutlineFeedbackPolicy.java new file mode 100644 index 0000000..8f66b5f --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/PlaceholderOutlineFeedbackPolicy.java @@ -0,0 +1,111 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies.containers; + +import java.util.ArrayList; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.geometry.Rectangle; +import org.tizen.efluibuilder.gef.figure.CommonRectangleFigure; +import org.tizen.efluibuilder.gef.policies.OutlineFeedbackPolicy; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.ui.resources.ColorResources; + + +public class PlaceholderOutlineFeedbackPolicy extends OutlineFeedbackPolicy { + + protected ArrayList placeholders = new ArrayList(); + protected static int MARGIN = 2; + + @Override + protected boolean needToShow() { + if (this.getHost().getModel() instanceof ComponentPart && this.getHost().getViewer() instanceof DesignViewer) { + ComponentPart model = (ComponentPart) this.getHost().getModel(); + DesignViewer viewer = (DesignViewer) this.getHost().getViewer(); + + if ((viewer.getMScreenQualifierManager().getCurrentConfigurePart() != null) && + DesignEditorUtil.isHided(model, viewer.getMScreenQualifierManager().getCurrentConfigurePart().getPropertyValue(LayoutSchemaConstants.ID))) { + return false; + } + } + return true; + } + + protected void removePlaceholders() { + for (CommonRectangleFigure placeholder : placeholders) { + getFeedbackLayer().remove(placeholder); + } + } + + @Override + public void deactivate() { + removePlaceholders(); + super.deactivate(); + } + + protected void setPlaceholder(int cnt) { + if (placeholders.size() == cnt) { + return; + } else if (placeholders.size() > cnt) { + while (true) { + placeholders.get(placeholders.size() - 1).erase(); + getFeedbackLayer().remove(placeholders.get(placeholders.size() - 1)); + placeholders.remove(placeholders.size() - 1); + if (placeholders.size() == cnt) { + break; + } + } + } else if (placeholders.size() < cnt) { + while (true) { + CommonRectangleFigure placeholder = new CommonRectangleFigure(); + decoreatePlaceholder(placeholder); + placeholders.add(placeholder); + if (placeholders.size() == cnt) { + break; + } + } + } + } + + protected void decoreatePlaceholder(CommonRectangleFigure figure) { + figure.setBackgroundColor(ColorResources.DESIGN_EDITOR_CHANGE_BOUND_FEEDBACK_FILL_COLOR, 0); + figure.setOutline(true); + + figure.setLineStyle(Graphics.LINE_SOLID); + figure.setForegroundColor(ColorResources.DESIGN_EDITOR_PLACEHOLDER_LINE_COLOR, 255); + figure.setBounds(new Rectangle(0, 0, 0, 0)); + figure.setVisible(true); + getFeedbackLayer().add(figure); + } + + public CommonRectangleFigure getPlaceholder(int index) { + return placeholders.get(index); + } + + public void refresh() { + // do nothing + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/TableChildResizablePolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/TableChildResizablePolicy.java new file mode 100644 index 0000000..795d481 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/TableChildResizablePolicy.java @@ -0,0 +1,260 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies.containers; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.Handle; +import org.eclipse.gef.Request; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.tizen.efluibuilder.gef.editparts.ContainerEditPart; +import org.tizen.efluibuilder.gef.editparts.DesignEditPart; +import org.tizen.efluibuilder.gef.editparts.DesignRootEditPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.renderer.Position; + + +public class TableChildResizablePolicy extends CommonChildResizablePolicy { + + public TableChildResizablePolicy() { + super(); + setDragAllowed(true); + } + + @Override + public void activate() { + super.activate(); + } + + @Override + public void deactivate() { + super.deactivate(); + } + + @Override + protected Rectangle getResizeComponentBound(Request request) { + DesignEditPart editPart = (DesignEditPart) getHost(); + Part part = (Part) editPart.getModel(); + Dimension realDelta = ((ChangeBoundsRequest) request).getSizeDelta(); + int resizeDirection = ((ChangeBoundsRequest) request).getResizeDirection(); + Rectangle newPackInfo = new Rectangle(0, 0, 0, 0); + Rectangle currPackInfo = new Rectangle(0, 0, 0, 0); + + // adjust zoom + { + double zoomSize = ((DesignRootEditPart) getHost().getRoot()).getZoomManager().getZoom(); + + realDelta.width /= zoomSize; + realDelta.height /= zoomSize; + } + + // get current pack info + { + currPackInfo.x = Integer.valueOf(part.getPropertyValue(LayoutSchemaConstants.TABLE_PACK_COL)); + currPackInfo.y = Integer.valueOf(part.getPropertyValue(LayoutSchemaConstants.TABLE_PACK_ROW)); + currPackInfo.width = Integer.valueOf(part.getPropertyValue(LayoutSchemaConstants.TABLE_COL_SPAN)); + currPackInfo.height = Integer.valueOf(part.getPropertyValue(LayoutSchemaConstants.TABLE_ROW_SPAN)); + } + + // calculate virtual-delta-value + { + ContainerEditPart parentEditPart = (ContainerEditPart) editPart.getParent(); + if (null == parentEditPart) { + return null; + } + + Position widgetPos = editPart.getPosition(); + Position parentWidgetPos = parentEditPart.getPosition(); + + Point visualDelta = new Point(realDelta.width, realDelta.height); + Point handlePos = new Point(widgetPos.x, widgetPos.y); + + int paddingValue = 10; + + switch (resizeDirection) { + case PositionConstants.NORTH: + visualDelta.y = widgetPos.y - visualDelta.y; + visualDelta.x = widgetPos.x; + break; + case PositionConstants.WEST: + visualDelta.x = widgetPos.x - visualDelta.x; + visualDelta.y = widgetPos.y; + break; + case PositionConstants.SOUTH: + visualDelta.y = widgetPos.y + widgetPos.height + visualDelta.y; + visualDelta.x = widgetPos.x; + handlePos.y += widgetPos.height - paddingValue; + break; + case PositionConstants.EAST: + visualDelta.x = widgetPos.x + widgetPos.width + visualDelta.x; + visualDelta.y = widgetPos.y; + handlePos.x += widgetPos.width - paddingValue; + break; + default: + return null; + } + + // threshold + { + int minX, maxX; + minX = parentWidgetPos.x; + maxX = parentWidgetPos.x + parentWidgetPos.width; + if (minX > visualDelta.x) { + visualDelta.x = minX + paddingValue; + } else if (maxX < visualDelta.x) { + visualDelta.x = maxX - paddingValue; + } + + int minY, maxY; + minY = parentWidgetPos.y; + maxY = parentWidgetPos.y + parentWidgetPos.height; + if (minY > visualDelta.y) { + visualDelta.y = minY + paddingValue; + } else if (maxY < visualDelta.y) { + visualDelta.y = maxY - paddingValue; + } + } + + int deltaIdx = parentEditPart.findIndexOfCellByPTwithoutWID(visualDelta.x, visualDelta.y); + int currIdx = parentEditPart.findIndexOfCellByPTwithoutWID(handlePos.x, handlePos.y); + + if ((deltaIdx == currIdx) || (deltaIdx < 0) || (currIdx < 0)) + return null; + + int tableColCount = parentEditPart.getCellColumCount(); + + int subdeltaIdx = (currIdx > deltaIdx) ? currIdx - deltaIdx : deltaIdx - currIdx; + + switch (resizeDirection) { + case PositionConstants.NORTH: + case PositionConstants.WEST: + if (currIdx < deltaIdx) + subdeltaIdx *= -1; + break; + case PositionConstants.SOUTH: + case PositionConstants.EAST: + if (currIdx > deltaIdx) + subdeltaIdx *= -1; + break; + } + + deltaIdx = subdeltaIdx / tableColCount; + if (deltaIdx == 0) + deltaIdx = subdeltaIdx % tableColCount; + + switch (resizeDirection) { + + case PositionConstants.NORTH: + newPackInfo.y = -deltaIdx; + newPackInfo.height += deltaIdx; + break; + case PositionConstants.WEST: + newPackInfo.x = -deltaIdx; + newPackInfo.width += deltaIdx; + break; + case PositionConstants.SOUTH: + newPackInfo.height += deltaIdx; + break; + case PositionConstants.EAST: + newPackInfo.width += deltaIdx; + break; + } + + } + + // make new pack info + { + newPackInfo.x += currPackInfo.x; + newPackInfo.y += currPackInfo.y; + newPackInfo.width += currPackInfo.width; + newPackInfo.height += currPackInfo.height; + } + + return newPackInfo; + } + + @Override + protected Rectangle getMoveComponentBound(Request request) { + + ContainerEditPart targetEditPart = (ContainerEditPart) getHost().getParent(); + if (null == targetEditPart) { + return null; + } + + Point location = DesignEditorUtil.getLocationByRequest(request).getCopy(); + if (null == location) { + return null; + } + + translateToCustom(location); + int cursorIdx = targetEditPart.findIndexOfCellByPT(location.x, location.y); + if (cursorIdx >= 0) { + int tableColCount = targetEditPart.getCellColumCount(); + + Rectangle newPackInfo = targetEditPart.getPackByIdx(cursorIdx, tableColCount); + + return newPackInfo; + } + + return null; + } + + @Override + protected Command getAlignCommand(Request request) { + return null; + } + + @SuppressWarnings("rawtypes") + @Override + protected List createSelectionHandles() { + + List list = new ArrayList(); + createMoveHandle(list); + createResizeHandle(list, PositionConstants.NORTH); + createResizeHandle(list, PositionConstants.EAST); + createResizeHandle(list, PositionConstants.SOUTH); + createResizeHandle(list, PositionConstants.WEST); + + setBorderSelectionHandles(list); + + return list; + } + + @Override + public void showTargetFeedback(Request request) { + super.showTargetFeedback(request); + } + + @Override + public void eraseTargetFeedback(Request request) { + super.eraseTargetFeedback(request); + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/TableLayoutPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/TableLayoutPolicy.java new file mode 100644 index 0000000..43132da --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/TableLayoutPolicy.java @@ -0,0 +1,159 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies.containers; + +import java.util.List; + +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.RectangleFigure; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.tizen.efluibuilder.gef.dnd.model.ITemplate; +import org.tizen.efluibuilder.gef.editparts.ContainerEditPart; +import org.tizen.efluibuilder.gef.editparts.DesignEditPart; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.ui.resources.ColorResources; + + +public class TableLayoutPolicy extends CommonLayoutPolicy { + + private RectangleFigure hoverFeedback; + + @Override + public void activate() { + super.activate(); + + if (hoverFeedback == null) { + hoverFeedback = new RectangleFigure(); + hoverFeedback.setAlpha(127); + hoverFeedback.setFill(true); + hoverFeedback.setOutline(false); + hoverFeedback.setLineWidth(2); + hoverFeedback.setBackgroundColor(ColorResources.DESIGN_EDITOR_CREATION_BOUND_FEEDBACK_COLOR); + hoverFeedback.setLineStyle(Graphics.LINE_SOLID); + hoverFeedback.setBounds(new Rectangle(0, 0, 0, 0)); + hoverFeedback.setVisible(false); + getFeedbackLayer().add(hoverFeedback); + } + } + + @Override + public void showTargetFeedback(Request request) { + super.showTargetFeedback(request); + + Object type = request.getType(); + if (type.equals(REQ_CREATE) || type.equals(REQ_RESIZE) || type.equals(REQ_MOVE)) { + ContainerEditPart targetEditPart = (ContainerEditPart) getHost(); + + if (type.equals(REQ_RESIZE) || type.equals(REQ_MOVE)) { + if (request instanceof ChangeBoundsRequest) { + + @SuppressWarnings("unchecked") + List childParts = ((ChangeBoundsRequest) request).getEditParts(); + for (EditPart part : childParts) { + DesignEditPart parentPart = (DesignEditPart) part.getParent(); + if (parentPart != targetEditPart) { + return; + } + } + } + } + + Point location = DesignEditorUtil.getLocationByRequest(request).getCopy(); + if (null == location) { + return; + } + + if (getHost().getParent() instanceof GraphicalEditPart) { + IFigure parentFigure = ((GraphicalEditPart) getHost().getParent()).getFigure(); + parentFigure.translateToRelative(location); + } + + int cursorIdx = targetEditPart.findIndexOfCellByPT(location.x, location.y); + if (cursorIdx >= 0) { + Rectangle placeholderRect = TablePlaceholderOutlineFeedbackPolicy.getPlaceholderFeedbackBound(targetEditPart, cursorIdx); + if (null != placeholderRect) { + hoverFeedback.setBounds(placeholderRect); + hoverFeedback.setVisible(true); + } + } + } + + return; + } + + @Override + public void eraseTargetFeedback(Request request) { + super.eraseTargetFeedback(request); + + if (null == hoverFeedback) + return; + + hoverFeedback.setVisible(false); + } + + @Override + protected EditPolicy createChildEditPolicy(EditPart child) { + if (child instanceof DesignEditPart) { + return new TableChildResizablePolicy(); + } + return null; + } + + @Override + protected Rectangle getComponentPack(int objtype, Point srcLoc, Point srcSize, ComponentPart srcModel) { + + switch (objtype) { + + case ITemplate.COMPONENT: + case ITemplate.SNIPPET: { + + ContainerEditPart hostEditPart = (ContainerEditPart) getHost(); + Point cursorPt = new Point(srcLoc); + + if (getHost().getParent() instanceof GraphicalEditPart) { + IFigure parentFigure = ((GraphicalEditPart) getHost().getParent()).getFigure(); + parentFigure.translateToRelative(cursorPt); + } + + int placeHolderIdx = hostEditPart.findIndexOfCellByPT(cursorPt.x, cursorPt.y); + if (placeHolderIdx >= 0) { + return hostEditPart.getPackByIdx(placeHolderIdx, hostEditPart.getCellColumCount()); + } + + } + break; + default: + break; + } + + return null; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/TablePlaceholderOutlineFeedbackPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/TablePlaceholderOutlineFeedbackPolicy.java new file mode 100644 index 0000000..add9caf --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/TablePlaceholderOutlineFeedbackPolicy.java @@ -0,0 +1,108 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies.containers; + +import java.util.List; + +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.EditPart; +import org.tizen.efluibuilder.gef.editparts.ContainerEditPart; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; + + +public class TablePlaceholderOutlineFeedbackPolicy extends PlaceholderOutlineFeedbackPolicy { + + public static Rectangle getPlaceholderFeedbackBound(EditPart tableEditPart, int index) { + int margin = MARGIN; + DesignViewer viewer; + Part configPart; + ContainerEditPart editPart; + double zoom; + + if ((tableEditPart instanceof ContainerEditPart == false) || + (tableEditPart.getViewer() instanceof DesignViewer == false)) { + return null; + } + viewer = (DesignViewer) tableEditPart.getViewer(); + configPart = viewer.getMScreenQualifierManager().getCurrentConfigurePart(); + if (configPart == null) { + return null; + } + + editPart = (ContainerEditPart) tableEditPart; + zoom = viewer.getZoomScale(); + + int cellCnt = editPart.getCellManager().getCellCount(); + + if (cellCnt > index) { + Rectangle cell = editPart.getCellByIdx(index); + Rectangle bound = new Rectangle((int) (zoom * cell.x + margin), + (int) (zoom * cell.y + margin), + (int) (zoom * cell.width - margin * 2), + (int) (zoom * cell.height - margin * 2)); + + return bound; + } + + return null; + } + + @Override + public void refresh() { + if (zoomMgr == null) { + return; + } + + if (this.getHost() instanceof ContainerEditPart && this.getHost().getViewer() instanceof DesignViewer) { + ContainerEditPart editPart = (ContainerEditPart) this.getHost(); + Part part = (Part) editPart.getModel(); + DesignViewer viewer = (DesignViewer) editPart.getViewer(); + Part configPart = viewer.getMScreenQualifierManager().getCurrentConfigurePart(); + if (configPart == null) { + return; + } + + int colCnt = Integer.parseInt(part.getPropertyValue(LayoutSchemaConstants.TABLE_COLS)); + int cellCnt = editPart.getCellManager().getCellCount(); + String configurationID = configPart.getPropertyValue(LayoutSchemaConstants.ID); + List emptyCells = DesignEditorUtil.getEmptyTableCellPosList(part, configurationID); + setPlaceholder(emptyCells.size()); + + int cellIndex; + for (int idx = 0; idx < emptyCells.size(); idx++) { + cellIndex = emptyCells.get(idx).x + emptyCells.get(idx).y * colCnt; + if (cellCnt > cellIndex) { + Rectangle bound = getPlaceholderFeedbackBound(editPart, cellIndex); + if (bound != null) { + getPlaceholder(idx).setBounds(bound); + getPlaceholder(idx).setVisible(this.needToShow()); + } + } + } + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/ViewChildResizablePolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/ViewChildResizablePolicy.java new file mode 100644 index 0000000..96a37b8 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/ViewChildResizablePolicy.java @@ -0,0 +1,78 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies.containers; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.gef.Handle; +import org.eclipse.gef.Request; +import org.eclipse.gef.commands.Command; + + +public class ViewChildResizablePolicy extends CommonChildResizablePolicy { + + public ViewChildResizablePolicy() { + super(); + setDragAllowed(false); + } + + @Override + public void activate() { + super.activate(); + } + + @Override + public void deactivate() { + super.deactivate(); + } + + @Override + protected Command getAlignCommand(Request request) { + return null; + } + + @SuppressWarnings({ "rawtypes" }) + @Override + protected List createSelectionHandles() { + + List list = new ArrayList(); + createMoveHandle(list); + + setBorderSelectionHandles(list); + + return list; + } + + @Override + public void showTargetFeedback(Request request) { + Object extendData = request.getExtendedData().get(REQ_KEY_CHANGETARGET); + if (null != extendData) { + boolean isShowFeedback = ((Boolean) extendData).booleanValue(); + if (isShowFeedback) { + super.showTargetFeedback(request); + } + } + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/ViewLayoutPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/ViewLayoutPolicy.java new file mode 100644 index 0000000..4c91daa --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/ViewLayoutPolicy.java @@ -0,0 +1,123 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies.containers; + +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.commands.Command; +import org.tizen.efluibuilder.gef.dnd.model.ITemplate; +import org.tizen.efluibuilder.gef.editparts.DesignEditPart; +import org.tizen.efluibuilder.gef.editparts.DesignRootEditPart; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.renderer.Position; + + +public class ViewLayoutPolicy extends CommonLayoutPolicy { + + @Override + public void deactivate() { + if (hoverFeedback != null) { + getFeedbackLayer().remove(hoverFeedback); + hoverFeedback = null; + } + + super.deactivate(); + } + + @Override + protected EditPolicy createChildEditPolicy(EditPart child) { + if (child instanceof DesignEditPart) { + return new ViewChildResizablePolicy(); + } + return null; + } + + @Override + public void showTargetFeedback(Request request) { + + Command cmd = getCommand(request); + if ((null == cmd) || (cmd.canExecute() == false)) { + return; + } + + DesignEditPart targetEditPart = (DesignEditPart) getHost(); + Position pos = targetEditPart.getPosition(); + Rectangle area = new Rectangle(pos.x, pos.y, pos.width, pos.height); + + double zoomSize = ((DesignRootEditPart) getHost().getRoot()).getZoomManager().getZoom(); + + DesignEditorUtil.scaleRect(area, zoomSize); + hoverFeedback.setBounds(area); + hoverFeedback.setVisible(true); + return; + } + + @Override + public void eraseTargetFeedback(Request request) { + hoverFeedback.setVisible(false); + return; + } + + @Override + protected Rectangle getComponentPack(int objtype, Point srcLoc, Point srcSize, ComponentPart srcModel) { + + if ((null == srcLoc) || (null == srcModel)) { + return null; + } + + switch (objtype) { + + case ITemplate.COMPONENT: + case ITemplate.SNIPPET: { + if (getHost().getChildren().size() == 0) { + + DesignViewer viewer = (DesignViewer) this.getHost().getViewer(); + if (null != viewer) { + Point windowSize = viewer.getMScreenQualifierManager().getScreenSize(); + if (null != windowSize) { + + return new Rectangle(0, 0, windowSize.x, windowSize.y); + } + } + break; + } + } + default: + break; + } + + return null; + } + + @Override + public Command getCommand(Request request) { + if (REQ_ADD.equals(request.getType())) + return null; + return super.getCommand(request); + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/ViewMovePolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/ViewMovePolicy.java new file mode 100644 index 0000000..80e4206 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/ViewMovePolicy.java @@ -0,0 +1,194 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies.containers; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.draw2d.AbstractBorder; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.Handle; +import org.eclipse.gef.LayerConstants; +import org.eclipse.gef.Request; +import org.eclipse.gef.SharedCursors; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CompoundCommand; +import org.eclipse.gef.editpolicies.ResizableEditPolicy; +import org.eclipse.gef.handles.MoveHandle; +import org.eclipse.gef.handles.ResizableHandleKit; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.tizen.efluibuilder.gef.editparts.DesignRootEditPart; +import org.tizen.efluibuilder.gef.figure.border.WidgetSelectionBorder; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.part.ConfigurationPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.resources.ColorResources; + + +public class ViewMovePolicy extends ResizableEditPolicy { + + final protected String REQ_KEY_CHANGETARGET = "change-target"; + + @Override + public void activate() { + super.activate(); + } + + @Override + public void deactivate() { + super.deactivate(); + } + + @Override + protected void createResizeHandle(List handles, int direction) { + // do nothing + } + + @Override + public Command getCommand(Request request) { + if (REQ_MOVE.equals(request.getType())) { + Point delta = getMoveDeltaByRequest(request); + EditPart editPart = this.getHost(); + Part viewPart = (Part) editPart.getModel(); + CompoundCommand cmd = new CompoundCommand(); + Point viewPos = DesignEditorUtil.getPageLocation(viewPart); + if (delta != null && delta.x != 0) { + cmd.add(PartUtil.createSetPropertyCommand(viewPart, LayoutSchemaConstants.PAGE_LOCATION_X, Integer.toString(delta.x + viewPos.x))); + } + if (delta != null && delta.y != 0) { + cmd.add(PartUtil.createSetPropertyCommand(viewPart, LayoutSchemaConstants.PAGE_LOCATION_Y, Integer.toString(delta.y + viewPos.y))); + } + + if (cmd.size() > 0) { + return cmd; + } + } + + return null; + } + + @SuppressWarnings("rawtypes") + @Override + protected List createSelectionHandles() { + + List list = new ArrayList(); + createMoveHandle(list); + + setBorderSelectionHandles(list); + + return list; + } + + @SuppressWarnings("rawtypes") + @Override + protected void createMoveHandle(List handles) { + if (isDragAllowed()) { + // display 'move' handle to allow dragging + ResizableHandleKit.addMoveHandle((GraphicalEditPart) getHost(), handles, getDragTracker(), SharedCursors.CURSOR_TREE_MOVE); + } else { + // display 'move' handle only to indicate selection + ResizableHandleKit.addMoveHandle((GraphicalEditPart) getHost(), handles, getSelectTracker(), SharedCursors.ARROW); + } + } + + @Override + protected IFigure getFeedbackLayer() { + return getLayer(LayerConstants.SCALED_FEEDBACK_LAYER); + } + + protected IFigure getNoneScalableFeedbackLayer() { + return getLayer(LayerConstants.FEEDBACK_LAYER); + } + + @Override + public EditPart getTargetEditPart(Request request) { + return this.getHost(); + } + + protected void translateToZoom(Point srcPt) { + if (null == srcPt) + return; + + double zoomSize = ((DesignRootEditPart) getHost().getRoot()).getZoomManager().getZoom(); + srcPt.x /= zoomSize; + srcPt.y /= zoomSize; + } + + protected Point getMoveDeltaByRequest(Request request) { + + if (!(request instanceof ChangeBoundsRequest)) { + return null; + } + + ChangeBoundsRequest moveReq = (ChangeBoundsRequest) request; + + Point realDelta = moveReq.getMoveDelta(); + Point sizeDelta = new Point(); + sizeDelta.x = realDelta.x; + sizeDelta.y = realDelta.y; + + translateToZoom(sizeDelta); + + return sizeDelta; + } + + protected void setBorderSelectionHandles(List list) { + + AbstractBorder selectionBorder = null; + selectionBorder = new WidgetSelectionBorder(ColorResources.DESIGN_EDITOR_SELECTION_LINE_COLOR); + + for (Handle handle : list) { + if (handle instanceof MoveHandle) { + ((MoveHandle) handle).setBorder(selectionBorder); + } + } + + return; + } + + public boolean IsChangeTargetForParent() { + return false; + } + + protected ConfigurationPart getCurrentConfiguration() { + DesignViewer viewer = (DesignViewer) getHost().getViewer(); + if (viewer == null) { + return null; + } + return viewer.getMScreenQualifierManager().getCurrentConfigurePart(); + } + + protected String getCurrentConfigurationID() { + ConfigurationPart configPart = getCurrentConfiguration(); + if (configPart == null) { + return null; + } + return configPart.getPropertyValue(LayoutSchemaConstants.ID); + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/ViewTemplateLayoutPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/ViewTemplateLayoutPolicy.java new file mode 100644 index 0000000..d7de5d4 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/policies/containers/ViewTemplateLayoutPolicy.java @@ -0,0 +1,225 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.policies.containers; + +import java.util.Collection; + +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.editparts.ZoomManager; +import org.eclipse.gef.requests.CreateRequest; +import org.tizen.efluibuilder.gef.dnd.model.ITemplate; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.app.AppManager; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.DocumentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.part.ViewsPart; +import org.tizen.efluibuilder.model.snippet.ISnippet; +import org.tizen.efluibuilder.model.snippet.ISnippetManager; +import org.tizen.efluibuilder.model.snippet.SnippetManager; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUnmarshaller; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.views.outline.OutlineConstants; +import org.w3c.dom.Document; + + +public class ViewTemplateLayoutPolicy extends CommonLayoutPolicy { + + static class TemplateFactory { + Part ctxPopupPart = null; + Part popupPart = null; + + public TemplateFactory() { + init(); + } + + private void init() { + String platform = null; + ISnippetManager manager = SnippetManager.getDefault(); + Collection templates = manager.getViewTemplates(); + + Document document = null; + + for (ISnippet template : templates) { + if (!template.getCategory().equals(ISnippet.CATEGORY_SYSTEM)) { + continue; + } + if (template.getName().equals(OutlineConstants.KEY_POPUP_VIEW)) { + document = template.getModel(); + DocumentPart docPart = (DocumentPart) PartUtil.createPart(PartType.DOCUMENT, null); + platform = AppManager.getAppManager().getPlatform(); + docPart.setPlatform(platform); + + PartUnmarshaller unmarshaller = new PartUnmarshaller(); + Part part = unmarshaller.unmarshall(docPart, document, false); + + // get ViewPart from part + popupPart = (part instanceof ViewsPart) ? part.getChildren().get(0) : null; + } + + if (template.getName().equals(OutlineConstants.KEY_CTXPOPUP_VIEW)) { + document = template.getModel(); + DocumentPart docPart = (DocumentPart) PartUtil.createPart(PartType.DOCUMENT, null); + platform = AppManager.getAppManager().getPlatform(); + docPart.setPlatform(platform); + + PartUnmarshaller unmarshaller = new PartUnmarshaller(); + Part part = unmarshaller.unmarshall(docPart, document, false); + + // get ViewPart from part + ctxPopupPart = (part instanceof ViewsPart) ? part.getChildren().get(0) : null; + } + + } + } + + Part getPartFromType(String descriptorId) { + if (LayoutSchemaConstants.CTXPOPUP.equals(descriptorId)) { + if (ctxPopupPart != null) { + return PartUtil.clone(ctxPopupPart, true, null, false); + } + } else if (LayoutSchemaConstants.POPUP.equals(descriptorId)) { + if (popupPart != null) { + return PartUtil.clone(popupPart, true, null, false); + } + } + return null; + } + } + + TemplateFactory factory = null; + + public ViewTemplateLayoutPolicy() { + super(); + } + + public EditPart getTargetEditPart(Request request) { + if (REQ_CREATE.equals(request.getType())) { + return getHost(); + } + return null; + } + + @Override + public void deactivate() { + super.deactivate(); + } + + @Override + protected EditPolicy createChildEditPolicy(EditPart child) { + return null; + } + + public boolean acceptableRequest(Request request) { + if (!REQ_CREATE.equals(request.getType())) { + return false; + } + CreateRequest createReq = (CreateRequest) request; + Object object = createReq.getNewObjectType(); + int objtype = (Integer) object; + if (ITemplate.COMPONENT == objtype && createReq.getNewObject() instanceof ComponentPart) { + ComponentPart part = (ComponentPart) createReq.getNewObject(); + if (LayoutSchemaConstants.VIEW.equals(part.getDescriptorId()) || + LayoutSchemaConstants.POPUP.equals(part.getDescriptorId()) || + LayoutSchemaConstants.CTXPOPUP.equals(part.getDescriptorId())) { + return true; + } + } + return false; + } + + @Override + public void showTargetFeedback(Request request) { + if (acceptableRequest(request)) { + CreateRequest createReq = (CreateRequest) request; + outlineFeedback.setVisible(true); + DesignViewer viewer = ((DesignViewer) getHost().getViewer()); + ZoomManager zoomMgr = viewer.getZoomManager(); + if (zoomMgr == null) { + return; + } + double scale = zoomMgr.getZoom(); + Point screenSize = viewer.getMScreenQualifierManager().getScreenSize(); + outlineFeedback.setBounds(new Rectangle(zoomMgr.getViewport().getViewLocation().x + createReq.getLocation().x, + zoomMgr.getViewport().getViewLocation().y + createReq.getLocation().y, (int) (screenSize.x * scale), + (int) (screenSize.y * scale))); + } + } + + @Override + public void eraseTargetFeedback(Request request) { + if (acceptableRequest(request)) { + outlineFeedback.setVisible(false); + } + } + + @Override + public Command getCommand(Request request) { + if (REQ_CREATE.equals(request.getType())) { + if (factory == null) { + factory = new TemplateFactory(); + } + return getCreateCommand((CreateRequest) request); + } + + return null; + } + + @Override + protected Command getCreateCommand(CreateRequest request) { + Object object = request.getNewObjectType(); + int objtype = (Integer) object; + Part newPart = null; + Part viewsPart = (Part) getHost().getViewer().getContents().getModel(); + if (ITemplate.COMPONENT == objtype && request.getNewObject() instanceof ComponentPart) { + ComponentPart part = (ComponentPart) request.getNewObject(); + if (LayoutSchemaConstants.VIEW.equals(part.getDescriptorId())) { + newPart = PartUtil.createPartWithInitValue(viewsPart.getOwnerDocumentPart(), PartType.VIEW, viewsPart, LayoutSchemaConstants.VIEW); + } else if (LayoutSchemaConstants.POPUP.equals(part.getDescriptorId()) || + LayoutSchemaConstants.CTXPOPUP.equals(part.getDescriptorId())) { + newPart = factory.getPartFromType(part.getDescriptorId()); + } + } + if (newPart != null) { + ZoomManager zoomMgr = ((DesignViewer) getHost().getViewer()).getZoomManager(); + if (zoomMgr == null) { + return null; + } + double scale = 1 / zoomMgr.getZoom(); + newPart.setPropertyValue(LayoutSchemaConstants.PAGE_LOCATION_X, + Integer.toString((int) (scale * (request.getLocation().x + zoomMgr.getViewport().getViewLocation().x)))); + newPart.setPropertyValue(LayoutSchemaConstants.PAGE_LOCATION_Y, + Integer.toString((int) (scale * (request.getLocation().y + +zoomMgr.getViewport().getViewLocation().y)))); + return PartUtil.createAddPartCommand(viewsPart, newPart, null); + } + return null; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/requests/DesignCreateRequest.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/requests/DesignCreateRequest.java new file mode 100644 index 0000000..9bf0030 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/requests/DesignCreateRequest.java @@ -0,0 +1,53 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.requests; + +import org.eclipse.gef.requests.CreateRequest; + + +public class DesignCreateRequest extends CreateRequest { + public static String TYPE_DEFAULT = "default"; + public static String TYPE_PALETTE = "palette"; + public static String TYPE_FILE = "file"; + public static String TYPE_TEMPLATE = "template"; + public static String TYPE_DATABINDING_TEMPLATE = "databindingTemplate"; + private String createType = null; + + public DesignCreateRequest(String reqType) { + super(); + this.createType = reqType; + } + + public DesignCreateRequest() { + this(TYPE_DEFAULT); + } + + public String getCreateType() { + return this.createType; + } + + public void setCreateRequestType(String reqType) { + createType = reqType; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/tools/DesignCreationTool.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/tools/DesignCreationTool.java new file mode 100644 index 0000000..2610e14 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/tools/DesignCreationTool.java @@ -0,0 +1,51 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.tools; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.tools.CreationTool; + + +public class DesignCreationTool extends CreationTool { + // if command is not executable, change target to parent, + private void updateTargetSpecificContainer() { + EditPart target = getTargetEditPart(); + while (target != null && target.getParent() != null) { + Command creationToolCommand = getCommand(); + if ((creationToolCommand != null) && (creationToolCommand.canExecute() == true)) { + break; + } else { + target = target.getParent(); + setTargetEditPart(target); + } + } + } + + protected boolean updateTargetUnderMouse() { + boolean changed = super.updateTargetUnderMouse(); + updateTargetSpecificContainer(); + return changed; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/tools/DesignDragEditPartsTracker.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/tools/DesignDragEditPartsTracker.java new file mode 100644 index 0000000..2695845 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/tools/DesignDragEditPartsTracker.java @@ -0,0 +1,68 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.tools; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.eclipse.gef.tools.DragEditPartsTracker; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.gef.editparts.DesignEditPart; +import org.tizen.efluibuilder.model.part.Part; + + +/** + * A DragTracker that moves {@link org.eclipse.gef.EditPart EditParts}. + */ +public class DesignDragEditPartsTracker extends DragEditPartsTracker /* SelectEditPartTracker */ { + + public DesignDragEditPartsTracker(EditPart sourceEditPart) { + super(sourceEditPart); + // TODO Auto-generated constructor stub + } + + @Override + protected boolean isMove() { + return true; + } + + @Override + protected void updateTargetRequest() { + super.updateTargetRequest(); + } + + @Override + protected void snapPoint(ChangeBoundsRequest request) { + + // !!!!!!!!!!!! NEED TO REFACTORING !!!!!!!!!! + if (getTargetEditPart() instanceof DesignEditPart) { + DesignEditPart editPart = (DesignEditPart) getTargetEditPart(); + if (null != editPart) { + Part targetPart = (Part) editPart.getModel(); + if (targetPart.getDescriptorId().equals(LayoutSchemaConstants.GRID)) { + super.snapPoint(request); + } + } + } + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/tools/DesignDragViewEditPartTracker.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/tools/DesignDragViewEditPartTracker.java new file mode 100644 index 0000000..f2e2d1b --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/tools/DesignDragViewEditPartTracker.java @@ -0,0 +1,105 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.tools; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.tizen.efluibuilder.gef.editparts.ViewEditPart; +import org.tizen.efluibuilder.gef.viewer.DesignStoryboardRouter; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.part.Part; + + + +/** + * A DragTracker that moves {@link org.eclipse.gef.EditPart EditParts}. + */ +public class DesignDragViewEditPartTracker extends DesignDragEditPartsTracker { + + public DesignDragViewEditPartTracker(EditPart sourceEditPart) { + super(sourceEditPart); + } + + @Override + protected void showSourceFeedback() { + ChangeBoundsRequest req = (ChangeBoundsRequest) getTargetRequest(); + DesignViewer viewer = (DesignViewer) this.getSourceEditPart().getViewer(); + double scale = viewer.getZoomScale(); + Point delta = req.getMoveDelta().getCopy(); + delta = new Point((int)(delta.x * (1.0 / scale)), (int)(delta.y * (1.0 / scale))); + List parts = new ArrayList(); + List editParts = getOperationSet(); + for (int i = 0; i < editParts.size(); i++) { + EditPart editPart = (EditPart) editParts.get(i); + if (editPart instanceof ViewEditPart) { + ((ViewEditPart)editPart).moveFigure(delta); + } + parts.add((Part) editPart.getModel()); + } + + DesignStoryboardRouter router = viewer.getStoryBoardRouter(); + router.setPagesDelta(delta, parts); + router.refreshAllConnections(); + } + + @Override + protected boolean handleDragStarted() { + DesignViewer viewer = (DesignViewer) this.getSourceEditPart().getViewer(); + viewer.setVisibleOutlineLayer(false); + return super.handleDragStarted(); + } + + public void deactivate() { + DesignViewer viewer = (DesignViewer) this.getSourceEditPart().getViewer(); + if (viewer != null) { + DesignStoryboardRouter router = viewer.getStoryBoardRouter(); + router.clearPagesDelta(); + } + super.deactivate(); + } + + protected boolean handleButtonUp(int button) { + if (stateTransition(STATE_DRAG_IN_PROGRESS, STATE_TERMINAL)) { + eraseSourceFeedback(); + eraseTargetFeedback(); + performDrag(); + return true; + } + + if (isInState(STATE_DRAG)) { + performSelection(); + setState(STATE_TERMINAL); + return true; + } + return false; + } + + + + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/tools/DesignEditDomain.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/tools/DesignEditDomain.java new file mode 100644 index 0000000..6052d5e --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/tools/DesignEditDomain.java @@ -0,0 +1,82 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.tools; + +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.gef.EditPartViewer; +import org.eclipse.gef.Tool; +import org.eclipse.gef.tools.ConnectionCreationTool; +import org.eclipse.gef.tools.PanningSelectionTool; +import org.eclipse.gef.tools.SelectionTool; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.ui.IEditorPart; +import org.tizen.efluibuilder.gef.editparts.ComponentEditPart; +import org.tizen.efluibuilder.gef.tools.DesignPanningTool; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.TizenEditDomain; + + + +public class DesignEditDomain extends TizenEditDomain { + private ConnectionCreationTool connectionCreationtool = new ConnectionCreationTool(); + private PanningSelectionTool panningTool = new DesignPanningTool(); + private boolean connectionEnable = false; + + public DesignEditDomain(IEditorPart editorPart) { + super(editorPart); + } + + public boolean isConnectionEnabled() { + return connectionEnable; + } + + public void clearConnectionEnabled () { + connectionEnable = false; + } + + public void mouseDown(MouseEvent mouseEvent, EditPartViewer viewer) { + Point p = new Point(mouseEvent.x, mouseEvent.y); + if ((mouseEvent.stateMask & SWT.SHIFT) != 0 + && viewer.findObjectAt(p) instanceof ComponentEditPart && getActiveTool() instanceof SelectionTool + ) { + this.setActiveTool(connectionCreationtool); + connectionEnable = true; + } else if (mouseEvent.button == 2) { + this.setActiveTool(panningTool); + } + + Tool tool = getActiveTool(); + if (tool != null) { + tool.mouseDown(mouseEvent, viewer); + } + } + + public void mouseUp(MouseEvent mouseEvent, EditPartViewer viewer) { + if (getActiveTool() instanceof ConnectionCreationTool || getActiveTool() instanceof DesignPanningTool) { + this.loadDefaultTool(); + } + + super.mouseUp(mouseEvent, viewer); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/tools/DesignMarqueeDragTracker.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/tools/DesignMarqueeDragTracker.java new file mode 100644 index 0000000..6efa665 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/tools/DesignMarqueeDragTracker.java @@ -0,0 +1,97 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.tools; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.tools.MarqueeDragTracker; +import org.eclipse.jface.viewers.StructuredSelection; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; + + +public class DesignMarqueeDragTracker extends MarqueeDragTracker { + + private EditPart sourceEditPart = null; + + public DesignMarqueeDragTracker(EditPart sourceEditPart) { + + this.sourceEditPart = sourceEditPart; + } + + private boolean isChildOfEditPart(EditPart parentEditPart, EditPart editPart) { + EditPart parent = editPart; + while (parent != null) { + if (parentEditPart == parent) { + return true; + } + parent = parent.getParent(); + } + return false; + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + protected Collection calculateMarqueeSelectedEditParts() { + HashSet selectedEditParts = (HashSet) super.calculateMarqueeSelectedEditParts(); + ArrayList removeParts = new ArrayList(); + for (EditPart targetPart : selectedEditParts) { + for (EditPart parentPart : selectedEditParts) { + if (parentPart == targetPart) { + continue; + } + if (isChildOfEditPart(parentPart, targetPart) == true) { + removeParts.add(targetPart); + break; + } + } + } + selectedEditParts.removeAll(removeParts); + + return selectedEditParts; + } + + @SuppressWarnings("unchecked") + @Override + protected void handleFinished() { + @SuppressWarnings("rawtypes") + Collection marqueeSelectedEditParts = calculateMarqueeSelectedEditParts(); + if (0 >= marqueeSelectedEditParts.size()) { + + List selectedEditParts = new ArrayList(); + + if (getCurrentViewer().getSelectedEditParts().size() > 0 && getCurrentSelectionMode() > 0) { + selectedEditParts.addAll(getCurrentViewer().getSelectedEditParts()); + } + selectedEditParts.add(sourceEditPart); + + ((DesignViewer) getCurrentViewer()).setSelection(new StructuredSelection(selectedEditParts)); + + } + + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/tools/DesignPanningTool.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/tools/DesignPanningTool.java new file mode 100644 index 0000000..7d4adf1 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/tools/DesignPanningTool.java @@ -0,0 +1,71 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.tools; + +import org.eclipse.draw2d.FigureCanvas; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.gef.tools.PanningSelectionTool; +import org.eclipse.swt.events.KeyEvent; + +public class DesignPanningTool extends PanningSelectionTool{ + private Point viewLocation; + + @Override + protected boolean handleButtonDown(int which) { + if (which == 2 && stateTransition(STATE_INITIAL, PAN) + && getCurrentViewer().getControl() instanceof FigureCanvas + && stateTransition(PAN, PAN_IN_PROGRESS) + ) { + refreshCursor(); + viewLocation = ((FigureCanvas) getCurrentViewer().getControl()) + .getViewport().getViewLocation(); + return true; + } + return super.handleButtonDown(which); + } + + @Override + protected boolean handleDrag() { + if (isInState(PAN_IN_PROGRESS) + && getCurrentViewer().getControl() instanceof FigureCanvas) { + FigureCanvas canvas = (FigureCanvas) getCurrentViewer() + .getControl(); + canvas.scrollTo(viewLocation.x - getDragMoveDelta().width, + viewLocation.y - getDragMoveDelta().height); + return true; + } else { + return super.handleDrag(); + } + } + + @Override + protected boolean handleKeyDown(KeyEvent e) { + return false; + } + + @Override + protected boolean handleKeyUp(KeyEvent e) { + return false; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/tools/DesignRootMarqueeDragTracker.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/tools/DesignRootMarqueeDragTracker.java new file mode 100644 index 0000000..7af5e4a --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/tools/DesignRootMarqueeDragTracker.java @@ -0,0 +1,87 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.tools; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.tools.MarqueeDragTracker; +import org.tizen.efluibuilder.model.part.ViewPart; + + +public class DesignRootMarqueeDragTracker extends MarqueeDragTracker { + + protected EditPart sourceEditPart = null; + + public DesignRootMarqueeDragTracker(EditPart sourceEditPart) { + + this.sourceEditPart = sourceEditPart; + } + + private boolean isChildOfEditPart(EditPart parentEditPart, EditPart editPart) { + EditPart parent = editPart; + while (parent != null) { + if (parentEditPart == parent) { + return true; + } + parent = parent.getParent(); + } + return false; + } + + @Override + protected Collection calculateMarqueeSelectedEditParts() { + @SuppressWarnings("unchecked") + HashSet selectedEditParts = (HashSet) super.calculateMarqueeSelectedEditParts(); + ArrayList removeParts = new ArrayList(); + + // remove view part + for (EditPart targetPart : selectedEditParts) { + if (targetPart.getModel() instanceof ViewPart) { + removeParts.add(targetPart); + } + } + selectedEditParts.removeAll(removeParts); + removeParts.clear(); + + // remove child part + for (EditPart targetPart : selectedEditParts) { + for (EditPart parentPart : selectedEditParts) { + if (parentPart == targetPart) { + continue; + } + if (isChildOfEditPart(parentPart, targetPart) == true) { + removeParts.add(targetPart); + break; + } + } + } + selectedEditParts.removeAll(removeParts); + + return selectedEditParts; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/tools/DesignSelectionTool.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/tools/DesignSelectionTool.java new file mode 100644 index 0000000..12c779f --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/tools/DesignSelectionTool.java @@ -0,0 +1,75 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.tools; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.tools.SelectionTool; +import org.tizen.efluibuilder.gef.editparts.DesignEditPart; + + +public class DesignSelectionTool extends SelectionTool { + + final static private int BORDER_SIZE = 10; + final static private String REQ_KEY_CHANGETARGET = "change-target"; + + @SuppressWarnings("unchecked") + private boolean updateTarget() { + + /* + * This logic make a cursor for own parent selection. + */ + boolean changed = false; + if (getTargetEditPart() == null) + return changed; + + if ((getTargetEditPart().getParent() != null) && (getTargetEditPart().getParent() instanceof DesignEditPart)) { + IFigure figure = ((DesignEditPart) getTargetEditPart()).getFigure(); + Rectangle parentBounds = figure.getParent().getBounds().getCopy(); + + Point mousept = getLocation(); + ((DesignEditPart) getTargetEditPart()).getFigure().translateToRelative(mousept); + + if (parentBounds.contains(mousept)) { + parentBounds.shrink(BORDER_SIZE, BORDER_SIZE); + if (!parentBounds.contains(mousept)) { + setTargetEditPart(getTargetEditPart().getParent()); + changed = true; + } + } + getTargetRequest().getExtendedData().put(REQ_KEY_CHANGETARGET, changed); + } + + return changed; + } + + protected boolean updateTargetUnderMouse() { + boolean changed = super.updateTargetUnderMouse(); + if (updateTarget() == true) { + changed = true; + } + return changed; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/ConnectionCreateListener.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/ConnectionCreateListener.java new file mode 100644 index 0000000..8791888 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/ConnectionCreateListener.java @@ -0,0 +1,61 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.viewer; + +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.MenuItem; +import org.tizen.efluibuilder.model.part.Part; + + +public class ConnectionCreateListener implements SelectionListener { + + DesignViewer viewer = null; + Part srcPart = null; + Part targetViewPart = null; + + public ConnectionCreateListener(DesignViewer viewer, Part srcPart, Part targetViewPart) { + this.viewer = viewer; + this.srcPart = srcPart; + this.targetViewPart = targetViewPart; + } + + protected void createConnection(String text, Part targetViewPart) { + this.targetViewPart = targetViewPart; + } + protected void createConnection(String text) { + ConnectionCreater.createConnection(viewer, srcPart, targetViewPart, text); + } + + @Override + public void widgetDefaultSelected(SelectionEvent event) { + createConnection(((MenuItem) event.getSource()).getText()); + } + + @Override + public void widgetSelected(SelectionEvent event) { + createConnection(((MenuItem) event.getSource()).getText()); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/ConnectionCreater.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/ConnectionCreater.java new file mode 100644 index 0000000..d3ec8f9 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/ConnectionCreater.java @@ -0,0 +1,49 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.viewer; + +import org.eclipse.gef.commands.Command; +import org.eclipse.ui.PlatformUI; +import org.tizen.efluibuilder.model.part.Part; + + +public class ConnectionCreater { + public static void createConnection(DesignViewer viewer, Part srcPart, Part targetPart, String eventText) { + Runnable createConnJob = new Runnable() { + @Override + public void run() { + if (srcPart != null && targetPart != null) { + String eventName = eventText.replace(',', '_'); + Command cmd = DesignStoryboardUtil.getCreateConnectionCommand(srcPart, targetPart, eventName, eventText); + viewer.getEditDomain().getCommandStack().execute(cmd); + viewer.getDesignStoryboardUtil().generateConnectionCode(srcPart, eventName); + } + + } + }; + + PlatformUI.getWorkbench().getDisplay().syncExec(createConnJob); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/DesignEventDelegator.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/DesignEventDelegator.java new file mode 100644 index 0000000..8e4826a --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/DesignEventDelegator.java @@ -0,0 +1,69 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.viewer; + +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.MouseMoveListener; +import org.tizen.efluibuilder.ui.editor.KeyHandler; + + +public class DesignEventDelegator implements MouseMoveListener, MouseListener, KeyListener { + + private KeyHandler keyHandler; + + public DesignEventDelegator(KeyHandler keyHandler) { + this.keyHandler = keyHandler; + } + + @Override + public void mouseMove(MouseEvent e) { + } + + @Override + public void mouseDown(MouseEvent e) { + } + + @Override + public void mouseDoubleClick(MouseEvent e) { + + } + + @Override + public void mouseUp(MouseEvent e) { + + } + + @Override + public void keyReleased(KeyEvent e) { + keyHandler.keyReleased(e); + } + + @Override + public void keyPressed(KeyEvent e) { + keyHandler.keyPressed(e); + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/DesignStoryboardRouter.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/DesignStoryboardRouter.java new file mode 100644 index 0000000..899e506 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/DesignStoryboardRouter.java @@ -0,0 +1,424 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.viewer; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.draw2d.AbstractRouter; +import org.eclipse.draw2d.Connection; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.PointList; +import org.eclipse.swt.graphics.Rectangle; +import org.tizen.efluibuilder.gef.editparts.DesignConnectionEditPart; +import org.tizen.efluibuilder.gef.editparts.DesignStoryboardPolylineConnection; +import org.tizen.efluibuilder.gef.policies.containers.DesignEditorUtil; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.mscreen.configurator.MScreenQualifierManager; + + +public class DesignStoryboardRouter extends AbstractRouter { + + static int MARGIN = 100; + static int SPACE = 80; + + Part docPart = null; + MScreenQualifierManager msqm = null; + DesignViewer viewer = null; + Map viewConnections = new HashMap(); + Map connections = new HashMap(); + boolean isViewPositionValidate = false; + + Point pageDelta = new Point(0, 0); + List deltaPages = new ArrayList(); + + public DesignStoryboardRouter(Part docPart, MScreenQualifierManager msqm, DesignViewer viewer) { + super(); + this.docPart = docPart; + this.msqm = msqm; + this.viewer = viewer; + this.refresh(); + } + + private Part getViewPartByName(String name) { + for (ViewConnections vc : viewConnections.values()) { + if (vc.viewPart.getPropertyValue(LayoutSchemaConstants.ID).equals(name)) { + return vc.viewPart; + } + } + return null; + } + + private Rectangle getPageSize(Part viewPart) { + Point screenSize = msqm.getScreenSize(); + org.eclipse.draw2d.geometry.Rectangle bound = DesignEditorUtil.getPageBound(viewPart, screenSize.x, screenSize.y); + Rectangle pageBound = new Rectangle(bound.x, bound.y, bound.width, bound.height); + if (deltaPages.contains(viewPart)) { + pageBound.x += pageDelta.x; + pageBound.y += pageDelta.y; + } + return pageBound; + } + + private ConnectionModel createConnectionModel(Part eventPart) { + Part srcView = ((ComponentPart) eventPart.getParent()).getOwnerViewPart(); + Part targetView = getViewPartByName(eventPart.getPropertyValue(LayoutSchemaConstants.EVENT_TARGET)); + if (srcView != null && targetView != null) { + return new ConnectionModel(eventPart, srcView, targetView, getPageSize(srcView), getPageSize(targetView)); + } + return null; + } + + private void initData() { + List connectionParts = null; + ConnectionModel model = null; + Part part = null; + connections.clear(); + for (ViewConnections vc : viewConnections.values()) { // create viewModel + part = vc.viewPart; + connectionParts = DesignStoryboardUtil.getConnectionPart(part); + for (Part connection : connectionParts) { // create connection model + model = createConnectionModel(connection); + if (model != null) { + connections.put(connection.getUniqueId(), model); + } + } + } + + for (ConnectionModel cd : connections.values()) { + if (cd.isBottomSource()) { + viewConnections.get(cd.srcViewPart.getUniqueId()).bottomSource.add(cd); + viewConnections.get(cd.targetViewPart.getUniqueId()).topTarget.add(cd); + } else { + viewConnections.get(cd.srcViewPart.getUniqueId()).rightSource.add(cd); + viewConnections.get(cd.targetViewPart.getUniqueId()).leftTarget.add(cd); + } + } + } + + public void refresh() { + viewConnections = new HashMap(); + Part viewsPart = PartUtil.findViewsPart(docPart); + if (viewsPart != null) { + for (Part part : viewsPart.getChildren()) { + viewConnections.put(part.getUniqueId(), new ViewConnections(part)); + } + } + + initData(); + for (ViewConnections vc : viewConnections.values()) { // create viewModel + vc.sort(); + } + for (ViewConnections vc : viewConnections.values()) { // create viewModel + vc.setPositions(); + } + + for (ViewConnections vc : viewConnections.values()) { // create viewModel + vc.decoratePolyline(); + } + } + + class ConnectionModel { + Part srcPart = null; + Part srcViewPart = null; + Part targetViewPart = null; + Point srcPoint = new Point(); + Point targetPoint = new Point(); + PointList points = new PointList(); + Rectangle srcBound; + Rectangle targetBound; + boolean isCtxpopupTarget = false; + + public ConnectionModel(Part srcPart, Part srcViewPart, Part targetViewPart, Rectangle srcBound, Rectangle targetBound) { + this.srcPart = srcPart; + this.srcViewPart = srcViewPart; + this.targetViewPart = targetViewPart; + this.srcBound = srcBound; + this.targetBound = targetBound; + isCtxpopupTarget = DesignEditorUtil.isCtxpopupView(targetViewPart); + } + + boolean isBottomSource() { + if (targetBound.y + targetBound.height < srcBound.y) { + return false; + } else if ((targetBound.y >= srcBound.y) && (targetBound.x >= srcBound.x + srcBound.width)) { + return false; + } + return true; + } + + PointList getConnectionPoints() { + double scale = viewer.getZoomScale(); + PointList pl = new PointList(); + for (int i = 0; i < points.size(); i++) { + pl.addPoint((int) (scale * points.getPoint(i).x), (int) (scale * points.getPoint(i).y)); + + } + return pl; + } + } + + private static class xAxisSourceComparator implements Comparator { + @Override + public int compare(ConnectionModel o1, ConnectionModel o2) { + Rectangle p1 = o1.srcBound; + Rectangle p2 = o2.srcBound; + if (p1.x == p2.x) { + return p1.y - p2.y; + } + return p1.x - p2.x; + } + + } + + private static class xAxisTargetComparator implements Comparator { + @Override + public int compare(ConnectionModel o1, ConnectionModel o2) { + Rectangle p1 = o1.targetBound; + Rectangle p2 = o2.targetBound; + if (p1.x == p2.x) { + return p1.y - p2.y; + } + return p1.x - p2.x; + } + + } + + private static class yAxisSourceComparator implements Comparator { + @Override + public int compare(ConnectionModel o1, ConnectionModel o2) { + Rectangle p1 = o1.srcBound; + Rectangle p2 = o2.srcBound; + if (p1.y == p2.y) { + return p1.x - p2.x; + } + return p1.y - p2.y; + } + + } + + private static class yAxisTargetComparator implements Comparator { + @Override + public int compare(ConnectionModel o1, ConnectionModel o2) { + Rectangle p1 = o1.targetBound; + Rectangle p2 = o2.targetBound; + if (p1.y == p2.y) { + return p1.x - p2.x; + } + return p1.y - p2.y; + } + + } + + class ViewConnections { + List connectionParts = null; + List connectionModels = null; + Part viewPart = null; + + List rightSource = new ArrayList(); + List bottomSource = new ArrayList(); + List leftTarget = new ArrayList(); + List topTarget = new ArrayList(); + + ViewConnections(Part viewPart) { + this.viewPart = viewPart; + } + + public List getRightSource() { + return rightSource; + } + + public List getBottomSource() { + return bottomSource; + } + + public List getLeftTarget() { + return leftTarget; + } + + public List getTopTarget() { + return topTarget; + } + + public void sort() { + rightSource.sort(new yAxisTargetComparator()); + leftTarget.sort(new yAxisSourceComparator()); + bottomSource.sort(new xAxisTargetComparator()); + topTarget.sort(new xAxisSourceComparator()); + } + + public void setPositions() { + int startPos; + ConnectionModel connectionModel; + // right source + Rectangle pageBound = getPageSize(viewPart); + startPos = ((pageBound.y + (pageBound.height - (SPACE * rightSource.size() - 1)) / 2)); + for (int i = 0; i < rightSource.size(); i++) { + connectionModel = rightSource.get(i); + connectionModel.srcPoint.x = pageBound.x + pageBound.width; + connectionModel.srcPoint.y = startPos + SPACE * i; + } + + // bottom source + startPos = ((pageBound.x + (pageBound.width - (SPACE * bottomSource.size() - 1)) / 2)); + for (int i = 0; i < bottomSource.size(); i++) { + connectionModel = bottomSource.get(i); + connectionModel.srcPoint.x = startPos + SPACE * i; + connectionModel.srcPoint.y = pageBound.y + pageBound.height; + } + + // left target + startPos = ((pageBound.y + (pageBound.height - (SPACE * leftTarget.size() - 1)) / 2)); + for (int i = 0; i < leftTarget.size(); i++) { + connectionModel = leftTarget.get(i); + connectionModel.targetPoint.x = pageBound.x; + connectionModel.targetPoint.y = startPos + SPACE * i; + } + + // top target + startPos = ((pageBound.x + (pageBound.width - (SPACE * topTarget.size() - 1)) / 2)); + for (int i = 0; i < topTarget.size(); i++) { + connectionModel = topTarget.get(i); + connectionModel.targetPoint.x = startPos + SPACE * i; + connectionModel.targetPoint.y = pageBound.y; + } + + } + + public void decoratePolyline() { + ConnectionModel connectionModel; + // right source + for (int i = 0; i < rightSource.size(); i++) { + connectionModel = rightSource.get(i); + connectionModel.points = new PointList(); + connectionModel.points.addPoint(connectionModel.srcPoint); + connectionModel.points.addPoint(new Point(connectionModel.srcPoint.x + MARGIN, connectionModel.srcPoint.y)); + connectionModel.points.addPoint(new Point(connectionModel.targetPoint.x - MARGIN, connectionModel.targetPoint.y)); + connectionModel.points.addPoint(connectionModel.targetPoint); + } + + // bottom source + for (int i = 0; i < bottomSource.size(); i++) { + connectionModel = bottomSource.get(i); + connectionModel.points.addPoint(connectionModel.srcPoint); + connectionModel.points.addPoint(new Point(connectionModel.srcPoint.x, connectionModel.srcPoint.y + MARGIN)); + connectionModel.points.addPoint(new Point(connectionModel.targetPoint.x, connectionModel.targetPoint.y - MARGIN)); + connectionModel.points.addPoint(connectionModel.targetPoint); + } + } + + public List getTargetParts() { + List targets = new ArrayList(); + for (ConnectionModel cm : leftTarget) { + targets.add(cm.srcPart); + } + + for (ConnectionModel cm : topTarget) { + targets.add(cm.srcPart); + } + return targets; + } + + } + + public ConnectionModel getConnectionModel(Part part) { + return connections.get(part.getUniqueId()); + } + + private void printConnection(Connection conn) { + if (conn.getPoints().size() > 0) { + System.out.printf("%s : ", ((DesignStoryboardPolylineConnection) conn).getOwnerPart().getPropertyValue(LayoutSchemaConstants.ID)); + for (int i = 0; i < conn.getPoints().size(); i++) { + Point pt = conn.getPoints().getPoint(i); + System.out.printf("%d %d, ", pt.x, pt.y); + } + System.out.println(""); + } + } + + @Override + public void route(Connection connection) { + Part part = null; + part = ((DesignStoryboardPolylineConnection) connection).getOwnerPart(); + ConnectionModel model = getConnectionModel(part); + if (model == null) { + return; + } + connection.getPoints().removeAllPoints(); + connection.setPoints(model.getConnectionPoints()); + ((DesignStoryboardPolylineConnection) connection).decorate(model.isBottomSource(), model.isCtxpopupTarget, viewer.getZoomScale()); + + if (isViewPositionValidate == true) { + connection.setVisible(true); + } else { + connection.setVisible(false); + } + } + + public void setPagesDelta(Point pageDelta, List viewParts) { + this.pageDelta = pageDelta; + this.deltaPages = viewParts; + } + + public void clearPagesDelta() { + if (deltaPages.isEmpty() == false) { + this.deltaPages.clear(); + refreshAllConnections(); + } + } + + public void refreshAllConnections() { + this.refresh(); + DesignConnectionEditPart editpart; + for (ConnectionModel cm : this.connections.values()) { + editpart = (DesignConnectionEditPart) viewer.getEditPartRegistry().get(cm.srcPart.getUniqueId()); + if (editpart != null) { + editpart.refreshFigure(); + } + } + + } + + public List getTargetConnectionPartFromView(Part viewPart) { + ViewConnections vc = this.viewConnections.get(viewPart.getUniqueId()); + if (vc != null) { + return vc.getTargetParts(); + } + return new ArrayList(); + } + + public void setViewPositionValidate(boolean validate) { + if (isViewPositionValidate != validate) { + isViewPositionValidate = validate; + this.refreshAllConnections(); + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/DesignStoryboardUtil.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/DesignStoryboardUtil.java new file mode 100644 index 0000000..bf8c018 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/DesignStoryboardUtil.java @@ -0,0 +1,357 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.viewer; + +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Queue; + +import org.eclipse.core.resources.IProject; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CompoundCommand; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.EventPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.storyboard.codegenerator.CodeGenerator; +import org.tizen.efluibuilder.storyboard.codegenerator.CodeGeneratorConstants; +import org.w3c.dom.Element; + + +public class DesignStoryboardUtil { + + SBMetaData sbMetaData = null; + static int MARGIN = 400; + CodeGenerator codeGenerator = null; + + public DesignStoryboardUtil(IProject project) { + codeGenerator = new CodeGenerator(project); + sbMetaData = new SBMetaData(project); + } + + static class Node { + int id = 0; + int col = 0; + int row = 0; + Part part = null; + List children = new ArrayList(); + + public Node(Part part, int id) { + this.part = part; + this.id = id; + } + + public void setChildren(List children) { + this.children = children; + } + + } + + private static Point dfs(Node node, Node parent, int row, int col, boolean[] visited) { + visited[node.id] = true; + node.col = col; + if (parent != null) { + node.row = row; + } else { + node.row = 0; + } + + int lastCol = node.col; + int lastRow = row; + Point lastChildPos; + for (Node child : node.children) { + if (visited[child.id] == false) { + lastChildPos = dfs(child, node, lastRow++, col + 1, visited); + lastCol = Math.max(lastCol, lastChildPos.x); + lastRow = Math.max(lastRow, lastChildPos.y); + } + } + + return new Point(lastCol, lastRow); + } + + public static boolean setStoryboardReconstructProperties(Part documentPart, Point screenSize) { + List views = PartUtil.findViewsPart(documentPart).getChildren(); + int size = views.size(); + Part view = null; + Node entryNode = null; + Node newNode = null; + Point lastPosition; + boolean bPropertyChanged = false; + + boolean[] visited = new boolean[size + 1]; + List nodeList = new ArrayList(); + + String entryViewStr = PartUtil.findViewsPart(documentPart).getPropertyValue(LayoutSchemaConstants.STARTUP); + for (int i = 0; i < size; i++) { + view = views.get(i); + newNode = new Node(view, i + 1); + nodeList.add(newNode); + if (entryViewStr.equals(view.getPropertyValue(LayoutSchemaConstants.ID))) { + entryNode = newNode; + } + } + + if (entryNode == null) { + return false; // Error case + } + + for (Node node : nodeList) { + List connections = getConnectionPart(node.part); + Node childNode = null; + for (Part part : connections) { + childNode = getNodeByViewName(nodeList, part.getPropertyValue(LayoutSchemaConstants.EVENT_TARGET)); + if (childNode != null) { + node.children.add(childNode); + } + } + } + + lastPosition = DesignStoryboardUtil.dfs(entryNode, null, 0, 0, visited); + for (Node node : nodeList) { + if (visited[node.id] == false) { + lastPosition = DesignStoryboardUtil.dfs(node, null, 0, lastPosition.x + 1, visited); + } + } + + for (int i = 0; i < nodeList.size(); i++) { + Node node = nodeList.get(i); + + String x = Integer.toString(node.col * (screenSize.x + MARGIN)); + String y = Integer.toString(node.row * (screenSize.y + MARGIN)); + Element element = node.part.getElement(); + element.setAttribute(LayoutSchemaConstants.PAGE_LOCATION_X, x); + element.setAttribute(LayoutSchemaConstants.PAGE_LOCATION_Y, y); + node.part.setPropertyValue(LayoutSchemaConstants.PAGE_LOCATION_X, x); + node.part.setPropertyValue(LayoutSchemaConstants.PAGE_LOCATION_Y, y); + bPropertyChanged = true; + } + + return bPropertyChanged; + + } + + public static Command getStoryboardReconstructCommand(Part documentPart, Point screenSize) { + List views = PartUtil.findViewsPart(documentPart).getChildren(); + int size = views.size(); + Part view = null; + Node entryNode = null; + Node newNode = null; + Point lastPosition; + CompoundCommand cmd = new CompoundCommand(); + + boolean[] visited = new boolean[size + 1]; + List nodeList = new ArrayList(); + + String entryViewStr = PartUtil.findViewsPart(documentPart).getPropertyValue(LayoutSchemaConstants.STARTUP); + for (int i = 0; i < size; i++) { + view = views.get(i); + newNode = new Node(view, i + 1); + nodeList.add(newNode); + if (entryViewStr.equals(view.getPropertyValue(LayoutSchemaConstants.ID))) { + entryNode = newNode; + } + } + + if (entryNode == null) { + return null; // Error case + } + + for (Node node : nodeList) { + List connections = getConnectionPart(node.part); + Node childNode = null; + for (Part part : connections) { + childNode = getNodeByViewName(nodeList, part.getPropertyValue(LayoutSchemaConstants.EVENT_TARGET)); + if (childNode != null) { + node.children.add(childNode); + } + } + } + + lastPosition = DesignStoryboardUtil.dfs(entryNode, null, 0, 0, visited); + for (Node node : nodeList) { + if (visited[node.id] == false) { + lastPosition = DesignStoryboardUtil.dfs(node, null, 0, lastPosition.x + 1, visited); + } + } + + for (int i = 0; i < nodeList.size(); i++) { + Node node = nodeList.get(i); + cmd.add(PartUtil.createSetPropertyCommand(node.part, LayoutSchemaConstants.PAGE_LOCATION_X, + Integer.toString(node.col * (screenSize.x + MARGIN)))); + cmd.add(PartUtil.createSetPropertyCommand(node.part, LayoutSchemaConstants.PAGE_LOCATION_Y, + Integer.toString(node.row * (screenSize.y + MARGIN)))); + } + + if (cmd.size() > 0) { + return cmd; + } else { + return null; + } + + } + + private static Node getNodeByViewName(List nodeList, String name) { + for (Node node : nodeList) { + if (node.part.getPropertyValue(LayoutSchemaConstants.ID).equals(name)) { + return node; + } + } + return null; + } + + public static List getConnectionPart(Part viewPart) { + Queue queue = new ArrayDeque(); + List connections = new ArrayList(); + + queue.add(viewPart); + List views = viewPart.getParent().getChildren(); + HashSet viewIdSet = new HashSet(); + + for (Part view : views) { + viewIdSet.add(view.getPropertyValue(LayoutSchemaConstants.ID)); + } + + while (!queue.isEmpty()) { + Part part = queue.poll(); + if (part.getType() == PartType.EVENT && part.hasProperty(LayoutSchemaConstants.EVENT_CONNECTION) && + viewIdSet.contains(part.getPropertyValue(LayoutSchemaConstants.EVENT_TARGET))) { + connections.add(part); + } + queue.addAll(part.getChildren()); + } + + return connections; + } + + public boolean isOldVersionStoryboard(Part viewsPart) { + if (viewsPart.getChildren().size() == 0) { + return false; + } + for (Part part : viewsPart.getChildren()) { + if (part.hasProperty(LayoutSchemaConstants.PAGE_LOCATION_X) == true + || part.hasProperty(LayoutSchemaConstants.PAGE_LOCATION_Y) == true) { + return false; + } + } + + if (sbMetaData.getViewLocationMap().keySet().size() > 0) { + return true; + } + + return false; + } + + public Command getCommandForSetOldPositions(Part viewsPart) { + for (Part part : viewsPart.getChildren()) { + if (sbMetaData.getPageLocation(part.getPropertyValue(LayoutSchemaConstants.ID)) == null) { + return null; + } + } + + CompoundCommand cmd = new CompoundCommand(); + Point pos; + + for (Part part : viewsPart.getChildren()) { + pos = sbMetaData.getPageLocation(part.getPropertyValue(LayoutSchemaConstants.ID)); + cmd.add(PartUtil.createSetPropertyCommand(part, LayoutSchemaConstants.PAGE_LOCATION_X, Integer.toString(pos.x))); + cmd.add(PartUtil.createSetPropertyCommand(part, LayoutSchemaConstants.PAGE_LOCATION_Y, Integer.toString(pos.y))); + } + + if (cmd.size() > 0) { + return cmd; + } + + return null; + } + + public boolean setSetOldPositionsProperties(Part viewsPart) { + for (Part part : viewsPart.getChildren()) { + if (sbMetaData.getPageLocation(part.getPropertyValue(LayoutSchemaConstants.ID)) == null) { + return false; + } + } + + boolean bPropertyChanged = false; + + Point pos; + + for (Part part : viewsPart.getChildren()) { + pos = sbMetaData.getPageLocation(part.getPropertyValue(LayoutSchemaConstants.ID)); + + String x = Integer.toString(pos.x); + String y = Integer.toString(pos.y); + Element element = part.getElement(); + element.setAttribute(LayoutSchemaConstants.PAGE_LOCATION_X, x); + element.setAttribute(LayoutSchemaConstants.PAGE_LOCATION_Y, y); + part.setPropertyValue(LayoutSchemaConstants.PAGE_LOCATION_X, x); + part.setPropertyValue(LayoutSchemaConstants.PAGE_LOCATION_Y, y); + + bPropertyChanged = true; + } + + return bPropertyChanged; + } + + public static boolean hasInvalidStoryboardPosition(Part viewsPart) { + for (Part part : viewsPart.getChildren()) { + if (part.hasProperty(LayoutSchemaConstants.PAGE_LOCATION_X) == false + || part.hasProperty(LayoutSchemaConstants.PAGE_LOCATION_Y) == false) { + return true; + } + } + return false; + } + + public static String getFunctionNameFromEventName(Part srcPart, String eventName) { + String functionName = ((ComponentPart) srcPart).getOwnerViewPart().getPropertyValue(LayoutSchemaConstants.ID) + + CodeGeneratorConstants.EVENT_UNDERSCORE + srcPart.getPropertyValue(LayoutSchemaConstants.ID) + + CodeGeneratorConstants.EVENT_UNDERSCORE + CodeGeneratorConstants.EVENT_PREFIX + eventName; + return functionName; + } + + public static Command getCreateConnectionCommand(Part srcPart, Part targetViewPart, String eventName, String signalName) { + String functionName = getFunctionNameFromEventName(srcPart, eventName); + EventPart eventPart = + (EventPart) PartUtil.createPartWithInitValue(srcPart.getOwnerDocumentPart(), PartType.EVENT, srcPart, LayoutSchemaConstants.EVENT); + if (eventPart != null) { + eventPart.setPropertyValue(LayoutSchemaConstants.EVENT_TARGET, targetViewPart.getPropertyValue(LayoutSchemaConstants.ID)); + eventPart.setPropertyValue(LayoutSchemaConstants.EVENT_CONNECTION, CodeGeneratorConstants.CONNECTION_WRAPPER + functionName); + eventPart.setPropertyValue(LayoutSchemaConstants.EVENT_FUNCTION_NAME, functionName); + eventPart.setPropertyValue(LayoutSchemaConstants.EVENT_SIGNAL, signalName); + Command cmd = PartUtil.createAddPartCommand(srcPart, eventPart, null); + return cmd; + } + return null; + } + + public void generateConnectionCode(Part srcPart, String eventName) { + codeGenerator.addConnectionAction(srcPart, eventName, getFunctionNameFromEventName(srcPart, eventName)); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/DesignViewer.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/DesignViewer.java new file mode 100644 index 0000000..14ebe39 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/DesignViewer.java @@ -0,0 +1,1163 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.viewer; + +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.resources.IProject; +import org.eclipse.draw2d.FigureCanvas; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.gef.dnd.TemplateTransfer; +import org.eclipse.gef.editparts.ZoomListener; +import org.eclipse.gef.editparts.ZoomManager; +import org.eclipse.gef.ui.parts.ScrollingGraphicalViewer; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DropTarget; +import org.eclipse.swt.dnd.FileTransfer; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.ui.IEditorInput; +import org.tizen.efluibuilder.core.configurator.ConfiguratorConstants; +import org.tizen.efluibuilder.gef.editparts.ContainerEditPart; +import org.tizen.efluibuilder.gef.editparts.DesignEditPart; +import org.tizen.efluibuilder.gef.editparts.DesignEditPartFactory; +import org.tizen.efluibuilder.gef.editparts.DesignRootEditPart; +import org.tizen.efluibuilder.gef.editparts.ViewEditPart; +import org.tizen.efluibuilder.gef.editparts.utility.CellManager; +import org.tizen.efluibuilder.gef.figure.ComponentFigure; +import org.tizen.efluibuilder.gef.figure.ViewFigure; +import org.tizen.efluibuilder.gef.layers.CustomLayerConstants; +import org.tizen.efluibuilder.gef.policies.containers.DesignEditorUtil; +import org.tizen.efluibuilder.gef.viewer.DesignStoryboardRouter.ConnectionModel; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.DocumentPart; +import org.tizen.efluibuilder.model.part.IPartChangedListener; +import org.tizen.efluibuilder.model.part.MScreenPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartMutation; +import org.tizen.efluibuilder.model.part.PartObserver; +import org.tizen.efluibuilder.model.part.ViewPart; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.ModelConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.mscreen.configurator.IScreenConfigurationSelectionChangedListener; +import org.tizen.efluibuilder.mscreen.configurator.MScreenQualifierManager; +import org.tizen.efluibuilder.renderer.PlaceholderPosition; +import org.tizen.efluibuilder.renderer.Position; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.efluibuilder.ui.editor.KeyHandler; +import org.tizen.efluibuilder.ui.editor.dnd.listener.DesignEditorDropTargetListener; +import org.tizen.efluibuilder.ui.editor.dnd.listener.TemplateTransferDropTargetListener2; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewer; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.TizenEditDomain; +import org.tizen.efluibuilder.ui.editor.palette.DesignEditorPaletteViewer; +import org.tizen.efluibuilder.ui.editor.toolbar.ScreenDesignToolbar; +import org.tizen.efluibuilder.ui.editor.toolbar.ViewNavigationToolbar; +import org.tizen.efluibuilder.ui.editor.toolbar.ZoomControlToolbar; +import org.tizen.efluibuilder.ui.resources.ColorResources; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; +import org.tizen.efluibuilder.utility.PlatformUtil; + +import edjResourceSyncManager.EdjResourceChangedEvent; +import edjResourceSyncManager.EdjResourceSyncManager; +import edjResourceSyncManager.IEdjResourceChangeListener; +import graphicalDataManager.ComponentGraphicalData; +import graphicalDataManager.GraphicalDataChangedEvent; +import graphicalDataManager.GraphicalDataInitializeFailedException; +import graphicalDataManager.GraphicalDataManager; +import graphicalDataManager.IGraphicalDataChangedListener; + + +public final class DesignViewer extends ScrollingGraphicalViewer + implements IGraphicalDataChangedListener, IPartChangedListener, IScreenConfigurationSelectionChangedListener, IScalableViewer, + IEdjResourceChangeListener { + + private static final int CONTENTS_PADDING = 20; + private static long firstInitializedTimeStamp = 0; + private static long initializeWaitTime = 2000; // 2S + private Listener resizeListener = null; + + private DropTarget dropTarget = null; + private DesignEditorDropTargetListener dropTargetListener = null; + private KeyHandler designerKeyHandler = null; + + private GraphicalDataManager graphicalDataManager = null; + private MScreenQualifierManager screenQualifierMgr = null; + private EditPart currentActivatedViewEditPart = null; + private boolean initRootEditPart = false; + private PartObserver observer = null; + + private List mscreenToolbarList = new ArrayList(); + private ZoomControlToolbar zoomToolBar = null; + private boolean isAutofitEnabled = false; + private boolean isInitialized = false; + + private CombineEditorPart editor = null; + private EdjResourceSyncManager edjResourceManager = null; + + private boolean enabled = true; + + private HashMap imgDescriptorMap = new HashMap(); + private HashMap revealMap = new HashMap(); + DesignStoryboardRouter router = null; + + DesignStoryboardUtil storyboardUtil = null; + + FitSingleViewState fitSingleViewState = new FitSingleViewState(); + + private static class FitSingleViewState { + public double zoom; + public Point location; + public Rectangle storyboardBound = null; + public Part targetPart = null; + + public void saveState(double zoom, Point location, Rectangle storyboardBound, Part targetPart) { + this.zoom = zoom; + this.location = location; + this.storyboardBound = storyboardBound; + this.targetPart = targetPart; + } + } + + public DesignViewer() { + setEditPartFactory(new DesignEditPartFactory()); + } + + @Override + protected void createDefaultRoot() { + setRootEditPart(new DesignRootEditPart()); + } + + @Override + public void setControl(Control control) { + super.setControl(control); + + if (control != null) { + getFigureCanvas().setHorizontalScrollBarVisibility(FigureCanvas.ALWAYS); + getFigureCanvas().setVerticalScrollBarVisibility(FigureCanvas.ALWAYS); + addEventListener(); + addDropTargetListener(); + } + } + + @Override + protected void handleDispose(DisposeEvent e) { + this.unbindFromGraphicalDataManager(); + super.handleDispose(e); + } + + @Override + public void reveal(EditPart part) { + // advux: for NPE + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=317537 + if (super.getFigureCanvas() == null) { + return; + } + if (part instanceof DesignEditPart) { + if (((DesignEditPart) part).getPosition().width > 0 && ((DesignEditPart) part).getPosition().height > 0) { + super.reveal(part); + } else { + ((DesignEditPart) part).setFlagReveal(true); + } + } + + } + + public void initContents(Part documentPart, IEditorInput editorInput, GraphicalDataManager graphicalDataManager, EdjResourceSyncManager edjResSyncMgr, + CombineEditorPart editor) { + this.observer = new PartObserver(this); + this.editor = editor; + + observer.observe(documentPart); + createMScreenQualifierManager(editorInput, documentPart); + setGraphicalDataManager(graphicalDataManager); + router = new DesignStoryboardRouter(documentPart, screenQualifierMgr, this); + storyboardUtil = new DesignStoryboardUtil(getProject()); + setContents(documentPart); + + reqNewPageGraphicData(); + // updateViewLocation(); + // setPositionToCenter(); + // updateAutoZoom(); + bindResizeListener(); + + for (ScreenDesignToolbar mscreenToolbar : this.mscreenToolbarList) { + mscreenToolbar.setMscreenManager(this.getMScreenQualifierManager()); + mscreenToolbar.refreshContents(this.getMScreenQualifierManager().getCommonConfigurationPart()); + } + + this.edjResourceManager = edjResSyncMgr; + edjResSyncMgr.addListener(this); + + if (((DocumentPart) documentPart).isValidDocument() == false) { + setEnabled(false); + } + getControl().addMouseListener(new DesignViewerMouseListener(this)); + if (checkStoryboardPosition() == true) { + router.refresh(); + router.refreshAllConnections(); + } + setFitMode(true); + + getControl().setBackground(ColorResources.DESIGN_EDITOR_BACKGROUND); + + } + + private void createMScreenQualifierManager(IEditorInput editorInput, Part documentPart) { + Part doc = documentPart; + for (Part part : doc.getChildren()) { + if (part instanceof MScreenPart) { + screenQualifierMgr = new MScreenQualifierManager((MScreenPart) part, editorInput); + screenQualifierMgr.addConfigureSelectionChangedListener(this); + } + } + } + + private void updateViewLocation() { + updateViewLocation(this.getZoomScale()); + } + + private void updateViewLocation(double scale) { + DesignRootEditPart rootEditPart = (DesignRootEditPart) getRootEditPart(); + if (rootEditPart == null) { + return; + } + Rectangle storyboardBound = getStoryboardBound(); + + Point screenSize = getMScreenQualifierManager().getScreenSize(); + storyboardBound.expand(screenSize.x * 2, screenSize.y * 2); + rootEditPart.setVirtualLayerSize(storyboardBound, (float) scale); + } + + @Override + public void setContents(Object contents) { + Part viewsPart = PartUtil.findViewsPart((Part) contents); + if (viewsPart == null) { + return; + } + super.setContents(viewsPart); + + // FIXME + if (getRootEditPart().getContents().getChildren().isEmpty() == false) { + setActiveViewEditPart((EditPart) getRootEditPart().getContents().getChildren().get(0)); + } + } + + public String getProfile() { + String currentDeviceName = screenQualifierMgr.getCurrentDevice().getName().toLowerCase(); + if (currentDeviceName.contains(ModelConstants.SHAPE_CIRCLE)) { + return ConfiguratorConstants.PROFILE_WEARABLE_CIRCLE; + } + + return ConfiguratorConstants.PROFILE_MOBILE; + } + + private Rectangle getEditorBound() { + return new Rectangle(getControl().getParent().getBounds().x, + getControl().getParent().getBounds().y, + getControl().getParent().getBounds().width, + getControl().getParent().getBounds().height); + } + + private Rectangle getEditorContentBound() { + Rectangle contentBound = new Rectangle(getControl().getParent().getBounds().x, + getControl().getParent().getBounds().y, + getControl().getParent().getBounds().width, + getControl().getParent().getBounds().height); + contentBound.width -= (CONTENTS_PADDING * 2); + contentBound.height -= (CONTENTS_PADDING * 2); + return contentBound; + } + + public void setPositionToCenter() { + Rectangle editorBound = getEditorBound(); + Rectangle storyboardBound = getScaledStoryboardBound(); + int x = 0, y = 0; + x = ((storyboardBound.x - ((editorBound.width - storyboardBound.width) / 2))); + y = ((storyboardBound.y - ((editorBound.height - storyboardBound.height) / 2))); + + ZoomManager zoomManager = getZoomManager(); + if (zoomManager != null) { + zoomManager.setViewLocation(new org.eclipse.draw2d.geometry.Point(x, y)); + } + } + + private Rectangle getScaledStoryboardBound() { + Rectangle rect = getStoryboardBound(); + rect.scale(getZoomScale()); + return rect; + } + + private Rectangle getStoryboardBound() { + Point viewSize = screenQualifierMgr.getScreenSize(); + return DesignEditorUtil.getPagesOuterBound((Part) getRootEditPart().getContents().getModel(), viewSize.x, viewSize.y); + } + + private double updateAutoZoom() { + double scale = getFitZoomScale(getStoryboardBound()); + setZoomScale(scale); + return scale; + } + + public void addTemplateTransferDropTargetListener2(TemplateTransferDropTargetListener2 listener) { + dropTargetListener.addTemplateTransferDropTargetListener2(listener); + } + + public void removeTemplateTransferDropTargetListener2(TemplateTransferDropTargetListener2 listener) { + dropTargetListener.removeTemplateTransferDropTargetListener2(listener); + } + + protected void addDropTargetListener() { + dropTarget = new DropTarget(this.getControl(), DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK | DND.DROP_DEFAULT); + Transfer[] types = { TemplateTransfer.getInstance(), FileTransfer.getInstance() }; + dropTarget.setTransfer(types); + dropTargetListener = new DesignEditorDropTargetListener(this); + dropTarget.addDropListener(dropTargetListener); + } + + private void addEventListener() { + getControl().addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if (e.keyCode == SWT.ESC) { + @SuppressWarnings("unchecked") + List eps = getSelectedEditParts(); + for (EditPart ep : eps) { + if (ep instanceof DesignEditPart) { + EditPart parent = ep.getParent(); + if (parent != null && parent.getModel() != null) { + DesignViewer.this.select(parent); + break; + } + } + } + } + } + }); + + DesignEventDelegator delegator = new DesignEventDelegator(designerKeyHandler); + getControl().addMouseMoveListener(delegator); + getControl().addMouseListener(delegator); + getControl().addKeyListener(delegator); + + } + + public KeyHandler getDesignerKeyHandler() { + return designerKeyHandler; + } + + public void setDesignerKeyHandler(KeyHandler designerKeyHandler) { + this.designerKeyHandler = designerKeyHandler; + } + + private void bindToGraphicalDataManager() { + if (this.graphicalDataManager != null) { + this.graphicalDataManager.addEventListener(this); + } + } + + private void unbindFromGraphicalDataManager() { + if (this.graphicalDataManager != null) { + this.graphicalDataManager.removeEventListener(this); + this.graphicalDataManager = null; + } + } + + public void setGraphicalDataManager(GraphicalDataManager graphicalDataManager) { + if (this.graphicalDataManager != null) { + this.unbindFromGraphicalDataManager(); + } + this.graphicalDataManager = graphicalDataManager; + this.bindToGraphicalDataManager(); + } + + private void refreshRecursive(EditPart editpart) { + editpart.refresh(); + List children = editpart.getChildren(); + for (EditPart child : children) { + refreshRecursive(child); + } + } + + private boolean setActiveViewEditPart(EditPart editpart) { + EditPart previousActivatedViewEditPart = currentActivatedViewEditPart; + if (currentActivatedViewEditPart != editpart) { + if (currentActivatedViewEditPart != null) { + // IFigure previousFigure = ((DesignEditPart) + // currentActivatedViewEditPart).getFigure(); + // previousFigure.setVisible(false); + } + currentActivatedViewEditPart = editpart; + if (previousActivatedViewEditPart != null) { + refreshRecursive(previousActivatedViewEditPart); + } + + if (currentActivatedViewEditPart != null) { + ((DesignEditPart) currentActivatedViewEditPart).getFigure().setVisible(true); + } + + updatePaletteViewer(); + return true; + } + return false; + } + + public DesignEditPart getCurrentViewEditPart() { + EditPart viewsEditPart = getRootEditPart().getContents(); + if (viewsEditPart.getChildren().size() > 0) { + return (DesignEditPart) viewsEditPart.getChildren().get(0); + } + return null; + } + + public Part getCurrentViewPart() { + DesignEditPart viewEditPart = this.getCurrentViewEditPart(); + if (viewEditPart != null) { + return (Part) viewEditPart.getModel(); + } + return null; + } + + private boolean isMyGraphicalData(GraphicalDataChangedEvent event) { + EditPart viewsEditPart = getRootEditPart().getContents(); + Part viewPart; + if (event.deviceName.equals(screenQualifierMgr.getCurrentDevice().getName()) + && event.orientation.equals(screenQualifierMgr.getCurrentOrientation()) && + event.locale.equals(screenQualifierMgr.getCurrentLocale())) { + for (Object obj : viewsEditPart.getChildren()) { + viewPart = (Part) (((EditPart) obj).getModel()); + if (event.viewId.equals(viewPart.getUniqueId())) { + return true; + } + } + } + return false; + } + + private void handleComponentImageDataChanged(GraphicalDataChangedEvent event) { + if (this.isMyGraphicalData(event) == true) { + imgDescriptorMap.put(event.viewId, event.graphicData.imageDescriptor); + // this.updatePageImageData(event.graphicData.imageDescriptor); + } + } + + private void handleComponentPositionChanged(GraphicalDataChangedEvent event) { + DesignEditPart viewPart = getViewPartById(event.viewId); + if (this.isMyGraphicalData(event) == true) { + this.updataPageComponentPositions(viewPart, event.graphicData.componentPositionMap); + } + } + + private void handlePlaceholderPositionChanged(GraphicalDataChangedEvent event) { + DesignEditPart viewPart = getViewPartById(event.viewId); + if (this.isMyGraphicalData(event) == true) { + this.updataPagePlaceholderPositions(viewPart, event.graphicData.placeholderPositionMap); + } + } + + private void reqNewPageGraphicData() { + reqNewPageGraphicData(false); + } + + private void reqNewPageGraphicData(boolean bForce) { + DesignEditPart viewEditPart = null; + Part viewPart = null; + EditPart viewsEditPart = getRootEditPart().getContents(); + for (int i = 0; i < viewsEditPart.getChildren().size(); i++) { + viewEditPart = (DesignEditPart) viewsEditPart.getChildren().get(i); + viewPart = (Part) viewEditPart.getModel(); + if (graphicalDataManager != null) { + try { + ComponentGraphicalData graphicalData = + graphicalDataManager.getGraphicalData(viewPart.getUniqueId(), screenQualifierMgr.getCurrentDevice(), + screenQualifierMgr.getCurrentOrientation(), screenQualifierMgr.getCurrentLocale(), bForce); + + if (graphicalData != null) { + if (graphicalData.imageDescriptor != null) { + imgDescriptorMap.put(viewPart.getUniqueId(), graphicalData.imageDescriptor); + // this.updatePageImageData(graphicalData.imageDescriptor); + } + + if (graphicalData.componentPositionMap != null) { + this.updataPageComponentPositions(viewEditPart, graphicalData.componentPositionMap); + } + + if (graphicalData.placeholderPositionMap != null) { + this.updataPagePlaceholderPositions(viewEditPart, graphicalData.placeholderPositionMap); + } + } + } catch (GraphicalDataInitializeFailedException e) { + if (this.editor != null && this.isInitialized == false) { + editor.closeEditor(); + } + //logger.debug(e.getMessage()); + } + } + } + } + + private void updatePageImageData(DesignEditPart viewEditPart, ImageDescriptor imageDescriptor) { + // TODO FIXME + { + if (initRootEditPart != false) { + this.initRootEditPart(); + } + } + // DesignEditPart viewEditPart = this.getCurrentViewEditPart(); + ((ViewFigure) viewEditPart.getFigure()).setImageDescriptor(imageDescriptor); + } + + private Point getPageLocation(Part viewPart) { + Point location = new Point(0, 0); + try { + location.x = Integer.parseInt(viewPart.getPropertyValue(LayoutSchemaConstants.PAGE_LOCATION_X)); + location.y = Integer.parseInt(viewPart.getPropertyValue(LayoutSchemaConstants.PAGE_LOCATION_Y)); + } catch (NumberFormatException e) { + location.x = location.y = 0; + } + return location; + } + + private void updataPageComponentPositions(DesignEditPart viewEditPart, final Map componentPositionMap) { + // final DesignEditPart viewEditPart = this.getCurrentViewEditPart(); + // TODO FIXME + // workaround code for flickering - start + // max indicator size = 52 + // abnormal indicator size = 162, 150, 103, 112 + + Part part = (Part) viewEditPart.getModel(); + List children = part.getChildren(); + if (children.size() == 1) { + Part child = children.get(0); + Position componentPosition = componentPositionMap.get(child.getUniqueId()); + if (componentPosition != null) { + if (componentPosition.y > 100) { + return; + } + } + } + // workaround code for flickering - end + + Point delta = getPageLocation(part); + + // delta.x -= 2; + // delta.y -= 150; + + if (imgDescriptorMap.containsKey(part.getUniqueId()) == true) { + this.updatePageImageData(viewEditPart, imgDescriptorMap.get(part.getUniqueId())); + } + + Display.getDefault().asyncExec(new Runnable() { + public void run() { + if (isInitialized == false) { + isInitialized = true; + updateAutoZoom(); + updateViewLocation(); + setPositionToCenter(); + } + if (null != viewEditPart) { + updateComponentPosition(delta, viewEditPart, componentPositionMap, true); + setVisibleOutlineLayer(true); + } + } + }); + + } + + private void updateComponentPosition(Point delta, DesignEditPart editPart, Map componentPositionMap, boolean isFireEvent) { + // FIXME : workaround code for connection's position when editor open + router.setViewPositionValidate(true); + + if (editPart != null) { + Part part = (Part) editPart.getModel(); + if (part.getUniqueId() != null && !part.getUniqueId().isEmpty()) { + Position componentPosition = componentPositionMap.get(part.getUniqueId()); + if (componentPosition != null) { + componentPosition = new Position(componentPosition.x + delta.x, componentPosition.y + delta.y, + componentPosition.width, componentPosition.height); + if (editPart instanceof ViewEditPart) { + componentPosition = DesignEditorUtil.getPagePositionFromComponentPosition(componentPosition); + } + if (editPart.setPosition(componentPosition) == true) { + // editPart.refresh(); + } + editPart.refresh(); + if (editPart.getFlagReveal() == true) { + reveal(editPart); + editPart.setFlagReveal(false); + } + } + } + + List children = editPart.getChildren(); + for (int i = 0; i < children.size(); i++) { + if (children.get(i) instanceof DesignEditPart) { + DesignEditPart childEditPart = (DesignEditPart) children.get(i); + updateComponentPosition(delta, childEditPart, componentPositionMap, isFireEvent); + } + } + } + } + + private void updataPagePlaceholderPositions(DesignEditPart viewEditPart, Map> placeholderPositionMap) { + if (placeholderPositionMap == null) { + return; + } + DesignRootEditPart rootEditPart = (DesignRootEditPart) getRootEditPart(); + if (rootEditPart != null) { + Point delta = getPageLocation((Part) viewEditPart.getModel()); + updataPagePlaceholderPosition(delta, viewEditPart, placeholderPositionMap, true); + } + } + + @SuppressWarnings("unchecked") + private void updataPagePlaceholderPosition(Point delta, DesignEditPart editPart, + Map> placeholderPositions, boolean isFireEvent) { + if (editPart != null) { + if (editPart.getId() != null && !editPart.getId().isEmpty()) { + List phPos = placeholderPositions.get(editPart.getId()); + if (null != phPos) { + if (editPart instanceof ContainerEditPart) { + ContainerEditPart containerEditPart = (ContainerEditPart) editPart; + CellManager cellManager = containerEditPart.getCellManager(); + if (null != cellManager) { + cellManager.clean(); + for (PlaceholderPosition pos : phPos) { + cellManager.addCell(pos.wid, pos.x + delta.x, pos.y + delta.y, pos.width, pos.height); + } + // containerEditPart.refreshCells(); + editPart.refresh(); + } + } + } + } + + List myChildren = editPart.getChildren(); + if (null != myChildren) { + for (DesignEditPart ePart : myChildren) { + updataPagePlaceholderPosition(delta, ePart, placeholderPositions, isFireEvent); + } + + } + } + } + + @Override + public void componentImageDataChanged(GraphicalDataChangedEvent event) { + this.handleComponentImageDataChanged(event); + } + + @Override + public void componentPositionDataChanged(GraphicalDataChangedEvent event) { + this.handleComponentPositionChanged(event); + + } + + @Override + public void placeholderPositionDataChanged(GraphicalDataChangedEvent event) { + this.handlePlaceholderPositionChanged(event); + + } + + private void initRootEditPart() { + // TODO FIXME + DesignRootEditPart rootEditPart = (DesignRootEditPart) getRootEditPart(); + if (rootEditPart == null) { + return; + } + rootEditPart.refresh(); + this.initRootEditPart = true; + } + + public void setEnabled(boolean enabled) { + if (this.enabled == enabled) { + return; + } + this.enabled = enabled; + if (!enabled) { + this.deselectAll(); + } + getLayerManager().getLayer(CustomLayerConstants.BLOCK_LAYER).setVisible(!enabled); + DesignEditorPaletteViewer paletteViewer = (DesignEditorPaletteViewer) ((TizenEditDomain) getEditDomain()).getTizenPaletteViewer(); + paletteViewer.setEnabled(enabled); + int scrollbarVisibleMode = enabled ? FigureCanvas.AUTOMATIC : FigureCanvas.NEVER; + getFigureCanvas().setScrollBarVisibility(scrollbarVisibleMode); + getControl().setEnabled(enabled); + editor.setEnableToolBar(enabled); + } + + @Override + public void partsChanged(List mutations, PartObserver observer, String sender) { + if (sender.equals(PartObserver.MESSAGE_VALID_XML)) { + setEnabled(true); + } else if (sender.equals(PartObserver.MESSAGE_INVALID_XML)) { + setEnabled(false); + return; + } + + // List partListToRefresh = new ArrayList(); + Map partMapToRefresh = new HashMap(); + // FIXME: It is not used. + // Map partMapToReorder = new HashMap(); + List removedScreenParts = new ArrayList(); + + boolean isViewChanged = false; + boolean isImageSrcChanged = false; + boolean isConfigChanged = false; + boolean isViewPositionChanged = false; + for (PartMutation mutation : mutations) { + String mutationType = mutation.getType(); + if (mutationType.equals(PartMutation.PARTS_ADDED)) { + for (Part part : mutation.getAddedParts()) { + if (part instanceof ViewPart) { + isViewChanged = true; + break; + } + } + } else if (mutationType.equals(PartMutation.PARTS_REMOVED)) { + for (Part part : mutation.getRemovedParts()) { + if (part instanceof ViewPart) { + isViewChanged = true; + // if (part == this.getCurrentViewPart()) { + break; + // } + } + } + } else if (mutationType.equals(PartMutation.CONFIGURES_REMOVED)) { + isConfigChanged = true; + for (Part part : mutation.getRemovedParts()) { + removedScreenParts.add(part); + } + } else if (PartMutation.CONFIGURES_ADDED.equals(mutationType)) { + isConfigChanged = true; + } else if (PartMutation.CONFIGURE_PROPERTY_CHANGED.equals(mutationType)) { + isConfigChanged = true; + } else if (mutationType.equals(PartMutation.PROPERTY_CHANGED)) { + if (LayoutSchemaConstants.IMAGE.equals(mutation.getTargetPart().getDescriptorId()) + && LayoutSchemaConstants.SRC.equals(mutation.getPropertyName())) { + isImageSrcChanged = true; + } else if (LayoutSchemaConstants.PAGE_LOCATION_X.equals(mutation.getPropertyName()) || + LayoutSchemaConstants.PAGE_LOCATION_Y.equals(mutation.getPropertyName())) { + isViewPositionChanged = true; + } + // partMapToRefresh.put(mutation.getTargetPart(), ""); //to slow when view moved + } + + if (mutationType.equals(PartMutation.PARTS_ADDED) || mutationType.equals(PartMutation.PARTS_REMOVED)) { + if (mutation.getTargetPart() instanceof ComponentPart) { + partMapToRefresh.put(mutation.getTargetPart(), ""); + } + } + + if (mutationType.equals(PartMutation.PARTS_ORDER_CHANGED)) { + if (mutation.getTargetPart() instanceof ComponentPart) + partMapToRefresh.put(mutation.getTargetPart(), ""); + } + + } + + this.router.refresh(); + + if (isViewChanged) { + getContents().refresh(); + } + // FIXME: After Storyboard is merged with Design, this routine does not need. + if (this.currentActivatedViewEditPart == null) { + setActiveViewEditPart((EditPart) getRootEditPart().getContents().getChildren().get(0)); + } + + for (Part child : partMapToRefresh.keySet()) { + DesignEditPart editPart = (DesignEditPart) getEditPartRegistry().get(child.getUniqueId()); + if (editPart != null) { + editPart.refresh(); + } + } + + // FIXME: It is not used + // for (Part child : partMapToReorder.keySet()) { + // DesignEditPart editPart = (DesignEditPart) + // getEditPartRegistry().get(child.getUniqueId()); + // if (editPart != null) { + // editPart.refreshChildren2(); + // editPart.reorderChildren(); + // } + // } + + // if (isCurrentViewRemoved) { + // // FIXME + // Part viewPart = ((Part) + // getRootEditPart().getContents().getModel()).getComponentChildren().get(0); + // selectView((ViewPart) viewPart); + // } + + // If screen configuration is changed from text editor + if (isConfigChanged) { + refreshMScreenToolBar(); + } + + MScreenQualifierManager mScreenManager = getMScreenQualifierManager(); + if (removedScreenParts.contains(mScreenManager.getCurrentConfigurePart()) == true) { + mScreenManager.setCurrentConfigurePart(mScreenManager.getCommonConfigurationPart()); + } + reqNewPageGraphicData(); + if (isImageSrcChanged && PlatformUtil.getOS().equals(PlatformUtil.OS_WIN32)) { // workaround + // code - + // #TSCP 450 + reqNewPageGraphicData(true); + } + + for (ConnectionModel cm : this.router.connections.values()) { + EditPart ep = null; + ep = (EditPart) this.getEditPartRegistry().get(cm); + if (ep != null) { + ep.refresh(); + } + } + updatePaletteViewer(); + if (isViewChanged || isViewPositionChanged) { + updateViewLocation(); + // router.refreshAllConnections(); + } + router.refreshAllConnections(); + + } + + public MScreenQualifierManager getMScreenQualifierManager() { + return screenQualifierMgr; + } + + public void addMScreenToolbar(ScreenDesignToolbar toolbar) { + if (!this.mscreenToolbarList.contains(toolbar)) { + this.mscreenToolbarList.add(toolbar); + } + } + + public void setViewNavigationToolbar(ViewNavigationToolbar toolbar) { + } + + public void selectView(ViewPart viewPart) { + EditPart viewEditPart = (EditPart) this.getEditPartRegistry().get(viewPart.getUniqueId()); + if (viewEditPart != null) { + this.select(viewEditPart); + } + } + + public boolean isAutoFit() { + if (this.zoomToolBar != null) { + return this.zoomToolBar.isFitMode(); + } + return false; + } + + @Override + public void configurationSelected(MScreenQualifierManager mscreenManager) { + this.reqNewPageGraphicData(); + this.setFitMode(true); + this.getStoryBoardRouter().refreshAllConnections(); + } + + @Override + public double getZoomScale() { + return ((DesignRootEditPart) getRootEditPart()).getZoomManager().getZoom(); + } + + @Override + public void setZoomScale(double scale) { + if (((DesignRootEditPart) getRootEditPart()).getZoomManager().getZoom() != scale) { + ((DesignRootEditPart) getRootEditPart()).getZoomManager().setZoom(scale); + // this.updateViewLocation(scale); + // this.setPositionToCenter(); + // procUpdateScrollbar(); + } + } + + @Override + public void setZoomControlToolbar(ZoomControlToolbar toolbar) { + zoomToolBar = toolbar; + toolbar.setFitMode(true); + } + + @Override + public void addZoomScaleChangedListener(ZoomListener listener) { + ((DesignRootEditPart) getRootEditPart()).getZoomManager().addZoomListener(listener); + } + + @Override + public void removeZoomScaleChangedListener(ZoomListener listener) { + ((DesignRootEditPart) getRootEditPart()).getZoomManager().removeZoomListener(listener); + } + + @Override + public void setFitMode(boolean isAutoFit) { + this.isAutofitEnabled = isAutoFit; + if (isAutoFit) { + this.updateViewLocation(); + this.updateAutoZoom(); + setPositionToCenter(); + } + } + + @Override + public boolean getFitMode() { + return isAutofitEnabled; + } + + public void refreshMScreenToolBar() { + mscreenToolbarList.get(0).refreshContents(this.getMScreenQualifierManager().getCurrentConfigurePart()); + } + + private void updatePaletteViewer() { + PaletteViewer paletteViewer = ((TizenEditDomain) getEditDomain()).getTizenPaletteViewer(); + paletteViewer.setCategoryState(false); + // if (currentActivatedViewEditPart != null && paletteViewer != null) { + // Part viewPart = (Part) currentActivatedViewEditPart.getModel(); + // if (viewPart.getChildren().size() == 0) { + // paletteViewer.setCategoryState(true); + // // hide components + // } else { + // paletteViewer.setCategoryState(false); + // // show components + // } + // } + } + + @Override + public void edjResourceChanged(EdjResourceChangedEvent event) { + if ((event.type == EdjResourceChangedEvent.TYPE_CHANGED || event.type == EdjResourceChangedEvent.TYPE_REMOVED) + && currentActivatedViewEditPart != null) { + Part viewPart = (Part) currentActivatedViewEditPart.getModel(); + Part part = null; + ArrayDeque queue = new ArrayDeque(); + queue.add(viewPart); + String realPath = null; + boolean bNeedRefresh = false; + while (!queue.isEmpty()) { + part = queue.removeFirst(); + if (LayoutSchemaConstants.LAYOUT.equals(part.getDescriptorId())) { + realPath = this.graphicalDataManager.getRenderDataGenerator().getRealPathFromResourceProperty(part, LayoutSchemaConstants.SRC, + screenQualifierMgr.getCurrentDevice(), + screenQualifierMgr.getCurrentLocale()); + if (realPath.equals(event.path)) { + bNeedRefresh = true; + break; + } + } + queue.addAll(part.getComponentChildren()); + + } + if (bNeedRefresh == true) { + reqNewPageGraphicData(true); + } + } + + } + + public EdjResourceSyncManager getEdjResourceSyncManager() { + return this.edjResourceManager; + } + + public void bindResizeListener() { + if (resizeListener == null) { + resizeListener = new Listener() { + + @Override + public void handleEvent(Event ev) { + if (firstInitializedTimeStamp == 0) { + firstInitializedTimeStamp = System.currentTimeMillis(); + } else if (System.currentTimeMillis() - firstInitializedTimeStamp > initializeWaitTime) { + unbindResizeListener(); + } else { + updateAutoZoom(); + setPositionToCenter(); + } + } + }; + this.getControl().addListener(SWT.RESIZE, resizeListener); + } + } + + public void unbindResizeListener() { + if (resizeListener != null) { + this.getControl().removeListener(SWT.RESIZE, resizeListener); + resizeListener = null; + } + } + + public GraphicalDataManager getGraphicalDataMgr() { + return this.graphicalDataManager; + } + + public IProject getProject() { + return this.editor.getProject(); + } + + public void showBindingInfo(boolean isBinded) { + DesignEditPart currentViewEditPart = getCurrentViewEditPart(); + if (currentViewEditPart != null) { + currentViewEditPart.setBinded(isBinded); + showBindingInfo(currentViewEditPart.isBinded(), currentViewEditPart); + } + } + + private void showBindingInfo(boolean isBinded, DesignEditPart editPart) { + if (null == editPart) { + return; + } + Part part = (Part) editPart.getModel(); + IFigure f = editPart.getFigure(); + + if (f instanceof ComponentFigure) { + ComponentFigure figure = (ComponentFigure) f; + String dataBind = part.getPropertyValue(BuilderConstants.ATTRIBUTE_DATA_BIND); + if (null != dataBind && !dataBind.isEmpty() && isBinded) { + figure.setBinded(true); + } else { + figure.setBinded(false); + } + figure.repaint(); + } + + List children = editPart.getChildren(); + for (Object child : children) { + showBindingInfo(isBinded, (DesignEditPart) child); + } + } + + DesignEditPart getViewPartById(String id) { + Part part = (Part) getRootEditPart().getContents().getModel(); + for (Part child : part.getChildren()) { + if (child.getUniqueId().equals(id)) { + return (DesignEditPart) this.getEditPartRegistry().get(child.getUniqueId()); + } + } + return null; + } + + public DesignStoryboardRouter getStoryBoardRouter() { + return router; + } + + public void setVisibleOutlineLayer(boolean visible) { + this.getLayerManager().getLayer(CustomLayerConstants.OUTLINE_LAYER).setVisible(visible); + } + + public void reconstructStoryboard() { + Command cmd = + DesignStoryboardUtil.getStoryboardReconstructCommand((Part) (getContents().getModel()), + this.getMScreenQualifierManager().getScreenSize()); + if (cmd != null) { + CommandStack cmdStack = getEditDomain().getCommandStack(); + cmdStack.execute(cmd); + setFitMode(true); + } + } + + private boolean checkStoryboardPosition() { + boolean bPropertyChanged = false; + Part viewsPart = (Part) (getContents().getModel()); + if (DesignStoryboardUtil.hasInvalidStoryboardPosition(viewsPart) == true) { + bPropertyChanged = storyboardUtil.setSetOldPositionsProperties(viewsPart); + } + + if (DesignStoryboardUtil.hasInvalidStoryboardPosition(viewsPart) == true) { + DesignStoryboardUtil.setStoryboardReconstructProperties(viewsPart, + this.getMScreenQualifierManager().getScreenSize()); + bPropertyChanged = true; + } + return bPropertyChanged; + } + + private double getFitZoomScale(Rectangle rect) { + double scale; + Rectangle editorContentBound = getEditorContentBound(); + scale = Math.min(editorContentBound.width / (double) rect.width, editorContentBound.height / (double) rect.height); + return scale; + } + + public ZoomManager getZoomManager() { + DesignRootEditPart rootEditPart = (DesignRootEditPart) getRootEditPart(); + if (rootEditPart != null) { + return rootEditPart.getZoomManager(); + } + return null; + } + + public void fitToSingleView(Part viewPart) { + Point viewSize = screenQualifierMgr.getScreenSize(); + Rectangle editorBound = getEditorBound(); + Rectangle viewBound = DesignEditorUtil.getPageBound(viewPart, viewSize.x, viewSize.y); + double zoom = getFitZoomScale(viewBound); + + Point viewLocation = new Point(); + viewBound.scale(zoom); + viewLocation.x = viewBound.x - ((editorBound.width - viewBound.width) / 2); + viewLocation.y = viewBound.y - ((editorBound.height - viewBound.height) / 2); + + DesignRootEditPart rootEditPart = (DesignRootEditPart) getRootEditPart(); + ZoomManager zoomManager = getZoomManager(); + if (rootEditPart == null || zoomManager == null) { + return; + } + + double currentZoom = zoomManager.getZoom(); + Point currentLocation = zoomManager.getViewport().getViewLocation(); + Rectangle storyboardBound = getStoryboardBound(); + + if (currentZoom == zoom && viewLocation.equals(currentLocation) && storyboardBound.equals(fitSingleViewState.storyboardBound) + && viewPart == fitSingleViewState.targetPart) { + zoomManager.setZoom(this.fitSingleViewState.zoom); + zoomManager.setViewLocation(this.fitSingleViewState.location); + } else { + fitSingleViewState.saveState(currentZoom, currentLocation, storyboardBound, viewPart); + zoomManager.setZoom(zoom); + zoomManager.setViewLocation(viewLocation); + } + } + + public IFigure findFigureAt(Point pt) { + return getLightweightSystem().getRootFigure().findFigureAt(pt.x, pt.y); + } + + public DesignStoryboardUtil getDesignStoryboardUtil() { + return storyboardUtil; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/DesignViewerMouseListener.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/DesignViewerMouseListener.java new file mode 100644 index 0000000..99f0210 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/DesignViewerMouseListener.java @@ -0,0 +1,104 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.viewer; + +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.gef.EditPart; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.tizen.efluibuilder.gef.editparts.DesignEditPart; +import org.tizen.efluibuilder.gef.tools.DesignEditDomain; +import org.tizen.efluibuilder.model.descriptors.EventDescriptor; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; + + +public class DesignViewerMouseListener implements MouseListener { + DesignViewer viewer = null; + EditPart srcEditPart = null; + + public DesignViewerMouseListener(DesignViewer viewer) { + this.viewer = viewer; + } + + @Override + public void mouseDoubleClick(MouseEvent arg0) { + // TODO Auto-generated method stub + } + + @Override + public void mouseDown(MouseEvent event) { + Point pos = new Point(event.x, event.y); + srcEditPart = viewer.findObjectAt(pos); + } + + private void createContextMenu(Part sourcePart, Part targetViewPart, org.eclipse.swt.graphics.Point creationPoint) { + Menu contextMenu = new Menu(viewer.getControl()); + ComponentDescriptor componentDescriptor = sourcePart.getOwnerDocumentPart().getComponentDescriptor(); + for (EventDescriptor descriptor : componentDescriptor.getWidgetDescriptor(sourcePart.getDescriptorId()).getEventDescriptors()) { + contextMenu.setVisible(false); + MenuItem menuItem = new MenuItem(contextMenu, SWT.POP_UP); + menuItem.setText(descriptor.getEventDisplayName()); + for (Part sourcePartEvent : ((ComponentPart) sourcePart).getEventParts()) { + if ((descriptor.getEventDisplayName()).equals(sourcePartEvent.getPropertyValue(LayoutSchemaConstants.EVENT_SIGNAL))) { + menuItem.setEnabled(false); + break; + } + } + menuItem.addSelectionListener(new ConnectionCreateListener(viewer, sourcePart, targetViewPart)); + } + if (creationPoint != null) { + contextMenu.setLocation(creationPoint); + contextMenu.setVisible(true); + } + } + + @Override + public void mouseUp(MouseEvent event) { + DesignEditDomain editdomain = (DesignEditDomain) viewer.getEditDomain(); + if (editdomain != null && editdomain.isConnectionEnabled()) { + editdomain.clearConnectionEnabled(); + } else { + return; + } + + Point pos = new Point(event.x, event.y); + EditPart targetEditPart = viewer.findObjectAt(pos); + if (srcEditPart instanceof DesignEditPart && targetEditPart instanceof DesignEditPart) { + Part srcViewPart = PartUtil.findViewPart((Part) srcEditPart.getModel()); + Part targetViewPart = PartUtil.findViewPart((Part) targetEditPart.getModel()); + if (srcViewPart != null && targetViewPart != null && srcViewPart != targetViewPart) { + createContextMenu((Part) srcEditPart.getModel(), targetViewPart, viewer.getControl().toDisplay(event.x, event.y)); + } + } + + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/IScalableViewer.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/IScalableViewer.java new file mode 100644 index 0000000..5b94483 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/IScalableViewer.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.gef.viewer; + +import org.eclipse.gef.editparts.ZoomListener; +import org.tizen.efluibuilder.ui.editor.toolbar.ZoomControlToolbar; + + +public interface IScalableViewer { + public double getZoomScale(); + + public boolean getFitMode(); + + public void setZoomScale(double scale); + + public void setFitMode(boolean isAutoFit); + + public void addZoomScaleChangedListener(ZoomListener listener); + + public void removeZoomScaleChangedListener(ZoomListener listener); + + public void setZoomControlToolbar(ZoomControlToolbar toolbar); +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/SBMetaData.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/SBMetaData.java new file mode 100644 index 0000000..066fac4 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/SBMetaData.java @@ -0,0 +1,159 @@ +/* +F * UI Builder - StoryBoard + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + + +package org.tizen.efluibuilder.gef.viewer; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.bind.JAXBException; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.draw2d.geometry.Point; +import org.tizen.common.util.Assert; +import org.tizen.efluibuilder.model.app.loader.PropertiesLoader; +import org.tizen.efluibuilder.model.app.loader.jaxb.Properties; +import org.tizen.efluibuilder.model.app.loader.jaxb.ViewModel; +import org.tizen.efluibuilder.model.util.ModelConstants; +import org.tizen.efluibuilder.ui.views.properties.PropertiesConstant; + + +public class SBMetaData { + private Properties properties; + private PropertiesLoader propLoader = new PropertiesLoader(); + private HashMap viewLocationMap = new HashMap(); + private String path; + private IFile file; + + public SBMetaData(IProject project) { + this.file = project.getFile(ModelConstants.PROJECT_FILE); + try { + properties = propLoader.load(file); + this.path = file.getLocation().toString(); + createViewLocationMap(); + } catch (JAXBException e) { + throw new RuntimeException(e.getMessage() + "\nLoad failed. (project file)"); + } + } + + private void createViewLocationMap() { + List viewModelList = properties.getViews(); + Assert.notNull(viewModelList); + for (ViewModel viewModel : viewModelList) { + viewLocationMap.put(viewModel.getId(), new Point(viewModel.getLocationX(), viewModel.getLocationY())); + } + } + + public Map getViewLocationMap() { + return viewLocationMap; + } + + public void addViewLocation(String viewId, Point location) { + viewLocationMap.put(viewId, location); + } + + public void deleteViewLocation(String viewId) { + viewLocationMap.remove(viewId); + } + + public void updateLocationX(String viewId, int locationX) { + Point location = viewLocationMap.get(viewId); + if (location != null) { + location.x = locationX; + } + } + + public void updateLocationY(String viewId, int locationY) { + Point location = viewLocationMap.get(viewId); + if (location != null) { + location.y = locationY; + } + } + + public Point getPageLocation(String viewId) { + return viewLocationMap.get(viewId); + } + + public String getLocationProperty(String viewId, String propertyName) { + Point viewLoc = viewLocationMap.get(viewId); + if (viewLoc == null) { + return null; + } + if (propertyName.equals(PropertiesConstant.PROPERTY_LOCATION_X)) { + return String.valueOf(viewLoc.x); + } else if (propertyName.equals(PropertiesConstant.PROPERTY_LOCATION_Y)) { + return String.valueOf(viewLoc.y); + } + return null; + } + + public void saveMetaData() { + try { + List viewModelList = createViewModelList(); + properties.setViews(viewModelList); + propLoader.data = properties; + propLoader.saveExisting(path); + + // FIXED: File synchronization in project explorer is broken. + this.file.refreshLocal(IFile.DEPTH_ZERO, null); + } catch (JAXBException e) { + throw new RuntimeException(e.getMessage() + "\nLoad failed. (project file)"); + } catch (CoreException e) { + // TODO: Need to add an exception process + e.printStackTrace(); + } + } + + private ViewModel createViewModel(String id, Point location) { + ViewModel model = new ViewModel(); + model.setId(id); + model.setLocationX(location.x); + model.setLocationY(location.y); + return model; + } + + private List createViewModelList() { + List viewModelList = new ArrayList(); + for (String key : viewLocationMap.keySet()) { + viewModelList.add(createViewModel(key, viewLocationMap.get(key))); + } + return viewModelList; + } + + public void updateViewLocationMap(String oldViewId, String newViewId) { + List viewModelList = properties.getViews(); + Assert.notNull(viewModelList); + for (ViewModel viewModel : viewModelList) { + if (viewModel.getId().equals(oldViewId)) { + viewModel.setId(newViewId); + viewLocationMap.put(newViewId, new Point(viewModel.getLocationX(), viewModel.getLocationY())); + viewLocationMap.remove(oldViewId); + break; + } + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/modules/RendererManager.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/modules/RendererManager.java new file mode 100644 index 0000000..48b20de --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/gef/viewer/modules/RendererManager.java @@ -0,0 +1,247 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.gef.viewer.modules; + +public class RendererManager { + + public RendererManager() { + } + + // // Renderer + // private IRenderer renderer = null; + // + // // Parent's handle (need to move) for updateModel() + // private IViewManager viewManager = null; + // + // private DesignerRootEditPart rootEditPart = null; + // private DesignerEditPart pageEditPart = null; + // + // private DesignerRootEditPart getRootEditpart() { + // return rootEditPart; + // } + // + // public void setRootEditpart(DesignerRootEditPart rootEditPart) { + // EditPart doc = rootEditPart.getContents(); + // @SuppressWarnings("unchecked") + // List pageEditParts = doc.getChildren(); + // if (pageEditParts.size() > 0) { + // this.pageEditPart = (DesignerEditPart) pageEditParts.get(0); + // } + // + // this.rootEditPart = rootEditPart; + // } + // + // private DesignerEditPart getPageEditpart() { + // return pageEditPart; + // } + // + // public void bindHandle(IViewManager viewManager) { + // this.viewManager = viewManager; + // } + // + // public void destroy() { + // if (null != renderer) { + // renderer.destroy(); + // } + // } + // + // public void create(int width, int height, String projectPath, String profile) { + // RendererFactory factory = RendererFactory.getDefault(); + // renderer = factory.create(viewManager.getVersion(), profile, projectPath); + // renderer.setName("Editor"); + // renderer.addRendererListener(this); + // renderer.create(width, height); + // } + // + // public void updatePage() { + // // get selection + // String id = viewManager.getSelection(); + // RenderDataGenerator generator = new RenderDataGenerator(viewManager); + // String renderData = generator.generate(id); + // renderer.render(IRenderer.RENDER_TYPE_DESIGN, renderData); + // } + // + // public IRenderer getHandle() { + // return renderer; + // } + // + // @Override + // public void replyRender(RenderEvent event) { + // if (!renderer.equals(event.renderer)) { + // return; + // } + // updatePageImage(event); + // } + // + // @Override + // public void reply(IArguments message) { + // handleReply(message); + // } + // + // public Image getPageImage() { + // DesignerEditPart pageEditPart = getPageEditpart(); + // ViewFigure figure = (ViewFigure) pageEditPart.getFigure(); + // if (null != figure) { + // if (figure.getImageDescriptor() != null) { + // return figure.getImageDescriptor().createImage(); + // } + // } + // + // return null; + // } + // + // private void updatePageImage(RenderEvent event) { + // DesignerEditPart pageEditPart = getPageEditpart(); + // if (pageEditPart == null) { + // return; + // } + // ViewFigure figure = (ViewFigure) pageEditPart.getFigure(); + // figure.setImageDescriptor(event.imageDescriptor); + // } + // + // private void handleReply(final IArguments message) { + // Display.getDefault().syncExec(new Runnable() { + // @Override + // public void run() { + // if (message.getId().equals(RendererConstants.EVENT_CREATE)) { + // onCreateCompleted(); + // } else if (message.getId().equals(RendererConstants.EVENT_GET_ALL_WIDGET_POSITIONS)) { + // onGetAllWidgetPosition(message); + // } else if (message.getId().equals(RendererConstants.EVENT_GET_PLACEHOLDER_POSITIONS)) { + // onGetAllPlaceHolderPosition(message); + // } + // } + // }); + // } + // + // private void onCreateCompleted() { + // DesignerRootEditPart rootEditPart = getRootEditpart(); + // if (rootEditPart == null) { + // return; + // } + // rootEditPart.refresh(); + // rootEditPart.updateScrollBar(); + // } + // + // private void onGetAllWidgetPosition(IArguments message) { + // @SuppressWarnings("unchecked") + // Map widgetPositions = (Map) + // message.getArg(0); + // if (widgetPositions == null) { + // return; + // } + // + // //viewsEditPart + // DesignerEditPart pageEditPart = getPageEditpart(); + // if (null == pageEditPart) { + // return; + // } + // + // List viewEditPartList = pageEditPart.getChildren(); + // for(int i = 0; i < viewEditPartList.size(); i++) { + // DesignerEditPart viewEditPart = (DesignerEditPart)viewEditPartList.get(i); + // ViewFigure figure = (ViewFigure) viewEditPart.getFigure(); + // figure.setVisible(false); // To refresh a ViewFigure (false -> true) + // updateOneWidgetPosition(viewEditPart, widgetPositions, true); + // figure.setVisible(true); + // } + // } + // + // protected void onGetAllPlaceHolderPosition(IArguments message) { + // @SuppressWarnings("unchecked") + // Map> placeholderPositions = (Map>) message.getArg(0); + // if (placeholderPositions == null) { + // return; + // } + // + // DesignerRootEditPart rootEditPart = getRootEditpart(); + // if (rootEditPart != null) { + // updateOnePlaceholderPosition(rootEditPart, null, placeholderPositions, true); + // } + // } + // + // private void updateOneWidgetPosition(DesignerEditPart editPart, Map widgetPositions, boolean isFireEvent) { + // if (editPart != null) { + // Part part = (Part)editPart.getModel(); + // if (part.getUniqueId() != null && !part.getUniqueId().isEmpty()) { + // ComponentPosition pos = widgetPositions.get(part.getUniqueId()); + // if (pos != null) { + // editPart.setPosition(pos); + // } + // } + // + // List children = editPart.getChildren(); + // for (int i = 0; i < children.size(); i++) { + // DesignerEditPart childEditPart = (DesignerEditPart) children.get(i); + // updateOneWidgetPosition(childEditPart, widgetPositions, isFireEvent); + // } + // } + // } + // + // @SuppressWarnings("unchecked") + // private void updateOnePlaceholderPosition(DesignerRootEditPart rootEditPart, DesignerEditPart + // editPart, + // Map> placeholderPositions, boolean isFireEvent) { + // if (editPart != null) { + // + // if (editPart.getId() != null && !editPart.getId().isEmpty()) { + // + // List phPos = placeholderPositions.get(editPart.getId()); + // if (null != phPos) { + // + // if (editPart instanceof ContainerEditPart) { + // ContainerEditPart containerEditPart = (ContainerEditPart) editPart; + // CellManager cellManager = containerEditPart.getCellManager(); + // + // if (null != cellManager) { + // cellManager.clean(); + // + // for (PlaceholderPosition pos : phPos) { + // cellManager.addCell(pos.wid, pos.x, pos.y, pos.width, pos.height); + // } + // + // containerEditPart.refreshCells(); + // } + // } + // } + // } + // + // List myChildren = editPart.getChildren(); + // if (null != myChildren) { + // for (DesignerEditPart ePart : myChildren) { + // updateOnePlaceholderPosition(rootEditPart, ePart, placeholderPositions, isFireEvent); + // } + // } + // } else { + // List rootChildren = rootEditPart.getChildren(); + // if (null != rootChildren) { + // for (DesignerEditPart ePart : rootChildren) { + // updateOnePlaceholderPosition(rootEditPart, ePart, placeholderPositions, isFireEvent); + // } + // } + // } + // } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/app/AppManager.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/app/AppManager.java new file mode 100644 index 0000000..e65580f --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/app/AppManager.java @@ -0,0 +1,166 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.app; + +import javax.xml.bind.JAXBException; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectNature; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.part.FileEditorInput; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.common.core.application.TizenProjectDescription; +import org.tizen.common.util.ProjectUtil; +import org.tizen.efluibuilder.core.configuration.device.DeviceManager; +import org.tizen.efluibuilder.core.configurator.Configurator; +import org.tizen.efluibuilder.core.configurator.ConfiguratorConstants; +import org.tizen.efluibuilder.model.app.loader.PropertiesLoader; +import org.tizen.efluibuilder.model.app.loader.jaxb.Properties; +import org.tizen.efluibuilder.model.util.ModelConstants; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; + + +public final class AppManager { + protected static Logger logger = LoggerFactory.getLogger(AppManager.class); + private Properties properties = null; + private String platform = null; + private String profile = null; + private String version = null; + private DeviceManager deviceManager = null; + private String schemaLocation = null; + private IProject project = null; + + public static AppManager getAppManager(IProject project) { + if (!project.isOpen()) { + throw new RuntimeException("Project is not opened"); + } + IProjectNature projectNature = null; + try { + projectNature = project.getNature("org.tizen.efluibuilder.nature"); + } catch (CoreException e) { + throw new RuntimeException(e.getMessage()); + } + + if (projectNature == null) { + throw new RuntimeException("Nature not found"); + } + + // is NUIB Project + if (!projectNature.getClass().getSimpleName().equals("NUIBNature")) { + throw new RuntimeException("NUIB Nature not found"); + } + + AppManager appManager = new AppManager(project); + return appManager; + } + + private AppManager(IProject project) { + TizenProjectDescription tizenProjectDescription = ProjectUtil.getTizenProjectDescription(project); + this.project = project; + // get .uproject file + IFile file = project.getFile(ModelConstants.PROJECT_FILE); + PropertiesLoader loader = new PropertiesLoader(); + try { + properties = loader.load(file); + } catch (JAXBException e) { + throw new RuntimeException(e.getMessage() + "\nLoad failed. (project file)"); + } + + String shape = properties.getShape(); + if (shape.equals(ModelConstants.SHAPE_SQUARE)) { + this.platform = tizenProjectDescription.getPlatformName(); + this.profile = tizenProjectDescription.getProfileName(); + } else if (shape.equals(ModelConstants.SHAPE_CIRCLE)) { + this.profile = ConfiguratorConstants.PROFILE_WEARABLE_CIRCLE; + this.platform = profile.concat("-").concat(tizenProjectDescription.getVersion()); + } + this.version = tizenProjectDescription.getVersion(); + + Configurator configurator = Configurator.of(platform); + this.deviceManager = configurator.getDeviceManager(); + this.schemaLocation = configurator.getLayoutSchemaLocation(); + } + + public void dispose() { + properties = null; + platform = null; + profile = null; + version = null; + deviceManager = null; + schemaLocation = null; + } + + public String getPlatform() { + return platform; + } + + public String getProfile() { + return profile; + } + + public String getVersion() { + return version; + } + + public DeviceManager getDeviceManager() { + return deviceManager; + } + + public String getSchemaLocation() { + return schemaLocation; + } + + public IProject getProject() { + return project; + } + + public static AppManager getAppManager() { + IProject project = null; + IWorkbenchWindow[] winList = PlatformUI.getWorkbench().getWorkbenchWindows(); + if (winList == null) + return null; + + for (IWorkbenchWindow win : winList) { + if (win.getActivePage() != null) { + if (win.getActivePage().getActiveEditor() instanceof CombineEditorPart) { + project = ((FileEditorInput) win.getActivePage().getActiveEditor().getEditorInput()).getFile().getProject(); + return AppManager.getAppManager(project); + } + } + } + + return null; + } + + public static AppManager getAppManager(IEditorInput editorInput) { + IProject project = null; + project = ((FileEditorInput) editorInput).getFile().getProject(); + return AppManager.getAppManager(project); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/app/loader/PropertiesLoader.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/app/loader/PropertiesLoader.java new file mode 100644 index 0000000..aa42106 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/app/loader/PropertiesLoader.java @@ -0,0 +1,82 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.app.loader; + +import java.io.File; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; + +import org.eclipse.core.resources.IFile; +import org.tizen.common.util.Assert; +import org.tizen.efluibuilder.model.app.loader.jaxb.Properties; + + +public final class PropertiesLoader { + public Properties data = null; + + public Properties load(IFile iFile) throws JAXBException { + String path = iFile.getLocation().toString(); + return load(path); + } + + public void save(IFile iFile) throws JAXBException { + String path = iFile.getLocation().toString(); + save(path); + } + + public Properties load(String path) throws JAXBException { + File file = new File(path); + Assert.isTrue(file.exists(), path); + Assert.isTrue(file.isFile(), path); + + JAXBContext jc = JAXBContext.newInstance(Properties.class); + Unmarshaller u = jc.createUnmarshaller(); + Properties properties = (Properties) u.unmarshal(file); + return properties; + } + + public void save(String path) throws JAXBException { + File file = new File(path); + Assert.isFalse(file.exists(), path); + // StoryBoard_START + saveFile(file); + } + + private void saveFile(File file) throws JAXBException { + JAXBContext jc = JAXBContext.newInstance(Properties.class); + Marshaller m = jc.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + m.marshal(data, file); + } + + public void saveExisting(String path) throws JAXBException { + File file = new File(path); + Assert.isTrue(file.exists(), path); + saveFile(file); + } + // StoryBoard_END +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/app/loader/PropertiesLoaderTest.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/app/loader/PropertiesLoaderTest.java new file mode 100644 index 0000000..7371382 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/app/loader/PropertiesLoaderTest.java @@ -0,0 +1,52 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.app.loader; + +import javax.xml.bind.JAXBException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.model.app.loader.jaxb.Properties; + + +public final class PropertiesLoaderTest { + private static Logger logger = LoggerFactory.getLogger(PropertiesLoaderTest.class); + public Properties data = null; + + public void test(String path) { + logger.info(path); + PropertiesLoader propertiesLoader = new PropertiesLoader(); + Properties properties; + try { + properties = propertiesLoader.load(path + "2"); + logger.info(properties.getShape()); + properties.setShape("circle"); + propertiesLoader.data = properties; + propertiesLoader.save(path + "3"); + } catch (JAXBException e) { + e.printStackTrace(); + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/app/loader/jaxb/ObjectFactory.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/app/loader/jaxb/ObjectFactory.java new file mode 100644 index 0000000..a8ec050 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/app/loader/jaxb/ObjectFactory.java @@ -0,0 +1,65 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 + * + */ + +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2016.03.08 at 04:51:38 PM KST +// + + +package org.tizen.efluibuilder.model.app.loader.jaxb; + +import javax.xml.bind.annotation.XmlRegistry; + + +/** + * This object contains factory methods for each Java content interface and Java element interface + * generated in the org.tizen.efluibuilder.model.properties package. + *

+ * An ObjectFactory allows you to programatically construct new instances of the Java representation + * for XML content. The Java representation of XML content can consist of schema derived interfaces + * and classes representing the binding of schema type definitions, element declarations and model + * groups. Factory methods for each of these are provided in this class. + * + */ +@XmlRegistry +public class ObjectFactory { + + /** + * Create a new ObjectFactory that can be used to create new instances of schema derived classes + * for package: org.tizen.efluibuilder.model.properties + * + */ + public ObjectFactory() { + } + + /** + * Create an instance of {@link Properties } + * + */ + public Properties createProperties() { + return new Properties(); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/app/loader/jaxb/Properties.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/app/loader/jaxb/Properties.java new file mode 100644 index 0000000..cb564f0 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/app/loader/jaxb/Properties.java @@ -0,0 +1,116 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 + * + */ + +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2016.03.08 at 04:51:38 PM KST +// + + +package org.tizen.efluibuilder.model.app.loader.jaxb; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

+ * Java class for anonymous complex type. + * + *

+ * The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="shape">
+ *           <simpleType>
+ *             <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ *               <enumeration value="square"/>
+ *               <enumeration value="circle"/>
+ *             </restriction>
+ *           </simpleType>
+ *         </element>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { "shape", "view" }) +@XmlRootElement(name = "properties") +public class Properties { + + @XmlElement(required = true) + protected String shape; + // StoryBoard_START + @XmlElementWrapper(name = "storyboard") + @XmlElement(required = true) + protected List view = new ArrayList(); + + // StoryBoard_END + + /** + * Gets the value of the shape property. + * + * @return possible object is {@link String } + * + */ + public String getShape() { + return shape; + } + + /** + * Sets the value of the shape property. + * + * @param value + * allowed object is {@link String } + * + */ + public void setShape(String value) { + this.shape = value; + } + + // StoryBoard_START + public List getViews() { + return view; + } + + public void setViews(List views) { + this.view = views; + } + // StoryBoard_END +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/app/loader/jaxb/ViewModel.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/app/loader/jaxb/ViewModel.java new file mode 100644 index 0000000..8f0ec36 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/app/loader/jaxb/ViewModel.java @@ -0,0 +1,66 @@ +/* + * UI Builder - StoryBoard + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + + +package org.tizen.efluibuilder.model.app.loader.jaxb; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlType; + + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +public class ViewModel { + @XmlAttribute(name = "id") + private String id; + @XmlAttribute(name = "location_x") + private int locationX; + @XmlAttribute(name = "location_y") + private int locationY; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public int getLocationX() { + return locationX; + } + + public void setLocationX(int locationX) { + this.locationX = locationX; + } + + public int getLocationY() { + return locationY; + } + + public void setLocationY(int locationY) { + this.locationY = locationY; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/command/AddPartCommand.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/command/AddPartCommand.java new file mode 100644 index 0000000..a3d9066 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/command/AddPartCommand.java @@ -0,0 +1,109 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.command; + +import org.eclipse.gef.commands.Command; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.DocumentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + + +public final class AddPartCommand extends Command { + private Part part = null; + private Part child = null; + private Part nextSibling = null; + + public AddPartCommand(Part parent, Part child, Part nextSibling) { + this.part = parent; + this.child = child; + this.nextSibling = nextSibling; + } + + @Override + public boolean canExecute() { + if (child.getType() != PartType.COMPONENT) { + // TODO There is no descriptor for the others(event, variation, configuration etc) + return true; + } + + // FIXED: prevent ClassCastException + if ((this.part instanceof ComponentPart) && (this.child instanceof ComponentPart)) { + DocumentPart documentPart = this.part.getOwnerDocumentPart(); + if (documentPart != null) { + ComponentDescriptor descriptor = documentPart.getComponentDescriptor(); + if (descriptor != null) { + return descriptor.canHaveChild((ComponentPart) this.part, (ComponentPart) this.child); + } + } + } + + return false; + } + + @Override + public void execute() { + Element parentElement = this.part.getElement(); + /* + * Add new DOM element + */ + Element childElement = makeElementFromPart(parentElement.getOwnerDocument(), part.getOwnerDocumentPart(), child); + + if (this.nextSibling != null) { + parentElement.insertBefore(childElement, this.nextSibling.getElement()); + } else { + parentElement.appendChild(childElement); + } + } + + private Element makeElementFromPart(final Document ownerDocument, final DocumentPart documentPart, Part part) { + Element element = ownerDocument.createElement(part.getDescriptorId()); + + PartUtil.setPartToElement(element, part); + part.setElement(element); + + if (part.hasProperty(LayoutSchemaConstants.ID) == false || part.getPropertyValue(LayoutSchemaConstants.ID).isEmpty()) { + documentPart.setPartPropertyIdRecursive(part); + } + + for (String key : part.getProperties().keySet()) { + String propertyValue = part.getPropertyValue(key); + if (propertyValue != null && !propertyValue.isEmpty()) { + element.setAttribute(key, part.getPropertyValue(key)); + } + } + + for (int i = 0; i < part.getChildren().size(); i++) { + Element childElement = makeElementFromPart(ownerDocument, documentPart, part.getChildren().get(i)); + element.appendChild(childElement); + } + + return element; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/command/ChangeOrderPartCommand.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/command/ChangeOrderPartCommand.java new file mode 100644 index 0000000..3924265 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/command/ChangeOrderPartCommand.java @@ -0,0 +1,80 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.command; + +import org.eclipse.gef.commands.Command; +import org.eclipse.wst.xml.core.internal.document.TextImpl; +import org.tizen.efluibuilder.model.part.Part; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + + +public final class ChangeOrderPartCommand extends Command { + private Part parent = null; + private Part child = null; + private Part nextSibling = null; + + public ChangeOrderPartCommand(Part child, Part nextSibling) { + this.parent = child.getParent(); + this.child = child; + this.nextSibling = nextSibling; + } + + @Override + public boolean canExecute() { + Part childParent = child.getParent(); + if (childParent != null) { + if (nextSibling == null) { + return true; + } + if (childParent == nextSibling.getParent()) { + return true; + } + } + + return false; + } + + @Override + public void execute() { + Element parentElement = parent.getElement(); + Element childElement = child.getElement(); + Element nextElement = null; + if (nextSibling != null) { + nextElement = nextSibling.getElement(); + } + + Node previousNode = childElement.getPreviousSibling(); + if (previousNode != null && previousNode instanceof TextImpl) { + parentElement.removeChild(previousNode); + } + parentElement.removeChild(childElement); + + if (nextElement == null) { + parentElement.appendChild(childElement); + } else { + parentElement.insertBefore(childElement, nextElement); + } + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/command/DisableUndoCommand.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/command/DisableUndoCommand.java new file mode 100644 index 0000000..8badff4 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/command/DisableUndoCommand.java @@ -0,0 +1,49 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.command; + +import org.eclipse.gef.commands.CompoundCommand; + + +public class DisableUndoCommand extends CompoundCommand { + @Override + public boolean canUndo() { + return false; + } + + @Override + public boolean canRedo() { + return false; + } + + @Override + public void undo() { + // Do nothing + } + + @Override + public void redo() { + // Do nothing + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/command/EMFCommandAdapter.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/command/EMFCommandAdapter.java new file mode 100644 index 0000000..a39a290 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/command/EMFCommandAdapter.java @@ -0,0 +1,69 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.command; + +import org.eclipse.emf.common.command.AbstractCommand; +import org.eclipse.gef.commands.Command; + +/* + * We now use the EMFCommandStack instead of the GEFCommandStack. + * This class makes that GEFCommand can be executed in EMFCommandStack. + */ +public class EMFCommandAdapter extends AbstractCommand { + private Command gefCommand; + + public EMFCommandAdapter(Command gefCommand) { + this.gefCommand = gefCommand; + } + + @Override + public boolean canExecute() { + return gefCommand.canExecute(); + } + + @Override + public boolean canUndo() { + return gefCommand.canUndo(); + } + + @Override + public void dispose() { + gefCommand.dispose(); + } + + @Override + public void execute() { + gefCommand.execute(); + } + + @Override + public void redo() { + gefCommand.redo(); + } + + @Override + public void undo() { + gefCommand.undo(); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/command/RemovePartCommand.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/command/RemovePartCommand.java new file mode 100644 index 0000000..c800aec --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/command/RemovePartCommand.java @@ -0,0 +1,65 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.command; + +import org.eclipse.gef.commands.Command; +import org.eclipse.wst.xml.core.internal.document.TextImpl; +import org.tizen.efluibuilder.model.part.Part; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + + +public final class RemovePartCommand extends Command { + + private Part parentPart = null; + private Part childPart = null; + + public RemovePartCommand(Part parent, Part child) { + this.parentPart = parent; + this.childPart = child; + } + + @Override + public boolean canExecute() { + return true; + } + + @Override + public void execute() { + Element parentElement = parentPart.getElement(); + Element childElement = childPart.getElement(); + + // Remove white space in layout.xml + Node previousNode = childElement.getPreviousSibling(); + if (previousNode != null && previousNode instanceof TextImpl) { + parentElement.removeChild(previousNode); + } + + /* + * Remove exist DOM element + */ + parentElement.removeChild(this.childPart.getElement()); + } + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/command/SetPropertyPartCommand.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/command/SetPropertyPartCommand.java new file mode 100644 index 0000000..5fc102f --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/command/SetPropertyPartCommand.java @@ -0,0 +1,65 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.command; + +import org.eclipse.gef.commands.Command; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.w3c.dom.Element; + + +public final class SetPropertyPartCommand extends Command { + + private Part part = null; + private String name = null; + private String value = null; + + public SetPropertyPartCommand(Part part, String name, String value) { + this.part = part; + this.name = name; + this.value = value; + } + + @Override + public boolean canExecute() { + if (part instanceof ComponentPart) { + return true; +// return part.hasProperty(name); + } + + // TODO check other part condition + return true; + + } + + @Override + public void execute() { + Element element = this.part.getElement(); + + /* + * change attribute of the DOM. + */ + element.setAttribute(name, value); + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/loader/jaxb/ObjectFactory.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/loader/jaxb/ObjectFactory.java new file mode 100644 index 0000000..38ed890 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/loader/jaxb/ObjectFactory.java @@ -0,0 +1,65 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 + * + */ + +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2016.03.08 at 04:51:38 PM KST +// + + +package org.tizen.efluibuilder.model.loader.jaxb; + +import javax.xml.bind.annotation.XmlRegistry; + + +/** + * This object contains factory methods for each Java content interface and Java element interface + * generated in the org.tizen.efluibuilder.model.properties package. + *

+ * An ObjectFactory allows you to programatically construct new instances of the Java representation + * for XML content. The Java representation of XML content can consist of schema derived interfaces + * and classes representing the binding of schema type definitions, element declarations and model + * groups. Factory methods for each of these are provided in this class. + * + */ +@XmlRegistry +public class ObjectFactory { + + /** + * Create a new ObjectFactory that can be used to create new instances of schema derived classes + * for package: org.tizen.efluibuilder.model.properties + * + */ + public ObjectFactory() { + } + + /** + * Create an instance of {@link Properties } + * + */ + public Properties createProperties() { + return new Properties(); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/loader/jaxb/Properties.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/loader/jaxb/Properties.java new file mode 100644 index 0000000..076ac28 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/loader/jaxb/Properties.java @@ -0,0 +1,116 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 + * + */ + +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2016.03.08 at 04:51:38 PM KST +// + + +package org.tizen.efluibuilder.model.loader.jaxb; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

+ * Java class for anonymous complex type. + * + *

+ * The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="shape">
+ *           <simpleType>
+ *             <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ *               <enumeration value="square"/>
+ *               <enumeration value="circle"/>
+ *             </restriction>
+ *           </simpleType>
+ *         </element>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { "shape", "view" }) +@XmlRootElement(name = "properties") +public class Properties { + + @XmlElement(required = true) + protected String shape; + // StoryBoard_START + @XmlElementWrapper(name = "storyboard") + @XmlElement(required = true) + protected List view = new ArrayList(); + + // StoryBoard_END + + /** + * Gets the value of the shape property. + * + * @return possible object is {@link String } + * + */ + public String getShape() { + return shape; + } + + /** + * Sets the value of the shape property. + * + * @param value + * allowed object is {@link String } + * + */ + public void setShape(String value) { + this.shape = value; + } + + // StoryBoard_START + public List getViews() { + return view; + } + + public void setViews(List views) { + this.view = views; + } + // StoryBoard_END +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/loader/jaxb/ViewModel.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/loader/jaxb/ViewModel.java new file mode 100644 index 0000000..9cfda9a --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/loader/jaxb/ViewModel.java @@ -0,0 +1,66 @@ +/* + * UI Builder - StoryBoard + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + + +package org.tizen.efluibuilder.model.loader.jaxb; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlType; + + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +public class ViewModel { + @XmlAttribute(name = "id") + private String id; + @XmlAttribute(name = "location_x") + private int locationX; + @XmlAttribute(name = "location_y") + private int locationY; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public int getLocationX() { + return locationX; + } + + public void setLocationX(int locationX) { + this.locationX = locationX; + } + + public int getLocationY() { + return locationY; + } + + public void setLocationY(int locationY) { + this.locationY = locationY; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/ComponentPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/ComponentPart.java new file mode 100644 index 0000000..93e0ffb --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/ComponentPart.java @@ -0,0 +1,135 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.part; + +import java.util.ArrayList; +import java.util.List; + +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; + + +public class ComponentPart extends Part { + private ViewPart ownerViewPart = null; + + public ComponentPart(String uniqueId, Part parentPart) { + super(uniqueId, parentPart, PartType.COMPONENT); + } + + public ViewPart getOwnerViewPart() { + if (this instanceof ViewPart) { + return (ViewPart) this; + } + + Part parent = getParent(); + if (parent == null) { + return ownerViewPart; + } else if (this instanceof ViewPart) { + return (ViewPart) this; + } else if (parent instanceof ComponentPart) { + return ((ComponentPart) parent).getOwnerViewPart(); + } + return null; + } + + public void setOwnerViewPart(ViewPart viewPart) { + this.ownerViewPart = viewPart; + } + + @Override + public void removeChild(Part child) { + if (children.remove(child)) { + if (child instanceof ComponentPart) { // set owner viewPart + ((ComponentPart) child).setOwnerViewPart(((ComponentPart) child).getOwnerViewPart()); + } + + this.addRemovedMutation(child); + child.setParent(null); + } + } + + public List getEventParts(String eventName) { + List eventParts = new ArrayList(); + + for (Part child : getChildren()) { + if (child.getType() == PartType.EVENT) { + if (eventName.equals(child.getPropertyValue(LayoutSchemaConstants.EVENT_SIGNAL))) { + eventParts.add((EventPart) child); + } + } + } + + return eventParts; + } + + public List getEventParts() { + List eventParts = new ArrayList(); + + for (Part child : getChildren()) { + if (child.getType() == PartType.EVENT) { + eventParts.add((EventPart) child); + } + } + + return eventParts; + } + + public List getVariationParts() { + List variationParts = new ArrayList(); + + for (Part child : getChildren()) { + if (child.getType() == PartType.VARIATION) { + variationParts.add((VariationPart) child); + } + } + + return variationParts; + } + + public VariationPart getVariationPart(String ref) { + if (ref == null) { + return null; + } + + List variations = getVariationParts(); + for (VariationPart variationPart : variations) { + if (variationPart.getPropertyValue(LayoutSchemaConstants.CONFIGURATION_REFERENCE).equals(ref)) { + return variationPart; + } + } + + return null; + } + + public String getPropertyValue(String configID, String key) { + String value = this.getPropertyValue(key); + VariationPart variationPart = getVariationPart(configID); + if (variationPart != null) { + String variationValue = variationPart.getPropertyValue(key); + if (variationValue != null) { + value = variationValue; + } + } + return value; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/ConfigurationPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/ConfigurationPart.java new file mode 100644 index 0000000..915dc32 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/ConfigurationPart.java @@ -0,0 +1,79 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.part; + +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.mscreen.configurator.MscreenConstants; + + +public class ConfigurationPart extends Part { + public ConfigurationPart(String uniqueId, Part parentPart) { + super(uniqueId, parentPart, PartType.CONFIGURATION); + } + + @Override + protected void addPropertyChangedMutation(String name, String value) { + PartMutation mutation = new PartMutation(); + mutation.initConfigurePropertyChanged(this, name, value); + this.addMutation(mutation); + } + + public boolean isCommon() { + // TODO FIXME + return MscreenConstants.CONFIGURATION_TYPE_COMMON.equals(getConfigurationType()); + } + + public String getName() { + return getPropertyValue(LayoutSchemaConstants.NAME); + } + + public String getConfigurationType() { + return getPropertyValue(LayoutSchemaConstants.TYPE); + } + + public String getDevice() { + return getPropertyValue(LayoutSchemaConstants.DEVICE); + } + + public String getOrientation() { + return getPropertyValue(LayoutSchemaConstants.ORIENTATION); + } + + public void setName(String name) { + setPropertyValue(LayoutSchemaConstants.NAME, name); + } + + public void setConfigurationType(String type) { + setPropertyValue(LayoutSchemaConstants.TYPE, type); + } + + public void setDevice(String device) { + setPropertyValue(LayoutSchemaConstants.DEVICE, device); + } + + public void setOrientation(String orientation) { + setPropertyValue(LayoutSchemaConstants.ORIENTATION, orientation); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/DataBindingPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/DataBindingPart.java new file mode 100644 index 0000000..41fcb62 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/DataBindingPart.java @@ -0,0 +1,60 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.model.part; + +import org.tizen.efluibuilder.model.util.IDGenerator; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; + +public class DataBindingPart extends Part { + + private IDGenerator propertyIDGenerator = null; + + public DataBindingPart(String uniqueId, ViewsPart parentPart) { + super(uniqueId, parentPart, PartType.DATABINDING); + propertyIDGenerator = new IDGenerator(); + } + + @Override + public void insertChildBefore(Part child, Part nextSibling) { + super.insertChildBefore(child, nextSibling); + if (child.hasProperty(LayoutSchemaConstants.ID) == false || child.getPropertyValue(LayoutSchemaConstants.ID).isEmpty()) { + this.setPartPropertyIdRecursive(child); + } + } + + private void setPartPropertyIdRecursive(Part part) { + part.setPropertyValue(LayoutSchemaConstants.ID, generateUniquePropertyId(part.getDescriptorId())); + for (Part chid : part.getChildren()) { + setPartPropertyIdRecursive(chid); + } + } + + private String generateUniquePropertyId(String descriptorId) { + return propertyIDGenerator.getID(descriptorId); + } + + public void updateID() { + propertyIDGenerator.update(this); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/DocumentPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/DocumentPart.java new file mode 100644 index 0000000..9945237 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/DocumentPart.java @@ -0,0 +1,117 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.part; + +import java.util.List; + +import org.tizen.efluibuilder.core.configurator.Configurator; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.IDGenerator; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; + + +public final class DocumentPart extends Part implements IPartChangedListener { + + private String platform = null; + private Integer lastUniqueId = null; + private IDGenerator propertyIDGenerator = null; + private PartObserver observer = null; + private boolean isValidDocument = true; + + public DocumentPart(String uniqueId) { + super(uniqueId, null, PartType.DOCUMENT); + lastUniqueId = -1; + propertyIDGenerator = new IDGenerator(); + observer = new PartObserver(this); + observer.observe(this); + } + + public void updateID() { + propertyIDGenerator.update(this); + } + + public void setPlatform(String platform) { + this.platform = platform; + } + + public String getPlatform() { + return platform; + } + + public String generateUniquePropertyId(String descriptorId) { + return propertyIDGenerator.getID(descriptorId); + } + + public String generateUniqueId() { + lastUniqueId++; + return lastUniqueId.toString(); + } + + public ComponentDescriptor getComponentDescriptor() { + Configurator configurator = Configurator.of(platform); + return new ComponentDescriptor(configurator.getDescriptorManager()); + } + + public void setPartUniqueIdRecursive(Part part) { + part.setUniqueId(generateUniqueId()); + for (Part chid : part.getChildren()) { + setPartUniqueIdRecursive(chid); + } + } + + public void setPartPropertyIdRecursive(Part part) { + if (!(part instanceof VariationPart) && !(part instanceof EventPart)) { + part.setPropertyValue(LayoutSchemaConstants.ID, generateUniquePropertyId(part.getDescriptorId())); + } + + for (Part chid : part.getChildren()) { + setPartPropertyIdRecursive(chid); + } + } + + @Override + public void partsChanged(List mutations, PartObserver observer, String sender) { + for (PartMutation mutation : mutations) { + Part targetPart = mutation.getTargetPart(); + if (targetPart == null) { + continue; + } + + String mutationType = mutation.getType(); + if (PartMutation.PROPERTY_CHANGED.equals(mutationType)) { + if (LayoutSchemaConstants.ID.equals(mutation.getPropertyName())) { + propertyIDGenerator.updateID(targetPart.getPropertyValue("id")); + } + } + } + } + + public boolean isValidDocument() { + return this.isValidDocument; + } + + public void setValidDocument(boolean isValidDocument) { + this.isValidDocument = isValidDocument; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/EventPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/EventPart.java new file mode 100644 index 0000000..23e47ba --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/EventPart.java @@ -0,0 +1,40 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.part; + +public final class EventPart extends Part { + private int eventType = EventType.NONE; + + public EventPart(String uniqueId, Part parentPart) { + super(uniqueId, parentPart, PartType.EVENT); + } + + public void setEventType(int eventType) { + this.eventType = eventType; + } + + public int getEventType() { + return eventType; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/EventType.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/EventType.java new file mode 100644 index 0000000..9282323 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/EventType.java @@ -0,0 +1,31 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.part; + +public final class EventType { + public static final int NONE = -1; + public static final int GOTO = 0; + public static final int RUN_JAVASCRIPT_FUNCTION = 2; // deprecated + public static final int OPEN_URL = 3; // deprecated +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/IPartChangedListener.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/IPartChangedListener.java new file mode 100644 index 0000000..b5bcb55 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/IPartChangedListener.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.model.part; + +import java.util.List; + + +public interface IPartChangedListener { + public void partsChanged(List mutations, PartObserver observer, String sender); +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/MScreenPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/MScreenPart.java new file mode 100644 index 0000000..47092c9 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/MScreenPart.java @@ -0,0 +1,69 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.part; + +import java.util.ArrayList; +import java.util.List; + + +public final class MScreenPart extends Part { + public MScreenPart(String uniqueId, Part parentPart) { + super(uniqueId, parentPart, PartType.MSCREEN); + } + + @Override + protected void addAddedMutation(Part child, Part nextSibling) { + PartMutation mutation = new PartMutation(); + Part prev = child.getPreviousSibling(); + Part next = child.getNextSibling(); + List addedParts = new ArrayList(); + addedParts.add(child); + mutation.initConfiguresAdded(this, addedParts, prev, next); + this.addMutation(mutation); + } + + protected void addRemovedMutation(Part child) { + PartMutation mutation = new PartMutation(); + Part prev = child.getPreviousSibling(); + Part next = child.getNextSibling(); + List removedParts = new ArrayList(); + removedParts.add(child); + mutation.initConfiguresRemoved(this, removedParts, prev, next); + this.addMutation(mutation); + } + + public ConfigurationPart getCommonConfigurationPart() { + for (Part part : this.getChildren()) { + if (part instanceof ConfigurationPart) { + ConfigurationPart configure = (ConfigurationPart) part; + if (configure.isCommon()) { + return configure; + } + } + } + + return null; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/Part.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/Part.java new file mode 100644 index 0000000..f5f925b --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/Part.java @@ -0,0 +1,443 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.part; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; + + +public abstract class Part implements Cloneable { + + protected final Logger logger = LoggerFactory.getLogger(getClass()); + + private final Object lockObj = new Object(); + + // Logical Data + private String uniqueId = ""; + protected Element element = null; + private Part parent = null; + private int type = PartType.NONE; + private List mutations = null; + private List observers = null; + private String descriptorId = null; + + // Model Data + protected ArrayList children = new ArrayList(); + private Map properties = new HashMap(); + + private void Init() { + this.mutations = new ArrayList(); + this.observers = new ArrayList(); + } + + public Part() { + this.Init(); + } + + protected Part(String uniqueId, Part parent, int type) { + setUniqueId(uniqueId); + setParent(parent); + setType(type); + this.Init(); + } + + protected void addAddedMutation(Part child, Part nextSibling) { + PartMutation mutation = new PartMutation(); + Part prev = child.getPreviousSibling(); + Part next = child.getNextSibling(); + List addedParts = new ArrayList(); + addedParts.add(child); + mutation.initPartsAdded(this, addedParts, prev, next); + this.addMutation(mutation); + } + + protected void addRemovedMutation(Part child) { + PartMutation mutation = new PartMutation(); + Part prev = child.getPreviousSibling(); + Part next = child.getNextSibling(); + List removedParts = new ArrayList(); + removedParts.add(child); + mutation.initPartsRemoved(this, removedParts, prev, next); + this.addMutation(mutation); + } + + protected void addOrderChangedMutation(Part child, Part nextSibling) { + PartMutation mutation = new PartMutation(); + List movedParts = new ArrayList(); + movedParts.add(child); + mutation.initPartsOrderChanged(this, movedParts); + this.addMutation(mutation); + } + + protected void addPropertyChangedMutation(String name, String value) { + PartMutation mutation = new PartMutation(); + mutation.initPropertyChanged(this, name, value); + this.addMutation(mutation); + } + + protected void setPartUniqueId(Part part) { + DocumentPart doc = this.getOwnerDocumentPart(); + if (doc != null) { + part.setUniqueId(doc.generateUniqueId()); + } + } + + public void dispose() { + children.clear(); + properties.clear(); + } + + @Override + public boolean equals(Object obj) { + // Must compare about model data + + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + + if (!this.uniqueId.equals(((Part) obj).uniqueId)) { + return false; + } + + if (!children.equals(((Part) obj).children)) { + return false; + } + + if (!properties.equals(((Part) obj).properties)) { + return false; + } + + return true; + } + + @Override + public Part clone() throws CloneNotSupportedException { + Part newPart = PartUtil.createPart(this.getType(), this.getDescriptorId()); + for (Map.Entry entry : getProperties().entrySet()) { + newPart.setPropertyValue(entry.getKey(), entry.getValue()); + } + return newPart; + } + + @Override + public int hashCode() { + return children.hashCode() + properties.hashCode() + uniqueId.hashCode(); + } + + public void insertChildBefore(Part child, Part nextSibling) { + // set part id; + // + if (this.getParent() != null) { + DocumentPart doc = this.getOwnerDocumentPart(); + if (doc != null) { + if (child.hasProperty(LayoutSchemaConstants.ID) == false || child.getPropertyValue(LayoutSchemaConstants.ID).isEmpty()) { + doc.setPartPropertyIdRecursive(child); + } + } + } + + child.setParent(this); + int siblingIndex = this.children.indexOf(nextSibling); + if (siblingIndex < 0) { + this.children.add(child); + } else { + this.children.add(siblingIndex, child); + } + this.addAddedMutation(child, nextSibling); + } + + public void moveChildBefore(Part child, Part nextSibling) { + if (this.children.contains(child)) { + this.children.remove(child); + int siblingIndex = this.children.indexOf(nextSibling); + if (siblingIndex < 0) { + this.children.add(child); + } else { + this.children.add(siblingIndex, child); + } + this.addOrderChangedMutation(child, nextSibling); + } + } + + public void removeChild(Part child) { + if (children.contains(child)) { + this.addRemovedMutation(child); + children.remove(child); + child.setParent(null); + // Stack stackParts = new Stack(); + // stackParts.add(child); + // while (stackParts.size() > 0) { + // Part part = stackParts.pop(); + // part.setElement(null); + // stackParts.addAll(part.getChildren()); + // } + } + } + + public void removeAllChildren() { + Iterator iter = children.iterator(); + while (iter.hasNext()) { + Part childPart = iter.next(); + this.addRemovedMutation(childPart); + iter.remove(); + childPart.setParent(null); + } + } + + @SuppressWarnings("unchecked") + public List getChildren() { + return (ArrayList) this.children.clone(); + // return children; + } + + public List getComponentChildren() { + List children = new ArrayList(); + for (Part child : this.children) { + if (child instanceof ComponentPart) { + children.add(child); + } + } + return children; + } + + public void setPropertyValue(String key, String value) { + if (value == null) { + return; + } + if (this.hasProperty(key) && this.getPropertyValue(key).equals(value)) { + // do nothing; + } else { + properties.put(key, value); + + // FIXME + // if (!key.equals(LayoutSchemaConstants.ID)) + this.addPropertyChangedMutation(key, value); + } + } + + public String getPropertyValue(String key) { + return properties.get(key); + } + + public boolean hasProperty(String name) { + return this.properties.containsKey(name); + } + + public boolean removeProperty(String name) { + if (this.properties.containsKey(name)) { + this.properties.remove(name); + this.addPropertyChangedMutation(name, null); + return true; + } + return false; + } + + public Map getProperties() { + return properties; + } + + public void setElement(Element element) { + this.element = element; + } + + public Element getElement() { + return element; + } + + public void setParent(Part parent) { + this.parent = parent; + } + + public Part getParent() { + return parent; + } + + public void setType(int type) { + this.type = type; + } + + public int getType() { + return type; + } + + public void setUniqueId(String uniqueId) { + this.uniqueId = uniqueId; + } + + public String getUniqueId() { + return uniqueId; + } + + public DocumentPart getOwnerDocumentPart() { + Part currentPart = this; + while (currentPart != null) { + if (currentPart.getType() == PartType.DOCUMENT) { + return (DocumentPart) currentPart; + } + + currentPart = currentPart.getParent(); + } + + return null; + } + + public void setDescriptorId(String id) { + this.descriptorId = id; + } + + public String getDescriptorId() { + // FIXME : Return value is null or empty string that is a policy + return descriptorId; + } + + public void addMutation(PartMutation mutation) { + synchronized (this.lockObj) { // + this.mutations.add(mutation); + if (this.parent != null) { + this.parent.addMutation(mutation); + } + } + } + + public void registerObserver(PartObserver observer) { + this.observers.add(observer); + } + + public void unregisterObserver(PartObserver observer) { + this.observers.remove(observer); + } + + public void notifyObservers(String sender) { + synchronized (this.lockObj) { + /* + * List children = this.getChildren(); for (int i = 0; i < children.size(); i++) { + * children.get(i).notifyObservers(sender); } + */ + + List unmodifiableList = Collections.unmodifiableList(this.mutations); + try { + List exceptionList = new ArrayList(); + for (PartObserver observer : this.observers) { + try { + observer.notify(unmodifiableList, observer, sender); + } catch (Exception e) { + exceptionList.add(e); + logger.error("Notification Error", e); + } + } + + if (!exceptionList.isEmpty()) { + // TODO: throw exceptions and follow policy + } + } finally { + this.mutations.clear(); + } + } + } + + public int getIndex() { + if (this.parent != null) { + return parent.children.indexOf(this); + } + return -1; + } + + public Part getNextSibling() { + if (this.parent != null) { + int index = parent.children.indexOf(this); + if (parent.children.size() > index + 1) { + return parent.children.get(index + 1); + } + } + + return null; + } + + public Part getPreviousSibling() { + if (this.parent != null) { + int index = parent.children.indexOf(this); + if (index > 0) { + return parent.children.get(index - 1); + } + } + + return null; + } + + public boolean isSameWith(Element element) { + if (element == null) { + return false; + } + + // check same type + String elementNodeName = element.getNodeName(); + if (elementNodeName.equals(this.getDescriptorId()) == false) { + return false; + } + + Map partProperties = this.getProperties(); + NamedNodeMap elementAttributes = element.getAttributes(); + + // check a number of properties + if (elementAttributes.getLength() != partProperties.size()) { + return false; + } + + // check each properties + + for (Entry property : partProperties.entrySet()) { + String key = property.getKey(); + String partValue = property.getValue(); + String elementValue = element.getAttribute(key); + + if (partValue == null) { + if (elementValue == null) { + continue; + } + return false; + } + + if (partValue.equals(elementValue) == false) { + return false; + } + } + + return true; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/PartMutation.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/PartMutation.java new file mode 100644 index 0000000..4735a7d --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/PartMutation.java @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.model.part; + +import java.util.List; + + +public class PartMutation { + public final static String PARTS_ADDED = "parts_added"; + public final static String PARTS_REMOVED = "parts_removed"; + public final static String PARTS_ORDER_CHANGED = "parts_order_changed"; + public final static String PROPERTY_CHANGED = "property_changed"; + public final static String CONFIGURES_ADDED = "configures_added"; + public final static String CONFIGURES_REMOVED = "configures_removed"; + public final static String CONFIGURE_PROPERTY_CHANGED = "configure_property_changed"; + public final static String CONNECTION_ADDED = "connection_added"; + public final static String CONNECTION_REMOVED = "connection_removed"; + + protected String type = null; + protected Part targetPart = null; + + protected List addedParts = null; + protected List removedParts = null; + protected List orderChangedParts = null; + protected Part previousSibling = null; + protected Part nextSibling = null; + + protected String propertyName = null; + protected String oldValue = null; + + public PartMutation() { + + } + + public String getType() { + return this.type; + } + + public Part getTargetPart() { + return this.targetPart; + } + + public List getAddedParts() { + return this.addedParts; + } + + public List getRemovedParts() { + return this.removedParts; + } + + public List getOrderChangedParts() { + return this.orderChangedParts; + } + + public Part getPreviousSibling() { + return this.previousSibling; + } + + public Part getNextSibling() { + return this.nextSibling; + } + + public String getPropertyName() { + return this.propertyName; + } + + public String getOldValue() { + return this.oldValue; + } + + public void initPartsAdded(Part targetPart, List addedParts, Part prevSibling, Part nextSibling) { + this.type = PartMutation.PARTS_ADDED; + this.targetPart = targetPart; + this.addedParts = addedParts; + this.previousSibling = prevSibling; + this.nextSibling = nextSibling; + } + + public void initPartsRemoved(Part targetPart, List removedParts, Part prevSibling, Part nextSibling) { + this.type = PartMutation.PARTS_REMOVED; + this.targetPart = targetPart; + this.removedParts = removedParts; + this.previousSibling = prevSibling; + this.nextSibling = nextSibling; + } + + public void initPropertyChanged(Part targetPart, String properyName, String oldValue) { + this.type = PartMutation.PROPERTY_CHANGED; + this.targetPart = targetPart; + this.propertyName = properyName; + this.oldValue = oldValue; + } + + public void initConfiguresAdded(Part targetPart, List addedParts, Part prevSibling, Part nextSibling) { + this.initPartsAdded(targetPart, addedParts, prevSibling, nextSibling); + this.type = PartMutation.CONFIGURES_ADDED; + } + + public void initConfiguresRemoved(Part targetPart, List removedParts, Part prevSibling, Part nextSibling) { + this.initPartsRemoved(targetPart, removedParts, prevSibling, nextSibling); + this.type = PartMutation.CONFIGURES_REMOVED; + + } + + public void initConfigurePropertyChanged(Part targetPart, String properyName, String oldValue) { + this.initPropertyChanged(targetPart, properyName, oldValue); + this.type = PartMutation.CONFIGURE_PROPERTY_CHANGED; + } + + public void initConnectionAdded(Part targetPart) { + this.type = PartMutation.CONNECTION_ADDED; + this.targetPart = targetPart; + } + + public void initConnectionRemoved(Part targetPart) { + this.type = PartMutation.CONNECTION_REMOVED; + this.targetPart = targetPart; + } + + public void initPartsOrderChanged(Part targetPart, List movedParts) { + this.type = PartMutation.PARTS_ORDER_CHANGED; + this.targetPart = targetPart; + this.orderChangedParts = movedParts; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/PartObserver.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/PartObserver.java new file mode 100644 index 0000000..7bd2107 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/PartObserver.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.model.part; + +import java.util.List; + + +public class PartObserver { + public static final String MESSAGE_GEF_EXECUTE = "EXECUTE"; + public static final String MESSAGE_GEF_UNDO = "UNDO"; + public static final String MESSAGE_GEF_REDO = "REDO"; + public static final String MESSAGE_VALID_XML = "VALID XML"; + public static final String MESSAGE_INVALID_XML = "INVALID XML"; + + private IPartChangedListener listener = null; + private Part target = null; + + public PartObserver(IPartChangedListener listener) { + this.listener = listener; + } + + public void observe(Part part) { + this.target = part; + this.target.registerObserver(this); + } + + public void disconnect() { + this.target.unregisterObserver(this); + this.target = null; + } + + public void notify(List mutations, PartObserver observer, String sender) { + this.listener.partsChanged(mutations, observer, sender); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/PartType.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/PartType.java new file mode 100644 index 0000000..397addf --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/PartType.java @@ -0,0 +1,40 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.part; + +public final class PartType { + public static final int NONE = -1; + public static final int DOCUMENT = 0; + public static final int CONFIGURATION = 1; + public static final int COMPONENT = 2; + public static final int VIEW = 3; + public static final int EVENT = 4; + public static final int VARIATION = 5; + public static final int MSCREEN = 6; + public static final int VIEWS = 7; + public static final int DATABINDING = 8; + public static final int DATASOURCE = 9; + public static final int DATAMODEL = 10; + public static final int BINDINGOBJECT = 11; +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/VariationPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/VariationPart.java new file mode 100644 index 0000000..110cdc7 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/VariationPart.java @@ -0,0 +1,30 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.part; + +public final class VariationPart extends Part { + public VariationPart(String uniqueId, Part parentPart) { + super(uniqueId, parentPart, PartType.VARIATION); + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/ViewPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/ViewPart.java new file mode 100644 index 0000000..c7f1528 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/ViewPart.java @@ -0,0 +1,52 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.part; + +public final class ViewPart extends ComponentPart { + int viewType = ViewType.VIEW; + + public ViewPart(String uniqueId, Part parentPart) { + super(uniqueId, parentPart); + setType(PartType.VIEW); + } + + @Override + public void removeChild(Part child) { + if (children.remove(child)) { + if (child instanceof ComponentPart) { // set owner viewPart + ((ComponentPart) child).setOwnerViewPart(this); + } + this.addRemovedMutation(child); + child.setParent(null); + } + } + + public void setViewType(int viewType) { + this.viewType = viewType; + } + + public int getViewType() { + return this.viewType; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/ViewType.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/ViewType.java new file mode 100644 index 0000000..17ca4b2 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/ViewType.java @@ -0,0 +1,29 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.part; + +public final class ViewType { + public static final int VIEW = 0; + public static final int POPUP = 1; +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/ViewsPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/ViewsPart.java new file mode 100644 index 0000000..eff2289 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/part/ViewsPart.java @@ -0,0 +1,30 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.part; + +public final class ViewsPart extends Part { + public ViewsPart(String uniqueId, Part parentPart) { + super(uniqueId, parentPart, PartType.VIEWS); + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/renderDataGenerator/Constants.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/renderDataGenerator/Constants.java new file mode 100644 index 0000000..3235527 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/renderDataGenerator/Constants.java @@ -0,0 +1,48 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.renderDataGenerator; + +//FIXME +//Need to be merge with LayoutSchemaConstants +public class Constants { + public static final String EMPTY = ""; //$NON-NLS-1$ + public static final String COLON = ":"; //$NON-NLS-1$ + public static final String SEMICOLON = ";"; //$NON-NLS-1$ + public static final String PART_TEXT = "html.text"; //$NON-NLS-1$ + public static final String PX = "px"; //$NON-NLS-1$ + public static final String ATTRIBUTE_PART_ID = "part-id"; //$NON-NLS-1$ + public static final String ATTRIBUTE_STYLE = "style"; //$NON-NLS-1$ + public static final String ATTRIBUTE_VALUE_WIDTH = "width"; //$NON-NLS-1$ + public static final String ATTRIBUTE_VALUE_HEIGHT = "height"; //$NON-NLS-1$ + public static final String ATTRIBUTE_VALUE_PX = PX; + public static final String ATTRIBUTE_TEXT = "text"; //$NON-NLS-1$ + public static final String ATTRIBUTE_LABEL = "label"; //$NON-NLS-1$ + + public static final String ATTRIBUTE_SRC = "src"; //$NON-NLS-1$ + public static final String ATTRIBUTE_END_IMAGE_PATH = "end_image_path"; //$NON-NLS-1$ + public static final String PROPERTY_GROUP_PREFIX = "group"; //$NON-NLS-1$ + + public static final String LOCALE_KEY = "@locale/"; //$NON-NLS-1$ + public static final String RESOURCE_KEY = "@resource/"; +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/renderDataGenerator/RenderDataGenerator.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/renderDataGenerator/RenderDataGenerator.java new file mode 100644 index 0000000..7ece853 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/renderDataGenerator/RenderDataGenerator.java @@ -0,0 +1,362 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.renderDataGenerator; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerException; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.Platform; +import org.osgi.framework.Bundle; +import org.tizen.common.util.Assert; +import org.tizen.efluibuilder.BuilderPlugin; +import org.tizen.efluibuilder.core.configuration.device.Device; +import org.tizen.efluibuilder.model.descriptors.ConstantDescriptor; +import org.tizen.efluibuilder.model.descriptors.PropertyDescriptor; +import org.tizen.efluibuilder.model.descriptors.TypeDescriptor; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.MScreenPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.part.ViewPart; +import org.tizen.efluibuilder.model.renderDataGenerator.reversetable.LayoutReverseConverterTable; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.mscreen.rm.ResourceManagerUtil; +import org.tizen.efluibuilder.utility.PlatformUtil; +import org.tizen.efluibuilder.utility.XMLUtil; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + +import edjResourceSyncManager.EdjResourceSyncManager; +import edjResourceSyncManager.ResourceFileDuplicator; + + +public final class RenderDataGenerator { + private static final String RENDER_SCRIPT = "/res/xsl/render_script.xsl"; + private Document xsl = null; + private String profile = null; + private String version = null; + private Path resPath = null; + ResourceManagerUtil rmUtil = null; + + private DocumentBuilder docBuilder = null; + private ResourceFileDuplicator resFileDuplicator = null; + private EdjResourceSyncManager edjResSyncMgr = null; + + public RenderDataGenerator(IProject project, String profile, String version, ResourceFileDuplicator resFileDuplicator, + EdjResourceSyncManager edjResSyncMgr) { + this.profile = profile; + this.version = version; + this.rmUtil = new ResourceManagerUtil(project); + this.resPath = Paths.get(project.getLocation().toString() + "/res"); + this.resFileDuplicator = resFileDuplicator; + this.edjResSyncMgr = edjResSyncMgr; + try { + load(); + } catch (ParserConfigurationException e) { + throw new RenderDataGeneratorException(); + } catch (SAXException e) { + throw new RenderDataGeneratorException(); + } catch (IOException e) { + throw new RenderDataGeneratorException(); + } + } + + private DocumentBuilder getDocBuilder() { + if (this.docBuilder == null) { + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + this.docBuilder = factory.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + throw new RenderDataGeneratorException(); + } + } + return this.docBuilder; + } + + private Document createtDocument() { + return this.getDocBuilder().newDocument(); + } + + private Element createElement(Document document, String tagName) { + return document.createElement(tagName); + } + + public String getJsonDataFromPart(Part part, String locale, Device device, String orientation) { + try { + Part docPart = part.getOwnerDocumentPart(); + if (docPart == null) { + return null; + } + Document document = createtDocument(); + + // create document part + Element documentElement = this.createElement(document, "tizen.doc"); // TODO : FIXME + + documentElement.setAttribute(Constants.ATTRIBUTE_PART_ID, docPart.getUniqueId()); + Element partElement = this.partToElement(document, part, getCurrentConfigurationID(part, device, orientation), locale, device); + + documentElement.appendChild(partElement); + document.appendChild(documentElement); + + String renderData = XMLUtil.transform(document, xsl); + return renderData; + } catch (TransformerException e) { + throw new RenderDataGeneratorException(); + } catch (IOException e) { + throw new RenderDataGeneratorException(); + } + } + + public Element partToElement(Document document, Part part, String currentConfigID, String locale, Device device) { + Element element = null; + String tagName; + if (part instanceof ViewPart) { + tagName = LayoutReverseConverterTable.convertElement(profile, LayoutSchemaConstants.VIEW); + } else { + tagName = LayoutReverseConverterTable.convertElement(profile, part.getDescriptorId()); + } + + element = this.createElement(document, tagName); + element.setAttribute(Constants.ATTRIBUTE_PART_ID, part.getUniqueId()); + + // this.setStyles(part, parentElement, element); + // if (part.getType() == PartType.COMPONENT) { + if (part instanceof ComponentPart) { + setStyles(document, element, (ComponentPart) part); + setProperties(element, (ComponentPart) part, currentConfigID, locale, device); + } + + // create element recursively + for (Part child : part.getChildren()) { + if (child.getType() == PartType.COMPONENT) { + Element childElement = partToElement(document, child, currentConfigID, locale, device); + if (childElement != null) { + element.appendChild(childElement); + } + } + } + return element; + } + + private String getCurrentConfigurationID(Part part, Device device, String orientation) { + Part docPart = part.getOwnerDocumentPart(); + for (Part child : docPart.getChildren()) { + if (child instanceof MScreenPart) { + for (Part configuration : child.getChildren()) { + if (device.getName().equals(configuration.getPropertyValue(LayoutSchemaConstants.DEVICE)) + && orientation.equals(configuration.getPropertyValue(LayoutSchemaConstants.ORIENTATION))) { + return configuration.getPropertyValue(LayoutSchemaConstants.ID); + } + } + } + } + return null; + } + + private InputStream openStream(String name) throws IOException { + Bundle bundle = Platform.getBundle(BuilderPlugin.PLUGIN_ID); + if (bundle != null) { + URL url = bundle.getResource(name); + if (url == null) { + throw new IOException(); + } + InputStream stream = url.openStream(); + return stream; + } + return null; + } + + private void load() throws ParserConfigurationException, SAXException, IOException { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + DocumentBuilder builder = factory.newDocumentBuilder(); + InputStream is = null; + try { + is = openStream(RENDER_SCRIPT); + if (is != null) { + xsl = builder.parse(is); + } + } finally { + if (is != null) { + is.close(); + } + } + } + + private void setStyles(Document document, Element element, ComponentPart part) { + ComponentDescriptor componentDescriptor = part.getOwnerDocumentPart().getComponentDescriptor(); + if (!componentDescriptor.canBeVisibleBorder(part)) { + return; + } + + Assert.isTrue(false); + // Adds height style attribute. + String heightString = componentDescriptor.getFeedbackHeight(part); + if (heightString != null && !heightString.isEmpty()) { + String widthString = componentDescriptor.getFeedbackWidth(part); + String widthValue = Constants.EMPTY; + if (widthString != null && !widthString.isEmpty()) { + int width = Integer.valueOf(widthString); + widthValue = Constants.ATTRIBUTE_VALUE_WIDTH + Constants.COLON + width + Constants.ATTRIBUTE_VALUE_PX + Constants.SEMICOLON; + } + String value = widthValue; + int height = Integer.valueOf(heightString).intValue(); + value = widthValue + Constants.ATTRIBUTE_VALUE_HEIGHT + Constants.COLON + height + Constants.ATTRIBUTE_VALUE_PX; + element.setAttribute(Constants.ATTRIBUTE_STYLE, value); + Element textElem = this.createElement(document, Constants.PART_TEXT); + textElem.setAttribute(Constants.ATTRIBUTE_TEXT, componentDescriptor.getGuideText(part)); + element.appendChild(textElem); + } + } + + private void setProperties(Element element, ComponentPart part, String currentConfigID, String locale, Device device) { + ComponentDescriptor componentDescriptor = part.getOwnerDocumentPart().getComponentDescriptor(); + String widgetId = LayoutReverseConverterTable.convertElement(profile, part.getDescriptorId()); + String parentWidgetId = LayoutReverseConverterTable.convertElement(profile, (part.getParent()).getDescriptorId()); + + ComponentPart parentPart = null; + if (part.getParent() instanceof ComponentPart) { + parentPart = (ComponentPart) part.getParent(); + } + List properties = componentDescriptor.getPropertyDescriptors(parentPart, part); + for (PropertyDescriptor property : properties) { + String originPropertyName = property.getPropertyName(); + String value = part.getPropertyValue(currentConfigID, originPropertyName); + if (value == null) { + continue; + } + + // temp reverse converting table + String propertyName = LayoutReverseConverterTable.convertAttribute(parentWidgetId, widgetId, originPropertyName); + value = LayoutReverseConverterTable.convertValue(parentWidgetId, widgetId, propertyName, value); + if (propertyName.equals(Constants.ATTRIBUTE_TEXT) || propertyName.equals(Constants.ATTRIBUTE_LABEL)) { + if (value.regionMatches(true, 0, Constants.LOCALE_KEY, 0, Constants.LOCALE_KEY.length())) { + + String msg = rmUtil.getMsg(value.substring(Constants.LOCALE_KEY.length()), locale); + if (msg == null) { + // no current locale + value = value.substring(Constants.LOCALE_KEY.length()); + } else if (msg.equals("")) { + // no default string(no KEY) + value = value.substring(Constants.LOCALE_KEY.length()); + } else { + value = msg; + } + } + } + // for RM - The alternative resource support 2.4 platform upper + else if (ResourceManagerUtil.isAlternativeResourceSupport(version)) { + if (isResProperty(property.getPropertyName())) { + if (value.regionMatches(true, 0, Constants.RESOURCE_KEY, 0, Constants.RESOURCE_KEY.length())) { + String resource = rmUtil.getResourcePath(value.substring(Constants.RESOURCE_KEY.length()), device.getDPI(), locale); + if (resource != null) { + value = resource; + } + } + } + } + + value = changeEnumValue(property, value); + + if (property.getPropertyType().equals(TypeDescriptor.ID_OF_HTMLSTRING)) { + Assert.isTrue(false); + element.setTextContent(value); + } else if (property.getPropertyType().indexOf(Constants.PROPERTY_GROUP_PREFIX) != 0) { + element.setAttribute(propertyName, value); + } + + if (value != null && !value.isEmpty() && isResProperty(originPropertyName)) { + Path absPath = resPath.resolve(value).normalize(); + edjResSyncMgr.addObserveTargetPath(resPath.relativize(absPath).toString()); + if (PlatformUtil.getOS().equals(PlatformUtil.OS_WIN32)) { + value = resFileDuplicator.copyFileToTempFolder(absPath.toString()); + } else { + value = absPath.toString(); + } + + if (value != null) { + element.setAttribute(propertyName, value); + } + } + + } + } + + private boolean isResProperty(String propertyName) { + if (LayoutSchemaConstants.SRC.equals(propertyName) || LayoutSchemaConstants.IMAGE_PATH.equals(propertyName) + || Constants.ATTRIBUTE_END_IMAGE_PATH.equals(propertyName)) { + return true; + } + return false; + } + + private String changeEnumValue(PropertyDescriptor property, String value) { + TypeDescriptor typeDescriptor = property.getTypeDescriptor(); + if (typeDescriptor == null) { + return value; + } + + List constants = typeDescriptor.getAvailableConstant(); + if ((constants == null) || (constants.isEmpty())) { + return value; + } + + String changedValue = value; + for (ConstantDescriptor constant : constants) { + if (value.equals(constant.getDisplayName())) { + changedValue = constant.getValue(); + } + } + return changedValue; + } + + public String getRealPathFromResourceProperty(Part part, String propertyName, Device device, String locale) { + String ret = part.getPropertyValue(propertyName); + if (ResourceManagerUtil.isAlternativeResourceSupport(version) == false || part.getPropertyValue(propertyName) == null || + !isResProperty(propertyName)) { + return ret; + } + + String value = part.getPropertyValue(propertyName); + if (value.regionMatches(true, 0, Constants.RESOURCE_KEY, 0, Constants.RESOURCE_KEY.length())) { + String resource = rmUtil.getResourcePath(value.substring(Constants.RESOURCE_KEY.length()), device.getDPI(), locale); + if (resource != null) { + return resource; + } + } + return ret; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/renderDataGenerator/RenderDataGeneratorException.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/renderDataGenerator/RenderDataGeneratorException.java new file mode 100644 index 0000000..530c668 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/renderDataGenerator/RenderDataGeneratorException.java @@ -0,0 +1,51 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.renderDataGenerator; + +public final class RenderDataGeneratorException extends RuntimeException { + + private static final long serialVersionUID = -1339463271450273863L; + + /** + * Constructs an {@code CodeGeneratorException} with {@code null} as its error detail message. + */ + public RenderDataGeneratorException() { + super(); + } + + /** + * Constructs an {@code CodeGeneratorException} with the specified detail message. + * + * @param message + * The detail message (which is saved for later retrieval by the + * {@link #getMessage()} method) + */ + public RenderDataGeneratorException(String message) { + super(message); + } + + public RenderDataGeneratorException(String message, Throwable e) { + super(message, e); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/renderDataGenerator/reversetable/AttributeTable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/renderDataGenerator/reversetable/AttributeTable.java new file mode 100644 index 0000000..af0f920 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/renderDataGenerator/reversetable/AttributeTable.java @@ -0,0 +1,115 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.renderDataGenerator.reversetable; + +final class AttributeTable { + + private static final int ELEMENT = 0; + private static final int PARENT_ELEMENT = 0; + private static final int NEW_ATTRIBUTE = 1; + private static final int OLD_ATTRIBUTE = 2; + + private static String[][] replaceAttribute = { + // element, new attr, old_attr + { "efl.bg", "src", "image-path" }, { "efl.box", "direction", "horizontal" }, { "efl.calendar", "min_year", "min-year" }, + { "efl.calendar", "max_year", "max-year" }, { "efl.calendar", "select-mode", "select_mode" }, { "efl.ctxpopup", "direction", "horizontal" }, + { "efl.ctxpopupitem", "text", "label" }, { "efl.entry", "scroll", "scrollable" }, { "efl.entry", "single_line", "single-line" }, + { "efl.entry", "context_menu", "context-menu-disabled" }, { "efl.entry", "file_text_format", "text-format" }, { "efl.entry", "src", "file-path" }, + { "efl.flipselectoritem", "text", "label" }, { "efl.gengrid", "select_mode", "select-mode" }, { "efl.gengrid", "direction", "horizontal" }, + { "efl.gengrid", "item_size_w", "item-size-w" }, { "efl.gengrid", "item_size_h", "item-size-h" }, { "efl.gengrid", "multi_select", "multi-select" }, + { "efl.gengrid", "scrollbar_h", "policy-h" }, { "efl.gengrid", "scrollbar_v", "policy-v" }, { "efl.gengriditem", "src", "image-path" }, + { "efl.genlist", "select_mode", "select-mode" }, { "efl.genlist", "item_style", "item-style" }, { "efl.genlist", "scrollbar_h", "policy-h" }, + { "efl.genlist", "scrollbar_v", "policy-v" }, { "efl.genlistitem", "text", "label" }, { "efl.genlistitem", "sub_text", "sub-label" }, + { "efl.genlistitem", "end_image_path", "end-image-path" }, { "efl.genlistitem", "end_standard_icon", "end-standard-icon" }, + { "efl.genlistitem", "image_path", "image-path" }, { "efl.genlistitem", "item_type", "item-type" }, + { "efl.genlistitem", "standard_icon", "standard-icon" }, { "efl.grid", "vsize_w", "col_count" }, + { "efl.grid", "vsize_h", "row_count" }, { "efl.image", "src", "image-path" }, { "efl.image", "aspect_fixed", "aspect-fixed" }, + { "efl.image", "fill_outside", "fill-outside" }, { "efl.image", "resizable_up", "resizable-up" }, + { "efl.image", "resizable_down", "resizable-down" }, { "efl.image", "no_scale", "no-scale" }, { "efl.index", "autohide", "autohide-disabled" }, + { "efl.index", "indicator", "indicator-disabled" }, { "efl.index", "direction", "horizontal" }, { "efl.label", "wrap_width", "wrap-width" }, + { "efl.label", "line_wrap", "wrap-set" }, + { "efl.layout", "src", "file-path" }, { "efl.layout", "group", "group-name" }, { "efl.list", "direction", "horizontal" }, + { "efl.list", "select_mode", "select-mode" }, { "efl.list", "multi_select", "multi-select" }, { "efl.list", "scrollbar_h", "policy-h" }, + { "efl.list", "scrollbar_v", "policy-v" }, { "efl.listitem", "text", "label" }, { "efl.map", "zoom_level", "zoom-level" }, + { "efl.map", "longitude", "region-lon" }, { "efl.map", "latitude", "region-lat" }, { "efl.panes", "direction", "horizontal" }, + { "efl.panes", "right_size", "right-size" }, { "efl.progressbar", "direction", "horizontal" }, { "efl.progressbar", "span_size", "span-size" }, + { "efl.radio", "state_value", "state-value" }, { "efl.scroller", "content_min_w", "min-limit-w" }, + { "efl.scroller", "content_min_h", "min-limit-h" }, { "efl.scroller", "propagate_events", "propagate-events" }, + { "efl.scroller", "scrollbar_h", "policy-h" }, { "efl.scroller", "scrollbar_v", "policy-v" }, { "efl.slider", "indicator", "show-indicator" }, + { "efl.slider", "direction", "horizontal" }, { "efl.slider", "indicator_format", "indicator-format" }, { "efl.table", "cols", "col_count" }, + { "efl.table", "rows", "row_count" }, { "efl.toolbar", "select_mode", "select-mode" }, { "efl.toolbar", "icon_size", "icon-size" }, + { "efl.toolbar", "direction", "horizontal" }, { "efl.toolbar", "shrink_mode", "shrink-mode" }, + { "efl.toolbar", "transverse_expand", "transverse-expanded" }, { "efl.toolbaritem", "src", "image-path" }, { "efl.toolbaritem", "text", "label" }, + { "tizen.view", "location_x", "location-x" }, { "tizen.view", "location_y", "location-y" }, + { "tizen.view", "screen_orientation", "screen-orientation" }, { "efl.circlegenlistitem", "image_path", "image-path" }, + { "efl.circlegenlistitem", "end_image_path", "end-image-path" }, { "efl.circlegenlistitem", "text", "label" }, + { "efl.circlegenlistitem", "sub_text", "sub-label" }, { "efl.circlegenlistitem", "item_style", "item-style" }, + { "efl.circlescroller", "content_min_w", "min-limit-w" }, { "efl.circlescroller", "content_min_h", "min-limit-h" }, + { "efl.circlescroller", "propagate_events", "propagate-events" }, }; + + private static String[][] commonReplaceAttribute = { + // new attr, old attr + { "align_h", "align-x" }, { "align_v", "align-y" }, { "weight_h", "weight-x" }, { "weight_v", "weight-y" }, }; + + private static String[][] packReplaceAttribute = { + // parent, source_attr, target_attr + { "efl.grid", "pack_x", "pack-left" }, { "efl.grid", "pack_y", "pack-top" }, { "efl.grid", "pack_w", "pack-width" }, + { "efl.grid", "pack_h", "pack-height" }, { "efl.table", "pack_col", "pack-left" }, { "efl.table", "pack_row", "pack-top" }, + { "efl.table", "col_span", "pack-width" }, { "efl.table", "row_span", "pack-height" }, { "efl.table", "row_span", "pack-height" }, + { "efl.panes", "pack", "pack-left" }, }; + + static String getReplaceAttribute(String elem, String attr) { + for (int i = 0; i < replaceAttribute.length; i++) { + String[] array = replaceAttribute[i]; + if (array[ELEMENT].equals(elem)) { + if (array[NEW_ATTRIBUTE].equals(attr)) { + return array[OLD_ATTRIBUTE]; + } + } + } + return null; + } + + static String getCommonReplaceAttribute(String attr) { + for (int i = 0; i < commonReplaceAttribute.length; i++) { + String[] array = commonReplaceAttribute[i]; + if (array[ELEMENT].equals(attr)) { + return array[NEW_ATTRIBUTE]; + } + } + return null; + } + + static String getPackReplaceAttribute(String parentElem, String attr) { + for (int i = 0; i < packReplaceAttribute.length; i++) { + String[] array = packReplaceAttribute[i]; + if (array[PARENT_ELEMENT].equals(parentElem)) { + if (array[NEW_ATTRIBUTE].equals(attr)) { + return array[OLD_ATTRIBUTE]; + } + } + } + return null; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/renderDataGenerator/reversetable/ElementTable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/renderDataGenerator/reversetable/ElementTable.java new file mode 100644 index 0000000..02cf2eb --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/renderDataGenerator/reversetable/ElementTable.java @@ -0,0 +1,103 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.renderDataGenerator.reversetable; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + + +final class ElementTable { + private static Map replaceElement = createElementMap(); + + private static Map createElementMap() { + Map element = new HashMap(); + element.put("bg", "efl.bg"); + element.put("box", "efl.box"); + element.put("button", "efl.button"); + element.put("calendar", "efl.calendar"); + element.put("check", "efl.check"); + element.put("colorselector", "efl.colorselector"); + element.put("ctxpopup", "efl.ctxpopup"); + element.put("ctxpopupitem", "efl.ctxpopupitem"); + element.put("datetime", "efl.datetime"); + element.put("entry", "efl.entry"); + element.put("flipselector", "efl.flipselector"); + element.put("flipselectoritem", "efl.flipselectoritem"); + element.put("gengrid", "efl.gengrid"); + element.put("gengriditem", "efl.gengriditem"); + element.put("genlist", "efl.genlist"); + element.put("genlistitem", "efl.genlistitem"); + element.put("grid", "efl.grid"); + element.put("hoversel", "efl.hoversel"); + element.put("hoverselitem", "efl.hoverselitem"); + element.put("icon", "efl.icon"); + element.put("image", "efl.image"); + element.put("index", "efl.index"); + element.put("indexitem", "efl.indexitem"); + element.put("label", "efl.label"); + element.put("layout", "efl.layout"); + element.put("list", "efl.list"); + element.put("listitem", "efl.listitem"); + element.put("map", "efl.map"); + element.put("multibuttonentry", "efl.multibuttonentry"); + element.put("multibuttonentryitem", "efl.multibuttonentryitem"); + element.put("panel", "efl.panel"); + element.put("panes", "efl.panes"); + element.put("popup", "efl.popup"); + element.put("progressbar", "efl.progressbar"); + element.put("radio", "efl.radio"); + element.put("rect", "efl.rect"); + element.put("scroller", "efl.scroller"); + element.put("slider", "efl.slider"); + element.put("spinner", "efl.spinner"); + element.put("table", "efl.table"); + element.put("toolbar", "efl.toolbar"); + element.put("toolbaritem", "efl.toolbaritem"); + element.put("view", "tizen.view"); + return Collections.unmodifiableMap(element); + } + + private static Map wearableElement = createWearableElementMap(); + + private static Map createWearableElementMap() { + Map element = new HashMap(); + element.put("datetime", "efl.circledatetime"); + element.put("genlist", "efl.circlegenlist"); + element.put("genlistitem", "efl.circlegenlistitem"); + element.put("progressbar", "efl.circleprogressbar"); + element.put("scroller", "efl.circlescroller"); + element.put("slider", "efl.circleslider"); + return Collections.unmodifiableMap(element); + } + + static String getReplaceWearableElement(String source) { + return wearableElement.get(source); + } + + static String getReplaceElement(String source) { + return replaceElement.get(source); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/renderDataGenerator/reversetable/LayoutReverseConverterTable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/renderDataGenerator/reversetable/LayoutReverseConverterTable.java new file mode 100644 index 0000000..5a19839 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/renderDataGenerator/reversetable/LayoutReverseConverterTable.java @@ -0,0 +1,82 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.renderDataGenerator.reversetable; + +public final class LayoutReverseConverterTable { + + public static String convertElement(String profile, String source) { + String results = null; + if (profile.equals("wearable-circle")) { + results = ElementTable.getReplaceWearableElement(source); + if (results != null) { + return results; + } + } + + results = ElementTable.getReplaceElement(source); + if (results != null) { + return results; + } + + return source; + } + + public static String convertAttribute(String parentElem, String elem, String attr) { + String results = AttributeTable.getReplaceAttribute(elem, attr); + if (results != null) { + return results; + } + + results = AttributeTable.getCommonReplaceAttribute(attr); + if (results != null) { + return results; + } + + results = AttributeTable.getPackReplaceAttribute(parentElem, attr); + if (results != null) { + return results; + } + + return attr; + } + + public static String convertValue(String parent, String elem, String attr, String val) { + String results = ValueTable.getCommonValue(attr, val); + if (results != null) { + return results; + } + + results = ValueTable.getReplacePackValue(parent, attr, val); + if (results != null) { + return results; + } + + results = ValueTable.getReplaceValue(elem, attr, val); + if (results != null) { + return results; + } + + return val; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/renderDataGenerator/reversetable/ValueTable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/renderDataGenerator/reversetable/ValueTable.java new file mode 100644 index 0000000..5e0cabd --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/renderDataGenerator/reversetable/ValueTable.java @@ -0,0 +1,115 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.renderDataGenerator.reversetable; + +final class ValueTable { + + private static final int ELEMENT = 0; + private static final int ATTRIBUTE = 1; + private static final int SOURCE_VALUE = 2; + private static final int TARGET_VALUE = 3; + + private static final int COMMON_ATTRIBUTE = 0; + private static final int COMMON_SOURCE_VALUE = 1; + private static final int COMMON_TARGET_VALUE = 2; + + private static final int PACK_PARENT_ELEMENT = 0; + + private static String[][] commonValue = { + // attribute, Source_value, Target_value + { "align-x", "fill", "FILL" }, { "align-y", "fill", "FILL" }, }; + + private static String[][] packValue = { { "efl.panes", "pack-left", "left", "0" }, { "efl.panes", "pack-left", "right", "1" }, }; + + private static String[][] replaceValue = { + // old element,old attribute, new_value, old_value + { "efl.bg", "option", "center", "0" }, { "efl.bg", "option", "scale", "1" }, { "efl.bg", "option", "stretch", "2" }, + { "efl.bg", "option", "tile", "3" }, { "efl.box", "horizontal", "horizontal", "true" }, { "efl.box", "horizontal", "vertical", "false" }, + { "efl.calendar", "select-mode", "default", "0" }, { "efl.calendar", "select-mode", "always", "1" }, { "efl.calendar", "select-mode", "none", "2" }, + { "efl.calendar", "select-mode", "ondemand", "3" }, { "efl.ctxpopup", "horizontal", "horizontal", "true" }, + { "efl.ctxpopup", "horizontal", "vertical", "false" }, { "efl.entry", "text-format", "plain_utf8", "0" }, + { "efl.entry", "text-format", "markup_utf8", "1" }, { "efl.entry", "context-menu-disabled", "false", "true" }, + { "efl.entry", "context-menu-disabled", "true", "false" }, { "efl.gengrid", "horizontal", "horizontal", "true" }, + { "efl.gengrid", "horizontal", "vertical", "false" }, { "efl.genlist", "select-mode", "default", "0" }, + { "efl.genlist", "select-mode", "always", "1" }, { "efl.genlist", "select-mode", "none", "2" }, + { "efl.genlist", "select-mode", "display_only", "3" }, { "efl.genlist", "policy-h", "auto", "0" }, { "efl.genlist", "policy-h", "true", "1" }, + { "efl.genlist", "policy-h", "false", "2" }, { "efl.genlist", "policy-v", "auto", "0" }, { "efl.genlist", "policy-v", "true", "1" }, + { "efl.genlist", "policy-v", "false", "2" }, { "efl.index", "autohide-disabled", "false", "true" }, + { "efl.index", "autohide-disabled", "true", "false" }, + { "efl.index", "indicator-disabled", "false", "true" }, { "efl.index", "indicator-disabled", "true", "false" }, + { "efl.index", "horizontal", "horizontal", "true" }, + { "efl.index", "horizontal", "vertical", "false" }, + { "efl.image", "orient", "none", "0" }, + { "efl.image", "orient", "orient_0", "0" }, { "efl.image", "orient", "orient_90", "1" }, { "efl.image", "orient", "rotate_90", "1" }, + { "efl.image", "orient", "orient_180", "2" }, { "efl.image", "orient", "rotate_180", "2" }, { "efl.image", "orient", "orient_270", "3" }, + { "efl.image", "orient", "rotate_270", "3" }, { "efl.image", "orient", "flip_horizontal", "4" }, { "efl.image", "orient", "flip_vertical", "5" }, + { "efl.image", "orient", "flip_transpose", "6" }, { "efl.image", "orient", "flip_transverse", "7" }, { "efl.label", "wrap-set", "none", "0" }, + { "efl.label", "wrap-set", "char", "1" }, { "efl.label", "wrap-set", "word", "2" }, { "efl.label", "wrap-set", "mixed", "3" }, + { "efl.list", "horizontal", "horizontal", "true" }, { "efl.list", "horizontal", "vertical", "false" }, + { "efl.list", "select-mode", "default", "0" }, { "efl.list", "select-mode", "always", "1" }, { "efl.list", "select-mode", "none", "2" }, + { "efl.list", "select-mode", "display_only", "3" }, { "efl.list", "mode", "compress", "0" }, { "efl.list", "mode", "scroll", "1" }, + { "efl.list", "mode", "limit", "2" }, { "efl.list", "mode", "expand", "3" }, { "efl.list", "policy-h", "auto", "0" }, + { "efl.list", "policy-h", "true", "1" }, { "efl.list", "policy-h", "false", "2" }, { "efl.list", "policy-v", "auto", "0" }, + { "efl.list", "policy-v", "true", "1" }, { "efl.list", "policy-v", "false", "2" }, { "efl.panes", "horizontal", "horizontal", "true" }, + { "efl.panes", "horizontal", "vertical", "false" }, { "efl.panel", "orient", "top", "0" }, { "efl.panel", "orient", "bottom", "1" }, + { "efl.panel", "orient", "left", "2" }, { "efl.panel", "orient", "right", "3" }, { "efl.progressbar", "horizontal", "horizontal", "true" }, + { "efl.progressbar", "horizontal", "vertical", "false" }, { "efl.scroller", "policy-h", "auto", "0" }, { "efl.scroller", "policy-h", "true", "1" }, + { "efl.scroller", "policy-h", "false", "2" }, { "efl.scroller", "policy-v", "auto", "0" }, { "efl.scroller", "policy-v", "true", "1" }, + { "efl.scroller", "policy-v", "false", "2" }, { "efl.slider", "horizontal", "horizontal", "true" }, + { "efl.slider", "horizontal", "vertical", "false" }, { "efl.toolbar", "select-mode", "default", "0" }, + { "efl.toolbar", "select-mode", "always", "1" }, { "efl.toolbar", "select-mode", "none", "2" }, + { "efl.toolbar", "select-mode", "display_only", "3" }, { "efl.toolbar", "horizontal", "horizontal", "true" }, + { "efl.toolbar", "horizontal", "vertical", "false" }, { "efl.toolbar", "shrink-mode", "none", "0" }, { "efl.toolbar", "shrink-mode", "hide", "1" }, + { "efl.toolbar", "shrink-mode", "scroll", "2" }, { "efl.toolbar", "shrink-mode", "menu", "3" }, { "efl.toolbar", "shrink-mode", "expand", "4" }, }; + + static String getCommonValue(String attr, String val) { + for (int i = 0; i < commonValue.length; i++) { + String[] array = commonValue[i]; + if (array[COMMON_ATTRIBUTE].equals(attr) && array[COMMON_SOURCE_VALUE].equals(val)) { + return array[COMMON_TARGET_VALUE]; + } + } + return null; + } + + static String getReplaceValue(String elem, String attr, String val) { + for (int i = 0; i < replaceValue.length; i++) { + String[] array = replaceValue[i]; + if (array[ELEMENT].equals(elem) && array[ATTRIBUTE].equals(attr) && array[SOURCE_VALUE].equals(val)) { + return array[TARGET_VALUE]; + } + } + return null; + } + + static String getReplacePackValue(String parent, String attr, String val) { + for (int i = 0; i < packValue.length; i++) { + String[] array = packValue[i]; + if (array[PACK_PARENT_ELEMENT].equals(parent) && array[ATTRIBUTE].equals(attr) && array[SOURCE_VALUE].equals(val)) { + return array[TARGET_VALUE]; + } + } + return null; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/snippet/ISnippet.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/snippet/ISnippet.java new file mode 100644 index 0000000..9e034b2 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/snippet/ISnippet.java @@ -0,0 +1,148 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.snippet; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.w3c.dom.Document; + + +public interface ISnippet extends Comparable { + public static final String CATEGORY_SYSTEM = "system"; + public static final String CATEGORY_USER = "user"; + + public static final String TYPE_VIEW = "view"; + public static final String TYPE_WIDGET = "widget"; + + /** + * Gets the id of this snippet + * + * @return an id of this snippet + */ + public String getId(); + + /** + * Sets the name of this snippet + * + * @param name + * a name of this snippet + */ + public void setName(String name); + + /** + * Gets the name of this snippet + * + * @return a name of this snippet + */ + public String getName(); + + /** + * Sets the type of this snippet + * + * @param type + * a type of this snippet + */ + public void setType(String type); + + /** + * Gets the type of this snippet + * + * @return a type of this snippet + */ + public String getType(); + + /** + * Gets a category of this snippet + * + * @return a category of this snippet + */ + public String getCategory(); + + /** + * Sets a category of this snippet + * + * @param category + * a category of this snippet + */ + public void setCategory(String category); + + /** + * Sets description of this snippet + * + * @param description + * description of this snippet + */ + public void setDescription(String description); + + /** + * Gets description of this snippet + * + * @return description of this snippet + */ + public String getDescription(); + + /** + * Sets image of this snippet + * + * @param imageDescriptor + * imageDescriptor of this snippet + */ + public void setImage(ImageDescriptor imageDescriptor); + + /** + * Gets image of this snippet + * + * @return imageDescriptor of this snippet + */ + public ImageDescriptor getImage(); + + /** + * Sets model of this snippet + * + * @param model + * model of this snippet + */ + public void setModel(Document model); + + /** + * Gets model of this snippet + * + * @return model of this snippet + */ + public Document getModel(); + + /** + * Gets icon path of this snippet icon file + * + * @return icon path of this snippet + */ + public String getSmallIconPath(); // advux-palette + + /** + * Gets icon image descriptor of this snippet icon file + * + * @return icon image descriptor of this snippet + */ + public ImageDescriptor getSmallIcon(); // advux-palette + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/snippet/ISnippetManager.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/snippet/ISnippetManager.java new file mode 100644 index 0000000..613eb0d --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/snippet/ISnippetManager.java @@ -0,0 +1,83 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.snippet; + +import java.io.File; +import java.util.Collection; +import java.util.List; + + +public interface ISnippetManager { + + public void load(File folder); + + /** + * + * @return + */ + public List getSnippets(); + + /** + * + * @return + */ + public Collection getViewTemplates(); + + /** + * + * @param id + * @return + */ + public ISnippet find(String id); + + /** + * @param snippet + */ + public void create(ISnippet snippet); + + /** + * @param snippet + */ + public void remove(ISnippet snippet); + + /** + * @param path + */ + @Deprecated + public void importSnippet(String path); + + /** + * @param snippet + */ + @Deprecated + public void importSnippet(ISnippet snippet); + + /** + * @param snippet + * @param path + */ + @Deprecated + public void exportSnippet(ISnippet snippet, String path); + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/snippet/Snippet.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/snippet/Snippet.java new file mode 100644 index 0000000..7039ab0 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/snippet/Snippet.java @@ -0,0 +1,147 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.snippet; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.BuilderPlugin; +import org.w3c.dom.Document; + + +public final class Snippet implements ISnippet { + + private String id = null; + private String name = null; + private String type = null; + private String category = CATEGORY_USER; + private String description = null; + private ImageDescriptor imageDescriptor = null; + private Document model = null; + + // advux-palette + private static final String SMALL_ICON_PATH = "snippet/pt_block_icon_nor.png"; //$NON-NLS-1$ + private ImageDescriptor smallIconImageDescriptor = null; + + public Snippet() { + super(); + } + + public void setId(String id) { + this.id = id; + } + + @Override + public String getId() { + return id; + } + + @Override + public void setName(String name) { + this.name = name; + } + + @Override + public String getName() { + return name; + } + + @Override + public void setType(String type) { + this.type = type; + } + + @Override + public String getType() { + return type; + } + + @Override + public String getCategory() { + return category; + } + + @Override + public void setCategory(String category) { + this.category = category; + } + + @Override + public void setDescription(String description) { + this.description = description; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public void setImage(ImageDescriptor imageDescriptor) { + this.imageDescriptor = imageDescriptor; + } + + @Override + public ImageDescriptor getImage() { + return imageDescriptor; + } + + @Override + public void setModel(Document object) { + this.model = object; + } + + @Override + public Document getModel() { + return model; + } + + @Override + public String getSmallIconPath() { + // advux-palette + return SMALL_ICON_PATH; + } + + @Override + public ImageDescriptor getSmallIcon() { + if (smallIconImageDescriptor == null) { + smallIconImageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(BuilderPlugin.PLUGIN_ID, BuilderConstants.ICON_DIR + getSmallIconPath()); + } + return smallIconImageDescriptor; + + } + + @Override + public int compareTo(ISnippet o) { + return getName().compareTo(o.getName()); + } + + @Override + public boolean equals(Object o) { + if (o instanceof ISnippet) { + return getName().equals(((ISnippet)o).getName()); + } + return false; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/snippet/SnippetException.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/snippet/SnippetException.java new file mode 100644 index 0000000..e416c51 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/snippet/SnippetException.java @@ -0,0 +1,50 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.snippet; + +public final class SnippetException extends RuntimeException { + private static final long serialVersionUID = -2208650678310419106L; + + /** + * Constructs an {@code CodeGeneratorException} with {@code null} as its error detail message. + */ + public SnippetException() { + super(); + } + + /** + * Constructs an {@code CodeGeneratorException} with the specified detail message. + * + * @param message + * The detail message (which is saved for later retrieval by the + * {@link #getMessage()} method) + */ + public SnippetException(String message) { + super(message); + } + + public SnippetException(String message, Throwable e) { + super(message, e); + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/snippet/SnippetLoader.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/snippet/SnippetLoader.java new file mode 100644 index 0000000..74d2941 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/snippet/SnippetLoader.java @@ -0,0 +1,219 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.snippet; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerException; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.ImageLoader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.utility.ResourceUtil; +import org.tizen.efluibuilder.utility.XMLUtil; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + + +public final class SnippetLoader { + private Logger logger = LoggerFactory.getLogger(SnippetLoader.class); + private static final String FILE_META = "meta.xml"; + private static final String FILE_DESCRIPTOR = "descriptor.xml"; + private static final String FILE_IMAGE = "image.png"; + + public ISnippet snippet = null; + + public SnippetLoader() { + super(); + } + + private void loadMetaFile(File file) throws MalformedURLException, ParserConfigurationException, SAXException, IOException { + Document document = XMLUtil.load(file); + + // id + NodeList nodes = document.getElementsByTagName("id"); + Node node = nodes.item(0); + String value = node.getTextContent(); + ((Snippet) snippet).setId(value); + + // name + nodes = document.getElementsByTagName("name"); + node = nodes.item(0); + value = node.getTextContent(); + snippet.setName(value); + + // type + nodes = document.getElementsByTagName("type"); + node = nodes.item(0); + value = node.getTextContent(); + snippet.setType(value); + + // category + nodes = document.getElementsByTagName("category"); + node = nodes.item(0); + value = node.getTextContent(); + snippet.setCategory(value); + + // description + nodes = document.getElementsByTagName("description"); + node = nodes.item(0); + value = node.getTextContent(); + snippet.setDescription(value); + } + + private void saveMetaFile(File file) throws ParserConfigurationException, IOException, TransformerException { + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder(); + Document document = builder.newDocument(); + + // root + Element rootElement = document.createElement("meta"); + document.appendChild(rootElement); + + // id + Element element = document.createElement("id"); + element.setTextContent(snippet.getId()); + rootElement.appendChild(element); + // name + element = document.createElement("name"); + element.setTextContent(snippet.getName()); + rootElement.appendChild(element); + + // type + element = document.createElement("type"); + element.setTextContent(snippet.getType()); + rootElement.appendChild(element); + + // category + element = document.createElement("category"); + element.setTextContent(snippet.getCategory()); + rootElement.appendChild(element); + + // description + element = document.createElement("description"); + element.setTextContent(snippet.getDescription()); + rootElement.appendChild(element); + + XMLUtil.save(document, file); + } + + private void loadDescriptorFile(File file) throws ParserConfigurationException, MalformedURLException, SAXException, IOException { + Document document = XMLUtil.load(file); + snippet.setModel(document); + } + + private void saveDescriptorFile(File file) throws IOException, TransformerException { + Document document = snippet.getModel(); + XMLUtil.save(document, file); + } + + private void loadImageFile(File file) throws IOException { + URL url = file.toURI().toURL(); + ImageDescriptor imageDescriptor = ResourceUtil.getImageDescriptor(url); + snippet.setImage(imageDescriptor); + } + + private void saveImageFile(ImageDescriptor image, File file) { + ImageLoader imageLoader = new ImageLoader(); + ImageData imageData = image.getImageData(); + // imageData = ImageUtils.resize(imageData, IMAGE_WIDTH, IMAGE_HEIGHT, false); + imageLoader.data = new ImageData[] { imageData }; + imageLoader.save(file.getPath(), SWT.IMAGE_PNG); + } + + public ISnippet load(File snippetFile) { + snippet = new Snippet(); + try { + File[] files = snippetFile.listFiles(); + if (files != null) { + for (File file : files) { + if (file.getName().equals(FILE_META)) { + loadMetaFile(file); + } else if (file.getName().equals(FILE_DESCRIPTOR)) { + loadDescriptorFile(file); + } else if (file.getName().equals(FILE_IMAGE)) { + loadImageFile(file); + } + } + } + } catch (MalformedURLException e) { + throw new SnippetException(e.getMessage()); + } catch (ParserConfigurationException e) { + throw new SnippetException(e.getMessage()); + } catch (SAXException e) { + throw new SnippetException(e.getMessage()); + } catch (IOException e) { + throw new SnippetException(e.getMessage()); + } + return snippet; + } + + public void save(File snippetFile) { + Assert.isTrue(!snippetFile.exists()); + boolean result = snippetFile.mkdir(); + if (result == false) { + logger.warn("It failed to make directory"); + } + String snippetFilePath = snippetFile.getAbsolutePath(); + File metaFile = new File(snippetFilePath + "/" + FILE_META); + try { + saveMetaFile(metaFile); + } catch (ParserConfigurationException e) { + throw new SnippetException(e.getMessage()); + } catch (IOException e) { + throw new SnippetException(e.getMessage()); + } catch (TransformerException e) { + throw new SnippetException(e.getMessage()); + } + + File descriptorFile = new File(snippetFilePath + "/" + FILE_DESCRIPTOR); + try { + saveDescriptorFile(descriptorFile); + } catch (IOException e) { + throw new SnippetException(e.getMessage()); + } catch (TransformerException e) { + throw new SnippetException(e.getMessage()); + } + + // save image + ImageDescriptor imageDescriptor = snippet.getImage(); + if (imageDescriptor != null) { + File imageFile = new File(snippetFilePath + "/" + FILE_IMAGE); + saveImageFile(imageDescriptor, imageFile); + } + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/snippet/SnippetManager.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/snippet/SnippetManager.java new file mode 100644 index 0000000..bc27400 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/snippet/SnippetManager.java @@ -0,0 +1,208 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.snippet; + +import java.io.File; +import java.net.URI; +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileStore; +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.tizen.efluibuilder.BuilderPlugin; +import org.tizen.efluibuilder.utility.ResourceUtil; + + +public final class SnippetManager implements ISnippetManager { + private static final String SNIPPET_FOLDER_PATH = "res/snippets"; + private static final String SNIPPET_PREFIX = "snippet"; + + private Map snippets = null; + + private File folder = null; + + private static ISnippetManager snippetManager = null; + + public static synchronized ISnippetManager getDefault() { + if (snippetManager == null) { + snippetManager = new SnippetManager(); + } + ((SnippetManager) snippetManager).load(); + return snippetManager; + } + + private SnippetManager() { + super(); + snippets = new HashMap(); + } + + public void dispose() { + snippets.clear(); + snippets = null; + folder = null; + } + + private boolean isSnippetFile(File snippetFile) { + Assert.isTrue(snippetFile.exists()); + Assert.isTrue(snippetFile.isDirectory()); + return true; + } + + @Override + public List getSnippets() { + List collection = new LinkedList(); + Collection values = snippets.values(); + + for (ISnippet snippet : values) { + if (!snippet.getType().equals(ISnippet.TYPE_WIDGET)) { + continue; + } + collection.add(snippet); + } + return collection; + } + + @Override + public Collection getViewTemplates() { + List collection = new LinkedList(); + Collection values = snippets.values(); + + for (ISnippet snippet : values) { + if (!snippet.getType().equals(ISnippet.TYPE_VIEW)) { + continue; + } + collection.add(snippet); + } + return collection; + } + + @Override + public ISnippet find(String id) { + return snippets.get(id); + } + + public void load() { + URI uri = ResourceUtil.getURI(BuilderPlugin.PLUGIN_ID, SNIPPET_FOLDER_PATH); + folder = new File(uri); + load(folder); + } + + public void load(File folder) { + snippets.clear(); + + this.folder = folder; + if (!folder.exists()) { + throw new SnippetException("Snippet folder not found"); + } + + if (!folder.isDirectory()) { + throw new SnippetException("Snippet folder not found"); + } + + File[] files = folder.listFiles(); + if (files != null) { + for (File file : files) { + if (!isSnippetFile(file)) { + continue; + } + SnippetLoader loader = new SnippetLoader(); + ISnippet snippet = loader.load(file); + if (snippet.getType().equals(ISnippet.TYPE_VIEW)) { + snippets.put(snippet.getId(), snippet); + } else if (snippet.getType().equals(ISnippet.TYPE_WIDGET)) { + snippets.put(snippet.getId(), snippet); + } + } + } + } + + private String createId() { + int index = 1; + String id = SNIPPET_PREFIX + index; + while (snippets.containsKey(id)) { + index++; + id = SNIPPET_PREFIX + index; + } + + return id; + } + + private File getFile(ISnippet snippet) { + String path = folder.getAbsolutePath() + File.separator + snippet.getId(); + File file = new File(path); + return file; + } + + public void create(ISnippet snippet) { + // create id; + String id = createId(); + ((Snippet) snippet).setId(id); + snippets.put(id, snippet); + + File snippetFile = getFile(snippet); + SnippetLoader loader = new SnippetLoader(); + loader.snippet = snippet; + loader.save(snippetFile); + load(); + } + + public void remove(ISnippet snippet) { + File file = getFile(snippet); + try { + IFileStore fileStore = EFS.getStore(file.toURI()); + fileStore.delete(EFS.NONE, new NullProgressMonitor()); + } catch (CoreException e) { + throw new SnippetException(e.getMessage()); + } + + load(); + } + + public void importSnippet(String path) { + File file = new File(path); + SnippetLoader loader = new SnippetLoader(); + ISnippet snippet = loader.load(file); + importSnippet(snippet); + } + + public void importSnippet(ISnippet snippet) { + create(snippet); + } + + public void exportSnippet(ISnippet snippet, String path) { + // Remove ID + ((Snippet) snippet).setId(""); + SnippetLoader snippetLoader = new SnippetLoader(); + snippetLoader.snippet = snippet; + File file = new File(path + File.separator + snippet.getName()); + snippetLoader.save(file); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/ComponentDescriptor.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/ComponentDescriptor.java new file mode 100644 index 0000000..31e70c1 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/ComponentDescriptor.java @@ -0,0 +1,362 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.model.util; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.tizen.efluibuilder.model.descriptors.DescriptorManager; +import org.tizen.efluibuilder.model.descriptors.EventDescriptor; +import org.tizen.efluibuilder.model.descriptors.EventParamDescriptor; +import org.tizen.efluibuilder.model.descriptors.PartConditionDescriptor; +import org.tizen.efluibuilder.model.descriptors.PropertyDescriptor; +import org.tizen.efluibuilder.model.descriptors.TypeDescriptor; +import org.tizen.efluibuilder.model.descriptors.WidgetDescriptor; +import org.tizen.efluibuilder.model.descriptors.WidgetDescriptor.DescriptorType; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.Part; + + +public class ComponentDescriptor { + + private DescriptorManager descriptorManager = null; + + public ComponentDescriptor(final DescriptorManager descriptorManager) { + this.descriptorManager = descriptorManager; + } + + // DEPRECATED + public WidgetDescriptor getWidgetDescriptor(String descriptorId) { + return descriptorManager.getWidgetDescriptor(descriptorId); + } + + public boolean canBeVisibleBorder(ComponentPart part) { + WidgetDescriptor widgetDescriptor = descriptorManager.getWidgetDescriptor(part.getDescriptorId()); + if (widgetDescriptor != null) { + if (widgetDescriptor.isBorderVisible()) { + // Checks that part can have a child part. + String condition = widgetDescriptor.getFeedbackCondition(); + if (condition == null || condition.isEmpty() || condition.equals(ModelConstants.ASTERISK)) { + if (widgetDescriptor.canHaveChildren()) { + if (part.getComponentChildren().size() == 0) { + return true; + } else { + return false; + } + } else { + return true; + } + } else { + String[] con = condition.split(ModelConstants.COMMA); + for (int i = 0; i < con.length; i++) { + if (widgetDescriptor.getPropertyDescriptor(con[i]) != null) { + String value = part.getPropertyValue(condition); + if (value == null || value.isEmpty()) { + continue; + } else { + return false; + } + } else { + + } + } + return true; + } + } + } + + return false; + } + + public boolean canHaveChild(ComponentPart part, ComponentPart childPart) { + WidgetDescriptor partDescriptor = descriptorManager.getWidgetDescriptor(part.getDescriptorId()); + WidgetDescriptor childPartDescriptor = descriptorManager.getWidgetDescriptor(childPart.getDescriptorId()); + + if (partDescriptor != null && childPartDescriptor != null) { + String exclusiveGroup = partDescriptor.getExclusiveGroupOfContent(childPartDescriptor.getDescriptorId()); + if (exclusiveGroup != null) { + if (findExclusiveGroupOfContent(part, exclusiveGroup)) { + return false; + } + } + int childSize = part.getComponentChildren().size(); + return partDescriptor.canHaveChild(childPartDescriptor, childSize) && childPartDescriptor.canSetParent(partDescriptor); + } else { + return false; + } + } + + private boolean findExclusiveGroupOfContent(ComponentPart part, String exclusiveGroup) { + WidgetDescriptor widgetDescriptor = descriptorManager.getWidgetDescriptor(part.getDescriptorId()); + if (widgetDescriptor == null || exclusiveGroup == null) { + return false; + } + + Iterator itr = part.getChildren().iterator(); + ComponentPart child = null; + boolean exclusiveType = false; + String groupName = null; + + while (itr.hasNext()) { + child = (ComponentPart) itr.next(); + groupName = widgetDescriptor.getExclusiveGroupOfContent(child.getDescriptorId()); + if ((groupName != null) && (exclusiveGroup.equals(groupName))) { + exclusiveType = true; + break; + } + } + + return exclusiveType; + } + + public boolean canCopyChild(ComponentPart part, ComponentPart childPart) { + WidgetDescriptor partDescriptor = descriptorManager.getWidgetDescriptor(part.getDescriptorId()); + WidgetDescriptor childPartDescriptor = descriptorManager.getWidgetDescriptor(childPart.getDescriptorId()); + if (partDescriptor != null && childPartDescriptor != null) { + return partDescriptor.canCopyChild(childPartDescriptor); + } else { + return false; + } + } + + public boolean canRemoveChild(ComponentPart part, ComponentPart childPart) { + WidgetDescriptor partDescriptor = descriptorManager.getWidgetDescriptor(part.getDescriptorId()); + WidgetDescriptor childPartDescriptor = descriptorManager.getWidgetDescriptor(childPart.getDescriptorId()); + if (partDescriptor != null && childPartDescriptor != null) { + + // getNumberOfChildByDescriptorId() + int number = 0; + { + Iterator itr = part.getChildren().iterator(); + while (itr.hasNext()) { + ComponentPart child = (ComponentPart) itr.next(); + if (child.getDescriptorId().equals(childPartDescriptor.getDescriptorId())) { + number++; + } + } + } + return partDescriptor.canRemoveChild(childPartDescriptor, number); + } else { + return false; + } + } + + public boolean isContainer(ComponentPart part) { + if (descriptorManager.getWidgetDescriptor(part.getDescriptorId()).getLayoutType() != null) { + return true; + } + return false; + } + + public List getEventParams(ComponentPart part, String id) { + List params = null; + for (EventDescriptor event : getEventDescriptors(part)) { + if (event.getEventName().equals(id)) { + params = event.getEventTypeDescriptor().getEventParameters(); + } + } + return params; + } + + public String getEventInfo(ComponentPart part, String id) { + String eventInfo = null; + for (EventDescriptor event : getEventDescriptors(part)) { + if (event.getEventName().equals(id)) { + eventInfo = event.getEventInfo(); + } + } + return eventInfo; + } + + public String getLayoutType(ComponentPart part) { + WidgetDescriptor desc = getPartComponentDescriptor(part); + if (desc != null) { + return desc.getLayoutType(); + } + return null; + } + + public String getMinWidth(ComponentPart part) { + WidgetDescriptor desc = getPartComponentDescriptor(part); + if (desc != null) { + return desc.getMinWidth(); + } + return null; + } + + public String getMinHeight(ComponentPart part) { + WidgetDescriptor desc = getPartComponentDescriptor(part); + if (desc != null) { + return desc.getMinHeight(); + } + return null; + } + + public String getFeedbackWidth(ComponentPart part) { + WidgetDescriptor desc = getPartComponentDescriptor(part); + if (desc != null) { + return desc.getFeedbackWidth(); + } + return null; + } + + public String getFeedbackHeight(ComponentPart part) { + WidgetDescriptor desc = getPartComponentDescriptor(part); + if (desc != null) { + return desc.getFeedbackHeight(); + } + return null; + } + + public String getIcon16(ComponentPart part) { + WidgetDescriptor desc = getPartComponentDescriptor(part); + if (desc != null) { + return desc.getIcon16(); + } + return null; + } + + public String getDisplayName(ComponentPart part) { + WidgetDescriptor desc = getPartComponentDescriptor(part); + if (desc != null) { + return desc.getDisplayName(); + } + return null; + } + + private WidgetDescriptor getPartComponentDescriptor(Part part) { + if (part != null && part.getDescriptorId() != null && descriptorManager.getWidgetDescriptor(part.getDescriptorId()) != null) { + return descriptorManager.getWidgetDescriptor(part.getDescriptorId()); + } + return null; + } + + public Collection getWidgetCategories() { + return descriptorManager.getWidgetCategories(); + } + + public List getWidgetDescriptorsOfCategory(String category) { + return descriptorManager.getWidgetDescriptorsOfCategory(category); + } + + public List getChildUIComponentPropertyDescriptors(String descriptorId) { + if (descriptorManager.getWidgetDescriptor(descriptorId) == null) { + return new ArrayList(); + } + return descriptorManager.getWidgetDescriptor(descriptorId).getChildUIComponentPropertyDescriptors(); + } + + public List getPropertyDescriptors(String parentDescriptorId, String descriptorId) { + List descriptors = new ArrayList(); + descriptors.addAll(descriptorManager.getWidgetDescriptor(descriptorId).getPropertyDescriptors()); + if (parentDescriptorId != null) { + descriptors.addAll(descriptorManager.getWidgetDescriptor(parentDescriptorId).getChildUIComponentPropertyDescriptors()); + } + return descriptors; + } + + public PropertyDescriptor getPropertyDescriptor(Part parent, ComponentPart part, String property) { + // property that has own properties + PropertyDescriptor propertyDescriptor = descriptorManager.getWidgetDescriptor(part.getDescriptorId()).getPropertyDescriptor(property); + if (propertyDescriptor != null) { + return propertyDescriptor; + } + + if (parent != null && parent instanceof ComponentPart) { + // property that has parent properties(like pack_x, pack_y...) + return descriptorManager.getWidgetDescriptor(parent.getDescriptorId()).getChildUIComponentPropertyDescriptor(property); + } + return null; + } + + public String getGuideText(ComponentPart part) { + WidgetDescriptor desc = getPartComponentDescriptor(part); + if (desc != null) { + return desc.getGuideText(); + } + return null; + } + + public List getConditions(ComponentPart part) { + return descriptorManager.getWidgetDescriptor(part.getDescriptorId()).getConditions(); + } + + public List getEventDescriptors(ComponentPart part) { + return descriptorManager.getWidgetDescriptor(part.getDescriptorId()).getEventDescriptors(); + } + + public DescriptorType getDescriptorType(String descriptorId) { + return descriptorManager.getWidgetDescriptor(descriptorId).getDescriptorType(); + } + + public Map getInitValues(ComponentPart parent, ComponentPart part) { + return getInitValues(getPropertyDescriptors(parent, part)); + } + + public List getPropertyDescriptors(ComponentPart parent, ComponentPart part) { + List descriptors = new ArrayList(); + if (part != null && part.getDescriptorId() != null && descriptorManager.getWidgetDescriptor(part.getDescriptorId()) != null) { + descriptors.addAll(descriptorManager.getWidgetDescriptor(part.getDescriptorId()).getPropertyDescriptors()); + if (parent != null && parent.getDescriptorId() != null && descriptorManager.getWidgetDescriptor(parent.getDescriptorId()) != null) { + descriptors.addAll(descriptorManager.getWidgetDescriptor(parent.getDescriptorId()).getChildUIComponentPropertyDescriptors()); + } + } + return descriptors; + } + + private Map getInitValues(List propertiesList) { + if (propertiesList == null) { + return new HashMap(); + } + + Map results = new HashMap(); + + for (PropertyDescriptor property : propertiesList) { + String name = property.getPropertyName(); + String value = null; + String type = property.getPropertyType(); + // TODO check why string or color2 does not use default value + if (TypeDescriptor.ID_OF_STRING.equals(type) || TypeDescriptor.ID_OF_COLOR2.equals(type)) { + value = ModelConstants.EMPTY; + } else { + value = property.getDefaultValue(); + } + String initValue = property.getInitValue(); + if (initValue != null) { + value = initValue; + } + + results.put(name, value); + } + + return results; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/ComponentValidator.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/ComponentValidator.java new file mode 100644 index 0000000..df87d57 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/ComponentValidator.java @@ -0,0 +1,968 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.util; + +import java.util.Iterator; +import java.util.List; + +import org.eclipse.osgi.util.NLS; +import org.tizen.efluibuilder.model.descriptors.ConditionDescriptor; +import org.tizen.efluibuilder.model.descriptors.ConstantDescriptor; +import org.tizen.efluibuilder.model.descriptors.PropertyConditionDescriptor; +import org.tizen.efluibuilder.model.descriptors.PropertyDescriptor; +import org.tizen.efluibuilder.model.descriptors.TypeDescriptor.Types; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.DocumentPart; +import org.tizen.efluibuilder.model.part.EventPart; +import org.tizen.efluibuilder.model.part.EventType; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.nl.BuilderMessages; + + +/** + * A Component validator. + */ +public class ComponentValidator { + + /** + * The OK string. + */ + public static final String OK = "ok"; //$NON-NLS-1$ + + /** + * The error string. + */ + public static final String ERROR = "error"; //$NON-NLS-1$ + + /** + * The string-id error key. + */ + private static final String ERROR_STRING_ID = "string-id"; //$NON-NLS-1$ + + /** + * The string-page-id error key. + */ + private static final String ERROR_STRING_PAGE_ID = "string-page-id"; //$NON-NLS-1$ + + /** + * The string-max-length error key. + */ + private static final String ERROR_STRING_MAX_LENGTH = "string-max-length"; //$NON-NLS-1$ + + /** + * The integer-min error key. + */ + private static final String ERROR_INTEGER_MIN = "integer-min"; //$NON-NLS-1$ + + /** + * The integer-min-by error key. + */ + private static final String ERROR_INTEGER_MIN_BY = "integer-min-by"; //$NON-NLS-1$ + + /** + * The integer-max error key. + */ + private static final String ERROR_INTEGER_MAX = "integer-max"; //$NON-NLS-1$ + + /** + * The integer-max-by error key. + */ + private static final String ERROR_INTEGER_MAX_BY = "integer-max-by"; //$NON-NLS-1$ + + /** + * The integer-max error key. + */ + private static final String ERROR_INTEGER_MIN_BY_PARENT_PROPERTY = "integer-min-by-parent-property"; //$NON-NLS-1$ + + /** + * The integer-max-by error key. + */ + private static final String ERROR_INTEGER_MAX_BY_PARENT_PROPERTY = "integer-max-by-parent-property"; //$NON-NLS-1$ + + /** + * The size-max error key. + */ + private static final String ERROR_SIZE_MAX = "size-max"; //$NON-NLS-1$ + + public String isValidName(String name) { + if (isCSyntaxReservedWord(name)) { + return BuilderMessages.ERROR_ID_EQUALS_RESERVED_WORD; + } + + if (!checkIdValue(name)) { + return BuilderMessages.ERROR_ID_INVALID_REGX; + } + return OK; + } + + /** + * Returns OK if property value can be set. + * + * @param part + * a {@link Part} + * @param propertyName + * a property name + * @param value + * a property value + * @return OK if property value can be set, and error message otherwise + */ + public String canSetPropertyValue(Part part, String propertyName, String value) { + return canSetPropertyValue(part, part.getParent(), propertyName, value); + } + + /** + * Returns OK if property value can be set. + * + * @param part + * a {@link Part} + * @param parent + * a part to be parent {@link Part} + * @param propertyName + * a property name + * @param value + * a property value + * @return OK if property value can be set, and error message otherwise + */ + private String canSetPropertyValue(Part part, Part parent, String propertyName, String value) { + if (part == null) { + // This case should not be happened. + return ERROR; + } + + ComponentDescriptor componentDescriptor = part.getOwnerDocumentPart().getComponentDescriptor(); + PropertyDescriptor desc = componentDescriptor.getPropertyDescriptor(parent, (ComponentPart) part, propertyName); + if (desc == null) { + // This case should not be happened. + return OK; + } + + Types type = desc.getTypeDescriptor().getType(); + switch (type) { + case INTEGER: + if (!checkIntegerValue(value)) { + return BuilderMessages.ERROR_INTEGER_VALUE; + } + + // FIXME + // workaround code to check input value range + // table padding_h/padding_v, gengrid item_size_w/item_size_h + if (!checkIntegerRange(value)) { + return BuilderMessages.ERROR_INTEGER_RANGE; + } + break; + case SCALE: + case DOUBLE: + if (!checkDoubleValue(value)) { + return BuilderMessages.ERROR_DOUBLE_VALUE; + } + break; + case STRING: + case RM_STRING: // for RM - localization + case BOOLEAN: + case SUB_VIEW: + case IMAGE: + case COLOR: + case COLOR2: + case DATE: + case TIME: + case AUDIO: + case VIDEO: + case HTMLSTRING: + case ENUM: + List items = desc.getTypeDescriptor().getAvailableConstant(); + for (ConstantDescriptor item : items) { + if (value.equals(item.getValue())) { + return OK; + } + } + break; + case CHECK_SCALE: + List check_scale_items = desc.getTypeDescriptor().getAvailableConstant(); + for (ConstantDescriptor item : check_scale_items) { + if (value.equals(item.getValue())) { + return OK; + } + } + if (!checkDoubleValue(value)) { + return BuilderMessages.ERROR_DOUBLE_VALUE; + } + break; + case UNKNOWN: + default: + break; + } + + String message = checkPropertyConditions(part, parent, desc.getConditionDescriptors(), value); + + return message; + } + + /** + * Returns OK if property value can be set. + * + * @param condition + * a {@link PropertyConditionDescriptor} + * @param value + * a property value + * @param comparerValue + * a comparer value + * @param displayName + * a display name of comparer property + * @return OK if property value can be set, and error message otherwise + */ + public String canSetPropertyValue(PropertyConditionDescriptor condition, String value, String comparerValue, String displayName) { + if (condition == null) { + // This case should not be happened. + return ERROR; + } + + String name = condition.getName(); + String error = condition.getError(); + if (name == null) { + // This case should not be happened. + return ERROR; + } + + if (name.equals(PropertyConditionDescriptor.INTEGER_MIN_BY)) { + if (!checkMinValue(value, comparerValue)) { + return NLS.bind(getErrorMessage(error), displayName); + } + } else if (name.equals(PropertyConditionDescriptor.INTEGER_MAX_BY)) { + if (!checkMaxValue(value, comparerValue)) { + return NLS.bind(getErrorMessage(error), displayName); + } + } + + return OK; + } + + /** + * Returns OK if value can be set. + * + * @param condition + * a {@link PropertyConditionDescriptor} + * @param value + * a style declaration value + * @return OK if style declaration value can be set, and error message otherwise + */ + public String canSetSizeStyleValue(PropertyConditionDescriptor condition, String value) { + if (condition == null || value.isEmpty()) { + return OK; + } + + String name = condition.getName(); + String conditionValue = condition.getValue(); + String error = condition.getError(); + if (name == null) { + return OK; + } + + String digitValue = ModelConstants.EMPTY; + StringBuffer buffer = new StringBuffer(); + + for (int i = 0; i < value.length(); i++) { + char c = value.charAt(i); + if (Character.isDigit(c) || c == '.' || c == '-' || c == '+') { + buffer.append(c); + } else { + break; + } + } + + digitValue = buffer.toString(); + + if (name.equals(PropertyConditionDescriptor.INTEGER_MIN)) { + if (!checkMinValue(digitValue, conditionValue)) { + return NLS.bind(getErrorMessage(error), conditionValue); + } + } else if (name.equals(PropertyConditionDescriptor.INTEGER_MAX)) { + if (!checkMaxValue(digitValue, conditionValue)) { + return NLS.bind(getErrorMessage(error), conditionValue); + } + } + + return OK; + } + + /** + * Returns OK if value can be set. + * + * @param descriptor + * a {@link PropertyDescriptor} + * @param value + * a style value + * @return OK if style value can be set, and error message otherwise + */ + public String canSetStyleDeclarationValue(PropertyDescriptor descriptor, String value) { + if (descriptor == null || value.isEmpty()) { + return OK; + } + Types type = descriptor.getTypeDescriptor().getType(); + switch (type) { + case SIZE: + case STYLE_FONT_SIZE: + case SIZE_PERCENT: + case SIZE_PIXEL: + case SIZE_ANGLE: + String message = checkSizeValue(value); + if ((message.equals(OK))) { + return checkSizeConditions(descriptor, value); + } else { + List items = descriptor.getTypeDescriptor().getAvailableConstant(); + for (ConstantDescriptor item : items) { + if (value.equals(item.getValue())) { + return OK; + } + } + return message; + } + case SIZE_REAL: + if (checkFloatValue(value)) { + return checkSizeConditions(descriptor, value); + } else { + return BuilderMessages.ERROR_STYLE_SIZE_NUMBER; + } + case INTEGER: + if (!checkIntegerValue(value)) { + return BuilderMessages.ERROR_INTEGER_VALUE; + } + break; + case SIZE_INTEGER: + if (checkIntegerValue(value)) { + return checkSizeConditions(descriptor, value); + } else { + List items = descriptor.getTypeDescriptor().getAvailableConstant(); + for (ConstantDescriptor item : items) { + if (value.equals(item.getValue())) { + return OK; + } + } + return BuilderMessages.ERROR_STYLE_SIZE_NUMBER; + } + case STRING: + if (!checkStringValue(value)) { + return BuilderMessages.ERROR_STRING_VALUE; + } + break; + case BOOLEAN: + case SUB_VIEW: + case IMAGE: + case COLOR: + case COLOR2: + case DATE: + case TIME: + case AUDIO: + case VIDEO: + case HTMLSTRING: + case ENUM: + case UNKNOWN: + default: + break; + } + + return OK; + } + + private String checkSizeConditions(PropertyDescriptor descriptor, String value) { + String message = OK; + + List conditions = descriptor.getConditionDescriptors(); + + for (PropertyConditionDescriptor condition : conditions) { + message = canSetSizeStyleValue(condition, value); + if (!(message.equals(OK))) { + return message; + } + } + return message; + } + + /** + * Returns OK if property condition is valid. + * + * @param part + * a {@link Part} + * @param parent + * a part to be parent {@link Part} + * @param conditions + * a List containing {@link ConditionDescriptor} + * @param value + * a property value to check validity + * @return OK if property condition is valid, and error message otherwise + */ + private String checkPropertyConditions(Part part, Part parent, List conditions, String value) { + if (conditions == null) { + // This case should not be happened. + return ERROR; + } + + int size = conditions.size(); + if (size == 0) { + return OK; + } + + for (int i = 0; i < size; i++) { + String message = checkPropertyCondition(part, parent, conditions.get(i), value); + if (message != OK) { + return message; + } + } + + return OK; + } + + /** + * Returns OK if property condition is valid. + * + * @param part + * a {@link Part} + * @param parent + * a part to be parent {@link Part} + * @param condition + * a {@link ConditionDescriptor} + * @param value + * a property value to check validity + * @return OK if property condition is valid, and error message otherwise + */ + private String checkPropertyCondition(Part part, Part parent, PropertyConditionDescriptor condition, String value) { + if (part == null || condition == null || value == null) { + // This case should not be happened. + return ERROR; + } + + String name = condition.getName(); + + String error = condition.getError(); + + if (name.equals(PropertyConditionDescriptor.STRING_ID)) { + // 150408: added by sonbc121: implementation for C Standard Styled Widget ID====// + // true if value is a C language syntax word, and false otherwise + if (isCSyntaxReservedWord(value)) + return BuilderMessages.ERROR_ID_EQUALS_RESERVED_WORD; + + // 150408: modified by sonbc121: implementation for C Standard Styled Widget ID====// + if (!checkIdValue(value)) { + return BuilderMessages.ERROR_ID_INVALID_REGX; + } + + Part docPart = null; + // Part pagePart = null; + + if (parent != null) { + docPart = (part instanceof DocumentPart) ? part : parent.getOwnerDocumentPart(); + // pagePart = (part.isViewPart()) ? part : parent.getOwnerPage(); + } else { + docPart = part.getOwnerDocumentPart(); + // pagePart = part.getOwnerPage(); + } + + if (docPart != null) { + if (!searchUsedPropertyValue(part, docPart, ModelConstants.PROPERTY_ID, value)) { + return getErrorMessage(error); + } + } + + // if (pagePart != null) { + // if (!searchUsedPropertyValue(part, pagePart, Constants.PROPERTY_ID, value, + // true)) { + // return getErrorMessage(error); + // } + // } + } else if (name.equals(PropertyConditionDescriptor.STRING_MAX_LENGTH)) { + String conditionValue = condition.getValue(); + int length = Long.valueOf(conditionValue).intValue(); + + if (value.length() > length) { + return NLS.bind(getErrorMessage(error), conditionValue); + } + } else if (name.equals(PropertyConditionDescriptor.INTEGER_MIN)) { + String conditionValue = condition.getValue(); + + if (!checkMinValue(value, conditionValue)) { + return NLS.bind(getErrorMessage(error), conditionValue); + } + } else if (name.equals(PropertyConditionDescriptor.INTEGER_MAX)) { + String conditionValue = condition.getValue(); + + if (!checkMaxValue(value, conditionValue)) { + return NLS.bind(getErrorMessage(error), conditionValue); + } + } else if (name.equals(PropertyConditionDescriptor.INTEGER_MIN_BY_PARENT_PROPERTY)) { + String conditionValue = condition.getTargetValue(); + + if (!checkMinValueByParentProperty(part, value, conditionValue)) { + return NLS.bind(getErrorMessage(error), conditionValue); + } + } else if (name.equals(PropertyConditionDescriptor.INTEGER_MAX_BY_PARENT_PROPERTY)) { + String conditionValue = condition.getTargetValue(); + + if (!checkMaxValueByParentProperty(part, value, conditionValue)) { + return NLS.bind(getErrorMessage(error), conditionValue); + } + } else if (name.equals(PropertyConditionDescriptor.SIZE_MAX)) { + String conditionValue = condition.getValue(); + String conditionTargetValue = condition.getTargetValue(); + + if (!checkMaxSize(part, value, conditionTargetValue, conditionValue)) { + return NLS.bind(getErrorMessage(error), conditionValue); + } + } + + return OK; + } + + /** + * Returns an error message corresponding to the key. + * + * @param key + * the key + * @return error message + */ + private String getErrorMessage(String key) { + if (key == null || key.equals(ModelConstants.EMPTY)) { + // This case should not be happened. + return ERROR; + } + + if (key.equals(ERROR_STRING_ID)) { + return BuilderMessages.ERROR_STRING_ID; + } else if (key.equals(ERROR_STRING_PAGE_ID)) { + return BuilderMessages.ERROR_STRING_PAGE_ID; + } else if (key.equals(ERROR_STRING_MAX_LENGTH)) { + return BuilderMessages.ERROR_STRING_MAX_LENGTH; + } else if (key.equals(ERROR_INTEGER_MIN)) { + return BuilderMessages.ERROR_INTEGER_MIN; + } else if (key.equals(ERROR_INTEGER_MIN_BY)) { + return BuilderMessages.ERROR_INTEGER_MIN_BY; + } else if (key.equals(ERROR_INTEGER_MAX)) { + return BuilderMessages.ERROR_INTEGER_MAX; + } else if (key.equals(ERROR_INTEGER_MAX_BY)) { + return BuilderMessages.ERROR_INTEGER_MAX_BY; + } else if (key.equals(ERROR_INTEGER_MIN_BY_PARENT_PROPERTY)) { + return BuilderMessages.ERROR_INTEGER_MIN_BY_PARENT_PROPERTY; + } else if (key.equals(ERROR_INTEGER_MAX_BY_PARENT_PROPERTY)) { + return BuilderMessages.ERROR_INTEGER_MAX_BY_PARENT_PROPERTY; + } else if (key.equals(ERROR_SIZE_MAX)) { + return BuilderMessages.ERROR_SIZE_MAX; + } + + // This case should not be happened. + return ERROR; + } + + /** + * Checks that value is an integer. + * + * @param value + * a property value + * @return true if value is an integer, and false otherwise + */ + private boolean checkIntegerValue(String value) { + if (value != null && value.matches(ModelConstants.INTEGERVALUE)) { + return true; + } else { + return false; + } + } + + private boolean checkIntegerRange(String value) { + if (value == null) { + return false; + } + double doubleValue = Double.parseDouble(value); + if ((Integer.MIN_VALUE <= doubleValue) && (doubleValue <= Integer.MAX_VALUE)) { + return true; + } else { + return false; + } + } + + private boolean checkDoubleValue(String value) { + if (value != null && value.matches(ModelConstants.FLOATVALUE)) { + return true; + } else { + return false; + } + } + + /** + * Checks that value is a proper string. + * + * @param value + * a property value + * @return true if value is a proper string, and false otherwise + */ + private boolean checkStringValue(String value) { + if (value != null && value.matches(ModelConstants.REGULAREXPRESSION)) { + return true; + } else { + return false; + } + } + + /** + * Checks that value is a proper ID. + * + * @param value + * an ID value + * @return true if value is a ID, and false otherwise + */ + private boolean checkIdValue(String value) { + if (value != null && value.matches(ModelConstants.ID_PATTERN)) { + return true; + } else { + return false; + } + } + + // ====[START]== 150407: added by sonbc121: implementation for C Standard Styled Widget ID====// + + private final String[] mstrArrayReservedKeywords = new String[] { // 45 + // == type ==// + "auto", "_Bool", "char", "_Complex", "const", "double", "enum", "extern", "float", // 24 + "int", "long", "register", "restrict", "short", "signed", "static", "struct", "typedef", "union", "unsigned", "void", "volatile", "NULL", "errno", + + // == predefine macro ==// + "__TIME__", "__DATE__", "__FILE__", "__LINE__", "__VA_ARGS__", "__FUNCTION__", // 6 + + // == C syntax ==// + "break", "case", "continue", "default", "do", "else", "for", "goto", "if", // 15 + "_Imaginary", // Complex data type + "inline", "return", "sizeof", "switch", "while" }; + + /** + * Checks that value is a proper ID by C language style. + * + * @param value + * an ID value + * @return true if value is a C language syntax word, and false otherwise + */ + private boolean isCSyntaxReservedWord(String strIdValue) { + strIdValue = strIdValue.trim(); + for (int iIdx = 0; iIdx < mstrArrayReservedKeywords.length; iIdx++) { + if (strIdValue.equals(mstrArrayReservedKeywords[iIdx])) { + return true; + } + } + return false; + } + + // ====[END]== 150407: added by sonbc121: implementation for C Standard Styled Widget ID====// + + private boolean searchUsedPropertyValue(Part myselfPart, Part part, String propertyName, String value) { + if (myselfPart == null || part == null) { + return false; + } + + Iterator itr = part.getChildren().iterator(); + List children = null; + while (itr.hasNext()) { + Part childPart = itr.next(); + if (!myselfPart.equals(childPart)) { + String propertyValue = childPart.getPropertyValue(propertyName); + if (propertyValue != null && propertyValue.equals(value)) { + return false; + } + } + + children = childPart.getChildren(); + if (children != null) { + if (!searchUsedPropertyValue(myselfPart, childPart, propertyName, value)) { + return false; + } + } + } + + return true; + } + + public int searchUsedEventValue(Part part, String value) { + int count = 0; + Part pagepart = ((ComponentPart) part).getOwnerViewPart(); + if (pagepart != null) { + count = searchUsedValue(pagepart, value); + } + + return count; + } + + private int searchUsedValue(Part part, String value) { + int refCount = 0; + List eventParts = ((ComponentPart) part).getEventParts(); + + for (EventPart event : eventParts) { + if (event.getEventType() == EventType.RUN_JAVASCRIPT_FUNCTION) { + String eventName = event.getPropertyValue(LayoutSchemaConstants.EVENT_FUNCTION_NAME); + if (value.equals(eventName)) + refCount++; + } + } + + for (Part child : part.getChildren()) { + refCount += searchUsedValue(child, value); + } + return refCount; + } + + public int getUsedEventNameCount(Part part, String value) { + int count = 0; + if (!(part instanceof ComponentPart)) { + return count; + } + Part viewPart = ((ComponentPart) part).getOwnerViewPart(); + if (viewPart != null) { + count = searchUsedEventName(viewPart, value); + } + + return count; + } + + private int searchUsedEventName(Part part, String value) { + int refCount = 0; + List children = part.getChildren(); + + for (Part child : children) { + if (child instanceof EventPart) { + String eventFunName = child.getPropertyValue(LayoutSchemaConstants.EVENT_FUNCTION_NAME); + if (value.equals(eventFunName)) { + refCount++; + } + } + refCount += searchUsedEventName(child, value); + } + + return refCount; + } + + /** + * Checks that value is less than minValue. + * + * @param part + * + * @param value + * an integer property value + * @param minValue + * a minimum value + * @return true if value is less than minValue, and false otherwise + */ + public boolean checkMinValueByParentProperty(Part part, String value, String minValue) { + if (part == null || value == null || value.isEmpty() || minValue == null || minValue.isEmpty()) { + return false; + } + int val = Integer.valueOf(value); + int min = 0; + ComponentDescriptor componentDescriptor = part.getOwnerDocumentPart().getComponentDescriptor(); + List parentProperties = + componentDescriptor.getPropertyDescriptors((ComponentPart) part.getParent().getParent(), (ComponentPart) part.getParent()); + for (PropertyDescriptor property : parentProperties) { + if (property.getPropertyName().equals(minValue)) { + String parentProperty = part.getPropertyValue(minValue); + min = Integer.valueOf(parentProperty); + } + } + + if (val <= min) { + return false; + } + + return true; + } + + /** + * Checks that value is more than maxValue. + * + * @param part + * + * @param value + * an integer property value + * @param maxValue + * a maximum value + * @return true if value is more than maxValue, and false otherwise + */ + public boolean checkMaxValueByParentProperty(Part part, String value, String maxValue) { + if (part == null || value == null || value.isEmpty() || maxValue == null || maxValue.isEmpty()) { + return false; + } + int val = Integer.valueOf(value); + int max = 0; + ComponentDescriptor componentDescriptor = part.getOwnerDocumentPart().getComponentDescriptor(); + List parentProperties = + componentDescriptor.getPropertyDescriptors((ComponentPart) part.getParent().getParent(), (ComponentPart) part.getParent()); + for (PropertyDescriptor property : parentProperties) { + if (property.getPropertyName().equals(maxValue)) { + String parentProperty = part.getParent().getPropertyValue(maxValue); + if (parentProperty != null) { + max = Integer.valueOf(parentProperty); + } + } + } + + if (val >= max) { + return false; + } + + return true; + } + + /** + * Checks that value is less than minValue. + * + * @param value + * an integer property value + * @param minValue + * a minimum value + * @return true if value is less than minValue, and false otherwise + */ + public boolean checkMinValue(String value, String minValue) { + if (value == null || value.isEmpty() || minValue == null || minValue.isEmpty()) { + return false; + } + float val = Float.valueOf(value); + float min = Float.valueOf(minValue); + + if (val < min) { + return false; + } + + return true; + } + + /** + * Checks that value is more than maxValue. + * + * @param value + * an integer property value + * @param maxValue + * a maximum value + * @return true if value is more than maxValue, and false otherwise + */ + public boolean checkMaxValue(String value, String maxValue) { + if (value == null || value.isEmpty() || maxValue == null || maxValue.isEmpty()) { + return false; + } + float val = Float.valueOf(value); + float min = Float.valueOf(maxValue); + + if (val > min) { + return false; + } + + return true; + } + + /** + * Checks that value is more than maxValue. + * + * @param part + * + * @param value + * an integer property value + * @param value + * an integer property value + * @param maxValue + * a maximum value + * @return true if value is more than maxValue, and false otherwise + */ + public boolean checkMaxSize(Part part, String value, String conditionTargetValue, String conditionValue) { + if (part == null || value == null || value.isEmpty() || conditionTargetValue == null || conditionTargetValue.isEmpty() || conditionValue == null + || conditionValue.isEmpty()) { + return false; + } + int val = Integer.valueOf(value); + int maxContainerSize = 0; + int currentPosition = 0; + + ComponentDescriptor componentDescriptor = part.getOwnerDocumentPart().getComponentDescriptor(); + List properties = + componentDescriptor.getPropertyDescriptors((ComponentPart) part.getParent().getParent(), (ComponentPart) part.getParent()); + for (PropertyDescriptor property : properties) { + if (property.getPropertyName().equals(conditionTargetValue)) { + String parentProperty = part.getParent().getPropertyValue(conditionTargetValue); + if (parentProperty != null) { + maxContainerSize = Integer.valueOf(parentProperty); + } + } + } + + properties = componentDescriptor.getPropertyDescriptors((ComponentPart) part.getParent(), (ComponentPart) part); + for (PropertyDescriptor property : properties) { + if (property.getPropertyName().equals(conditionValue)) { + String parentProperty = part.getPropertyValue(conditionValue); + if (parentProperty != null) { + currentPosition = Integer.valueOf(parentProperty); + } + } + } + + if (val > (maxContainerSize - (currentPosition))) { + return false; + } + + return true; + } + + private String checkSizeValue(String value) { + if (value == null) { + // This case should not be happened. + return ERROR; + } + + String message = OK; + + if (!value.matches(ModelConstants.SIZEVALUE)) { + String number = ModelConstants.EMPTY; + String unit = ModelConstants.EMPTY; + StringBuffer buffer = new StringBuffer(); + + for (int i = 0; i < value.length(); i++) { + char c = value.charAt(i); + if (Character.isDigit(c) || c == '.') { + buffer.append(c); + } else { + number = buffer.toString(); + unit = value.substring(i); + break; + } + } + + if (number.isEmpty()) { + message = BuilderMessages.ERROR_STYLE_SIZE_NUMBER; + } else { + if (!unit.matches(ModelConstants.UNITPATTERN)) { + message = BuilderMessages.ERROR_STYLE_SIZE_UNIT; + } else { + // This case should not be happened. + message = ERROR; + } + } + } + + return message; + } + + private boolean checkFloatValue(String value) { + return value.matches(ModelConstants.FLOATVALUE); + } + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/DBPartUnmarshaller.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/DBPartUnmarshaller.java new file mode 100644 index 0000000..efafe1e --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/DBPartUnmarshaller.java @@ -0,0 +1,103 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.model.util; + +import org.tizen.efluibuilder.model.part.DataBindingPart; +import org.tizen.efluibuilder.model.part.DocumentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingData; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingObject; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public final class DBPartUnmarshaller { + public Part unmarshall(Part rootPart, Document document, boolean bAssign) { + return writePartbyElement(document.getDocumentElement(), rootPart, null, bAssign, bAssign); + } + + public Part unmarshallForUpdate(Part rootPart, Document document) { + return writePartbyElement(document.getDocumentElement(), rootPart, null, true, false); + } + + private Part writePartbyElement(Element element, Part rootPart, Part parentPart, boolean bAssignElementToPart, boolean bAssignPartToElement) { + String tagName = element.getTagName(); + + Part part = null; + + if (tagName.equals(LayoutSchemaConstants.DATABINDING)) { + if (parentPart == null || parentPart instanceof DocumentPart) { + if (rootPart == null) { + rootPart = PartUtil.createPart(PartType.DATABINDING, tagName); + } + part = rootPart; + } + } else if (tagName.equals(LayoutSchemaConstants.DATASOURCE)) { + if (parentPart == null || parentPart instanceof DataBindingPart) { + part = PartUtil.createPart(PartType.DATASOURCE, tagName); + } + } else if (tagName.equals(LayoutSchemaConstants.DATAMODEL)) { + if (parentPart == null || parentPart instanceof DataBindingPart) { + part = PartUtil.createPart(PartType.DATAMODEL, tagName); + } + } else if (tagName.equals(LayoutSchemaConstants.BINDINGOBJECT)) { + if (parentPart == null || parentPart instanceof BindingData || parentPart instanceof BindingObject) { + part = PartUtil.createPart(PartType.BINDINGOBJECT, tagName); + } + } + + if (part == null) + return null; + + NamedNodeMap attrList = element.getAttributes(); + for (int i = 0; i < attrList.getLength(); i++) { + Attr attr = (Attr) attrList.item(i); + part.setPropertyValue(attr.getName(), attr.getValue()); + } + + NodeList nodes = element.getChildNodes(); + for (int i = 0; i < nodes.getLength(); i++) { + Node child = nodes.item(i); + if (child instanceof Element) { + Part childPart = writePartbyElement((Element) child, rootPart, part, bAssignElementToPart, bAssignPartToElement); + if (childPart != null) { + childPart.setParent(part); + part.insertChildBefore(childPart, null); + } + } + } + + if (bAssignElementToPart) { + part.setElement(element); + } + + if (bAssignPartToElement) { + element.setUserData(ModelConstants.ELEMENT_UD_PART_KEY, part, null); + } + return part; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/IDGenerator.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/IDGenerator.java new file mode 100644 index 0000000..00e8f83 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/IDGenerator.java @@ -0,0 +1,119 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.util; + +import java.util.HashMap; +import java.util.Map; + +import org.tizen.efluibuilder.model.part.Part; + + +public class IDGenerator { + private Map maxIDs = new HashMap(); + + public void update(Part part) { + updateMaxID(part); + } + + public void clear() { + maxIDs.clear(); + } + + public void updateID(String id) { + if (id == null) { + return; + } + + // seperate number and strings from id + String number = getNumber(id); + String text = getText(id, number); + if (text == null) { + return; + } + int index = 0; + try { + index = Integer.parseInt(number); + } catch (NumberFormatException e) { + // This exception does not effect seriously in this case + return; + } + + Integer integer = maxIDs.get(text); + if (integer == null || index > integer.intValue()) { + maxIDs.put(text, Integer.valueOf(index)); + } + } + + private void updateMaxID(Part part) { + for (Part child : part.getChildren()) { + updateID(child.getPropertyValue("id")); + updateMaxID(child); + } + } + + private String getNumber(String id) { + String str = id.replaceAll("[^-?0-9]+", ","); + + String[] results = str.trim().split(","); + if (results.length == 0) { + return null; + } + + return results[results.length - 1]; + } + + private String getText(String id, String number) { + if (id == null || id.isEmpty()) { + return null; + } + + if (number == null || number.isEmpty()) { + return id; + } + + int lastIndex = id.lastIndexOf(number); + if (lastIndex >= id.length()) { + return null; + } + + return id.substring(0, lastIndex); + } + + public String getID(String descriptorId) { + if (descriptorId == null) { + return null; + } + + int id; + Integer maxID = maxIDs.get(descriptorId); + if (maxID == null) { + id = 1; + } else { + id = maxID.intValue() + 1; + } + + maxIDs.put(descriptorId, Integer.valueOf(id)); + return descriptorId + String.valueOf(id); + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/LayoutSchemaConstants.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/LayoutSchemaConstants.java new file mode 100644 index 0000000..99adec0 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/LayoutSchemaConstants.java @@ -0,0 +1,160 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.util; + +public class LayoutSchemaConstants { + + // document + public static final String DOCUMENT = "document"; //$NON-NLS-1$ + + // view + public static final String VIEWS = "views"; //$NON-NLS-1$ + public static final String VIEW = "view"; //$NON-NLS-1$ + public static final String STARTUP = "startup"; //$NON-NLS-1$ + public static final String VIEWID = "viewId"; //$NON-NLS-1$ + public static final String DEVICE = "device"; //$NON-NLS-1$ + public static final String NAME = "name"; //$NON-NLS-1$ + public static final String TYPE = "type"; //$NON-NLS-1$ + + // databinding + public static final String DATABINDING = "dataBinding"; //$NON-NLS-1$ + public static final String DATASOURCE = "dataSource"; //$NON-NLS-1$ + public static final String DATAMODEL = "dataModel"; //$NON-NLS-1$ + public static final String BINDINGOBJECT = "observableObject"; //$NON-NLS-1$ + + // widget & element + public static final String BG = "bg"; //$NON-NLS-1$ + public static final String BOX = "box"; //$NON-NLS-1$ + public static final String BUTTON = "button"; //$NON-NLS-1$ + public static final String CALENDAR = "calendar"; //$NON-NLS-1$ + public static final String CHECK = "check"; //$NON-NLS-1$ + public static final String COLORSELECTOR = "colorselector"; //$NON-NLS-1$ + public static final String CTXPOPUP = "ctxpopup"; //$NON-NLS-1$ + public static final String CTXPOPUPITEM = "ctxpopupitem"; //$NON-NLS-1$ + public static final String DATETIME = "datetime"; //$NON-NLS-1$ + public static final String ENTRY = "entry"; //$NON-NLS-1$ + public static final String FLIPSELECTOR = "flipselector"; //$NON-NLS-1$ + public static final String FLIPSELECTORITEM = "flipselectoritem"; //$NON-NLS-1$ + public static final String GENGRID = "gengrid"; //$NON-NLS-1$ + public static final String GENGRIDITEM = "gengriditem"; //$NON-NLS-1$ + public static final String GENLIST = "genlist"; //$NON-NLS-1$ + public static final String GENLISTITEM = "genlistitem"; //$NON-NLS-1$ + public static final String GRID = "grid"; //$NON-NLS-1$ + public static final String GROUP = "group"; //$NON-NLS-1$ + public static final String HOVERSEL = "hoversel"; //$NON-NLS-1$ + public static final String HOVERSELITEM = "hoverselitem"; //$NON-NLS-1$ + public static final String ICON = "icon"; //$NON-NLS-1$ + public static final String IMAGE = "image"; //$NON-NLS-1$ + public static final String INDEX = "index"; //$NON-NLS-1$ + public static final String INDEXITEM = "indexitem"; //$NON-NLS-1$ + public static final String LABEL = "label"; //$NON-NLS-1$ + public static final String LAYOUT = "layout"; //$NON-NLS-1$ + public static final String LIST = "list"; //$NON-NLS-1$ + public static final String LISTITEM = "listitem"; //$NON-NLS-1$ + public static final String MAP = "map"; //$NON-NLS-1$ + public static final String MULTIBUTTONENTRY = "multibuttonentry"; //$NON-NLS-1$ + public static final String MULTIBUTTONENTRYITEM = "multibuttonentryitem"; //$NON-NLS-1$ + public static final String PANEL = "panel"; //$NON-NLS-1$ + public static final String PANES = "panes"; //$NON-NLS-1$ + public static final String POPUP = "popup"; //$NON-NLS-1$ + public static final String PROGRESSBAR = "progressbar"; //$NON-NLS-1$ + public static final String RADIO = "radio"; //$NON-NLS-1$ + public static final String RECT = "rect"; //$NON-NLS-1$ + public static final String SCROLLER = "scroller"; //$NON-NLS-1$ + public static final String SLIDER = "slider"; //$NON-NLS-1$ + public static final String SPINNER = "spinner"; //$NON-NLS-1$ + public static final String TABLE = "table"; //$NON-NLS-1$ + public static final String TOOLBAR = "toolbar"; //$NON-NLS-1$ + public static final String TOOLBARITEM = "toolbaritem"; //$NON-NLS-1$ + public static final String DOC = "doc"; //$NON-NLS-1$ + public static final String MSCREEN = "mscreen"; //$NON-NLS-1$ + public static final String CONFIGURATION = "configuration"; //$NON-NLS-1$ + public static final String VARIATION = "variation"; //$NON-NLS-1$ + public static final String ID = "id"; //$NON-NLS-1$ + + // property + // common + public static final String ALIGN_H_FILL = "fill"; + public static final String TEXT = "text"; + public static final String SUB_LABEL = "sub-label"; + + public static final String GRID_VSIZE_W = "vsize_w"; //$NON-NLS-1$ + public static final String GRID_VSIZE_H = "vsize_h"; //$NON-NLS-1$ + public static final String GRID_PACK_X = "pack_x"; //$NON-NLS-1$ + public static final String GRID_PACK_Y = "pack_y"; //$NON-NLS-1$ + public static final String GRID_PACK_W = "pack_w"; //$NON-NLS-1$ + public static final String GRID_PACK_H = "pack_h"; //$NON-NLS-1$ + + public static final String TABLE_COLS = "cols"; //$NON-NLS-1$ + public static final String TABLE_ROWS = "rows"; //$NON-NLS-1$ + public static final String TABLE_PACK_COL = "pack_col"; //$NON-NLS-1$ + public static final String TABLE_PACK_ROW = "pack_row"; //$NON-NLS-1$ + public static final String TABLE_COL_SPAN = "col_span"; //$NON-NLS-1$ + public static final String TABLE_ROW_SPAN = "row_span"; //$NON-NLS-1$ + + public static final String PANES_PACK = "pack"; //$NON-NLS-1$ + public static final String DIRECTION = "direction"; //$NON-NLS-1$ + public static final String VISIBLE = "visible"; //$NON-NLS-1$ + + public static final String SRC = "src"; //$NON-NLS-1$ + public static final String IMAGE_PATH = "image_path"; //$NON-NLS-1$ + public static final String STYLE = "style"; //$NON-NLS-1$ + + public static final String COLORS = "colors"; //$NON-NLS-1$ + + // event + public static final String EVENT = "event"; //$NON-NLS-1$ + public static final String EVENT_SIGNAL = "signal"; //$NON-NLS-1$ + public static final String EVENT_NAME = "event_name"; //$NON-NLS-1$ + public static final String EVENT_FUNCTION_NAME = "function_name"; //$NON-NLS-1$ + public static final String EVENT_TARGET = "target"; //$NON-NLS-1$ + public static final String EVENT_CONNECTION = "connection_wrapper"; //$NON-NLS-1$ + + // value + public static final String TRUE = "true"; //$NON-NLS-1$ + public static final String FALSE = "false"; //$NON-NLS-1$ + public static final String PANES_PACK_LEFT = "left"; //$NON-NLS-1$ + public static final String PANES_PACK_RIGHT = "right"; //$NON-NLS-1$ + public static final String BOX_DIRECTION_HORIZONTAL = "horizontal"; //$NON-NLS-1$ + public static final String BOX_DIRECTION_VERTICAL = "vertical"; //$NON-NLS-1$ + + // configure + public static final String ORIENTATION = "orientation"; //$NON-NLS-1$ + public static final String CONFIGURATION_TYPE_COMMON = "common"; //$NON-NLS-1$ + public static final String CONFIGURATION_TYPE_SPECIFIC = "specific"; //$NON-NLS-1$ + public static final String CONFIGURATION_ID_PREFIX = "config"; //$NON-NLS-1$ + public static final String CONFIGURATION_REFERENCE = "config_ref"; //$NON-NLS-1$ + + // variation properties + public static final String[] GRID_PACK_PROPERTIES = { GRID_PACK_X, GRID_PACK_Y, GRID_PACK_W, GRID_PACK_H }; + public static final String[] TABLE_PACK_PROPERTIES = { TABLE_PACK_COL, TABLE_PACK_ROW, TABLE_COL_SPAN, TABLE_ROW_SPAN }; + public static final String[] PANES_PACK_PROPERTIES = { PANES_PACK }; + public static final String[] VARIATION_PROPERTIES = + { GRID_PACK_X, GRID_PACK_Y, GRID_PACK_W, GRID_PACK_H, TABLE_PACK_COL, TABLE_PACK_ROW, TABLE_COL_SPAN, TABLE_ROW_SPAN, PANES_PACK, VISIBLE }; + + // page location + public static final String PAGE_LOCATION_X = "page_location_x"; + public static final String PAGE_LOCATION_Y = "page_location_y"; + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/ModelConstants.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/ModelConstants.java new file mode 100644 index 0000000..e61ad1f --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/ModelConstants.java @@ -0,0 +1,76 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.util; + +public final class ModelConstants { + + public static final String EMPTY = ""; + public static final String ASTERISK = "*"; + public static final String COMMA = ","; + + public static final String ELEMENT_UD_PART_KEY = "part"; + public static final String PROJECT_FILE = ".uproject"; + public static final String SHAPE_SQUARE = "square"; + public static final String SHAPE_CIRCLE = "circle"; + + // part & element + public static final String PART_DOC = "doc"; + public static final String PART_VIEW = "view"; + public static final String PART_VARIATION = "variation"; //$NON-NLS-1$ + public static final String PART_MSCREEN = "mscreen"; //$NON-NLS-1$ + public static final String PART_CONFIGURATION = "configuration"; //$NON-NLS-1$ + + // property & attribute + public static final String PROPERTY_ID = "id"; //$NON-NLS-1$ + public static final String PROPERTY_VSIZE_W = "vsize_w"; //$NON-NLS-1$ + public static final String PROPERTY_VSIZE_H = "vsize_h"; //$NON-NLS-1$ + public static final String CONFIGURATION_REFERENCE = "config_ref"; //$NON-NLS-1$ + + // property & attribute value + public static final String CONFIGURATION_TYPE_COMMON = "common"; //$NON-NLS-1$ + public static final String CONFIGURATION_TYPE_SPECIFIC = "specific"; //$NON-NLS-1$ + public static final String CONFIGURATION_NAME = "name"; //$NON-NLS-1$ + public static final String CONFIGURATION_TYPE = "type"; //$NON-NLS-1$ + public static final String CONFIGURATION_ID = "id"; //$NON-NLS-1$ + public static final String CONFIGURATION_ID_PREFIX = "config"; //$NON-NLS-1$ + + // Component Validator + public static final String REGULAREXPRESSION = "^[a-zA-Z]+[a-zA-Z0-9_]*$"; //$NON-NLS-1$ + public static final String ID_PATTERN = "^[a-zA-Z_]+[a-zA-Z0-9_]*$"; //$NON-NLS-1$ , 150407: + // updated by sonbc121: + // implementation for C + // Standard Styled Widget + // ID (Added under bar) + public static final String INTEGERVALUE = "^[0-9-]?+[0-9]*$"; //$NON-NLS-1$ + public static final String FLOATVALUE = "^[-]?\\d*(\\.?\\d*)$"; //$NON-NLS-1$ + public static final String SIZEVALUE = "^[0-9-]+[.?0-9]*(?:px|%|cm|em|deg)$"; //$NON-NLS-1$ + public static final String UNITPATTERN = "(px|%|cm|em)?$"; //$NON-NLS-1$ + // StoryBoard_START + public static final String PROPERTY_LOCATION_X = "location_x"; //$NON-NLS-1$ + public static final String PROPERTY_LOCATION_Y = "location_y"; //$NON-NLS-1$ + // StoryBoard_END + + public static final String KEY_WIDGET_NAVIFRAME = "efl.naviframe"; + public static final String KEY_PART_VIEW = "tizen.view"; +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/PartMarshaller.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/PartMarshaller.java new file mode 100644 index 0000000..fc56280 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/PartMarshaller.java @@ -0,0 +1,139 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.util; + +import java.util.Map.Entry; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.tizen.efluibuilder.model.descriptors.PropertyDescriptor; +import org.tizen.efluibuilder.model.descriptors.PropertyDescriptor.UnusedEditors; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.DocumentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + + +public final class PartMarshaller { + + public Document marshall(Part part) { + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = null; + try { + builder = documentBuilderFactory.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + } + // write document node + if (builder != null) { + Document document = builder.newDocument(); + + Element element = writeElementbyPart(document, part); + document.appendChild(element); + return document; + } + return null; + } + + public Element marshall(Document document, Part part) { + return writeElementbyPart(document, part); + } + + private String getTagName(Part part) { + switch (part.getType()) { + case PartType.DOCUMENT: + return LayoutSchemaConstants.DOCUMENT; + case PartType.CONFIGURATION: + return LayoutSchemaConstants.CONFIGURATION; + case PartType.VIEW: + return LayoutSchemaConstants.VIEW; + case PartType.EVENT: + return LayoutSchemaConstants.EVENT; + case PartType.VARIATION: + return LayoutSchemaConstants.VARIATION; + case PartType.MSCREEN: + return LayoutSchemaConstants.MSCREEN; + case PartType.VIEWS: + return LayoutSchemaConstants.VIEWS; + case PartType.COMPONENT: + return ((ComponentPart) part).getDescriptorId(); + case PartType.DATABINDING: + return part.getDescriptorId(); + case PartType.DATASOURCE: + return part.getDescriptorId(); + case PartType.DATAMODEL: + return part.getDescriptorId(); + case PartType.BINDINGOBJECT: + return part.getDescriptorId(); + default: + break; + } + + return null; + } + + private Element writeElementbyPart(Document document, Part part) { + String tagName = getTagName(part); + Element element = null; + + if (tagName != null) + element = document.createElement(tagName); + + ComponentDescriptor componentDescriptor = null; + DocumentPart documentPart = part.getOwnerDocumentPart(); + if (documentPart != null) { + componentDescriptor = documentPart.getComponentDescriptor(); + } + + for (Entry property : part.getProperties().entrySet()) { + if (part instanceof ComponentPart && componentDescriptor != null) { + // check property not to be exposed to the xml by unusedEditor property from + // descriptor + PropertyDescriptor propertyDescriptor = componentDescriptor.getPropertyDescriptor(part.getParent(), (ComponentPart) part, property.getKey()); + if (propertyDescriptor != null) { + if (propertyDescriptor.checkUnusedEditors(UnusedEditors.SOURCE_TAB)) { + continue; + } + } + } + if (element != null) { + element.setAttribute(property.getKey(), property.getValue()); + } + } + + if (element != null) { + for (Part child : part.getChildren()) { + Element childElement = writeElementbyPart(document, child); + if (childElement != null) { + element.appendChild(childElement); + } + } + } + + return element; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/PartUnmarshaller.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/PartUnmarshaller.java new file mode 100644 index 0000000..faa191b --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/PartUnmarshaller.java @@ -0,0 +1,130 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.util; + +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.DocumentPart; +import org.tizen.efluibuilder.model.part.MScreenPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.part.ViewPart; +import org.tizen.efluibuilder.model.part.ViewsPart; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + + +public final class PartUnmarshaller { + public Part unmarshall(DocumentPart docPart, Document document, boolean bAssign) { + return writePartbyElement(document.getDocumentElement(), docPart, null, bAssign, bAssign); + } + + public Part unmarshallForUpdate(DocumentPart docPart, Document document) { + return writePartbyElement(document.getDocumentElement(), docPart, null, true, false); + } + + private Part writePartbyElement(Element element, DocumentPart docPart, Part parentPart, boolean bAssignElementToPart, boolean bAssignPartToElement) { + String tagName = element.getTagName(); + + Part part = null; + + if (tagName.equals(LayoutSchemaConstants.DOCUMENT)) { + if (docPart == null) + docPart = (DocumentPart) PartUtil.createPart(PartType.DOCUMENT, null); + part = docPart; + } else if (tagName.equals(LayoutSchemaConstants.MSCREEN)) { + if (parentPart == null || parentPart instanceof DocumentPart) + // part = PartUtil.createMScreenPart((DocPart) parentPart); + part = PartUtil.createPartWithInitValue(docPart, PartType.MSCREEN, parentPart, tagName); + } else if (tagName.equals(LayoutSchemaConstants.VIEWS)) { + if (parentPart == null || parentPart instanceof DocumentPart) { + // part = PartUtil.createViewsPart((DocPart) parentPart); + part = PartUtil.createPartWithInitValue(docPart, PartType.VIEWS, parentPart, tagName); + } + } else if (tagName.equals(LayoutSchemaConstants.CONFIGURATION)) { + if (parentPart == null || parentPart instanceof MScreenPart) { + // part = PartUtil.createConfigurationPart((MScreenPart) parentPart); + part = PartUtil.createPartWithInitValue(docPart, PartType.CONFIGURATION, parentPart, tagName); + } + } else if (tagName.equals(LayoutSchemaConstants.VIEW)) { + if (parentPart == null || parentPart instanceof ViewsPart) { + // part = PartUtil.createViewPart((ViewsPart) parentPart); + part = PartUtil.createPartWithInitValue(docPart, PartType.VIEW, parentPart, tagName); + } + } else if (tagName.equals(LayoutSchemaConstants.EVENT)) { + if (parentPart == null || parentPart instanceof ComponentPart) { + // part = PartUtil.createEventPart((ComponentPart) parentPart); + part = PartUtil.createPartWithInitValue(docPart, PartType.EVENT, parentPart, tagName); + } + } else if (tagName.equals(LayoutSchemaConstants.VARIATION)) { + if (parentPart == null || parentPart instanceof ComponentPart) { + // part = PartUtil.createVariationPart((ComponentPart) parentPart); + part = PartUtil.createPartWithInitValue(docPart, PartType.VARIATION, parentPart, tagName); + } + } else { + // assume component + if (parentPart == null || (parentPart instanceof ViewPart) || (parentPart instanceof ComponentPart)) { + // part = PartUtil.createComponentPart(parentPart); + if (docPart.getComponentDescriptor().getWidgetDescriptor(tagName) != null) { + part = PartUtil.createPartWithInitValue(docPart, PartType.COMPONENT, parentPart, tagName); + } + } else { + return null; + } + } + + if (part == null) + return null; + + NamedNodeMap attrList = element.getAttributes(); + for (int i = 0; i < attrList.getLength(); i++) { + Attr attr = (Attr) attrList.item(i); + part.setPropertyValue(attr.getName(), attr.getValue()); + } + + NodeList nodes = element.getChildNodes(); + for (int i = 0; i < nodes.getLength(); i++) { + Node child = nodes.item(i); + if (child instanceof Element) { + Part childPart = writePartbyElement((Element) child, docPart, part, bAssignElementToPart, bAssignPartToElement); + if (childPart != null) { + childPart.setParent(part); + part.insertChildBefore(childPart, null); + } + } + } + + if (bAssignElementToPart) { + part.setElement(element); + } + + if (bAssignPartToElement) { + element.setUserData(ModelConstants.ELEMENT_UD_PART_KEY, part, null); + } + return part; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/PartUtil.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/PartUtil.java new file mode 100644 index 0000000..8685ed3 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/model/util/PartUtil.java @@ -0,0 +1,748 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.model.util; + +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Queue; +import java.util.Stack; + +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CompoundCommand; +import org.tizen.common.util.Assert; +import org.tizen.efluibuilder.model.command.AddPartCommand; +import org.tizen.efluibuilder.model.command.ChangeOrderPartCommand; +import org.tizen.efluibuilder.model.command.RemovePartCommand; +import org.tizen.efluibuilder.model.command.SetPropertyPartCommand; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.ConfigurationPart; +import org.tizen.efluibuilder.model.part.DataBindingPart; +import org.tizen.efluibuilder.model.part.DocumentPart; +import org.tizen.efluibuilder.model.part.EventPart; +import org.tizen.efluibuilder.model.part.MScreenPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.part.VariationPart; +import org.tizen.efluibuilder.model.part.ViewPart; +import org.tizen.efluibuilder.model.part.ViewsPart; +import org.tizen.efluibuilder.nl.BuilderMessages; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingData; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingObject; +import org.w3c.dom.Node; + + +public final class PartUtil { + public static int SUCCESS = 0; + public static int ERROR_ID_EXISTS = 1; + public static int ERROR_INVALID_ID = 2; + + private static int uniqueId = 0; + + private static String getUniqueId() { + return "" + uniqueId++; + } + + /** + * Process searching a part of views. + * + * @param rootPart + * a root node of tree. @return a part which has views type. it is null if there has + * no one. @throws + * + */ + public static Part findViewsPart(Part rootPart) { + if (rootPart != null) { + Stack partStack = new Stack(); + partStack.add(rootPart); + + while (partStack.size() > 0) { + Part popPart = partStack.pop(); + if (popPart.getType() == PartType.VIEWS) + return popPart; + + for (Part child : popPart.getChildren()) + partStack.add(child); + } + } + + return null; + } + + /** + * Process searching a part of view from a leaf node. + * + * @param leafPart + * a part which is behind the view. @return a part which has view type. it is null if + * there has no one. @throws + * + */ + public static Part findViewPart(Part leafPart) { + while (leafPart != null) { + if (leafPart.getType() == PartType.VIEW) { + return leafPart; + } + leafPart = leafPart.getParent(); + } + + return null; + } + + /** + * Create a part with initial values by a own descriptor + * + * @param docPart + * you can get componentDescriptor @param type a type of part @param parent @param + * tagName will be descriptorId + * + * @return a new part @throws + */ + public static Part createPartWithInitValue(DocumentPart docPart, int type, Part parent, String tagName) { + if (docPart == null) { + return null; + } + Part part = createPart(type, tagName); + + if (part instanceof ComponentPart) { + ComponentDescriptor componentDescriptor = docPart.getComponentDescriptor(); + Map initValues = null; + if (parent instanceof ComponentPart) { + initValues = componentDescriptor.getInitValues((ComponentPart) parent, (ComponentPart) part); + } else { + initValues = componentDescriptor.getInitValues(null, (ComponentPart) part); + } + setInitValues(part, initValues); + } + return part; + } + + /** + * Set initial values to a part + * + * @param part + * @param initValues + * @return @throws + */ + public static void setInitValues(Part part, Map initValues) { + if (part == null) { + return; + } + if (initValues == null || initValues.isEmpty()) { + return; + } + + for (Entry entry : initValues.entrySet()) { + part.setPropertyValue(entry.getKey(), entry.getValue()); + } + } + + /** + * Create a part + * + * @param type + * PartType @param tagName will be descriptorId @return a new part @throws + */ + public static Part createPart(int type, String tagName) { + return PartUtil.createPart(type, tagName, null); + } + + /** + * Create a part + * + * @param type + * PartType @param tagName will be descriptorId @param parent + * + * @return a new part @throws + */ + public static Part createPart(int type, String tagName, Part parent) { + Part part = null; + switch (type) { + case PartType.DOCUMENT: + part = createDocPart(); + part.setDescriptorId(LayoutSchemaConstants.DOCUMENT); + break; + case PartType.MSCREEN: + part = createMScreenPart((DocumentPart) parent); + part.setDescriptorId(LayoutSchemaConstants.MSCREEN); + break; + case PartType.CONFIGURATION: + part = createConfigurationPart((MScreenPart) parent); + part.setDescriptorId(LayoutSchemaConstants.CONFIGURATION); + break; + case PartType.VIEWS: + part = createViewsPart((DocumentPart) parent); + part.setDescriptorId(LayoutSchemaConstants.VIEWS); + break; + case PartType.VIEW: + part = createViewPart((ViewsPart) parent); + part.setDescriptorId(LayoutSchemaConstants.VIEW); + break; + case PartType.VARIATION: + part = createVariationPart((ComponentPart) parent); + part.setDescriptorId(LayoutSchemaConstants.VARIATION); + break; + case PartType.COMPONENT: + part = createComponentPart(parent); + break; + case PartType.EVENT: + part = createEventPart((ComponentPart) parent); + part.setDescriptorId(LayoutSchemaConstants.EVENT); + break; + case PartType.DATABINDING: + part = createDataBindingPart((ViewsPart) parent); + part.setDescriptorId(LayoutSchemaConstants.DATABINDING); + break; + case PartType.DATASOURCE: + part = createDataSourcePart((DataBindingPart) parent); + part.setDescriptorId(LayoutSchemaConstants.DATASOURCE); + break; + case PartType.DATAMODEL: + part = createDataModelPart((DataBindingPart) parent); + part.setDescriptorId(LayoutSchemaConstants.DATAMODEL); + break; + case PartType.BINDINGOBJECT: + part = createBindingObjectPart((DataBindingPart) parent); + part.setDescriptorId(LayoutSchemaConstants.BINDINGOBJECT); + break; + } + + if (part instanceof ComponentPart) { + part.setDescriptorId(tagName); + } + return part; + } + + /** + * Create a AddPartCommand + * + * @param @return + * @throws + */ + public static Command createAddPartCommand(Part parent, Part child, Part nextSibiling) { + return new AddPartCommand(parent, child, nextSibiling); + } + + /** + * Create a RemovePartCommand + * + * @param @return + * @throws + */ + public static Command createRemovePartCommand(Part parent, Part child) { + return new RemovePartCommand(parent, child); + } + + /** + * Create a SetPropertyPartCommand + * + * @param @return + * @throws + */ + public static Command createSetPropertyCommand(Part part, String name, String value) { + return new SetPropertyPartCommand(part, name, value); + } + + /** + * Create SetPropertiesPartCommand + * + * @param @return + * @throws + */ + public static Command createSetPropertiesCommand(Part part, VariationPart variationPart, List keys) { + if (part == null || variationPart == null || keys == null) { + return null; + } + + CompoundCommand compCmd = new CompoundCommand(); + for (String key : keys) { + String value = part.getPropertyValue(key); + compCmd.add(PartUtil.createSetPropertyCommand(variationPart, key, value)); + } + + return compCmd; + } + + /** + * + * + * @param @return + * @throws + */ + public static Command createMovePartCommand(Part part, Part oldParent, Part newParent, Part nextSibling) { + CompoundCommand compCmd = new CompoundCommand(); + if (part == null || newParent == null) { + return compCmd; + } + compCmd.add(createRemovePartCommand(oldParent, part)); + compCmd.add(createAddPartCommand(newParent, part, nextSibling)); + + return compCmd; + } + + /** + * + * + * @param @return + * @throws + */ + public static Command createChangePartOrderCommand(Part part, Part newNextSibling) { + return new ChangeOrderPartCommand(part, newNextSibling); + } + + /** + * Create a CompoundCommand about event + * + * @param @return + * @throws + */ + public static Command createEventPartCommand(Part parent, Part part, String eventName, String signal) { + CompoundCommand compCmd = new CompoundCommand(); + if (part == null || parent == null) { + return compCmd; + } + compCmd.add(createAddPartCommand(parent, part, null)); + compCmd.add(createSetPropertyCommand(part, LayoutSchemaConstants.EVENT_FUNCTION_NAME, eventName)); + compCmd.add(createSetPropertyCommand(part, LayoutSchemaConstants.EVENT_SIGNAL, signal)); + return compCmd; + } + + /** + * + * + * @param @return + * @throws + */ + public static Command createPackCommandWithVariation(ComponentPart part, Part parent, ConfigurationPart configPart, Rectangle packBound) { + CompoundCommand compCmd = new CompoundCommand(); + if (part == null || parent == null || configPart == null) { + return null; + } + String type = configPart.getPropertyValue(LayoutSchemaConstants.TYPE); + if (type.equals(LayoutSchemaConstants.CONFIGURATION_TYPE_COMMON)) { + compCmd.add(PartUtil.createPackCommand(part, parent, packBound)); + } else { + // if current configuration is specific configuration + String configurationId = configPart.getPropertyValue(LayoutSchemaConstants.ID); + VariationPart variationPart = part.getVariationPart(configurationId); + if (variationPart == null) { + variationPart = (VariationPart) PartUtil.createPartWithInitValue(part.getOwnerDocumentPart(), PartType.VARIATION, part, null); + compCmd.add(PartUtil.createVariationPartCommand(part, variationPart, configurationId, LayoutSchemaConstants.TRUE)); + } + compCmd.add(PartUtil.createPackCommand(variationPart, parent, packBound)); + } + + if (compCmd.isEmpty()) { + compCmd = null; + return null; + } else { + return compCmd; + } + } + + /** + * Create a CompoundCommand about variation + * + * @param @return + * @throws + */ + public static Command createVariationPartCommand(Part parent, Part part, String config_ref, String visible) { + CompoundCommand compCmd = new CompoundCommand(); + if (part == null || parent == null) { + return null; + } + + compCmd.add(createAddPartCommand(parent, part, null)); + compCmd.add(createSetPropertyCommand(part, LayoutSchemaConstants.CONFIGURATION_REFERENCE, config_ref)); + compCmd.add(createSetPropertyCommand(part, LayoutSchemaConstants.VISIBLE, visible)); + + return compCmd; + } + + /** + * Create a CompoundCommand about pack + * + * @param @return + * @throws + */ + public static Command createPackCommand(Part part, Part parent, Rectangle rectangle) { + Command cmd = null; + if (part == null) { + return cmd; + } + + if (parent == null) { + if (part instanceof ComponentPart) { + parent = part.getParent(); + } else if (part instanceof VariationPart) { + parent = part.getParent().getParent(); + } + if (parent == null) { + return cmd; + } + } + + String descriptorId = parent.getDescriptorId(); + if (descriptorId.equals(LayoutSchemaConstants.GRID)) { + cmd = createGridPackCommand(part, rectangle); + } else if (descriptorId.equals(LayoutSchemaConstants.TABLE)) { + cmd = createTablePackCommand(part, rectangle); + } else if (descriptorId.equals(LayoutSchemaConstants.PANES)) { + cmd = createPanesPackCommand(part, rectangle); + } + + return cmd; + } + + /** + * Create a CompoundCommand about gridPack + * + * @param @return + * @throws + */ + public static Command createGridPackCommand(Part part, Rectangle rectangle) { + CompoundCommand compCmd = new CompoundCommand(); + if (part == null) { + return null; + } + + compCmd.add(createSetPropertyCommand(part, LayoutSchemaConstants.GRID_PACK_X, Integer.toString(rectangle.x))); + compCmd.add(createSetPropertyCommand(part, LayoutSchemaConstants.GRID_PACK_Y, Integer.toString(rectangle.y))); + compCmd.add(createSetPropertyCommand(part, LayoutSchemaConstants.GRID_PACK_W, Integer.toString(rectangle.width))); + compCmd.add(createSetPropertyCommand(part, LayoutSchemaConstants.GRID_PACK_H, Integer.toString(rectangle.height))); + + return compCmd; + } + + /** + * Create a CompoundCommand about tablePack + * + * @param @return + * @throws + */ + public static Command createTablePackCommand(Part part, Rectangle rectangle) { + CompoundCommand compCmd = new CompoundCommand(); + if (part == null) { + return null; + } + + compCmd.add(createSetPropertyCommand(part, LayoutSchemaConstants.TABLE_PACK_COL, Integer.toString(rectangle.x))); + compCmd.add(createSetPropertyCommand(part, LayoutSchemaConstants.TABLE_PACK_ROW, Integer.toString(rectangle.y))); + compCmd.add(createSetPropertyCommand(part, LayoutSchemaConstants.TABLE_COL_SPAN, Integer.toString(rectangle.width))); + compCmd.add(createSetPropertyCommand(part, LayoutSchemaConstants.TABLE_ROW_SPAN, Integer.toString(rectangle.height))); + return compCmd; + } + + /** + * Create a CompoundCommand panesPack + * + * @param @return + * @throws + */ + public static Command createPanesPackCommand(Part part, Rectangle rectangle) { + CompoundCommand compCmd = new CompoundCommand(); + if (part == null) { + return null; + } + compCmd.add(createSetPropertyCommand(part, LayoutSchemaConstants.PANES_PACK, getPanesPackValue(rectangle))); + return compCmd; + } + + public static Command createSetViewPropertyIdCommand(ViewPart part, String value) { + CompoundCommand compCmd = new CompoundCommand(); + compCmd.add(new SetPropertyPartCommand(part, LayoutSchemaConstants.ID, value)); + if (part.getParent().getPropertyValue(LayoutSchemaConstants.STARTUP).equals(part.getPropertyValue(LayoutSchemaConstants.ID))) { + compCmd.add(new SetPropertyPartCommand(part.getParent(), LayoutSchemaConstants.STARTUP, value)); + } + List events = getEventPartsFromTargetView(part); + for (Part event : events) { + compCmd.add(new SetPropertyPartCommand(event, LayoutSchemaConstants.EVENT_TARGET, value)); + } + return compCmd; + } + + public static List getEventPartsFromTargetView(ViewPart viewPart) { + List events = new ArrayList(); + Queue queue = new ArrayDeque(); + Part part; + String viewId = viewPart.getPropertyValue(LayoutSchemaConstants.ID); + if (viewPart.getParent() != null) { + for (Part child : viewPart.getParent().getChildren()) { + queue.addAll(child.getChildren()); + while(queue.isEmpty() == false) { + part = queue.poll(); + if (part instanceof EventPart && part.hasProperty(LayoutSchemaConstants.EVENT_CONNECTION) && viewId.equals(part.getPropertyValue(LayoutSchemaConstants.EVENT_TARGET))) { + events.add(part); + } + queue.addAll(part.getChildren()); + } + } + } + return events; + } + + private static String getPanesPackValue(Rectangle rectangle) { + // FIXME need to check parent's direction + // if direction is vertical, value can be left or right + // also if direction is horizontal, value can be top or bottom + String value = null; + if (0 == rectangle.x) { + value = LayoutSchemaConstants.PANES_PACK_LEFT; + } else { + value = LayoutSchemaConstants.PANES_PACK_RIGHT; + } + return value; + } + + public static int isValidViewName(Part viewsPart, String name) { + Assert.notNull(name); + + ComponentValidator validator = new ComponentValidator(); + String result = validator.isValidName(name); + if (result.equals(BuilderMessages.ERROR_ID_EQUALS_RESERVED_WORD)) { + return ERROR_INVALID_ID; + } else if (result.equals(BuilderMessages.ERROR_ID_INVALID_REGX)) { + return ERROR_INVALID_ID; + } + + if (isViewNameExist(viewsPart, name)) { + return ERROR_ID_EXISTS; + } + + return SUCCESS; + } + + private static boolean isViewNameExist(Part viewsPart, String name) { + String idValue; + for (Part view : viewsPart.getChildren()) { + idValue = view.getPropertyValue(LayoutSchemaConstants.ID); + if (idValue != null && idValue.equals(name)) { + return true; + } + } + return false; + } + + public static Part clone(Part part) { + return PartUtil.clone(part, true, null); + } + + public static Part clone(Part part, boolean deep, String configurationID, boolean bRemainUniqueId) { + if (part instanceof ComponentPart != true) { + return null; + } + + Part newPart = PartUtil.createPart(part.getType(), part.getDescriptorId()); + if (bRemainUniqueId) { + newPart.setUniqueId(part.getUniqueId()); + } + Part newChild = null; + for (Entry entry : part.getProperties().entrySet()) { + newPart.setPropertyValue(entry.getKey(), entry.getValue()); + } + if (configurationID != null) { + for (Part child : part.getChildren()) { + if (child instanceof VariationPart && configurationID.equals(child.getPropertyValue(LayoutSchemaConstants.CONFIGURATION_REFERENCE))) { + for (Entry entry : child.getProperties().entrySet()) { + String childKey = entry.getKey(); + if (newPart.hasProperty(childKey)) { + // Set only the attributes that exist in the component from variation + newPart.setPropertyValue(childKey, entry.getValue()); + } + } + } + } + } + + if (deep) { + for (Part child : part.getChildren()) { + newChild = PartUtil.clone(child, deep, configurationID); + if (newChild != null) { + newPart.insertChildBefore(newChild, null); + + } + } + } + return newPart; + } + + public static Part clone(Part part, boolean deep, String configurationID) { + return clone(part, deep, configurationID, false); + } + + private static DocumentPart createDocPart() { + return new DocumentPart(getUniqueId()); + } + + private static MScreenPart createMScreenPart(DocumentPart _parentPart) { + return new MScreenPart(getUniqueId(), _parentPart); + } + + private static ConfigurationPart createConfigurationPart(MScreenPart _parentPart) { + return new ConfigurationPart(getUniqueId(), _parentPart); + } + + private static ViewsPart createViewsPart(DocumentPart _parentPart) { + return new ViewsPart(getUniqueId(), _parentPart); + } + + private static ViewPart createViewPart(ViewsPart _parentPart) { + return new ViewPart(getUniqueId(), _parentPart); + } + + private static ComponentPart createComponentPart(Part _parentPart) { + return new ComponentPart(getUniqueId(), _parentPart); + } + + private static EventPart createEventPart(ComponentPart _parentPart) { + return new EventPart(getUniqueId(), _parentPart); + } + + private static VariationPart createVariationPart(ComponentPart _parentPart) { + return new VariationPart(getUniqueId(), _parentPart); + } + + public static String setColorString(String colorValues, String partName, String color) { + if (colorValues != null) { + Map colorMap = getPartColors(colorValues); + if (colorMap == null) { + colorMap = new HashMap(); + } + colorMap.put(partName, color); + return convertColorMapToPropertyValue(colorMap); + } + return null; + } + + public static String setColorString(String colorValues, Map partColorMap) { + if (colorValues != null) { + Map colorMap = getPartColors(colorValues); + if (colorMap == null) { + colorMap = new HashMap(); + } + colorMap.putAll(partColorMap); + return convertColorMapToPropertyValue(colorMap); + } + return null; + } + + public static String convertColorMapToPropertyValue(Map colorMap) { + StringBuffer str = new StringBuffer(); + boolean bFirst = true; + for (Entry entry : colorMap.entrySet()) { + if (bFirst) { + str.append(entry.getKey() + ":" + entry.getValue() + ";"); + bFirst = false; + } else { + str.append(" " + entry.getKey() + ":" + entry.getValue() + ";"); + } + } + return str.toString(); + } + + public static String getColor(String colorValues, String partName) { + Map colorMap = getPartColors(colorValues); + if (colorMap != null) { + return colorMap.get(partName); + } + return null; + } + + public static String getColor(Part part, String partName) { + Map colorMap = getPartColors(part); + if (colorMap != null) { + return colorMap.get(partName); + } + return null; + } + + public static Map getPartColors(String colorValues) { + Map colorMap = null; + if (colorValues != null && !colorValues.isEmpty()) { + String[] color = colorValues.split(";"); + String[] colorPart; + for (int i = 0; i < color.length; i++) { + colorPart = color[i].split(":"); + if (colorPart.length == 2) { + if (colorMap == null) { + colorMap = new HashMap(); + } + String key = colorPart[0].trim(); + String colorValue = colorPart[1].trim(); + colorMap.put(key, colorValue); + } + } + } + return colorMap; + } + + public static Map getPartColors(Part part) { + String colorValues = part.getPropertyValue(LayoutSchemaConstants.COLORS); + return getPartColors(colorValues); + } + + public static String getRemovedColorString(String colorValues, String partName) { + Map colorMap = getPartColors(colorValues); + if (colorMap != null) { + colorMap.remove(partName); + return convertColorMapToPropertyValue(colorMap); + } + return null; + + } + + private static Part createDataBindingPart(ViewsPart _parentPart) { + return new DataBindingPart(getUniqueId(), _parentPart); + } + + private static Part createDataSourcePart(DataBindingPart _parentPart) { + return new BindingData(getUniqueId(), _parentPart, PartType.DATASOURCE); + } + + private static Part createDataModelPart(DataBindingPart _parentPart) { + return new BindingData(getUniqueId(), _parentPart, PartType.DATAMODEL); + } + + private static Part createBindingObjectPart(DataBindingPart _parentPart) { + return new BindingObject(getUniqueId(), _parentPart); + } + + public static Part getPartFrom(Node node) { + if (node != null) { + Object userData = node.getUserData(ModelConstants.ELEMENT_UD_PART_KEY); + if (userData instanceof Part) { + return (Part) userData; + } + } + + return null; + } + + public static void setPartToElement(Node node, Part part) { + node.setUserData(ModelConstants.ELEMENT_UD_PART_KEY, part, null); + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/IScreenConfigurationSelectionChangedListener.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/IScreenConfigurationSelectionChangedListener.java new file mode 100644 index 0000000..7ddd17f --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/IScreenConfigurationSelectionChangedListener.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.mscreen.configurator; + +public interface IScreenConfigurationSelectionChangedListener { + public void configurationSelected(MScreenQualifierManager mscreenManager); +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/MScreenQualifierManager.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/MScreenQualifierManager.java new file mode 100644 index 0000000..991845f --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/MScreenQualifierManager.java @@ -0,0 +1,210 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.mscreen.configurator; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.ui.IEditorInput; +import org.tizen.efluibuilder.core.configuration.device.Device; +import org.tizen.efluibuilder.model.app.AppManager; +import org.tizen.efluibuilder.model.part.ConfigurationPart; +import org.tizen.efluibuilder.model.part.MScreenPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.mscreen.rm.ResourceManagerUtil; + + +public class MScreenQualifierManager { + private ConfigurationPart currentConfigurePart = null; // can be NULL + private MScreenPart mscreenPart = null; + Collection devices = null; + String[] locales = null; + String locale = null; + List listeners = + new ArrayList(); + + public MScreenQualifierManager(MScreenPart rootPart, IEditorInput editorInput) { + AppManager appManager = AppManager.getAppManager(editorInput); + devices = appManager.getDeviceManager().getDevices(); + + ResourceManagerUtil resourceManager = new ResourceManagerUtil(appManager.getProject()); + locales = resourceManager.getLocales(); + locale = locales[0]; + + // this.setCurrentConfigurePart(this.getCommonConfigurationPart()); + + this.mscreenPart = rootPart; + } + + public ConfigurationPart getCurrentConfigurePart() { + if (this.currentConfigurePart == null) { + return getCommonConfigurationPart(); + } else { + return this.currentConfigurePart; + } + } + + public void setCurrentConfigurePart(ConfigurationPart configurePart) { + this.currentConfigurePart = configurePart; + this.fireCurrentConfigureChanged(); + } + + public void fireCurrentConfigureChanged() { + for (IScreenConfigurationSelectionChangedListener listener : this.listeners) { + listener.configurationSelected(this); + } + } + + public void fireCurrentLocaleChanged() { + fireCurrentConfigureChanged(); + } + + private ConfigurationPart getConfigurePartFromQualifiers(String deviceName, String orientation) { + if (deviceName == null || orientation == null) { + return null; + } + + for (Part part : this.mscreenPart.getChildren()) { + if (part instanceof ConfigurationPart) { + ConfigurationPart configPart = (ConfigurationPart) part; + if (deviceName.equals(configPart.getDevice()) + && orientation.equals(configPart.getOrientation())) { + return configPart; + } + } + } + + return null; + } + + public ConfigurationPart getConfigurePartFromQualifiers(Device device, String orientation) { + if (device == null) { + return null; + } + + return getConfigurePartFromQualifiers(device.getName(), orientation); + } + + public ConfigurationPart getConfigurePartFromScreenConfiguration(ScreenConfiguration configuration) { + if (configuration == null) { + return null; + } + + String deviceName = configuration.getQualifier(LayoutSchemaConstants.DEVICE); + String orientation = configuration.getQualifier(LayoutSchemaConstants.ORIENTATION); + + return getConfigurePartFromQualifiers(deviceName, orientation); + } + + public List getScreenConfiguration() { + List configurations = new ArrayList(); + for (Part part : this.mscreenPart.getChildren()) { + if (part instanceof ConfigurationPart) { + configurations.add(new ScreenConfiguration((ConfigurationPart) part)); + } + } + + return configurations; + } + + public void updateConfigurePartFromQualifiers(String device, String orientation) { + + } + + public void resetCurrentConfigurePart() { + List children = this.mscreenPart.getChildren(); + if (children.size() > 0) { + setCurrentConfigurePart((ConfigurationPart) children.get(0)); + } + } + + public ConfigurationPart getCommonConfigurationPart() { + return this.mscreenPart.getCommonConfigurationPart(); + } + + public String getCurrentOrientation() { + ConfigurationPart currentPart = getCurrentConfigurePart(); + if (currentPart == null) { + return null; + } + + return currentPart.getOrientation(); + } + + public Device getCurrentDevice() { + ConfigurationPart currentPart = getCurrentConfigurePart(); + if (currentPart == null) { + return null; + } + + String deviceName = currentPart.getDevice(); + for (Device device : this.devices) { + if (device.getName().equals(deviceName)) { + return device; + } + } + + return null; + } + + public void setLocale(String locale) { + if (locale != null && locale.equals(this.locale) == false) { + this.locale = locale; + fireCurrentLocaleChanged(); + } + } + + public String getCurrentLocale() { + return this.locale; + } + + public MScreenPart getMScreenPart() { + return this.mscreenPart; + } + + public Point getScreenSize() { + Device device = getCurrentDevice(); + String orientation = getCurrentOrientation(); + if (MscreenConstants.ORIENTATION_PORTRAIT.equals(orientation)) { + return new Point(device.getWidth(), device.getHeight()); + } else { + return new Point(device.getHeight(), device.getWidth()); + } + } + + public void addConfigureSelectionChangedListener(IScreenConfigurationSelectionChangedListener listener) { + this.listeners.add(listener); + } + + public void removeConfigureSelectionChangedListener(IScreenConfigurationSelectionChangedListener listener) { + this.listeners.remove(listener); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/MsConfiguratorWizard.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/MsConfiguratorWizard.java new file mode 100644 index 0000000..bb2ad58 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/MsConfiguratorWizard.java @@ -0,0 +1,76 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.mscreen.configurator; + +import org.eclipse.gef.commands.Command; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.model.part.MScreenPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.ui.wizard.snippet.AbstractWizard; + + +public class MsConfiguratorWizard extends AbstractWizard { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + private MsConfiguratorWizardFirstPage firstPage = null; + + public MsConfiguratorWizard() { + super(); + setWindowTitle(MscreenMessage.CONFIGURATOR_DLG_TITLE); + } + + @Override + public void addPages() { + super.addPages(); + firstPage = new MsConfiguratorWizardFirstPage(MsConfiguratorWizardFirstPage.NAME, MscreenMessage.CONFIGURATOR_DLG_FIRST_PAGE_TITLE, null); + // TODO FIXME + Part mscreenPart = (Part) getModel(); + if (mscreenPart instanceof MScreenPart) { + firstPage.setContents((MScreenPart) mscreenPart); + } + addPage(firstPage); + } + + @Override + public boolean performFinish() { + try { + return firstPage.remakeMscreenConfigurations(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + return false; + } + } + + public Command getCommand() { + return firstPage.getCommand(); + } + + @Override + public void dispose() { + firstPage.dispose(); + super.dispose(); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/MsConfiguratorWizardFirstPage.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/MsConfiguratorWizardFirstPage.java new file mode 100644 index 0000000..a8f26c3 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/MsConfiguratorWizardFirstPage.java @@ -0,0 +1,1017 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.mscreen.configurator; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CompoundCommand; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.custom.TableEditor; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseTrackAdapter; +import org.eclipse.swt.events.MouseTrackListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +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; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Text; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.core.configuration.device.Device; +import org.tizen.efluibuilder.core.configuration.device.ScreenDesc.DPI; +import org.tizen.efluibuilder.core.configurator.ConfiguratorConstants; +import org.tizen.efluibuilder.model.part.ConfigurationPart; +import org.tizen.efluibuilder.model.part.MScreenPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.ModelConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.resources.ColorResources; +import org.tizen.efluibuilder.ui.resources.ImageResources; +import org.tizen.efluibuilder.ui.wizard.snippet.AbstractWizardPage; + + +public class MsConfiguratorWizardFirstPage extends AbstractWizardPage { + public static final String NAME = MsConfiguratorWizardFirstPage.class.getName(); + + private static final int NAME_COLUMN_MAX_LEN = 30; + // controls + private Composite rootComposite = null; + + private ScrolledComposite tableComposite = null; + + private static final String KEY_TBL_ITEM_DATA_MS_CONFIG = "key-ms-data"; //$NON-NLS-1$ + + // name key + private static final String KEY_NAME = "" + eTBLCol.NAME.value; //$NON-NLS-1$ + private static final String KEY_TBL_ITEM_DATA_TBL_NAME_EDITOR = KEY_NAME + "editor"; //$NON-NLS-1$ + + // resolution key + private static final String KEY_DEVICE = "" + eTBLCol.DEVICE.value; //$NON-NLS-1$ + private static final String KEY_TBL_ITEM_DATA_TBL_DEVICE_EDITOR = "" + KEY_DEVICE + "editor"; //$NON-NLS-1$ + + // orientation key + private static final String KEY_ORIENTATION = "" + eTBLCol.ORIENTATION.value; + private static final String KEY_TBL_ITEM_DATA_TBL_ORIENTATION_EDITOR = KEY_ORIENTATION + "editor"; //$NON-NLS-1$ + private static final String KEY_TBL_ITEM_DATA_ORIENTATION_STRING = KEY_ORIENTATION + "string"; //$NON-NLS-1$ + private static final String KEY_ORIENTATION_ICON_DATA_TBL_ITEM = KEY_ORIENTATION + "item"; //$NON-NLS-1$ + + // delete key + private static final String KEY_DELETE = "" + eTBLCol.DELETE.value; + private static final String KEY_TBL_ITEM_DATA_TBL_DELETE_EDITOR = KEY_DELETE + "editor"; //$NON-NLS-1$ + private static final String KEY_DEL_ICON_DATA_TBL_ITEM = KEY_DELETE + "item"; //$NON-NLS-1$ + + private static final String SPACING = "\n"; + + private static Logger logger = LoggerFactory.getLogger(MsConfiguratorWizardFirstPage.class); + + // Define control variable + private Table table = null; + private Button addBtn = null; + + private MScreenPart mscreenPart = null; + + CompoundCommand compCmd = null; + TableEditor editor = null; + // Define Logic variable + // private MscreenManager mscreenManager = null; + + private int deleteColumnWidth = 225; + + private void setDeleteColumnWidth() { + if (Platform.OS_MACOSX.equals(Platform.getOS())) { + deleteColumnWidth = 255; + } else { // linux, windows case + deleteColumnWidth = 225; + } + } + + private enum eTBLCol { + TEMP(0), NAME(1), DEVICE(2), ORIENTATION(3), DELETE(4); + private int value; + + private eTBLCol(int value) { + this.value = value; + } + } + + protected MsConfiguratorWizardFirstPage(String pageName, String title, ImageDescriptor titleImage) { + super(pageName, title, titleImage); + setDeleteColumnWidth(); + setTitle(MscreenMessage.CONFIGURATOR_DLG_FIRST_PAGE_TITLE); + setDescription(MscreenMessage.CONFIGURATOR_DLG_FIRST_PAGE_DESCRIPTION); + + } + + private SelectionListener buttonAddListener = new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent event) { + disposeEditor(editor); + + editor.horizontalAlignment = SWT.CENTER; + editor.grabHorizontal = true; + + addRow(table, null, true); + setPageComplete(false); + + TableContainInfo tblContainInfo = new TableContainInfo(table.getItemCount() - 1, table.getItem(table.getItemCount() - 1)); + final TableItem item = tblContainInfo.getTableItem(); + // Create the Text object for our editor + editNameColumn(editor, item); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }; + + @Override + public void createControl(Composite parent) { + boolean bNew = true; + if (bNew) { + // Root Composite + rootComposite = new Composite(parent, SWT.NONE); + rootComposite.setLayout(new GridLayout(6, false)); + rootComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); + setControl(rootComposite); + + addBtn = new Button(rootComposite, SWT.PUSH); + addBtn.setText(MscreenMessage.CONFIGURATOR_DLG_BTN_ADD); + + GridData gd = createGridData(GridData.HORIZONTAL_ALIGN_END, 6, SWT.RIGHT, 65); + gd.heightHint = 30; + addBtn.setLayoutData(gd); + addBtn.setSelection(false); + + tableComposite = new ScrolledComposite(rootComposite, SWT.NONE); + tableComposite.setBackground(ColorResources.DIALOG_TABLE_BG); + tableComposite.setLayout(new GridLayout()); + gd = createGridData(GridData.FILL_BOTH, 6, -1, -1); + tableComposite.setLayoutData(gd); + table = new Table(tableComposite, SWT.MULTI | SWT.BORDER); + tableComposite.setContent(table); + tableComposite.setExpandHorizontal(true); + tableComposite.setExpandVertical(true); + tableComposite.setAlwaysShowScrollBars(true); + tableComposite.setMinSize(table.computeSize(SWT.DEFAULT, SWT.DEFAULT)); + tableComposite.setFocus(); + table.setHeaderVisible(true); + table.setLinesVisible(false); + initTableEditors(); + createTableContents(); + setPageComplete(false); + addListeners(); + this.getShell().setMinimumSize(660, 461); + this.getShell().setLocation(SWT.CENTER, SWT.CENTER); + } + } + + @Override + public void dispose() { + removeListeners(); + super.dispose(); + } + + private void addListeners() { + table.addListener(SWT.MeasureItem, tableActionListener); + table.addListener(SWT.Selection, tableActionListener); + table.getColumn(0).addListener(SWT.Selection, tableColumnListener); + addBtn.addSelectionListener(buttonAddListener); + } + + private void removeListeners() { + if (!table.isDisposed()) { + table.removeListener(SWT.MeasureItem, tableActionListener); + table.removeListener(SWT.Selection, tableActionListener); + table.getColumn(0).removeListener(SWT.Selection, tableColumnListener); + } + if (!addBtn.isDisposed()) { + addBtn.removeSelectionListener(buttonAddListener); + } + } + + private void setValidate(String errorMessage) { + if (errorMessage != null) { + setMessage(null, errorMessage); + setPageComplete(false); + } else { + setMessage(MscreenMessage.CONFIGURATOR_DLG_FIRST_PAGE_DESCRIPTION, null); + setPageComplete(checkUniqueConfigurations()); + + } + } + + public void printAllMscreenConfiguration() { + logger.debug("==============[printAllMscreenConfiguration]==========="); + List configurations = this.getScreenConfigurations(); + for (Iterator itr = configurations.iterator(); itr.hasNext();) { + ScreenConfiguration msConfiguration = itr.next(); + logger.debug("-------------------------------------------------------"); + logger.debug("* config-id:{}, config-name:{}", msConfiguration.getId(), msConfiguration.getName()); + logger.debug("* config-orientation:{}, config-device:{}", msConfiguration.getQualifier(MscreenConstants.ORIENTATION), + msConfiguration.getQualifier(MscreenConstants.DEVICE)); + } + logger.debug("==============[printAllMscreenConfiguration]==========="); + } + + private boolean isStringEmpty(String string) { + if (string == null) + return false; + string = string.trim(); + return (string.isEmpty()) ? true : false; + } + + private boolean isUniqueName(String srcName, int srcIdx) { + TableItem destItem = null; + String destName; + srcName = srcName.trim(); + + if (srcName.isEmpty()) { + return true; + } + + for (int j = 0; j < table.getItemCount(); j++) { + destItem = table.getItems()[j]; + destName = destItem.getText(eTBLCol.NAME.value).trim(); + if (destName.isEmpty()) { + continue; + } + if (srcIdx == j) { + continue; + } + + if (srcName.equals(destName)) { + setValidate(MscreenMessage.CONFIGURATOR_DLG_MSG_NOT_UNIQ_NAME); + return false; + } + } + return true; + } + + private boolean isUniqueNames() { + String srcName; + + for (TableItem srcItem : table.getItems()) { + srcName = srcItem.getText(eTBLCol.NAME.value).trim(); + if (!checkValidName(srcName, srcItem, eTBLCol.NAME.value)) { + return false; + } + } + return true; + } + + private boolean checkAllUnique() { + return isUniqueNames() && checkUniqueConfigurations(); + } + + private boolean checkUniqueConfigurations() { + TableItem srcItem = null, destItem = null; + + for (int i = 0; i < table.getItemCount(); i++) { + srcItem = table.getItems()[i]; + + if (isStringEmpty(srcItem.getText(eTBLCol.NAME.value))) { + continue; + } + + String strSrcRowItemValue = srcItem.getText(eTBLCol.DEVICE.value) + ":" + srcItem.getData(KEY_TBL_ITEM_DATA_ORIENTATION_STRING); + + for (int j = 0; j < table.getItemCount(); j++) { + destItem = table.getItems()[j]; + String strCompareRowItemValue = destItem.getText(eTBLCol.DEVICE.value) + ":" + destItem.getData(KEY_TBL_ITEM_DATA_ORIENTATION_STRING); + + if (isMscreenTypeCommon(destItem)) { + continue; + } + if (isStringEmpty(destItem.getText(eTBLCol.NAME.value))) { + continue; + } + if (i == j) { // own self item + continue; + } + + if (strSrcRowItemValue.equals(strCompareRowItemValue)) { + setValidate(MscreenMessage.CONFIGURATOR_DLG_MSG_NOT_UNIQ_ITEM); + return false; + } + } + } + return true; + } + + public boolean remakeMscreenConfigurations() { + if (!checkAllUnique()) { + return false; + } + this.compCmd = new CompoundCommand(); + + // check removed parts + for (ScreenConfiguration config : getScreenConfigurations()) { + boolean isExist = false; + for (TableItem item : table.getItems()) { + ScreenConfiguration msConfigurationItem = getItemData(item); + if (msConfigurationItem != null && (msConfigurationItem.getPart() == config.getPart())) { + isExist = true; + break; + } + } + if (isExist == false) { + compCmd.add(PartUtil.createRemovePartCommand(config.getPart().getParent(), config.getPart())); + } + } + + for (TableItem item : table.getItems()) { + ScreenConfiguration oldConfiguration = getItemData(item); + if (oldConfiguration != null) { + ScreenConfiguration newConfiguration = getCurrentScreenConfiguration(item); + if (newConfiguration != null) { + Part configurePart = newConfiguration.getPart(); + // configuration name changed + if (configurePart.getPropertyValue(LayoutSchemaConstants.NAME).equals(newConfiguration.getName()) == false) { + compCmd.add(PartUtil.createSetPropertyCommand(configurePart, LayoutSchemaConstants.NAME, newConfiguration.getName())); + } + + // qualifiers changed + for (Map.Entry entry : newConfiguration.getQualifiers().entrySet()) { + if (configurePart.getPropertyValue(entry.getKey()).equals(entry.getValue()) == false) { + compCmd.add(PartUtil.createSetPropertyCommand(configurePart, entry.getKey(), entry.getValue())); + } + } + } + } else { + // configuration added + if (!item.getText(eTBLCol.NAME.value).isEmpty()) { + Part configurePart = PartUtil.createPart(PartType.CONFIGURATION, LayoutSchemaConstants.CONFIGURATION); + configurePart.setPropertyValue(LayoutSchemaConstants.NAME, item.getText(eTBLCol.NAME.value)); + configurePart.setPropertyValue(LayoutSchemaConstants.DEVICE, item.getText(eTBLCol.DEVICE.value)); + configurePart.setPropertyValue(LayoutSchemaConstants.ORIENTATION, (String) item.getData(KEY_TBL_ITEM_DATA_ORIENTATION_STRING)); + configurePart.setPropertyValue(LayoutSchemaConstants.TYPE, LayoutSchemaConstants.CONFIGURATION_TYPE_SPECIFIC); + compCmd.add(PartUtil.createAddPartCommand(mscreenPart, configurePart, null)); + } + } + } + // printAllMscreenConfiguration(); + if (compCmd.isEmpty()) { + compCmd = null; + } + return true; + + } + + private ScreenConfiguration getCurrentScreenConfiguration(TableItem item) { + ScreenConfiguration oldConfiguration = getItemData(item); + if (oldConfiguration == null) { + return null; + } + ConfigurationPart part = oldConfiguration.getPart(); + Map qualifiers = new HashMap(); + qualifiers.put(LayoutSchemaConstants.DEVICE, item.getText(eTBLCol.DEVICE.value)); + qualifiers.put(LayoutSchemaConstants.ORIENTATION, (String) item.getData(KEY_TBL_ITEM_DATA_ORIENTATION_STRING)); + return new ScreenConfiguration(part, item.getText(eTBLCol.NAME.value), part.getConfigurationType(), qualifiers); + } + + private ScreenConfiguration getItemData(TableItem item) { + if (item == null) { + return null; + } + + return (ScreenConfiguration) item.getData(KEY_TBL_ITEM_DATA_MS_CONFIG); + } + + private boolean isMscreenTypeCommon(TableItem item) { + ScreenConfiguration msConfiguration = getItemData(item); + if (msConfiguration == null) { + return false; + } + return msConfiguration.isCommon(); + } + + private Device findDeviceByDisplayName(String deviceName) { + Collection devices = deviceManager.getDevices(); + for (Device device : devices) { + if (device.getName().equals(deviceName)) { + return device; + } + } + return null; + } + + private String getDeviceDetails(String deviceName) { + StringBuilder deviceDetails = new StringBuilder(MscreenMessage.DEVICE_DETAILS_TITLE); + Device device = findDeviceByDisplayName(deviceName); + if (device != null) { + if (device.getWidth() > 0) { + deviceDetails.append(SPACING); + deviceDetails.append(MscreenMessage.DEVICE_DETAILS_WIDTH); + deviceDetails.append(device.getWidth()); + + } + if (device.getHeight() > 0) { + deviceDetails.append(SPACING); + deviceDetails.append(MscreenMessage.DEVICE_DETAILS_HEIGHT); + deviceDetails.append(device.getHeight()); + } + if ((device.getDPI() != DPI.INVALID_VALUE)) { + deviceDetails.append(SPACING); + deviceDetails.append(MscreenMessage.DEVICE_DETAILS_DPI); + deviceDetails.append(device.getDPI().name()); + } + if (isStringEmpty(device.getDisplaySize())) { + deviceDetails.append(SPACING); + deviceDetails.append(MscreenMessage.DEVICE_DETAILS_SIZE); + deviceDetails.append(device.getDisplaySize()); + } + } + return deviceDetails.toString(); + } + + private void initTableEditors() { + editor = new TableEditor(table); + editor.horizontalAlignment = SWT.CENTER; + editor.grabHorizontal = true; + + table.addMouseTrackListener(new MouseTrackListener() { + + @Override + public void mouseEnter(MouseEvent arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseExit(MouseEvent arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseHover(MouseEvent event) { + // TODO Auto-generated method stub + + TableContainInfo tblContainInfo = new TableContainInfo(table, event.x, event.y); + final TableItem item = tblContainInfo.getTableItem(); + if (item != null) { + String deviceName = item.getText(eTBLCol.DEVICE.value); + String deviceDetails = getDeviceDetails(deviceName); + table.setToolTipText(deviceDetails); + } else { + table.setToolTipText(null); + } + } + + }); + + // TextEdit Handler + table.addMouseListener(new MouseAdapter() { + public void mouseDown(MouseEvent event) { + // Dispose any existing editor + disposeEditor(editor); + // Determine where the mouse was clicked + TableContainInfo tblContainInfo = new TableContainInfo(table, event.x, event.y); + final TableItem item = tblContainInfo.getTableItem(); + + if (item != null) { + // Determine which column was selected + int column = tblContainInfo.getColumn(); + if (isMscreenTypeCommon(item)) { + return; // No edit.. + } + if (column == eTBLCol.NAME.value) { // 1? + // Create the Text object for our editor + editNameColumn(editor, item); + } else if (column == eTBLCol.DEVICE.value) { + createDeviceCombo(editor, table, column, item, getDeviceNames(), item.getText(column)); + } + } + } + }); + } + + private boolean checkNameValue(String strValue) { + return strValue != null && strValue.matches(ModelConstants.ID_PATTERN); + } + + private Listener tableActionListener = new Listener() { + @Override + public void handleEvent(Event event) { + + switch (event.type) { + case SWT.MeasureItem: { + final int widths[] = { 22, 157, 150, 150, deleteColumnWidth }; + event.width = widths[event.index]; + event.height = event.gc.getFontMetrics().getHeight(); // default + // height + // is + // 18 + + } + break; + case SWT.Selection: { + table.deselectAll(); + } + break; + default: + + break; + } + } + }; + + private Listener tableColumnListener = new Listener() { + @Override + public void handleEvent(Event event) { + // TODO SORTING + } + }; + + private void createDeviceCombo(TableEditor editor, Table tbl, int iColNum, final TableItem tblItem, String[] arrayStrings, String strSelectedValue) { + final CCombo combo = new CCombo(tbl, SWT.READ_ONLY); + for (int i = 0, n = arrayStrings.length; i < n; i++) { + combo.add(arrayStrings[i]); + } + tblItem.setText(iColNum, tblItem.getText(eTBLCol.DEVICE.value)); + combo.select(combo.indexOf(strSelectedValue)); // assign selected string + editor.minimumWidth = combo.computeSize(150, SWT.DEFAULT).x; + tbl.getColumn(iColNum).setWidth(editor.minimumWidth); + + // Set the focus on the dropdown and set into the editor + combo.setFocus(); + editor.horizontalAlignment = SWT.CENTER; + editor.setEditor(combo, tblItem, iColNum); + + // Add a listener to set the selected item back into the cell + final int iCol = iColNum; + combo.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + tblItem.setText(iCol, combo.getText()); + + if (checkAllUnique()) { + setValidate(null); + } + } + }); + tblItem.setData(KEY_TBL_ITEM_DATA_TBL_DEVICE_EDITOR, editor); + } + + private void changeOrientationImage(String orientation, Label portraitLabel, Label landscapeLabel) { + Image portraitImage = null; + Image landScapeImage = null; + if (orientation.equals(MscreenConstants.ORIENTATION_PORTRAIT)) { // port on + portraitImage = ImageResources.getImage(ImageResources.DIALOG_DEVICE_MOBILE_PORTRAIT_NOR); + landScapeImage = ImageResources.getImage(ImageResources.DIALOG_DEVICE_MOBILE_LANDSCAPE_DIM); + } else { + portraitImage = ImageResources.getImage(ImageResources.DIALOG_DEVICE_MOBILE_PORTRAIT_DIM); + landScapeImage = ImageResources.getImage(ImageResources.DIALOG_DEVICE_MOBILE_LANDSCAPE_NOR); + } + portraitLabel.setImage(portraitImage); + landscapeLabel.setImage(landScapeImage); + portraitLabel.pack(); + landscapeLabel.pack(); + } + + private boolean isWearableProfile() { + return profile.startsWith(ConfiguratorConstants.PROFILE_WEARABLE); + } + + private void selectOrientation(Table table, String orientation, Label portraitLabel, Label landscapeLabel) { + + TableItem item = (TableItem) portraitLabel.getData(KEY_ORIENTATION_ICON_DATA_TBL_ITEM); + if (item != null) { + if (orientation.equals(item.getData(KEY_TBL_ITEM_DATA_ORIENTATION_STRING))) { + return; // No change + } else if (orientation.equals(MscreenConstants.ORIENTATION_LANDSCAPE)) { + // exclude: wearable profile is only portrait + if (isWearableProfile()) { + return; + } + } + changeOrientationImage(orientation, portraitLabel, landscapeLabel); + item.setData(KEY_TBL_ITEM_DATA_ORIENTATION_STRING, orientation); + if (checkAllUnique()) { + setValidate(null); + } + } + } + + private void setOrientation(Table table, TableItem item, String orientation, Label portraitLabel, Label landscapeLabel) { + + // final TableItem item = item; + if (item != null) { + changeOrientationImage(orientation, portraitLabel, landscapeLabel); + item.setData(KEY_TBL_ITEM_DATA_ORIENTATION_STRING, orientation); + portraitLabel.setData(KEY_ORIENTATION_ICON_DATA_TBL_ITEM, item); + landscapeLabel.setData(item); + } + } + + private void addBlankColumn(TableItem item, String defaultValue) { + item.setText(eTBLCol.TEMP.value, defaultValue); + if (isMscreenTypeCommon(item)) { + item.setGrayed(true); + } + } + + private void addNameColumn(TableItem item, String defaultValue) { + item.setText(eTBLCol.NAME.value, defaultValue); + + if (isMscreenTypeCommon(item)) { + item.setGrayed(true); + } + } + + private void addDeviceColumn(TableItem item, String defaultValue) { + if (defaultValue.isEmpty()) { + defaultValue = getDeviceNames()[0]; + } + item.setText(eTBLCol.DEVICE.value, defaultValue); + } + + private void addOrientationColumn(TableItem item, String defaultValue) { + if (defaultValue.isEmpty()) { + defaultValue = MscreenConstants.ORIENTATIONS[0]; + } + final TableEditor editor = new TableEditor(table); + Composite orientationComposite = new Composite(table, SWT.NONE); + FormData form = new FormData(); + form.left = new FormAttachment(0, -10); + editor.setEditor(orientationComposite, item, eTBLCol.ORIENTATION.value); + + orientationComposite.setLayout(new FormLayout()); + orientationComposite.setLayoutData(form); + + final Label portraitLabel = new Label(orientationComposite, SWT.NONE); + form = new FormData(); + form.left = new FormAttachment(0, 48); + form.top = new FormAttachment(0, 6); + + portraitLabel.setLayoutData(form); + portraitLabel.pack(); + + form = new FormData(); + form.left = new FormAttachment(portraitLabel, 1); + form.top = new FormAttachment(0, 6); + + final Label landscapeLabel = new Label(orientationComposite, SWT.NONE); + landscapeLabel.setLayoutData(form); + landscapeLabel.pack(); + orientationComposite.setBackgroundMode(SWT.INHERIT_FORCE); + + portraitLabel.addMouseListener(new MouseAdapter() { + public void mouseUp(MouseEvent event) { + selectOrientation(table, MscreenConstants.ORIENTATION_PORTRAIT, portraitLabel, landscapeLabel); + } + }); + landscapeLabel.addMouseListener(new MouseAdapter() { + public void mouseUp(MouseEvent event) { + selectOrientation(table, MscreenConstants.ORIENTATION_LANDSCAPE, portraitLabel, landscapeLabel); + } + }); + setOrientation(table, item, defaultValue, portraitLabel, landscapeLabel); + editor.minimumWidth = portraitLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).x + landscapeLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).x + 100; + editor.minimumHeight = portraitLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; + + if (Platform.OS_WIN32.equals(Platform.getOS())) { + table.getColumn(eTBLCol.ORIENTATION.value).setWidth(editor.minimumWidth + 2); + + } else if (Platform.OS_LINUX.equals(Platform.getOS())) { + table.getColumn(eTBLCol.ORIENTATION.value).setWidth(editor.minimumWidth + 4); + } else { // OS X Select + table.getColumn(eTBLCol.ORIENTATION.value).setWidth(editor.minimumWidth + 2); + + } + editor.horizontalAlignment = SWT.CENTER; + editor.verticalAlignment = SWT.CENTER; + + item.setData(KEY_TBL_ITEM_DATA_TBL_ORIENTATION_EDITOR, editor); + } + + private void addDeleteColumn(TableItem item) { + if (!isMscreenTypeCommon(item)) { + final TableEditor editorDel = new TableEditor(table); + Composite deleteComposite = new Composite(table, SWT.NONE); + deleteComposite.setLayout(new FormLayout()); + final Label deleteLabel = new Label(deleteComposite, SWT.NONE); + FormData form = new FormData(); + form.left = new FormAttachment(0, 29); + form.top = new FormAttachment(0, 6); + + deleteLabel.setLayoutData(form); + // deleteLabel.pack(); + Image image = ImageResources.getImage(ImageResources.DIALOG_PROFILE_DELETE_NOR); + deleteLabel.setImage(image); + // deleteLabel.pack(); + + editorDel.minimumWidth = deleteLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).x + 56; + editorDel.minimumHeight = deleteLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; + table.getColumn(eTBLCol.DELETE.value) + .setWidth(table.getColumn(eTBLCol.DELETE.value).getParent().getSize().x - table.getColumn(eTBLCol.TEMP.value).getWidth() + - table.getColumn(eTBLCol.NAME.value).getWidth() + - table.getColumn(eTBLCol.DEVICE.value).getWidth() - table.getColumn(eTBLCol.ORIENTATION.value).getWidth() - 21); + + editorDel.horizontalAlignment = SWT.CENTER; + editorDel.verticalAlignment = SWT.CENTER; + editorDel.setEditor(deleteComposite, item, eTBLCol.DELETE.value); + item.setData(KEY_TBL_ITEM_DATA_TBL_DELETE_EDITOR, editorDel); + deleteLabel.setData(KEY_DEL_ICON_DATA_TBL_ITEM, item); + + deleteLabel.addMouseTrackListener(new MouseTrackAdapter() { + @Override + public void mouseEnter(MouseEvent event) { + Image image = ImageResources.getImage(ImageResources.DIALOG_PROFILE_DELETE_OVER); + + deleteLabel.setImage(image); + } + + @Override + public void mouseExit(MouseEvent event) { + Image image = ImageResources.getImage(ImageResources.DIALOG_PROFILE_DELETE_NOR); + + deleteLabel.setImage(image); + } + + }); + deleteLabel.addMouseListener(new MouseAdapter() { + + @Override + public void mouseDown(MouseEvent event) { + Image image = ImageResources.getImage(ImageResources.DIALOG_PROFILE_DELETE_SEL); + + deleteLabel.setImage(image); + + } + + public void mouseUp(MouseEvent event) { + final TableItem item = (TableItem) deleteLabel.getData(KEY_DEL_ICON_DATA_TBL_ITEM); + table.setRedraw(false); + disposeEditor(item, KEY_TBL_ITEM_DATA_TBL_NAME_EDITOR); + disposeEditor(item, KEY_TBL_ITEM_DATA_TBL_DEVICE_EDITOR); + disposeEditor(item, KEY_TBL_ITEM_DATA_TBL_ORIENTATION_EDITOR); + disposeEditor(item, KEY_TBL_ITEM_DATA_TBL_DELETE_EDITOR); + table.remove(table.indexOf(item)); + table.pack(); + // addEmptyRow(); + table.pack(); + table.setRedraw(true); + if (isUniqueNames() && checkUniqueConfigurations()) { + setValidate(null); + } + } + }); + } + } + + private void addRow(Table tbl, ScreenConfiguration mScreenConfiguration, boolean bAddToBottom) { + String name = "", device = "", orientation = ""; //$NON-NLS-1$ + if (mScreenConfiguration != null) { + name = mScreenConfiguration.getName(); + device = mScreenConfiguration.getQualifier(MscreenConstants.DEVICE); + orientation = mScreenConfiguration.getQualifier(MscreenConstants.ORIENTATION); + } + + int iAddIdx = (bAddToBottom) ? tbl.getItemCount() : 1; // Add or init? + TableItem item = new TableItem(tbl, SWT.NONE, iAddIdx); + + Image makeHeightImage = new Image(tbl.getDisplay(), 22, 37); + + item.setImage(0, makeHeightImage); + item.setData(KEY_TBL_ITEM_DATA_MS_CONFIG, mScreenConfiguration); + + addBlankColumn(item, ""); + addNameColumn(item, name); + addDeviceColumn(item, device); + addOrientationColumn(item, orientation); + addDeleteColumn(item); + table.setBackgroundMode(SWT.INHERIT_FORCE); + table.pack(); + + } + + // + + // ms-util + private GridData createGridData(int style, int horizontalSpan, int horizontalAlignment, int widthHint) { + GridData gd = new GridData(style); + if (horizontalSpan > 0) + gd.horizontalSpan = horizontalSpan; + if (horizontalAlignment > 0) + gd.horizontalAlignment = horizontalAlignment; + if (widthHint > 0) + gd.widthHint = widthHint; + return gd; + } + + // ms-util + private void disposeEditor(TableItem item, String key) { + TableEditor tblEidtor = (TableEditor) item.getData(key); + if (tblEidtor != null) { + disposeEditor(tblEidtor); + } + } + + // ms-util + private void disposeEditor(TableEditor editor) { + // Dispose any existing editor + Control old = editor.getEditor(); + if (old != null) { + old.dispose(); + } + } + + // ms-util + private void editNameColumn(TableEditor editor, TableItem nameItem) { + + final int iCol = eTBLCol.NAME.value; + final TableItem item = nameItem; + final Text text = new Text(table, SWT.LEFT); + text.setTextLimit(NAME_COLUMN_MAX_LEN); + text.setText(item.getText(iCol)); + text.setForeground(item.getForeground()); + text.setFocus(); + text.selectAll(); + + // Recalculate the minimum width for the editor + editor.minimumWidth = text.getBounds().width; + editor.minimumHeight = text.getBounds().height; + // Set the control into the editor + editor.setEditor(text, item, iCol); + item.setData(KEY_TBL_ITEM_DATA_TBL_NAME_EDITOR, editor); + + // Add a handler to transfer the text back to the cell + // any time it's modified + // final int iCol = column; + + text.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent event) { + checkValidName(text.getText().trim(), item, iCol); + if (checkAllUnique()) { + setPageComplete(true); + } else { + setPageComplete(false); + } + + } + }); + text.addFocusListener(new FocusListener() { + + @Override + public void focusLost(FocusEvent arg0) { + checkValidName(text.getText().trim(), item, iCol); + if (checkAllUnique()) { + setPageComplete(true); + } else { + setPageComplete(false); + } + } + + @Override + public void focusGained(FocusEvent arg0) { + } + }); + + } + + private boolean checkValidName(String inputName, TableItem item, int iCol) { + boolean isSucceed = false; + int srcIdx = table.indexOf(item); + if (inputName.isEmpty()) { + setValidate(MscreenMessage.CONFIGURATOR_DLG_MSG_CONFIG_NAME_EMPTY); + item.setText(iCol, inputName); + } else if (inputName.length() >= NAME_COLUMN_MAX_LEN) { + setValidate(MscreenMessage.CONFIGURATOR_DLG_MSG_NAME_LENGTH); + item.setText(iCol, inputName); + } else if (!checkNameValue(inputName)) { + setValidate(MscreenMessage.CONFIGURATOR_DLG_MSG_CONFIG_NAME_REGX); + item.setText(iCol, inputName); + } else if (!isUniqueName(inputName, srcIdx)) { + item.setText(iCol, inputName); + } else { // succeed + item.setText(iCol, inputName); + if (checkUniqueConfigurations()) { + setValidate(null); + } + isSucceed = true; + } + return isSucceed; + } + + private void drawTable(Table tbl) { + tbl.setRedraw(false); + tbl.removeAll(); + List configurations = this.getScreenConfigurations(); + for (Iterator itr = configurations.iterator(); itr.hasNext();) { + ScreenConfiguration msConfiguration = itr.next(); + + addRow(tbl, msConfiguration, true); + + } + + tbl.setRedraw(true); + } + + private void createTableContents() { + String[] strColTitle = new String[] { " ", MscreenMessage.CONFIGURATOR_TBL_TITLE_NAME, MscreenMessage.CONFIGURATOR_TBL_TITLE_DEVICE, + MscreenMessage.CONFIGURATOR_TBL_TITLE_ORIENTATION, MscreenMessage.CONFIGURATOR_TBL_TITLE_DELETE }; + TableColumn[] columns = new TableColumn[strColTitle.length]; + + for (int i = 0; i < strColTitle.length; i++) { + if (i == 1) { + columns[i] = new TableColumn(table, SWT.LEFT); + } else { + columns[i] = new TableColumn(table, SWT.CENTER); + } + columns[i].setText(strColTitle[i]); + + } + + drawTable(table); + table.setBackground(ColorResources.DIALOG_TABLE_BG); + table.addListener(SWT.MeasureItem, tableActionListener); + + // Pack each column so initial display is good + for (int i = 0, n = columns.length; i < n; i++) { + columns[i].pack(); + } + + } + + private String[] getDeviceNames() { + String[] results = new String[deviceManager.getDevices().size()]; + int i = 0; + for (Device device : deviceManager.getDevices()) { + results[i] = device.getName(); + i++; + } + + return results; + } + + public void setContents(MScreenPart mscreenPart) { + this.mscreenPart = mscreenPart; + } + + private List getScreenConfigurations() { + List configurations = new ArrayList(); + for (Part part : mscreenPart.getChildren()) { + if (part instanceof ConfigurationPart) { + configurations.add(new ScreenConfiguration((ConfigurationPart) part)); + } + } + + return configurations; + } + + public Command getCommand() { + return this.compCmd; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/MscreenConstants.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/MscreenConstants.java new file mode 100644 index 0000000..70b77e8 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/MscreenConstants.java @@ -0,0 +1,42 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.mscreen.configurator; + +public class MscreenConstants { + + public static final String LOCALE_KEY = "@locale/"; //$NON-NLS-1$ + public static final String RESOURCE_KEY = "@resource/"; + public static final String RESOURCE_DIRECTORY = "/res/"; //$NON-NLS-1$ + public static final String CONFIGURATION_TYPE_COMMON = "common"; //$NON-NLS-1$ + + public static final String DEVICE = "device"; //$NON-NLS-1$ + public static final String ORIENTATION = "orientation"; //$NON-NLS-1$ + public static final String ORIENTATION_PORTRAIT = "portrait"; //$NON-NLS-1$ + public static final String ORIENTATION_LANDSCAPE = "landscape"; //$NON-NLS-1$ + + public static final String[] ORIENTATIONS = { + ORIENTATION_PORTRAIT, + ORIENTATION_LANDSCAPE + }; +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/MscreenMessage.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/MscreenMessage.java new file mode 100644 index 0000000..9e83ddd --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/MscreenMessage.java @@ -0,0 +1,65 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.mscreen.configurator; + +import org.eclipse.osgi.util.NLS; + + +public class MscreenMessage extends NLS { + + private static final String BUNDLE_NAME = MscreenMessage.class.getName(); + + public static String CONFIGURATOR_DLG_TITLE; + public static String CONFIGURATOR_DLG_FIRST_PAGE_TITLE; + public static String CONFIGURATOR_DLG_FIRST_PAGE_DESCRIPTION; + public static String CONFIGURATOR_DLG_BTN_ADD; + public static String CONFIGURATOR_DLG_BTN_DELETE; + + public static String CONFIGURATOR_TBL_TITLE_NAME; + public static String CONFIGURATOR_TBL_TITLE_DEVICE; + public static String CONFIGURATOR_TBL_TITLE_ORIENTATION; + public static String CONFIGURATOR_TBL_TITLE_DELETE; + + public static String CONFIGURATOR_DLG_MSG_NOT_UNIQ_ITEM; + public static String CONFIGURATOR_DLG_MSG_NOT_UNIQ_NAME; + public static String CONFIGURATOR_DLG_MSG_CONFIG_NAME_EMPTY; + public static String CONFIGURATOR_DLG_MSG_CONFIG_NAME_REGX; + public static String CONFIGURATOR_DLG_MSG_NAME_LENGTH; + + public static String RM_DND_ERR_TITLE_INVALID_PROJECT; + public static String RM_DND_MSG_TITLE_INVALID_PROJECT; + + public static String DEVICE_DETAILS_TITLE; + public static String DEVICE_DETAILS_WIDTH; + public static String DEVICE_DETAILS_HEIGHT; + public static String DEVICE_DETAILS_DPI; + public static String DEVICE_DETAILS_SIZE; + + static { + NLS.initializeMessages(BUNDLE_NAME, MscreenMessage.class); + } + + private MscreenMessage() { + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/MscreenMessage.properties b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/MscreenMessage.properties new file mode 100644 index 0000000..b299b90 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/MscreenMessage.properties @@ -0,0 +1,21 @@ +CONFIGURATOR_DLG_TITLE=Screen Configurations +CONFIGURATOR_DLG_FIRST_PAGE_TITLE=Manage screen configurations +CONFIGURATOR_DLG_FIRST_PAGE_DESCRIPTION=Specify the name, resolution, and orientation of the application screen. +CONFIGURATOR_DLG_BTN_ADD=Add +CONFIGURATOR_DLG_BTN_DELETE=Delete +CONFIGURATOR_TBL_TITLE_NAME=Name +CONFIGURATOR_TBL_TITLE_DEVICE=Resolution +CONFIGURATOR_TBL_TITLE_ORIENTATION=Orientation +CONFIGURATOR_TBL_TITLE_DELETE=Remove +CONFIGURATOR_DLG_MSG_NOT_UNIQ_ITEM=The same configuration already exists. Specify another configuration. +CONFIGURATOR_DLG_MSG_NOT_UNIQ_NAME=A configuration with the same name already exists. Enter another name. +CONFIGURATOR_DLG_MSG_CONFIG_NAME_EMPTY=Enter a screen name. +CONFIGURATOR_DLG_MSG_CONFIG_NAME_REGX=The name must begin with a letter (case-sensitivity alphabet or underscore), and can only contain letters (A-Z, a-z,_) and digits (0-9). +CONFIGURATOR_DLG_MSG_NAME_LENGTH=The name must be 1 - 30 characters long. +RM_DND_ERR_TITLE_INVALID_PROJECT=Drag-and-drop failure +RM_DND_MSG_TITLE_INVALID_PROJECT=Please select file in your current project (res directory only) +DEVICE_DETAILS_TITLE=Details: +DEVICE_DETAILS_WIDTH=- Width: +DEVICE_DETAILS_HEIGHT=- Height: +DEVICE_DETAILS_DPI=- DPI: +DEVICE_DETAILS_SIZE=- Size: \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/ScreenConfiguration.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/ScreenConfiguration.java new file mode 100644 index 0000000..95c4039 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/ScreenConfiguration.java @@ -0,0 +1,141 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.mscreen.configurator; + +import java.text.MessageFormat; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.tizen.common.util.Assert; +import org.tizen.efluibuilder.model.part.ConfigurationPart; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; + + +public final class ScreenConfiguration { + + private ConfigurationPart part = null; + + private String id = null; + private String name = null; + private String type = ""; + + private Map qualifiers = null; + + public ScreenConfiguration(ConfigurationPart part, String name, String type, Map qualifiers) { + this.part = part; + + this.id = part.getUniqueId(); + this.name = name; + this.type = type; + + if (qualifiers == null) { + qualifiers = createQualifiers(part); + } + this.qualifiers = qualifiers; + } + + public ScreenConfiguration(ConfigurationPart configurePart) { + this.part = configurePart; + this.id = configurePart.getUniqueId(); + this.name = configurePart.getName(); + this.type = configurePart.getConfigurationType(); + + this.qualifiers = createQualifiers(configurePart); + } + + public static Map createQualifiers(ConfigurationPart configPart) { + Map qualifiers = new HashMap(); + qualifiers.put(LayoutSchemaConstants.DEVICE, configPart.getDevice()); + qualifiers.put(LayoutSchemaConstants.ORIENTATION, configPart.getOrientation()); + return qualifiers; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public String getType() { + return type; + } + + public boolean isCommon() { + return MscreenConstants.CONFIGURATION_TYPE_COMMON.equals(this.type); + } + + public void setType(String type) { + if (type == null) { + return; + } + this.type = type; + } + + public String getQualifier(String key) { + Assert.notNull(key); + return qualifiers.get(key); + } + + public Iterator getQualifierKeys() { + return qualifiers.keySet().iterator(); + } + + public Map getQualifiers() { + return qualifiers; + } + + public String getDisplayName() { + StringBuffer results = new StringBuffer(name + " ("); + Iterator itr = getQualifierKeys(); + while (itr.hasNext()) { + String key = itr.next(); + results.append(getQualifier(key)); + + if (itr.hasNext()) { + results.append("_"); + } + } + + results.append(")"); + + return results.toString(); + } + + @Override + public String toString() { + return MessageFormat.format("{0}:{1}:{2}:{3}:{4}", + getId(), + getName(), + getType(), + getQualifier(MscreenConstants.DEVICE), + getQualifier(MscreenConstants.ORIENTATION)); + } + + public ConfigurationPart getPart() { + return this.part; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/TableContainInfo.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/TableContainInfo.java new file mode 100644 index 0000000..cb51168 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/configurator/TableContainInfo.java @@ -0,0 +1,83 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.mscreen.configurator; + +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; + + +public class TableContainInfo { + private int column; + private TableItem tableItem; + + protected TableContainInfo(int column, TableItem tableItem) { + this.column = column; + this.tableItem = tableItem; + } + + public void measureContainInfo(Table table, int x, int y) { + // Determine where the mouse was clicked + Point pt = new Point(x, y); + + // Determine which row was selected + TableItem[] tableItems = table.getItems(); + TableItem tableItemIter = null; + int column = -1; + + for (int itemIdx = 0; itemIdx < tableItems.length; itemIdx++) { + for (int colIdx = 0; colIdx < table.getColumnCount(); colIdx++) { + Rectangle rect = tableItems[itemIdx].getBounds(colIdx); + if (rect.contains(pt)) { + tableItemIter = tableItems[itemIdx]; + column = colIdx; + break; + } + } + } + final TableItem item = tableItemIter; + if ((item == null) || (column < 0)) { + this.column = -1; + this.tableItem = null; + return; + } else { + this.column = column; + this.tableItem = item; + } + } + + protected TableContainInfo(Table table, int x, int y) { + measureContainInfo(table, x, y); + } + + public int getColumn() { + return column; + } + + public TableItem getTableItem() { + return tableItem; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/rm/AutoCompleteTextUtil.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/rm/AutoCompleteTextUtil.java new file mode 100644 index 0000000..e88d0d7 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/rm/AutoCompleteTextUtil.java @@ -0,0 +1,155 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.mscreen.rm; + +import org.eclipse.jface.bindings.keys.KeyStroke; +import org.eclipse.jface.bindings.keys.ParseException; +import org.eclipse.jface.fieldassist.ContentProposal; +import org.eclipse.jface.fieldassist.ContentProposalAdapter; +import org.eclipse.jface.fieldassist.SimpleContentProposalProvider; +import org.eclipse.jface.fieldassist.TextContentAdapter; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Text; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class AutoCompleteTextUtil { + + private static Logger logger = LoggerFactory.getLogger(AutoCompleteTextUtil.class); + private static final String KEYSTROKE_PRESS = "Ctrl+Space"; //$NON-NLS-1$ + private static final String KEY_ENABLE_SHORTCUT = "enable-shortcut"; //$NON-NLS-1$ + private static final String LOG_PRINT_KEYSTROKE_EXCEPTION = "KeyStroke Parse Exception"; //$NON-NLS-1$ + private static final String LOG_PRINT_PROPOSALS_EXCEPTION = "This proposals are null or no data."; //$NON-NLS-1$ + + /** + * This method is used to provide the implementaion of eclipse autocompletion feature. User has + * to press "CTRL+Space" to see the autocompletion effect. + * + * @param text + * of type {@link Text} + * @param proposals + * of type String Array + * @param shortcut + * String if this Method use shortcut string, and null + * otherwise + * @param itemCommonImage + * Image if this Method use item image, and null otherwise + */ + public static void setAutoCompletion(Text text, String[] proposals, String shortcut, Image itemCommonImage) { + try { + String autoActivationCharacters = ""; + SimpleContentProposalProvider simpleContentProposalProvider = new SimpleContentProposalProvider(proposals); + StringBuffer buf = new StringBuffer(); + + if ((proposals == null) || (proposals.length < 1)) { + logger.warn(LOG_PRINT_PROPOSALS_EXCEPTION); + return; + } + + for (int i = 0; i < proposals.length; i++) { + if (proposals[i].length() == 0) + continue; + + char c = proposals[i].charAt(0); + if (autoActivationCharacters.indexOf(c) == -1) { + buf.append(c); + } + } + autoActivationCharacters = autoActivationCharacters + buf.toString(); + /* This is very important for pre-builtin text */ + autoActivationCharacters += text.getText(); + + KeyStroke keyStroke = null; + simpleContentProposalProvider.setFiltering(true); + try { + keyStroke = KeyStroke.getInstance(KEYSTROKE_PRESS); + } catch (ParseException e) { + logger.warn(LOG_PRINT_KEYSTROKE_EXCEPTION); + } + + final Text labelText = text; + final String labelShortcut = shortcut; + final Image labelItemCommonImage = itemCommonImage; + + boolean enableShortcutStatus = true; + labelText.setData(KEY_ENABLE_SHORTCUT, enableShortcutStatus); + ContentProposalAdapter proposalAdapter = new ContentProposalAdapter(text, new TextContentAdapter(), simpleContentProposalProvider, keyStroke, + autoActivationCharacters.toCharArray()); + + proposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE); + proposalAdapter.setLabelProvider(new ILabelProvider() { + + @Override + public void removeListener(ILabelProviderListener listener) { + } + + @Override + public boolean isLabelProperty(Object element, String property) { + return false; + } + + @Override + public void dispose() { + } + + @Override + public void addListener(ILabelProviderListener listener) { + } + + @Override + public String getText(Object element) { + /* + * This eventListener is inappropriate. Whenever text is matched, Same listener + * is added to Text object. Furthermore, this listener seems unnecessary. It + * works well without this listener. + */ + + boolean enableShortcutStatus = (Boolean) labelText.getData(KEY_ENABLE_SHORTCUT); + + if ((labelShortcut != null) && (labelShortcut.length() > 1)) { + String firstCh = labelShortcut.charAt(0) + ""; + String secondChs = labelShortcut.substring(1); + if (labelText.getText().equals(firstCh) && (enableShortcutStatus)) { // eg) + // "@" + labelText.insert(secondChs); // eg) "resource" + } + } + return ((ContentProposal) element).getLabel(); + } + + @Override + public Image getImage(Object element) { + return labelItemCommonImage; // + } + }); + + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/rm/IRMWrapper.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/rm/IRMWrapper.java new file mode 100644 index 0000000..33d035a --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/rm/IRMWrapper.java @@ -0,0 +1,42 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.mscreen.rm; + +import org.tizen.efluibuilder.core.configuration.device.ScreenDesc.DPI; + + +public interface IRMWrapper { + + public String getMsg(String id, String locale); + + public String[] getLocales(); + + public String getResourcePath(String id, DPI dpi, String locale); + + /* [START]==added by SBC for AutoCompleteText */ + public String[] getAllResourceKeys(String shortcutPrefixString, String[] extentionFilters); + + public String[] getMsgKeys(String shortcutPrefixString); + /* [END]==added by SBC for AutoCompleteText */ +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/rm/ResourceManagerUtil.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/rm/ResourceManagerUtil.java new file mode 100644 index 0000000..00f89a2 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/mscreen/rm/ResourceManagerUtil.java @@ -0,0 +1,310 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.mscreen.rm; + +import java.io.File; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.eclipse.core.resources.IProject; +import org.tizen.common.util.Assert; +import org.tizen.efluibuilder.core.configuration.device.ScreenDesc.DPI; +import org.tizen.efluibuilder.model.app.AppManager; +import org.tizen.efluibuilder.mscreen.configurator.MscreenConstants; +import org.tizen.nativecommon.po.INativeLocaleMessages; +import org.tizen.nativecommon.po.NativeLocaleMessageManager; +import org.tizen.nativecommon.rm.model.ITizenRMFeature; +import org.tizen.nativecommon.rm.model.RMHandler; +import org.tizen.nativecommon.rm.model.ResConfig.Key; +import org.tizen.nativecommon.rm.model.TizenDPI; +import org.tizen.nativecommon.rm.model.TizenLocale; + + +public final class ResourceManagerUtil { + + private IProject project = null; + + public ResourceManagerUtil(IProject project) { + this.project = project; + } + + private static final float SUPPORT_RM_VERSION = 2.4F; + public static final TizenLocale RM_LOCALE_ALL = TizenLocale.ALL; + + // for fallback resources + private static final int FB_STEP0_START = 0; // 0 + private static final int FB_STEP1_LOCALE_ALL = FB_STEP0_START + 1; // 1 + private static final int FB_STEP2_ALL_DPI = FB_STEP1_LOCALE_ALL + 1; // 2 + private static final int FB_STEP3_ALL_ALL = FB_STEP2_ALL_DPI + 1; // 3 + + private DPI selectedDpi = DPI.ALL; + private String selectedLocale = RM_LOCALE_ALL.getName(); + + // == [START]==added by SBC for AutoCompleteText==// + + public static boolean isAlternativeResourceSupport(String platformVersionString) { + platformVersionString = platformVersionString.substring(0, 3); // eg) 2.3.1 -> 2.3 + float platformVersionFloat = Float.parseFloat(platformVersionString); + if (platformVersionFloat >= SUPPORT_RM_VERSION) { // The alternative resource support 2.4 + // platform upper + return true; + } else { + return false; + } + } + + public String[] getAllResourceKeys(String shortcutPrefixString, String[] extentionFilters) { + + List listResourceKeys = new ArrayList(); + + // eg) projectPath==/home/sonbc121/workspace/UIBuilderSingleView + String projectResRootPath = project.getLocation().toString() + MscreenConstants.RESOURCE_DIRECTORY; + getResFilePaths(projectResRootPath, projectResRootPath, listResourceKeys, extentionFilters); + + String platformVersionString = AppManager.getAppManager().getVersion(); + + if (isAlternativeResourceSupport(platformVersionString)) { + getResourceKeys(shortcutPrefixString, listResourceKeys, extentionFilters); + } + return listResourceKeys.toArray(new String[listResourceKeys.size()]); + } + + private void getResFilePaths(String projectResRootPath, String resCurrentPath, List resourcePaths, String[] extentionFilters) { + String resRelativePath = null; + File file = new File(resCurrentPath); + File[] fileList = file.listFiles(); + + for (int i = 0; i < fileList.length; i++) { + File f = fileList[i]; + if (f.isDirectory()) { + getResFilePaths(projectResRootPath, f.getAbsolutePath(), resourcePaths, extentionFilters); + } else { + for (int j = 0; j < extentionFilters.length; j++) { + if (f.getPath().toLowerCase().endsWith(extentionFilters[j])) { + resRelativePath = f.getPath().substring(projectResRootPath.length()); + resourcePaths.add(resRelativePath); + } + } + } + } + return; + } + + private List getResourceKeys(String shortcutPrefixString, List listResourceKeys, String[] extentionFilters) { + + String defaultKeyAnnotationString = null; + RMHandler rmHandler = new RMHandler(project); + Set defaultKeysString = rmHandler.getDefaultKeysString(); + + if (defaultKeysString == null) { + return null; + } + + for (String keyString : defaultKeysString) { + for (int j = 0; j < extentionFilters.length; j++) { + if (keyString.toLowerCase().endsWith(extentionFilters[j])) { + if (shortcutPrefixString != null) { + defaultKeyAnnotationString = shortcutPrefixString + keyString; + } + listResourceKeys.add(defaultKeyAnnotationString); + break; + } + } + } + return listResourceKeys; + } + + public String[] getMsgKeys(String shortcutPrefixString) { + INativeLocaleMessages localeMessages = NativeLocaleMessageManager.getLocaleMessages(project); + + /* You must pass to null in order to get MsgIDs (default string) */ + String[] msgKeys = localeMessages.getMsgIds(null); + + if (msgKeys == null) + return null; + + /* add shortcut prefix string */ + if (shortcutPrefixString != null) { + for (int i = 0; i < msgKeys.length; i++) { + msgKeys[i] = shortcutPrefixString + msgKeys[i]; + } + } + return msgKeys; + } + + // == [END]==added by SBC for AutoCompleteText==// + + public String[] getLocales() { + List results = new ArrayList(); + results.add(RM_LOCALE_ALL.getName()); + // from RM(Resource Management) + RMHandler rmHandler = new RMHandler(project); + Set supportedLocales = rmHandler.getSupportedLocales(); + Iterator iterator = supportedLocales.iterator(); + while (iterator.hasNext()) { + ITizenRMFeature next = iterator.next(); + if (!results.contains(next.getName())) { + results.add(next.getName()); + } + } + + // from po + INativeLocaleMessages localeMessages = NativeLocaleMessageManager.getLocaleMessages(project); + String[] locales = localeMessages.getLocales(); + for (int i = 0; i < locales.length; i++) { + String locale = locales[i]; + if (!results.contains(locale)) { + results.add(locale); + } + } + + Collections.sort(results, new LocaleAscCompare()); + + return results.toArray(new String[results.size()]); + } + + /* + * RM(Image, Audio, Video....) + */ + + public String getResourcePath(String id, DPI dpi, String locale) { + if (id == null || id.equals("")) { + return null; + } + selectedDpi = dpi; + selectedLocale = locale; + + Key rmResKey = getFallbackRmResKey(id, dpi, locale, FB_STEP0_START); + if (rmResKey == null) { + return null; + } + // comment end + + String results = rmResKey.getRes().getFullPath().toString(); + int indexOf = results.indexOf(MscreenConstants.RESOURCE_DIRECTORY) + MscreenConstants.RESOURCE_DIRECTORY.length(); + results = results.substring(indexOf); + return results; + } + + private Key getFallbackRmResKey(String id, DPI dpi, String locale, int fallBackTargetStep) { + if (id == null || id.equals("")) { + return null; + } + + HashSet feature = new HashSet(); + feature.add(convertDPI(dpi)); + feature.add(convertLocale(locale)); + + RMHandler rmHandler = new RMHandler(project); + Key rmResKey = rmHandler.getResSpecificKey(id, feature); + + if (rmResKey != null) { + return rmResKey; + } + + fallBackTargetStep++; // change next-step + + // check next-step and call + switch (fallBackTargetStep) { + case FB_STEP1_LOCALE_ALL: + return getFallbackRmResKey(id, DPI.ALL, selectedLocale, fallBackTargetStep); + case FB_STEP2_ALL_DPI: + return getFallbackRmResKey(id, selectedDpi, RM_LOCALE_ALL.getName(), fallBackTargetStep); + case FB_STEP3_ALL_ALL: + return rmHandler.getResKey(id, feature); // get default key! + default: + break; + } + return rmResKey; + } + + /* + * PO editor(Locale) + */ + public String getMsg(String id, String locale) { + Assert.notNull(id); + INativeLocaleMessages localeMessages = NativeLocaleMessageManager.getLocaleMessages(project); + TizenLocale convertLocale = convertLocale(locale); + Assert.notNull(convertLocale); + return localeMessages.getMsgString(id, convertLocale); + } + + private TizenDPI convertDPI(DPI dpi) { + TizenDPI results = TizenDPI.ALL; + switch (dpi) { + case ALL: + results = TizenDPI.ALL; // for resource fallback + break; + case LDPI: + results = TizenDPI.LDPI; + break; + case MDPI: + results = TizenDPI.MDPI; + break; + case HDPI: + results = TizenDPI.HDPI; + break; + case XHDPI: + results = TizenDPI.XHDPI; + break; + case XXHDPI: + results = TizenDPI.XXHDPI; + break; + default: + + } + + return results; + } + + private TizenLocale convertLocale(String locale) { + if (locale == null) { + return RM_LOCALE_ALL; + } + + TizenLocale[] locales = TizenLocale.values(); + for (int i = 0; i < locales.length; i++) { + TizenLocale tizenLocale = locales[i]; + if (tizenLocale.getName().equals(locale)) { + return tizenLocale; + } + } + return RM_LOCALE_ALL; + } + + static class LocaleAscCompare implements Comparator, Serializable { + private static final long serialVersionUID = -4912444302160863880L; + + @Override + public int compare(String arg0, String arg1) { + return arg0.compareTo(arg1); + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/nl/BuilderMessages.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/nl/BuilderMessages.java new file mode 100644 index 0000000..3890583 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/nl/BuilderMessages.java @@ -0,0 +1,131 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.nl; + +import org.eclipse.osgi.util.NLS; + + +public final class BuilderMessages { + + private static final String BUNDLE_NAME = BuilderMessages.class.getName(); + + /************************************************************************** + * Design Editor + ***************************************************************************/ + public static String TABTEXTDESIGN; + public static String TABTEXTTEXTEDITOR; + public static String TABTEXTPRVIEW; + public static String TABTEXTSTORYBOARD; + + // ScaleControlToolbar tooltip + public static String SCREEN_PERCENTAGE; + public static String AUTO_FIT; + public static String AUTO_FIT_ON; + public static String AUTO_FIT_OFF; + public static String ZOOM_IN; + public static String ZOOM_OUT; + public static String ROTATE; + public static String DESIGNERMODE; + + // MscreenDesignToolbar messages + public static String MS_DESIGN_LAUNCH_CONFIGURATION; + + // MscreenDesignToolbar tooltip + public static String MS_CONFIG_BTN; + public static String MS_DESIGN_CONFIGURATION; + public static String MS_DESIGN_CONFIGURATION_NONE; + + // MscreenPreviewToolbar tooltip + public static String MS_PREVIEW_DEVICE; + public static String MS_PREVIEW_ORIENTATION; + public static String MS_PREVIEW_LOCALE; + + // ViewControlToolbar tooltip + public static String SELECT_VIEW; + public static String PREV_VIEW; + public static String NEXT_VIEW; + + // EditorModeToolbar tooltip + public static String SOURCE_MODE; + public static String DESIGN_MODE; + + // StoryboardAutoLayoutToolbar tooltip + public static String AUTO_LAYOUT; + + // View Title + public static String POPUP_VIEW_TITLE; + public static String CTX_POPUP_VIEW_TITLE; + + /************************************************************************** + * Error Messages + ***************************************************************************/ + // ==[START]==150408: added by sonbc121: implementation for C Standard Styled Widget ID==// + public static String ERROR_ID_INVALID_REGX; + public static String ERROR_ID_EQUALS_RESERVED_WORD; + // ==[END]==150408: added by sonbc121: implementation for C Standard Styled Widget ID==// + // Properties view, Outline view error tooltip + public static String ERROR_STRING_VALUE; + public static String ERROR_INTEGER_VALUE; + public static String ERROR_INTEGER_RANGE; + public static String ERROR_DOUBLE_VALUE; + public static String ERROR_STRING_ID; + public static String ERROR_STRING_PAGE_ID; + public static String ERROR_STRING_MAX_LENGTH; + public static String ERROR_INTEGER_MIN; + public static String ERROR_INTEGER_MIN_BY; + public static String ERROR_INTEGER_MAX; + public static String ERROR_INTEGER_MAX_BY; + public static String ERROR_INTEGER_MIN_BY_PARENT_PROPERTY; + public static String ERROR_INTEGER_MAX_BY_PARENT_PROPERTY; + public static String ERROR_SIZE_MAX; + public static String ERROR_STYLE_SIZE_UNIT; + public static String ERROR_STYLE_SIZE_NUMBER; + public static String ERROR_INVALID_XML_TITLE; + public static String ERROR_INVALID_XML_DESCRIPTION_01; + public static String ERROR_INVALID_XML_DESCRIPTION_02; + + /************************************************************************** + * Component designer + ***************************************************************************/ + public static String COMPONENT_DESIGNER_DIALOG_TITLE; + public static String COMPONENT_DESIGNER_DIALOG_LABEL; + public static String COMPONENT_DESIGNER_BUTTON_DELETE; + public static String COMPONENT_DESIGNER_BUTTON_MODIFY; + public static String COMPONENT_DESIGNER_BUTTON_EXTEND; + public static String COMPONENT_DESIGNER_BUTTON_RESET; + public static String COMPONENT_DESIGNER_LABEL_INPUT; + public static String COMPONENT_DESIGNER_BUTTON_OK; + public static String COMPONENT_DESIGNER_BUTTON_CANCEL; + + static { + NLS.initializeMessages(BUNDLE_NAME, BuilderMessages.class); + } + + /** + * Constructor. + */ + private BuilderMessages() { + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/nl/BuilderMessages.properties b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/nl/BuilderMessages.properties new file mode 100644 index 0000000..5eedb90 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/nl/BuilderMessages.properties @@ -0,0 +1,84 @@ +################################################################### +# Design Editor +################################################################### +TABTEXTDESIGN=Design +TABTEXTTEXTEDITOR=Source +TABTEXTPRVIEW=Preview +TABTEXTSTORYBOARD=Storyboard + +# ScaleControlToolbar tooltip +SCREEN_PERCENTAGE=Screen percentage +AUTO_FIT=Fit to Screen +AUTO_FIT_ON=Turn on Autofit +AUTO_FIT_OFF=Turn off Autofit +ZOOM_IN=Zoom in +ZOOM_OUT=Zoom out +ROTATE=Rotate +DESIGNERMODE=Designer Mode + +# MscreenDesignToolbar messages +MS_DESIGN_LAUNCH_CONFIGURATION=Edit Screen Configuration + +# MscreenDesignToolbar tooltip +MS_CONFIG_BTN=Screen Configurator +MS_DESIGN_CONFIGURATION=Screen Configuration +MS_DESIGN_CONFIGURATION_NONE=None + +# MscreenPreviewToolbar tooltip +MS_PREVIEW_DEVICE=Resolution +MS_PREVIEW_ORIENTATION=Orientation +MS_PREVIEW_LOCALE=Locale + +# ViewControlToolbar tooltip +SELECT_VIEW=Select view +PREV_VIEW=Previous view +NEXT_VIEW=Next view + +# EditorModeToolbar tooltip +SOURCE_MODE=Source Editor +DESIGN_MODE=Design Editor + +# StoryboardAutoLayoutToolbar tooltip +AUTO_LAYOUT=Auto Layout + +# View Title +POPUP_VIEW_TITLE=(Popup) +CTX_POPUP_VIEW_TITLE=(Ctxpopup) + +#==[START] 150408: added by sonbc121: implementation for C Standard Styled Widget ID====// +ERROR_ID_INVALID_REGX=The ID can be composed of alphabets, digits and underscore ("_"), and must not begin with a digit. +ERROR_ID_EQUALS_RESERVED_WORD=The ID uses a reserved word and is consequently invalid. +#==[END] 150408: added by sonbc121: implementation for C Standard Styled Widget ID====// + +#Properties view, Outline view error tooltip +ERROR_STRING_VALUE=The string is invalid; you can only enter an alphabet, a number, or a '_'. +ERROR_INTEGER_VALUE=The value must be an integer. +ERROR_INTEGER_RANGE=The value must be in integer range. +ERROR_DOUBLE_VALUE=The value must be a double. +ERROR_STRING_ID=The ID must be unique in a view. +ERROR_STRING_PAGE_ID=The ID must be unique in a project. +ERROR_STRING_MAX_LENGTH=The maximum length of the string is {0}. +ERROR_INTEGER_MIN=The value cannot be less than {0}. +ERROR_INTEGER_MIN_BY=The value cannot be less than value of the {0} property. +ERROR_INTEGER_MAX=The value cannot be more than {0}. +ERROR_INTEGER_MAX_BY=The value cannot be more than value of the {0} property. +ERROR_INTEGER_MIN_BY_PARENT_PROPERTY=The value cannot be less than value of the parents {0} property. +ERROR_INTEGER_MAX_BY_PARENT_PROPERTY=The value cannot be more than value of the parents {0} property. +ERROR_SIZE_MAX=The value cannot be more than value of the container size. +ERROR_STYLE_SIZE_UNIT = The unit must be px, %, em, or cm. +ERROR_STYLE_SIZE_NUMBER = Enter a number. +ERROR_INVALID_XML_TITLE=Invalid XML +ERROR_INVALID_XML_DESCRIPTION_01=You must fix the layout in the Source Editor +ERROR_INVALID_XML_DESCRIPTION_02=before you can edit your application in the Design Editor. + +#Component designer +COMPONENT_DESIGNER_DIALOG_TITLE=Component Designer: Style design +COMPONENT_DESIGNER_DIALOG_LABEL=After you edit a style from the component designer or remove styles,\n\ +please refresh your project in the Project Explorer. +COMPONENT_DESIGNER_BUTTON_DELETE=Delete +COMPONENT_DESIGNER_BUTTON_MODIFY=Modify +COMPONENT_DESIGNER_BUTTON_EXTEND=Extend +COMPONENT_DESIGNER_BUTTON_RESET=Reset +COMPONENT_DESIGNER_LABEL_INPUT=New Style +COMPONENT_DESIGNER_BUTTON_OK=OK +COMPONENT_DESIGNER_BUTTON_CANCEL=Cancel diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/storyboard/codegenerator/CodeGenerator.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/storyboard/codegenerator/CodeGenerator.java new file mode 100644 index 0000000..9e14df1 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/storyboard/codegenerator/CodeGenerator.java @@ -0,0 +1,147 @@ +/* + * UI Builder - StoryBoard + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * - S-Core Co., Ltd + * + */ + + +package org.tizen.efluibuilder.storyboard.codegenerator; + +import java.io.File; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.PlatformUI; +import org.tizen.efluibuilder.codegenerator.CodeGeneratorException; +import org.tizen.efluibuilder.codegenerator.ICodeGenerator; +import org.tizen.efluibuilder.codegenerator.event.EventCodeGenerator; +import org.tizen.efluibuilder.codegenerator.event.EventCodeGeneratorUtil; +import org.tizen.efluibuilder.codegenerator.event.IEventCodeGenerator; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.ui.editor.designeditor.DesignEditorException; +import org.tizen.efluibuilder.ui.views.properties.events.HandlerCodeWriter; +import org.tizen.efluibuilder.ui.views.properties.events.IHandlerCodeWriter; + + +/** + * Code generator for storyboard connection + * + */ +public class CodeGenerator { + private IHandlerCodeWriter codeWriter = new HandlerCodeWriter(); + private IProject project; + + public CodeGenerator(IProject project) { + this.project = project; + } + + /** + * Create action for the sourcePart + * + * @param command + * @return + */ + + public boolean addConnectionAction(Part sourcePart, String eventName, String functionName) { + if (sourcePart != null) { + ComponentDescriptor componentDescriptor = sourcePart.getOwnerDocumentPart().getComponentDescriptor(); + String eventInfo = componentDescriptor.getEventInfo((ComponentPart) sourcePart, eventName); + String pageID = ((ComponentPart) sourcePart).getOwnerViewPart().getPropertyValue(LayoutSchemaConstants.ID); + IFile ifile = getFile(pageID); + if (ifile != null) { + String projectName = ifile.getProject().getName(); + if (projectName != null && projectName.equals(project.getName())) { + codeWriter.addConnectionHandler(functionName, pageID, CodeGeneratorUtil.getEventParams(sourcePart, eventName), eventInfo); + // Create a worker thread to generate managed code section + ExecutorService executor = Executors.newFixedThreadPool(1); + executor.execute(new GenerateManagedCode()); + executor.shutdown(); + } + } + } else { + // SBLoggerManager.logErrorMessage(CodeGenerator.class, + // Messages.CodeGenerator_SRC_PART_NULL + connectionData.getSource() + + // SBConstants.EMPTY_SPACE + connectionData.getParent()); + } + return true; + } + + /** + * Retrieve code writer handler + * + * @return + */ + public IHandlerCodeWriter getCodeWriter() { + return codeWriter; + } + + /** + * Retrieve design editor + * + * @return + */ + + private class GenerateManagedCode implements Runnable { + + @Override + public void run() { + File managedFolder = new File(new File(project.getLocation().toString()), Messages.CodeGenerator_2); + if (!managedFolder.exists()) { + ICodeGenerator generator = new org.tizen.efluibuilder.codegenerator.CodeGenerator(project); + try { + generator.generate(); + } catch (CodeGeneratorException e) { + throw new DesignEditorException(e.getMessage()); + } + } + } + } + + private IFile getFile(String id) { + IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); + if (editorPart == null) { + return null; + } + + IFileEditorInput input = (IFileEditorInput) editorPart.getEditorInput(); + IFile file = input.getFile(); + IProject project = file.getProject(); + IFile eventHandlerFile = EventCodeGeneratorUtil.getEventHandlerFile(project, id); + if (eventHandlerFile.exists()) { + return eventHandlerFile; + } + + IEventCodeGenerator generator = new EventCodeGenerator(project); + try { + generator.addView(id); + } catch (CodeGeneratorException e) { + // SBLoggerManager.logErrorMessage(CodeGenerator.class, e.getMessage()); + } + + return eventHandlerFile; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/storyboard/codegenerator/CodeGeneratorConstants.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/storyboard/codegenerator/CodeGeneratorConstants.java new file mode 100644 index 0000000..a358a7b --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/storyboard/codegenerator/CodeGeneratorConstants.java @@ -0,0 +1,49 @@ +/* + * UI Builder - StoryBoard + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + + +package org.tizen.efluibuilder.storyboard.codegenerator; + +import org.tizen.efluibuilder.BuilderConstants; + + +public class CodeGeneratorConstants { + public static final String PAGENAME = "$(page_name)"; + public static final String FUNCNAME = "%FuncName%"; + public static final String FUNCPARAMS = "%FuncParams%"; + public static final String EVENT_HANDLER_SIGNATURE = "\nvoid " + FUNCNAME + "(" + FUNCPARAMS + ")"; + public static final String COMMENT = "\t// This method is added by Storyboard\n"; + public static final String EVENT_PREFIX = "on"; + public static final String EVENT_UNDERSCORE = "_"; + public static final String LAYOUT_FOLDER = "layout"; + public static final String LAYOUT_XML = "layout.xml"; + public static final String CONNECTION_WRAPPER = "connection_"; + public static final String WRAPPER_COMMENT_PRE = BuilderConstants.TAB + BuilderConstants.COMMENT + "Invoked at the start of wrapper function "; + public static final String WRAPPER_COMMENT_POST = BuilderConstants.TAB + BuilderConstants.COMMENT + "Invoked post wrapper function "; + public static final String WRAPPER_COMMENT = BuilderConstants.COMMENT + "Invoked"; + public static final String WRAPPER_POST = "_post"; + public static final String WRAPPER_PARAM = "void* param, "; + public static final String SUBTITLE_SET_METHOD = "\telm_object_item_part_text_set(navi_item, \"subtitle\", "; + public static final String QUOTES = "\""; + public static final String TYPE_POST = "post"; + public static final String TYPE_PRE = "pre"; +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/storyboard/codegenerator/CodeGeneratorUtil.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/storyboard/codegenerator/CodeGeneratorUtil.java new file mode 100644 index 0000000..c7dcb22 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/storyboard/codegenerator/CodeGeneratorUtil.java @@ -0,0 +1,141 @@ +/* + * UI Builder - StoryBoard + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + + +package org.tizen.efluibuilder.storyboard.codegenerator; + +import java.util.List; + +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.model.descriptors.EventDescriptor; +import org.tizen.efluibuilder.model.descriptors.EventParamDescriptor; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.EventPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; + + +public class CodeGeneratorUtil { + + public static String getWrapperComment(String pageID, String funcName, String type) { + String comment; + if (type.equals(CodeGeneratorConstants.TYPE_POST)) + comment = CodeGeneratorConstants.WRAPPER_COMMENT_POST; + else + comment = CodeGeneratorConstants.WRAPPER_COMMENT_PRE; + return comment + pageID + BuilderConstants.UNDERSCORE + CodeGeneratorConstants.CONNECTION_WRAPPER + funcName + "\n"; + } + + public static String getFunctionDefinition(String pageID, String funcName, String type) { + return CodeGeneratorConstants.EVENT_HANDLER_SIGNATURE + " {\n" + getWrapperComment(pageID, funcName, type) + "\n}\n"; + } + + /* + * public static String getChangePage(ConnectionData connectionData) { String changePage = ""; + * if (connectionData != null) { changePage = + * "Elm_Object_Item* navi_item = change_page(vc->parent, \"" + + * connectionData.getConnectionPropertyValue(PropertiesConstant.PROPERTY_TITLE) + + * "\", NULL, NULL, \"" + + * connectionData.getConnectionPropertyValue(PropertiesConstant.PROPERTY_TARGET_VIEW) + + * "\", NULL);"; } return changePage; } + */ + + /** + * Remove target attribute from the action of the source widget + * + * @param sourcePart + * @param event + */ + public static void removeTargetFromAction(Part sourcePart, String event) { + List events = ((ComponentPart) sourcePart).getEventParts(); + for (EventPart child : events) { + if (event.equals(child.getPropertyValue(LayoutSchemaConstants.EVENT_SIGNAL))) { + sourcePart.removeChild(child); + // events.remove(child); // Removing the event + } + } + } + + + /** + * Retrieve parameters for events + * + * @param model + * @param id + * @return + */ + public static List getEventParams(Part model, String eventName) { + ComponentDescriptor componentDescriptor = model.getOwnerDocumentPart().getComponentDescriptor(); + final List events = componentDescriptor.getEventDescriptors((ComponentPart) model); + List params = null; + for (EventDescriptor event : events) { + if (event.getEventName().equals(eventName)) { + params = event.getEventTypeDescriptor().getEventParameters(); + break; + } + } + return params; + } + + /** + * Check if the event exists in the widget + * + * @param sourcePart + * @param event + * @return + */ + public static boolean isEventExists(Part sourcePart, String event) { + List events = ((ComponentPart) sourcePart).getEventParts(); + for (EventPart child : events) { + if (event.equals(child.getPropertyValue(LayoutSchemaConstants.EVENT_SIGNAL))) { + return true; + } + + } + + return false; + } + + /** + * Create connection code upon undo of delete view + * + * @param connection + * @param editor + * @param model + */ + /* + * public static void codeGenForUndoDeleteView(Connection connection, DesignEditor editor, + * Storyboard model) { ConnectionData connectionData = connection.getConnectionData(); String + * event = CodeGeneratorConstants.EVENT_PREFIX + connection.getConnectionData().getEvent(); + * WidgetAction partAction = new WidgetAction(ActionType.RUN_JAVASCRIPT_FUNCTION, + * connection.getSource().getIdPartPropertyValue() + CodeGeneratorConstants.EVENT_UNDERSCORE + + * event, null, connectionData); if (connection.getSource() != null) { if + * (!isEventExists(connection.getSource(), event)) connection.getSource().addPartAction(event, + * partAction, false); IHandlerCodeWriter codeWriter = new HandlerCodeWriter(); String eventInfo + * = editor.getPartDescriptor().getEventInfo(connection.getSource(), event); + * codeWriter.addConnectionHandler(connection.getSource().getIdPartPropertyValue() + + * CodeGeneratorConstants.EVENT_UNDERSCORE + event, connection.getSource().getOwnerPage() + * .getIdPartPropertyValue(), CodeGeneratorUtil.getEventParams(editor, connection.getSource(), + * event), eventInfo); } } + */ +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/storyboard/codegenerator/Messages.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/storyboard/codegenerator/Messages.java new file mode 100644 index 0000000..ee4bdfc --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/storyboard/codegenerator/Messages.java @@ -0,0 +1,51 @@ +/* + * UI Builder - StoryBoard + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + + +package org.tizen.efluibuilder.storyboard.codegenerator; + +import org.eclipse.osgi.util.NLS; + + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.tizen.efluibuilder.storyboard.codegenerator.messages"; //$NON-NLS-1$ + public static String CodeGenerator_0; + public static String CodeGenerator_2; + public static String CodeGenerator_CHANGE_PAGE_METHOD; + public static String CodeGenerator_COMMA; + public static String CodeGenerator_CHANGE_END; + public static String CodeGenerator_CHANGE_START; + public static String CodeGenerator_COMMENT_START; + public static String CodeGenerator_COMMENT_END; + public static String CodeGenerator_SRC_PART_NULL; + public static String StoryboardMouseListener_PART_NULL_ERROR; + public static String StoryboardViewer_EFL_NAVIFRAME; + public static String StoryboardViewer_NAVIFRAME_MSG; + public static String StoryboardViewer_SAME_VIEW_MSG; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/storyboard/codegenerator/messages.properties b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/storyboard/codegenerator/messages.properties new file mode 100644 index 0000000..c6b59ca --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/storyboard/codegenerator/messages.properties @@ -0,0 +1,13 @@ +StoryboardMouseListener_PART_NULL_ERROR=Source or Target Part is null +StoryboardViewer_EFL_NAVIFRAME=efl.naviframe +StoryboardViewer_NAVIFRAME_MSG=Cannot add naviframe view +StoryboardViewer_SAME_VIEW_MSG=\ already added +CodeGenerator_0= +CodeGenerator_2=src/managed +CodeGenerator_CHANGE_PAGE_METHOD=change_page +CodeGenerator_COMMA=, +CodeGenerator_CHANGE_END=; +CodeGenerator_COMMENT_START=/* +CodeGenerator_COMMENT_END=*/ +CodeGenerator_CHANGE_START=Elm_Object_Item +CodeGenerator_SRC_PART_NULL=Source Part is null diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/storyboard/gef/policies/NodeComponentEditPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/storyboard/gef/policies/NodeComponentEditPolicy.java new file mode 100644 index 0000000..322dad8 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/storyboard/gef/policies/NodeComponentEditPolicy.java @@ -0,0 +1,31 @@ +/* + * UI Builder - StoryBoard + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + + +package org.tizen.efluibuilder.storyboard.gef.policies; + +import org.eclipse.gef.editpolicies.ComponentEditPolicy; + + +public class NodeComponentEditPolicy extends ComponentEditPolicy { + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/storyboard/gef/policies/NodeGraphicalNodeEditPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/storyboard/gef/policies/NodeGraphicalNodeEditPolicy.java new file mode 100644 index 0000000..b2263dd --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/storyboard/gef/policies/NodeGraphicalNodeEditPolicy.java @@ -0,0 +1,54 @@ +/* + * UI Builder - StoryBoard + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + + +package org.tizen.efluibuilder.storyboard.gef.policies; + +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.editpolicies.GraphicalNodeEditPolicy; +import org.eclipse.gef.requests.CreateConnectionRequest; +import org.eclipse.gef.requests.ReconnectRequest; + + +public class NodeGraphicalNodeEditPolicy extends GraphicalNodeEditPolicy { + + private static class ConnectionStartCommand extends Command { + + } + + protected Command getConnectionCompleteCommand(CreateConnectionRequest request) { + return null; + } + + protected Command getConnectionCreateCommand(CreateConnectionRequest request) { + return new ConnectionStartCommand(); + } + + protected Command getReconnectTargetCommand(ReconnectRequest request) { + return null; + } + + protected Command getReconnectSourceCommand(ReconnectRequest request) { + return null; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/SelectionManager.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/SelectionManager.java new file mode 100644 index 0000000..6c0fb5b --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/SelectionManager.java @@ -0,0 +1,70 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui; + +import org.eclipse.core.commands.common.EventManager; +import org.eclipse.core.runtime.SafeRunner; +import org.eclipse.jface.util.SafeRunnable; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; + + +public class SelectionManager extends EventManager { + /** + * + * @param listener + * listen + */ + public void addSelectionChangedListener(ISelectionChangedListener listener) { + addListenerObject(listener); + } + + /** + * + * @param listener + * listen + */ + public void removeSelectionChangedListener(ISelectionChangedListener listener) { + removeListenerObject(listener); + } + + /** + * + * @param event + * the event + */ + public void selectionChanged(final SelectionChangedEvent event) { + // pass on the notification to listeners + Object[] listeners = getListeners(); + for (int i = 0; i < listeners.length; ++i) { + final ISelectionChangedListener l = (ISelectionChangedListener) listeners[i]; + SafeRunner.run(new SafeRunnable() { + @Override + public void run() { + l.selectionChanged(event); + } + }); + } + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/SelectionProvider.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/SelectionProvider.java new file mode 100644 index 0000000..62e77fc --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/SelectionProvider.java @@ -0,0 +1,87 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui; + +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; + + +public class SelectionProvider implements ISelectionProvider { + private SelectionManager selectionListener = new SelectionManager(); + private ISelection selection; + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener + * (org.eclipse.jface.viewers.ISelectionChangedListener) + */ + @Override + public void addSelectionChangedListener(ISelectionChangedListener listener) { + selectionListener.addSelectionChangedListener(listener); + } + + /* + * (non-Javadoc) Method declared on ISelectionProvider. + */ + @Override + public void removeSelectionChangedListener(ISelectionChangedListener listener) { + selectionListener.removeSelectionChangedListener(listener); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse + * .jface.viewers.ISelection) + */ + @Override + public void setSelection(ISelection selection) { + this.selection = selection; + selectionChanged(new SelectionChangedEvent(this, selection)); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection() + */ + @Override + public ISelection getSelection() { + return selection; + } + + /** + * The selection has changed. Process the event, notifying selection listeners and post + * selection listeners. + * + * @param event + * the change + */ + public void selectionChanged(final SelectionChangedEvent event) { + selectionListener.selectionChanged(event); + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/SelectionProviderAdapter.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/SelectionProviderAdapter.java new file mode 100644 index 0000000..e5cf6e6 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/SelectionProviderAdapter.java @@ -0,0 +1,92 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui; + +import org.eclipse.core.commands.common.EventManager; +import org.eclipse.core.runtime.SafeRunner; +import org.eclipse.jface.util.SafeRunnable; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; + + +/** + * Provides an simple implementation of {@link ISelectionProvider} that propagates selection events + * to registered listeners. + * + * @author Steffen Pingel + * @since 3.7 + */ +public class SelectionProviderAdapter extends EventManager implements ISelectionProvider, ISelectionChangedListener { + private ISelection selection; + + /** + * Constructs a SelectionProviderAdapter and initializes the selection to + * selection. + * + * @param selection + * the initial selection + * @see #setSelection(ISelection) + */ + public SelectionProviderAdapter(ISelection selection) { + setSelection(selection); + } + + /** + * Constructs a SelectionProviderAdapter with a null selection. + */ + public SelectionProviderAdapter() { + } + + public void addSelectionChangedListener(ISelectionChangedListener listener) { + addListenerObject(listener); + } + + public ISelection getSelection() { + return selection; + } + + public void removeSelectionChangedListener(ISelectionChangedListener listener) { + removeListenerObject(listener); + } + + public void selectionChanged(final SelectionChangedEvent event) { + this.selection = event.getSelection(); + Object[] listeners = getListeners(); + for (Object listener2 : listeners) { + final ISelectionChangedListener listener = (ISelectionChangedListener) listener2; + SafeRunner.run(new SafeRunnable() { + public void run() { + listener.selectionChanged(event); + } + }); + } + } + + public void setSelection(ISelection selection) { + selectionChanged(new SelectionChangedEvent(this, selection)); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/actions/ActionConstants.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/actions/ActionConstants.java new file mode 100644 index 0000000..0174021 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/actions/ActionConstants.java @@ -0,0 +1,102 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.actions; + +import org.eclipse.gef.ui.actions.GEFActionConstants; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.actions.ActionFactory; + + +public final class ActionConstants implements IWorkbenchActionConstants { + + public static final String ALIGN = "Align"; + public static final String ALIGN_LEFT = GEFActionConstants.ALIGN_LEFT; + public static final String ALIGN_TOP = GEFActionConstants.ALIGN_TOP; + public static final String ALIGN_RIGHT = GEFActionConstants.ALIGN_RIGHT; + public static final String ALIGN_BOTTOM = GEFActionConstants.ALIGN_BOTTOM; + public static final String ALIGN_VERTICAL_CENTER = GEFActionConstants.ALIGN_MIDDLE; + public static final String ALIGN_HORIZONTAL_CENTER = GEFActionConstants.ALIGN_CENTER; + + public static final String ALIGN_DISTRIBUTE_VERTICAL_SPACING = "org.tizen.efluibuilder.align_v_distribute";//$NON-NLS-1$ + public static final String ALIGN_DISTRIBUTE_HORIZONTAL_SPACING = "org.tizen.efluibuilder.align_h_distribute";//$NON-NLS-1$ + + public static final String MATCH_SIZE = "Match Size"; + public static final String MATCH_WIDTH = GEFActionConstants.MATCH_WIDTH; + public static final String MATCH_HEIGHT = GEFActionConstants.MATCH_HEIGHT; + + public static final String NAVIGATE_SELECTION = "Select"; + public static final String CHANGE_SELECTION = "org.tizen.efluibuilder.select";//$NON-NLS-1$ + public static final String SELECT_PARENT = "org.tizen.efluibuilder.select_parent";//$NON-NLS-1$ + public static final String SELECT_CHILD = "org.tizen.efluibuilder.select_child";//$NON-NLS-1$ + public static final String SELECT_PREV_SIBLING = "org.tizen.efluibuilder.select_prev_sibling";//$NON-NLS-1$ + public static final String SELECT_NEXT_SIBLING = "org.tizen.efluibuilder.select_next_sibling";//$NON-NLS-1$ + + public static final String DELETE_PART = ActionFactory.DELETE.getId(); + public static final String UNDO = ActionFactory.UNDO.getId(); + public static final String REDO = ActionFactory.REDO.getId(); + public static final String CUT_PART = ActionFactory.CUT.getId(); + public static final String COPY_PART = ActionFactory.COPY.getId(); + public static final String PASTE_PART = ActionFactory.PASTE.getId(); + public static final String PASTE_PART_COLOR = "org.tizen.efluibuilder.paste.color";//$NON-NLS-1$ + + public static final String ZORDER_FRONT = "org.tizen.efluibuilder.zorder.front";//$NON-NLS-1$ + public static final String ZORDER_BACK = "org.tizen.efluibuilder.zorder.back";//$NON-NLS-1$ + public static final String ZORDER = "org.tizen.efluibuilder.group.zorder";//$NON-NLS-1$ + public static final String ZORDER_FRONTWARD = "org.tizen.efluibuilder.zorder.frontward";//$NON-NLS-1$ + public static final String ZORDER_BACKWARD = "org.tizen.efluibuilder.zorder.backward";//$NON-NLS-1$ + public static final String GROUP_ZORDER = "org.tizen.efluibuilder.group.zorder";//$NON-NLS-1$ + public static final String NEW = "New";//$NON-NLS-1$ + public static final String ADD_VIEW_EMPTY = "org.tizen.efluibuilder.add_view_empty";//$NON-NLS-1$ + public static final String SET_STARTUP_VIEW = "org.tizen.efluibuilder.set_startup_view";//$NON-NLS-1$ + + public static final String STORYBOARD = "storyboard"; + public static final String ALIGN_STORYBOARD = "org.tizen.efluibuilder.align_storyboard";//$NON-NLS-1$ + + public static final String OPEN_EDC_EDITOR = "org.tizen.efluibuilder.open_edc_editor";//$NON-NLS-1$ + public static final String FIT_TO_SINGLE_VIEW = "org.tizen.efluibuilder.fit_to_single_view";//$NON-NLS-1$ + + public static final String VIEW = "view";//$NON-NLS-1$ + + /** + * New Snippet action id. Value: "org.tizen.efluibuilder.newSnippet" + */ + public static final String NEW_SNIPPET = "org.tizen.efluibuilder.newSnippet";//$NON-NLS-1$ + + /** + * Delete Snippet action id. Value: "org.tizen.efluibuilder.deleteSnippet" + */ + public static final String DELETE_SNIPPET = "org.tizen.efluibuilder.deleteSnippet";//$NON-NLS-1$ + + /** + * Import Snippet action id. Value: "org.tizen.efluibuilder.importSnippet" + */ + public static final String IMPORT_SNIPPET = "org.tizen.efluibuilder.importSnippet";//$NON-NLS-1$ + + /** + * Export Snippet action id. Value: "org.tizen.efluibuilder.exportSnippet" + */ + public static final String EXPORT_SNIPPET = "org.tizen.efluibuilder.exportSnippet";//$NON-NLS-1$ + + public static final String NEW_EMPTY_VIEW = "org.tizen.efluibuilder.ui.view.outline.NewEmptyView";//$NON-NLS-1$ +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/contextmenu/CommonContextMenu.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/contextmenu/CommonContextMenu.java new file mode 100644 index 0000000..c64949c --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/contextmenu/CommonContextMenu.java @@ -0,0 +1,287 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.contextmenu; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.gef.ContextMenuProvider; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPartViewer; +import org.eclipse.gef.ui.actions.ActionRegistry; +import org.eclipse.gef.ui.actions.GEFActionConstants; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.ui.actions.ActionFactory; +import org.tizen.efluibuilder.core.configurator.ConfiguratorConstants; +import org.tizen.efluibuilder.model.app.AppManager; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.EventPart; +import org.tizen.efluibuilder.model.part.ViewPart; +import org.tizen.efluibuilder.ui.actions.ActionConstants; +import org.tizen.efluibuilder.ui.views.outline.Messages; +import org.tizen.efluibuilder.ui.views.outline.OutlineConstants; + + +/** + * A context menu class. + */ +public abstract class CommonContextMenu extends ContextMenuProvider { + + public static class EditPartSet { + public static final int TYPE_EMPTY = 0; + public static final int TYPE_VIEW = 1; + public static final int TYPE_COMPONENT = 2; + public static final int TYPE_CONNECTION = 4; + public static final int TYPE_MULTI = 8; + + public int type; + public List views; + public List components; + public List events; + + public EditPartSet(List selection) { + type = TYPE_EMPTY; + views = new ArrayList(); + components = new ArrayList(); + events = new ArrayList(); + for (Object editpart : selection) { + if (((EditPart) editpart).getModel() instanceof ViewPart) { + views.add((EditPart) editpart); + type |= TYPE_VIEW; + } else if (((EditPart) editpart).getModel() instanceof ComponentPart) { + components.add((EditPart) editpart); + type |= TYPE_COMPONENT; + } else if (((EditPart) editpart).getModel() instanceof EventPart) { + events.add((EditPart) editpart); + type |= TYPE_CONNECTION; + } + } + if (Integer.bitCount(type) > 1) { + type = TYPE_MULTI; + } + } + } + + private ActionRegistry actionRegistry = null; + + /** + * Constructor. + * + * @param viewer + * a {@link EditPartViewer} + * @param registry + * a {@link ActionRegistry} + */ + public CommonContextMenu(EditPartViewer viewer, ActionRegistry registry) { + super(viewer); + actionRegistry = registry; + } + + protected IAction getAction(String id) { + return actionRegistry.getAction(id); + } + + protected void appendAction(String actionId, IMenuManager toMenu, String toGroup) { + + IAction action = getAction(actionId); + if (null != action) { + toMenu.appendToGroup(toGroup, action); + } + } + + protected void addUndoContextMenu(IMenuManager menu) { + + menu.add(new Separator(GEFActionConstants.GROUP_UNDO)); + + appendAction(ActionFactory.UNDO.getId(), menu, GEFActionConstants.GROUP_UNDO); + appendAction(ActionFactory.REDO.getId(), menu, GEFActionConstants.GROUP_UNDO); + } + + protected void addEditContextMenu(IMenuManager menu) { + + menu.add(new Separator(GEFActionConstants.GROUP_EDIT)); + + appendAction(ActionConstants.CUT_PART, menu, GEFActionConstants.GROUP_EDIT); + appendAction(ActionConstants.COPY_PART, menu, GEFActionConstants.GROUP_EDIT); + appendAction(ActionConstants.PASTE_PART, menu, GEFActionConstants.GROUP_EDIT); + appendAction(ActionConstants.DELETE_PART, menu, GEFActionConstants.GROUP_EDIT); + appendAction(ActionConstants.PASTE_PART_COLOR, menu, GEFActionConstants.GROUP_EDIT); + } + + protected void addMatchSizeContextMenu(IMenuManager menu) { + + menu.add(new Separator(ActionConstants.MATCH_SIZE)); + + MenuManager subMenu = new MenuManager(ActionConstants.MATCH_SIZE, null); + IAction action = getAction(ActionConstants.MATCH_WIDTH); + if (null != action) { + subMenu.add(action); + } + action = getAction(ActionConstants.MATCH_HEIGHT); + if (null != action) { + subMenu.add(action); + } + + menu.appendToGroup(ActionConstants.ALIGN, subMenu); + + } + + protected void addAlignContextMenu(IMenuManager menu) { + + menu.add(new Separator(ActionConstants.ALIGN)); + + MenuManager subMenu = new MenuManager(ActionConstants.ALIGN, null); + IAction action = getAction(ActionConstants.ALIGN_LEFT); + if (null != action) { + subMenu.add(action); + } + action = getAction(ActionConstants.ALIGN_HORIZONTAL_CENTER); + if (null != action) { + subMenu.add(action); + } + action = getAction(ActionConstants.ALIGN_RIGHT); + if (null != action) { + subMenu.add(action); + } + + action = getAction(ActionConstants.ALIGN_TOP); + if (null != action) { + subMenu.add(action); + } + action = getAction(ActionConstants.ALIGN_VERTICAL_CENTER); + if (null != action) { + subMenu.add(action); + } + action = getAction(ActionConstants.ALIGN_BOTTOM); + if (null != action) { + subMenu.add(action); + } + + action = getAction(ActionConstants.ALIGN_DISTRIBUTE_HORIZONTAL_SPACING); + if (null != action) { + subMenu.add(action); + } + action = getAction(ActionConstants.ALIGN_DISTRIBUTE_VERTICAL_SPACING); + if (null != action) { + subMenu.add(action); + } + + menu.appendToGroup(ActionConstants.ALIGN, subMenu); + + return; + } + + protected void addNavigateContextMenu(IMenuManager menu) { + menu.add(new Separator(ActionConstants.NAVIGATE_SELECTION)); + + MenuManager subMenu = new MenuManager(ActionConstants.NAVIGATE_SELECTION, null); + IAction action = getAction(ActionConstants.SELECT_PARENT); + if (null != action) { + subMenu.add(action); + } + action = getAction(ActionConstants.SELECT_CHILD); + if (null != action) { + subMenu.add(action); + } + action = getAction(ActionConstants.SELECT_PREV_SIBLING); + if (null != action) { + subMenu.add(action); + } + action = getAction(ActionConstants.SELECT_NEXT_SIBLING); + if (null != action) { + subMenu.add(action); + } + + menu.appendToGroup(ActionConstants.NAVIGATE_SELECTION, subMenu); + } + + protected void addNewContextMenu(IMenuManager menu) { + menu.add(new Separator(ActionConstants.NEW)); + + MenuManager subMenu = new MenuManager(ActionConstants.NEW, null); + IAction action = getAction(ActionConstants.NEW_SNIPPET); + if (null != action) { + subMenu.add(action); + } + + menu.appendToGroup(ActionConstants.NEW, subMenu); + } + + protected void addStoryboardContextMenu(IMenuManager menu) { + // menu.add(new Separator(ActionConstants.STORYBOARD)); + // appendAction(ActionConstants.ALIGN_STORYBOARD, menu, ActionConstants.STORYBOARD); + } + + protected void addViewSpecificContextMenu(IMenuManager menu) { + addCreateViewMenu(menu); + addControlViewMenu(menu); + } + + protected void addCreateViewMenu(IMenuManager menu) { + menu.add(new Separator(OutlineConstants.ADD_VIEW_GROUP)); + + MenuManager subMenu = new MenuManager(Messages.ACTION_ADD_VIEW_TITLE, null); + + String id = ActionConstants.ADD_VIEW_EMPTY; + subMenu.add(getAction(id)); + + id = OutlineConstants.ADD_VIEW_TEMPLATE; + subMenu.add(getAction(id)); + + if (AppManager.getAppManager().getProfile().equals(ConfiguratorConstants.PROFILE_MOBILE)) { + id = OutlineConstants.ADD_VIEW_POPUP; + subMenu.add(getAction(id)); + + id = OutlineConstants.ADD_VIEW_CTXPOPUP; + subMenu.add(getAction(id)); + } + menu.appendToGroup(OutlineConstants.ADD_VIEW_GROUP, subMenu); + } + + protected void addControlViewMenu(IMenuManager menu) { + IAction action = null; + menu.add(new Separator(OutlineConstants.ADD_VIEW_GROUP)); + action = getAction(ActionConstants.SET_STARTUP_VIEW); + menu.appendToGroup(OutlineConstants.ADD_VIEW_GROUP, action); + + action = getAction(OutlineConstants.CREATE_TEMPLATE_VIEW); + menu.appendToGroup(OutlineConstants.ADD_VIEW_GROUP, action); + } + + protected void addComponentSpecificContextMenu(IMenuManager menu) { + + } + + protected void addCanvasSpecificContextMenu(IMenuManager menu) { + + } + + protected EditPartSet getSelectedPartSet() { + return new EditPartSet(getViewer().getSelectedEditParts()); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/CombineEditorPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/CombineEditorPart.java new file mode 100644 index 0000000..61091c3 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/CombineEditorPart.java @@ -0,0 +1,493 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor; + +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceChangeEvent; +import org.eclipse.core.resources.IResourceChangeListener; +import org.eclipse.core.resources.IResourceDelta; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.gef.EditDomain; +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.gef.ui.parts.SelectionSynchronizer; +import org.eclipse.jface.dialogs.IPageChangedListener; +import org.eclipse.jface.dialogs.PageChangedEvent; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorSite; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.views.contentoutline.IContentOutlinePage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.BuilderPlugin; +import org.tizen.efluibuilder.codegenerator.CodeGenerator; +import org.tizen.efluibuilder.codegenerator.CodeGeneratorException; +import org.tizen.efluibuilder.codegenerator.ICodeGenerator; +import org.tizen.efluibuilder.core.configuration.device.Device; +import org.tizen.efluibuilder.core.configurator.Configurator; +import org.tizen.efluibuilder.model.app.AppManager; +import org.tizen.efluibuilder.model.part.ConfigurationPart; +import org.tizen.efluibuilder.model.part.DocumentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.mscreen.configurator.MscreenConstants; +import org.tizen.efluibuilder.ui.editor.designeditor.DesignEditor; +import org.tizen.efluibuilder.ui.editor.texteditor.TextEditor; +import org.tizen.efluibuilder.ui.editor.toolbar.DesignEditorToolbar; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingManager; +import org.tizen.efluibuilder.ui.views.outline.OutlinePage; +import org.tizen.efluibuilder.ui.views.properties.PropertiesPage; +import org.tizen.efluibuilder.ui.views.properties.style.StyleEDJManager; +import org.tizen.efluibuilder.utility.IDEUtil; + +import edjResourceSyncManager.EdjResourceSyncManager; +import edjResourceSyncManager.ResourceFileDuplicator; +import graphicalDataManager.GraphicalDataInitializeFailedException; +import graphicalDataManager.GraphicalDataManager; + + +public class CombineEditorPart extends MultiPageEditorPart implements IPageChangedListener, IResourceChangeListener { + + protected final Logger logger = LoggerFactory.getLogger(getClass()); + + public static final int DESIGN_TAB = 0; + public static final int TEXTEDITOR_TAB = 1; + public static final int STORYBOARD_TAB = 2; + + private DesignEditorToolbar designEditorToolBar; + private DesignEditorToolbar storyboardToolBar; + + private ResourceFileDuplicator resFileDuplicator = new ResourceFileDuplicator(System.getProperty("java.io.tmpdir") + "TIZEN_UIB_RES\\"); + + private DesignEditor designEditor = new DesignEditor() { + @Override + public void createPartControl(Composite parent) { + designEditorToolBar = new DesignEditorToolbar(parent, CombineEditorPart.this); + designEditorToolBar.setType(DESIGN_TAB); + parent = designEditorToolBar.create(); + edjResSyncMgr = new EdjResourceSyncManager(); + super.createPartControl(parent); + } + }; + private TextEditor textEditor = new TextEditor(); + // private DesignEditorToolbar toolbar = null; + + private PropertiesPage properties = null; + + private GraphicalDataManager graphicalDataManager = null; + private Part documentPart = null; + private Part dataBindingPart = null; + private SelectionSynchronizer editorsSelectionSynchronizer = new EditorsSelectionSynchronizer(); + private DataBindingManager dataBindManager = new DataBindingManager(); + private EdjResourceSyncManager edjResSyncMgr = null; + private StyleEDJManager styleEDJManager = null; + + @Override + public void init(IEditorSite site, IEditorInput input) throws PartInitException { + super.init(site, input); + addListeners(); + createDocumentPart(input); + createDataBindingPart(); + } + + private void createDataBindingPart() { + dataBindingPart = PartUtil.createPart(PartType.DATABINDING, null); + } + + private void createDocumentPart(IEditorInput input) { + documentPart = PartUtil.createPart(PartType.DOCUMENT, null); + + AppManager appManager = AppManager.getAppManager(input); + ((DocumentPart) documentPart).setPlatform(appManager.getPlatform()); + } + + @Override + public void resourceChanged(IResourceChangeEvent event) { + IResourceDelta parentDelta = event.getDelta(); + if (parentDelta == null) { // res folder, extension EDJ; + return; + } + + // get 'layout.xml' file + IFile file = getFile(); + if (file == null) { + return; + } + + // if have delta of 'layout.xml' with removed state, close editor. + IResourceDelta member = parentDelta.findMember(file.getFullPath()); + if (member != null && member.getKind() == IResourceDelta.REMOVED) { + closeEditor(); + } + } + + protected void addListeners() { + addPageChangedListener(this); + ResourcesPlugin.getWorkspace().addResourceChangeListener(this); + } + + protected void removeListeners() { + removePageChangedListener(this); + ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); + } + + @Override + protected void createPages() { + createDesignEditor(); + createTextEditor(); + // createStoryboardView(); + + createLayoutModel(); + createDataBindingModel(); + try { + initContents(); + } catch (GraphicalDataInitializeFailedException e) { // renderer + // connection + // timeout + closeEditor(); + } catch (Exception e) { + closeEditor(); + + IDEUtil.showErrorDialogWithStacktrace(BuilderPlugin.PLUGIN_ID, getContainer().getShell(), this.getTitle(), "Failed to initialize Layout Editor", e); + } + } + + public void setActivePage(int index) { + super.setActivePage(index); + } + + private void createDesignEditor() { + try { + addPage(DESIGN_TAB, designEditor, getEditorInput()); + } catch (PartInitException e) { + logger.error(e.getMessage(), e); + } + setPartName(getFile().getName()); + } + + private void createTextEditor() { + refreshLocal(); + try { + addPage(TEXTEDITOR_TAB, textEditor, getEditorInput()); + } catch (PartInitException e) { + logger.error(e.getMessage(), e); + } + } + + private void refreshLocal() { + try { + + IEditorInput input = this.getEditorInput(); + + // FIXED: If the file is not synchronized, + // this model doesn't have a document element. + if (input instanceof IFileEditorInput) { + IFile file = ((IFileEditorInput) input).getFile(); + if (file.isSynchronized(IResource.DEPTH_ZERO) == false) { + file.refreshLocal(IResource.DEPTH_ZERO, null); + } + } + + } catch (CoreException e) { + logger.error(e.getMessage(), e); + } + } + + private void initContents() { + AppManager appMgr = AppManager.getAppManager(getEditorInput()); + Configurator configurator = Configurator.of(appMgr.getPlatform()); + List defaultStyleEDJs = configurator.getDescriptorManager().getDefaultStyleEDJs(); + if (documentPart != null) { + styleEDJManager = new StyleEDJManager(documentPart, getProject(), appMgr.getVersion(), appMgr.getProfile(), defaultStyleEDJs, resFileDuplicator); + edjResSyncMgr.addListener(styleEDJManager); + styleEDJManager.init(); + graphicalDataManager = new GraphicalDataManager(getEditorInput(), documentPart, resFileDuplicator, edjResSyncMgr, styleEDJManager); + edjResSyncMgr.initContents(getProject(), appMgr.getVersion(), appMgr.getProfile(), resFileDuplicator, styleEDJManager); + + designEditor.initContents(documentPart, dataBindingPart, getSelectionSynchronizer(), graphicalDataManager, edjResSyncMgr, this, textEditor); + + textEditor.initContents(this, documentPart, getEditorInput(), getEditDomain(), getSelectionSynchronizer(), graphicalDataManager); + + // sbTabManager.initializeSBTab(this, documentPart, getEditorInput(), + // getSelectionSynchronizer()); + // sbTabManager.initializeViewerControl(); + + this.designEditorToolBar.initContents(); + // this.storyboardToolBar.initContents(); + this.dataBindManager.initializeDataBindingModelListener(dataBindingPart); + } + // FIXED: Error state problem for modified project when delete it. + this.textEditor.validateEditorInputState(); + } + + private void createDataBindingModel() { + dataBindManager.createDataBindingModel(dataBindingPart, getEditorInput()); + } + + private void createLayoutModel() { + try { + // POLICY: If XML model has a fault, Part model is null; + boolean bValid = textEditor.isValidDocument(); + if (bValid == false) { + logger.warn("XML model is invalid."); + Part mscreenPart = PartUtil.createPart(PartType.MSCREEN, null); + ConfigurationPart configurationPart = (ConfigurationPart) PartUtil.createPart(PartType.CONFIGURATION, null); + Iterator iter = AppManager.getAppManager(getEditorInput()).getDeviceManager().getDevices().iterator(); + configurationPart.setPropertyValue(LayoutSchemaConstants.DEVICE, iter.next().getName()); + configurationPart.setPropertyValue(LayoutSchemaConstants.TYPE, MscreenConstants.CONFIGURATION_TYPE_COMMON); + configurationPart.setPropertyValue(LayoutSchemaConstants.NAME, MscreenConstants.CONFIGURATION_TYPE_COMMON); + configurationPart.setPropertyValue(LayoutSchemaConstants.ORIENTATION, MscreenConstants.ORIENTATION_PORTRAIT); + mscreenPart.insertChildBefore(configurationPart, null); + + Part viewsPart = PartUtil.createPart(PartType.VIEWS, null); + + documentPart.insertChildBefore(mscreenPart, null); + documentPart.insertChildBefore(viewsPart, null); + + ((DocumentPart) documentPart).setValidDocument(bValid); + return; + } + + documentPart = textEditor.createLayoutModel(documentPart); + // TODO: Need to find cause of null + if (documentPart == null) { + closeEditor(); + } + } catch (Exception e) { + logger.error(e.getMessage(), e); + closeEditor(); + } + } + + @Override + public void dispose() { + removeListeners(); + // if (toolbar != null) { + // toolbar.dispose(); + // toolbar = null; + // } + + if (this.designEditorToolBar != null) { + this.designEditorToolBar.dispose(); + this.designEditorToolBar = null; + } + if (this.storyboardToolBar != null) { + this.storyboardToolBar.dispose(); + this.storyboardToolBar = null; + } + + if (textEditor != null) { + textEditor.dispose(); + textEditor = null; + } + + if (designEditor != null) { + designEditor.dispose(); + designEditor = null; + } + + if (graphicalDataManager != null) { + graphicalDataManager.destroy(); + graphicalDataManager = null; + } + + if (edjResSyncMgr != null) { + edjResSyncMgr.dispose(); + edjResSyncMgr = null; + } + + super.dispose(); + } + + public IProject getProject() { + return getFile().getProject(); + } + + public IFile getFile() { + IEditorInput input = getEditorInput(); + if (input instanceof IFileEditorInput) { + return ((IFileEditorInput) input).getFile(); + } + + throw new IllegalArgumentException("Cannot get an editing file."); + } + + @Override + public void doSave(IProgressMonitor monitor) { + try { + SubMonitor subMonitor = SubMonitor.convert(monitor, "Saving layout.xml", 100); + + getFile().refreshLocal(IResource.DEPTH_ZERO, subMonitor.newChild(10)); + + { + // // 1. write location of view to .uproject + // sbTabManager.saveMetaData(); + + // 2. write layout.xml + textEditor.doSave(subMonitor.newChild(20)); + + // 3. write binding meta data + dataBindManager.doSave(subMonitor.newChild(20)); + + // 4. generate managed sources + if (textEditor.isValidDocument()) { + boolean isAutoBuild = getProject().getWorkspace().getDescription().isAutoBuilding(); + if (isAutoBuild == false) { + ICodeGenerator codeGenerator = new CodeGenerator(getProject()); + subMonitor.newChild(40); + try { + codeGenerator.generate(); + } catch (CodeGeneratorException e) { + logger.error(e.getMessage()); + } + subMonitor.done(); + } + } + } + + designEditor.getEditDomain().getCommandStack().markSaveLocation(); + getFile().refreshLocal(IResource.DEPTH_INFINITE, subMonitor.newChild(10)); + } catch (CoreException e) { + } finally { + if (monitor != null) { + monitor.done(); + } + } + } + + @Override + public void doSaveAs() { + designEditor.doSaveAs(); + } + + @Override + public boolean isSaveAsAllowed() { + return false; + } + + @Override + public void pageChanged(PageChangedEvent arg0) { + + switch (getActivePage()) { + case DESIGN_TAB: { + designEditor.setGraphicalViewer(designEditor.getViewer()); + // this.designEditorToolBar.refreshToolbar(); + break; + } + case TEXTEDITOR_TAB: { + break; + } + default: + return; + } + // computeToolbarBounds(); + // toolbar.refreshToolbar(); + } + + @Override + @SuppressWarnings({ "rawtypes", "unchecked" }) + public Object getAdapter(Class type) { + if (type == null) + return null; + + if (type == CommandStack.class) { + return designEditor.getEditDomain().getCommandStack(); + } + + if (type == org.eclipse.ui.views.properties.IPropertySheetPage.class) { + properties = new PropertiesPage(designEditor.getEditDomain().getCommandStack(), designEditor.getActions(), documentPart, edjResSyncMgr, + graphicalDataManager, styleEDJManager); + return properties; + } else if (type == IContentOutlinePage.class) { + // return new OutlinePage(documentPart, + // designEditor.getEditDomain(), + // designEditor.getActions(), editorsSelectionSynchronizer, + // sbTabManager); + return new OutlinePage(documentPart, designEditor.getEditDomain(), designEditor.getActions(), editorsSelectionSynchronizer); + } + + return super.getAdapter(type); + } + + public void setEnableToolBar(boolean enable) { + this.designEditorToolBar.setEnabled(enable); + } + + public Part getDocumentPart() { + return documentPart; + } + + public Part getDataBindingPart() { + return dataBindingPart; + } + + public GraphicalDataManager getGraphiclaDataManager() { + return graphicalDataManager; + } + + public EditDomain getEditDomain() { + return designEditor.getEditDomain(); + } + + public SelectionSynchronizer getSelectionSynchronizer() { + return editorsSelectionSynchronizer; + } + + public DesignEditor getDesignEditor() { + return designEditor; + } + + public void closeEditor() { + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + getSite().getPage().closeEditor(CombineEditorPart.this, false); + } + }); + } + + public EdjResourceSyncManager getEdjResourceSyncManager() { + return this.edjResSyncMgr; + } + + public DataBindingManager getDataBindManager() { + return dataBindManager; + } + + public void setDataBindManager(DataBindingManager dataBindManager) { + this.dataBindManager = dataBindManager; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/EditorConstants.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/EditorConstants.java new file mode 100644 index 0000000..da911e5 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/EditorConstants.java @@ -0,0 +1,29 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor; + +public final class EditorConstants { + // TextEditor + public static final String ENCODING = "UTF-8"; //$NON-NLS-1$ +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/EditorsSelectionSynchronizer.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/EditorsSelectionSynchronizer.java new file mode 100644 index 0000000..0d06d6d --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/EditorsSelectionSynchronizer.java @@ -0,0 +1,52 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPartViewer; +import org.eclipse.gef.ui.parts.SelectionSynchronizer; +import org.tizen.common.util.Assert; +import org.tizen.efluibuilder.model.part.Part; + + +public class EditorsSelectionSynchronizer extends SelectionSynchronizer { + + @Override + protected EditPart convert(EditPartViewer viewer, EditPart editPart) { + Assert.notNull(viewer); + Assert.notNull(editPart); + Object model = editPart.getModel(); + Assert.notNull(model); + if (!(model instanceof Part)) { + return null; + } + Object object = viewer.getEditPartRegistry().get(((Part) model).getUniqueId()); + if (object == null) { + return null; + } + + Assert.isTrue(object instanceof EditPart); + return (EditPart) object; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/IProjectResourceFileChangeListener.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/IProjectResourceFileChangeListener.java new file mode 100644 index 0000000..02391c6 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/IProjectResourceFileChangeListener.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.ui.editor; + +import java.util.ArrayList; + +public interface IProjectResourceFileChangeListener { + public void projectResourceFileChanged(ArrayList changedFiles); +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/KeyHandler.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/KeyHandler.java new file mode 100644 index 0000000..1689877 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/KeyHandler.java @@ -0,0 +1,266 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.gef.ui.actions.ActionRegistry; +import org.eclipse.jface.action.IAction; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyEvent; +import org.tizen.efluibuilder.gef.actions.Messages; +import org.tizen.efluibuilder.ui.actions.ActionConstants; + + +public class KeyHandler { + + private Map actions; + private IAction prevExecutedAction = null; + long actionExecutedTime = 0; + long actionExecutableMinTime = 100; + public static int KEY_CODE_A = 97; + + public KeyHandler(ActionRegistry actionRegistry) { + init(actionRegistry); + } + + public boolean keyPressed(KeyEvent event) { + if (performStroke(KeyStroke.getPressed(event.keyCode, event.stateMask))) { + event.doit = false; + return true; + } + return false; + } + + public boolean keyReleased(KeyEvent event) { + if (performStroke(KeyStroke.getReleased(event.keyCode, event.stateMask))) { + return true; + } + return false; + } + + private boolean performStroke(KeyStroke keyStroke) { + if (actions == null) + return false; + IAction action = actions.get(keyStroke); + if (action == null) { + return false; + } else { + if (this.prevExecutedAction != action) { + this.prevExecutedAction = action; + } else { + if (this.actionExecutedTime != 0) { + long currentTime = System.currentTimeMillis(); + long timediff = currentTime - this.actionExecutedTime; + if (timediff < this.actionExecutableMinTime) { + return false; + } + } + } + if (action.isEnabled()) { + this.actionExecutedTime = System.currentTimeMillis(); + action.run(); + } + } + + return true; + } + + public void put(KeyStroke keyStroke, IAction action) { + if (actions == null) + actions = new HashMap(); + actions.put(keyStroke, action); + } + + public void remove(KeyStroke keyStroke) { + if (actions != null) + actions.remove(keyStroke); + } + + private int getKeycodeFromChar(char character) { + return KEY_CODE_A + Character.toLowerCase(character) - 'a'; + } + + private void init(ActionRegistry actionRegistry) { + + // REGISTER EDIT : Del, Undo&Redo, Copy&Paste, Cut + { + // put(KeyStroke.getPressed(127, SWT.NONE), // Del + // actionRegistry.getAction(ActionConstants.DELETE_PART)); + // put(KeyStroke.getReleased(122, SWT.CTRL), // Ctrl+z + // actionRegistry.getAction(ActionFactory.UNDO.getId())); + // put(KeyStroke.getReleased(121, SWT.CTRL), // Ctrl+y + // actionRegistry.getAction(ActionFactory.REDO.getId())); + + // put(KeyStroke.getReleased(99, SWT.CTRL), // Ctrl+c + // actionRegistry.getAction(ActionConstants.COPY_PART)); + // put(KeyStroke.getReleased(118, SWT.CTRL), // Ctrl+v + // actionRegistry.getAction(ActionConstants.PASTE_PART)); + // put(KeyStroke.getReleased(120, SWT.CTRL), // Ctrl+x + // actionRegistry.getAction(ActionConstants.CUT_PART)); + // put(KeyStroke.getPressed(getKeycodeFromChar('V'), SWT.CTRL + SWT.SHIFT), + // actionRegistry.getAction(Messages.ACTION_MOVE_DOWN)); + } + + // REGISTER EDIT : Move + { + put(KeyStroke.getPressed(SWT.ARROW_LEFT, SWT.NONE), actionRegistry.getAction(Messages.ACTION_MOVE_LEFT)); + put(KeyStroke.getPressed(SWT.ARROW_RIGHT, SWT.NONE), actionRegistry.getAction(Messages.ACTION_MOVE_RIGHT)); + put(KeyStroke.getPressed(SWT.ARROW_UP, SWT.NONE), actionRegistry.getAction(Messages.ACTION_MOVE_UP)); + put(KeyStroke.getPressed(SWT.ARROW_DOWN, SWT.NONE), actionRegistry.getAction(Messages.ACTION_MOVE_DOWN)); + } + + // REGISTER ALIGN + { + put(KeyStroke.getReleased(SWT.ARROW_LEFT, SWT.CTRL), actionRegistry.getAction(ActionConstants.ALIGN_LEFT)); + + put(KeyStroke.getReleased(SWT.ARROW_UP, SWT.CTRL), actionRegistry.getAction(ActionConstants.ALIGN_TOP)); + + put(KeyStroke.getReleased(SWT.ARROW_RIGHT, SWT.CTRL), actionRegistry.getAction(ActionConstants.ALIGN_RIGHT)); + + put(KeyStroke.getReleased(SWT.ARROW_DOWN, SWT.CTRL), actionRegistry.getAction(ActionConstants.ALIGN_BOTTOM)); + + put(KeyStroke.getReleased(SWT.ARROW_LEFT, SWT.CTRL + SWT.SHIFT), actionRegistry.getAction(ActionConstants.ALIGN_HORIZONTAL_CENTER)); + + put(KeyStroke.getReleased(SWT.ARROW_UP, SWT.CTRL + SWT.SHIFT), actionRegistry.getAction(ActionConstants.ALIGN_VERTICAL_CENTER)); + + put(KeyStroke.getReleased(SWT.ARROW_RIGHT, SWT.CTRL + SWT.SHIFT), actionRegistry.getAction(ActionConstants.ALIGN_DISTRIBUTE_HORIZONTAL_SPACING)); + + put(KeyStroke.getReleased(SWT.ARROW_DOWN, SWT.CTRL + SWT.SHIFT), actionRegistry.getAction(ActionConstants.ALIGN_DISTRIBUTE_VERTICAL_SPACING)); + } + + // REGISTER NAVIGATE_SELECTION + { + put(KeyStroke.getReleased(SWT.ARROW_LEFT, SWT.SHIFT), actionRegistry.getAction(ActionConstants.SELECT_PREV_SIBLING)); + + put(KeyStroke.getReleased(SWT.ARROW_UP, SWT.SHIFT), actionRegistry.getAction(ActionConstants.SELECT_PARENT)); + + put(KeyStroke.getReleased(SWT.ARROW_RIGHT, SWT.SHIFT), actionRegistry.getAction(ActionConstants.SELECT_NEXT_SIBLING)); + + put(KeyStroke.getReleased(SWT.ARROW_DOWN, SWT.SHIFT), actionRegistry.getAction(ActionConstants.SELECT_CHILD)); + } + + // REGISTER ZORDER + { + // put(KeyStroke.getReleased(getKeycodeFromChar('b'), SWT.CTRL + SWT.SHIFT), + // actionRegistry.getAction(ActionConstants.ZORDER_BACK)); + // put(KeyStroke.getReleased(getKeycodeFromChar('f'), SWT.CTRL + SWT.SHIFT), + // actionRegistry.getAction(ActionConstants.ZORDER_FRONT)); + + put(KeyStroke.getReleased(getKeycodeFromChar('b'), SWT.CTRL + SWT.SHIFT), actionRegistry.getAction(ActionConstants.ZORDER_BACKWARD)); + put(KeyStroke.getReleased(getKeycodeFromChar('f'), SWT.CTRL + SWT.SHIFT), actionRegistry.getAction(ActionConstants.ZORDER_FRONTWARD)); + } + // put(KeyStroke.getReleased(SWT.ARROW_LEFT, SWT.CTRL), + // actionRegistry.getAction(Messages.ACTION_MOVE_LEFT_DETAIL)); + // put(KeyStroke.getReleased(SWT.ARROW_RIGHT, SWT.CTRL), + // actionRegistry.getAction(Messages.ACTION_MOVE_RIGHT_DETAIL)); + // put(KeyStroke.getReleased(SWT.ARROW_UP, SWT.CTRL), + // actionRegistry.getAction(Messages.ACTION_MOVE_UP_DETAIL)); + // put(KeyStroke.getReleased(SWT.ARROW_DOWN, SWT.CTRL), + // actionRegistry.getAction(Messages.ACTION_MOVE_DOWN_DETAIL)); + // + // put(KeyStroke.getPressed(SWT.ARROW_LEFT, SWT.SHIFT), + // actionRegistry.getAction(Messages.ACTION_DEC_WIDTH)); + // put(KeyStroke.getPressed(SWT.ARROW_RIGHT, SWT.SHIFT), + // actionRegistry.getAction(Messages.ACTION_INC_WIDTH)); + // put(KeyStroke.getPressed(SWT.ARROW_UP, SWT.SHIFT), + // actionRegistry.getAction(Messages.ACTION_DEC_HEIGHT)); + // put(KeyStroke.getPressed(SWT.ARROW_DOWN, SWT.SHIFT), + // actionRegistry.getAction(Messages.ACTION_INC_HEIGHT)); + // + // put(KeyStroke.getReleased(SWT.ARROW_LEFT, SWT.CTRL + SWT.SHIFT), + // actionRegistry.getAction(Messages.ACTION_DEC_WIDTH_DETAIL)); + // put(KeyStroke.getReleased(SWT.ARROW_RIGHT, SWT.CTRL + SWT.SHIFT), + // actionRegistry.getAction(Messages.ACTION_INC_WIDTH_DETAIL)); + // put(KeyStroke.getReleased(SWT.ARROW_UP, SWT.CTRL + SWT.SHIFT), + // actionRegistry.getAction(Messages.ACTION_DEC_HEIGHT_DETAIL)); + // put(KeyStroke.getReleased(SWT.ARROW_DOWN, SWT.CTRL + SWT.SHIFT), + // actionRegistry.getAction(Messages.ACTION_INC_HEIGHT_DETAIL)); + + // put(KeyStroke.getPressed(105, SWT.CTRL + SWT.SHIFT + SWT.ALT), // Ctrl+Shift+Alt+I + // actionRegistry.getAction(Messages.ACTION_SHOW_INSPECTOR)); + + } + + private static class KeyStroke { + private int keyCode; + private int stateMask; + private boolean isPressed; + + private KeyStroke(int keyCode, int stateMask, boolean isPressed) { + this.keyCode = keyCode; + this.stateMask = stateMask; + this.isPressed = isPressed; + } + + public static KeyStroke getPressed(int keyCode, int stateMask) { + KeyStroke keyStroke = new KeyStroke(keyCode, stateMask, true); + return keyStroke; + } + + public static KeyStroke getReleased(int keyCode, int stateMask) { + KeyStroke keyStroke = new KeyStroke(keyCode, stateMask, false); + return keyStroke; + } + + public int getKeyCode() { + return keyCode; + } + + public int getStateMask() { + return stateMask; + } + + public boolean isPressed() { + return isPressed; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof KeyStroke)) { + return false; + } + + KeyStroke keyStroke = (KeyStroke) obj; + + if (this.keyCode == keyStroke.getKeyCode() && this.stateMask == keyStroke.getStateMask() && this.isPressed == keyStroke.isPressed()) { + return true; + } + + return false; + } + + @Override + public int hashCode() { + final int PRIME = 31; + int result = 1; + result = PRIME * result + keyCode; + result = PRIME * result + stateMask; + result = result + ((isPressed) ? 0 : PRIME); + return result; + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/Messages.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/Messages.java new file mode 100644 index 0000000..c5d0a1a --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/Messages.java @@ -0,0 +1,47 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor; + +import org.eclipse.osgi.util.NLS; + + +public final class Messages { + private static final String BUNDLE_NAME = Messages.class.getName(); + + public static String PALETTE_GROUP_SNIPPET; + + public static String ACTION_NEW_SNIPPET; + public static String ACTION_DELETE_SNIPPET; + + public static String ACTION_IMPORT_SNIPPET; + public static String ACTION_EXPORT_SNIPPET; + + static { + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/Messages.properties b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/Messages.properties new file mode 100644 index 0000000..b64b812 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/Messages.properties @@ -0,0 +1,5 @@ +PALETTE_GROUP_SNIPPET = Snippets +ACTION_NEW_SNIPPET = New Snippet +ACTION_DELETE_SNIPPET = Delete +ACTION_IMPORT_SNIPPET = Import; +ACTION_EXPORT_SNIPPET = Export; \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/MouseWheelZoomHandler.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/MouseWheelZoomHandler.java new file mode 100644 index 0000000..8589a13 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/MouseWheelZoomHandler.java @@ -0,0 +1,54 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor; + +import org.eclipse.gef.EditPartViewer; +import org.eclipse.gef.MouseWheelHandler; +import org.eclipse.swt.widgets.Event; +import org.tizen.efluibuilder.gef.viewer.IScalableViewer; + + +public class MouseWheelZoomHandler implements MouseWheelHandler { + + public static final MouseWheelHandler SINGLETON = new MouseWheelZoomHandler(); + + public MouseWheelZoomHandler() { + } + + @Override + public void handleMouseWheel(Event event, EditPartViewer viewer) { + if (viewer instanceof IScalableViewer) { + IScalableViewer scalableViewer = (IScalableViewer) viewer; + double zoomValue = ((scalableViewer.getZoomScale() * 100) + event.count) / 100; + scalableViewer.setZoomScale(zoomValue); + event.doit = false; + + // Off Fit-mode + if (scalableViewer.getFitMode()) { + scalableViewer.setFitMode(false); + } + + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/MultiPageEditorPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/MultiPageEditorPart.java new file mode 100644 index 0000000..269fd45 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/MultiPageEditorPart.java @@ -0,0 +1,1427 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 440810 + * 2017-10-10 Seongwon Shim sw83.shim@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * 1) update package name + * 2) Replace container(CTabFolder -> Composite(stacklayout)) and modify related code + * - replace member variable type : CTabFolder - > Composite + * - addPage, addControl, removeControl : manage composite for each page + * - createContainer : replace createContinaer method + * - createItem, initializePageSwitching, setPageImage, setPageText, getPageImage, getPageText, getTabFolder : comment out unnecessary source code + * - dispose : dispose page control + * - getActivePage : replace implementation for active page + * - getControl : replace implementation to get page control + * - getEditor : replace implementation to get Editor + * - getPageCount : replace implementation to get page count + * - setActivePage : replace implementation to set active page + *******************************************************************************/ + +package org.tizen.efluibuilder.ui.editor; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.util.Tracing; +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.ISafeRunnable; +import org.eclipse.core.runtime.ListenerList; +import org.eclipse.core.runtime.SafeRunner; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.jface.dialogs.IPageChangeProvider; +import org.eclipse.jface.dialogs.IPageChangedListener; +import org.eclipse.jface.dialogs.PageChangedEvent; +import org.eclipse.jface.util.SafeRunnable; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StackLayout; +import org.eclipse.swt.events.TraverseEvent; +import org.eclipse.swt.events.TraverseListener; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Layout; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Widget; +import org.eclipse.ui.IEditorActionBarContributor; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorSite; +import org.eclipse.ui.IKeyBindingService; +import org.eclipse.ui.INestableKeyBindingService; +import org.eclipse.ui.IPartService; +import org.eclipse.ui.IPropertyListener; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchPartSite; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.handlers.IHandlerService; +import org.eclipse.ui.internal.PartSite; +import org.eclipse.ui.internal.WorkbenchPlugin; +import org.eclipse.ui.internal.misc.Policy; +import org.eclipse.ui.internal.services.INestable; +import org.eclipse.ui.internal.services.IServiceLocatorCreator; +import org.eclipse.ui.internal.util.Util; +import org.eclipse.ui.part.EditorPart; +import org.eclipse.ui.part.IWorkbenchPartOrientation; +import org.eclipse.ui.part.MultiPageEditorActionBarContributor; +import org.eclipse.ui.services.IDisposable; +import org.eclipse.ui.services.IServiceLocator; + + +/** + * A multi-page editor is an editor with multiple pages, each of which may contain an editor or an + * arbitrary SWT control. + *

+ * Subclasses must implement the following methods: + *

    + *
  • createPages - to create the required pages by calling one of the + * addPage methods
  • + *
  • IEditorPart.doSave - to save contents of editor
  • + *
  • IEditorPart.doSaveAs - to save contents of editor
  • + *
  • IEditorPart.isSaveAsAllowed - to enable Save As
  • + *
  • IEditorPart.gotoMarker - to scroll to a marker
  • + *
+ *

+ *

+ * Multi-page editors have a single action bar contributor, which manages contributions for all the + * pages. The contributor must be a subclass of MultiPageEditorActionBarContributor. + * Note that since any nested editors are created directly in code by callers of + * addPage(IEditorPart,IEditorInput), nested editors do not have their own + * contributors. + *

+ *

+ * As of 3.5 multi-page editors will post PageChangedEvents at the end of {@link #pageChange(int)}. + * Subclasses may override {@link #getSelectedPage()} to return a page appropriate to their + * multi-page editor. IPartListener2 listeners registered with the IPartService can implement + * IPageChangedListener to be notified about all page change events within the workbench page or + * workbench window. + *

+ * + * @see org.eclipse.ui.part.MultiPageEditorActionBarContributor + * @see org.eclipse.jface.dialogs.IPageChangeProvider + * @see org.eclipse.jface.dialogs.IPageChangedListener + * @see org.eclipse.ui.IPartService + */ +public abstract class MultiPageEditorPart extends EditorPart implements IPageChangeProvider { + + private static final String COMMAND_NEXT_SUB_TAB = "org.eclipse.ui.navigate.nextSubTab"; //$NON-NLS-1$ + private static final String COMMAND_PREVIOUS_SUB_TAB = "org.eclipse.ui.navigate.previousSubTab"; //$NON-NLS-1$ + + /** + * Subclasses that override {@link #createPageContainer(Composite)} can use this constant to get + * a site for the container that can be active while the current page is deactivated. + * + * @since 3.4 + * @see #activateSite() + * @see #deactivateSite(boolean, boolean) + * @see #getPageSite(int) + */ + protected static final int PAGE_CONTAINER_SITE = 65535; + + /** + * Private tracing output. + */ + private static final String TRACING_COMPONENT = "MPE"; //$NON-NLS-1$ + + /** + * The active service locator. This value may be null if there is no selected page, + * or if the selected page is a control with no site. + */ + private INestable activeServiceLocator; + + /** + * The container widget. + */ + // private CTabFolder container; + /* TIZEN: add new UI: replace container { */ + private Composite container; + + private List pageControls; + /* TIZEN } */ + + /** + * List of nested editors. Element type: IEditorPart. Need to hang onto them here, in addition + * to using get/setData on the items, because dispose() needs to access them, but widgetry has + * already been disposed at that point. + */ + private ArrayList nestedEditors = new ArrayList(3); + + private List pageSites = new ArrayList(3); + + private IServiceLocator pageContainerSite; + + private ListenerList pageChangeListeners = new ListenerList( + ListenerList.IDENTITY); + + /** + * Creates an empty multi-page editor with no pages. + */ + protected MultiPageEditorPart() { + super(); + } + + /** + * Creates and adds a new page containing the given control to this multi-page editor. The + * control may be null, allowing it to be created and set later using + * setControl. + * + * @param control + * the control, or null + * @return the index of the new page + * + * @see MultiPageEditorPart#setControl(int, Control) + */ + public int addPage(Control control) { + int index = getPageCount(); + addPage(index, control); + return index; + } + + /** + * Creates and adds a new page containing the given control to this multi-page editor. The page + * is added at the given index. The control may be null, allowing it to be created + * and set later using setControl. + * + * @param index + * the index at which to add the page (0-based) + * @param control + * the control, or null + * + * @see MultiPageEditorPart#setControl(int, Control) + */ + public void addPage(int index, Control control) { + addControl(index, control); + } + + /** + * Creates and adds a new page containing the given editor to this multi-page editor. This also + * hooks a property change listener on the nested editor. + * + * @param editor + * the nested editor + * @param input + * the input for the nested editor + * @return the index of the new page + * @exception PartInitException + * if a new page could not be created + * + * @see MultiPageEditorPart#handlePropertyChange(int) the handler for property change events + * from the nested editor + */ + public int addPage(IEditorPart editor, IEditorInput input) + throws PartInitException { + int index = getPageCount(); + addPage(index, editor, input); + return index; + } + + /** + * Creates and adds a new page containing the given editor to this multi-page editor. The page + * is added at the given index. This also hooks a property change listener on the nested editor. + * + * @param index + * the index at which to add the page (0-based) + * @param editor + * the nested editor + * @param input + * the input for the nested editor + * @exception PartInitException + * if a new page could not be created + * + * @see MultiPageEditorPart#handlePropertyChange(int) the handler for property change events + * from the nested editor + */ + public void addPage(int index, IEditorPart editor, IEditorInput input) + throws PartInitException { + IEditorSite site = createSite(editor); + // call init first so that if an exception is thrown, we have created no + // new widgets + editor.init(site, input); + Composite parent2 = new Composite(getContainer(), + getOrientation(editor)); + parent2.setLayout(new FillLayout()); + editor.createPartControl(parent2); + editor.addPropertyListener(new IPropertyListener() { + @Override + public void propertyChanged(Object source, int propertyId) { + MultiPageEditorPart.this.handlePropertyChange(propertyId); + } + }); + + /* TIZEN: add new UI: manage composite for each page { */ + parent2.setData(editor); + addControl(index, parent2); + /* TIZEN } */ + + nestedEditors.add(editor); + } + + /* TIZEN: add new UI: manage composite for each page { */ + private void addControl(int index, Control composite) { + if (index < 0 || index > pageControls.size()) { + return; + } + + if (index < pageControls.size() && pageControls.get(index) != null) { + pageControls.remove(index); + } + + pageControls.add(index, composite); + } + + private void removeControl(int index) { + if (index < 0 || index > pageControls.size()) { + return; + } + + pageControls.remove(index); + } + /* TIZEN } */ + + /** + * Get the orientation of the editor. + * + * @param editor + * @return int the orientation flag + * @see SWT#RIGHT_TO_LEFT + * @see SWT#LEFT_TO_RIGHT + * @see SWT#NONE + */ + private int getOrientation(IEditorPart editor) { + if (editor instanceof IWorkbenchPartOrientation) { + return ((IWorkbenchPartOrientation) editor).getOrientation(); + } + return getOrientation(); + } + + /* TIZEN: add new UI: replace createContinaer method { */ + /** + * Creates an empty container. Creates a CTabFolder with no style bits set, and hooks a + * selection listener which calls pageChange() whenever the selected tab changes. + * + * @param parent + * The composite in which the container tab folder should be created; must not be + * null. + * @return a new container + */ +// private CTabFolder createContainer(Composite parent) { +// // use SWT.FLAT style so that an extra 1 pixel border is not reserved +// // inside the folder +// parent.setLayout(new FillLayout()); +// final CTabFolder newContainer = new CTabFolder(parent, SWT.BOTTOM +// | SWT.FLAT); +// newContainer.addSelectionListener(new SelectionAdapter() { +// @Override +// public void widgetSelected(SelectionEvent e) { +// int newPageIndex = newContainer.indexOf((CTabItem) e.item); +// pageChange(newPageIndex); +// } +// }); +// newContainer.addTraverseListener(new TraverseListener() { +// // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=199499 : Switching tabs by Ctrl+PageUp/PageDown must not be caught on the inner tab set +// @Override +// public void keyTraversed(TraverseEvent e) { +// switch (e.detail) { +// case SWT.TRAVERSE_PAGE_NEXT: +// case SWT.TRAVERSE_PAGE_PREVIOUS: +// int detail = e.detail; +// e.doit = true; +// e.detail = SWT.TRAVERSE_NONE; +// Control control = newContainer.getParent(); +// do { +// if (control.traverse(detail)) +// return; +// if (control.getListeners(SWT.Traverse).length != 0) +// return; +// if (control instanceof Shell) +// return; +// control = control.getParent(); +// } while (control != null); +// } +// } +// }); +// return newContainer; +// } + + + private Composite createContainer(Composite parent) { + StackLayout layout = new StackLayout(); + parent.setLayout(layout); + this.pageControls = new ArrayList(); + parent.setData(this.pageControls); + + parent.addTraverseListener(new TraverseListener() { + // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=199499 : Switching tabs by + // Ctrl+PageUp/PageDown must not be caught on the inner tab set + @Override + public void keyTraversed(TraverseEvent e) { + switch (e.detail) { + case SWT.TRAVERSE_PAGE_NEXT: + case SWT.TRAVERSE_PAGE_PREVIOUS: + int detail = e.detail; + e.doit = true; + e.detail = SWT.TRAVERSE_NONE; + Control control = parent.getParent(); + do { + if (control.traverse(detail)) + return; + if (control.getListeners(SWT.Traverse).length != 0) + return; + if (control instanceof Shell) + return; + control = control.getParent(); + } while (control != null); + } + } + }); + return parent; + + } + /* TIZEN } */ + + /* TIZEN: add new UI: comment out unnecessary source code{ */ + /** + * Creates a tab item at the given index and places the given control in the new item. The item + * is a CTabItem with no style bits set. + * + * @param index + * the index at which to add the control + * @param control + * is the control to be placed in an item + * @return a new item + */ +// private CTabItem createItem(int index, Control control) { +// CTabItem item = new CTabItem(getTabFolder(), SWT.NONE, index); +// item.setControl(control); +// return item; +// } + /* TIZEN } */ + + + /** + * Creates the pages of this multi-page editor. + *

+ * Subclasses must implement this method. + *

+ */ + protected abstract void createPages(); + + /** + * The MultiPageEditor implementation of this IWorkbenchPart method + * creates the control for the multi-page editor by calling createContainer, then + * createPages. Subclasses should implement createPages rather than + * overriding this method. + * + * @param parent + * The parent in which the editor should be created; must not be null. + */ + @Override + public final void createPartControl(Composite parent) { + Composite pageContainer = createPageContainer(parent); + this.container = createContainer(pageContainer); + createPages(); + // set the active page (page 0 by default), unless it has already been + // done + if (getActivePage() == -1) { + setActivePage(0); + IEditorPart part = getEditor(0); + if (part != null) { + final IServiceLocator serviceLocator = part.getEditorSite(); + if (serviceLocator instanceof INestable) { + activeServiceLocator = (INestable) serviceLocator; + activeServiceLocator.activate(); + } + } + } + initializePageSwitching(); + initializeSubTabSwitching(); + } + + /** + * Initialize the MultiPageEditorPart to use the page switching command. Clients can override + * this method with an empty body if they wish to opt-out. + * + * @since 3.4 + */ + protected void initializePageSwitching() { + /* TIZEN: add new UI: comment out unnecessary source code{ */ + /* new PageSwitcher(this) { + @Override + public Object[] getPages() { + int pageCount = getPageCount(); + Object[] result = new Object[pageCount]; + for (int i = 0; i < pageCount; i++) { + result[i] = new Integer(i); + } + return result; + } + + @Override + public String getName(Object page) { + return getPageText(((Integer) page).intValue()); + } + + @Override + public ImageDescriptor getImageDescriptor(Object page) { + Image image = getPageImage(((Integer) page).intValue()); + if (image == null) + return null; + + return ImageDescriptor.createFromImage(image); + } + + @Override + public void activatePage(Object page) { + setActivePage(((Integer) page).intValue()); + } + + @Override + public int getCurrentPageIndex() { + return getActivePage(); + } + };*/ + /* TIZEN } */ + } + + /** + * Initialize the MultiPageEditorPart to use the sub-tab switching commands. + * + * @since 3.5 + */ + private void initializeSubTabSwitching() { + IHandlerService service = getSite().getService(IHandlerService.class); + service.activateHandler(COMMAND_NEXT_SUB_TAB, new AbstractHandler() { + /** + * {@inheritDoc} + * + * @throws ExecutionException + * if an exception occurred during execution + */ + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + int n = getPageCount(); + if (n == 0) + return null; + + int i = getActivePage() + 1; + if (i >= n) + i = 0; + setActivePage(i); + return null; + } + }); + + service.activateHandler(COMMAND_PREVIOUS_SUB_TAB, new AbstractHandler() { + /** + * {@inheritDoc} + * + * @throws ExecutionException + * if an exception occurred during execution + */ + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + int n = getPageCount(); + if (n == 0) + return null; + + int i = getActivePage() - 1; + if (i < 0) + i = n - 1; + setActivePage(i); + return null; + } + }); + } + + /** + * Creates the parent control for the container returned by {@link #getContainer() }. + * + *

+ * Subclasses may extend and must call super implementation first. + *

+ * + * @param parent + * the parent for all of the editors contents. + * @return the parent for this editor's container. Must not be null. + * + * @since 3.2 + */ + protected Composite createPageContainer(Composite parent) { + return parent; + } + + /** + * Creates the site for the given nested editor. The MultiPageEditorPart + * implementation of this method creates an instance of MultiPageEditorSite. + * Subclasses may reimplement to create more specialized sites. + * + * @param editor + * the nested editor + * @return the editor site + */ + protected IEditorSite createSite(IEditorPart editor) { + return new MultiPageEditorSite(this, editor); + } + + /** + * The MultiPageEditorPart implementation of this IWorkbenchPart + * method disposes all nested editors. Subclasses may extend. + */ + @Override + public void dispose() { + deactivateSite(true, false); + + pageChangeListeners.clear(); + for (int i = 0; i < nestedEditors.size(); ++i) { + IEditorPart editor = (IEditorPart) nestedEditors.get(i); + disposePart(editor); + } + nestedEditors.clear(); + if (pageContainerSite instanceof IDisposable) { + ((IDisposable) pageContainerSite).dispose(); + pageContainerSite = null; + } + for (int i = 0; i < pageSites.size(); i++) { + IServiceLocator sl = (IServiceLocator) pageSites.get(i); + if (sl instanceof IDisposable) { + ((IDisposable) sl).dispose(); + } + } + pageSites.clear(); + /* TIZEN: add new UI: dispose page control{ */ + for(int i = 0; i < pageControls.size(); i++) { + Control control = pageControls.get(i); + if(control == null || control.isDisposed()) { + continue; + } + + control.dispose(); + } + pageControls.clear(); + /* TIZEN } */ + super.dispose(); + } + + /** + * Returns the active nested editor if there is one. + *

+ * Subclasses should not override this method + *

+ * + * @nooverride + * @return the active nested editor, or null if none + */ + protected IEditorPart getActiveEditor() { + int index = getActivePage(); + if (index != -1) { + return getEditor(index); + } + return null; + } + + /** + * Returns the index of the currently active page, or -1 if there is no active page. + *

+ * Subclasses should not override this method + *

+ * + * @nooverride + * + * @return the index of the active page, or -1 if there is no active page + * @since 3.5 + */ + /* TIZEN: add new UI: replace implementation for active page{ */ + public int getActivePage() { + /*CTabFolder tabFolder = getTabFolder(); + if (tabFolder != null && !tabFolder.isDisposed()) { + return tabFolder.getSelectionIndex(); + } + return -1;*/ + + int result = -1; + Composite container = getContainer(); + if (container == null || container.isDisposed()) { + return result; + } + Layout layout = container.getLayout(); + if (layout instanceof StackLayout) { + StackLayout stackLayout = (StackLayout) layout; + return getActivePage(stackLayout.topControl); + } + + return result; + } + + + private int getActivePage(Control control) { + if (control == null) { + return -1; + } + for (int i = 0; i < pageControls.size(); i++) { + if (pageControls.get(i).equals(control)) { + return i; + } + } + return -1; + } + /* TIZEN } */ + + /** + * Returns the composite control containing this multi-page editor's pages. This should be used + * as the parent when creating controls for the individual pages. That is, when calling + * addPage(Control), the passed control should be a child of this container. + *

+ * Warning: Clients should not assume that the container is any particular subclass of + * Composite. The actual class used may change in order to improve the look and feel of + * multi-page editors. Any code making assumptions on the particular subclass would thus be + * broken. + *

+ *

+ * Subclasses should not override this method + *

+ * + * @return the composite, or null if createPartControl has not been + * called yet + */ + protected Composite getContainer() { + return container; + } + + /** + * Returns the control for the given page index, or null if no control has been set + * for the page. The page index must be valid. + *

+ * Subclasses should not override this method + *

+ * + * @param pageIndex + * the index of the page + * @return the control for the specified page, or null if none has been set + */ + /* TIZEN: add new UI: replace implementation to get page control{ */ + protected Control getControl(int pageIndex) { +// return getItem(pageIndex).getControl(); + if (pageIndex < 0 || pageIndex > pageControls.size()) { + return null; + } + return pageControls.get(pageIndex); + } + /* TIZEN } */ + + /** + * Returns the editor for the given page index. The page index must be valid. + * + * @param pageIndex + * the index of the page + * @return the editor for the specified page, or null if the specified page was not + * created with addPage(IEditorPart,IEditorInput) + */ + /* TIZEN: add new UI: replace implementation to get Editor{ */ + protected IEditorPart getEditor(int pageIndex) { + /*Item item = getItem(pageIndex); + if (item != null) { + Object data = item.getData(); + if (data instanceof IEditorPart) { + return (IEditorPart) data; + } + } + return null;*/ + Control control = getControl(pageIndex); + if (control != null) { + Object data = control.getData(); + if (data instanceof IEditorPart) { + return (IEditorPart) data; + } + } + return null; + } + /* TIZEN } */ + + /** + * Returns the service locator for the given page index. This method can be used to create + * service locators for pages that are just controls. The page index must be valid. + *

+ * This will return the editor site service locator for an editor, and create one for a page + * that is just a control. + *

+ * + * @param pageIndex + * the index of the page + * @return the editor for the specified page, or null if the specified page was not + * created with addPage(IEditorPart,IEditorInput) + * @since 3.4 + */ + protected final IServiceLocator getPageSite(int pageIndex) { + if (pageIndex == PAGE_CONTAINER_SITE) { + return getPageContainerSite(); + } + + Control control = getControl(pageIndex); + if (control != null) { + Object data = control.getData(); + if (data instanceof IEditorPart) { + return ((IEditorPart) data).getSite(); + } else if (data instanceof IServiceLocator) { + return (IServiceLocator) data; + } else if (data == null) { + IServiceLocatorCreator slc = getSite() + .getService(IServiceLocatorCreator.class); + IServiceLocator sl = slc.createServiceLocator(getSite(), null, new IDisposable() { + @Override + public void dispose() { + close(); + } + }); + control.setData(sl); + pageSites.add(sl); + return sl; + } + } + return null; + } + + void close() { + // 3.x implementation closes the editor when the ISL is disposed + PartSite partSite = (PartSite) getSite(); + MPart model = partSite.getModel(); + Widget widget = (Widget) model.getWidget(); + if (widget != null && !widget.isDisposed()) { + getSite().getPage().closeEditor(MultiPageEditorPart.this, true); + } + } + + /** + * @return A site that can be used with a header. + * @since 3.4 + * @see #createPageContainer(Composite) + * @see #PAGE_CONTAINER_SITE + * @see #getPageSite(int) + */ + private IServiceLocator getPageContainerSite() { + if (pageContainerSite == null) { + IServiceLocatorCreator slc = getSite() + .getService(IServiceLocatorCreator.class); + pageContainerSite = slc.createServiceLocator(getSite(), null, new IDisposable() { + @Override + public void dispose() { + close(); + } + }); + } + return pageContainerSite; + } + + /** + * Returns the number of pages in this multi-page editor. + * + * @return the number of pages + */ + /* TIZEN: add new UI: replace implementation to get page count{ */ + protected int getPageCount() { + /*CTabFolder folder = getTabFolder(); + // May not have been created yet, or may have been disposed. + if (folder != null && !folder.isDisposed()) { + return folder.getItemCount(); + } + return 0;*/ + + if (pageControls == null) { + return 0; + } + + return pageControls.size(); + } + /* TIZEN } */ + + /* TIZEN: add new UI: comment out unnecessary source code { */ + /** + * Returns the image for the page with the given index, or null + * if no image has been set for the page. The page index must be valid. + * + * @param pageIndex + * the index of the page + * @return the image, or null if none + */ +// protected Image getPageImage(int pageIndex) { +// return getItem(pageIndex).getImage(); +// } + + /** + * Returns the text label for the page with the given index. Returns the + * empty string if no text label has been set for the page. The page index + * must be valid. + * + * @param pageIndex + * the index of the page + * @return the text label for the page + */ +// protected String getPageText(int pageIndex) { +// return getItem(pageIndex).getText(); +// } + + /** + * Returns the tab folder containing this multi-page editor's pages. + * + * @return the tab folder, or null if + * createPartControl has not been called yet + */ +// private CTabFolder getTabFolder() { +// return container; +// } + /* TIZEN } */ + + /** + * Handles a property change notification from a nested editor. The default implementation + * simply forwards the change to listeners on this multi-page editor by calling + * firePropertyChange with the same property id. For example, if the dirty state of + * a nested editor changes (property id IEditorPart.PROP_DIRTY), this method + * handles it by firing a property change event for IEditorPart.PROP_DIRTY to + * property listeners on this multi-page editor. + *

+ * Subclasses may extend or reimplement this method. + *

+ * + * @param propertyId + * the id of the property that changed + */ + protected void handlePropertyChange(int propertyId) { + firePropertyChange(propertyId); + } + + /** + * The MultiPageEditorPart implementation of this IEditorPart method + * sets its site to the given site, its input to the given input, and the site's selection + * provider to a MultiPageSelectionProvider. Subclasses may extend this method. + * + * @param site + * The site for which this part is being created; must not be null. + * @param input + * The input on which this editor should be created; must not be null. + * @throws PartInitException + * If the initialization of the part fails -- currently never. + */ + @Override + public void init(IEditorSite site, IEditorInput input) + throws PartInitException { + setSite(site); + setInput(input); + site.setSelectionProvider(new MultiPageSelectionProvider(this)); + } + + /** + * The MultiPageEditorPart implementation of this IEditorPart method + * returns whether the contents of any of this multi-page editor's nested editors have changed + * since the last save. Pages created with addPage(Control) are ignored. + *

+ * Subclasses may extend or reimplement this method. + *

+ * + * @return true if any of the nested editors are dirty; false + * otherwise. + */ + @Override + public boolean isDirty() { + // use nestedEditors to avoid SWT requests; see bug 12996 + for (Iterator i = nestedEditors.iterator(); i.hasNext();) { + IEditorPart editor = (IEditorPart) i.next(); + if (editor.isDirty()) { + return true; + } + } + return false; + } + + /** + * Notifies this multi-page editor that the page with the given id has been activated. This + * method is called when the user selects a different tab. + *

+ * The MultiPageEditorPart implementation of this method sets focus to the new + * page, and notifies the action bar contributor (if there is one). This checks whether the + * action bar contributor is an instance of MultiPageEditorActionBarContributor, + * and, if so, calls setActivePage with the active nested editor. This also fires a + * selection change event if required. + *

+ *

+ * Subclasses may extend this method. + *

+ * + * @param newPageIndex + * the index of the activated page + */ + protected void pageChange(int newPageIndex) { + deactivateSite(false, false); + + IPartService partService = getSite().getService( + IPartService.class); + if (partService.getActivePart() == this) { + setFocus(); + } + + IEditorPart activeEditor = getEditor(newPageIndex); + + IEditorActionBarContributor contributor = getEditorSite() + .getActionBarContributor(); + if (contributor != null + && contributor instanceof MultiPageEditorActionBarContributor) { + ((MultiPageEditorActionBarContributor) contributor) + .setActivePage(activeEditor); + } + + if (activeEditor != null) { + ISelectionProvider selectionProvider = activeEditor.getSite() + .getSelectionProvider(); + if (selectionProvider != null) { + ISelectionProvider outerProvider = getSite() + .getSelectionProvider(); + if (outerProvider instanceof MultiPageSelectionProvider) { + SelectionChangedEvent event = new SelectionChangedEvent( + selectionProvider, selectionProvider.getSelection()); + + MultiPageSelectionProvider provider = (MultiPageSelectionProvider) outerProvider; + provider.fireSelectionChanged(event); + provider.firePostSelectionChanged(event); + } else { + if (Policy.DEBUG_MPE) { + Tracing.printTrace(TRACING_COMPONENT, + "MultiPageEditorPart " + getTitle() //$NON-NLS-1$ + + " did not propogate selection for " //$NON-NLS-1$ + + activeEditor.getTitle()); + } + } + } + } + + activateSite(); + Object selectedPage = getSelectedPage(); + if (selectedPage != null) { + firePageChanged(new PageChangedEvent(this, selectedPage)); + } + } + + /** + * This method can be used by implementors of + * {@link MultiPageEditorPart#createPageContainer(Composite)} to deactivate the active inner + * editor services while their header has focus. A deactivateSite() must have a matching call to + * activateSite() when appropriate. + *

+ * An new inner editor will have its site activated on a + * {@link MultiPageEditorPart#pageChange(int)}. + *

+ *

+ * Note: This API is evolving in 3.4 and this might not be its final form. + *

+ * + * @param immediate + * immediately deactivate the legacy keybinding service + * @param containerSiteActive + * Leave the page container site active. + * @since 3.4 + * @see #activateSite() + * @see #createPageContainer(Composite) + * @see #getPageSite(int) + * @see #PAGE_CONTAINER_SITE + */ + protected final void deactivateSite(boolean immediate, + boolean containerSiteActive) { + // Deactivate the nested services from the last active service locator. + if (activeServiceLocator != null) { + activeServiceLocator.deactivate(); + activeServiceLocator = null; + } + + final int pageIndex = getActivePage(); + final IKeyBindingService service = getSite().getKeyBindingService(); + if (pageIndex < 0 || pageIndex >= getPageCount() || immediate) { + // There is no selected page, so deactivate the active service. + if (service instanceof INestableKeyBindingService) { + final INestableKeyBindingService nestableService = (INestableKeyBindingService) service; + nestableService.activateKeyBindingService(null); + } else { + WorkbenchPlugin + .log("MultiPageEditorPart.deactivateSite() Parent key binding service was not an instance of INestableKeyBindingService. It was an instance of " //$NON-NLS-1$ + + service.getClass().getName() + " instead."); //$NON-NLS-1$ + } + } + + if (containerSiteActive) { + IServiceLocator containerSite = getPageContainerSite(); + if (containerSite instanceof INestable) { + activeServiceLocator = (INestable) containerSite; + activeServiceLocator.activate(); + } + } + } + + /** + * This method can be used by implementors of {@link #createPageContainer(Composite)} to + * activate the active inner editor services when their header loses focus. + *

+ * An new inner editor will have its site activated on a {@link #pageChange(int)}. + *

+ *

+ * Note: This API is evolving in 3.4 and this might not be its final form. + *

+ * + * @since 3.4 + * @see #deactivateSite(boolean,boolean) + * @see #createPageContainer(Composite) + * @see #getPageSite(int) + */ + protected final void activateSite() { + if (activeServiceLocator != null) { + activeServiceLocator.deactivate(); + activeServiceLocator = null; + } + + final IKeyBindingService service = getSite().getKeyBindingService(); + final int pageIndex = getActivePage(); + final IEditorPart editor = getEditor(pageIndex); + + if (editor != null) { + // active the service for this inner editor + if (service instanceof INestableKeyBindingService) { + final INestableKeyBindingService nestableService = (INestableKeyBindingService) service; + nestableService.activateKeyBindingService(editor + .getEditorSite()); + + } else { + WorkbenchPlugin + .log("MultiPageEditorPart.activateSite() Parent key binding service was not an instance of INestableKeyBindingService. It was an instance of " //$NON-NLS-1$ + + service.getClass().getName() + " instead."); //$NON-NLS-1$ + } + // Activate the services for the new service locator. + final IServiceLocator serviceLocator = editor.getEditorSite(); + if (serviceLocator instanceof INestable) { + activeServiceLocator = (INestable) serviceLocator; + activeServiceLocator.activate(); + } + + } else { + // There is no selected editor, so deactivate the active service. + if (service instanceof INestableKeyBindingService) { + final INestableKeyBindingService nestableService = (INestableKeyBindingService) service; + nestableService.activateKeyBindingService(null); + } else { + WorkbenchPlugin + .log("MultiPageEditorPart.activateSite() Parent key binding service was not an instance of INestableKeyBindingService. It was an instance of " //$NON-NLS-1$ + + service.getClass().getName() + " instead."); //$NON-NLS-1$ + } + + Control control = getControl(pageIndex); + if (control != null && control.getData() instanceof INestable) { + activeServiceLocator = (INestable) control.getData(); + activeServiceLocator.activate(); + } + } + } + + /** + * Disposes the given part and its site. + * + * @param part + * The part to dispose; must not be null. + */ + private void disposePart(final IWorkbenchPart part) { + SafeRunner.run(new ISafeRunnable() { + @Override + public void run() { + IWorkbenchPartSite partSite = part.getSite(); + part.dispose(); + if (partSite instanceof MultiPageEditorSite) { + ((MultiPageEditorSite) partSite).dispose(); + } + } + + @Override + public void handleException(Throwable e) { + // Exception has already being logged by Core. Do nothing. + } + }); + } + + /** + * Removes the page with the given index from this multi-page editor. The controls for the page + * are disposed of; if the page has an editor, it is disposed of too. The page index must be + * valid. + * + * @param pageIndex + * the index of the page + * @see MultiPageEditorPart#addPage(Control) + * @see MultiPageEditorPart#addPage(IEditorPart, IEditorInput) + */ + public void removePage(int pageIndex) { + Assert.isTrue(pageIndex >= 0 && pageIndex < getPageCount()); + // get editor (if any) before disposing item + IEditorPart editor = getEditor(pageIndex); + + // get control for the item if it's not an editor + Control pageControl = getControl(pageIndex); + IServiceLocator pageLocator = null; + if (pageControl != null) { + if (pageControl.getData() instanceof IServiceLocator) { + pageLocator = (IServiceLocator) pageControl.getData(); + } + pageControl.dispose(); + } + + removeControl(pageIndex); + + // dispose editor (if any) + if (editor != null) { + nestedEditors.remove(editor); + disposePart(editor); + } + if (pageLocator != null) { + pageSites.remove(pageLocator); + if (pageLocator instanceof IDisposable) { + ((IDisposable) pageLocator).dispose(); + } + } + } + + /** + * Sets the currently active page. + * + * @param pageIndex + * the index of the page to be activated; the index must be valid + */ + /* TIZEN: add new UI: replace implementation to set active page{ */ + protected void setActivePage(int pageIndex) { +// Assert.isTrue(pageIndex >= 0 && pageIndex < getPageCount()); +// getTabFolder().setSelection(pageIndex); +// pageChange(pageIndex); + if (pageIndex > pageControls.size()) { + return; + } + + Composite container = getContainer(); + if (container == null || container.isDisposed()) { + return; + } + + Layout layout = container.getLayout(); + if (layout instanceof StackLayout) { + StackLayout stackLayout = (StackLayout) layout; + stackLayout.topControl = pageControls.get(pageIndex); + container.layout(); + } + pageChange(pageIndex); + } + /* TIZEN } */ + + /** + * The MultiPageEditor implementation of this IWorkbenchPart method + * sets focus on the active nested editor, if there is one. + *

+ * Subclasses may extend or reimplement. + *

+ */ + @Override + public void setFocus() { + setFocus(getActivePage()); + } + + /** + * Sets focus to the control for the given page. If the page has an editor, this calls its + * setFocus() method. Otherwise, this calls setFocus on the control + * for the page. + * + * @param pageIndex + * the index of the page + */ + private void setFocus(int pageIndex) { + if (pageIndex < 0 || pageIndex >= getPageCount()) { + // page index out of bounds, don't set focus. + return; + } + final IEditorPart editor = getEditor(pageIndex); + if (editor != null) { + editor.setFocus(); + + } else { + // Give the page's control focus. + final Control control = getControl(pageIndex); + if (control != null) { + control.setFocus(); + } + } + } + + /* TIZEN: add new UI: comment out unnecessary source code { */ + /** + * Sets the image for the page with the given index, or null + * to clear the image for the page. The page index must be valid. + * + * @param pageIndex + * the index of the page + * @param image + * the image, or null + */ +// protected void setPageImage(int pageIndex, Image image) { +// getItem(pageIndex).setImage(image); +// } + + /** + * Sets the text label for the page with the given index. The page index + * must be valid. The text label must not be null. + * + * @param pageIndex + * the index of the page + * @param text + * the text label + */ +// protected void setPageText(int pageIndex, String text) { +// getItem(pageIndex).setText(text); +// } + /* TIZEN } */ + + /** + * If there is an adapter registered against the subclass of MultiPageEditorPart return that. + * Otherwise, delegate to the internal editor. + * + * @see org.eclipse.ui.part.WorkbenchPart#getAdapter(java.lang.Class) + */ + @Override + public T getAdapter(Class adapter) { + T result = super.getAdapter(adapter); + // restrict delegating to the UI thread for bug 144851 + if (result == null && Display.getCurrent() != null) { + IEditorPart innerEditor = getActiveEditor(); + // see bug 138823 - prevent some subclasses from causing + // an infinite loop + if (innerEditor != null && innerEditor != this) { + result = Util.getAdapter(innerEditor, adapter); + } + } + return result; + } + + /** + * Find the editors contained in this multi-page editor whose editor input match the provided + * input. + * + * @param input + * the editor input + * @return the editors contained in this multi-page editor whose editor input match the provided + * input + * @since 3.3 + */ + public final IEditorPart[] findEditors(IEditorInput input) { + List result = new ArrayList(); + int count = getPageCount(); + for (int i = 0; i < count; i++) { + IEditorPart editor = getEditor(i); + if (editor != null + && editor.getEditorInput() != null + && editor.getEditorInput().equals(input)) { + result.add(editor); + } + } + return (IEditorPart[]) result.toArray(new IEditorPart[result.size()]); + } + + /** + * Set the active page of this multi-page editor to the page that contains the given editor + * part. This method has no effect of the given editor part is not contained in this multi-page + * editor. + * + * @param editorPart + * the editor part + * @since 3.3 + */ + public final void setActiveEditor(IEditorPart editorPart) { + int count = getPageCount(); + for (int i = 0; i < count; i++) { + IEditorPart editor = getEditor(i); + if (editor == editorPart) { + setActivePage(i); + break; + } + } + } + + /** + * Returns the selected page for the current active page index, either the IEditorPart for + * editors or the Control for other pages. + *

+ * Note: clients may override this method to return a page appropriate for their editors. + * Maybe be null. + *

+ * + * @return The IEditorPart or Control representing the current active page, or null + * if there are no active pages. + * @since 3.5 + * @see #getActivePage() + */ + @Override + public Object getSelectedPage() { + int index = getActivePage(); + if (index == -1) { + return null; + } + IEditorPart editor = getEditor(index); + if (editor != null) { + return editor; + } + return getControl(index); + } + + /** + * Add the page change listener to be notified when the page changes. The newly selected page + * will be the Object returned from {@link #getSelectedPage()}. In the default case, this will + * be the active page Control, IEditorPart, or null. + *

+ * This method has no effect if the listener has already been added. + *

+ * + * @nooverride + * + * @since 3.5 + */ + @Override + public void addPageChangedListener(IPageChangedListener listener) { + pageChangeListeners.add(listener); + } + + /** + * Remove the page change listener. + *

+ * This method has no effect if the listener is not in the list. + *

+ * + * @nooverride + * + * @since 3.5 + */ + @Override + public void removePageChangedListener(IPageChangedListener listener) { + pageChangeListeners.remove(listener); + } + + private void firePageChanged(final PageChangedEvent event) { + Object[] listeners = pageChangeListeners.getListeners(); + for (int i = 0; i < listeners.length; ++i) { + final IPageChangedListener l = (IPageChangedListener) listeners[i]; + SafeRunnable.run(new SafeRunnable() { + @Override + public void run() { + l.pageChanged(event); + } + }); + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/MultiPageEditorSite.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/MultiPageEditorSite.java new file mode 100644 index 0000000..ecf5713 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/MultiPageEditorSite.java @@ -0,0 +1,619 @@ +/******************************************************************************* + * Copyright (c) 2000, 2013 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2017-10-10 Seongwon Shim sw83.shim@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * 1) update package name + * 2) comment out compile error code + * - initializeDefaultServices : comment out compile error code + *******************************************************************************/ +package org.tizen.efluibuilder.ui.editor; + +import java.util.ArrayList; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.viewers.ILabelDecorator; +import org.eclipse.jface.viewers.IPostSelectionProvider; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IEditorActionBarContributor; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorSite; +import org.eclipse.ui.IKeyBindingService; +import org.eclipse.ui.INestableKeyBindingService; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.contexts.IContextService; +import org.eclipse.ui.handlers.IHandlerService; +import org.eclipse.ui.internal.KeyBindingService; +import org.eclipse.ui.internal.PartSite; +import org.eclipse.ui.internal.PopupMenuExtender; +import org.eclipse.ui.internal.WorkbenchPlugin; +import org.eclipse.ui.internal.contexts.NestableContextService; +import org.eclipse.ui.internal.handlers.LegacyHandlerService; +import org.eclipse.ui.internal.services.INestable; +import org.eclipse.ui.internal.services.IServiceLocatorCreator; +import org.eclipse.ui.internal.services.IWorkbenchLocationService; +import org.eclipse.ui.internal.services.ServiceLocator; +import org.eclipse.ui.internal.services.WorkbenchLocationService; +import org.eclipse.ui.services.IDisposable; +import org.eclipse.ui.services.IServiceScopes; + +/** + * Site for a nested editor within a multi-page editor. Selection is handled by + * forwarding the event to the multi-page editor's selection listeners; most + * other methods are forwarded to the multi-page editor's site. + *

+ * The base implementation of MultiPageEditor.createSite creates + * an instance of this class. This class may be instantiated or subclassed. + *

+ */ +public class MultiPageEditorSite implements IEditorSite, INestable { + + /** + * The nested editor. + */ + private IEditorPart editor; + + /** + * The list of popup menu extenders; null if none registered. + */ + private ArrayList menuExtenders; + + /** + * The multi-page editor. + */ + private MultiPageEditorPart multiPageEditor; + + /** + * The post selection changed listener. + */ + private ISelectionChangedListener postSelectionChangedListener = null; + + /** + * The selection change listener, initialized lazily; null if + * not yet created. + */ + private ISelectionChangedListener selectionChangedListener = null; + + /** + * The selection provider; null if none. + * + * @see MultiPageEditorSite#setSelectionProvider(ISelectionProvider) + */ + private ISelectionProvider selectionProvider = null; + + /** + * The cached copy of the key binding service specific to this multi-page + * editor site. This value is null if it is not yet + * initialized. + */ + private IKeyBindingService service = null; + + /** + * The local service locator for this multi-page editor site. This value is + * never null. + */ + private final ServiceLocator serviceLocator; + + private NestableContextService contextService; + + private IEclipseContext context; + + private boolean active = false; + + /** + * Creates a site for the given editor nested within the given multi-page + * editor. + * + * @param multiPageEditor + * the multi-page editor + * @param editor + * the nested editor + */ + public MultiPageEditorSite(MultiPageEditorPart multiPageEditor, + IEditorPart editor) { + Assert.isNotNull(multiPageEditor); + Assert.isNotNull(editor); + this.multiPageEditor = multiPageEditor; + this.editor = editor; + + PartSite site = (PartSite) multiPageEditor.getSite(); + + IServiceLocatorCreator slc = (IServiceLocatorCreator) site + .getService(IServiceLocatorCreator.class); + Assert.isNotNull(slc); + context = site.getModel().getContext().createChild("MultiPageEditorSite"); //$NON-NLS-1$ + serviceLocator = (ServiceLocator) slc.createServiceLocator( + multiPageEditor.getSite(), null, new IDisposable(){ + @Override + public void dispose() { + getMultiPageEditor().close(); + } + }, context); + + initializeDefaultServices(); + } + + /** + * Initialize the slave services for this site. + */ + private void initializeDefaultServices() { + serviceLocator.registerService(IWorkbenchLocationService.class, + new WorkbenchLocationService(IServiceScopes.MPESITE_SCOPE, + getWorkbenchWindow().getWorkbench(), + getWorkbenchWindow(), getMultiPageEditor().getSite(), + this, null, 3)); +// serviceLocator.registerService(IMultiPageEditorSiteHolder.class, +// new IMultiPageEditorSiteHolder() { +// @Override +// public MultiPageEditorSite getSite() { +// return MultiPageEditorSite.this; +// } +// }); + + context.set(IContextService.class.getName(), new ContextFunction() { + @Override + public Object compute(IEclipseContext ctxt, String contextKey) { + if (contextService == null) { +// contextService = new NestableContextService(ctxt.getParent().get( +// IContextService.class), new ActivePartExpression(multiPageEditor)); + } + return contextService; + } + }); + + // create a local handler service so that when this page + // activates/deactivates, its handlers will also be taken into/out of + // consideration during handler lookups + IHandlerService handlerService = new LegacyHandlerService(context); + context.set(IHandlerService.class, handlerService); + } + + /** + * Notifies the multi page editor service that the component within which it + * exists has become active. + * + * @since 3.2 + */ + @Override + public final void activate() { + active = true; + context.activate(); + serviceLocator.activate(); + + if (contextService != null) { + contextService.activate(); + } + } + + /** + * Notifies the multi page editor service that the component within which it + * exists has been deactived. + * + * @since 3.2 + */ + @Override + public final void deactivate() { + active = false; + if (contextService != null) { + contextService.deactivate(); + } + + serviceLocator.deactivate(); + context.deactivate(); + } + + /** + * Dispose the contributions. + */ + public void dispose() { + if (menuExtenders != null) { + for (int i = 0; i < menuExtenders.size(); i++) { + ((PopupMenuExtender) menuExtenders.get(i)).dispose(); + } + menuExtenders = null; + } + + // Remove myself from the list of nested key binding services. + if (service != null) { + IKeyBindingService parentService = getMultiPageEditor().getEditorSite() + .getKeyBindingService(); + if (parentService instanceof INestableKeyBindingService) { + INestableKeyBindingService nestableParent = (INestableKeyBindingService) parentService; + nestableParent.removeKeyBindingService(this); + } + if (service instanceof KeyBindingService) { + ((KeyBindingService) service).dispose(); + } + service = null; + } + + if (contextService != null) { + contextService.dispose(); + } + + if (serviceLocator != null) { + serviceLocator.dispose(); + } + context.dispose(); + } + + /** + * The MultiPageEditorSite implementation of this + * IEditorSite method returns null, since + * nested editors do not have their own action bar contributor. + * + * @return null + */ + @Override + public IEditorActionBarContributor getActionBarContributor() { + return null; + } + + /** + * The MultiPageEditorSite implementation of this + * IEditorSite method forwards to the multi-page editor to + * return the action bars. + * + * @return The action bars from the parent multi-page editor. + */ + @Override + public IActionBars getActionBars() { + return multiPageEditor.getEditorSite().getActionBars(); + } + + @Override + public Object getAdapter(Class adapter) { + return null; + } + + /** + * The MultiPageEditorSite implementation of this + * IWorkbenchPartSite method forwards to the multi-page + * editor to return the decorator manager. + * + * @return The decorator from the workbench window. + * @deprecated use IWorkbench.getDecoratorManager() + */ + @Deprecated + public ILabelDecorator getDecoratorManager() { + return getWorkbenchWindow().getWorkbench().getDecoratorManager() + .getLabelDecorator(); + } + + /** + * Returns the nested editor. + * + * @return the nested editor + */ + public IEditorPart getEditor() { + return editor; + } + + /** + * The MultiPageEditorSite implementation of this + * IWorkbenchPartSite method returns an empty string since + * the nested editor is not created from the registry. + * + * @return An empty string. + */ + @Override + public String getId() { + return ""; //$NON-NLS-1$ + } + + @Override + public IKeyBindingService getKeyBindingService() { + if (service == null) { + service = getMultiPageEditor().getEditorSite() + .getKeyBindingService(); + if (service instanceof INestableKeyBindingService) { + INestableKeyBindingService nestableService = (INestableKeyBindingService) service; + service = nestableService.getKeyBindingService(this); + + } else { + /* + * This is an internal reference, and should not be copied by + * client code. If you are thinking of copying this, DON'T DO + * IT. + */ + WorkbenchPlugin + .log("MultiPageEditorSite.getKeyBindingService() Parent key binding service was not an instance of INestableKeyBindingService. It was an instance of " + service.getClass().getName() + " instead."); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + return service; + } + + /** + * Returns the multi-page editor. + * + * @return the multi-page editor + */ + public MultiPageEditorPart getMultiPageEditor() { + return multiPageEditor; + } + + /** + * The MultiPageEditorSite implementation of this + * IWorkbenchPartSite method forwards to the multi-page + * editor to return the workbench page. + * + * @return The workbench page in which this editor site resides. + */ + @Override + public IWorkbenchPage getPage() { + return getMultiPageEditor().getSite().getPage(); + } + + @Override + public IWorkbenchPart getPart() { + return editor; + } + + /** + * The MultiPageEditorSite implementation of this + * IWorkbenchPartSite method returns an empty string since + * the nested editor is not created from the registry. + * + * @return An empty string. + */ + @Override + public String getPluginId() { + return ""; //$NON-NLS-1$ + } + + /** + * Returns the post selection change listener which listens to the nested + * editor's selection changes. + * + * @return the post selection change listener. + */ + private ISelectionChangedListener getPostSelectionChangedListener() { + if (postSelectionChangedListener == null) { + postSelectionChangedListener = new ISelectionChangedListener() { + @Override + public void selectionChanged(SelectionChangedEvent event) { + MultiPageEditorSite.this.handlePostSelectionChanged(event); + } + }; + } + return postSelectionChangedListener; + } + + /** + * The MultiPageEditorSite implementation of this + * IWorkbenchPartSite method returns an empty string since + * the nested editor is not created from the registry. + * + * @return An empty string. + */ + @Override + public String getRegisteredName() { + return ""; //$NON-NLS-1$ + } + + /** + * Returns the selection changed listener which listens to the nested + * editor's selection changes, and calls handleSelectionChanged. + * + * @return the selection changed listener + */ + private ISelectionChangedListener getSelectionChangedListener() { + if (selectionChangedListener == null) { + selectionChangedListener = new ISelectionChangedListener() { + @Override + public void selectionChanged(SelectionChangedEvent event) { + MultiPageEditorSite.this.handleSelectionChanged(event); + } + }; + } + return selectionChangedListener; + } + + /** + * The MultiPageEditorSite implementation of this + * IWorkbenchPartSite method returns the selection provider + * set by setSelectionProvider. + * + * @return The current selection provider. + */ + @Override + public ISelectionProvider getSelectionProvider() { + return selectionProvider; + } + + @Override + public final Object getService(final Class key) { + Object service = serviceLocator.getService(key); + if (active && service instanceof INestable) { + // services need to know that it is currently in an active state + ((INestable) service).activate(); + } + return service; + } + + /** + * The MultiPageEditorSite implementation of this + * IWorkbenchPartSite method forwards to the multi-page + * editor to return the shell. + * + * @return The shell in which this editor site resides. + */ + @Override + public Shell getShell() { + return getMultiPageEditor().getSite().getShell(); + } + + /** + * The MultiPageEditorSite implementation of this + * IWorkbenchPartSite method forwards to the multi-page + * editor to return the workbench window. + * + * @return The workbench window in which this editor site resides. + */ + @Override + public IWorkbenchWindow getWorkbenchWindow() { + return getMultiPageEditor().getSite().getWorkbenchWindow(); + } + + /** + * Handles a post selection changed even from the nexted editor. + *

+ * Subclasses may extend or reimplement this method + * + * @param event the event + * + * @since 3.2 + */ + protected void handlePostSelectionChanged(SelectionChangedEvent event) { + ISelectionProvider parentProvider = getMultiPageEditor().getSite() + .getSelectionProvider(); + if (parentProvider instanceof MultiPageSelectionProvider) { + SelectionChangedEvent newEvent = new SelectionChangedEvent( + parentProvider, event.getSelection()); + MultiPageSelectionProvider prov = (MultiPageSelectionProvider) parentProvider; + prov.firePostSelectionChanged(newEvent); + } + } + + /** + * Handles a selection changed event from the nested editor. The default + * implementation gets the selection provider from the multi-page editor's + * site, and calls fireSelectionChanged on it (only if it is + * an instance of MultiPageSelectionProvider), passing a new + * event object. + *

+ * Subclasses may extend or reimplement this method. + *

+ * + * @param event + * the event + */ + protected void handleSelectionChanged(SelectionChangedEvent event) { + ISelectionProvider parentProvider = getMultiPageEditor().getSite() + .getSelectionProvider(); + if (parentProvider instanceof MultiPageSelectionProvider) { + SelectionChangedEvent newEvent = new SelectionChangedEvent( + parentProvider, event.getSelection()); + MultiPageSelectionProvider prov = (MultiPageSelectionProvider) parentProvider; + prov.fireSelectionChanged(newEvent); + } + } + + @Override + public final boolean hasService(final Class key) { + return serviceLocator.hasService(key); + } + + /** + * The MultiPageEditorSite implementation of this + * IWorkbenchPartSite method forwards to the multi-page + * editor for registration. + * + * @param menuManager + * The menu manager + * @param selProvider + * The selection provider. + */ + @Override + public void registerContextMenu(MenuManager menuManager, + ISelectionProvider selProvider) { + getMultiPageEditor().getSite().registerContextMenu(menuManager, + selProvider); + } + + @Override + public final void registerContextMenu(final MenuManager menuManager, + final ISelectionProvider selectionProvider, + final boolean includeEditorInput) { + registerContextMenu(getId(), menuManager, selectionProvider, + includeEditorInput); + } + + /** + * The MultiPageEditorSite implementation of this + * IWorkbenchPartSite method forwards to the multi-page + * editor for registration. + * + * @param menuID + * The identifier for the menu. + * @param menuMgr + * The menu manager + * @param selProvider + * The selection provider. + */ + @Override + public void registerContextMenu(String menuID, MenuManager menuMgr, + ISelectionProvider selProvider) { + if (menuExtenders == null) { + menuExtenders = new ArrayList(1); + } + PartSite.registerContextMenu(menuID, menuMgr, selProvider, true, editor, context, + menuExtenders); + } + + @Override + public final void registerContextMenu(final String menuId, + final MenuManager menuManager, + final ISelectionProvider selectionProvider, + final boolean includeEditorInput) { + if (menuExtenders == null) { + menuExtenders = new ArrayList(1); + } + PartSite.registerContextMenu(menuId, menuManager, selectionProvider, includeEditorInput, + editor, context, menuExtenders); + } + + /** + * The MultiPageEditorSite implementation of this + * IWorkbenchPartSite method remembers the selection + * provider, and also hooks a listener on it, which calls + * handleSelectionChanged when a selection changed event + * occurs. + * + * @param provider + * The selection provider. + * @see MultiPageEditorSite#handleSelectionChanged(SelectionChangedEvent) + */ + @Override + public void setSelectionProvider(ISelectionProvider provider) { + ISelectionProvider oldSelectionProvider = selectionProvider; + selectionProvider = provider; + if (oldSelectionProvider != null) { + oldSelectionProvider + .removeSelectionChangedListener(getSelectionChangedListener()); + if (oldSelectionProvider instanceof IPostSelectionProvider) { + ((IPostSelectionProvider) oldSelectionProvider) + .removePostSelectionChangedListener(getPostSelectionChangedListener()); + } else { + oldSelectionProvider + .removeSelectionChangedListener(getPostSelectionChangedListener()); + } + } + if (selectionProvider != null) { + selectionProvider + .addSelectionChangedListener(getSelectionChangedListener()); + if (selectionProvider instanceof IPostSelectionProvider) { + ((IPostSelectionProvider) selectionProvider) + .addPostSelectionChangedListener(getPostSelectionChangedListener()); + } else { + selectionProvider.addSelectionChangedListener(getPostSelectionChangedListener()); + } + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/MultiPageSelectionProvider.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/MultiPageSelectionProvider.java new file mode 100644 index 0000000..c8ae3db --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/MultiPageSelectionProvider.java @@ -0,0 +1,168 @@ +/******************************************************************************* + * Copyright (c) 2000, 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.tizen.efluibuilder.ui.editor; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.ListenerList; +import org.eclipse.core.runtime.SafeRunner; +import org.eclipse.jface.util.SafeRunnable; +import org.eclipse.jface.viewers.IPostSelectionProvider; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.ui.IEditorPart; + +/** + * Manages the current selection in a multi-page editor by tracking the active + * nested editor within the multi-page editor. When the selection changes, + * notifications are sent to all registered listeners. + *

+ * This class may be instantiated; it is not intended to be subclassed. + * The base implementation of MultiPageEditor.init creates + * an instance of this class. + *

+ * @noextend This class is not intended to be subclassed by clients. + */ +public class MultiPageSelectionProvider implements IPostSelectionProvider { + + /** + * Registered selection changed listeners (element type: + * ISelectionChangedListener). + */ + private ListenerList listeners = new ListenerList(); + + /** + * Registered post selection changed listeners. + */ + private ListenerList postListeners = new ListenerList(); + + /** + * The multi-page editor. + */ + private MultiPageEditorPart multiPageEditor; + + /** + * Creates a selection provider for the given multi-page editor. + * + * @param multiPageEditor the multi-page editor + */ + public MultiPageSelectionProvider(MultiPageEditorPart multiPageEditor) { + Assert.isNotNull(multiPageEditor); + this.multiPageEditor = multiPageEditor; + } + + @Override + public void addSelectionChangedListener(ISelectionChangedListener listener) { + listeners.add(listener); + } + + /** + * Adds a listener for post selection changes in this multi page selection provider. + * + * @param listener a selection changed listener + * @since 3.2 + */ + @Override + public void addPostSelectionChangedListener(ISelectionChangedListener listener) { + postListeners.add(listener); + } + + /** + * Notifies all registered selection changed listeners that the editor's + * selection has changed. Only listeners registered at the time this method is + * called are notified. + * + * @param event the selection changed event + */ + public void fireSelectionChanged(final SelectionChangedEvent event) { + Object[] listeners = this.listeners.getListeners(); + fireEventChange(event, listeners); + } + + /** + * Notifies all post selection changed listeners that the editor's + * selection has changed. + * + * @param event the event to propogate. + * @since 3.2 + */ + public void firePostSelectionChanged(final SelectionChangedEvent event) { + Object[] listeners = postListeners.getListeners(); + fireEventChange(event, listeners); + } + + private void fireEventChange(final SelectionChangedEvent event, Object[] listeners) { + for (int i = 0; i < listeners.length; ++i) { + final ISelectionChangedListener l = (ISelectionChangedListener) listeners[i]; + SafeRunner.run(new SafeRunnable() { + @Override + public void run() { + l.selectionChanged(event); + } + }); + } + } + + /** + * Returns the multi-page editor. + * @return the multi-page editor. + */ + public MultiPageEditorPart getMultiPageEditor() { + return multiPageEditor; + } + + @Override + public ISelection getSelection() { + IEditorPart activeEditor = multiPageEditor.getActiveEditor(); + if (activeEditor != null) { + ISelectionProvider selectionProvider = activeEditor.getSite() + .getSelectionProvider(); + if (selectionProvider != null) { + return selectionProvider.getSelection(); + } + } + return StructuredSelection.EMPTY; + } + + /* (non-JavaDoc) + * Method declaed on ISelectionProvider. + */ + @Override + public void removeSelectionChangedListener( + ISelectionChangedListener listener) { + listeners.remove(listener); + } + + /** + * Removes a listener for post selection changes in this multi page selection provider. + * + * @param listener a selection changed listener + * @since 3.2 + */ + @Override + public void removePostSelectionChangedListener(ISelectionChangedListener listener) { + postListeners.remove(listener); + } + + @Override + public void setSelection(ISelection selection) { + IEditorPart activeEditor = multiPageEditor.getActiveEditor(); + if (activeEditor != null) { + ISelectionProvider selectionProvider = activeEditor.getSite() + .getSelectionProvider(); + if (selectionProvider != null) { + selectionProvider.setSelection(selection); + } + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ZoomUtil.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ZoomUtil.java new file mode 100644 index 0000000..68b3258 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ZoomUtil.java @@ -0,0 +1,74 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor; + +public class ZoomUtil { + // ratio + public static double[] zoomLevels = new double[] { + 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, + 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0 + }; + public static float DEFAULT_ZOOM = 1.0f; + public static float MIN_ZOOM = (float) zoomLevels[0]; + public static float MAX_ZOOM = (float) zoomLevels[zoomLevels.length - 1]; + + // percent + public static int ZOOM_INCREMENT = 10; + public static int MIN_ZOOM_PERCENT = (int) (MIN_ZOOM * 100); + public static int MAX_ZOOM_PERCENT = (int) (MAX_ZOOM * 100); + + private static float floatFrom(String percent) { + return Float.parseFloat(percent) / 100; + } + + public static boolean isInZoomRange(String zoom) { + float value = floatFrom(zoom); + return MIN_ZOOM <= value && value <= MAX_ZOOM; + } + + public static boolean isGTMaxZoom(float zoom) { + return MAX_ZOOM <= zoom; + } + + public static boolean isGTMaxZoom(String zoom) { + return isGTMaxZoom(floatFrom(zoom)); + } + + public static boolean isLTMinZoom(float zoom) { + return zoom <= MIN_ZOOM; + } + + public static boolean isLTMinZoom(String zoom) { + return isLTMinZoom(floatFrom(zoom)); + } + + public static String getMinZoom() { + return Integer.toString(MIN_ZOOM_PERCENT); + } + + public static String getMaxZoom() { + return Integer.toString(MAX_ZOOM_PERCENT); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/action/AbstractEditorAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/action/AbstractEditorAction.java new file mode 100644 index 0000000..941c053 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/action/AbstractEditorAction.java @@ -0,0 +1,78 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.action; + +import org.eclipse.gef.ui.actions.SelectionAction; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorReference; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.efluibuilder.ui.editor.designeditor.DesignEditor; + + +public abstract class AbstractEditorAction extends SelectionAction { + protected static Logger logger = LoggerFactory.getLogger(AbstractEditorAction.class); + + public AbstractEditorAction(IWorkbenchPart part) { + super(part); + } + + protected void refreshPalette() { + IWorkbench workbench = PlatformUI.getWorkbench(); + if (workbench == null) { + return; + } + IWorkbenchWindow ww = workbench.getActiveWorkbenchWindow(); + if (ww == null) { + return; + } + + IWorkbenchPage wp = ww.getActivePage(); + if (wp == null) { + return; + } + + IEditorReference[] editors = wp.getEditorReferences(); + if (editors.length <= 0) { + return; + } + + for (IEditorReference editor : editors) { + IEditorPart editorPart = editor.getEditor(true); + if (!(editorPart instanceof CombineEditorPart)) { + continue; + } + // Refresh all palettes of opened NUIB editors + CombineEditorPart combineEditor = (CombineEditorPart) editorPart; + DesignEditor designEditor = combineEditor.getDesignEditor(); + designEditor.refreshPalette(); + } + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/action/AbstractPaletteAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/action/AbstractPaletteAction.java new file mode 100644 index 0000000..a80a720 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/action/AbstractPaletteAction.java @@ -0,0 +1,87 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.action; + +import java.util.List; + +import org.eclipse.gef.EditPart; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.tizen.common.util.Assert; +import org.tizen.efluibuilder.gef.dnd.model.SnippetTemplate; +import org.tizen.efluibuilder.model.snippet.ISnippet; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.CombinedTemplateCreationEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewer; + + +public abstract class AbstractPaletteAction extends AbstractEditorAction { + public AbstractPaletteAction(PaletteViewer paletteViewer) { + super(null); + this.setSelectionProvider(paletteViewer); + } + + @Override + protected boolean calculateEnabled() { + // empty selection + List selectedObjects = getSelectedObjects(); + if (selectedObjects.isEmpty()) { + return false; + } + + // if selection is not snippet + ISnippet snippet = getSelectedSnippet(); + if (snippet == null) { + return false; + } + + return true; + } + + protected ISnippet getSelectedSnippet() { + ISelection selection = getSelection(); + Assert.isTrue(selection instanceof StructuredSelection, selection.getClass().getName()); + StructuredSelection ss = (StructuredSelection) selection; + Object object = ss.getFirstElement(); + + if (!(object instanceof EditPart)) { + return null; + } + + EditPart editPart = (EditPart) object; + Object model = editPart.getModel(); + if (!(model instanceof CombinedTemplateCreationEntry)) { + return null; + } + + CombinedTemplateCreationEntry entry = (CombinedTemplateCreationEntry) model; + Object template = entry.getTemplate(); + if (!(template instanceof SnippetTemplate)) { + return null; + } + + SnippetTemplate snippetTemplate = (SnippetTemplate) template; + ISnippet snippet = snippetTemplate.getSnippet(); + return snippet; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/action/DeleteSnippetAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/action/DeleteSnippetAction.java new file mode 100644 index 0000000..0fb89c0 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/action/DeleteSnippetAction.java @@ -0,0 +1,62 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.action; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.MessageBox; +import org.tizen.efluibuilder.model.snippet.ISnippet; +import org.tizen.efluibuilder.model.snippet.ISnippetManager; +import org.tizen.efluibuilder.model.snippet.SnippetManager; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewer; + + +public final class DeleteSnippetAction extends AbstractPaletteAction { + + public DeleteSnippetAction(PaletteViewer viewer) { + super(viewer); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.action.Action#run() + */ + @Override + public void run() { + MessageBox msgBox = new MessageBox(Display.getDefault().getActiveShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION); + msgBox.setMessage("Do you really want to delete this snippet? \nDeleted snippet can not be restored."); + int result = msgBox.open(); + if (result == SWT.YES) { + ISnippet snippet = getSelectedSnippet(); + ISnippetManager manager = SnippetManager.getDefault(); + if (snippet != null) { + manager.remove(snippet); + } + } + + refreshPalette(); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/action/ExportSnippetAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/action/ExportSnippetAction.java new file mode 100644 index 0000000..5de028a --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/action/ExportSnippetAction.java @@ -0,0 +1,63 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.action; + +import org.tizen.efluibuilder.ui.actions.ActionConstants; +import org.tizen.efluibuilder.ui.editor.Messages; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewer; + + +public final class ExportSnippetAction extends AbstractPaletteAction { + + public ExportSnippetAction(PaletteViewer viewer) { + super(viewer); + setId(ActionConstants.EXPORT_SNIPPET); + setText(Messages.ACTION_EXPORT_SNIPPET); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled() + */ + @Override + protected boolean calculateEnabled() { + return true; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.action.Action#run() + */ + @Override + public void run() { + // ExportWizard wizard = new ExportWizard(); + // IWorkbench workbench = PlatformUI.getWorkbench(); + // Shell shell = workbench.getActiveWorkbenchWindow().getShell(); + // WizardDialog dialog = new WizardDialog(shell, wizard); + // dialog.open(); + } + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/action/ImportSnippetAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/action/ImportSnippetAction.java new file mode 100644 index 0000000..844420c --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/action/ImportSnippetAction.java @@ -0,0 +1,62 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.action; + +import org.tizen.efluibuilder.ui.actions.ActionConstants; +import org.tizen.efluibuilder.ui.editor.Messages; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewer; + + +public final class ImportSnippetAction extends AbstractPaletteAction { + + public ImportSnippetAction(PaletteViewer viewer) { + super(viewer); + setId(ActionConstants.IMPORT_SNIPPET); + setText(Messages.ACTION_IMPORT_SNIPPET); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled() + */ + @Override + protected boolean calculateEnabled() { + return true; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.action.Action#run() + */ + @Override + public void run() { + // ImportWizard wizard = new ImportWizard(); + // IWorkbench workbench = PlatformUI.getWorkbench(); + // Shell shell = workbench.getActiveWorkbenchWindow().getShell(); + // WizardDialog dialog = new WizardDialog(shell, wizard); + // dialog.open(); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/action/NewSnippetAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/action/NewSnippetAction.java new file mode 100644 index 0000000..ea609c5 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/action/NewSnippetAction.java @@ -0,0 +1,108 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.action; + +import java.util.List; + +import org.eclipse.gef.EditPart; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbenchPart; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.ui.actions.ActionConstants; +import org.tizen.efluibuilder.ui.editor.Messages; +import org.tizen.efluibuilder.ui.wizard.snippet.NewSnippetDialogPage; + + +public final class NewSnippetAction extends AbstractEditorAction { + protected static Logger logger = LoggerFactory.getLogger(AbstractPaletteAction.class); + + public NewSnippetAction(IWorkbenchPart part) { + super(part); + setId(ActionConstants.NEW_SNIPPET); + setText(Messages.ACTION_NEW_SNIPPET); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled() + */ + @Override + protected boolean calculateEnabled() { + List selectedObjects = getSelectedObjects(); + if (selectedObjects == null || selectedObjects.isEmpty()) { + return false; + } + + if (selectedObjects.size() != 1) { + return false; + } + + for (Object object : selectedObjects) { + if (!(object instanceof EditPart)) { + return false; + } + EditPart editpart = (EditPart) object; + Object model = editpart.getModel(); + if (!(model instanceof Part)) { + return false; + } + Part part = (Part) model; + if (part.getType() != PartType.COMPONENT) { + return false; + } + } + return true; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.action.Action#run() + */ + @Override + public void run() { + List selectedObjects = getSelectedObjects(); + Object object = selectedObjects.get(0); + if (!(object instanceof EditPart)) { + return; + } + EditPart editpart = (EditPart) object; + Object model = editpart.getModel(); + + Shell shell = Display.getDefault().getActiveShell(); + NewSnippetDialogPage dialog = new NewSnippetDialogPage(shell); + dialog.setModel(model); + int result = dialog.open(); + if (result == Dialog.OK) { + refreshPalette(); + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/DesignEditCommandStack.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/DesignEditCommandStack.java new file mode 100644 index 0000000..341cbf9 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/DesignEditCommandStack.java @@ -0,0 +1,230 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.designeditor; + +import java.util.List; + +import org.eclipse.emf.common.command.BasicCommandStack; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.gef.commands.CompoundCommand; +import org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager; +import org.eclipse.wst.sse.ui.internal.StructuredTextViewer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.common.util.Assert; +import org.tizen.efluibuilder.model.command.EMFCommandAdapter; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartObserver; +import org.tizen.efluibuilder.ui.editor.texteditor.TextEditor; +import org.tizen.efluibuilder.ui.view.databinding.model.command.ConfigureDataModelCommand; +import org.tizen.efluibuilder.ui.view.databinding.model.command.ConfigureDataSourceCommand; +import org.tizen.efluibuilder.ui.view.databinding.model.command.DataBindingCommandAdapter; +import org.tizen.efluibuilder.utility.DOMUtil; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + + +public class DesignEditCommandStack extends CommandStack { + + protected final Logger logger = LoggerFactory.getLogger(getClass()); + public static final String KEY_PART_COMMAND = "PART_COMMAND"; + + private IStructuredTextUndoManager undoManager; + private StructuredTextViewer textViewer; + + private Part documentPart = null; + private Part dataBindingPart = null; + + public DesignEditCommandStack(TextEditor textEditor, Part documentPart, Part dataBindingPart) { + super(); + + // UndoManager must not be null + Assert.notNull(textEditor); + // CommandStack of UndoManager must be BasicCommandStack + Assert.isTrue(textEditor.getModel().getUndoManager().getCommandStack() instanceof BasicCommandStack); + this.undoManager = textEditor.getModel().getUndoManager(); + this.textViewer = textEditor.getTextViewer(); + + this.documentPart = documentPart; + this.dataBindingPart = dataBindingPart; + } + + @Override + public void execute(Command command) { + execute(command, PartObserver.MESSAGE_GEF_EXECUTE); + } + + private void executeSuperWithoutStack(Command command) { + if ((command == null) || (!(command.canExecute()))) { + return; + } + + notifyListeners(command, PRE_EXECUTE); + try { + command.execute(); + notifyListeners(); + } finally { + notifyListeners(command, POST_EXECUTE); + } + } + + public void execute(Command command, String sender) { + try { + if (documentPart == null || executeDataBindingCommand(command)) { + return; + } + setPartCommandMode(DOMUtil.getDocument(documentPart.getElement()), true); + this.undoManager.beginRecording(this, KEY_PART_COMMAND); + try { + executeSuperWithoutStack(command); + if (textViewer.canDoOperation(StructuredTextViewer.FORMAT_DOCUMENT)) { + textViewer.doOperation(StructuredTextViewer.FORMAT_DOCUMENT); + } + } finally { + this.undoManager.endRecording(this); + setPartCommandMode(DOMUtil.getDocument(documentPart.getElement()), false); + } + + documentPart.getOwnerDocumentPart().notifyObservers(sender); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + // prevent silent exception + logger.error(e.getMessage(), e); + } + } + + @Override + public void undo() { + try { + // delegate to XML editor + org.eclipse.emf.common.command.Command undoCommand = undoManager.getUndoCommand(); + String commandKind = undoCommand != null ? undoCommand.getLabel() : null; + boolean isGEFCommand = (commandKind != null) && (commandKind.equals(KEY_PART_COMMAND)); + if (isGEFCommand) { + setPartCommandMode(DOMUtil.getDocument(documentPart.getElement()), true); + } + this.undoManager.undo(); + if (isGEFCommand) { + setPartCommandMode(DOMUtil.getDocument(documentPart.getElement()), false); + documentPart.getOwnerDocumentPart().notifyObservers(PartObserver.MESSAGE_GEF_UNDO); + } + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + // prevent silent exception + logger.error(e.getMessage(), e); + } + } + + @Override + public void redo() { + try { + // delegate to XML editor + org.eclipse.emf.common.command.Command redoCommand = undoManager.getRedoCommand(); + String commandKind = redoCommand != null ? redoCommand.getLabel() : null; + boolean isGEFCommand = (commandKind != null) && (commandKind.equals(KEY_PART_COMMAND)); + if (isGEFCommand) { + setPartCommandMode(DOMUtil.getDocument(documentPart.getElement()), true); + } + undoManager.redo(); + if (isGEFCommand) { + setPartCommandMode(DOMUtil.getDocument(documentPart.getElement()), false); + documentPart.getOwnerDocumentPart().notifyObservers(PartObserver.MESSAGE_GEF_REDO); + } + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + // prevent silent exception + logger.error(e.getMessage(), e); + } + } + + @Override + public boolean canRedo() { + // delegate to XML editor + return this.undoManager.getCommandStack().canRedo(); + } + + @Override + public boolean canUndo() { + // delegate to XML editor + return this.undoManager.getCommandStack().canUndo(); + } + + public static void setPartCommandMode(Node node, boolean mode) { + Document document = DOMUtil.getDocument(node); + if (document != null) { + document.setUserData(KEY_PART_COMMAND, mode, null); + } + } + + public static boolean isPartCommandMode(Node node) { + Document document = DOMUtil.getDocument(node); + if (document != null) { + Object userData = document.getUserData(KEY_PART_COMMAND); + if (userData instanceof Boolean) { + return (Boolean) userData; + } + } + + return false; + } + + private boolean executeDataBindingCommand(Command command) { + DataBindingCommandAdapter dataBindingCommand = new DataBindingCommandAdapter(dataBindingPart, this); + if (command instanceof ConfigureDataModelCommand || command instanceof ConfigureDataSourceCommand) { + EMFCommandAdapter emfCmd = new EMFCommandAdapter(command); + dataBindingCommand.append(emfCmd); + undoManager.getCommandStack().execute(dataBindingCommand); + return true; + } + if (command instanceof CompoundCommand) { + List commands = ((CompoundCommand) command).getCommands(); + for (Command cmd : commands) { + if (cmd instanceof ConfigureDataModelCommand || cmd instanceof ConfigureDataSourceCommand) { + EMFCommandAdapter emfCmd = new EMFCommandAdapter(cmd); + dataBindingCommand.append(emfCmd); + } + } + if (dataBindingCommand.isEmpty() == false) { + undoManager.getCommandStack().execute(dataBindingCommand); + return true; + } + } + return false; + } + + private static class DummyCommand extends Command { + final static DummyCommand INSTANCE = new DummyCommand(); + } + + public void makeDirtyByForce() { + // flush CommandStack to maintain always only one DummyCommand in CommandStack. + this.flush(); + super.execute(DummyCommand.INSTANCE); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/DesignEditor.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/DesignEditor.java new file mode 100644 index 0000000..ea13be3 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/DesignEditor.java @@ -0,0 +1,560 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.designeditor; + +import java.util.Collection; +import java.util.Collections; +import java.util.EventObject; +import java.util.List; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.gef.DefaultEditDomain; +import org.eclipse.gef.GraphicalViewer; +import org.eclipse.gef.MouseWheelHandler; +import org.eclipse.gef.SnapToGeometry; +import org.eclipse.gef.SnapToGrid; +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.gef.editparts.ZoomManager; +import org.eclipse.gef.rulers.RulerProvider; +import org.eclipse.gef.ui.actions.ActionRegistry; +import org.eclipse.gef.ui.actions.RedoAction; +import org.eclipse.gef.ui.actions.ToggleGridAction; +import org.eclipse.gef.ui.actions.ToggleRulerVisibilityAction; +import org.eclipse.gef.ui.actions.ToggleSnapToGeometryAction; +import org.eclipse.gef.ui.actions.UndoAction; +import org.eclipse.gef.ui.parts.GraphicalEditor; +import org.eclipse.gef.ui.parts.SelectionSynchronizer; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; +import org.tizen.common.util.cache.ColorCache; +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.BuilderPlugin; +import org.tizen.efluibuilder.gef.actions.AddEmptyViewAction; +import org.tizen.efluibuilder.gef.actions.AlignPartActionBottom; +import org.tizen.efluibuilder.gef.actions.AlignPartActionHCenter; +import org.tizen.efluibuilder.gef.actions.AlignPartActionHDistribute; +import org.tizen.efluibuilder.gef.actions.AlignPartActionLeft; +import org.tizen.efluibuilder.gef.actions.AlignPartActionRight; +import org.tizen.efluibuilder.gef.actions.AlignPartActionTop; +import org.tizen.efluibuilder.gef.actions.AlignPartActionVCenter; +import org.tizen.efluibuilder.gef.actions.AlignPartActionVDistribute; +import org.tizen.efluibuilder.gef.actions.StoryboardAutoLayoutAction; +import org.tizen.efluibuilder.gef.actions.CopyPartAction; +import org.tizen.efluibuilder.gef.actions.CutPartAction; +import org.tizen.efluibuilder.gef.actions.DeletePartAction; +import org.tizen.efluibuilder.gef.actions.MatchSizeAction; +import org.tizen.efluibuilder.gef.actions.MoveAbsolutePartAction; +import org.tizen.efluibuilder.gef.actions.PartAction; +import org.tizen.efluibuilder.gef.actions.PastePartAction; +import org.tizen.efluibuilder.gef.actions.PastePartColorAction; +import org.tizen.efluibuilder.gef.actions.SelectChildPartAction; +import org.tizen.efluibuilder.gef.actions.SelectNextSiblingPartAction; +import org.tizen.efluibuilder.gef.actions.SelectParentPartAction; +import org.tizen.efluibuilder.gef.actions.SelectPreviousSiblingPartAction; +import org.tizen.efluibuilder.gef.actions.SetStartupViewAction; +import org.tizen.efluibuilder.gef.actions.ZorderBackAction; +import org.tizen.efluibuilder.gef.actions.ZorderBackwardAction; +import org.tizen.efluibuilder.gef.actions.ZorderFrontAction; +import org.tizen.efluibuilder.gef.actions.ZorderFrontwardAction; +import org.tizen.efluibuilder.gef.dnd.model.ComponentTemplate; +import org.tizen.efluibuilder.gef.dnd.model.SnippetTemplate; +import org.tizen.efluibuilder.gef.editparts.DesignRootEditPart; +import org.tizen.efluibuilder.gef.tools.DesignCreationTool; +import org.tizen.efluibuilder.gef.tools.DesignEditDomain; +import org.tizen.efluibuilder.gef.tools.DesignSelectionTool; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.descriptors.WidgetDescriptor; +import org.tizen.efluibuilder.model.part.DocumentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.snippet.ISnippet; +import org.tizen.efluibuilder.model.snippet.ISnippetManager; +import org.tizen.efluibuilder.model.snippet.SnippetManager; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.efluibuilder.ui.editor.KeyHandler; +import org.tizen.efluibuilder.ui.editor.Messages; +import org.tizen.efluibuilder.ui.editor.MouseWheelZoomHandler; +import org.tizen.efluibuilder.ui.editor.action.NewSnippetAction; +import org.tizen.efluibuilder.ui.editor.dnd.listener.TemplateTransferDropTargetListener2; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.CombinedTemplateCreationEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteDrawer; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteRoot; +import org.tizen.efluibuilder.ui.editor.internal.gef.ruler.DesignEditorRulerComposite; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.DefaultPaletteViewerPreferences; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.FlyoutPaletteComposite; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.FlyoutPaletteComposite.FlyoutPreferences; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewer; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewerPreferences; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewerProvider; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.TizenEditDomain; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.views.palette.PalettePage; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.views.palette.PaletteViewerPage; +import org.tizen.efluibuilder.ui.editor.palette.DesignEditorPaletteViewerProvider; +import org.tizen.efluibuilder.ui.editor.palette.PaletteConstants; +import org.tizen.efluibuilder.ui.editor.palette.PaletteConstants.CATEGORY_ICON; +import org.tizen.efluibuilder.ui.editor.ruler.DesignerRuler; +import org.tizen.efluibuilder.ui.editor.ruler.DesignerRulerProvider; +import org.tizen.efluibuilder.ui.editor.texteditor.TextEditor; +import org.tizen.efluibuilder.ui.views.outline.actions.OutlineCreateTemplateAction; +import org.tizen.efluibuilder.ui.views.outline.actions.OutlineNewViewCtxPopupAction; +import org.tizen.efluibuilder.ui.views.outline.actions.OutlineNewViewPopupAction; +import org.tizen.efluibuilder.ui.views.outline.actions.OutlineNewViewTemplateAction; +import org.tizen.efluibuilder.utility.ResourceUtil; + +import edjResourceSyncManager.EdjResourceSyncManager; +import graphicalDataManager.GraphicalDataManager; + + +public class DesignEditor extends GraphicalEditor implements ISelectionChangedListener { + private static final int PALETTE_WIDTH = 222; // advux + private static final RGB CANVAS_BG_COLOR = new RGB(0xdc, 0xdc, 0xdc); + + private DesignViewer designerViewer = new DesignViewer(); + + private DesignEditorRulerComposite rulerComp = null; + + private PaletteViewerProvider paletteViewerProvider = null; + private Composite splitter = null; + + private SelectionSynchronizer selectionSynchronizer = null; + private Part documentPart = null; + + public void initContents(Part documentPart, Part dataBindingPart, SelectionSynchronizer selectionSynchronizer, + GraphicalDataManager graphicalDataManager, + EdjResourceSyncManager edjResSyncMgr, + CombineEditorPart editor, + TextEditor textEditor) { + this.documentPart = documentPart; + this.selectionSynchronizer = selectionSynchronizer; + ((TizenEditDomain) getEditDomain()).setPaletteRoot(createPaletteRoot()); + getEditDomain().setCommandStack(new DesignEditCommandStack(textEditor, documentPart, dataBindingPart)); + getEditDomain().getCommandStack().addCommandStackListener(this); + + hookGraphicalViewer(); + designerViewer.initContents(documentPart, getEditorInput(), graphicalDataManager, edjResSyncMgr, editor); + designerViewer.setProperty(MouseWheelHandler.KeyGenerator.getKey(SWT.MOD1), MouseWheelZoomHandler.SINGLETON); + + } + + @Override + protected void setInput(IEditorInput input) { + super.setInput(input); + DesignEditDomain editDomain = new DesignEditDomain(this); + editDomain.setDefaultTool(new DesignSelectionTool()); + setEditDomain(editDomain); + } + + private FlyoutPreferences setupFlyoutPreference() { + FlyoutPreferences flyoutPreferences = new FlyoutPaletteComposite.FlyoutPreferences() { + @Override + public int getDockLocation() { + return getPreferenceStore().getInt(BuilderConstants.PROPERTY_DOCK_LOCATION); + } + + @Override + public int getPaletteState() { + return getPreferenceStore().getInt(BuilderConstants.PROPERTY_STATE); + } + + @Override + public int getPaletteWidth() { + return getPreferenceStore().getInt(BuilderConstants.PROPERTY_PALETTE_WIDTH); + } + + private IPreferenceStore getPreferenceStore() { + return BuilderPlugin.getDefault().getPreferenceStore(); + } + + @Override + public void setDockLocation(int location) { + getPreferenceStore().setValue(BuilderConstants.PROPERTY_DOCK_LOCATION, location); + } + + @Override + public void setPaletteState(int state) { + getPreferenceStore().setValue(BuilderConstants.PROPERTY_STATE, state); + } + + @Override + public void setPaletteWidth(int width) { + getPreferenceStore().setValue(BuilderConstants.PROPERTY_PALETTE_WIDTH, width); + } + + }; + flyoutPreferences.setDockLocation(PositionConstants.EAST); // advux: palette position + flyoutPreferences.setPaletteState(FlyoutPaletteComposite.STATE_PINNED_OPEN); + flyoutPreferences.setPaletteWidth(PALETTE_WIDTH); // advux + + return flyoutPreferences; + } + + @Override + public void createPartControl(Composite parent) { + DefaultPaletteViewerPreferences preferences = new DefaultPaletteViewerPreferences(); + preferences.setLayoutSetting(PaletteViewerPreferences.LAYOUT_COLUMNS); + preferences.setUseLargeIcons(PaletteViewerPreferences.LAYOUT_COLUMNS, false); + PaletteViewer paletteViewer = ((TizenEditDomain) getEditDomain()).getTizenPaletteViewer(); // advux + if (paletteViewer != null) { + paletteViewer.setPaletteViewerPreferences(preferences); + } + + if (splitter == null) { + FlyoutPreferences flyoutPreferences = setupFlyoutPreference(); + paletteViewerProvider = new DesignEditorPaletteViewerProvider(getEditDomain()); // advux + splitter = + new FlyoutPaletteComposite(parent, SWT.NONE, getSite().getPage(), paletteViewerProvider, + flyoutPreferences); // advux + } + if (rulerComp == null) { + rulerComp = new DesignEditorRulerComposite(splitter, SWT.NONE); + } + + super.createPartControl(splitter); + ((FlyoutPaletteComposite) splitter).setGraphicalControl(rulerComp); + } + + @Override + protected void createGraphicalViewer(Composite parent) { + designerViewer.addSelectionChangedListener(this); + designerViewer.setDesignerKeyHandler(new KeyHandler(getActionRegistry())); + + rulerComp = new DesignEditorRulerComposite(parent, SWT.NONE); + designerViewer.createControl(rulerComp); + setGraphicalViewer(designerViewer); + configureGraphicalViewer(); + initializeGraphicalViewer(); + rulerComp.setGraphicalViewer(designerViewer); + + // rulerComp.addListener(SWT.Resize, this); + } + + @Override + protected void initializeGraphicalViewer() { + } + + @Override + protected void configureGraphicalViewer() { + super.configureGraphicalViewer(); + GraphicalViewer viewer = getGraphicalViewer(); + configureRuler(viewer); + configureGeometry(viewer); + configureGrid(viewer); + getGraphicalViewer().setContextMenu(new DesignEditorContextMenu(this, getActionRegistry())); + viewer.getControl().setBackground(ColorCache.getColorFromRGB(CANVAS_BG_COLOR)); + } + + private PaletteRoot createPaletteRoot() { + PaletteRoot root = new PaletteRoot(); + + // create widget group + createComponentGroup(root, PaletteDrawer.INITIAL_STATE_OPEN); + + // create snippet group + createSnippetGroup(root, PaletteDrawer.INITIAL_STATE_OPEN); + return root; + } + + private String getCategoryTitle(String name, int totalNum) { + return name + " (" + totalNum + ")"; + } + + private void createComponentGroup(PaletteRoot root, int style) { + ComponentDescriptor componentDescriptor = ((DocumentPart) documentPart).getComponentDescriptor(); + Collection categories = componentDescriptor.getWidgetCategories(); + for (String category : categories) { + // create drawer + PaletteDrawer drawer = new PaletteDrawer(category, null); + drawer.setDescription(category); + drawer.setInitialState(style); + + List descriptors = componentDescriptor.getWidgetDescriptorsOfCategory(category); + if (!category.equals(PaletteConstants.CATEGORY_NAME_UI_VIEWS)) { + Collections.sort(descriptors); // new UI: ascend sort + } + + int size = descriptors.size(); + for (int i = 0; i < size; i++) { + WidgetDescriptor desc = descriptors.get(i); + if (desc.isPaletteVisible()) { + String name = desc.getDisplayName(); + if (name.equals("View")) { //$NON-NLS-1$ + name = "Empty"; //$NON-NLS-1$ + } + String id = desc.getDescriptorId(); + String description = desc.getDescription(); + ImageDescriptor smallIcon = ResourceUtil.getImageDescriptor(BuilderPlugin.PLUGIN_ID, BuilderConstants.ICON_DIR + desc.getSmallIcon()); + ComponentTemplate template = new ComponentTemplate((DocumentPart) documentPart, id); + CombinedTemplateCreationEntry entry = new DesignEditorCombinedTemplateCreationEntry(name, description, template, template.getFactory(), + smallIcon, smallIcon, desc.getSmallIcon()); + entry.setToolClass(DesignCreationTool.class); + drawer.add(entry); + } + } + if (PaletteConstants.CATEGORY_ICON.get(category) != null) { + drawer.setSmallIcon(PaletteConstants.CATEGORY_ICON.get(category).getImageDescriptor(false)); + } + + drawer.setLabel(getCategoryTitle(category, drawer.getChildren().size())); + + root.add(drawer); + } + } + + private void createSnippetGroup(PaletteRoot root, int style) { + // add snippets + ISnippetManager snippetManager = SnippetManager.getDefault(); + List snippets = snippetManager.getSnippets(); + + Collections.sort(snippets); // new UI: ascend sort + + PaletteDrawer snippetDrawer = new PaletteDrawer(Messages.PALETTE_GROUP_SNIPPET, null); + snippetDrawer.setDescription(Messages.PALETTE_GROUP_SNIPPET); + snippetDrawer.setInitialState(style); + + for (ISnippet snippet : snippets) { + String name = snippet.getName(); + String description = snippet.getDescription(); + SnippetTemplate template = new SnippetTemplate(snippet, (DocumentPart) documentPart); + ImageDescriptor smallIcon = snippet.getSmallIcon(); + + CombinedTemplateCreationEntry entry = new DesignEditorCombinedTemplateCreationEntry(name, description, template, template.getFactory(), smallIcon, + smallIcon, snippet.getSmallIconPath()); + + entry.setToolClass(DesignCreationTool.class); + snippetDrawer.add(entry); + } + CATEGORY_ICON categoryIcon = PaletteConstants.CATEGORY_ICON.get(Messages.PALETTE_GROUP_SNIPPET); + if (categoryIcon != null) { + snippetDrawer.setSmallIcon(categoryIcon.getImageDescriptor(false)); + } + snippetDrawer.setLabel(getCategoryTitle(Messages.PALETTE_GROUP_SNIPPET, snippetDrawer.getChildren().size())); + + root.add(snippetDrawer); + } + + public void addTemplateTransferDropTargetListener2(TemplateTransferDropTargetListener2 listener) { + designerViewer.addTemplateTransferDropTargetListener2(listener); + } + + public void removeTemplateTransferDropTargetListener2(TemplateTransferDropTargetListener2 listener) { + designerViewer.removeTemplateTransferDropTargetListener2(listener); + } + + public DefaultEditDomain getEditDomain() { + return super.getEditDomain(); + } + + public ActionRegistry getActions() { + return getActionRegistry(); + } + + @SuppressWarnings("unchecked") + private void registerOutlineActions(IAction action) { + ActionRegistry actionRegistry = getActionRegistry(); + actionRegistry.registerAction(action); + getSelectionActions().add(action.getId()); + } + + @Override + protected void createActions() { + if (designerViewer == null) { + return; + } + + final int moveDist = MoveAbsolutePartAction.MOVE_DIST; + final boolean moveOverflow = false; + final boolean movePixelBase = false; + + IAction pastePartAction = new PastePartAction(this, designerViewer.getRootEditPart()); + IAction[] actions = { new UndoAction(this), new RedoAction(this), new DeletePartAction(this, designerViewer.getRootEditPart()), + + // == Outline + // new OutlineRenameAction(this), + new AddEmptyViewAction(this, designerViewer.getRootEditPart()), new OutlineNewViewTemplateAction(designerViewer, this), + new OutlineNewViewPopupAction(this), new OutlineNewViewCtxPopupAction(this), new OutlineCreateTemplateAction(this), + new SetStartupViewAction(this, designerViewer.getRootEditPart()), + + new CopyPartAction(this, designerViewer.getRootEditPart(), (PartAction) pastePartAction), + new CutPartAction(this, designerViewer.getRootEditPart(), (PartAction) pastePartAction), pastePartAction, + new PastePartColorAction(this, designerViewer.getRootEditPart()), + + new MoveAbsolutePartAction(this, PositionConstants.LEFT, moveDist, designerViewer.getRootEditPart(), moveOverflow, movePixelBase), + new MoveAbsolutePartAction(this, PositionConstants.RIGHT, moveDist, designerViewer.getRootEditPart(), moveOverflow, movePixelBase), + new MoveAbsolutePartAction(this, PositionConstants.TOP, moveDist, designerViewer.getRootEditPart(), moveOverflow, movePixelBase), + new MoveAbsolutePartAction(this, PositionConstants.BOTTOM, moveDist, designerViewer.getRootEditPart(), moveOverflow, movePixelBase), + + new NewSnippetAction(this), + + new AlignPartActionLeft(this, designerViewer.getRootEditPart()), new AlignPartActionTop(this, designerViewer.getRootEditPart()), + new AlignPartActionRight(this, designerViewer.getRootEditPart()), new AlignPartActionBottom(this, designerViewer.getRootEditPart()), + new AlignPartActionHCenter(this, designerViewer.getRootEditPart()), new AlignPartActionVCenter(this, designerViewer.getRootEditPart()), + new AlignPartActionHDistribute(this, designerViewer.getRootEditPart()), new AlignPartActionVDistribute(this, designerViewer.getRootEditPart()), + + new SelectParentPartAction(this, designerViewer.getRootEditPart()), new SelectChildPartAction(this, designerViewer.getRootEditPart()), + new SelectPreviousSiblingPartAction(this, designerViewer.getRootEditPart()), + new SelectNextSiblingPartAction(this, designerViewer.getRootEditPart()), + new MatchSizeAction(this, designerViewer.getRootEditPart(), MatchSizeAction.TYPE_WIDTH), + new MatchSizeAction(this, designerViewer.getRootEditPart(), MatchSizeAction.TYPE_HEIGHT), + + // zorder + new ZorderBackAction(this, designerViewer.getRootEditPart()), new ZorderBackwardAction(this, designerViewer.getRootEditPart()), + new ZorderFrontAction(this, designerViewer.getRootEditPart()), new ZorderFrontwardAction(this, designerViewer.getRootEditPart()), + + // storyboard + new StoryboardAutoLayoutAction(this, designerViewer.getRootEditPart()), + }; + + for (IAction action : actions) { + registerOutlineActions(action); + } + + } + + @Override + public void commandStackChanged(EventObject event) { + super.commandStackChanged(event); + firePropertyChange(IEditorPart.PROP_DIRTY); + updateActions(getSelectionActions()); + } + + private void configureRuler(GraphicalViewer viewer) { + if (viewer != null) { + viewer.setProperty(RulerProvider.PROPERTY_VERTICAL_RULER, new DesignerRulerProvider(new DesignerRuler(false))); + viewer.setProperty(RulerProvider.PROPERTY_HORIZONTAL_RULER, new DesignerRulerProvider(new DesignerRuler(true))); + viewer.setProperty(RulerProvider.PROPERTY_RULER_VISIBILITY, false); + + IAction action = new ToggleRulerVisibilityAction(viewer); + getActionRegistry().registerAction(action); + } + } + + private void configureGeometry(GraphicalViewer viewer) { + if (viewer != null) { + viewer.setProperty(SnapToGeometry.PROPERTY_SNAP_ENABLED, false); + IAction action = new ToggleSnapToGeometryAction(viewer); + getActionRegistry().registerAction(action); + } + } + + private void configureGrid(GraphicalViewer viewer) { + if (viewer != null) { + viewer.setProperty(SnapToGrid.PROPERTY_GRID_ENABLED, true); + viewer.setProperty(SnapToGrid.PROPERTY_GRID_VISIBLE, false); + + IAction action = new ToggleGridAction(viewer); + getActionRegistry().registerAction(action); + } + } + + @Override + @SuppressWarnings("rawtypes") + public Object getAdapter(Class type) { + + if (null == type) { + return null; + } + // CommandStack + if (type.equals(CommandStack.class)) { + return getCommandStack(); + } + + if (type == PalettePage.class) { + return new PaletteViewerPage(paletteViewerProvider); + } + + if (type == ZoomManager.class) { + return ((DesignRootEditPart) getGraphicalViewer().getRootEditPart()).getZoomManager(); + } + + return super.getAdapter(type); + } + + @Override + public SelectionSynchronizer getSelectionSynchronizer() { + return selectionSynchronizer; + } + + @Override + public boolean isSaveAsAllowed() { + return false; + } + + @Override + public void setFocus() { + if (getGraphicalViewer() != null) { + getGraphicalViewer().getControl().setFocus(); + } + } + + @Override + public void selectionChanged(SelectionChangedEvent arg0) { + updateActions(getSelectionActions()); + } + + @Override + public void doSave(IProgressMonitor arg0) { + } + + public DesignViewer getViewer() { + return designerViewer; + } + + public void refreshPalette() { + PaletteRoot root = ((TizenEditDomain) getEditDomain()).getTizenPaletteViewer().getPaletteRoot(); + + // remove snippets in palette + List palettes = root.getChildren(); + for (int i = 0; i < palettes.size(); i++) { + if (palettes.get(i) instanceof PaletteDrawer) { + PaletteDrawer palette = (PaletteDrawer) palettes.get(i); + if (palette.getLabel().startsWith(Messages.PALETTE_GROUP_SNIPPET)) { + palettes.remove(i); + break; + } + } + } + + createSnippetGroup(root, PaletteDrawer.INITIAL_STATE_OPEN); + } + + public void setGraphicalViewer(GraphicalViewer viewer) { + super.setGraphicalViewer(viewer); + + getSite().setSelectionProvider(viewer); + } + + public void refreshActions() { + updateActions(getSelectionActions()); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/DesignEditorActionBarContributor.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/DesignEditorActionBarContributor.java new file mode 100644 index 0000000..50be90d --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/DesignEditorActionBarContributor.java @@ -0,0 +1,163 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.designeditor; + +import org.eclipse.gef.ui.actions.ActionBarContributor; +import org.eclipse.gef.ui.actions.DeleteRetargetAction; +import org.eclipse.gef.ui.actions.MatchHeightRetargetAction; +import org.eclipse.gef.ui.actions.MatchWidthRetargetAction; +import org.eclipse.gef.ui.actions.RedoRetargetAction; +import org.eclipse.gef.ui.actions.UndoRetargetAction; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IContributionItem; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.actions.ActionFactory; +import org.eclipse.ui.actions.RetargetAction; +import org.tizen.efluibuilder.gef.actions.AlignPartAction; +import org.tizen.efluibuilder.gef.actions.AlignPartRetargetAction; +import org.tizen.efluibuilder.gef.actions.Messages; +import org.tizen.efluibuilder.ui.actions.ActionConstants; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.efluibuilder.ui.resources.ImageResources; + + +public class DesignEditorActionBarContributor extends ActionBarContributor { + + public DesignEditorActionBarContributor() { + } + + @Override + protected void buildActions() { + + addRetargetAction(new UndoRetargetAction()); + addRetargetAction(new RedoRetargetAction()); + addRetargetAction(new DeleteRetargetAction()); + + IWorkbenchWindow window = getPage().getWorkbenchWindow(); + addRetargetAction((RetargetAction) ActionFactory.CUT.create(window)); + addRetargetAction((RetargetAction) ActionFactory.COPY.create(window)); + addRetargetAction((RetargetAction) ActionFactory.PASTE.create(window)); + + // addRetargetAction(new AlignmentRetargetAction(PositionConstants.LEFT)); + // addRetargetAction(new AlignmentRetargetAction(PositionConstants.CENTER)); + // addRetargetAction(new AlignmentRetargetAction(PositionConstants.RIGHT)); + // addRetargetAction(new AlignmentRetargetAction(PositionConstants.TOP)); + // addRetargetAction(new AlignmentRetargetAction(PositionConstants.MIDDLE)); + // addRetargetAction(new AlignmentRetargetAction(PositionConstants.BOTTOM)); + + addRetargetAction(new AlignPartRetargetAction(AlignPartAction.TYPE_LEFT)); + addRetargetAction(new AlignPartRetargetAction(AlignPartAction.TYPE_HORIZONTAL_CENTER)); + addRetargetAction(new AlignPartRetargetAction(AlignPartAction.TYPE_RIGHT)); + + addRetargetAction(new AlignPartRetargetAction(AlignPartAction.TYPE_TOP)); + addRetargetAction(new AlignPartRetargetAction(AlignPartAction.TYPE_VERTICAL_CENTER)); + addRetargetAction(new AlignPartRetargetAction(AlignPartAction.TYPE_BOTTOM)); + + addRetargetAction(new AlignPartRetargetAction(AlignPartAction.TYPE_DISTRIBUTE_HORIZONTAL_SPACING)); + addRetargetAction(new AlignPartRetargetAction(AlignPartAction.TYPE_DISTRIBUTE_VERTICAL_SPACING)); + + MatchWidthRetargetAction matchWidthRetargetAction = new MatchWidthRetargetAction(); + matchWidthRetargetAction.setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_WIDTH_NOR)); + matchWidthRetargetAction.setDisabledImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_WIDTH_DIM)); + matchWidthRetargetAction.setHoverImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_WIDTH_MV)); + matchWidthRetargetAction.setToolTipText(Messages.ACTION_MATCH_WIDTH); + addRetargetAction(matchWidthRetargetAction); + + MatchHeightRetargetAction matchHeightRetargetAction = new MatchHeightRetargetAction(); + matchHeightRetargetAction.setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_HEIGHT_NOR)); + matchHeightRetargetAction.setDisabledImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_HEIGHT_DIM)); + matchHeightRetargetAction.setHoverImageDescriptor(ImageResources.getImageDescriptor(ImageResources.TOOLBAR_ALIGN_HEIGHT_MV)); + matchHeightRetargetAction.setToolTipText(Messages.ACTION_MATCH_HEIGHT); + addRetargetAction(matchHeightRetargetAction); + } + + @Override + public void contributeToMenu(IMenuManager menuManager) { + super.contributeToMenu(menuManager); + + // MenuManager viewMenu = new MenuManager("View"); + // viewMenu.add(getAction(GEFActionConstants.TOGGLE_RULER_VISIBILITY)); + // viewMenu.add(getAction(GEFActionConstants.TOGGLE_SNAP_TO_GEOMETRY)); + // viewMenu.add(getAction(GEFActionConstants.TOGGLE_GRID_VISIBILITY)); + // menuManager.add(viewMenu); + } + + @Override + public void contributeToToolBar(IToolBarManager toolBarManager) { + super.contributeToToolBar(toolBarManager); + + // addActionsToToolBar(toolBarManager); + } + + private void addActionsToToolBar(IToolBarManager toolBarManager) { + Object[] actionIds = { + // ActionFactory.UNDO.getId(), + // ActionFactory.REDO.getId(), + // new Separator(), + // ActionFactory.CUT.getId(), + // ActionFactory.COPY.getId(), + // ActionFactory.PASTE.getId(), + // new Separator(), + // ActionFactory.DELETE.getId(), + new Separator(), ActionConstants.ALIGN_LEFT, ActionConstants.ALIGN_HORIZONTAL_CENTER, ActionConstants.ALIGN_RIGHT, new Separator(), + ActionConstants.ALIGN_TOP, ActionConstants.ALIGN_VERTICAL_CENTER, ActionConstants.ALIGN_BOTTOM, + // new Separator(), + // ActionConstants.ALIGN_DISTRIBUTE_HORIZONTAL_SPACING, + // ActionConstants.ALIGN_DISTRIBUTE_VERTICAL_SPACING, + new Separator(), ActionConstants.MATCH_WIDTH, ActionConstants.MATCH_HEIGHT, }; + + for (Object actionObj : actionIds) { + if (actionObj instanceof String) { + IAction action = getAction((String) actionObj); + toolBarManager.add(action); + } else if (actionObj instanceof IContributionItem) { + toolBarManager.add((IContributionItem) actionObj); + } else { + throw new IllegalArgumentException("Not matched actions"); + } + } + } + + public void contributeToCustomToolBar(IToolBarManager toolBarManager) { + buildActions(); + addActionsToToolBar(toolBarManager); + } + + @Override + protected void declareGlobalActionKeys() { + } + + @Override + public void setActiveEditor(IEditorPart editor) { + if (editor instanceof CombineEditorPart) { + if (((CombineEditorPart) editor).getActivePage() == CombineEditorPart.DESIGN_TAB) { + super.setActiveEditor(editor); + } + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/DesignEditorCombinedTemplateCreationEntry.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/DesignEditorCombinedTemplateCreationEntry.java new file mode 100644 index 0000000..f17be99 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/DesignEditorCombinedTemplateCreationEntry.java @@ -0,0 +1,102 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.designeditor; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.eclipse.gef.requests.CreationFactory; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.BuilderPlugin; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.CombinedTemplateCreationEntry; + + +public class DesignEditorCombinedTemplateCreationEntry extends CombinedTemplateCreationEntry { + + public enum State { + NORMAL("nor"), SELECT("sel"), MOUSEOVER("mv"); + + String value; + + State(String value) { + this.value = value; + } + + public String get() { + return this.value; + } + } + + private State currentState = State.NORMAL; + private ImageDescriptor selectImageDescriptor = null; + private ImageDescriptor mouseOverImageDescriptor = null; + + private final Pattern pattern = Pattern.compile("(.*)nor(.*)"); + private String iconSmallPath; + + public DesignEditorCombinedTemplateCreationEntry(String label, String shortDesc, Object template, CreationFactory factory, ImageDescriptor iconSmall, + ImageDescriptor iconLarge, String iconSmallPath) { + super(label, shortDesc, template, factory, iconSmall, iconLarge); + + this.iconSmallPath = iconSmallPath; + } + + @Override + public ImageDescriptor getSmallIcon() { + String path = getSelectedIconPath(); + + switch (currentState) { + case SELECT: + if (selectImageDescriptor == null) { + selectImageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(BuilderPlugin.PLUGIN_ID, path); + } + return selectImageDescriptor; + case MOUSEOVER: + if (mouseOverImageDescriptor == null) { + mouseOverImageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(BuilderPlugin.PLUGIN_ID, path); + } + return mouseOverImageDescriptor; + default: + return super.getSmallIcon(); + } + } + + private String getSelectedIconPath() { + Matcher matcher = this.pattern.matcher(this.iconSmallPath); + if (matcher.matches()) { + String prefix = matcher.group(1); + String postfix = matcher.group(2); + + return BuilderConstants.ICON_DIR + prefix + currentState.get() + postfix; + } + + return null; + } + + public void setIconMode(State state) { + currentState = state; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/DesignEditorContextMenu.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/DesignEditorContextMenu.java new file mode 100644 index 0000000..5a70f8b --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/DesignEditorContextMenu.java @@ -0,0 +1,73 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.designeditor; + +import org.eclipse.gef.ui.actions.ActionRegistry; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.Separator; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.ui.actions.ActionConstants; +import org.tizen.efluibuilder.ui.contextmenu.CommonContextMenu; + + +public class DesignEditorContextMenu extends CommonContextMenu { + + private DesignEditor editor = null; + public DesignEditorContextMenu(DesignEditor editor, ActionRegistry registry) { + super(editor.getViewer(), registry); + this.editor = editor; + } + + @Override + public void buildContextMenu(IMenuManager menu) { + editor.refreshActions(); + addUndoContextMenu(menu); + addNewContextMenu(menu); + addEditContextMenu(menu); + addAlignContextMenu(menu); + addZOrderContextMenu(menu); + addSelectionSpecificMenu(menu); + return; + } + + private void addSelectionSpecificMenu(IMenuManager menu) { + EditPartSet partSet = getSelectedPartSet(); + if (partSet.type == EditPartSet.TYPE_VIEW || partSet.type == EditPartSet.TYPE_EMPTY) { + addViewSpecificContextMenu(menu); + } else if (partSet.type == EditPartSet.TYPE_COMPONENT && partSet.components.size() == 1) { + DesignEditorContextMenuItemManager mgr = new DesignEditorContextMenuItemManager((DesignViewer) getViewer(), (Part) partSet.components.get(0).getModel()); + mgr.addCreateConnectionMenu(menu, partSet.components); + } + } + + private void addZOrderContextMenu(IMenuManager menu) { + menu.add(new Separator(ActionConstants.GROUP_ZORDER)); + appendAction(ActionConstants.ZORDER_BACK, menu, ActionConstants.GROUP_ZORDER); + appendAction(ActionConstants.ZORDER_BACKWARD, menu, ActionConstants.GROUP_ZORDER); + appendAction(ActionConstants.ZORDER_FRONT, menu, ActionConstants.GROUP_ZORDER); + appendAction(ActionConstants.ZORDER_FRONTWARD, menu, ActionConstants.GROUP_ZORDER); + + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/DesignEditorContextMenuItemManager.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/DesignEditorContextMenuItemManager.java new file mode 100644 index 0000000..eb65a39 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/DesignEditorContextMenuItemManager.java @@ -0,0 +1,206 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.designeditor; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.gef.EditPart; +import org.eclipse.jface.action.ContributionItem; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.Shell; +import org.tizen.efluibuilder.gef.viewer.ConnectionCreater; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.descriptors.EventDescriptor; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.EventPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; + + +public class DesignEditorContextMenuItemManager { + + private static class TargetViewDialog extends Dialog { + + private int WIDTH = 350; + private int HEIGHT = 160; + private List viewList; + private DesignViewer viewer; + private Part source; + private String eventName; + private Combo viewCombo; + + public TargetViewDialog(DesignViewer viewer, List viewList, Part source, String eventName) { + super(viewer.getControl().getShell()); + this.viewer = viewer; + this.source = source; + this.eventName = eventName; + this.viewList = viewList; + } + + private void setComboContents(Combo combo) { + String[] contents = new String[viewList.size()]; + for (int i = 0; i < viewList.size(); i++) { + contents[i] = viewList.get(i).getPropertyValue(LayoutSchemaConstants.ID); + } + combo.setItems(contents); + combo.select(0); + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite parentComposite = (Composite) super.createDialogArea(parent); + Composite contentComposite = new Composite(parentComposite, SWT.NONE); + contentComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + GridLayout layout = new GridLayout(2, false); + contentComposite.setLayout(layout); + Label label = new Label(contentComposite, SWT.NONE); + label.setText(Messages.SET_TARGET_VIEW_DIALOG_TITLE); + viewCombo = new Combo(contentComposite, SWT.NONE); + GridData data = new GridData(); + data.grabExcessHorizontalSpace = true; + data.horizontalAlignment = GridData.FILL; + viewCombo.setLayoutData(data); + setComboContents(viewCombo); + return parentComposite; + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText(Messages.SET_TARGET_VIEW_DIALOG_TITLE); + } + + @Override + protected void okPressed() { + ConnectionCreater.createConnection(viewer, source, viewList.get(viewCombo.getSelectionIndex()), eventName); + super.okPressed(); + } + + @Override + protected Point getInitialSize() { + return new Point(WIDTH, HEIGHT); + } + } + + private class MenuContributionItem extends ContributionItem { + private Part model; + + public MenuContributionItem(Part model) { + this.model = model; + } + + private SelectionListener createTransitionEventSelectedListener(final String eventName) { + return new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent arg0) { + List targetViewList = getTargetViewList(((ComponentPart) model).getOwnerViewPart().getPropertyValue(LayoutSchemaConstants.ID)); + if (targetViewList.size() > 0) { + TargetViewDialog dialog = new TargetViewDialog(viewer, targetViewList, + model, eventName); + dialog.open(); + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + } + }; + } + + @Override + public void fill(Menu menu, int index) { + boolean binded = false; + MenuItem menuItem = null; + ComponentDescriptor componentDescriptor = model.getOwnerDocumentPart().getComponentDescriptor(); + for (final EventDescriptor descriptor : componentDescriptor.getWidgetDescriptor(model.getDescriptorId()).getEventDescriptors()) { + binded = false; + + for (EventPart sourcePartEvent : ((ComponentPart) model).getEventParts()) { + if (descriptor.getEventDisplayName().equals(sourcePartEvent.getPropertyValue(LayoutSchemaConstants.EVENT_SIGNAL))) { + binded = true; + break; + } + } + menuItem = new MenuItem(menu, SWT.POP_UP); + menuItem.setText(descriptor.getEventDisplayName()); + menuItem.addSelectionListener(createTransitionEventSelectedListener(descriptor.getEventDisplayName())); + menuItem.setEnabled(!binded); + } + } + } + + private DesignViewer viewer = null; + private Part documentPart = null; + + public DesignEditorContextMenuItemManager(DesignViewer viewer, Part sourcePart) { + this.viewer = viewer; + this.documentPart = sourcePart.getOwnerDocumentPart(); + } + + private List getTargetViewList(String currViewName) { + List targetViewList = new ArrayList(); + Part viewsPart = PartUtil.findViewsPart(documentPart); + for (Part viewPart : viewsPart.getChildren()) { + if (currViewName.equals(viewPart.getPropertyValue(LayoutSchemaConstants.ID))) { + continue; + } + targetViewList.add(viewPart); + } + return targetViewList; + } + + public void addCreateConnectionMenu(IMenuManager menuMgr, List selectedEditParts) { + if (selectedEditParts.size() == 1) { + EditPart editPart = selectedEditParts.get(0); + Part model = (Part) editPart.getModel(); + ComponentDescriptor componentDescriptor = model.getOwnerDocumentPart().getComponentDescriptor(); + List listEvents = componentDescriptor.getWidgetDescriptor(model.getDescriptorId()).getEventDescriptors(); + if (!listEvents.isEmpty()) { + menuMgr.add(new Separator()); + MenuManager subMenuMgr = new MenuManager(Messages.CREATE_CONNECTION_MENU_NAME, null, Messages.CREATE_CONNECTION_MENU_NAME); + subMenuMgr.add(new MenuContributionItem(model)); + menuMgr.add(subMenuMgr); + } + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/DesignEditorException.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/DesignEditorException.java new file mode 100644 index 0000000..6b762ec --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/DesignEditorException.java @@ -0,0 +1,37 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.designeditor; + +public final class DesignEditorException extends RuntimeException { + + private static final long serialVersionUID = -5758363921548681956L; + + public DesignEditorException(String message) { + super(message); + } + + public DesignEditorException(String message, Throwable e) { + super(message, e); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/DesignEditorLayout.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/DesignEditorLayout.java new file mode 100644 index 0000000..b736fd8 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/DesignEditorLayout.java @@ -0,0 +1,75 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.designeditor; + +import org.eclipse.swt.custom.CTabFolder; +import org.eclipse.swt.custom.CTabItem; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Layout; +import org.tizen.efluibuilder.nl.BuilderMessages; +import org.tizen.efluibuilder.utility.PlatformUtil; + + +public class DesignEditorLayout extends Layout { + private Composite menPart; + private Composite tabPart; + + public DesignEditorLayout(Composite menu, Composite tabFolder) { + this.menPart = menu; + this.tabPart = tabFolder; + } + + @Override + protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) { + return null; + } + + @Override + protected void layout(Composite composite, boolean flushCache) { + Rectangle parentRect = composite.getBounds(); + int MENU_HEIGHT = 0; + + CTabItem item = ((CTabFolder) tabPart).getSelection(); + if (item != null && !item.getText().equals(BuilderMessages.TABTEXTTEXTEDITOR)) { + if (PlatformUtil.getOS().equals(PlatformUtil.OS_LINUX)) { + MENU_HEIGHT = 30; + } else { + MENU_HEIGHT = 23; + } + } + int min_height = MENU_HEIGHT; + int design_height = parentRect.height; + + if (parentRect.height > min_height) { + design_height -= min_height; + } else { + design_height = 0; + } + + menPart.setBounds(0, 0, parentRect.width, MENU_HEIGHT); + tabPart.setBounds(0, MENU_HEIGHT, parentRect.width, design_height); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/Messages.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/Messages.java new file mode 100644 index 0000000..de449d6 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/Messages.java @@ -0,0 +1,41 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.designeditor; + +import org.eclipse.osgi.util.NLS; + + +public final class Messages { + private static final String BUNDLE_NAME = Messages.class.getName(); + + public static String SET_TARGET_VIEW_DIALOG_TITLE; + public static String CREATE_CONNECTION_MENU_NAME; + static { + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/Messages.properties b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/Messages.properties new file mode 100644 index 0000000..84cc40e --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/designeditor/Messages.properties @@ -0,0 +1,3 @@ +# Messages +SET_TARGET_VIEW_DIALOG_TITLE=Target View +CREATE_CONNECTION_MENU_NAME=Create Connections \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/dnd/listener/DesignEditorDropTargetListener.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/dnd/listener/DesignEditorDropTargetListener.java new file mode 100644 index 0000000..19f0b2b --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/dnd/listener/DesignEditorDropTargetListener.java @@ -0,0 +1,209 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.dnd.listener; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.dnd.TemplateTransfer; +import org.eclipse.gef.dnd.TemplateTransferDropTargetListener; +import org.eclipse.gef.requests.CreationFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.FileTransfer; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Shell; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.gef.dnd.model.DataBindingTemplate; +import org.tizen.efluibuilder.gef.dnd.model.ITemplate; +import org.tizen.efluibuilder.gef.dnd.model.RMResourceTemplate; +import org.tizen.efluibuilder.gef.requests.DesignCreateRequest; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.mscreen.configurator.MscreenMessage; +import org.tizen.efluibuilder.utility.IDEUtil; + + +public class DesignEditorDropTargetListener extends TemplateTransferDropTargetListener { + private TemplateTransferDropTargetManager eventManager = new TemplateTransferDropTargetManager(); + private DesignCreateRequest request = null; + private static Logger logger = LoggerFactory.getLogger(DesignEditorDropTargetListener.class); + + public DesignEditorDropTargetListener(DesignViewer viewer) { + super(viewer); + } + + public void addTemplateTransferDropTargetListener2(TemplateTransferDropTargetListener2 listener) { + eventManager.addTemplateTransferDropTargetListener2(listener); + } + + public void removeTemplateTransferDropTargetListener2(TemplateTransferDropTargetListener2 listener) { + eventManager.removeTemplateTransferDropTargetListener2(listener); + } + + private boolean isRequestByRM(Object eventData) { + if ((eventData != null) && (eventData instanceof String)) { + return true; + } else { + return false; + } + } + + @Override + protected Request createTargetRequest() { + if (request == null) { + request = new DesignCreateRequest(); + request.getExtendedData().clear(); + } + + request.setCreateRequestType(DesignCreateRequest.TYPE_DEFAULT); + + // for D&D, by SBC + boolean isTemplateTransfer = TemplateTransfer.getInstance().isSupportedType(getCurrentEvent().currentDataType); + boolean isFileTransfer = FileTransfer.getInstance().isSupportedType(getCurrentEvent().currentDataType); + + if (isTemplateTransfer) { + // coding + if (isRequestByRM(getCurrentEvent().data)) { + String dropResKey = (String) getCurrentEvent().data; + logger.debug("is_support--isTemplateTransfer:{}", isTemplateTransfer); + logger.debug("dropResKey:{}", dropResKey); + + RMResourceTemplate rmResourceTemplate = new RMResourceTemplate(dropResKey, true); + if (rmResourceTemplate.isValidRMResource()) { + request.setFactory(getFactory(rmResourceTemplate)); // RM request + request.setCreateRequestType(DesignCreateRequest.TYPE_TEMPLATE); + return request; + } else { + getCurrentEvent().data = null; + return request; + } + } + } else if (isFileTransfer) { + if (getCurrentEvent().data != null) { + String[] dndFiles = (String[]) getCurrentEvent().data; + + logger.debug("is_support--isFileTransfer:{}" + isFileTransfer); + logger.debug("dndFiles:{}", dndFiles[0]); + + RMResourceTemplate rmResourceTemplate = new RMResourceTemplate(dndFiles[0], false); + if (rmResourceTemplate.isCurrentProjectResource()) { + request.setFactory(getFactory(rmResourceTemplate)); // FileBrowser request + request.setCreateRequestType(DesignCreateRequest.TYPE_FILE); + return request; + } else { + getCurrentEvent().data = null; + return request; + } + } + } + // Widget Palette (Widget/Container) + if (getFactory(TemplateTransfer.getInstance().getTemplate()) != null) { + request.setFactory(getFactory(TemplateTransfer.getInstance().getTemplate())); + if(TemplateTransfer.getInstance().getTemplate() instanceof DataBindingTemplate){ + request.setCreateRequestType(DesignCreateRequest.TYPE_DATABINDING_TEMPLATE); + } else{ + request.setCreateRequestType(DesignCreateRequest.TYPE_PALETTE); + } + } + return request; + } + + @Override + protected void handleDragOver() { + updateTargetRequest(); + updateTargetEditPart(); + if (getCreateRequest() instanceof DesignCreateRequest && + DesignCreateRequest.TYPE_PALETTE.equals(((DesignCreateRequest) getCreateRequest()).getCreateType())) { + showTargetFeedback(); + } + } + + @Override + public CreationFactory getFactory(Object template) { + if (!(template instanceof ITemplate)) { + return null; + } + ITemplate iTemplate = (ITemplate) template; + return iTemplate.getFactory(); + } + + // if command is not executable, change target to parent, + private void updateTargetSpecificContainer() { + EditPart target = getTargetEditPart(); + while (target != null && target.getParent() != null) { + if ((getCommand() != null) && (getCommand().canExecute() == true)) { + break; + } else { + target = target.getParent(); + setTargetEditPart(target); + } + } + } + + @Override + protected void updateTargetEditPart() { + super.updateTargetEditPart(); + if (getCreateRequest() instanceof DesignCreateRequest && + DesignCreateRequest.TYPE_PALETTE.equals(((DesignCreateRequest) getCreateRequest()).getCreateType())) { + updateTargetSpecificContainer(); + } + } + + @Override + protected void handleDrop() { + try { + preDrop(); + super.handleDrop(); + postDrop(); + + this.request = null; // Initialize + } catch (IllegalArgumentException ex) { + Shell shell = Display.getDefault().getActiveShell(); + if (shell == null) { + shell = IDEUtil.getRealCurrentActiveShell(); + } + showErrMessageBoxInvalidProject(shell); + } finally { + this.request = null; // Initialize + } + } + + private void showErrMessageBoxInvalidProject(Shell shell) { + if (shell != null) { + MessageBox msgBox = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING); + msgBox.setText(MscreenMessage.RM_DND_ERR_TITLE_INVALID_PROJECT); + msgBox.setMessage(MscreenMessage.RM_DND_MSG_TITLE_INVALID_PROJECT); + msgBox.open(); + } + } + + protected void preDrop() { + eventManager.preDrop(getCurrentEvent()); + } + + protected void postDrop() { + eventManager.postDrop(getCurrentEvent()); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/dnd/listener/OutlineDropTargetListener.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/dnd/listener/OutlineDropTargetListener.java new file mode 100644 index 0000000..51fdb4c --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/dnd/listener/OutlineDropTargetListener.java @@ -0,0 +1,199 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.dnd.listener; + +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPartViewer; +import org.eclipse.gef.Request; +import org.eclipse.gef.TreeEditPart; +import org.eclipse.gef.dnd.AbstractTransferDropTargetListener; +import org.eclipse.gef.dnd.TemplateTransfer; +import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gef.requests.CreationFactory; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.TreeItem; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; + + +public class OutlineDropTargetListener extends AbstractTransferDropTargetListener { + + public OutlineDropTargetListener(EditPartViewer outlinePageViewer) { + super(outlinePageViewer, TemplateTransfer.getInstance()); + } + + public CreationFactory getFactory(Object template) { + return null; + } + + @Override + protected Request createTargetRequest() { + if (TemplateTransfer.getInstance().isSupportedType(getCurrentEvent().currentDataType)) { + CreateRequest request = new CreateRequest(); + request.setFactory(getFactory(TemplateTransfer.getInstance().getTemplate())); + return request; + } else { + return null; + } + } + + protected final CreateRequest getCreateRequest() { + return ((CreateRequest) getTargetRequest()); + } + + @Override + protected void handleDragOperationChanged() { + if (TemplateTransfer.getInstance().isSupportedType(getCurrentEvent().currentDataType)) { + getCurrentEvent().detail = DND.DROP_COPY; + super.handleDragOperationChanged(); + } + } + + @Override + protected void handleDragOver() { + if (TemplateTransfer.getInstance().isSupportedType(getCurrentEvent().currentDataType)) { + Part target = null; + Request request = getTargetRequest(); + Part part = null; + TreeItem treeItem = null; + TreeEditPart treeEditPart = null; + Rectangle rect = null; + Point point = null; + + if (getTargetEditPart() == null) { + return; + } + + point = ((CreateRequest) request).getLocation(); + + treeEditPart = (TreeEditPart) getTargetEditPart().getViewer().findObjectAt(point); + + target = (Part) treeEditPart.getModel(); + part = (Part) getTargetEditPart().getModel(); + getCurrentEvent().detail = DND.DROP_COPY; + + if (target != null) { + Part newPart = null; + try { + Object object = ((CreateRequest) request).getNewObject(); + if (object instanceof Part) { + newPart = (Part) object; + } + } catch (IllegalArgumentException e) { + return; + } + + if (newPart != null) { + ComponentDescriptor componentDescriptor = part.getOwnerDocumentPart().getComponentDescriptor(); + if ((target.equals(part)) && (componentDescriptor.canHaveChild((ComponentPart) target, (ComponentPart) newPart))) { + getCurrentEvent().feedback = DND.FEEDBACK_SCROLL | DND.FEEDBACK_EXPAND | DND.FEEDBACK_SELECT; + } else if ((target.equals(part)) || (!componentDescriptor.canHaveChild((ComponentPart) target, (ComponentPart) newPart)) + || (target.getParent().equals(((ComponentPart) target).getOwnerViewPart())) + || (target.equals(((ComponentPart) target).getOwnerViewPart()))) { + getCurrentEvent().detail = DND.DROP_NONE; + getCurrentEvent().feedback = DND.FEEDBACK_NONE; + } else if (treeEditPart.getWidget() instanceof TreeItem) { + treeItem = (TreeItem) treeEditPart.getWidget(); + rect = treeItem.getBounds(); + if (isNextPosion(rect, point)) { + getCurrentEvent().feedback = DND.FEEDBACK_SCROLL | DND.FEEDBACK_EXPAND | DND.FEEDBACK_INSERT_AFTER; + } else { + getCurrentEvent().feedback = DND.FEEDBACK_SCROLL | DND.FEEDBACK_EXPAND | DND.FEEDBACK_INSERT_BEFORE; + } + } else { + getCurrentEvent().feedback = DND.FEEDBACK_SCROLL | DND.FEEDBACK_EXPAND | DND.FEEDBACK_INSERT_BEFORE; + } + } + } else { + getCurrentEvent().detail = DND.DROP_NONE; + getCurrentEvent().feedback = DND.FEEDBACK_NONE; + } + super.handleDragOver(); + } + } + + private boolean isNextPosion(Rectangle rect, Point point) { + Rectangle temp = rect; + temp.y = rect.y + (rect.height / 2); + temp.height = rect.height / 2; + + if (temp.contains(point.x, point.y)) { + return true; + } else { + return false; + } + } + + @Override + protected void handleDrop() { + if (TemplateTransfer.getInstance().isSupportedType(getCurrentEvent().currentDataType)) { + + Request request = getTargetRequest(); + Part source = null; + try { + source = (Part) ((CreateRequest) request).getNewObject(); + } catch (IllegalArgumentException e) { + // selectAddedObject(); + return; + } + + if (source != null) { + EditPart ep = (EditPart) getViewer().getEditPartRegistry().get(source.getUniqueId()); + if (ep != null) { + getViewer().select(ep); + } + } + super.handleDrop(); + selectAddedObject(); + } + + } + + private void selectAddedObject() { + Object model = getCreateRequest().getNewObject(); + if (model == null) { + return; + } + EditPartViewer viewer = getViewer(); + viewer.getControl().forceFocus(); + Object editpart = viewer.getEditPartRegistry().get(model); + if (editpart instanceof EditPart) { + // Force a layout first. + getViewer().flush(); + viewer.select((EditPart) editpart); + } + } + + @Override + protected void updateTargetRequest() { + if (TemplateTransfer.getInstance().isSupportedType(getCurrentEvent().currentDataType)) { + CreateRequest request = getCreateRequest(); + request.setLocation(getDropLocation()); + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/dnd/listener/TemplateTransferDropTargetListener2.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/dnd/listener/TemplateTransferDropTargetListener2.java new file mode 100644 index 0000000..0f14875 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/dnd/listener/TemplateTransferDropTargetListener2.java @@ -0,0 +1,33 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.dnd.listener; + +import org.eclipse.swt.dnd.DropTargetEvent; + + +public interface TemplateTransferDropTargetListener2 { + public void preDrop(DropTargetEvent event); + + public void postDrop(DropTargetEvent event); +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/dnd/listener/TemplateTransferDropTargetManager.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/dnd/listener/TemplateTransferDropTargetManager.java new file mode 100644 index 0000000..52fd1e3 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/dnd/listener/TemplateTransferDropTargetManager.java @@ -0,0 +1,54 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.dnd.listener; + +import org.eclipse.core.commands.common.EventManager; +import org.eclipse.swt.dnd.DropTargetEvent; + + +public class TemplateTransferDropTargetManager extends EventManager { + public void addTemplateTransferDropTargetListener2(TemplateTransferDropTargetListener2 listener) { + addListenerObject(listener); + } + + public void removeTemplateTransferDropTargetListener2(TemplateTransferDropTargetListener2 listener) { + removeListenerObject(listener); + } + + public void preDrop(DropTargetEvent event) { + Object[] listeners = getListeners(); + for (int i = 0; i < listeners.length; ++i) { + TemplateTransferDropTargetListener2 l = (TemplateTransferDropTargetListener2) listeners[i]; + l.preDrop(event); + } + } + + public void postDrop(DropTargetEvent event) { + Object[] listeners = getListeners(); + for (int i = 0; i < listeners.length; ++i) { + TemplateTransferDropTargetListener2 l = (TemplateTransferDropTargetListener2) listeners[i]; + l.postDrop(event); + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/dnd/TemplateTransferDragSourceListener.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/dnd/TemplateTransferDragSourceListener.java new file mode 100644 index 0000000..da8b196 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/dnd/TemplateTransferDragSourceListener.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.dnd; + +import java.util.List; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPartViewer; +import org.eclipse.gef.dnd.AbstractTransferDragSourceListener; +import org.eclipse.gef.dnd.TemplateTransfer; +import org.eclipse.swt.dnd.DragSourceEvent; +import org.eclipse.swt.dnd.Transfer; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.CombinedTemplateCreationEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteTemplateEntry; + + +/** + * Allows a single {@link PaletteTemplateEntry PaletteTemplateEntry} to be dragged from an + * EditPartViewer. The PaletteTemplateEntry's template object is the data that is being + * transfered to the DropTarget. + * + * @since 2.1 + * @author Eric Bordeau + */ +public class TemplateTransferDragSourceListener extends + AbstractTransferDragSourceListener { + + /** + * @deprecated Use the constructor without the transfer specified. + * @param viewer + * viewer + * @param xfer + * xfer + */ + public TemplateTransferDragSourceListener(EditPartViewer viewer, + Transfer xfer) { + super(viewer, xfer); + } + + /** + * Constructs a new listener for the specified EditPartViewer. The provided Viewer should be one + * that is displaying a Palette. The TemplateTransferDragSourceListener will only be enabled + * when a single EditPart is selected, and the EditPart's model is a + * {@link PaletteTemplateEntry}. + * + * @param viewer + * the EditPartViewer that is the drag source + */ + public TemplateTransferDragSourceListener(EditPartViewer viewer) { + super(viewer, TemplateTransfer.getInstance()); + } + + /** + * @see AbstractTransferDragSourceListener#dragFinished(DragSourceEvent) + */ + public void dragFinished(DragSourceEvent event) { + TemplateTransfer.getInstance().setTemplate(null); + } + + /** + * Get the template from the selected {@link PaletteTemplateEntry} and sets it as the + * event data to be dropped. + * + * @param event + * the DragSourceEvent + */ + public void dragSetData(DragSourceEvent event) { + event.data = getTemplate(); + } + + /** + * Cancels the drag if the selected item does not represent a PaletteTemplateEntry. + * + * @see org.eclipse.swt.dnd.DragSourceListener#dragStart(DragSourceEvent) + */ + public void dragStart(DragSourceEvent event) { + Object template = getTemplate(); + if (template == null) + event.doit = false; + TemplateTransfer.getInstance().setTemplate(template); + } + + /** + * A helper method that returns null or the template Object from the + * currently selected EditPart. + * + * @return the template + */ + protected Object getTemplate() { + List selection = getViewer().getSelectedEditParts(); + if (selection.size() == 1) { + EditPart editpart = (EditPart) getViewer().getSelectedEditParts() + .get(0); + Object model = editpart.getModel(); + if (model instanceof PaletteTemplateEntry) + return ((PaletteTemplateEntry) model).getTemplate(); + if (model instanceof CombinedTemplateCreationEntry) + return ((CombinedTemplateCreationEntry) model).getTemplate(); + } + return null; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/PaletteColorUtil.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/PaletteColorUtil.java new file mode 100644 index 0000000..ea2d708 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/PaletteColorUtil.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * Copyright (c) 2008, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-09 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette; + +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.FigureUtilities; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Display; + + +/** + * A class to keep miscellaneous palette color utilities. + * + * @author crevells + * @since 3.4 + */ +public class PaletteColorUtil { + + public static final Color WIDGET_BACKGROUND = ColorConstants.button; + + public static final Color WIDGET_NORMAL_SHADOW = ColorConstants.buttonDarker; + + public static final Color WIDGET_DARK_SHADOW = ColorConstants.buttonDarkest; + + public static final Color WIDGET_LIST_BACKGROUND = ColorConstants.listBackground; + + public static final Color INFO_FOREGROUND = ColorConstants.tooltipForeground; + + public static final Color ARROW_HOVER = new Color(null, 229, 229, 219); + + private static final Color HOVER_COLOR = new Color(null, 252, 228, 179); + + private static final Color SELECTED_COLOR = new Color(null, 207, 227, 250); + + private static final Color HOVER_COLOR_HICONTRAST = new Color(null, 0, 128, + 0); + + private static final Color SELECTED_COLOR_HICONTRAST = new Color(null, 128, + 0, 128); + + public static final Color WIDGET_BACKGROUND_LIST_BACKGROUND_40 = FigureUtilities + .mixColors(PaletteColorUtil.WIDGET_BACKGROUND, + PaletteColorUtil.WIDGET_LIST_BACKGROUND, 0.4); + + public static final Color WIDGET_BACKGROUND_LIST_BACKGROUND_60 = FigureUtilities + .mixColors(PaletteColorUtil.WIDGET_BACKGROUND, + PaletteColorUtil.WIDGET_LIST_BACKGROUND, 0.6); + + public static final Color WIDGET_BACKGROUND_LIST_BACKGROUND_85 = FigureUtilities + .mixColors(PaletteColorUtil.WIDGET_BACKGROUND, + PaletteColorUtil.WIDGET_LIST_BACKGROUND, 0.85); + + public static final Color WIDGET_BACKGROUND_LIST_BACKGROUND_90 = FigureUtilities + .mixColors(PaletteColorUtil.WIDGET_BACKGROUND, + PaletteColorUtil.WIDGET_LIST_BACKGROUND, 0.9); + + public static final Color WIDGET_BACKGROUND_NORMAL_SHADOW_40 = FigureUtilities + .mixColors(PaletteColorUtil.WIDGET_BACKGROUND, + PaletteColorUtil.WIDGET_NORMAL_SHADOW, 0.4); + + public static final Color WIDGET_BACKGROUND_NORMAL_SHADOW_45 = FigureUtilities + .mixColors(PaletteColorUtil.WIDGET_BACKGROUND, + PaletteColorUtil.WIDGET_NORMAL_SHADOW, 0.45); + + public static final Color WIDGET_BACKGROUND_NORMAL_SHADOW_65 = FigureUtilities + .mixColors(PaletteColorUtil.WIDGET_BACKGROUND, + PaletteColorUtil.WIDGET_NORMAL_SHADOW, 0.65); + + public static final Color WIDGET_BACKGROUND_NORMAL_SHADOW_70 = FigureUtilities + .mixColors(PaletteColorUtil.WIDGET_BACKGROUND, + PaletteColorUtil.WIDGET_NORMAL_SHADOW, 0.7); + + public static final Color WIDGET_BACKGROUND_NORMAL_SHADOW_80 = FigureUtilities + .mixColors(PaletteColorUtil.WIDGET_BACKGROUND, + PaletteColorUtil.WIDGET_NORMAL_SHADOW, 0.8); + + public static final Color WIDGET_BACKGROUND_NORMAL_SHADOW_90 = FigureUtilities + .mixColors(PaletteColorUtil.WIDGET_BACKGROUND, + PaletteColorUtil.WIDGET_NORMAL_SHADOW, 0.9); + + public static final Color WIDGET_BACKGROUND_NORMAL_SHADOW_95 = FigureUtilities + .mixColors(PaletteColorUtil.WIDGET_BACKGROUND, + PaletteColorUtil.WIDGET_NORMAL_SHADOW, 0.95); + + /** + * Gets the color to be used when hovering over palette items. The color differs in high + * contrast mode. + * + * @return the hover color + * @since 3.4 + */ + public static Color getHoverColor() { + Display display = Display.getCurrent(); + if (display == null) { + display = Display.getDefault(); + } + if (display.getHighContrast()) { + return HOVER_COLOR_HICONTRAST; + } + return HOVER_COLOR; + } + + /** + * Gets the color to be used when selecting palette items. The color differs in high contrast + * mode. + * + * @return the selected color + * @since 3.4 + */ + public static Color getSelectedColor() { + Display display = Display.getCurrent(); + if (display == null) { + display = Display.getDefault(); + } + if (display.getHighContrast()) { + return SELECTED_COLOR_HICONTRAST; + } + return SELECTED_COLOR; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/PaletteSelectionTool.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/PaletteSelectionTool.java new file mode 100644 index 0000000..3464b09 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/PaletteSelectionTool.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-09 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette; + +import org.eclipse.gef.tools.SelectionTool; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyEvent; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewer; + + +/** + * Selection Tool to be used in the Palette. + */ +public class PaletteSelectionTool extends SelectionTool { + + private PaletteViewer getPaletteViewer() { + return (PaletteViewer) getCurrentViewer(); + } + + private boolean handleAbort(KeyEvent e) { + if (e.keyCode == SWT.ESC) { + return (getPaletteViewer().getPaletteRoot().getDefaultEntry() != null); + } + return false; + } + + protected boolean handleKeyDown(KeyEvent e) { + if (handleAbort(e)) { + loadDefaultTool(); + return true; + } + return super.handleKeyDown(e); + } + + private void loadDefaultTool() { + getPaletteViewer().setActiveTool( + getPaletteViewer().getPaletteRoot().getDefaultEntry()); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/ToolbarDropdownContributionItem.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/ToolbarDropdownContributionItem.java new file mode 100644 index 0000000..7f6112d --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/ToolbarDropdownContributionItem.java @@ -0,0 +1,719 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-09 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.ContributionItem; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IContributionManagerOverrides; +import org.eclipse.jface.action.IMenuCreator; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Item; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; +import org.eclipse.swt.widgets.Widget; + + +/** + * A contribution item which delegates to an action. + *

+ * This class may be instantiated; it is not intended to be subclassed. + *

+ */ +public class ToolbarDropdownContributionItem extends ContributionItem { + + private static ImageCache globalImageCache; + + /** + * The action. + */ + private IAction action; + + /** + * The widget created for this item; null before creation and after disposal. + */ + private Widget widget = null; + + /** + * Nested class handles notification from SWT widget and from Action, to avoid polluting + * ToolbarDropdownContributionItem with public listener methods. + */ + private class ActionListener implements Listener, IPropertyChangeListener { + public void handleEvent(Event event) { + ToolbarDropdownContributionItem.this.handleWidgetEvent(event); + } + + public void propertyChange(PropertyChangeEvent event) { + ToolbarDropdownContributionItem.this.actionPropertyChange(event); + } + } + + private ActionListener listener = new ActionListener(); + + private static class ImageCache { + /** Map from ImageDescriptor to Entry */ + private Map entries = new HashMap(11); + private Image missingImage; + + private static class Entry { + protected Image image; + protected Image grayImage; + + void dispose() { + if (image != null) { + image.dispose(); + image = null; + } + if (grayImage != null) { + grayImage.dispose(); + grayImage = null; + } + } + } + + Entry getEntry(ImageDescriptor desc) { + Entry entry = (Entry) entries.get(desc); + if (entry == null) { + entry = new Entry(); + entries.put(desc, entry); + } + return entry; + } + + Image getImage(ImageDescriptor desc) { + if (desc == null) { + return null; + } + Entry entry = getEntry(desc); + if (entry.image == null) { + entry.image = desc.createImage(); + } + return entry.image; + } + + Image getGrayImage(ImageDescriptor desc) { + if (desc == null) { + return null; + } + Entry entry = getEntry(desc); + if (entry.grayImage == null) { + Image image = getImage(desc); + if (image != null) { + entry.grayImage = new Image(null, image, SWT.IMAGE_GRAY); + } + } + return entry.grayImage; + } + + Image getMissingImage() { + if (missingImage == null) { + missingImage = getImage(ImageDescriptor + .getMissingImageDescriptor()); + } + return missingImage; + } + + void dispose() { + for (Iterator i = entries.values().iterator(); i.hasNext();) { + Entry entry = (Entry) i.next(); + entry.dispose(); + } + entries.clear(); + } + } + + /** + * Creates a new contribution item from the given action. The id of the action is used as the id + * of the item. + * + * @param action + * the action + */ + public ToolbarDropdownContributionItem(IAction action) { + super(action.getId()); + this.action = action; + } + + /** + * Handles a property change event on the action (forwarded by nested listener). + */ + private void actionPropertyChange(final PropertyChangeEvent e) { + // This code should be removed. Avoid using free asyncExec + + if (isVisible() && widget != null) { + Display display = widget.getDisplay(); + if (display.getThread() == Thread.currentThread()) { + update(e.getProperty()); + } else { + display.asyncExec(new Runnable() { + public void run() { + update(e.getProperty()); + } + }); + } + + } + } + + /** + * Checks whether the given menu item belongs to a context menu (the one that pops up if the + * user presses the right mouse button). + */ + private static boolean belongsToContextMenu(MenuItem item) { + Menu menu = item.getParent(); + if (menu == null) + return false; + while (menu.getParentMenu() != null) + menu = menu.getParentMenu(); + return (menu.getStyle() & SWT.BAR) == 0; + } + + /** + * Compares this action contribution item with another object. Two action contribution items are + * equal if they refer to the identical Action. + */ + public boolean equals(Object o) { + if (!(o instanceof ToolbarDropdownContributionItem)) { + return false; + } + return action.equals(((ToolbarDropdownContributionItem) o).action); + } + + /** + * The ToolbarDropdownContributionItem implementation of this + * IContributionItem method creates a SWT Button for the action. If the action's + * checked property has been set, a toggle button is created and primed to the value of the + * checked property. + */ + public void fill(Composite parent) { + if (widget == null && parent != null) { + int flags = SWT.PUSH; + + if (action != null) { + if (action.getStyle() == IAction.AS_CHECK_BOX) + flags = SWT.TOGGLE; + Button b = new Button(parent, flags); + b.setData(this); + b.addListener(SWT.Dispose, listener); + // Don't hook a dispose listener on the parent + b.addListener(SWT.Selection, listener); + if (action.getHelpListener() != null) + b.addHelpListener(action.getHelpListener()); + widget = b; + + update(null); + + action.addPropertyChangeListener(listener); + } + } + } + + /** + * The ToolbarDropdownContributionItem implementation of this + * IContributionItem method creates a SWT MenuItem for the action. If the action's + * checked property has been set, a toggle button is created and primed to the value of the + * checked property. If the action's menu creator property has been set, a cascading submenu is + * created. + */ + public void fill(Menu parent, int index) { + if (widget == null && parent != null) { + int flags = SWT.PUSH; + Menu subMenu = null; + + if (action != null) { + int style = action.getStyle(); + if (style == IAction.AS_CHECK_BOX) + flags = SWT.CHECK; + else if (style == IAction.AS_DROP_DOWN_MENU) { + IMenuCreator mc = action.getMenuCreator(); + subMenu = mc.getMenu(parent); + flags = SWT.CASCADE; + } + } + + MenuItem mi = null; + if (index >= 0) + mi = new MenuItem(parent, flags, index); + else + mi = new MenuItem(parent, flags); + widget = mi; + + mi.setData(this); + mi.addListener(SWT.Arm, listener); + mi.addListener(SWT.Dispose, listener); + mi.addListener(SWT.Selection, listener); + if (action != null && action.getHelpListener() != null) + mi.addHelpListener(action.getHelpListener()); + + if (subMenu != null) + mi.setMenu(subMenu); + + update(null); + + if (action != null) { + action.addPropertyChangeListener(listener); + } + } + } + + /** + * The ToolbarDropdownContributionItem implementation of this + * IContributionItem method creates a SWT ToolItem for the action. If the action's + * checked property has been set, a toggle button is created and primed to the value of the + * checked property. If the action's menu creator property has been set, a drop-down tool item + * is created. + */ + public void fill(ToolBar parent, int index) { + if (widget == null && parent != null) { + int flags = SWT.PUSH; + + if (action != null) { + int style = action.getStyle(); + if (style == IAction.AS_CHECK_BOX) + flags = SWT.CHECK; + else if (style == IAction.AS_DROP_DOWN_MENU) + flags = SWT.DROP_DOWN; + } + + ToolItem ti = null; + if (index >= 0) + ti = new ToolItem(parent, flags, index); + else + ti = new ToolItem(parent, flags); + ti.setData(this); + ti.addListener(SWT.Selection, listener); + ti.addListener(SWT.Dispose, listener); + + widget = ti; + + update(null); + + action.addPropertyChangeListener(listener); + } + } + + /** + * Returns the action associated with this contribution item. + * + * @return the action + */ + public IAction getAction() { + return action; + } + + /** + * Returns the image cache. The cache is global, and is shared by all action contribution items. + * This has the disadvantage that once an image is allocated, it is never freed until the + * display is disposed. However, it has the advantage that the same image in different + * contribution managers is only ever created once. + */ + private ImageCache getImageCache() { + ImageCache cache = globalImageCache; + if (cache == null) { + globalImageCache = cache = new ImageCache(); + Display display = Display.getDefault(); + if (display != null) { + display.disposeExec(new Runnable() { + public void run() { + if (globalImageCache != null) { + globalImageCache.dispose(); + globalImageCache = null; + } + } + }); + } + } + return cache; + } + + /** + * Handles a widget arm event. + */ + private void handleWidgetArm(Event e) { + /* + * String description= null; if (fAction instanceof Action) // getDescription should go into + * IAction description= ((Action)fAction).getDescription(); if (description != null) + * ApplicationWindow.showDescription(e.widget, description); else + * ApplicationWindow.resetDescription(e.widget); + */ + } + + /** + * Handles a widget dispose event for the widget corresponding to this item. + */ + private void handleWidgetDispose(Event e) { + if (e.widget == widget) { + // the item is being disposed + if (action.getStyle() == IAction.AS_DROP_DOWN_MENU) { + action.getMenuCreator().dispose(); + } + action.removePropertyChangeListener(listener); + widget = null; + } + } + + /** + * Handles an event from the widget (forwarded from nested listener). + */ + private void handleWidgetEvent(Event e) { + switch (e.type) { + case SWT.Arm: + handleWidgetArm(e); + break; + case SWT.Dispose: + handleWidgetDispose(e); + break; + case SWT.Selection: + handleWidgetSelection(e); + break; + } + } + + /** + * Handles a widget selection event. + */ + private void handleWidgetSelection(Event e) { + Widget item = e.widget; + if (item != null) { + + int style = item.getStyle(); + + if ((style & (SWT.TOGGLE | SWT.CHECK)) != 0) { + if (action.getStyle() == IAction.AS_CHECK_BOX) { + action.setChecked(!action.isChecked()); + } + + } else if ((style & SWT.DROP_DOWN) != 0) { + /* + * Added by Pratik Shah Do this regardless of whether the down arrow button on the + * side was clicked, or the main button itself + */ + if (action.getStyle() == IAction.AS_DROP_DOWN_MENU) { + IMenuCreator mc = action.getMenuCreator(); + ToolItem ti = (ToolItem) item; + // we create the menu as a sub-menu of "dummy" so that we + // can use + // it in a cascading menu too. + // If created on a SWT control we would get an SWT error... + // Menu dummy= new Menu(ti.getParent()); + // Menu m= mc.getMenu(dummy); + // dummy.dispose(); + + Menu m = mc.getMenu(ti.getParent()); + if (m != null) { + // position the menu below the drop down item + Rectangle b = ti.getBounds(); + Point p = ti.getParent().toDisplay( + new Point(b.x, b.y + b.height)); + m.setLocation(p.x, p.y); // waiting for SWT 0.42 + m.setVisible(true); + return; // we don't fire the action + } + } + } + + // Ensure action is enabled first. + // See 1GAN3M6: ITPUI:WINNT - Any IAction in the workbench can be + // executed + // while disabled. + if (action.isEnabled()) { + action.runWithEvent(e); + } + } + } + + /* + * (non-Javadoc) Method declared on Object. + */ + public int hashCode() { + return action.hashCode(); + } + + /* + * (non-Javadoc) Method declared on IContributionItem. + */ + public boolean isEnabled() { + return action != null && action.isEnabled(); + } + + /** + * The action item implementation of this IContributionItem method returns + * true for menu items and false for everything else. + */ + public boolean isDynamic() { + if (widget instanceof MenuItem) { + // Optimization. Only recreate the item is the check style has + // changed. + boolean itemIsCheck = (widget.getStyle() & SWT.CHECK) != 0; + boolean actionIsCheck = getAction() != null + && getAction().getStyle() == IAction.AS_CHECK_BOX; + return itemIsCheck != actionIsCheck; + } + return false; + } + + /** + * Returns true if this item is allowed to enable, false otherwise. + * + * @return if this item is allowed to be enabled + * @since 2.0 + */ + protected boolean isEnabledAllowed() { + if (getParent() == null) + return true; + Boolean value = getParent().getOverrides().getEnabled(this); + return (value == null) ? true : value.booleanValue(); + } + + /** + * The action item implementation of this IContributionItem method calls + * update(null). + */ + public final void update() { + update(null); + } + + /** + * Synchronizes the UI with the given property. + * + * @param propertyName + * the name of the property, or null meaning all applicable properties + */ + public void update(String propertyName) { + if (widget != null) { + + // determine what to do + boolean textChanged = propertyName == null + || propertyName.equals(Action.TEXT); + boolean imageChanged = propertyName == null + || propertyName.equals(Action.IMAGE); + boolean tooltipTextChanged = propertyName == null + || propertyName.equals(Action.TOOL_TIP_TEXT); + boolean enableStateChanged = propertyName == null + || propertyName.equals(Action.ENABLED) + || propertyName + .equals(IContributionManagerOverrides.P_ENABLED); + boolean checkChanged = (action.getStyle() == IAction.AS_CHECK_BOX) + && (propertyName == null || propertyName + .equals(Action.CHECKED)); + + if (widget instanceof ToolItem) { + ToolItem ti = (ToolItem) widget; + if (imageChanged) { + updateImages(true); + } + if (tooltipTextChanged) + ti.setToolTipText(action.getToolTipText()); + + if (enableStateChanged) { + boolean shouldBeEnabled = action.isEnabled() + && isEnabledAllowed(); + if (ti.getEnabled() != shouldBeEnabled) + ti.setEnabled(shouldBeEnabled); + } + + if (checkChanged) { + boolean bv = action.isChecked(); + if (ti.getSelection() != bv) + ti.setSelection(bv); + } + return; + } + + if (widget instanceof MenuItem) { + MenuItem mi = (MenuItem) widget; + boolean isContextMenu = belongsToContextMenu(mi); + + // We only install an accelerator if the menu item doesn't + // belong to a context menu (right mouse button menu). + if (textChanged) { + if (isContextMenu) { + String text = action.getText(); + if (text != null) { + text = Action.removeAcceleratorText(text); + mi.setText(text); + } + } else { + String text = null; + IContributionManagerOverrides overrides = null; + if (getParent() != null) + overrides = getParent().getOverrides(); + if (overrides != null) + text = getParent().getOverrides().getText(this); + if (text == null) + text = action.getText(); + if (text != null) { + String label = Action.removeAcceleratorText(text); + String accText = null; + Integer acc = null; + if (overrides != null) { + accText = overrides.getAcceleratorText(this); + acc = overrides.getAccelerator(this); + } + if ((accText == null) + && (label.length() + 1 < text.length())) + accText = text.substring(label.length() + 1); + if (acc == null) + acc = new Integer(action.getAccelerator()); + if (acc.intValue() >= 0) + mi.setAccelerator(acc.intValue()); + if (accText == null) + mi.setText(label); + else + mi.setText(label + '\t' + accText); + } + } + } + if (imageChanged) { + updateImages(false); + } + if (enableStateChanged) { + boolean shouldBeEnabled = action.isEnabled() + && isEnabledAllowed(); + if (mi.getEnabled() != shouldBeEnabled) + mi.setEnabled(shouldBeEnabled); + } + + if (checkChanged) { + boolean bv = action.isChecked(); + if (mi.getSelection() != bv) + mi.setSelection(bv); + } + return; + } + + if (widget instanceof Button) { + Button button = (Button) widget; + if (imageChanged) { + if (updateImages(false)) { + // don't update text if it has an image + textChanged = false; + } + } + if (textChanged) { + String text = action.getText(); + if (text != null) + button.setText(text); + } + if (tooltipTextChanged) + button.setToolTipText(action.getToolTipText()); + + if (enableStateChanged) { + boolean shouldBeEnabled = action.isEnabled() + && isEnabledAllowed(); + if (button.getEnabled() != shouldBeEnabled) + button.setEnabled(shouldBeEnabled); + } + + if (checkChanged) { + boolean bv = action.isChecked(); + if (button.getSelection() != bv) + button.setSelection(bv); + } + return; + } + } + } + + /** + * Updates the images for this action. + * + * @param forceImage + * true if some form of image is compulsory, and false if + * it is acceptable for this item to have no image + * @return true if there are images for this action, false if not + */ + private boolean updateImages(boolean forceImage) { + + ImageCache cache = getImageCache(); + + if (widget instanceof ToolItem) { + Image image = cache.getImage(action.getImageDescriptor()); + Image hoverImage = cache.getImage(action.getHoverImageDescriptor()); + Image disabledImage = cache.getImage(action + .getDisabledImageDescriptor()); + + // If there is no regular image, but there is a hover image, + // convert the hover image to gray and use it as the regular image. + if (image == null && hoverImage != null) { + image = cache.getGrayImage(action.getHoverImageDescriptor()); + } else { + // If there is no hover image, use the regular image as the + // hover image, + // and convert the regular image to gray + if (hoverImage == null && image != null) { + hoverImage = image; + image = cache.getGrayImage(action.getImageDescriptor()); + } + } + + // Make sure there is a valid image. + if (hoverImage == null && image == null && forceImage) { + image = cache.getMissingImage(); + } + + // performance: more efficient in SWT to set disabled and hot image + // before + // regular image + if (disabledImage != null) { + // Set the disabled image if we were able to create one. + // Assumes that SWT.ToolItem will use platform's default + // behavior to show item when it is disabled and a disabled + // image has not been set. + ((ToolItem) widget).setDisabledImage(disabledImage); + } + ((ToolItem) widget).setHotImage(hoverImage); + ((ToolItem) widget).setImage(image); + + return image != null; + } else if (widget instanceof Item || widget instanceof Button) { + // Use hover image if there is one, otherwise use regular image. + Image image = cache.getImage(action.getHoverImageDescriptor()); + if (image == null) { + image = cache.getImage(action.getImageDescriptor()); + } + // Make sure there is a valid image. + if (image == null && forceImage) { + image = cache.getMissingImage(); + } + if (widget instanceof Item) { + ((Item) widget).setImage(image); + } else if (widget instanceof Button) { + ((Button) widget).setImage(image); + } + return image != null; + } + return false; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/ColumnsLayout.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/ColumnsLayout.java new file mode 100644 index 0000000..e96830c --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/ColumnsLayout.java @@ -0,0 +1,112 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-09 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts; + +import java.util.Iterator; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.geometry.Dimension; + + +/** + * Special FlowLayout to display the palette in the columns view. + * + * @author Pratik Shah + */ +public class ColumnsLayout extends PaletteContainerFlowLayout { + + private Dimension defaultConstraint = null; + private Dimension cachedConstraint = null; + + /** + * Constructs a new layout + */ + public ColumnsLayout() { + super(true); + setMinorSpacing(0); + setMajorSpacing(0); + setStretchMinorAxis(true); + setDefaultConstraint(new Dimension(55, 55)); + } + + /** + * @see org.eclipse.draw2d.FlowLayout#getChildSize(IFigure, int, int) + */ + protected Dimension getChildSize(IFigure child, int wHint, int hHint) { + if (!(child instanceof SeparatorEditPart.SeparatorFigure)) { + Dimension hints = getMinimumHints(child, wHint, hHint); + int numOfColumns = (wHint + majorSpacing) + / (hints.width + majorSpacing); + // numOfColumns = Math.min(numOfColumns, + // maxChildrenInRowWith(child)); + if (numOfColumns == 0) { + wHint = hints.width; + } else { + wHint = (wHint - ((numOfColumns - 1) * majorSpacing)) + / numOfColumns; + } + hHint = hints.height; + } + + return super.getChildSize(child, wHint, hHint); + } + + /* + * Returns a dimension which has a width that is the greater of the following two: the default + * width (set on defaultConstraint), and the minimum width of the widest child. + */ + private Dimension getMinimumHints(IFigure figure, int wHint, int hHint) { + if (cachedConstraint == null) { + cachedConstraint = defaultConstraint.getCopy(); + List children = figure.getParent().getChildren(); + for (Iterator iter = children.iterator(); iter.hasNext();) { + IFigure child = (IFigure) iter.next(); + Dimension childSize = (child instanceof PinnablePaletteStackFigure) ? ((PinnablePaletteStackFigure) child) + .getHeaderPreferredSize(cachedConstraint.width, + cachedConstraint.height) + : child + .getPreferredSize(cachedConstraint.width, + cachedConstraint.height); + cachedConstraint.width = Math.max(cachedConstraint.width, + childSize.width); + } + cachedConstraint.height = hHint; + } + return cachedConstraint; + } + + /** + * @see org.eclipse.draw2d.AbstractHintLayout#invalidate() + */ + public void invalidate() { + super.invalidate(); + cachedConstraint = null; + } + + /** + * For use by the palette + * + * @param d + * The constraints to be respected by the children of the figure that has this + * layout; Should not be null. + */ + public void setDefaultConstraint(Dimension d) { + defaultConstraint = d; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/DetailedLabelFigure.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/DetailedLabelFigure.java new file mode 100644 index 0000000..be06a96 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/DetailedLabelFigure.java @@ -0,0 +1,364 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-09 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * - update package name + * - add method "getCachedImage" for direct manipulation + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts; + +import java.util.Collection; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.draw2d.Border; +import org.eclipse.draw2d.BorderLayout; +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.Figure; +import org.eclipse.draw2d.FocusEvent; +import org.eclipse.draw2d.ImageFigure; +import org.eclipse.draw2d.ImageUtilities; +import org.eclipse.draw2d.MarginBorder; +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.draw2d.text.FlowPage; +import org.eclipse.draw2d.text.ParagraphTextLayout; +import org.eclipse.draw2d.text.TextFlow; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.widgets.Display; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteMessages; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewerPreferences; + + +/** + * A customized figure used to represent entries in the GEF Palette. + * + * @author Pratik Shah + */ +public class DetailedLabelFigure extends Figure { + + private static final FontCache FONTCACHE = new FontCache(); + private static final Border PAGE_BORDER = new MarginBorder(0, 1, 0, 1); + + private SelectableImageFigure image; + private FlowPage page; + private TextFlow nameText, descText; + private Font boldFont; + private boolean selectionState; + private int layoutMode = -1; + private Font cachedFont; + + /** + * Constructor + */ + public DetailedLabelFigure() { + image = new SelectableImageFigure(); + image.setAlignment(PositionConstants.NORTH); + page = new FlowPage(); + page.setBorder(PAGE_BORDER); + + nameText = new TextFlow(); + nameText.setLayoutManager(new ParagraphTextLayout(nameText, + ParagraphTextLayout.WORD_WRAP_TRUNCATE)); + + descText = new TextFlow(); + descText.setLayoutManager(new ParagraphTextLayout(descText, + ParagraphTextLayout.WORD_WRAP_TRUNCATE)); + + page.add(nameText); + add(image); + add(page); + BorderLayout layout = new BorderLayout(); + layout.setHorizontalSpacing(2); + layout.setVerticalSpacing(0); + setLayoutManager(layout); + } + + /* + * TIZEN: add new UI: current drag cached image for direct manipulation { + */ + public Image getCachedImage() { + return image.getImage(); + } + /* TIZEN } */ + + /** + * @see org.eclipse.draw2d.Figure#addNotify() + */ + public void addNotify() { + super.addNotify(); + updateFont(layoutMode); + } + + /** + * Releases any OS resources used by the figure. + */ + protected void dispose() { + if (boldFont != null) { + nameText.setFont(null); + FONTCACHE.checkIn(boldFont); + boldFont = null; + } + if (image != null) { + image.disposeShadedImage(); + } + } + + /** + * @see org.eclipse.draw2d.IFigure#handleFocusGained(FocusEvent) + */ + public void handleFocusGained(FocusEvent event) { + super.handleFocusGained(event); + updateImage(); + } + + /** + * @see org.eclipse.draw2d.Figure#handleFocusLost(FocusEvent) + */ + public void handleFocusLost(FocusEvent event) { + super.handleFocusLost(event); + updateImage(); + } + + /** + * @return whether the name is truncated + */ + public boolean isNameTruncated() { + return nameText.isTextTruncated(); + } + + /** + * @return whether this figure is selected or not + */ + public boolean isSelected() { + return selectionState; + } + + /** + * @param s + * The description for this entry + */ + public void setDescription(String s) { + String str = ""; //$NON-NLS-1$ + if (s != null && !s.trim().equals("") //$NON-NLS-1$ + && !s.trim().equals(nameText.getText().trim())) { + str = " " + PaletteMessages.NAME_DESCRIPTION_SEPARATOR //$NON-NLS-1$ + + " " + s; //$NON-NLS-1$ + } + if (descText.getText().equals(str)) { + return; + } + descText.setText(str); + } + + /** + * Sets the icon for this figure + * + * @param icon + * The new image + */ + public void setImage(Image icon) { + image.setImage(icon); + } + + /** + * @param layoutMode + * the palette layout (any of the PaletteViewerPreferences.LAYOUT_XXXX options) + */ + public void setLayoutMode(int layoutMode) { + updateFont(layoutMode); + + if (layoutMode == this.layoutMode) + return; + + this.layoutMode = layoutMode; + + add(page); + if (descText.getParent() == page) + page.remove(descText); + + BorderLayout layout = (BorderLayout) getLayoutManager(); + if (layoutMode == PaletteViewerPreferences.LAYOUT_COLUMNS) { + page.setHorizontalAligment(PositionConstants.CENTER); + layout.setConstraint(image, BorderLayout.TOP); + layout.setConstraint(page, BorderLayout.CENTER); + } else if (layoutMode == PaletteViewerPreferences.LAYOUT_ICONS) { + layout.setConstraint(image, BorderLayout.CENTER); + remove(page); + } else if (layoutMode == PaletteViewerPreferences.LAYOUT_LIST) { + page.setHorizontalAligment(PositionConstants.LEFT); + layout.setConstraint(image, BorderLayout.LEFT); + layout.setConstraint(page, BorderLayout.CENTER); + } else if (layoutMode == PaletteViewerPreferences.LAYOUT_DETAILS) { + /* + * Fix for Bug# 39130 Earlier, descText was only being added to the page if the + * description was not an empty String. Now, it's always added. This fixes the case + * mentioned in 39130. The undesirable side-effect is that the descText will be added to + * the page even when it's empty. However, that shouldn't affect anything because the + * descText will be empty (even in the case where the description is not empty, but is + * equal to the name -- see setDescription()). + */ + page.add(descText); + page.setHorizontalAligment(PositionConstants.LEFT); + layout.setConstraint(image, BorderLayout.LEFT); + layout.setConstraint(page, BorderLayout.CENTER); + } + } + + /** + * @param str + * The new name for this entry + */ + public void setName(String str) { + if (nameText.getText().equals(str)) { + return; + } + nameText.setText(str); + } + + /** + * @param state + * true if this entry is to be set as selected + */ + public void setSelected(boolean state) { + selectionState = state; + updateImage(); + } + + private void updateImage() { + if (isSelected()) { + if (hasFocus()) { + image.useShadedImage(); + } else { + image.disposeShadedImage(); + } + } else { + image.disposeShadedImage(); + } + } + + private void updateFont(int layout) { + boolean layoutChanged = (layoutMode != layout); + boolean fontChanged = (cachedFont == null || cachedFont != getFont()); + + cachedFont = getFont(); + if (layoutChanged || fontChanged) { + if (boldFont != null) { + FONTCACHE.checkIn(boldFont); + boldFont = null; + } + if (layout == PaletteViewerPreferences.LAYOUT_DETAILS + && cachedFont != null) + boldFont = FONTCACHE.checkOut(cachedFont); + nameText.setFont(boldFont); + } + } + + private static class SelectableImageFigure extends ImageFigure { + private Image shadedImage; + + protected void useShadedImage() { + disposeShadedImage(); + if (super.getImage() != null) { + ImageData data = ImageUtilities + .createShadedImage(super.getImage(), + ColorConstants.menuBackgroundSelected); + shadedImage = new Image(null, data, data.getTransparencyMask()); + } + } + + protected void disposeShadedImage() { + if (shadedImage != null) { + shadedImage.dispose(); + shadedImage = null; + } + } + + public Image getImage() { + if (shadedImage != null) + return shadedImage; + return super.getImage(); + } + + public void setImage(Image image) { + if (image == super.getImage()) + return; + boolean wasShaded = shadedImage != null; + disposeShadedImage(); + super.setImage(image); + if (wasShaded) + useShadedImage(); + } + } + + private static class FontCache { + private Hashtable table = new Hashtable(); + + private static class FontInfo { + private Font boldFont; + private int refCount; + } + + /* + * Clients should only check in fonts that they checked out from this cache, and should do + * only one check-in per checkout. If the given font is not found, a null pointer exception + * will be encountered. + */ + public void checkIn(Font boldFont) { + FontInfo info = null; + Map.Entry entry = null; + Collection values = table.entrySet(); + for (Iterator iter = values.iterator(); iter.hasNext();) { + Map.Entry tempEntry = (Map.Entry) iter.next(); + FontInfo tempInfo = (FontInfo) tempEntry.getValue(); + if (tempInfo.boldFont == boldFont) { + info = tempInfo; + entry = tempEntry; + break; + } + } + if ((info == null) || (entry == null)) { + return; + } + info.refCount--; + if (info.refCount == 0) { + boldFont.dispose(); + table.remove(entry.getKey()); + } + } + + public Font checkOut(Font font) { + FontInfo info = null; + FontData key = font.getFontData()[0]; + Object obj = table.get(key); + if (obj != null) { + info = (FontInfo) obj; + } else { + info = new FontInfo(); + FontData[] boldDatas = font.getFontData(); + for (int i = 0; i < boldDatas.length; i++) { + boldDatas[i].setStyle(SWT.BOLD); + } + info.boldFont = new Font(Display.getCurrent(), boldDatas); + table.put(key, info); + } + info.refCount++; + return info.boldFont; + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/DrawerEditPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/DrawerEditPart.java new file mode 100644 index 0000000..f33edfb --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/DrawerEditPart.java @@ -0,0 +1,346 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-09 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * 1) update package name + * 2) apply new UI + * - deactivate: add new UI: Clean up image' resource + * - refreshVisuals: add new UI: Set font size + * - setSelected: add new UI: Image processing for selected state + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts; + +import org.eclipse.draw2d.FocusEvent; +import org.eclipse.draw2d.FocusListener; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.RangeModel; +import org.eclipse.draw2d.geometry.Insets; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.ExposeHelper; +import org.eclipse.gef.MouseWheelHelper; +import org.eclipse.gef.editparts.ViewportExposeHelper; +import org.eclipse.gef.editparts.ViewportMouseWheelHelper; +import org.eclipse.gef.internal.InternalImages; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.accessibility.ACC; +import org.eclipse.swt.accessibility.AccessibleControlEvent; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.IMemento; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.PaletteColorUtil; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteDrawer; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteTemplateEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewerPreferences; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.editparts.IPinnableEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.editparts.PaletteAnimator; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.editparts.PaletteEditPart; +import org.tizen.efluibuilder.ui.editor.palette.PaletteConstants; +import org.tizen.efluibuilder.ui.editor.palette.PaletteConstants.CATEGORY_ICON; +import org.tizen.efluibuilder.ui.resources.FontResources; + + +/** + * EditPart for a PaletteDrawer + * + * @author Pratik Shah + */ +public class DrawerEditPart extends PaletteEditPart implements + IPinnableEditPart { + + private static final String PROPERTY_EXPANSION_STATE = "expansion"; //$NON-NLS-1$ + private static final String PROPERTY_PINNED_STATE = "pinned"; //$NON-NLS-1$ + + /** + * Constructor + * + * @param drawer + * The PaletteDrawer that this EditPart is representing + */ + public DrawerEditPart(PaletteDrawer drawer) { + super(drawer); + } + + /** + * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure() + */ + public IFigure createFigure() { + DrawerFigure fig = new DrawerFigure(getViewer().getControl()) { + IFigure buildTooltip() { + return createToolTip(); + } + }; + fig.setExpanded(getDrawer().isInitiallyOpen()); + fig.setPinned(getDrawer().isInitiallyPinned()); + + fig.getCollapseToggle().addFocusListener(new FocusListener.Stub() { + public void focusGained(FocusEvent fe) { + getViewer().select(DrawerEditPart.this); + } + }); + + fig.getScrollpane().getContents() + .addLayoutListener(getPaletteAnimator()); + + return fig; + } + + /** + * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class) + */ + public Object getAdapter(Class key) { + if (key == ExposeHelper.class) { + ViewportExposeHelper helper = new ViewportExposeHelper(this); + helper.setMinimumFrameCount(6); + helper.setMargin(new Insets(PaletteScrollBar.BUTTON_HEIGHT, 0, + PaletteScrollBar.BUTTON_HEIGHT, 0)); + return helper; + } + if (key == MouseWheelHelper.class) + return new ViewportMouseWheelHelper(this); + return super.getAdapter(key); + } + + private PaletteAnimator getPaletteAnimator() { + return (PaletteAnimator) getViewer().getEditPartRegistry().get( + PaletteAnimator.class); + } + + /** + * Convenience method that provides access to the PaletteDrawer that is the model. + * + * @return The model PaletteDrawer + */ + public PaletteDrawer getDrawer() { + return (PaletteDrawer) getPaletteEntry(); + } + + /** + * Convenience method to get the DrawerFigure for the model drawer. + * + * @return The DrawerFigure created in {@link #createFigure()} + */ + public DrawerFigure getDrawerFigure() { + return (DrawerFigure) getFigure(); + } + + /** + * @see org.eclipse.gef.GraphicalEditPart#getContentPane() + */ + public IFigure getContentPane() { + return getDrawerFigure().getContentPane(); + } + + public boolean isExpanded() { + return getDrawerFigure().isExpanded(); + } + + public boolean isPinnedOpen() { + return getDrawerFigure().isPinnedOpen(); + } + + /** + * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#nameNeededInToolTip() + */ + protected boolean nameNeededInToolTip() { + return false; + } + + /** + * @return true if the DrawerFigure can be pinned open. This is only true when the + * drawer is expanded and the auto-collapse strategy is + * PaletteViewerPreferences.COLLAPSE_AS_NEEDED. + */ + public boolean canBePinned() { + return getDrawerFigure().isPinShowing(); + } + + /** + * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#createAccessible() + */ + protected AccessibleEditPart createAccessible() { + return new AccessibleGraphicalEditPart() { + public void getDescription(AccessibleEvent e) { + e.result = getPaletteEntry().getDescription(); + } + + public void getName(AccessibleEvent e) { + e.result = getPaletteEntry().getLabel(); + } + + public void getRole(AccessibleControlEvent e) { + e.detail = ACC.ROLE_TREE; + } + + public void getState(AccessibleControlEvent e) { + super.getState(e); + e.detail |= isExpanded() ? ACC.STATE_EXPANDED + : ACC.STATE_COLLAPSED; + } + }; + } + + /** + * @see org.eclipse.gef.editparts.AbstractEditPart#refreshVisuals() + */ + protected void refreshVisuals() { + getDrawerFigure().setToolTip(createToolTip()); + + ImageDescriptor img = getDrawer().getSmallIcon(); + if (img == null && getDrawer().showDefaultIcon()) { + img = InternalImages.DESC_FOLDER_OPEN; + } + setImageDescriptor(img); + + getDrawerFigure().setTitle(getPaletteEntry().getLabel()); + getDrawerFigure().setLayoutMode(getLayoutSetting()); + + boolean showPin = getPreferenceSource().getAutoCollapseSetting() == PaletteViewerPreferences.COLLAPSE_AS_NEEDED; + getDrawerFigure().showPin(showPin); + + Color background = getDrawer().getDrawerType().equals( + PaletteTemplateEntry.PALETTE_TYPE_TEMPLATE) ? PaletteColorUtil.WIDGET_LIST_BACKGROUND + : null; + getDrawerFigure().getScrollpane().setBackgroundColor(background); + + /* TIZEN: add new UI: Set font size { */ + getFigure().setFont(FontResources.PALETTE_CATEGORY_NORMAL); + /* TIZEN } */ + } + + /** + * @see org.eclipse.gef.editparts.AbstractEditPart#register() + */ + protected void register() { + super.register(); + getPaletteAnimator().addDrawer(this); + getFigure().addLayoutListener(getPaletteAnimator()); + } + + /** + * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#restoreState(org.eclipse.ui.IMemento) + */ + public void restoreState(IMemento memento) { + setExpanded(new Boolean(memento.getString(PROPERTY_EXPANSION_STATE)) + .booleanValue()); + setPinnedOpen(new Boolean(memento.getString(PROPERTY_PINNED_STATE)) + .booleanValue()); + RangeModel rModel = getDrawerFigure().getScrollpane().getViewport() + .getVerticalRangeModel(); + rModel.setMinimum(memento.getInteger(RangeModel.PROPERTY_MINIMUM) + .intValue()); + rModel.setMaximum(memento.getInteger(RangeModel.PROPERTY_MAXIMUM) + .intValue()); + rModel.setExtent(memento.getInteger(RangeModel.PROPERTY_EXTENT) + .intValue()); + rModel.setValue(memento.getInteger(RangeModel.PROPERTY_VALUE) + .intValue()); + super.restoreState(memento); + } + + /** + * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#saveState(org.eclipse.ui.IMemento) + */ + public void saveState(IMemento memento) { + memento.putString(PROPERTY_EXPANSION_STATE, + new Boolean(isExpanded()).toString()); + memento.putString(PROPERTY_PINNED_STATE, + new Boolean(isPinnedOpen()).toString()); + RangeModel rModel = getDrawerFigure().getScrollpane().getViewport() + .getVerticalRangeModel(); + memento.putInteger(RangeModel.PROPERTY_MINIMUM, rModel.getMinimum()); + memento.putInteger(RangeModel.PROPERTY_MAXIMUM, rModel.getMaximum()); + memento.putInteger(RangeModel.PROPERTY_EXTENT, rModel.getExtent()); + memento.putInteger(RangeModel.PROPERTY_VALUE, rModel.getValue()); + super.saveState(memento); + } + + /** + * Sets the expansion state of the DrawerFigure + * + * @param expanded + * true if the drawer is expanded; false otherwise. + */ + public void setExpanded(boolean expanded) { + getDrawerFigure().setExpanded(expanded); + } + + /** + * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#setImageInFigure(Image) + */ + protected void setImageInFigure(Image image) { + getDrawerFigure().setTitleIcon(image); + } + + public void setPinnedOpen(boolean pinned) { + getDrawerFigure().setPinned(pinned); + } + + /** + * @see org.eclipse.gef.EditPart#setSelected(int) + */ + public void setSelected(int value) { + + /* TIZEN: add new UI: Image processing for selected state { */ + if (this.getSelected() == value) { + return; + } + + boolean bSelected = value != EditPart.SELECTED_NONE; + + // Image processing for selected state + DrawerFigure drawerFigure = getDrawerFigure(); + drawerFigure.setSelected(bSelected); + + // for the selected category icon + PaletteDrawer drawer = getDrawer(); + ImageDescriptor img = drawer.getSmallIcon(); + if (img == null && drawer.showDefaultIcon()) { + // if no icon + img = InternalImages.DESC_FOLDER_OPEN; + } else { + String category = drawer.getDescription(); + CATEGORY_ICON icon = PaletteConstants.CATEGORY_ICON.get(category); + if (icon != null) { + + img = icon.getImageDescriptor(bSelected); + } + drawer.setSmallIcon(img); + + } + /* TIZEN: add new UI } */ + + super.setSelected(value); + getDrawerFigure().getCollapseToggle().requestFocus(); + } + + /** + * @see org.eclipse.gef.editparts.AbstractEditPart#unregister() + */ + protected void unregister() { + getPaletteAnimator().removeDrawer(this); + super.unregister(); + } + + /** + * deactivate method of the EditPart Dispose created image's resource + */ + @Override + public void deactivate() { + /* TIZEN: add new UI: Clean up image' resource { */ + getDrawerFigure().dispose(); + /* TIZEN: add new UI: Clean up image' resource } */ + super.deactivate(); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/DrawerFigure.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/DrawerFigure.java new file mode 100644 index 0000000..21ce074 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/DrawerFigure.java @@ -0,0 +1,580 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-09 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * 1) update package name + * 2) apply new UI + * - deactivate: Clean up image' resource + * - CollapseToggle.handleStateChanged: add new UI: apply arrowButton's direction + * - DrawerFigure: add arrowButton and modified always selected the pinFigure + * - getSelected: add new method + * - setSelected: add new method + * - paintToggleGradient: The eclipse source is commented and add Tizen source for new UI + * - setLayoutMode: call arrowButton's setLayout method + * - dispose: add new dispose method + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts; + +import java.util.Iterator; +import java.util.List; + +import org.eclipse.draw2d.Animation; +import org.eclipse.draw2d.Border; +import org.eclipse.draw2d.BorderLayout; +import org.eclipse.draw2d.ButtonModel; +import org.eclipse.draw2d.ChangeEvent; +import org.eclipse.draw2d.ChangeListener; +import org.eclipse.draw2d.Clickable; +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.CompoundBorder; +import org.eclipse.draw2d.Figure; +import org.eclipse.draw2d.FigureUtilities; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.LayoutManager; +import org.eclipse.draw2d.MarginBorder; +import org.eclipse.draw2d.MouseEvent; +import org.eclipse.draw2d.MouseListener; +import org.eclipse.draw2d.MouseMotionListener; +import org.eclipse.draw2d.SchemeBorder; +import org.eclipse.draw2d.ScrollPane; +import org.eclipse.draw2d.Toggle; +import org.eclipse.draw2d.ToolbarLayout; +import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.draw2d.geometry.Insets; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.ui.palette.PaletteViewerPreferences; +import org.eclipse.gef.ui.palette.editparts.PaletteToolbarLayout; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.PaletteColorUtil; +import org.tizen.efluibuilder.ui.editor.palette.internal.ArrowButton; +import org.tizen.efluibuilder.ui.resources.ColorResources; + + +/** + * @author Pratik Shah + */ +public class DrawerFigure extends Figure { + + /** Foreground color constant **/ + protected static final Color FG_COLOR = FigureUtilities.mixColors( + PaletteColorUtil.WIDGET_NORMAL_SHADOW, + PaletteColorUtil.WIDGET_BACKGROUND); + + /** Scrollpane border constant for icon and column layout mode **/ + protected static final Border SCROLL_PANE_BORDER = new MarginBorder(2, 2, + 2, 2); + /** Scrollpane border constant for list and details layout mode **/ + protected static final Border SCROLL_PANE_LIST_BORDER = new MarginBorder(2, + 0, 2, 0); + /** Title margin border constant **/ + protected static final Border TITLE_MARGIN_BORDER = new MarginBorder(4, 2, + 2, 2); + /** Toggle button border constant **/ + protected static final Border TOGGLE_BUTTON_BORDER = new RaisedBorder(); + /** Tooltip border constant **/ + protected static final Border TOOLTIP_BORDER = new CompoundBorder( + new SchemeBorder(SchemeBorder.SCHEMES.RAISED), new MarginBorder(1)); + private Toggle collapseToggle; + private Label drawerLabel, tipLabel; + + private boolean addedScrollpane = false; + private int layoutMode = -1; + private PinFigure pinFigure; + private ScrollPane scrollpane; + private boolean showPin = true, skipNextEvent; + private EditPartTipHelper tipHelper; + + /* TIZEN: { */ + private boolean isSelected = false; + private ArrowButton arrowButton; + /* TIZEN: } */ + + /** + * This is the figure for the entire drawer label button. + */ + private class CollapseToggle extends Toggle { + + public CollapseToggle(IFigure contents) { + super(contents); + setSelected(true); + setRequestFocusEnabled(true); + addChangeListener(new ChangeListener() { + + public void handleStateChanged(ChangeEvent e) { + if (e.getPropertyName().equals(ButtonModel.SELECTED_PROPERTY)) { + Animation.markBegin(); + handleExpandStateChanged(); + Animation.run(150); + + /* TIZEN: add new UI: apply arrowButton's direction { */ + if (isExpanded()) { + arrowButton.setDirection(ArrowButton.DIRECTION_EXPANDED); + } else { + arrowButton.setDirection(ArrowButton.DIRECTION_COLLAPSED); + } + /* TIZEN: } */ + } else if (e.getPropertyName().equals(ButtonModel.MOUSEOVER_PROPERTY)) { + repaint(); + } + } + }); + } + + public IFigure getToolTip() { + return buildTooltip(); + } + + protected void paintFigure(Graphics g) { + super.paintFigure(g); + Rectangle r = Rectangle.SINGLETON; + r.setBounds(getBounds()); + + // draw top border of drawer figure + g.setForegroundColor(PaletteColorUtil.WIDGET_NORMAL_SHADOW); + g.drawLine(r.getTopLeft(), r.getTopRight()); + g.setForegroundColor(ColorConstants.white); + g.drawLine(r.getTopLeft().getTranslated(0, 1), r.getTopRight() + .getTranslated(0, 1)); + r.crop(new Insets(2, 0, 0, 0)); + if (isExpanded()) { + g.setForegroundColor(PaletteColorUtil.WIDGET_BACKGROUND_NORMAL_SHADOW_65); + g.drawLine(r.getLocation(), r.getTopRight()); + r.crop(new Insets(1, 0, 0, 0)); + } + + // draw bottom border of drawer figure + if (!isExpanded()) { + g.setForegroundColor(ColorConstants.white); + g.drawLine(r.getBottomLeft().getTranslated(0, -1), r + .getBottomRight().getTranslated(0, -1)); + r.crop(new Insets(0, 0, 1, 0)); + } + + paintToggleGradient(g, r); + + } + } + + /** + * Constructor + * + * @param control + * The Control of the LWS to which this Figure belongs (it is used to display the + * drawer header with an EditPartTipHelper, if the header is not completely visible). + * It can be null (the tip won't be displayed). + */ + public DrawerFigure(final Control control) { + /* + * A PaletteToolbarLayout is being used here instead of a ToolbarLayout so that the + * ScrollPane can be stretched to take up vertical space. This affects selection and + * appearance (background color). + */ + setLayoutManager(new PaletteToolbarLayout() { + protected boolean isChildGrowing(IFigure child) { + int wHint = child.getBounds().width; + return child.getPreferredSize(wHint, -1).height != child + .getMinimumSize(wHint, -1).height; + } + }); + + Figure title = new Figure(); + title.setBorder(TITLE_MARGIN_BORDER); + BorderLayout borderLayout = new BorderLayout(); + borderLayout.setHorizontalSpacing(2); + title.setLayoutManager(borderLayout); + + drawerLabel = new Label(); + drawerLabel.setLabelAlignment(Label.LEFT); + + pinFigure = new PinFigure(); + title.add(pinFigure, BorderLayout.RIGHT); + + /* TIZEN: Add arrowButton { */ + arrowButton = new ArrowButton(ArrowButton.DIRECTION_EXPANDED); + arrowButton.setPreferredSize(ArrowButton.TRIANGLE_SIZE * 2 + 2, ArrowButton.TRIANGLE_SIZE); + title.add(arrowButton, BorderLayout.RIGHT); + /* } TIZEN */ + + title.add(drawerLabel, BorderLayout.CENTER); + + collapseToggle = new CollapseToggle(title); + + /* + * @TODO:Pratik + * + * There is a bug here. Right-click on the name pop-up for the header of a drawer figure in + * the palette. This will hide the pop-up. Right-click again, this time on the collapse + * toggle, to bring up the drawer's context menu. Now, left-click on the collapse toggle. + * The context menu will disappear, the name pop-up will re-appear, and the drawer will + * collapse/expand. If the drawer was in such a position, that collapsing/expanding it will + * cause its header to move, the name pop-up will now be floating over where the collapse + * toggle used to be, but is not anymore. To fix this, you can detect the left mouse click + * on the collapse toggle and hide the name pop-up then. The problem is that when you click + * on the collapseToggle after the context menu has been brought up, it does not fire a + * mouse pressed event. The listener below, that is commented out for now, is never + * notified. + */ + // collapseToggle.addMouseListener(new MouseListener.Stub(){ + // public void mousePressed(MouseEvent me) { + // System.out.println("AAA"); + // } + // }); + + add(collapseToggle); + createScrollpane(); + createHoverHelp(control); + + /* TIZEN: pinFigure is always selected { */ + pinFigure.setSelected(true); + showPin(false); + /* } TIZEN */ + } + + /* TIZEN: category's getSelected method { */ + public boolean getSelected() { + return this.isSelected; + } + /* } TIZEN */ + + /* TIZEN: category's selected method { */ + public void setSelected(boolean isSelected) { + this.isSelected = isSelected; + } + /* } TIZEN */ + + /** + * Paints the background gradient on the drawer toggle figure. + * + * @param g + * the graphics object + * @param rect + * the rectangle which the background gradient should cover + */ + private void paintToggleGradient(Graphics g, Rectangle rect) { + /* + * ECLIPSE { + * + * if (isExpanded()) { + * g.setBackgroundColor(PaletteColorUtil.WIDGET_BACKGROUND_LIST_BACKGROUND_85); + * g.fillRectangle(rect); } else if (collapseToggle.getModel().isMouseOver()) { Color color1 + * = PaletteColorUtil.WIDGET_BACKGROUND_LIST_BACKGROUND_60; Color color2 = + * PaletteColorUtil.WIDGET_BACKGROUND_NORMAL_SHADOW_90; Color color3 = + * PaletteColorUtil.WIDGET_BACKGROUND_NORMAL_SHADOW_95; Color color4 = + * PaletteColorUtil.WIDGET_BACKGROUND_LIST_BACKGROUND_90; + * + * g.setForegroundColor(color1); g.setBackgroundColor(color2); g.fillGradient(rect.x, + * rect.y, rect.width, rect.height - 4, true); + * + * g.setForegroundColor(color2); g.setBackgroundColor(color3); g.fillGradient(rect.x, + * rect.bottom() - 4, rect.width, 2, true); + * + * g.setForegroundColor(color3); g.setBackgroundColor(color4); g.fillGradient(rect.x, + * rect.bottom() - 2, rect.width, 2, true); } else { + * g.setForegroundColor(PaletteColorUtil.WIDGET_BACKGROUND_LIST_BACKGROUND_85); + * g.setBackgroundColor(PaletteColorUtil.WIDGET_BACKGROUND_NORMAL_SHADOW_45); + * g.fillGradient(rect, true); } + * + * } ECLIPSE + */ + /* TIZEN { */ + g.setForegroundColor(ColorResources.PALETTE_CATEGORY_NORMAL); + g.setBackgroundColor(ColorResources.PALETTE_CATEGORY_BACKGROUND); + g.fillRectangle(rect); + /* } TIZEN */ + + } + + private void createHoverHelp(final Control control) { + if (control == null) { + return; + } + // If a control was provided, create the tipLabel -- if the text in the + // header is + // truncated, it will display it as a tooltip. + tipLabel = new Label() { + /** + * @see org.eclipse.draw2d.Figure#getToolTip() + */ + public IFigure getToolTip() { + return buildTooltip(); + } + + protected void paintFigure(Graphics graphics) { + Rectangle r = Rectangle.SINGLETON; + r.setBounds(getBounds()); + graphics.pushState(); + paintToggleGradient(graphics, getBounds()); + graphics.popState(); + super.paintFigure(graphics); + } + }; + tipLabel.setOpaque(false); + tipLabel.setBorder(TOOLTIP_BORDER); + collapseToggle.addMouseMotionListener(new MouseMotionListener.Stub() { + public void mouseMoved(MouseEvent e) { + if (!drawerLabel.getBounds().contains(e.getLocation())) + return; + if (skipNextEvent) { + skipNextEvent = false; + return; + } + if (drawerLabel.isTextTruncated() + && !EditPartTipHelper.isCurrent(tipHelper)) { + tipLabel.setText(drawerLabel.getText()); + tipLabel.setIcon(drawerLabel.getIcon()); + tipLabel.setFont(drawerLabel.getFont()); + tipHelper = new EditPartTipHelper(control); + Rectangle bounds = drawerLabel.getBounds() + .getExpanded(2, 2); + drawerLabel.translateToAbsolute(bounds); + org.eclipse.swt.graphics.Rectangle loc = new org.eclipse.swt.graphics.Rectangle( + bounds.x, bounds.y, bounds.width, bounds.height); + loc = Display.getCurrent().map(control, null, loc); + tipHelper.displayToolTipAt(tipLabel, loc.x, loc.y); + } + } + }); + tipLabel.addMouseListener(new MouseListener.Stub() { + public void mousePressed(MouseEvent e) { + if (e.button == 1) { + Rectangle original = getCollapseToggle().getBounds() + .getCopy(); + getCollapseToggle().requestFocus(); + setExpanded(!isExpanded()); + // Hide the tip if expanding the drawer causes the collapse + // toggle to move + if (!original.equals(getCollapseToggle().getBounds())) { + tipHelper.hide(); + } + } else { + tipHelper.hide(); + if (e.button == 3) { + skipNextEvent = true; + } + } + } + }); + } + + private void createScrollpane() { + scrollpane = new ScrollPane(); + scrollpane.getViewport().setContentsTracksWidth(true); + scrollpane.setMinimumSize(new Dimension(0, 0)); + scrollpane.setHorizontalScrollBarVisibility(ScrollPane.NEVER); + scrollpane.setVerticalScrollBar(new PaletteScrollBar()); + scrollpane.getVerticalScrollBar().setStepIncrement(20); + scrollpane.setLayoutManager(new OverlayScrollPaneLayout()); + scrollpane.setContents(new Figure()); + scrollpane.getContents().setOpaque(true); + scrollpane.getContents().setBackgroundColor(PaletteColorUtil.WIDGET_LIST_BACKGROUND); + } + + IFigure buildTooltip() { + return null; + } + + /** + * @return The Clickable that is used to expand/collapse the drawer. + */ + public Clickable getCollapseToggle() { + return collapseToggle; + } + + /** + * @return The content pane for this figure, i.e. the Figure to which children can be added. + */ + public IFigure getContentPane() { + return scrollpane.getContents(); + } + + /** + * @see Figure#getMinimumSize(int, int) + */ + public Dimension getMinimumSize(int wHint, int hHint) { + /* + * Fix related to Bug #35176 The figure returns a minimum size that is of at least a certain + * height, so as to prevent each drawer from getting too small (in which case, the + * scrollbars cover up the entire available space). + */ + if (isExpanded()) { + List children = getContentPane().getChildren(); + if (!children.isEmpty()) { + Dimension result = collapseToggle + .getPreferredSize(wHint, hHint).getCopy(); + result.height += getContentPane().getInsets().getHeight(); + IFigure child = (IFigure) children.get(0); + result.height += Math.min(80, + child.getPreferredSize(wHint, -1).height + 9); + return result.intersect(getPreferredSize(wHint, hHint)); + } + } + + return super.getMinimumSize(wHint, hHint); + } + + /** + * Returns the ScrollPane associated with this DrawerFigure + * + * @return the ScrollPane + */ + public ScrollPane getScrollpane() { + return scrollpane; + } + + protected void handleExpandStateChanged() { + if (isExpanded()) { + if (scrollpane.getParent() != this) + add(scrollpane); + } else { + if (scrollpane.getParent() == this) + remove(scrollpane); + + // collapse all pinnable palette stack children that aren't pinned + for (Iterator iterator = getContentPane().getChildren().iterator(); iterator + .hasNext();) { + Object child = iterator.next(); + if (child instanceof PinnablePaletteStackFigure + && !((PinnablePaletteStackFigure) child).isPinnedOpen()) { + ((PinnablePaletteStackFigure) child).setExpanded(false); + } + } + + } + + if (pinFigure != null) { + pinFigure.setVisible(isExpanded() && showPin); + } + } + + /** + * @return true if the drawer is expanded + */ + public boolean isExpanded() { + return collapseToggle.isSelected(); + } + + /** + * @return true if the drawer is expanded and is pinned (i.e., it can't be + * automatically collapsed) + */ + public boolean isPinnedOpen() { + return isExpanded() && pinFigure.isVisible() && pinFigure.isSelected(); + } + + /** + * @return true if the drawer is expanded and its pin is showing + */ + public boolean isPinShowing() { + return isExpanded() && showPin; + } + + public void setAnimating(boolean isAnimating) { + if (isAnimating) { + if (scrollpane.getParent() != this) { + addedScrollpane = true; + add(scrollpane); + } + scrollpane.setVerticalScrollBarVisibility(ScrollPane.NEVER); + } else { + scrollpane.setVerticalScrollBarVisibility(ScrollPane.AUTOMATIC); + if (addedScrollpane) { + remove(scrollpane); + addedScrollpane = false; + } + } + } + + public void setExpanded(boolean value) { + collapseToggle.setSelected(value); + } + + public void setLayoutMode(int layoutMode) { + if (this.layoutMode == layoutMode) { + return; + } + + this.layoutMode = layoutMode; + + LayoutManager manager; + if (layoutMode == PaletteViewerPreferences.LAYOUT_COLUMNS) { + manager = new ColumnsLayout(); + getContentPane().setBorder(SCROLL_PANE_BORDER); + } else if (layoutMode == PaletteViewerPreferences.LAYOUT_ICONS) { + PaletteContainerFlowLayout fl = new PaletteContainerFlowLayout(); + fl.setMinorSpacing(0); + fl.setMajorSpacing(0); + manager = fl; + getContentPane().setBorder(SCROLL_PANE_BORDER); + } else { + manager = new ToolbarLayout(); + getContentPane().setBorder(SCROLL_PANE_LIST_BORDER); + } + getContentPane().setLayoutManager(manager); + /* TIZEN: Because the layout(clientArea) of the initial state is invalid, reset layout. { */ + arrowButton.setLayout(); + /* } TIZEN */ + } + + /** + * Pins or unpins the drawer. The drawer can be pinned open only when it is expanded. Attempts + * to pin it when it is collapsed will do nothing. + * + * @param pinned + * true if the drawer is to be pinned + */ + public void setPinned(boolean pinned) { + if (!isExpanded() || !showPin) { + return; + } + + pinFigure.setSelected(pinned); + } + + /** + * Displays the given text in the drawer's header as its title. + * + * @param s + * The title of the drawer + */ + public void setTitle(String s) { + drawerLabel.setText(s); + } + + /** + * Displays the given image in the header as the drawer's icon. + * + * @param icon + * The icon for this drawer. + */ + public void setTitleIcon(Image icon) { + drawerLabel.setIcon(icon); + } + + public void showPin(boolean show) { + showPin = show; + handleExpandStateChanged(); + } + + /* TIZEN: clean-up image's resource { */ + public void dispose() { + arrowButton.dispose(); + arrowButton.setParent(null); + ((PaletteScrollBar) scrollpane.getVerticalScrollBar()).dispose(); + } + /* } TIZEN */ +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/DropShadowButtonBorder.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/DropShadowButtonBorder.java new file mode 100644 index 0000000..c080e61 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/DropShadowButtonBorder.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-09 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts; + +import org.eclipse.draw2d.AbstractBorder; +import org.eclipse.draw2d.ButtonModel; +import org.eclipse.draw2d.Clickable; +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.geometry.Insets; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.swt.custom.ViewForm; +import org.eclipse.swt.graphics.Color; + + +class DropShadowButtonBorder extends AbstractBorder { + + protected Insets insets = new Insets(1, 1, 3, 3); + + private static final Color highlight = ColorConstants.menuBackgroundSelected, + dropshadow2 = new Color(null, ViewForm.borderMiddleRGB), + dropshadow3 = new Color(null, ViewForm.borderOutsideRGB); + + /** + * Returns the space used by the border for the figure provided as input. In this border all + * sides always have equal width. + * + * @param figure + * Figure for which this is the border. + * @return Insets for this border. + */ + public Insets getInsets(IFigure figure) { + return insets; + } + + public boolean isOpaque() { + return true; + } + + public void paint(IFigure figure, Graphics g, Insets insets) { + ButtonModel model = ((Clickable) figure).getModel(); + Rectangle r = getPaintRectangle(figure, insets); + g.setLineWidth(1); + r.width -= 3; + r.height -= 3; + + if (model.isMouseOver() && !model.isArmed()) { + g.setForegroundColor(highlight); + g.drawRectangle(r); + + r.translate(1, 1); + g.setForegroundColor(dropshadow2); + g.drawLine(r.x, r.bottom(), r.right(), r.bottom()); + g.drawLine(r.right(), r.y, r.right(), r.bottom()); + + r.translate(1, 1); + g.setForegroundColor(dropshadow3); + g.drawLine(r.x + 1, r.bottom(), r.right() - 1, r.bottom()); + g.drawLine(r.right(), r.y + 1, r.right(), r.bottom() - 1); + } else if (model.isPressed()) { + r.translate(1, 1); + + g.setForegroundColor(highlight); + g.drawRectangle(r); + + r.translate(1, 1); + g.setForegroundColor(dropshadow2); + g.drawLine(r.x, r.bottom(), r.right(), r.bottom()); + g.drawLine(r.right(), r.y, r.right(), r.bottom()); + } else { + r.translate(1, 1); + + g.setForegroundColor(dropshadow3); + g.drawRectangle(r); + + r.translate(1, 1); + g.drawLine(r.x, r.bottom(), r.right(), r.bottom()); + g.drawLine(r.right(), r.y, r.right(), r.bottom()); + } + + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/EditPartTipHelper.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/EditPartTipHelper.java new file mode 100644 index 0000000..c3a6920 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/EditPartTipHelper.java @@ -0,0 +1,190 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-09 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseMoveListener; +import org.eclipse.swt.events.MouseTrackAdapter; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.events.ShellAdapter; +import org.eclipse.swt.events.ShellEvent; +import org.eclipse.swt.events.ShellListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + + +class EditPartTipHelper extends org.eclipse.draw2d.PopUpHelper { + + private static EditPartTipHelper currentHelper; + private ShellListener shellListener; + + private static void setHelper(EditPartTipHelper helper) { + if (currentHelper != null && currentHelper != helper + && currentHelper.isShowing()) + currentHelper.hide(); + currentHelper = helper; + } + + public EditPartTipHelper(Control c) { + super(c, SWT.ON_TOP | SWT.TOOL | SWT.NO_TRIM); + } + + /** + * Sets the LightWeightSystem object's contents to the passed tooltip, and displays the tip at + * the coordianates specified by tipPosX and tipPosY. The given coordinates will be adjusted if + * the tip cannot be completely visible on the screen. + * + * @param tip + * The tool tip to be displayed. + * @param tipPosX + * X coordiante of tooltip to be displayed + * @param tipPosY + * Y coordinate of tooltip to be displayed + */ + public void displayToolTipAt(IFigure tip, int tipPosX, int tipPosY) { + if (tip != null) { + // Adjust the position if the tip will not be completely visible on + // the screen + int shiftX = 0; + int shiftY = 0; + Dimension tipSize = tip.getPreferredSize(); + getShell(); + tipSize = tipSize.getExpanded(getShellTrimSize()); + org.eclipse.swt.graphics.Rectangle area = control.getDisplay() + .getClientArea(); + org.eclipse.swt.graphics.Point end = new org.eclipse.swt.graphics.Point( + tipPosX + tipSize.width, tipPosY + tipSize.height); + if (!area.contains(end)) { + shiftX = end.x - (area.x + area.width); + shiftY = end.y - (area.y + area.height); + shiftX = shiftX < 0 ? 0 : shiftX; + shiftY = shiftY < 0 ? 0 : shiftY; + } + tipPosX -= shiftX; + tipPosY -= shiftY; + + // Display the tip + EditPartTipHelper.setHelper(this); + getLightweightSystem().setContents(tip); + setShellBounds(tipPosX, tipPosY, tipSize.width, tipSize.height); + show(); + getShell().setCapture(true); + } + } + + public void dispose() { + if (shellListener != null) { + control.getShell().removeShellListener(shellListener); + shellListener = null; + } + super.dispose(); + } + + /** + * @see org.eclipse.draw2d.PopUpHelper#hide() + */ + protected void hide() { + super.hide(); + currentHelper = null; + } + + protected void hookShellListeners() { + + /* + * If the cursor leaves the tip window, hide the tooltip and dispose of its shell + */ + getShell().addMouseTrackListener(new MouseTrackAdapter() { + public void mouseExit(MouseEvent e) { + getShell().setCapture(false); + dispose(); + } + }); + /* + * If the mouseExit listener does not get called, dispose of the shell if the cursor is no + * longer in the tooltip. This occurs in the rare case that a mouseEnter is not received on + * the tooltip when it appears. + */ + getShell().addMouseMoveListener(new MouseMoveListener() { + public void mouseMove(MouseEvent e) { + Point eventPoint = getShell().toDisplay(new Point(e.x, e.y)); + if (!getShell().getBounds().contains(eventPoint)) { + if (isShowing()) + getShell().setCapture(false); + dispose(); + } + } + }); + + // This is to dispose of the tooltip when the user ALT-TABs to another + // window. + if (shellListener == null) { + shellListener = new ShellAdapter() { + public void shellDeactivated(ShellEvent event) { + Display.getCurrent().asyncExec(new Runnable() { + public void run() { + Shell active = Display.getCurrent() + .getActiveShell(); + if (getShell() == active + || control.getShell() == active + || getShell().isDisposed()) + return; + if (isShowing()) + getShell().setCapture(false); + dispose(); + } + }); + } + }; + control.getShell().addShellListener(shellListener); + getShell().addShellListener(shellListener); + } + + /* + * Workaround for GTK Bug - Control.setCapture(boolean) not implemented: If the cursor is + * not over the shell when it is first painted, hide the tooltip and dispose of the shell. + */ + if (SWT.getPlatform().equals("gtk")) { //$NON-NLS-1$ + getShell().addPaintListener(new PaintListener() { + public void paintControl(PaintEvent event) { + Point cursorLoc = Display.getCurrent().getCursorLocation(); + if (!getShell().getBounds().contains(cursorLoc)) { + // This must be run asynchronously. If not, other paint + // listeners may attempt to paint on a disposed control. + Display.getCurrent().asyncExec(new Runnable() { + public void run() { + if (isShowing()) + getShell().setCapture(false); + dispose(); + } + }); + } + } + }); + } + } + + public static boolean isCurrent(EditPartTipHelper helper) { + return currentHelper != null && helper == currentHelper; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/GroupEditPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/GroupEditPart.java new file mode 100644 index 0000000..54a5098 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/GroupEditPart.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-09 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts; + +import org.eclipse.draw2d.Border; +import org.eclipse.draw2d.Figure; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.LayoutManager; +import org.eclipse.draw2d.MarginBorder; +import org.eclipse.draw2d.ToolbarLayout; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.PaletteColorUtil; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteContainer; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewerPreferences; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.editparts.PaletteEditPart; + + +public class GroupEditPart extends PaletteEditPart { + + /** Scrollpane border constant for icon and column layout mode **/ + private static final Border SCROLL_PANE_BORDER = new MarginBorder(2, 2, 2, + 2); + + /** Scrollpane border constant for list and details layout mode **/ + private static final Border SCROLL_PANE_LIST_BORDER = new MarginBorder(2, + 0, 2, 0); + + private int cachedLayout = -1; + + public GroupEditPart(PaletteContainer group) { + super(group); + } + + /** + * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure() + */ + public IFigure createFigure() { + Figure figure = new Figure(); + figure.setOpaque(true); + figure.setBackgroundColor(PaletteColorUtil.WIDGET_LIST_BACKGROUND); + return figure; + } + + /** + * @see org.eclipse.gef.editparts.AbstractEditPart#refreshVisuals() + */ + protected void refreshVisuals() { + int layout = getLayoutSetting(); + if (cachedLayout == layout) + return; + cachedLayout = layout; + LayoutManager manager; + if (layout == PaletteViewerPreferences.LAYOUT_COLUMNS) { + manager = new ColumnsLayout(); + getContentPane().setBorder(SCROLL_PANE_BORDER); + } else if (layout == PaletteViewerPreferences.LAYOUT_ICONS) { + PaletteContainerFlowLayout flow = new PaletteContainerFlowLayout(); + flow.setMajorSpacing(0); + flow.setMinorSpacing(0); + manager = flow; + getContentPane().setBorder(SCROLL_PANE_BORDER); + } else { + manager = new ToolbarLayout(); + getContentPane().setBorder(SCROLL_PANE_LIST_BORDER); + } + getContentPane().setLayoutManager(manager); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/IPaletteStackEditPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/IPaletteStackEditPart.java new file mode 100644 index 0000000..1fcfeca --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/IPaletteStackEditPart.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2008, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-09 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts; + +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.editparts.PaletteEditPart; + + +/** + * An interface to define the common behavior between all palette stack editparts (i.e. the type on + * the palette toolbar and the type in a drawer or group on the palette pane). + * + * @author crevells + * @since 3.4 + */ +public interface IPaletteStackEditPart { + + /** + * Opens/expands the palette stack. + */ + void openMenu(); + + /** + * Returns the active palette entry editpart in the stack. + * + * @return the active part + */ + PaletteEditPart getActiveEntry(); +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/OverlayScrollPaneLayout.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/OverlayScrollPaneLayout.java new file mode 100644 index 0000000..6a3cabd --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/OverlayScrollPaneLayout.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-09 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.ScrollBar; +import org.eclipse.draw2d.ScrollPane; +import org.eclipse.draw2d.ScrollPaneLayout; +import org.eclipse.draw2d.Viewport; +import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.draw2d.geometry.Insets; +import org.eclipse.draw2d.geometry.Rectangle; + + +public class OverlayScrollPaneLayout extends ScrollPaneLayout { + + /** + * {@inheritDoc} In OverlayScrollPane, scrollbars are overlayed on top of the Viewport, so the + * preferred size is just the Viewports preferred size. + * + * @since 2.0 + */ + protected Dimension calculatePreferredSize(IFigure container, int wHint, + int hHint) { + ScrollPane scrollpane = (ScrollPane) container; + Insets insets = scrollpane.getInsets(); + + int excludedWidth = insets.getWidth(); + int excludedHeight = insets.getHeight(); + + return scrollpane + .getViewport() + .getPreferredSize(wHint - excludedWidth, hHint - excludedHeight) + .getExpanded(excludedWidth, excludedHeight); + } + + /** {@inheritDoc} */ + public void layout(IFigure parent) { + ScrollPane scrollpane = (ScrollPane) parent; + Rectangle clientArea = parent.getClientArea(); + + ScrollBar hBar = scrollpane.getHorizontalScrollBar(), vBar = scrollpane + .getVerticalScrollBar(); + Viewport viewport = scrollpane.getViewport(); + + Insets insets = new Insets(); + insets.bottom = hBar.getPreferredSize(clientArea.width, + clientArea.height).height; + insets.right = vBar.getPreferredSize(clientArea.width, + clientArea.height).width; + + int hVis = scrollpane.getHorizontalScrollBarVisibility(), vVis = scrollpane + .getVerticalScrollBarVisibility(); + + Dimension available = clientArea.getSize(), preferred = viewport + .getPreferredSize(available.width, available.height).getCopy(); + + boolean none = available.contains(preferred), both = !none + && vVis != NEVER && hVis != NEVER + && preferred.contains(available), showV = both + || preferred.height > available.height, + showH = both + || preferred.width > available.width; + + // Adjust for visibility override flags + showV = !(vVis == NEVER) && (showV || vVis == ALWAYS); + showH = !(hVis == NEVER) && (showH || hVis == ALWAYS); + + if (!showV) + insets.right = 0; + if (!showH) + insets.bottom = 0; + Rectangle bounds, viewportArea = clientArea; + + if (showV) { + bounds = new Rectangle(viewportArea.right() - insets.right, + viewportArea.y, insets.right, viewportArea.height); + vBar.setBounds(bounds); + // vBar.setMaximum(preferred.height); + } + if (showH) { + bounds = new Rectangle(viewportArea.x, viewportArea.bottom() + - insets.bottom, viewportArea.width, insets.bottom); + hBar.setBounds(bounds); + // hBar.setMaximum(preferred.width); + } + vBar.setVisible(showV); + hBar.setVisible(showH); + viewport.setBounds(viewportArea); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/PaletteContainerFlowLayout.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/PaletteContainerFlowLayout.java new file mode 100644 index 0000000..b564e21 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/PaletteContainerFlowLayout.java @@ -0,0 +1,213 @@ +/******************************************************************************* + * Copyright (c) 2008, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-09 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts; + +import java.util.List; + +import org.eclipse.draw2d.FlowLayout; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.draw2d.geometry.Rectangle; + + +/** + * Extends FlowLayout to allow the pane of a pinnable stack in icon mode to occupy the + * row following the row in which the icon of the palette stack header appears. + * + * @author crevells + * @since 3.4 + */ +public class PaletteContainerFlowLayout extends FlowLayout { + + /** + * Constructs a PaletteContainerFlowLayout with horizontal orientation. + */ + public PaletteContainerFlowLayout() { + } + + /** + * Constructs a PaletteContainerFlowLayout whose orientation is given in the input. + * + * @param isHorizontal + * true if the layout should be horizontal + */ + public PaletteContainerFlowLayout(boolean isHorizontal) { + setHorizontal(isHorizontal); + } + + /** + * Overridden to include the size of the expanded pane of an expanded pinnable palette stack. + * + * @see org.eclipse.draw2d.AbstractLayout#calculatePreferredSize(IFigure, int, int) + */ + protected Dimension calculatePreferredSize(IFigure container, int wHint, + int hHint) { + + Dimension prefSize = super.calculatePreferredSize(container, wHint, + hHint); + + List children = container.getChildren(); + IFigure child; + + // Build the sizes for each row, and update prefSize accordingly + Dimension expandedPaneSize = null; + for (int i = 0; i < children.size(); i++) { + child = (IFigure) children.get(i); + + if (child instanceof PinnablePaletteStackFigure + && ((PinnablePaletteStackFigure) child).isExpanded()) { + + // Subtract out the insets from the hints + if (wHint > -1) + wHint = Math.max(0, wHint + - container.getInsets().getWidth()); + if (hHint > -1) + hHint = Math.max(0, hHint + - container.getInsets().getHeight()); + + // Figure out the new hint that we are interested in based on + // the + // orientation. Ignore the other hint (by setting it to -1). + // NOTE: + // The children of the parent figure will then be asked to + // ignore + // that hint as well. + if (isHorizontal()) { + hHint = -1; + } else { + wHint = -1; + } + + expandedPaneSize = ((PinnablePaletteStackFigure) child) + .getExpandedContainerPreferredSize(wHint, hHint); + + break; // there can only be one expanded stack + } + } + + if (expandedPaneSize != null) { + // increment height to account for expanded stack + prefSize.height += transposer.t(expandedPaneSize).height; + prefSize.union(getBorderPreferredSize(container)); + } + + return prefSize; + } + + /** + * Overridden to handle PinnablePaletteStackFigure. + * + * @see FlowLayout#getChildSize(IFigure, int, int) + */ + protected Dimension getChildSize(IFigure child, int wHint, int hHint) { + if (child instanceof PinnablePaletteStackFigure) { + return ((PinnablePaletteStackFigure) child).getHeaderPreferredSize( + wHint, hHint); + } else { + return child.getPreferredSize(wHint, hHint); + } + } + + /** + * Overridden to include the size of the expanded pane of an expanded pinnable palette stack + * during the layout. + * + * @see FlowLayout#layoutRow(IFigure) + */ + protected void layoutRow(IFigure parent) { + int majorAdjustment = 0; + int minorAdjustment = 0; + int correctMajorAlignment = majorAlignment; + int correctMinorAlignment = minorAlignment; + + majorAdjustment = data.area.width - data.rowWidth + getMinorSpacing(); + + switch (correctMajorAlignment) { + case ALIGN_LEFTTOP: + majorAdjustment = 0; + break; + case ALIGN_CENTER: + majorAdjustment /= 2; + break; + case ALIGN_RIGHTBOTTOM: + break; + } + + int expandedPaneHeight = 0; + for (int j = 0; j < data.rowCount; j++) { + if (fill) { + data.bounds[j].height = data.rowHeight; + } else { + minorAdjustment = data.rowHeight - data.bounds[j].height; + switch (correctMinorAlignment) { + case ALIGN_LEFTTOP: + minorAdjustment = 0; + break; + case ALIGN_CENTER: + minorAdjustment /= 2; + break; + case ALIGN_RIGHTBOTTOM: + break; + } + data.bounds[j].y += minorAdjustment; + } + data.bounds[j].x += majorAdjustment; + + IFigure child = data.row[j]; + setBoundsOfChild(parent, data.row[j], transposer.t(data.bounds[j])); + + if (child instanceof PinnablePaletteStackFigure + && ((PinnablePaletteStackFigure) child).isExpanded()) { + + int wHint = -1; + int hHint = -1; + if (isHorizontal()) + wHint = parent.getClientArea().width; + else + hHint = parent.getClientArea().height; + + expandedPaneHeight = ((PinnablePaletteStackFigure) child) + .getExpandedContainerPreferredSize(wHint, hHint).height; + child.setBounds(new Rectangle(data.area.x, data.area.y + + data.rowY, data.area.width, data.rowHeight + + expandedPaneHeight)); + } + } + data.rowY += getMajorSpacing() + data.rowHeight + expandedPaneHeight; + initRow(); + } + + /** + * Overridden to set the bounds for PinnablePaletteStackFigures . + * + * @see FlowLayout#setBoundsOfChild(IFigure, IFigure, Rectangle) + */ + protected void setBoundsOfChild(IFigure parent, IFigure child, + Rectangle bounds) { + + if (child instanceof PinnablePaletteStackFigure + && ((PinnablePaletteStackFigure) child).isExpanded()) { + parent.getClientArea(Rectangle.SINGLETON); + bounds.translate(Rectangle.SINGLETON.x, Rectangle.SINGLETON.y); + ((PinnablePaletteStackFigure) child) + .setHeaderBoundsLayoutHint(bounds); + } else { + super.setBoundsOfChild(parent, child, bounds); + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/PaletteScrollBar.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/PaletteScrollBar.java new file mode 100644 index 0000000..8a083d7 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/PaletteScrollBar.java @@ -0,0 +1,273 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-09 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * 1) update package name + * 2) apply new UI + * - update UI category's scrolling button (color, dimension) + * - The scrollbar's triangle widgets changed into the images. + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts; + +import org.eclipse.draw2d.BorderLayout; +import org.eclipse.draw2d.Clickable; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.RangeModel; +import org.eclipse.draw2d.ScrollBar; +import org.eclipse.draw2d.ScrollBarLayout; +import org.eclipse.draw2d.Toggle; +import org.eclipse.draw2d.TreeSearch; +import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.draw2d.geometry.Insets; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.swt.SWT; +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.widgets.Display; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.PaletteColorUtil; +import org.tizen.efluibuilder.ui.editor.palette.internal.ArrowButton; + + +public final class PaletteScrollBar extends ScrollBar { + + /* ECLIPSE { */ + // private static final PointList OUTER_DOWN_TRIANGLE = new PointList(3); + // private static final PointList INNER_DOWN_TRIANGLE = new PointList(3); + // private static final PointList OUTER_UP_TRIANGLE = new PointList(3); + // private static final PointList INNER_UP_TRIANGLE = new PointList(3); + + // public static final int BUTTON_HEIGHT = 7; + /* ECLIPSE } */ + + /* TIZEN: update UI: modify scrolling button's height { */ + public static final int BUTTON_HEIGHT = 10; + // these are figure for image figures + private ArrowButton arrowButtonUp, arrowButtonDown; + /* TIZEN } */ + private static final int BUTTON_WIDTH = 76; + + private static final int SCROLL_TIME = 200; + + private static final Image TRANSPARENCY; + + static { + Display display = Display.getCurrent(); + PaletteData pData = new PaletteData(0xFF, 0xFF00, 0xFF0000); + RGB rgb = display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW) + .getRGB(); + int fillColor = pData.getPixel(rgb); + ImageData iData = new ImageData(1, 1, 24, pData); + iData.setPixel(0, 0, fillColor); + iData.setAlpha(0, 0, 200); + TRANSPARENCY = new Image(display, iData); + + /* ECLIPSE { */ + // OUTER_DOWN_TRIANGLE.addPoint(new Point(34, 2)); + // OUTER_DOWN_TRIANGLE.addPoint(new Point(38, 6)); + // OUTER_DOWN_TRIANGLE.addPoint(new Point(42, 2)); + + // INNER_DOWN_TRIANGLE.addPoint(new Point(35, 2)); + // INNER_DOWN_TRIANGLE.addPoint(new Point(37, 5)); + // INNER_DOWN_TRIANGLE.addPoint(new Point(41, 2)); + + // OUTER_UP_TRIANGLE.addPoint(new Point(33, 5)); + // OUTER_UP_TRIANGLE.addPoint(new Point(38, 0)); + // OUTER_UP_TRIANGLE.addPoint(new Point(42, 5)); + + // INNER_UP_TRIANGLE.addPoint(new Point(34, 5)); + // INNER_UP_TRIANGLE.addPoint(new Point(38, 1)); + // INNER_UP_TRIANGLE.addPoint(new Point(42, 5)); + /* ECLIPSE } */ + } + +// protected Label downLabel; +// +// protected Label upLabel; + + public PaletteScrollBar() { + super(); + } + + public boolean containsPoint(int x, int y) { + return findDescendantAtExcluding(x, y, IdentitySearch.INSTANCE) != null; + } + + protected Clickable createDefaultDownButton() { + arrowButtonDown = new ArrowButton(ArrowButton.DIRECTION_DOWN); + return createTransparentArrowButton(true); + } + + protected Clickable createDefaultUpButton() { + arrowButtonUp = new ArrowButton(ArrowButton.DIRECTION_UP); + return createTransparentArrowButton(false); + } + + /** + * Creates the figure used for the scrollbar button. + * + * @param down + * true if the arrow should be pointing down; false, if it should be pointing up. + * @return a new Toggle figure for the scroll bar button + */ + private Toggle createTransparentArrowButton(final boolean down) { + Toggle button = new Toggle() { + protected void paintFigure(Graphics g) { + // paint background + if (!getModel().isMouseOver()) + g.drawImage(TRANSPARENCY, new Rectangle(0, 0, 1, 1), + getBounds()); + else { + g.setBackgroundColor(getModel().isArmed() ? PaletteColorUtil + .getSelectedColor() : PaletteColorUtil + .getHoverColor()); + g.fillRectangle(getBounds()); + } + + // paint triangle + g.translate(getLocation()); + /* ECLIPSE { */ + // PointList outerPoints = transpose(down ? OUTER_DOWN_TRIANGLE + // : OUTER_UP_TRIANGLE); + // PointList innerPoints = transpose(down ? INNER_DOWN_TRIANGLE + // : INNER_UP_TRIANGLE); + // g.setBackgroundColor(PaletteColorUtil.WIDGET_LIST_BACKGROUND); + // g.fillPolygon(outerPoints); + // g.setBackgroundColor(PaletteColorUtil.WIDGET_DARK_SHADOW); + // g.fillPolygon(innerPoints); + /* ECLIPSE } */ + g.translate(getLocation().getNegated()); + } + }; + + /* TIZEN : The scrollbar's triangle widgets changed into the images { */ + + ArrowButton arrowButton = (down) ? arrowButtonDown : arrowButtonUp; + arrowButton.setPreferredSize(ArrowButton.TRIANGLE_SIZE * 2 + 2, + ArrowButton.TRIANGLE_SIZE); + button.setLayoutManager(new BorderLayout()); + button.add(arrowButton, BorderLayout.CENTER); + arrowButton.setLayout(); + /* TIZEN } */ + button.setRolloverEnabled(true); + button.setRequestFocusEnabled(false); + return button; + } + + /** + * Transposes a list of points using the transposer. + * + * @param origPoints + * the original list of points + * @return a new list of transposed points + */ + /* ECLIPSE { : never used */ + // private PointList transpose(PointList origPoints) { + // PointList transposedPoints = new PointList(origPoints.size()); + // for (int i = 0; i < origPoints.size(); i++) { + // transposedPoints.addPoint(transposer.t(origPoints.getPoint(i))); + // } + // return transposedPoints; + // } + /* ECLIPSE } */ + + public IFigure findFigureAt(int x, int y, TreeSearch search) { + IFigure result = super.findFigureAt(x, y, search); + if (result != this) + return result; + return null; + } + + public Dimension getPreferredSize(int wHint, int hHint) { + return new Dimension(wHint, hHint); + } + + protected void initialize() { + super.initialize(); + setLayoutManager(new ScrollBarLayout(transposer) { + protected Rectangle layoutButtons(ScrollBar scrollBar) { + Rectangle bounds = transposer.t(scrollBar.getClientArea()); + Dimension buttonSize = new Dimension(BUTTON_WIDTH, + BUTTON_HEIGHT); + + getButtonUp().setBounds( + transposer.t(new Rectangle(bounds.getTop() + .getTranslated(-(buttonSize.width / 2), 0), + buttonSize))); + Rectangle r = new Rectangle(bounds.getBottom().getTranslated( + -(buttonSize.width / 2), -buttonSize.height), + buttonSize); + getButtonDown().setBounds(transposer.t(r)); + Rectangle trackBounds = bounds.getCropped(new Insets( + buttonSize.height, 0, buttonSize.height, 0)); + RangeModel model = scrollBar.getRangeModel(); + getButtonUp() + .setVisible(model.getValue() != model.getMinimum()); + getButtonDown().setVisible( + model.getValue() != model.getMaximum() + - model.getExtent()); + return trackBounds; + } + }); + setPageUp(null); + setPageDown(null); + setThumb(null); + setOpaque(false); + } + + protected void stepDown() { + timedStep(false); + } + + protected void stepUp() { + timedStep(true); + } + + protected void timedStep(boolean up) { + int increment = Math.max(getExtent() * 1 / 2, getStepIncrement()); + int value = getValue(); + long startTime = System.currentTimeMillis(); + long elapsedTime = System.currentTimeMillis() - startTime; + while (elapsedTime < SCROLL_TIME) { + int step = (int) (increment * elapsedTime / SCROLL_TIME); + step = up ? value - step : value + step; + setValue(step); + getUpdateManager().performUpdate(); + elapsedTime = System.currentTimeMillis() - startTime; + } + } + +// protected void updateDownLabel() { +// getButtonDown().setVisible(getValue() < (getMaximum() - getExtent())); +// } +// +// protected void updateUpLabel() { +// getButtonUp().setVisible(getValue() > getMinimum()); +// } + + public void dispose() { + if (arrowButtonUp != null) { + getButtonUp().remove(arrowButtonUp); + arrowButtonUp.dispose(); + arrowButtonUp = null; + } + if (arrowButtonDown != null) { + getButtonDown().remove(arrowButtonDown); + arrowButtonDown.dispose(); + arrowButtonDown = null; + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/PaletteStackEditPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/PaletteStackEditPart.java new file mode 100644 index 0000000..1935df3 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/PaletteStackEditPart.java @@ -0,0 +1,416 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-09 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts; + +import java.beans.PropertyChangeEvent; +import java.util.Iterator; + +import org.eclipse.draw2d.ActionEvent; +import org.eclipse.draw2d.ActionListener; +import org.eclipse.draw2d.Border; +import org.eclipse.draw2d.BorderLayout; +import org.eclipse.draw2d.ButtonBorder; +import org.eclipse.draw2d.ButtonModel; +import org.eclipse.draw2d.ChangeEvent; +import org.eclipse.draw2d.ChangeListener; +import org.eclipse.draw2d.Clickable; +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.Figure; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.StackLayout; +import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.RequestConstants; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.swt.events.MenuEvent; +import org.eclipse.swt.events.MenuListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Menu; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteListener; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteStack; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.ToolEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.actions.SetActivePaletteToolAction; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewer; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.editparts.PaletteEditPart; + + +/** + * The EditPart for a PaletteStack to be used on the toolbar. + * + * @author Whitney Sorenson + * @since 3.0 + */ +public class PaletteStackEditPart extends PaletteEditPart implements + IPaletteStackEditPart { + + private static final Dimension EMPTY_DIMENSION = new Dimension(0, 0); + + // listen to changes of clickable tool figure + private ChangeListener clickableListener = new ChangeListener() { + public void handleStateChanged(ChangeEvent event) { + if (event.getPropertyName().equals(ButtonModel.MOUSEOVER_PROPERTY)) + arrowFigure.getModel().setMouseOver( + activeFigure.getModel().isMouseOver()); + else if (event.getPropertyName().equals(ButtonModel.ARMED_PROPERTY)) + arrowFigure.getModel().setArmed( + activeFigure.getModel().isArmed()); + } + }; + + // listen to changes of arrow figure + private ChangeListener clickableArrowListener = new ChangeListener() { + public void handleStateChanged(ChangeEvent event) { + if (event.getPropertyName().equals(ButtonModel.MOUSEOVER_PROPERTY)) + activeFigure.getModel().setMouseOver( + arrowFigure.getModel().isMouseOver()); + if (event.getPropertyName().equals(ButtonModel.ARMED_PROPERTY)) + activeFigure.getModel().setArmed( + arrowFigure.getModel().isArmed()); + } + }; + + // listen to see if arrow is pressed + private ActionListener actionListener = new ActionListener() { + public void actionPerformed(ActionEvent event) { + openMenu(); + } + }; + + // listen to see if active tool is changed in palette + private PaletteListener paletteListener = new PaletteListener() { + public void activeToolChanged(PaletteViewer palette, ToolEntry tool) { + if (getStack().getChildren().contains(tool)) { + if (!arrowFigure.getModel().isSelected()) + arrowFigure.getModel().setSelected(true); + if (!getStack().getActiveEntry().equals(tool)) + getStack().setActiveEntry(tool); + } else + arrowFigure.getModel().setSelected(false); + } + }; + + private Clickable activeFigure; + private RolloverArrow arrowFigure; + private Figure contentsFigure; + private Menu menu; + + /** + * Creates a new PaletteStackEditPart with the given PaletteStack as its model. + * + * @param model + * the PaletteStack to associate with this EditPart. + */ + public PaletteStackEditPart(PaletteStack model) { + super(model); + } + + /** + * @see org.eclipse.gef.EditPart#activate() + */ + public void activate() { + // in case the model is out of sync + checkActiveEntrySync(); + getPaletteViewer().addPaletteListener(paletteListener); + super.activate(); + } + + /** + * Called when the active entry has changed. + * + * @param oldValue + * the old model value (can be null) + * @param newValue + * the new model value (can be null) + */ + private void activeEntryChanged(Object oldValue, Object newValue) { + GraphicalEditPart part = null; + Clickable clickable = null; + + if (newValue != null) { + part = (GraphicalEditPart) getViewer().getEditPartRegistry().get( + newValue); + clickable = (Clickable) part.getFigure(); + clickable.setVisible(true); + clickable.addChangeListener(clickableListener); + activeFigure = clickable; + } else { + activeFigure = null; + } + + if (oldValue != null) { + part = (GraphicalEditPart) getViewer().getEditPartRegistry().get( + oldValue); + // if part is null, its no longer a child. + if (part != null) { + clickable = (Clickable) part.getFigure(); + clickable.setVisible(false); + clickable.removeChangeListener(clickableListener); + } + } + } + + private void checkActiveEntrySync() { + if (activeFigure == null) + activeEntryChanged(null, getStack().getActiveEntry()); + } + + /** + * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure() + */ + public IFigure createFigure() { + + Figure figure = new Figure() { + public Dimension getPreferredSize(int wHint, int hHint) { + if (PaletteStackEditPart.this.getChildren().isEmpty()) + return EMPTY_DIMENSION; + return super.getPreferredSize(wHint, hHint); + } + }; + figure.setLayoutManager(new BorderLayout()); + + contentsFigure = new Figure(); + StackLayout stackLayout = new StackLayout(); + // make it so the stack layout does not allow the invisible figures to + // contribute + // to its bounds + stackLayout.setObserveVisibility(true); + contentsFigure.setLayoutManager(stackLayout); + figure.add(contentsFigure, BorderLayout.CENTER); + + arrowFigure = new RolloverArrow(); + arrowFigure.addChangeListener(clickableArrowListener); + arrowFigure.addActionListener(actionListener); + figure.add(arrowFigure, BorderLayout.RIGHT); + + return figure; + } + + /** + * @see org.eclipse.gef.EditPart#deactivate() + */ + public void deactivate() { + if (activeFigure != null) + activeFigure.removeChangeListener(clickableListener); + arrowFigure.removeActionListener(actionListener); + arrowFigure.removeChangeListener(clickableArrowListener); + getPaletteViewer().removePaletteListener(paletteListener); + super.deactivate(); + } + + /** + * @see org.eclipse.gef.EditPart#eraseTargetFeedback(org.eclipse.gef.Request) + */ + public void eraseTargetFeedback(Request request) { + Iterator children = getChildren().iterator(); + + while (children.hasNext()) { + PaletteEditPart part = (PaletteEditPart) children.next(); + part.eraseTargetFeedback(request); + } + super.eraseTargetFeedback(request); + } + + /** + * @see org.eclipse.gef.GraphicalEditPart#getContentPane() + */ + public IFigure getContentPane() { + return contentsFigure; + } + + private PaletteStack getStack() { + return (PaletteStack) getModel(); + } + + /** + * Opens the menu to display the choices for the active entry. + */ + public void openMenu() { + MenuManager menuManager = new MenuManager(); + + Iterator children = getChildren().iterator(); + PaletteEditPart part = null; + PaletteEntry entry = null; + while (children.hasNext()) { + part = (PaletteEditPart) children.next(); + entry = (PaletteEntry) part.getModel(); + + menuManager + .add(new SetActivePaletteToolAction(getPaletteViewer(), + entry.getLabel(), entry.getSmallIcon(), getStack() + .getActiveEntry().equals(entry), + (ToolEntry) entry)); + } + + menu = menuManager.createContextMenu(getPaletteViewer().getControl()); + + // make the menu open below the figure + Rectangle figureBounds = getFigure().getBounds().getCopy(); + getFigure().translateToAbsolute(figureBounds); + + Point menuLocation = getPaletteViewer().getControl().toDisplay( + figureBounds.getBottomLeft().x, figureBounds.getBottomLeft().y); + + // remove feedback from the arrow Figure and children figures + arrowFigure.getModel().setMouseOver(false); + eraseTargetFeedback(new Request(RequestConstants.REQ_SELECTION)); + + menu.setLocation(menuLocation); + menu.addMenuListener(new StackMenuListener(menu, getViewer() + .getControl().getDisplay())); + menu.setVisible(true); + } + + /** + * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) + */ + public void propertyChange(PropertyChangeEvent event) { + if (event.getPropertyName().equals(PaletteStack.PROPERTY_ACTIVE_ENTRY)) + activeEntryChanged(event.getOldValue(), event.getNewValue()); + else + super.propertyChange(event); + } + + /** + * @see org.eclipse.gef.editparts.AbstractEditPart#refreshChildren() + */ + protected void refreshChildren() { + super.refreshChildren(); + checkActiveEntrySync(); + Iterator children = getChildren().iterator(); + while (children.hasNext()) { + PaletteEditPart editPart = (PaletteEditPart) children.next(); + if (!editPart.getFigure().equals(activeFigure)) + editPart.getFigure().setVisible(false); + } + } + + /** + * @see org.eclipse.gef.EditPart#showTargetFeedback(org.eclipse.gef.Request) + */ + public void showTargetFeedback(Request request) { + // if menu is showing, don't show feedback. this is a fix + // for the occasion when show is called after forced erase + if (menu != null && !menu.isDisposed() && menu.isVisible()) + return; + + Iterator children = getChildren().iterator(); + while (children.hasNext()) { + PaletteEditPart part = (PaletteEditPart) children.next(); + part.showTargetFeedback(request); + } + + super.showTargetFeedback(request); + } + + public PaletteEditPart getActiveEntry() { + return (PaletteEditPart) getViewer().getEditPartRegistry().get( + getStack().getActiveEntry()); + } + +} + + +class StackMenuListener implements MenuListener { + + private Menu menu; + private Display d; + + /** + * Creates a new listener to listen to the menu that it used to select the active tool on a + * stack. Disposes the stack with an asyncExec after hidden is called. + */ + StackMenuListener(Menu menu, Display d) { + this.menu = menu; + this.d = d; + } + + /** + * @see org.eclipse.swt.events.MenuListener#menuShown(org.eclipse.swt.events.MenuEvent) + */ + public void menuShown(MenuEvent e) { + } + + /** + * @see org.eclipse.swt.events.MenuListener#menuHidden(org.eclipse.swt.events.MenuEvent) + */ + public void menuHidden(MenuEvent e) { + d.asyncExec(new Runnable() { + public void run() { + if (menu != null) { + if (!menu.isDisposed()) + menu.dispose(); + menu = null; + } + } + }); + } + +} + + +class RolloverArrow extends Clickable { + + private static final Border BORDER_TOGGLE = new ButtonBorder( + ButtonBorder.SCHEMES.TOOLBAR); + + /** + * Creates a new Clickable that paints a triangle figure. + */ + RolloverArrow() { + super(); + setRolloverEnabled(true); + setBorder(BORDER_TOGGLE); + setBackgroundColor(ColorConstants.black); + setOpaque(false); + setPreferredSize(11, -1); + } + + /** + * @return false so that the focus rectangle is not drawn. + */ + public boolean hasFocus() { + return false; + } + + public void paintFigure(Graphics graphics) { + Rectangle rect = getClientArea(); + + graphics.translate(getLocation()); + + // fill the arrow + int[] points = new int[8]; + + points[0] = 3; + points[1] = rect.height / 2; + points[2] = 8; + points[3] = rect.height / 2; + points[4] = 5; + points[5] = 3 + rect.height / 2; + points[6] = 3; + points[7] = rect.height / 2; + + graphics.fillPolygon(points); + + graphics.translate(getLocation().getNegated()); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/PinFigure.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/PinFigure.java new file mode 100644 index 0000000..2a5d63b --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/PinFigure.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2008, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-09 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts; + +import org.eclipse.draw2d.Border; +import org.eclipse.draw2d.ButtonModel; +import org.eclipse.draw2d.ChangeEvent; +import org.eclipse.draw2d.ChangeListener; +import org.eclipse.draw2d.FigureUtilities; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.ImageFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.MarginBorder; +import org.eclipse.draw2d.Toggle; +import org.eclipse.gef.internal.InternalImages; +import org.eclipse.gef.internal.ui.palette.PaletteColorUtil; +import org.eclipse.gef.ui.palette.PaletteMessages; +import org.eclipse.swt.graphics.Color; + + +/** + * This is the figure for the pinned and unpinned toggle. + * + * @author crevells + * @since 3.4 + */ +public class PinFigure extends Toggle { + + private static final Color PIN_HOTSPOT_COLOR = FigureUtilities.mixColors( + PaletteColorUtil.WIDGET_LIST_BACKGROUND, + PaletteColorUtil.WIDGET_NORMAL_SHADOW, 0.60); + + private static final Border TOOLTIP_BORDER = new MarginBorder(0, 2, 1, 0); + + public PinFigure() { + super(new ImageFigure(InternalImages.get(InternalImages.IMG_UNPINNED))); + setRolloverEnabled(true); + setRequestFocusEnabled(false); + Label tooltip = new Label(PaletteMessages.TOOLTIP_PIN_FIGURE); + tooltip.setBorder(TOOLTIP_BORDER); + setToolTip(tooltip); + setOpaque(false); + + addChangeListener(new ChangeListener() { + + public void handleStateChanged(ChangeEvent e) { + if (e.getPropertyName().equals(ButtonModel.SELECTED_PROPERTY)) { + if (isSelected()) { + ((ImageFigure) (getChildren().get(0))) + .setImage(InternalImages + .get(InternalImages.IMG_PINNED)); + ((Label) getToolTip()) + .setText(PaletteMessages.TOOLTIP_UNPIN_FIGURE); + } else { + ((ImageFigure) (getChildren().get(0))) + .setImage(InternalImages + .get(InternalImages.IMG_UNPINNED)); + ((Label) getToolTip()) + .setText(PaletteMessages.TOOLTIP_PIN_FIGURE); + } + } + } + }); + } + + protected void paintFigure(Graphics graphics) { + super.paintFigure(graphics); + + ButtonModel model = getModel(); + if (isRolloverEnabled() && model.isMouseOver()) { + graphics.setBackgroundColor(PIN_HOTSPOT_COLOR); + graphics.fillRoundRectangle(getClientArea().getCopy().shrink(1, 1), + 3, 3); + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/PinnablePaletteStackEditPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/PinnablePaletteStackEditPart.java new file mode 100644 index 0000000..4196ed8 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/PinnablePaletteStackEditPart.java @@ -0,0 +1,237 @@ +/******************************************************************************* + * Copyright (c) 2008, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-09 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts; + +import java.beans.PropertyChangeEvent; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.Request; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteListener; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteStack; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.ToolEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewer; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.editparts.IPinnableEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.editparts.PaletteEditPart; + + +/** + * The EditPart for a pinnable PaletteStack to be used in a drawer or group. Some of this code has + * been take from PaletteStackEditPart, but they are significantly different to warrant + * two editpart classes. + * + * @author Whitney Sorenson, crevells + * @since 3.4 + */ +public class PinnablePaletteStackEditPart extends PaletteEditPart implements + IPaletteStackEditPart, IPinnableEditPart { + + // listen to see if active tool is changed in the palette + private PaletteListener paletteListener = new PaletteListener() { + + public void activeToolChanged(PaletteViewer palette, ToolEntry tool) { + if (!getStackFigure().isPinnedOpen() + && getStack().getChildren().contains(tool)) { + if (!getStack().getActiveEntry().equals(tool)) { + getStack().setActiveEntry(tool); + } + } + if (!getStackFigure().isPinnedOpen()) { + getStackFigure().setExpanded(false); + } + } + }; + + /** + * Creates a new PaletteStackEditPart with the given PaletteStack as its model. + * + * @param model + * the PaletteStack to associate with this EditPart. + */ + public PinnablePaletteStackEditPart(PaletteStack model) { + super(model); + } + + /** + * @see org.eclipse.gef.EditPart#activate() + */ + public void activate() { + // in case the model is out of sync + checkActiveEntrySync(); + getPaletteViewer().addPaletteListener(paletteListener); + super.activate(); + } + + /** + * Called when the active entry has changed. + * + * @param oldValue + * the old model value (can be null) + * @param newValue + * the new model value (can be null) + */ + private void activeEntryChanged(Object oldValue, Object newValue) { + GraphicalEditPart part = null; + IFigure oldFigure = null; + IFigure newFigure = null; + int index = -1; + + if (oldValue != null) { + part = (GraphicalEditPart) getViewer().getEditPartRegistry().get( + oldValue); + // if part is null, its no longer a child. + if (part != null) { + oldFigure = part.getFigure(); + + // preserve the original order of the palette stack children + index = getModelChildren().indexOf(part.getModel()); + } + } + + if (newValue != null) { + part = (GraphicalEditPart) getViewer().getEditPartRegistry().get( + newValue); + newFigure = part.getFigure(); + } + + getStackFigure().activeEntryChanged(oldFigure, index, newFigure); + } + + private void checkActiveEntrySync() { + if (getStackFigure().getActiveFigure() == null) + activeEntryChanged(null, getStack().getActiveEntry()); + } + + public IFigure createFigure() { + return new PinnablePaletteStackFigure(); + } + + private PinnablePaletteStackFigure getStackFigure() { + return (PinnablePaletteStackFigure) getFigure(); + } + + public void deactivate() { + getPaletteViewer().removePaletteListener(paletteListener); + super.deactivate(); + } + + public void eraseTargetFeedback(Request request) { + Iterator children = getChildren().iterator(); + + while (children.hasNext()) { + PaletteEditPart part = (PaletteEditPart) children.next(); + part.eraseTargetFeedback(request); + } + super.eraseTargetFeedback(request); + } + + public IFigure getContentPane() { + // not completely accurate, but is there any other way? + return getStackFigure().getContentPane(); + } + + protected void removeChildVisual(EditPart childEditPart) { + IFigure child = ((GraphicalEditPart) childEditPart).getFigure(); + getStackFigure().getContentPane(child).remove(child); + } + + protected void addChild(EditPart childEP, int index) { + index = updateIndexBasedOnActiveFigure(index, childEP); + super.addChild(childEP, index); + } + + protected void reorderChild(EditPart childEP, int index) { + IFigure childFigure = ((GraphicalEditPart) childEP).getFigure(); + if (childFigure == getStackFigure().getActiveFigure()) { + // no need to reorder figures if this is the active figure + List children = getChildren(); + children.remove(childEP); + children.add(index, childEP); + } else { + removeChildVisual(childEP); + List children = getChildren(); + children.remove(childEP); + children.add(index, childEP); + index = updateIndexBasedOnActiveFigure(index, childEP); + addChildVisual(childEP, index); + } + } + + private int updateIndexBasedOnActiveFigure(int index, EditPart childEP) { + for (int i = 0; i < index; i++) { + Object ep = getChildren().get(i); + if (((GraphicalEditPart) ep).getFigure() == getStackFigure() + .getActiveFigure()) { + return index - 1; + } + } + return index; + } + + private PaletteStack getStack() { + return (PaletteStack) getModel(); + } + + public void propertyChange(PropertyChangeEvent event) { + if (event.getPropertyName().equals(PaletteStack.PROPERTY_ACTIVE_ENTRY)) + activeEntryChanged(event.getOldValue(), event.getNewValue()); + else + super.propertyChange(event); + } + + protected void refreshChildren() { + super.refreshChildren(); + checkActiveEntrySync(); + } + + protected void refreshVisuals() { + getStackFigure().setLayoutMode(getLayoutSetting()); + } + + public void openMenu() { + setExpanded(true); + } + + public void setExpanded(boolean value) { + getStackFigure().setExpanded(value); + } + + public boolean isExpanded() { + return getStackFigure().isExpanded(); + } + + public boolean canBePinned() { + return isExpanded(); + } + + public boolean isPinnedOpen() { + return getStackFigure().isPinnedOpen(); + } + + public void setPinnedOpen(boolean pinned) { + getStackFigure().setPinned(pinned); + } + + public PaletteEditPart getActiveEntry() { + return (PaletteEditPart) getViewer().getEditPartRegistry().get( + getStack().getActiveEntry()); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/PinnablePaletteStackFigure.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/PinnablePaletteStackFigure.java new file mode 100644 index 0000000..17c5db3 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/PinnablePaletteStackFigure.java @@ -0,0 +1,604 @@ +/******************************************************************************* + * Copyright (c) 2008, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-09 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts; + +import java.util.Iterator; + +import org.eclipse.draw2d.AbstractLayout; +import org.eclipse.draw2d.Animation; +import org.eclipse.draw2d.BorderLayout; +import org.eclipse.draw2d.ButtonModel; +import org.eclipse.draw2d.ChangeEvent; +import org.eclipse.draw2d.ChangeListener; +import org.eclipse.draw2d.Clickable; +import org.eclipse.draw2d.Figure; +import org.eclipse.draw2d.FlowLayout; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.MarginBorder; +import org.eclipse.draw2d.StackLayout; +import org.eclipse.draw2d.Toggle; +import org.eclipse.draw2d.ToolbarLayout; +import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.PointList; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.internal.ui.palette.PaletteColorUtil; +import org.eclipse.gef.ui.palette.PaletteViewerPreferences; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.ToolEntryEditPart.ToolEntryToggle; + + +/** + * A pinnable palette stack figure. + * + * @author crevells + * @since 3.4 + */ +public class PinnablePaletteStackFigure extends Figure { + + private static final Dimension EMPTY_DIMENSION = new Dimension(0, 0); + + static final int ARROW_WIDTH = 9; + + /** + * A toggle with a triangle figure. + */ + class RolloverArrow extends Toggle { + + RolloverArrow() { + super(); + setRolloverEnabled(true); + setBorder(null); + setOpaque(false); + setPreferredSize(ARROW_WIDTH, -1); + } + + /** + * @return false so that the focus rectangle is not drawn. + */ + public boolean hasFocus() { + return false; + } + + public void paintFigure(Graphics graphics) { + Rectangle rect = getClientArea(); + + ButtonModel model = getModel(); + if (isRolloverEnabled() && model.isMouseOver()) { + graphics.setBackgroundColor(PaletteColorUtil.ARROW_HOVER); + graphics.fillRoundRectangle(rect, 3, 3); + } + + graphics.translate(getLocation()); + + // fill the arrow + int[] points = new int[8]; + + int middleY = rect.height / 2; + if (isSelected() + || layoutMode == PaletteViewerPreferences.LAYOUT_ICONS + || layoutMode == PaletteViewerPreferences.LAYOUT_COLUMNS) { + // pointing down + int startingX = (ARROW_WIDTH - 5) / 2; // triangle width = 5 + points[0] = startingX; + points[1] = middleY; + points[2] = startingX + 5; + points[3] = middleY; + points[4] = startingX + 2; + points[5] = middleY + 3; + points[6] = startingX; + points[7] = middleY; + } else { + // pointing to the right + int startingX = (ARROW_WIDTH - 3) / 2; // triangle width = 3 + points[0] = startingX; + points[1] = middleY - 2; + points[2] = startingX + 3; + points[3] = middleY + 1; + points[4] = startingX; + points[5] = middleY + 4; + points[6] = startingX; + points[7] = middleY - 2; + } + + graphics.setBackgroundColor(PaletteColorUtil.WIDGET_DARK_SHADOW); + graphics.fillPolygon(points); + + graphics.translate(getLocation().getNegated()); + } + } + + /** + * Layout manager for the palette stack header figure that handles the layout of the + * headerFigure (arrowFigure and the active tool figure) when in icons + * or columns layout mode. + */ + private class HeaderIconLayout extends StackLayout { + + protected boolean isSensitiveVertically(IFigure container) { + return false; + } + + public void layout(IFigure parent) { + + Rectangle r = parent.getClientArea(); + + if (activeToolFigure != null) { + activeToolFigure.setBounds(r); + } + + // All tool figures have saved an area in its margin for the arrow + // figure in + // case that tool figure is in a stack (see the BORDER variables in + // ToolEntryEditPart). Calculate the arrow figure bounds by using + // the insets + // of the active tool figure. + r.x = r.right() - ToolEntryEditPart.ICON_HIGHLIGHT_INSETS.right + - ARROW_WIDTH; + r.y += ToolEntryEditPart.ICON_HIGHLIGHT_INSETS.top; + r.width = ARROW_WIDTH; + r.height -= ToolEntryEditPart.ICON_HIGHLIGHT_INSETS.getHeight(); + arrowFigure.setBounds(r); + } + } + + /** + * Layout manager for the palette stack header figure that handles the layout of the + * headerFigure (pinFigure, arrowFigure, and the active + * tool figure) when in list or details layout mode. + */ + private class HeaderListLayout extends StackLayout { + + protected boolean isSensitiveVertically(IFigure container) { + return false; + } + + protected Dimension calculatePreferredSize(IFigure parent, int wHint, + int hHint) { + if (isExpanded()) { + Dimension pinSize = pinFigure.getSize(); + Dimension preferredSize = super.calculatePreferredSize(parent, + wHint - pinSize.width, hHint); + preferredSize.width += pinSize.width; + return preferredSize; + } else { + return super.calculatePreferredSize(parent, wHint, hHint); + } + } + + public void layout(IFigure parent) { + + Rectangle r = parent.getClientArea(); + Dimension pinSize = isExpanded() ? pinFigure.getPreferredSize() + : EMPTY_DIMENSION; + + // layout the pin figure + Rectangle.SINGLETON.setSize(pinSize); + Rectangle.SINGLETON.setLocation(r.right() - pinSize.width, + r.getCenter().y - (pinSize.height / 2)); + pinFigure.setBounds(Rectangle.SINGLETON); + + if (activeToolFigure != null) { + activeToolFigure.setBounds(r.getResized(-pinSize.width, 0)); + } + + // All tool figures have saved an area in its margin for the arrow + // figure in + // case that tool figure is in a stack (see the BORDER variables in + // ToolEntryEditPart). Calculate the arrow figure bounds by using + // the insets + // of the active tool figure. + r.x += ToolEntryEditPart.LIST_HIGHLIGHT_INSETS.left; + r.y += ToolEntryEditPart.LIST_HIGHLIGHT_INSETS.top; + r.width = ARROW_WIDTH; + r.height -= ToolEntryEditPart.LIST_HIGHLIGHT_INSETS.getHeight(); + arrowFigure.setBounds(r); + + } + } + + /** + * Layout manager for the palette stack figure that handles the layout of the + * headerFigure, expandablePane, and pinFigure when in + * icons or columns layout mode. + */ + private class PaletteStackIconLayout extends AbstractLayout { + + protected Dimension calculatePreferredSize(IFigure parent, int wHint, + int hHint) { + return parent.getSize(); + } + + public void layout(IFigure parent) { + if (isExpanded()) { + headerFigure.setBounds(headerBoundsLayoutHint); + + Rectangle paneBounds = parent.getClientArea(); + paneBounds.y += headerBoundsLayoutHint.height; + paneBounds.height -= headerBoundsLayoutHint.height; + expandablePane.setBounds(paneBounds); + + Rectangle pinBounds = Rectangle.SINGLETON; + Dimension pinSize = pinFigure.getPreferredSize(); + pinBounds.setSize(pinSize); + int pinFigureAreaHeight = expandablePane.getInsets().top; + pinBounds.setLocation(expandablePane.getClientArea().right() + - pinSize.width, + (paneBounds.y + pinFigureAreaHeight / 2) + - (pinSize.height / 2)); + pinFigure.setBounds(pinBounds); + } else { + headerFigure.setBounds(parent.getClientArea()); + } + } + } + + /** + * listens to selection events on the arrow figure + */ + private ChangeListener clickableArrowListener = new ChangeListener() { + + public void handleStateChanged(ChangeEvent event) { + Clickable clickable = (Clickable) event.getSource(); + if (event.getPropertyName() == ButtonModel.MOUSEOVER_PROPERTY + && getActiveFigure() instanceof ToolEntryToggle) { + ((ToolEntryToggle) getActiveFigure()) + .setShowHoverFeedback(clickable.getModel() + .isMouseOver()); + } + if (event.getPropertyName() == ButtonModel.SELECTED_PROPERTY) { + + Animation.markBegin(); + handleExpandStateChanged(); + Animation.run(150); + + // Now collapse other stacks when they are not pinned open or in + // the + // case of columns and icons layout mode (where only one stack + // can + // be expanded at a time for layout reasons). + if (isExpanded()) { + boolean collapseOtherStacks = + (layoutMode == PaletteViewerPreferences.LAYOUT_COLUMNS || layoutMode == PaletteViewerPreferences.LAYOUT_ICONS); + + for (Iterator iterator = getParent().getChildren() + .iterator(); iterator.hasNext();) { + Object childFigure = iterator.next(); + if (childFigure instanceof PinnablePaletteStackFigure + && childFigure != PinnablePaletteStackFigure.this) { + + if (collapseOtherStacks + || (((PinnablePaletteStackFigure) childFigure) + .isExpanded() && !((PinnablePaletteStackFigure) childFigure) + .isPinnedOpen())) { + + ((PinnablePaletteStackFigure) childFigure) + .setExpanded(false); + } + } + } + } + } + } + }; + + private IFigure headerFigure; + + private IFigure activeToolFigure; + + private PinFigure pinFigure; + + private RolloverArrow arrowFigure; + + private IFigure expandablePane; + + private int layoutMode = -1; + + private Rectangle headerBoundsLayoutHint = new Rectangle(); + + public PinnablePaletteStackFigure() { + super(); + + arrowFigure = new RolloverArrow(); + arrowFigure.addChangeListener(clickableArrowListener); + + headerFigure = new Figure(); + headerFigure.add(arrowFigure); + + pinFigure = new PinFigure(); + pinFigure.setBorder(new MarginBorder(0, 0, 0, 2)); + + expandablePane = new Figure(); + + add(headerFigure); + } + + protected void paintFigure(Graphics g) { + super.paintFigure(g); + + if (!isExpanded()) { + return; + } + + Rectangle headerBounds = headerFigure.getBounds().getCopy(); + Rectangle paneBounds = expandablePane.getClientArea(); + + // fill expandable pane background + g.setBackgroundColor(PaletteColorUtil.WIDGET_BACKGROUND_LIST_BACKGROUND_40); + g.fillRectangle(paneBounds); + + if (layoutMode == PaletteViewerPreferences.LAYOUT_ICONS + || layoutMode == PaletteViewerPreferences.LAYOUT_COLUMNS) { + + int pinHeight = expandablePane.getInsets().top; + Rectangle pinAreaBounds = new Rectangle(paneBounds.x, + expandablePane.getBounds().y, paneBounds.width, pinHeight); + + // fill background colors + g.setForegroundColor(PaletteColorUtil.WIDGET_BACKGROUND_LIST_BACKGROUND_40); + g.setBackgroundColor(PaletteColorUtil.WIDGET_BACKGROUND_LIST_BACKGROUND_85); + g.fillGradient(headerBounds, true); + + g.setBackgroundColor(PaletteColorUtil.WIDGET_BACKGROUND_LIST_BACKGROUND_85); + g.fillRectangle(pinAreaBounds); + + // draw white lines + g.setForegroundColor(PaletteColorUtil.WIDGET_LIST_BACKGROUND); + g.drawLine(headerBounds.getTopLeft().getTranslated(1, 1), + headerBounds.getTopRight().getTranslated(-1, 1)); + g.drawLine(headerBounds.getBottomLeft().getTranslated(1, 0), + headerBounds.getTopLeft().getTranslated(1, 1)); + g.drawLine(headerBounds.getBottomRight().getTranslated(-2, 0), + headerBounds.getTopRight().getTranslated(-2, 1)); + + g.drawLine(pinAreaBounds.getTopLeft().getTranslated(0, 1), + pinAreaBounds.getTopRight().getTranslated(-1, 1)); + g.drawLine(pinAreaBounds.getBottomLeft().getTranslated(0, -2), + pinAreaBounds.getBottomRight().getTranslated(-1, -2)); + + // draw grey border around the whole palette stack + PointList points = new PointList(); + points.addPoint(headerBounds.getBottomLeft()); + points.addPoint(headerBounds.getTopLeft().getTranslated(0, 2)); + points.addPoint(headerBounds.getTopLeft().getTranslated(1, 1)); + points.addPoint(headerBounds.getTopLeft().getTranslated(2, 0)); + points.addPoint(headerBounds.getTopRight().getTranslated(-3, 0)); + points.addPoint(headerBounds.getTopRight().getTranslated(-2, 1)); + points.addPoint(headerBounds.getTopRight().getTranslated(-1, 2)); + points.addPoint(headerBounds.getBottomRight().getTranslated(-1, 0)); + points.addPoint(pinAreaBounds.getTopRight().getTranslated(-1, 0)); + points.addPoint(paneBounds.getBottomRight().getTranslated(-1, -1)); + points.addPoint(paneBounds.getBottomLeft().getTranslated(0, -1)); + points.addPoint(pinAreaBounds.getTopLeft().getTranslated(0, 0)); + points.addPoint(headerBounds.getBottomLeft()); + + g.setForegroundColor(PaletteColorUtil.WIDGET_BACKGROUND_NORMAL_SHADOW_40); + g.drawPolygon(points); + + g.setForegroundColor(PaletteColorUtil.WIDGET_BACKGROUND_NORMAL_SHADOW_80); + Point pt = headerBounds.getTopLeft().getTranslated(0, 1); + g.drawPoint(pt.x, pt.y); + pt = headerBounds.getTopLeft().getTranslated(1, 0); + g.drawPoint(pt.x, pt.y); + pt = headerBounds.getTopRight().getTranslated(-2, 0); + g.drawPoint(pt.x, pt.y); + pt = headerBounds.getTopRight().getTranslated(-1, 1); + g.drawPoint(pt.x, pt.y); + } else { + + // fill header background + g.setBackgroundColor(PaletteColorUtil.WIDGET_BACKGROUND_LIST_BACKGROUND_85); + g.fillRectangle(headerBounds); + + // draw top and bottom border lines of header figure + g.setForegroundColor(PaletteColorUtil.WIDGET_BACKGROUND_NORMAL_SHADOW_65); + g.drawLine(headerBounds.getTopLeft(), headerBounds.getTopRight()); + g.setForegroundColor(PaletteColorUtil.WIDGET_LIST_BACKGROUND); + g.drawLine(headerBounds.getBottomLeft().getTranslated(0, -2), + headerBounds.getBottomRight().getTranslated(0, -2)); + + // draw bottom border line of expandable pane + g.setForegroundColor(PaletteColorUtil.WIDGET_BACKGROUND_NORMAL_SHADOW_65); + g.drawLine(paneBounds.getBottomLeft().getTranslated(0, -1), + paneBounds.getBottomRight().getTranslated(0, -1)); + } + + } + + /** + * @return The content pane for this figure, i.e. the Figure to which children can be added. + */ + public IFigure getContentPane(IFigure figure) { + if (figure == activeToolFigure) { + return headerFigure; + } + return getContentPane(); + } + + public IFigure getContentPane() { + return expandablePane; + } + + public IFigure getActiveFigure() { + return activeToolFigure; + } + + /** + * @return true if the palette stack is expanded + */ + public boolean isExpanded() { + return arrowFigure.getModel().isSelected(); + } + + /** + * @return true if the palette stack is expanded and is pinned (i.e., it can't be + * automatically collapsed) + */ + public boolean isPinnedOpen() { + return isExpanded() && pinFigure.getModel().isSelected(); + } + + /** + * Pins or unpins the stack. The stack can be pinned open only when it is expanded. Attempts to + * pin it when it is collapsed will do nothing. + * + * @param pinned + * true if the stack is to be pinned + */ + public void setPinned(boolean pinned) { + if (isExpanded()) { + pinFigure.setSelected(pinned); + } + } + + public void setExpanded(boolean value) { + arrowFigure.setSelected(value); + if (!value) { + pinFigure.setSelected(false); + } + } + + public void setLayoutMode(int newLayoutMode) { + if (this.layoutMode == newLayoutMode) { + return; + } + + this.layoutMode = newLayoutMode; + + // Only one stack can be expanded in icons and layout mode, therefore + // for + // consistency let's always collapse stacks when changing the layout + // modes. + setExpanded(false); + + if (newLayoutMode == PaletteViewerPreferences.LAYOUT_LIST + || newLayoutMode == PaletteViewerPreferences.LAYOUT_DETAILS) { + + headerFigure.setLayoutManager(new HeaderListLayout()); + + expandablePane.setLayoutManager(new ToolbarLayout()); + expandablePane.setBorder(new MarginBorder(1, 0, 1, 0)); + setLayoutManager(new ToolbarLayout()); + + } else { + headerFigure.setLayoutManager(new HeaderIconLayout()); + if (activeToolFigure != null) { + headerFigure.setConstraint(activeToolFigure, + BorderLayout.CENTER); + } + + setLayoutManager(new PaletteStackIconLayout()); + + // account for space used by pin figure + expandablePane.setBorder(new MarginBorder(18, 0, 0, 0)); + + if (layoutMode == PaletteViewerPreferences.LAYOUT_COLUMNS) { + expandablePane.setLayoutManager(new ColumnsLayout()); + } else { // LAYOUT_ICONS + FlowLayout fl = new FlowLayout(); + fl.setMinorSpacing(0); + fl.setMajorSpacing(0); + expandablePane.setLayoutManager(fl); + } + } + } + + public void activeEntryChanged(IFigure oldFigure, int oldFigureIndex, + IFigure newFigure) { + + if (oldFigure != null) { + // if figure is null, its no longer a child. + expandablePane.add(oldFigure, oldFigureIndex); + } + + if (newFigure != null) { + activeToolFigure = newFigure; + headerFigure.add(activeToolFigure, BorderLayout.CENTER, 0); + } else { + activeToolFigure = null; + } + } + + private void handleExpandStateChanged() { + if (isExpanded()) { + if (expandablePane.getParent() != this) { + add(expandablePane); + + if (layoutMode == PaletteViewerPreferences.LAYOUT_LIST + || layoutMode == PaletteViewerPreferences.LAYOUT_DETAILS) { + headerFigure.add(pinFigure); + } else { + add(pinFigure); + } + } + } else { + if (expandablePane.getParent() == this) { + remove(expandablePane); + pinFigure.getParent().remove(pinFigure); + } + } + } + + /** + * Gets the preferred size of the expandable pane figure. Used by + * PaletteContainerFlowLayout when the layout is icons or columns mode. + * + * @param wHint + * width hint + * @param hHint + * height hint + * @return the preferred size of the expandable pane figure or (0,0) if the pane is collapsed + */ + public Dimension getExpandedContainerPreferredSize(int wHint, int hHint) { + if (isExpanded()) { + return expandablePane.getPreferredSize(wHint, hHint); + } else { + return EMPTY_DIMENSION; + } + } + + /** + * Sets the header bounds layout hint. Set by PaletteContainerFlowLayout when the + * layout is icons or columns mode and used by PaletteStackIconLayout. + * + * @param rect + * the new value + */ + public void setHeaderBoundsLayoutHint(Rectangle rect) { + headerBoundsLayoutHint.setBounds(rect); + } + + /** + * Gets the preferred size of the header figure. Used by PaletteContainerFlowLayout + * and ColumnsLayout when the layout is icons or columns mode. + * + * @param wHint + * width hint + * @param hHint + * height hint + * @return the preferred size of the header figure + */ + public Dimension getHeaderPreferredSize(int wHint, int hHint) { + return headerFigure.getPreferredSize(wHint, hHint); + } + + public boolean containsPoint(int x, int y) { + return headerFigure.containsPoint(x, y) + || (isExpanded() && expandablePane.containsPoint(x, y)); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/RaisedBorder.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/RaisedBorder.java new file mode 100644 index 0000000..e1296d5 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/RaisedBorder.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-09 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts; + +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.MarginBorder; +import org.eclipse.draw2d.geometry.Insets; +import org.eclipse.draw2d.geometry.Rectangle; + + +/** + * @author Pratik Shah + */ +public class RaisedBorder extends MarginBorder { + + private static final Insets DEFAULT_INSETS = new Insets(1, 1, 1, 1); + + /** + * @see org.eclipse.draw2d.Border#getInsets(IFigure) + */ + public Insets getInsets(IFigure figure) { + return insets; + } + + public RaisedBorder() { + this(DEFAULT_INSETS); + } + + public RaisedBorder(Insets insets) { + super(insets); + } + + public RaisedBorder(int t, int l, int b, int r) { + super(t, l, b, r); + } + + public boolean isOpaque() { + return true; + } + + /** + * @see org.eclipse.draw2d.Border#paint(IFigure, Graphics, Insets) + */ + public void paint(IFigure figure, Graphics g, Insets insets) { + g.setLineStyle(Graphics.LINE_SOLID); + g.setLineWidth(1); + g.setForegroundColor(ColorConstants.buttonLightest); + Rectangle r = getPaintRectangle(figure, insets); + r.resize(-1, -1); + g.drawLine(r.x, r.y, r.right(), r.y); + g.drawLine(r.x, r.y, r.x, r.bottom()); + g.setForegroundColor(ColorConstants.buttonDarker); + g.drawLine(r.x, r.bottom(), r.right(), r.bottom()); + g.drawLine(r.right(), r.y, r.right(), r.bottom()); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/SeparatorBorder.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/SeparatorBorder.java new file mode 100644 index 0000000..205b2ad --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/SeparatorBorder.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-09 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts; + +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.MarginBorder; +import org.eclipse.draw2d.geometry.Insets; +import org.eclipse.draw2d.geometry.Rectangle; + + +final class SeparatorBorder extends MarginBorder { + + SeparatorBorder(int t, int l, int b, int r) { + super(t, l, b, r); + } + + public void paint(IFigure f, Graphics g, Insets i) { + Rectangle r = getPaintRectangle(f, i); + r.height--; + g.setForegroundColor(ColorConstants.buttonDarker); + g.drawLine(r.x, r.bottom(), r.right(), r.bottom()); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/SeparatorEditPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/SeparatorEditPart.java new file mode 100644 index 0000000..6e8ab70 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/SeparatorEditPart.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-09 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts; + +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.Figure; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.draw2d.geometry.Insets; +import org.eclipse.draw2d.geometry.Rectangle; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.PaletteColorUtil; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteSeparator; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.editparts.PaletteEditPart; + + +/** + * EditPart for the PaletteSeparator + * + * @author Pratik Shah + */ +public class SeparatorEditPart extends PaletteEditPart { + + /** + * Constructor + * + * @param separator + * The PaletteSeparator for which this EditPart is being created + */ + public SeparatorEditPart(PaletteSeparator separator) { + super(separator); + } + + /** + * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure() + */ + protected IFigure createFigure() { + return new SeparatorFigure(); + } + + /** + * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#getToolTipText() + */ + protected String getToolTipText() { + return null; + } + + /** + * Figure for the separator + * + * @author Pratik Shah + */ + static class SeparatorFigure extends Figure { + /** + * @see org.eclipse.draw2d.IFigure#getPreferredSize(int, int) + */ + public Dimension getPreferredSize(int wHint, int hHint) { + if (getBackgroundColor().equals(PaletteColorUtil.WIDGET_BACKGROUND)) + return new Dimension(wHint, 4); + return new Dimension(wHint, 5); + } + + private static final Insets CROP = new Insets(1, 3, 2, 4); + + /** + * + * @see org.eclipse.draw2d.Figure#paintFigure(Graphics) + */ + protected void paintFigure(Graphics g) { + Rectangle r = getBounds().getCropped(CROP); + if (getBackgroundColor().equals( + PaletteColorUtil.WIDGET_LIST_BACKGROUND)) { + g.setForegroundColor(PaletteColorUtil.WIDGET_NORMAL_SHADOW); + g.drawLine(r.getLeft(), r.getRight()); + } else { + g.setForegroundColor(PaletteColorUtil.WIDGET_NORMAL_SHADOW); + g.drawLine(r.getBottomLeft(), r.getTopLeft()); + g.drawLine(r.getTopLeft(), r.getTopRight()); + + g.setForegroundColor(ColorConstants.buttonLightest); + g.drawLine(r.getBottomLeft(), r.getBottomRight()); + g.drawLine(r.getBottomRight(), r.getTopRight()); + } + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/SliderPaletteEditPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/SliderPaletteEditPart.java new file mode 100644 index 0000000..a463053 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/SliderPaletteEditPart.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-09 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts; + +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.Figure; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.ToolbarLayout; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteRoot; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewer; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.editparts.PaletteAnimator; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.editparts.PaletteEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.editparts.PaletteToolbarLayout; + + +public class SliderPaletteEditPart extends PaletteEditPart { + + private PaletteAnimator controller; + + public SliderPaletteEditPart(PaletteRoot paletteRoot) { + super(paletteRoot); + } + + public IFigure createFigure() { + Figure figure = new Figure(); + figure.setOpaque(true); + figure.setForegroundColor(ColorConstants.listForeground); + figure.setBackgroundColor(ColorConstants.listBackground); + return figure; + } + + /** + * This method overrides super's functionality to do nothing. + * + * @see PaletteEditPart#refreshVisuals() + */ + protected void refreshVisuals() { + } + + /** + * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#registerVisuals() + */ + protected void registerVisuals() { + super.registerVisuals(); + controller = new PaletteAnimator( + ((PaletteViewer) getViewer()).getPaletteViewerPreferences()); + getViewer().getEditPartRegistry() + .put(PaletteAnimator.class, controller); + ToolbarLayout layout = new PaletteToolbarLayout(); + getFigure().setLayoutManager(layout); + getFigure().addLayoutListener(controller); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/TemplateEditPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/TemplateEditPart.java new file mode 100644 index 0000000..b0f3380 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/TemplateEditPart.java @@ -0,0 +1,206 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-09 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts; + +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.IFigure; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.DragTracker; +import org.eclipse.gef.Request; +import org.eclipse.swt.accessibility.ACC; +import org.eclipse.swt.accessibility.AccessibleControlEvent; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.IMemento; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.PaletteColorUtil; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteTemplateEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewerPreferences; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.editparts.PaletteEditPart; + + +/** + * @author Eric Bordeau, Pratik Shah + */ +public class TemplateEditPart extends PaletteEditPart { + + private static final String SELECTION_STATE = "selection"; //$NON-NLS-1$ + + /** + * Constructor + * + * @param entry + * The model entry + */ + public TemplateEditPart(PaletteTemplateEntry entry) { + super(entry); + } + + /** + * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#createAccessible() + */ + protected AccessibleEditPart createAccessible() { + return new AccessibleGraphicalEditPart() { + public void getDescription(AccessibleEvent e) { + e.result = getTemplateEntry().getDescription(); + } + + public void getName(AccessibleEvent e) { + e.result = getTemplateEntry().getLabel(); + } + + public void getRole(AccessibleControlEvent e) { + e.detail = ACC.ROLE_LISTITEM; + } + }; + } + + /** + * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure() + */ + public IFigure createFigure() { + IFigure fig = new DetailedLabelFigure() { + + public IFigure getToolTip() { + return createToolTip(); + } + + protected void paintFigure(Graphics graphics) { + super.paintFigure(graphics); + + if (isSelected()) { + graphics.setBackgroundColor(PaletteColorUtil + .getSelectedColor()); + } + graphics.fillRoundRectangle(ToolEntryEditPart + .getSelectionRectangle(getLayoutSetting(), this), 3, 3); + } + + }; + fig.setRequestFocusEnabled(true); + return fig; + } + + /** + * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#deactivate() + */ + public void deactivate() { + ((DetailedLabelFigure) getFigure()).dispose(); + super.deactivate(); + } + + /** + * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#getDragTracker(Request) + */ + public DragTracker getDragTracker(Request request) { + return new SingleSelectionTracker() { + protected boolean handleButtonDown(int button) { + getFigure().requestFocus(); + return super.handleButtonDown(button); + } + }; + } + + private PaletteTemplateEntry getTemplateEntry() { + return (PaletteTemplateEntry) getModel(); + } + + /** + * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#getToolTipText() + */ + protected String getToolTipText() { + String result = null; + if (getLayoutSetting() != PaletteViewerPreferences.LAYOUT_DETAILS) { + result = super.getToolTipText(); + } + return result; + } + + /** + * If this edit part's name is truncated in its label, the name should be prepended to the + * tooltip. + * + * @return whether the name needs to be included in the tooltip + */ + protected boolean nameNeededInToolTip() { + DetailedLabelFigure label = (DetailedLabelFigure) getFigure(); + return label.isNameTruncated() || super.nameNeededInToolTip(); + } + + /** + * @see org.eclipse.gef.editparts.AbstractEditPart#refreshVisuals() + */ + protected void refreshVisuals() { + DetailedLabelFigure fig = (DetailedLabelFigure) getFigure(); + PaletteEntry entry = getPaletteEntry(); + fig.setName(entry.getLabel()); + fig.setDescription(entry.getDescription()); + if (getPreferenceSource().useLargeIcons()) + setImageDescriptor(entry.getLargeIcon()); + else + setImageDescriptor(entry.getSmallIcon()); + int layoutMode = getLayoutSetting(); + fig.setLayoutMode(layoutMode); + if (layoutMode == PaletteViewerPreferences.LAYOUT_COLUMNS) { + fig.setBorder(ToolEntryEditPart.ICON_BORDER); + } else if (layoutMode == PaletteViewerPreferences.LAYOUT_LIST + || layoutMode == PaletteViewerPreferences.LAYOUT_DETAILS) { + fig.setBorder(ToolEntryEditPart.LIST_BORDER); + } else if (layoutMode == PaletteViewerPreferences.LAYOUT_ICONS + && !isToolbarItem()) { + fig.setBorder(ToolEntryEditPart.ICON_BORDER); + } else { + fig.setBorder(null); + } + super.refreshVisuals(); + } + + public void restoreState(IMemento memento) { + setSelected(memento.getInteger(SELECTION_STATE).intValue()); + super.restoreState(memento); + } + + public void saveState(IMemento memento) { + memento.putInteger(SELECTION_STATE, getSelected()); + super.saveState(memento); + } + + /** + * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#setImageInFigure(Image) + */ + protected void setImageInFigure(Image image) { + DetailedLabelFigure fig = (DetailedLabelFigure) getFigure(); + fig.setImage(image); + } + + /** + * @see org.eclipse.gef.EditPart#setSelected(int) + */ + public void setSelected(int value) { + super.setSelected(value); + DetailedLabelFigure label = (DetailedLabelFigure) getFigure(); + if (value == SELECTED_PRIMARY) { + label.requestFocus(); + label.setSelected(true); + } else { + label.setSelected(false); + } + label.repaint(); + + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/ToolEntryEditPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/ToolEntryEditPart.java new file mode 100644 index 0000000..1de88da --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/ToolEntryEditPart.java @@ -0,0 +1,673 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-09 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * 1) update package name + * 2) apply new UI + * - paintFigure: apply 3-state mode (normal, mouse over, selected) + * - activate: Sets customLabel's font + * - setSelected: add method for apply selected effect icon + * - changeToolEntryItem: add method for 3-state's icon and font + * - getCachedImage: return the Palette icon's cached image for the direct manipulation + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts; + +import org.eclipse.draw2d.ActionEvent; +import org.eclipse.draw2d.ActionListener; +import org.eclipse.draw2d.Border; +import org.eclipse.draw2d.ButtonBorder; +import org.eclipse.draw2d.ButtonModel; +import org.eclipse.draw2d.Clickable; +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.MarginBorder; +import org.eclipse.draw2d.Toggle; +import org.eclipse.draw2d.geometry.Insets; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.DragTracker; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.RequestConstants; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.ACC; +import org.eclipse.swt.accessibility.AccessibleControlEvent; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.dnd.DragSourceEvent; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.ui.IMemento; +import org.tizen.efluibuilder.ui.editor.designeditor.DesignEditorCombinedTemplateCreationEntry; +import org.tizen.efluibuilder.ui.editor.designeditor.DesignEditorCombinedTemplateCreationEntry.State; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteStack; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.ToolEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewerPreferences; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.editparts.IPinnableEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.editparts.PaletteEditPart; +import org.tizen.efluibuilder.ui.resources.ColorResources; +import org.tizen.efluibuilder.ui.resources.FontResources; + + +public class ToolEntryEditPart extends PaletteEditPart { + + class MenuTimer implements Runnable { + public static final int MENU_TIMER_DELAY = 400; + + private boolean enabled = true; + + public void disable() { + enabled = false; + } + + public void run() { + if (enabled) { + getButtonModel().setArmed(false); + getButtonModel().setPressed(false); + ((IPaletteStackEditPart) getParent()).openMenu(); + getViewer().getEditDomain().loadDefaultTool(); + } + } + } + + abstract class ToggleButtonTracker extends SingleSelectionTracker { + private MenuTimer timer = null; + + protected void enableTimer() { + timer = new MenuTimer(); + getViewer().getControl().getDisplay() + .timerExec(MenuTimer.MENU_TIMER_DELAY, timer); + } + + protected void disableTimer() { + if (timer != null) { + timer.disable(); + timer = null; + } + } + + protected boolean handleButtonDown(int button) { + if (getParent() instanceof IPaletteStackEditPart) + enableTimer(); + + if (button == 2 && isInState(STATE_INITIAL)) + performConditionalSelection(); + super.handleButtonDown(button); + if (button == 1) { + getFigure().internalGetEventDispatcher().requestRemoveFocus( + getFigure()); + getButtonModel().setArmed(true); + getButtonModel().setPressed(true); + } + return true; + } + + protected boolean handleDrag() { + org.eclipse.draw2d.geometry.Point point = getLocation().getCopy(); + getFigure().translateToRelative(point); + if (!getFigure().containsPoint(point)) { + getButtonModel().setArmed(false); + getButtonModel().setMouseOver(false); + disableTimer(); + } else { + getButtonModel().setArmed(true); + getButtonModel().setMouseOver(true); + } + return true; + } + + protected boolean handleNativeDragFinished(DragSourceEvent event) { + getPaletteViewer().setActiveTool(null); + return true; + } + } + + class GTKToggleButtonTracker extends ToggleButtonTracker { + int gtkState = 0; + + public void deactivate() { + disableTimer(); + super.deactivate(); + } + + protected boolean handleButtonUp(int button) { + disableTimer(); + + // Workaround for Bug 96351. It should be removed when Bug 35585 is + // fixed. + if (gtkState == 1) { + handleNativeDragFinished(null); + return true; + } + + if (button == 1) { + getButtonModel().setPressed(false); + getButtonModel().setArmed(false); + } + return super.handleButtonUp(button); + } + + protected boolean handleNativeDragStarted(DragSourceEvent event) { + disableTimer(); + gtkState = 1; + return true; + } + } + + class OtherToggleButtonTracker extends ToggleButtonTracker { + + private static final int WIN_THRESHOLD = 3; + + private Point mouseDownLoc = null; + + public void deactivate() { + disableTimer(); + getButtonModel().setPressed(false); + getButtonModel().setArmed(false); + super.deactivate(); + } + + protected boolean handleButtonDown(int button) { + mouseDownLoc = new Point(getLocation().x, getLocation().y); + return super.handleButtonDown(button); + } + + protected boolean handleButtonUp(int button) { + disableTimer(); + + if (button == 1) { + getButtonModel().setPressed(false); + getButtonModel().setArmed(false); + } + return super.handleButtonUp(button); + } + + protected boolean handleNativeDragStarted(DragSourceEvent event) { + disableTimer(); + + // win hack because button down is delayed + if (getParent() instanceof IPaletteStackEditPart + && SWT.getPlatform().equals("win32")) { //$NON-NLS-1$ + Point nds = getPaletteViewer().getControl().toControl( + event.display.getCursorLocation()); + if (mouseDownLoc != null + && (Math.abs(nds.x - mouseDownLoc.x) + Math.abs(nds.y + - mouseDownLoc.y)) < WIN_THRESHOLD) { + getButtonModel().setArmed(false); + getButtonModel().setPressed(false); + ((IPaletteStackEditPart) getParent()).openMenu(); + getViewer().getEditDomain().loadDefaultTool(); + event.doit = false; + return false; + } + } + + getButtonModel().setPressed(false); + getButtonModel().setArmed(false); + return true; + } + } + + /** + * The figure for for a ToolEntryEditPart. + */ + class ToolEntryToggle extends Toggle { + + private boolean showHoverFeedback = false; + + ToolEntryToggle(IFigure contents) { + super(contents); + setOpaque(false); + setEnabled(true); + if (isToolbarItem()) { + setStyle(Clickable.STYLE_BUTTON | Clickable.STYLE_TOGGLE); + setBorder(TOOLBAR_ITEM_BORDER); + } + } + + public boolean containsPoint(int x, int y) { + Rectangle rect = getBounds().getCopy(); + if (customLabel.getBorder() == ICON_BORDER) { + rect.width -= PinnablePaletteStackFigure.ARROW_WIDTH; + } else if (customLabel.getBorder() == LIST_BORDER) { + rect.width -= PinnablePaletteStackFigure.ARROW_WIDTH; + rect.x += PinnablePaletteStackFigure.ARROW_WIDTH; + } + return rect.contains(x, y); + } + + public IFigure findMouseEventTargetAt(int x, int y) { + return null; + } + + public IFigure getToolTip() { + return createToolTip(); + } + + public void setEnabled(boolean value) { + super.setEnabled(value); + if (isEnabled()) { + setRolloverEnabled(true); + if (getFlag(STYLE_BUTTON)) { + setBorder(TOOLBAR_ITEM_BORDER); + } + setForegroundColor(null); + } else { + if (getFlag(STYLE_BUTTON)) { + setBorder(null); + } + setRolloverEnabled(false); + setForegroundColor(ColorConstants.gray); + } + } + + protected void paintFigure(Graphics graphics) { + super.paintFigure(graphics); + + if (!isToolbarItem() && isEnabled() && isRolloverEnabled()) { + ButtonModel model = getModel(); + + /* ECLIPSE { */ + /* + * if (model.isSelected()) { graphics.setBackgroundColor(PaletteColorUtil + * .getSelectedColor()); graphics.fillRoundRectangle( + * getSelectionRectangle(getLayoutSetting(), customLabel), 3, 3); } else if + * (model.isMouseOver() || showHoverFeedback) { + * graphics.setBackgroundColor(PaletteColorUtil .getHoverColor()); + * graphics.fillRoundRectangle( getSelectionRectangle(getLayoutSetting(), + * customLabel), 3, 3); } + */ + /* } ECLIPSE */ + + /* TIZEN: add 3-state mode (normal, mouseover, selected) { */ + if (model.isSelected()) { + } else if (model.isMouseOver() || showHoverFeedback) { + // true case: This is normal only + if (currentState == State.NORMAL) { + changeToolEntryItem(State.MOUSEOVER); + } + } else { + if (this.hasFocus()) { + return; + } + // true case: This is not normal only + if (currentState != State.NORMAL) { + changeToolEntryItem(State.NORMAL); + } + } + /* } TIZEN */ + } + } + + protected void paintBorder(Graphics graphics) { + if (isEnabled()) { + + if (getBorder() != null) + getBorder().paint(this, graphics, NO_INSETS); + if (hasFocus()) { + graphics.setForegroundColor(ColorConstants.black); + graphics.setBackgroundColor(ColorConstants.white); + + Rectangle area = isToolbarItem() ? getClientArea() + : getSelectionRectangle(getLayoutSetting(), + customLabel); + if (isStyle(STYLE_BUTTON)) + graphics.drawFocus(area.x, area.y, area.width, + area.height); + else + graphics.drawFocus(area.x, area.y, area.width - 1, + area.height - 1); + } + } else { + super.paintBorder(graphics); + } + } + + /** + * Should hover feedback be shown? Allows other palette entities to control when the hover + * feedback should be shown on this tool entry. + * + * @param showHoverFeedback + * true if the hover feedback is to be shown; false otherwise. + */ + public void setShowHoverFeedback(boolean showHoverFeedback) { + this.showHoverFeedback = showHoverFeedback; + repaint(); + } + } + + private static final String ACTIVE_STATE = "active"; //$NON-NLS-1$ + private DetailedLabelFigure customLabel; + + public ToolEntryEditPart(PaletteEntry paletteEntry) { + super(paletteEntry); + } + + /* TIZEN: add new UI: current drag cached image for direct manipulation { */ + public Image getCachedImage() { + return customLabel.getCachedImage(); + } + /* TIZEN } */ + + public Object getAdapter(Class key) { + if (key == IPinnableEditPart.class) { + if ((getParent() instanceof PinnablePaletteStackEditPart) + && ((PinnablePaletteStackEditPart) getParent()) + .canBePinned() + && ((PaletteStack) getParent().getModel()).getActiveEntry() + .equals(getModel())) { + return getParent(); + } + } + return super.getAdapter(key); + } + + protected AccessibleEditPart createAccessible() { + return new AccessibleGraphicalEditPart() { + public void getDescription(AccessibleEvent e) { + e.result = getPaletteEntry().getDescription(); + } + + public void getName(AccessibleEvent e) { + e.result = getPaletteEntry().getLabel(); + } + + public void getRole(AccessibleControlEvent e) { + if (getParent() instanceof IPaletteStackEditPart + && (ToolEntryEditPart.this == ((IPaletteStackEditPart) getParent()) + .getActiveEntry())) { + e.detail = ACC.ROLE_COMBOBOX; + } else { + e.detail = ACC.ROLE_PUSHBUTTON; + } + } + + public void getState(AccessibleControlEvent e) { + super.getState(e); + if (getButtonModel().isSelected()) + e.detail |= ACC.STATE_CHECKED; + } + }; + } + + static final Border TOOLBAR_ITEM_BORDER = new ButtonBorder( + ButtonBorder.SCHEMES.TOOLBAR); + + // The following are the insets that the bounds of the label figure should + // be + // cropped to paint the blue/orange select and hover feedback rectangles. + static final Insets LIST_HIGHLIGHT_INSETS = new Insets(1, 5, 2, 0); + static final Insets ICON_HIGHLIGHT_INSETS = new Insets(2, 1, 2, 1); + + // The following are the borders that go around the entire tool figure to + // provide room to draw the arrow and outline of the palette stack figure if + // this tool happens to appear as the active tool of a stack. + static final Border LIST_BORDER = new MarginBorder(3, + PinnablePaletteStackFigure.ARROW_WIDTH + 7, 4, 0); + static final Border ICON_BORDER = new MarginBorder(4, 4, 3, + PinnablePaletteStackFigure.ARROW_WIDTH + 4); + + public IFigure createFigure() { + + customLabel = new DetailedLabelFigure(); + Clickable button = new ToolEntryToggle(customLabel); + button.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + getPaletteViewer().setActiveTool(getToolEntry()); + } + }); + + return button; + } + + /** + * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#deactivate() + */ + public void deactivate() { + customLabel.dispose(); + super.deactivate(); + } + + /** + * @see org.eclipse.gef.EditPart#eraseTargetFeedback(Request) + */ + public void eraseTargetFeedback(Request request) { + if (RequestConstants.REQ_SELECTION.equals(request.getType())) + getButtonModel().setMouseOver(false); + super.eraseTargetFeedback(request); + } + + private ButtonModel getButtonModel() { + Clickable c = (Clickable) getFigure(); + return c.getModel(); + } + + /** + * @see PaletteEditPart#getDragTracker(Request) + */ + public DragTracker getDragTracker(Request request) { + if (SWT.getPlatform().equals("gtk")) //$NON-NLS-1$ + return new GTKToggleButtonTracker(); + else + return new OtherToggleButtonTracker(); + } + + private ToolEntry getToolEntry() { + return (ToolEntry) getPaletteEntry(); + } + + /** + * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#getToolTipText() + */ + protected String getToolTipText() { + String result = null; + if (getLayoutSetting() != PaletteViewerPreferences.LAYOUT_DETAILS) { + result = super.getToolTipText(); + } + return result; + } + + /** + * If this edit part's name is truncated in its label, the name should be prepended to the + * tooltip. + * + * @return whether the name needs to be included in the tooltip + */ + protected boolean nameNeededInToolTip() { + DetailedLabelFigure label = (DetailedLabelFigure) getFigure() + .getChildren().get(0); + return label.isNameTruncated() || super.nameNeededInToolTip(); + } + + /** + * @see org.eclipse.gef.editparts.AbstractEditPart#refreshVisuals() + */ + protected void refreshVisuals() { + PaletteEntry entry = getPaletteEntry(); + + customLabel.setName(entry.getLabel()); + customLabel.setDescription(entry.getDescription()); + if (getPreferenceSource().useLargeIcons()) + setImageDescriptor(entry.getLargeIcon()); + else + setImageDescriptor(entry.getSmallIcon()); + int layoutMode = getLayoutSetting(); + customLabel.setLayoutMode(layoutMode); + if (layoutMode == PaletteViewerPreferences.LAYOUT_COLUMNS) { + customLabel.setBorder(ICON_BORDER); + } else if (layoutMode == PaletteViewerPreferences.LAYOUT_LIST + || layoutMode == PaletteViewerPreferences.LAYOUT_DETAILS) { + customLabel.setBorder(LIST_BORDER); + } else if (layoutMode == PaletteViewerPreferences.LAYOUT_ICONS + && !isToolbarItem()) { + customLabel.setBorder(ICON_BORDER); + } else { + customLabel.setBorder(null); + } + super.refreshVisuals(); + } + + @Override + public void activate() { + /* TIZEN: new UI: Sets customLabel's font { */ + customLabel.setFont(FontResources.PALETTE_COMPONENT_NORMAL); + customLabel.setForegroundColor(ColorResources.PALETTE_UI_COMPONENT_NORMAL); + /* } TIZEN */ + super.activate(); + } + + /** + * @see org.eclipse.gef.EditPart#removeNotify() + */ + public void removeNotify() { + if (getButtonModel().isSelected()) + getPaletteViewer().setActiveTool(null); + super.removeNotify(); + } + + public void setToolSelected(boolean value) { + getButtonModel().setSelected(value); + } + + public void restoreState(IMemento memento) { + if (new Boolean(memento.getString(ACTIVE_STATE)).booleanValue()) + getPaletteViewer().setActiveTool(getToolEntry()); + super.restoreState(memento); + } + + public void saveState(IMemento memento) { + memento.putString(ACTIVE_STATE, new Boolean(getPaletteViewer() + .getActiveTool() == getToolEntry()).toString()); + super.saveState(memento); + } + + /** + * @see PaletteEditPart#setImageInFigure(Image) + */ + protected void setImageInFigure(Image image) { + DetailedLabelFigure fig = (DetailedLabelFigure) (getFigure() + .getChildren().get(0)); + fig.setImage(image); + } + + /** + * @see org.eclipse.gef.EditPart#setSelected(int) + */ + public void setSelected(int value) { + /* TIZEN: add new UI: apply selected effect icon { */ + if (this.getSelected() == value) { + return; + } + changeToolEntryItem((value != EditPart.SELECTED_NONE) ? State.SELECT : State.NORMAL); + /* } TIZEN */ + + super.setSelected(value); + if (value == SELECTED_PRIMARY + && getPaletteViewer().getControl() != null + && !getPaletteViewer().getControl().isDisposed() + && getPaletteViewer().getControl().isFocusControl()) + getFigure().requestFocus(); + } + + /* TIZEN: added for 3-state { */ + private State currentState = State.NORMAL; + /* } TIZEN */ + + /* TIZEN: added managing for 3-state's icon and font { */ + private void changeToolEntryItem(State changeState) { + if (currentState == changeState) { + return; + } + + Color foregroundColor; + Font newFont = null; + + switch (changeState) { + case MOUSEOVER: + currentState = State.MOUSEOVER; + newFont = FontResources.PALETTE_COMPONENT_BOLD; + foregroundColor = ColorResources.PALETTE_UI_COMPONENT_NORMAL; + break; + case SELECT: + currentState = State.SELECT; + newFont = FontResources.PALETTE_COMPONENT_NORMAL; + foregroundColor = ColorResources.PALETTE_UI_COMPONENT_SELECT; + break; + default: // or NORMAL + currentState = State.NORMAL; + newFont = FontResources.PALETTE_COMPONENT_NORMAL; + foregroundColor = ColorResources.PALETTE_UI_COMPONENT_NORMAL; + break; + } + + DesignEditorCombinedTemplateCreationEntry entry = (DesignEditorCombinedTemplateCreationEntry) getToolEntry(); + entry.setIconMode(currentState); + ImageDescriptor smallIcon = entry.getSmallIcon(); + setImageDescriptor(smallIcon); + + customLabel.setForegroundColor(foregroundColor); + customLabel.setFont(newFont); + customLabel.invalidateTree(); // advux: font -bold issue + } + /* } TIZEN */ + + /** + * @see org.eclipse.gef.EditPart#showTargetFeedback(Request) + */ + public void showTargetFeedback(Request request) { + if (RequestConstants.REQ_SELECTION.equals(request.getType())) + getButtonModel().setMouseOver(true); + super.showTargetFeedback(request); + } + + static Rectangle getSelectionRectangle(int layoutMode, + DetailedLabelFigure labelFigure) { + Rectangle rect = Rectangle.SINGLETON; + rect.setBounds(labelFigure.getBounds()); + if (layoutMode == PaletteViewerPreferences.LAYOUT_LIST + || layoutMode == PaletteViewerPreferences.LAYOUT_DETAILS) { + + rect.x += PinnablePaletteStackFigure.ARROW_WIDTH; + rect.width -= PinnablePaletteStackFigure.ARROW_WIDTH; + int newWidth = labelFigure.getPreferredSize().width + 17; + if (newWidth < rect.width) { + rect.width = newWidth; + } + rect.crop(LIST_HIGHLIGHT_INSETS); + } else { + rect.width -= PinnablePaletteStackFigure.ARROW_WIDTH; + rect.crop(ICON_HIGHLIGHT_INSETS); + } + return rect; + } + + // Reference code for java reflection: Using in createFigure() + // private void setCustomLabel(DetailedLabelFigure figure) { + // final String INTERNAL_FIELD_CUSTOMLABEL = "customLabel"; + // + // Field field = ReflectionUtil.getField(this, INTERNAL_FIELD_CUSTOMLABEL, true); + // try { + // if (field != null) { + // field.set(this, figure); + // } + // } catch (IllegalArgumentException e) { + // e.printStackTrace(); + // } catch (IllegalAccessException e) { + // e.printStackTrace(); + // } + // } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/ToolbarEditPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/ToolbarEditPart.java new file mode 100644 index 0000000..fb829be --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/internal/ui/palette/editparts/ToolbarEditPart.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2008, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-09 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts; + +import org.eclipse.draw2d.Figure; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.MarginBorder; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.PaletteColorUtil; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteToolbar; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewerPreferences; + + +/** + * An editpart for the PaletteToolbar. + * + * @author crevells + * @since 3.4 + */ +public class ToolbarEditPart extends GroupEditPart { + + /** + * Creates a new instance. + * + * @param model + * the PaletteToolbar + */ + public ToolbarEditPart(PaletteToolbar model) { + super(model); + } + + public IFigure createFigure() { + IFigure figure = new Figure() { + + protected void paintFigure(Graphics graphics) { + super.paintFigure(graphics); + + // draw top border + graphics.setForegroundColor(PaletteColorUtil.WIDGET_LIST_BACKGROUND); + graphics.drawLine(getBounds().getTopLeft(), getBounds() + .getTopRight()); + + // draw bottom border + graphics.setForegroundColor(PaletteColorUtil.WIDGET_BACKGROUND_NORMAL_SHADOW_70); + graphics.drawLine( + getBounds().getBottomLeft().getTranslated(0, -1), + getBounds().getBottomRight().getTranslated(0, -1)); + } + + }; + figure.setOpaque(true); + figure.setBackgroundColor(PaletteColorUtil.WIDGET_BACKGROUND); + figure.setBorder(new MarginBorder(2, 1, 1, 1)); + + return figure; + } + + protected int getLayoutSetting() { + return PaletteViewerPreferences.LAYOUT_ICONS; + } + + public boolean isToolbarItem() { + return true; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/CombinedTemplateCreationEntry.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/CombinedTemplateCreationEntry.java new file mode 100644 index 0000000..52b0321 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/CombinedTemplateCreationEntry.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + * - modify Constructs of CombinedTemplateCreationEntry + * from @link org.eclipse.gef.dnd.TemplateTransferDragSourceListener to org.tizen.efluibuilder.ui.editor.internal.gef.dnd.TemplateTransferDragSourceListener + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.palette; + +import org.eclipse.gef.requests.CreationFactory; +import org.eclipse.jface.resource.ImageDescriptor; + + +/** + * A combination of a {@link PaletteTemplateEntry} and {@link ToolEntry}. The entry will be rendered + * as a ToolEntry, but it will also be possible to use the entry as a DragSource in the same way as + * a template. + * + * @author hudsonr + */ +public class CombinedTemplateCreationEntry extends CreationToolEntry { + + private Object template; + + /** + * Constructs an entry with the given creation factory and template. The creation factory is + * used by the creation tool when the entry is selected. The template is used with the + * {@link org.tizen.efluibuilder.ui.editor.internal.gef.dnd.TemplateTransferDragSourceListener}. + * + * @since 3.2 + * @param label + * the label + * @param shortDesc + * the descriptoin + * @param template + * the template object + * @param factory + * the CreationFactory + * @param iconSmall + * the small icon + * @param iconLarge + * the large icon + */ + public CombinedTemplateCreationEntry(String label, String shortDesc, + Object template, CreationFactory factory, + ImageDescriptor iconSmall, ImageDescriptor iconLarge) { + super(label, shortDesc, factory, iconSmall, iconLarge); + setTemplate(template); + } + + /** + * Constructs an entry with the given creation factory. The creation factory is also used as the + * template object. + * + * @param label + * the label + * @param shortDesc + * the description + * @param factory + * the creation factory and template + * @param iconSmall + * the small icon + * @param iconLarge + * the large icon + * @since 3.2 + */ + public CombinedTemplateCreationEntry(String label, String shortDesc, + CreationFactory factory, ImageDescriptor iconSmall, + ImageDescriptor iconLarge) { + this(label, shortDesc, factory, factory, iconSmall, iconLarge); + } + + /** + * Returns the template object. + * + * @return Object the template + */ + public Object getTemplate() { + return template; + } + + /** + * Sets the template. + * + * @param template + * The template + */ + public void setTemplate(Object template) { + this.template = template; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/ConnectionCreationToolEntry.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/ConnectionCreationToolEntry.java new file mode 100644 index 0000000..4b2baa6 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/ConnectionCreationToolEntry.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.palette; + +import org.eclipse.gef.requests.CreationFactory; +import org.eclipse.gef.tools.ConnectionCreationTool; +import org.eclipse.jface.resource.ImageDescriptor; + + +/** + * A palette ToolEntry for a {@link org.eclipse.gef.tools.ConnectionCreationTool}. + * + * @author hudsonr + * @since 2.1 + */ +public class ConnectionCreationToolEntry extends CreationToolEntry { + + /** + * Constructor for ConnectionCreationToolEntry. + * + * @param label + * the label + * @param shortDesc + * the description + * @param factory + * the CreationFactory + * @param iconSmall + * the small icon + * @param iconLarge + * the large icon + */ + public ConnectionCreationToolEntry(String label, String shortDesc, + CreationFactory factory, ImageDescriptor iconSmall, + ImageDescriptor iconLarge) { + super(label, shortDesc, factory, iconSmall, iconLarge); + setToolClass(ConnectionCreationTool.class); + setUserModificationPermission(PERMISSION_NO_MODIFICATION); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/CreationToolEntry.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/CreationToolEntry.java new file mode 100644 index 0000000..d741eaa --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/CreationToolEntry.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.palette; + +import org.eclipse.gef.requests.CreationFactory; +import org.eclipse.gef.tools.CreationTool; +import org.eclipse.jface.resource.ImageDescriptor; + + +/** + * A palette ToolEntry for a {@link CreationTool}. + * + * @author hudsonr + * @since 2.1 + */ +public class CreationToolEntry extends ToolEntry { + + /** + * The creation factory used with the returned creation tool. + * + * @deprecated in 3.1. This field will be removed in future releases. The factory is being + * provided to the tool via the {@link ToolEntry#setToolProperty(Object, Object)} + * method. + */ + protected final CreationFactory factory; + + /** + * Constructor for CreationToolEntry. + * + * @param label + * the label + * @param shortDesc + * the description + * @param factory + * the CreationFactory + * @param iconSmall + * the small icon + * @param iconLarge + * the large icon + */ + public CreationToolEntry(String label, String shortDesc, + CreationFactory factory, ImageDescriptor iconSmall, + ImageDescriptor iconLarge) { + super(label, shortDesc, iconSmall, iconLarge, CreationTool.class); + this.factory = factory; + setToolProperty(CreationTool.PROPERTY_CREATION_FACTORY, factory); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/MarqueeToolEntry.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/MarqueeToolEntry.java new file mode 100644 index 0000000..660bcc8 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/MarqueeToolEntry.java @@ -0,0 +1,148 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.palette; + +import org.eclipse.gef.SharedImages; +import org.eclipse.gef.internal.GEFMessages; +import org.eclipse.gef.tools.MarqueeSelectionTool; +import org.eclipse.jface.resource.ImageDescriptor; + + +/** + * A palette ToolEntry for a {@link org.eclipse.gef.tools.MarqueeSelectionTool}. + * + * @author rhudson + * @author pshah + * @author anyssen + * + * @since 2.1 + */ +public class MarqueeToolEntry extends ToolEntry { + + /** + * Creates a new MarqueeToolEntry that can select nodes + */ + public MarqueeToolEntry() { + this(null, null); + } + + /** + * Constructor for MarqueeToolEntry. + * + * @param label + * the label + */ + public MarqueeToolEntry(String label) { + this(label, null); + } + + /** + * Constructor for MarqueeToolEntry. + * + * @param label + * the label; can be null + * @param description + * the description (can be null) + */ + public MarqueeToolEntry(String label, String description) { + super(label, description, null, null, MarqueeSelectionTool.class); + if (label == null || label.length() == 0) + setLabel(GEFMessages.MarqueeTool_Label); + setUserModificationPermission(PERMISSION_NO_MODIFICATION); + } + + /** + * @see org.eclipse.gef.palette.PaletteEntry#getDescription() + */ + public String getDescription() { + String description = super.getDescription(); + if (description != null) + return description; + + int marqueeBehavior = getMarqueeBehavior(); + if (marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_CONNECTIONS_TOUCHED) { + return GEFMessages.MarqueeTool_Connections_Touched_Desc; + } + if (marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_CONNECTIONS_CONTAINED) { + return GEFMessages.MarqueeTool_Connections_Contained_Desc; + } + if (marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_NODES_TOUCHED) { + return GEFMessages.MarqueeTool_Nodes_Touched_Desc; + } + if (marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_NODES_CONTAINED) { + return GEFMessages.MarqueeTool_Nodes_Contained_Desc; + } + if (marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_NODES_TOUCHED_AND_RELATED_CONNECTIONS) { + return GEFMessages.MarqueeTool_Nodes_Touched_And_Related_Connections_Desc; + } + if (marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_NODES_CONTAINED_AND_RELATED_CONNECTIONS) { + return GEFMessages.MarqueeTool_Nodes_Contained_And_Related_Connections_Desc; + } + throw new IllegalArgumentException("Unknown marquee behavior"); //$NON-NLS-1$ + } + + /** + * @see org.eclipse.gef.palette.PaletteEntry#getLargeIcon() + */ + public ImageDescriptor getLargeIcon() { + ImageDescriptor imageDescriptor = super.getLargeIcon(); + if (imageDescriptor != null) { + return imageDescriptor; + } + // infer icon from behavior mode + int marqueeBehavior = getMarqueeBehavior(); + if (marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_CONNECTIONS_CONTAINED + || marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_CONNECTIONS_TOUCHED) { + return SharedImages.DESC_MARQUEE_TOOL_CONNECTIONS_24; + } else if (marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_NODES_CONTAINED + || marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_NODES_TOUCHED) { + return SharedImages.DESC_MARQUEE_TOOL_NODES_24; + } else { + return SharedImages.DESC_MARQUEE_TOOL_24; + } + } + + private int getMarqueeBehavior() { + // retrieve marquee behavior from tool property + Object value = getToolProperty(MarqueeSelectionTool.PROPERTY_MARQUEE_BEHAVIOR); + if (value != null && value instanceof Integer) { + return ((Integer) value).intValue(); + } + // return default behavior + return MarqueeSelectionTool.DEFAULT_MARQUEE_BEHAVIOR; + } + + /** + * @see org.eclipse.gef.palette.PaletteEntry#getSmallIcon() + */ + public ImageDescriptor getSmallIcon() { + ImageDescriptor imageDescriptor = super.getSmallIcon(); + if (imageDescriptor != null) { + return imageDescriptor; + } + // infer icon from marquee behavior + int marqueeBehavior = getMarqueeBehavior(); + if (marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_CONNECTIONS_CONTAINED + || marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_CONNECTIONS_TOUCHED) { + return SharedImages.DESC_MARQUEE_TOOL_CONNECTIONS_16; + } else if (marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_NODES_CONTAINED + || marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_NODES_TOUCHED) { + return SharedImages.DESC_MARQUEE_TOOL_NODES_16; + } else { + return SharedImages.DESC_MARQUEE_TOOL_16; + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteContainer.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteContainer.java new file mode 100644 index 0000000..0d45d99 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteContainer.java @@ -0,0 +1,262 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.palette; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.resource.ImageDescriptor; + + +/** + * Default implementation of PaletteContainer + * + * @author Pratik Shah + */ +public class PaletteContainer extends PaletteEntry { + + /** + * Property name indicating that this PaletteContainer's children have changed + */ + public static final String PROPERTY_CHILDREN = "Children Changed"; //$NON-NLS-1$ + + /** + * This container's contents + */ + protected List children = new ArrayList(); + + /** + * Constructor + *

+ * Any parameter can be null. + *

+ * + * @param label + * The container's name + * @param desc + * The container's description + * @param icon + * The small icon to represent this container + * @param type + * The container's type + */ + protected PaletteContainer(String label, String desc, ImageDescriptor icon, + Object type) { + super(label, desc, icon, null, type); + } + + /** + * Returns true if this type can be a child of this container. + * + * @param type + * the type being requested + * @return true if this can be a child of this container + */ + public boolean acceptsType(Object type) { + return true; + } + + /** + * Adds the given entry to the end of this PaletteContainer + * + * @param entry + * the PaletteEntry to add + */ + public void add(PaletteEntry entry) { + add(-1, entry); + } + + /** + * Adds the given PaletteEntry at position index. + * + * @param index + * position to add the PaletteEntry + * @param entry + * the PaletteEntry to add + */ + public void add(int index, PaletteEntry entry) { + if (!acceptsType(entry.getType())) + throw new IllegalArgumentException( + "This container can not contain this type of child: " //$NON-NLS-1$ + + entry.getType()); + + List oldChildren = new ArrayList(getChildren()); + + int actualIndex = index < 0 ? getChildren().size() : index; + getChildren().add(actualIndex, entry); + entry.setParent(this); + listeners.firePropertyChange(PROPERTY_CHILDREN, oldChildren, + getChildren()); + } + + /** + * Adds the list of {@link PaletteEntry} objects to this PaletteContainer. + * + * @param list + * a list of PaletteEntry objects to add to this PaletteContainer + */ + public void addAll(List list) { + ArrayList oldChildren = new ArrayList(getChildren()); + for (int i = 0; i < list.size(); i++) { + PaletteEntry child = (PaletteEntry) list.get(i); + if (!acceptsType(child.getType())) + throw new IllegalArgumentException( + "This container can not contain this type of child: " //$NON-NLS-1$ + + child.getType()); + getChildren().add(child); + child.setParent(this); + } + listeners.firePropertyChange(PROPERTY_CHILDREN, oldChildren, + getChildren()); + } + + /** + * Appends the given entry after the entry with the given id, but before the next separator. + * + * @param id + * the id of the entry to append after + * @param entry + * the entry to add + */ + public void appendToSection(String id, PaletteEntry entry) { + // find the entry with the given id + boolean found = false; + for (int i = 0; i < getChildren().size(); i++) { + PaletteEntry currEntry = (PaletteEntry) getChildren().get(i); + if (currEntry.getId().equals(id)) + found = true; + else if (found && currEntry instanceof PaletteSeparator) { + add(i, entry); + return; + } + } + if (found) + add(entry); + else + throw new IllegalArgumentException("Section not found: " + id); //$NON-NLS-1$ + } + + /** + * @return the children of this container + */ + public List getChildren() { + return children; + } + + private boolean move(PaletteEntry entry, boolean up) { + int index = getChildren().indexOf(entry); + if (index < 0) { + // This container does not contain the given palette entry + return false; + } + index = up ? index - 1 : index + 1; + if (index < 0 || index >= getChildren().size()) { + // Performing the move operation will give the child an invalid + // index + return false; + } + if (getChildren().get(index) instanceof PaletteContainer + && getUserModificationPermission() == PaletteEntry.PERMISSION_FULL_MODIFICATION) { + // move it into a container if we have full permission + PaletteContainer container = (PaletteContainer) getChildren().get( + index); + if (container.acceptsType(entry.getType()) + && container.getUserModificationPermission() == PaletteEntry.PERMISSION_FULL_MODIFICATION) { + remove(entry); + if (up) + container.add(entry); + else + container.add(0, entry); + return true; + } + } + List oldChildren = new ArrayList(getChildren()); + getChildren().remove(entry); + getChildren().add(index, entry); + listeners.firePropertyChange(PROPERTY_CHILDREN, oldChildren, + getChildren()); + return true; + } + + /** + * Moves the given entry down, if possible. This method only handles moving the child within + * this container. + * + * @param entry + * The entry to be moved + * @return true if the given entry was successfully moved down + */ + public boolean moveDown(PaletteEntry entry) { + return move(entry, false); + } + + /** + * Moves the given entry up, if possible. This method only handles moving the child within this + * container. + * + * @param entry + * The entry to be moved + * @return true if the given entry was successfully moved up + */ + public boolean moveUp(PaletteEntry entry) { + return move(entry, true); + } + + /** + * Removes the given PaletteEntry from this PaletteContainer + * + * @param entry + * the PaletteEntry to remove + */ + public void remove(PaletteEntry entry) { + List oldChildren = new ArrayList(getChildren()); + if (getChildren().remove(entry)) { + entry.setParent(null); + listeners.firePropertyChange(PROPERTY_CHILDREN, oldChildren, + getChildren()); + } + } + + /** + * Sets the children of this PaletteContainer to the given list of {@link PaletteEntry} objects. + * + * @param list + * the list of children + */ + public void setChildren(List list) { + List oldChildren = children; + for (int i = 0; i < oldChildren.size(); i++) { + PaletteEntry entry = (PaletteEntry) oldChildren.get(i); + entry.setParent(null); + } + children = list; + for (int i = 0; i < children.size(); i++) { + PaletteEntry entry = (PaletteEntry) children.get(i); + entry.setParent(this); + } + listeners.firePropertyChange(PROPERTY_CHILDREN, oldChildren, + getChildren()); + } + + /** + * @see java.lang.Object#toString() + */ + public String toString() { + return "Palette Container (" //$NON-NLS-1$ + + (getLabel() != null ? getLabel() : "") //$NON-NLS-1$ + + ")"; //$NON-NLS-1$ + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteDrawer.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteDrawer.java new file mode 100644 index 0000000..25ca3b6 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteDrawer.java @@ -0,0 +1,186 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.palette; + +import org.eclipse.jface.resource.ImageDescriptor; + + +/** + * A PaletteDrawer is a collapsible container that can have other non-container palette entries. + * + * @author Pratik Shah + */ +public class PaletteDrawer extends PaletteContainer { + + /** + * The type for this PaletteEntry. + * + * @see PaletteEntry#getType() + */ + public static final Object PALETTE_TYPE_DRAWER = "$Palette Drawer"; //$NON-NLS-1$ + /** + * Property name used when notification about a change in the drawer's initial state is fired. + */ + public static final String PROPERTY_INITIAL_STATUS = "Initial status"; //$NON-NLS-1$ + + /** + * Constants indicating the possible initial states for a drawer: + *
    + *
  • INITIAL_STATE_OPEN - The drawer is expanded when the palette is created.
  • + *
  • INITIAL_STATE_CLOSED - The drawer is collapsed when the palette is created.
  • + *
  • INITIAL_STATE_PINNED_OPEN - The drawer is pinned open (which would prevent it from being + * collapsed automatically) when the palette is created.
  • + *
+ */ + public static final int INITIAL_STATE_OPEN = 0, INITIAL_STATE_CLOSED = 1, + INITIAL_STATE_PINNED_OPEN = 2; + + /** + * @deprecated use {@link #INITIAL_STATE_PINNED_OPEN} + */ + public static final int INITIAL_STATUS_PINNED_OPEN = 2; + + private int initialState; + private Object drawerType; + private boolean showDefaultIcon = true; + + /** + * Constructor + * + * @param label + * The name/label for this entry + */ + public PaletteDrawer(String label) { + this(label, (ImageDescriptor) null); + } + + /** + * Constructor + * + * @param label + * The name/label for this entry + * @param icon + * An icon for this drawer + */ + public PaletteDrawer(String label, ImageDescriptor icon) { + super(label, null, icon, PALETTE_TYPE_DRAWER); + setUserModificationPermission(PERMISSION_LIMITED_MODIFICATION); + } + + /** + * Returns true if this type can be a child of this container + * + * @param type + * the type being requested + * @return true if this can be a child of this container + */ + public boolean acceptsType(Object type) { + if (type.equals(PALETTE_TYPE_DRAWER) + || type.equals(PaletteGroup.PALETTE_TYPE_GROUP)) + return false; + return super.acceptsType(type); + } + + /** + * @return ToolEntry.PALETTE_TYPE_TOOL or + * PaletteTemplateEntry.PALETTE_TYPE_TEMPLATE or (if the drawer is empty + * and a drawerType has not been explicitly set) PALETTE_TYPE_UNKNOWN + * + * @see #setDrawerType(Object) + */ + public Object getDrawerType() { + if (drawerType != null) { + return drawerType; + } + for (int i = 0; i < children.size(); i++) { + PaletteEntry child = (PaletteEntry) children.get(i); + Object type = child.getType(); + if (PaletteSeparator.PALETTE_TYPE_SEPARATOR.equals(type) == false) + return type; + } + return PaletteEntry.PALETTE_TYPE_UNKNOWN; + } + + /** + * @return INITIAL_STATE_OPEN or INITIAL_STATE_CLOSED or INITIAL_STATE_PINNED_OPEN + */ + public int getInitialState() { + return initialState; + } + + /** + * @return true if open initially + */ + public boolean isInitiallyOpen() { + return (getInitialState() == INITIAL_STATE_OPEN || getInitialState() == INITIAL_STATE_PINNED_OPEN); + } + + /** + * @return true if the drawer is to be pinned open initially. + */ + public boolean isInitiallyPinned() { + return (getInitialState() == INITIAL_STATE_PINNED_OPEN); + } + + /** + * DrawerType indicates whether a drawer will contain ToolEntries of PaletteTemplateEntries. A + * drawer should not contain entries of both these types. However, there are no + * checks/restrictions that will prevent you from doing so. + * + * @param obj + * ToolEntry.PALETTE_TYPE_TOOL or + * PaletteTemplateEntry.PALETTE_TYPE_TEMPLATE + */ + public void setDrawerType(Object obj) { + drawerType = obj; + } + + /** + * Sets the initial state of this drawer (i.e. the state that this drawer should be when the + * palette is created). + * + * @param state + * INITIAL_STATE_OPEN or INITIAL_STATE_CLOSED or INITIAL_STATE_PINNED_OPEN + */ + public void setInitialState(int state) { + if (initialState == state) + return; + int oldState = initialState; + initialState = state; + listeners.firePropertyChange(PROPERTY_INITIAL_STATUS, oldState, state); + } + + /** + * Should the default icon be shown for this drawer if no icon is set? + * + * @return true if the default icon should be shown if no icon is set; false otherwise + * @since 3.4 + */ + public boolean showDefaultIcon() { + return showDefaultIcon; + } + + /** + * Should the default icon be shown for this drawer if no icon is set? + * + * @param showDefaultIcon + * true if the default icon should be shown if no icon is set; false otherwise + * @since 3.4 + */ + public void setShowDefaultIcon(boolean showDefaultIcon) { + this.showDefaultIcon = showDefaultIcon; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteEntry.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteEntry.java new file mode 100644 index 0000000..4e9b414 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteEntry.java @@ -0,0 +1,463 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.palette; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; + +import org.eclipse.jface.resource.ImageDescriptor; + + +/** + * Root class (statically) for the palette model. + * + * @author Pratik Shah + */ +public class PaletteEntry { + + /** + * Property name for the entry's small icon + */ + public static final String PROPERTY_SMALL_ICON = "Small Icon"; //$NON-NLS-1$ + + /** + * Property name for the entry's type + */ + public static final String PROPERTY_TYPE = "Type"; //$NON-NLS-1$ + + /** + * Property name for the entry's large icon + */ + public static final String PROPERTY_LARGE_ICON = "Large Icon"; //$NON-NLS-1$ + + /** + * Property name for the entry's label (name) + */ + public static final String PROPERTY_LABEL = "Name"; //$NON-NLS-1$ + + /** + * Property name for the entry's description + */ + public static final String PROPERTY_DESCRIPTION = "Description"; //$NON-NLS-1$ + + /** + * Property name for the entry's hidden status + */ + public static final String PROPERTY_VISIBLE = "Visible"; //$NON-NLS-1$ + + /** + * Property name for the entry's default staus + */ + public static final String PROPERTY_DEFAULT = "Default"; //$NON-NLS-1$ + + /** + * Property name for the entry's parent + */ + public static final String PROPERTY_PARENT = "Parent"; //$NON-NLS-1$ + + /** + * Type unknown + */ + public static final String PALETTE_TYPE_UNKNOWN = "Palette_type_Unknown";//$NON-NLS-1$ + + /** + * No changes can be made to a PaletteEntry with this permission level. + */ + public static final int PERMISSION_NO_MODIFICATION = 1; + + /** + * Entries with this permission level can only be hidden/shown. + */ + public static final int PERMISSION_HIDE_ONLY = 3; + + /** + * Any property of entries with this level of permission can be changed; however, they cannot be + * deleted from the palette. The children PaletteContainers with this permission level can be + * reordered within that container (however, cross-container moving is not allowed). + * + */ + public static final int PERMISSION_LIMITED_MODIFICATION = 7; + + /** + * All modifications allowed. + */ + public static final int PERMISSION_FULL_MODIFICATION = 15; + + /** + * PropertyChangeSupport + */ + protected PropertyChangeSupport listeners = new PropertyChangeSupport(this); + + private PaletteContainer parent; + private String label, id; + private String shortDescription; + private ImageDescriptor iconSmall; + private ImageDescriptor iconLarge; + private boolean visible = true; + private int permission = PERMISSION_FULL_MODIFICATION; + private Object type = PaletteEntry.PALETTE_TYPE_UNKNOWN; + + /** + * Constructor + *

+ * Any parameter can be null + *

+ * + * @param label + * The entry's name + * @param shortDescription + * The entry's description + */ + public PaletteEntry(String label, String shortDescription) { + this(label, shortDescription, null, null, null); + } + + /** + * Constructor + *

+ * Any parameter can be null + *

+ * + * @param label + * The entry's name + * @param shortDescription + * The entry's description + * @param type + * The entry's type + */ + public PaletteEntry(String label, String shortDescription, Object type) { + this(label, shortDescription, null, null, type); + } + + /** + * Constructor + *

+ * Any parameter can be null + *

+ * + * @param label + * The entry's name + * @param shortDescription + * The entry's description + * @param iconSmall + * The small icon to represent this entry + * @param iconLarge + * The large icon to represent this entry + */ + public PaletteEntry(String label, String shortDescription, + ImageDescriptor iconSmall, ImageDescriptor iconLarge) { + this(label, shortDescription, iconSmall, iconLarge, null); + } + + /** + * Constructor + *

+ * Any parameter can be null + *

+ * + * @param label + * The entry's name + * @param shortDescription + * The entry's description + * @param iconSmall + * The small icon to represent this entry + * @param iconLarge + * The large icon to represent this entry + * @param type + * The entry's type + */ + public PaletteEntry(String label, String shortDescription, + ImageDescriptor iconSmall, ImageDescriptor iconLarge, Object type) { + this(label, shortDescription, iconSmall, iconLarge, type, null); + } + + /** + * Constructor + *

+ * Any parameter can be null + *

+ * + * @param label + * The entry's name + * @param shortDescription + * The entry's description + * @param smallIcon + * The small icon to represent this entry + * @param largeIcon + * The large icon to represent this entry + * @param type + * The entry's type + * @param id + * The entry's id (preferrably unique) + */ + public PaletteEntry(String label, String shortDescription, + ImageDescriptor smallIcon, ImageDescriptor largeIcon, Object type, + String id) { + setLabel(label); + setDescription(shortDescription); + setSmallIcon(smallIcon); + setLargeIcon(largeIcon); + setType(type); + setId(id); + } + + /** + * A listener can only be added once. Adding it more than once will do nothing. + * + * @param listener + * the PropertyChangeListener that is to be notified of changes + * @see java.beans.PropertyChangeSupport#addPropertyChangeListener(java.beans.PropertyChangeListener) + */ + public void addPropertyChangeListener(PropertyChangeListener listener) { + listeners.removePropertyChangeListener(listener); + listeners.addPropertyChangeListener(listener); + } + + /** + * @return a short desecription describing this entry. + */ + public String getDescription() { + return shortDescription; + } + + /** + * Returns the id. If no ID has been set (or it is null), an empty String will be + * returned. + * + * @return String id + */ + public String getId() { + if (id == null) + return ""; //$NON-NLS-1$ + return id; + } + + /** + * @return the label for this entry. + */ + public String getLabel() { + return label; + } + + /** + * @return a large icon representing this entry. + */ + public ImageDescriptor getLargeIcon() { + return iconLarge; + } + + /** + * @return the parent container of this entry + */ + public PaletteContainer getParent() { + return parent; + } + + /** + * @return a small icon representing the entry. + */ + public ImageDescriptor getSmallIcon() { + return iconSmall; + } + + /** + * @return the type of this entry. Useful for different interpretations of the palette model. + */ + public Object getType() { + return type; + } + + /** + * Returned values are from amongst the following: + *
    + *
  • PERMISSION_NO_MODIFICATION
  • + *
  • PERMISSION_HIDE_ONLY
  • + *
  • PERMISSION_LIMITED_MODIFICATION
  • + *
  • PERMISSION_FULL_MODIFICATION
  • + *
+ * + * @return the permission level for this entry. + * @see #setUserModificationPermission(int) + */ + public int getUserModificationPermission() { + return permission; + } + + /** + * @return whether or not this entry is visible. An entry that is not visible is not shown on + * the palette. + */ + public boolean isVisible() { + return visible; + } + + /** + * @param listener + * the PropertyChangeListener that is not to be notified anymore + * @see java.beans.PropertyChangeSupport#removePropertyChangeListener(java.beans.PropertyChangeListener) + */ + public void removePropertyChangeListener(PropertyChangeListener listener) { + listeners.removePropertyChangeListener(listener); + } + + /** + * Mutator method for description + * + * @param s + * The new description + */ + public void setDescription(String s) { + if (s == null && shortDescription == null) { + return; + } + + if (s == null || !s.equals(shortDescription)) { + String oldDescrption = shortDescription; + shortDescription = s; + listeners.firePropertyChange(PROPERTY_DESCRIPTION, oldDescrption, + shortDescription); + } + } + + /** + * Sets the id. Can be null. + * + * @param id + * The new id to be set + */ + public void setId(String id) { + this.id = id; + } + + /** + * Mutator method for label + * + * @param s + * The new name + */ + public void setLabel(String s) { + if (s == null && label == null) { + return; + } + + if (s == null || !s.equals(label)) { + String oldLabel = label; + label = s; + listeners.firePropertyChange(PROPERTY_LABEL, oldLabel, label); + } + } + + /** + * Mutator method for large icon + * + * @param icon + * The large icon to represent this entry + */ + public void setLargeIcon(ImageDescriptor icon) { + if (icon != iconLarge) { + ImageDescriptor oldIcon = iconLarge; + iconLarge = icon; + listeners.firePropertyChange(PROPERTY_LARGE_ICON, oldIcon, + iconLarge); + } + } + + /** + * Sets the parent of this entry + * + * @param newParent + * The parent PaletteContainer + */ + public void setParent(PaletteContainer newParent) { + if (parent != newParent) { + PaletteContainer oldParent = parent; + parent = newParent; + listeners.firePropertyChange(PROPERTY_PARENT, oldParent, parent); + } + } + + /** + * Mutator method for small icon + * + * @param icon + * The new small icon to represent this entry + */ + public void setSmallIcon(ImageDescriptor icon) { + if (icon != iconSmall) { + ImageDescriptor oldIcon = iconSmall; + iconSmall = icon; + listeners.firePropertyChange(PROPERTY_SMALL_ICON, oldIcon, icon); + } + } + + /** + * Mutator method for type + * + * @param newType + * The new type + */ + public void setType(Object newType) { + if (newType == null && type == null) { + return; + } + + if (type == null || !type.equals(newType)) { + Object oldType = type; + type = newType; + listeners.firePropertyChange(PROPERTY_TYPE, oldType, type); + } + } + + /** + * Permissions are not checked before making modifications. Clients should check the permission + * before invoking a modification. Sub-classes may extend the set of permissions. Current set + * has: + *
    + *
  • PERMISSION_NO_MODIFICATION
  • + *
  • PERMISSION_HIDE_ONLY
  • + *
  • PERMISSION_LIMITED_MODIFICATION
  • + *
  • PERMISSION_FULL_MODIFICATION
  • + *
+ * Default is PERMISSION_FULL_MODIFICATION + * + * @param permission + * One of the above-specified permission levels + */ + public void setUserModificationPermission(int permission) { + this.permission = permission; + } + + /** + * Makes this entry visible or invisible. An invisible entry does not show up on the palette. + * + * @param newVal + * The new boolean indicating whether the entry is visible or not + */ + public void setVisible(boolean newVal) { + if (newVal != visible) { + visible = newVal; + listeners.firePropertyChange(PROPERTY_VISIBLE, !visible, visible); + } + } + + /** + * @see java.lang.Object#toString() + */ + public String toString() { + return "Palette Entry (" + (label != null ? label : "") //$NON-NLS-2$//$NON-NLS-1$ + + ")"; //$NON-NLS-1$ + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteGroup.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteGroup.java new file mode 100644 index 0000000..2785284 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteGroup.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.palette; + +import java.util.List; + + +/** + * A PaletteGroup consists of a group of {@link org.eclipse.gef.palette.PaletteEntry} objects that + * are uncollapsible . The user modification level is set to + * {@link PaletteEntry#PERMISSION_NO_MODIFICATION}, meaning that the entries cannot be reordered. + */ +public class PaletteGroup extends PaletteContainer { + + /** Type Identifier **/ + public static final String PALETTE_TYPE_GROUP = "Palette_Group";//$NON-NLS-1$ + + /** + * Creates a new PaletteGroup with the given label + * + * @param label + * the label + */ + public PaletteGroup(String label) { + super(label, null, null, PALETTE_TYPE_GROUP); + setUserModificationPermission(PERMISSION_NO_MODIFICATION); + } + + /** + * Creates a new PaletteGroup with the given label and list of {@link PaletteEntry Palette + * Entries}. + * + * @param label + * the label + * @param children + * the list of PaletteEntry children + */ + public PaletteGroup(String label, List children) { + this(label); + addAll(children); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteListener.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteListener.java new file mode 100644 index 0000000..3cb55ee --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteListener.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.palette; + +import java.util.EventListener; + +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewer; + + +/** + * Listens to changes in the palette. + */ +public interface PaletteListener extends EventListener { + + /** + * A new tool was activated in the palette. + * + * @param palette + * the source of the change + * @param tool + * the new tool that was activated + */ + void activeToolChanged(PaletteViewer palette, ToolEntry tool); + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteRoot.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteRoot.java new file mode 100644 index 0000000..6f1a0bd --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteRoot.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.palette; + +/** + * Serves as the root {@link org.eclipse.gef.palette.PaletteEntry} for the palette model. + */ +public class PaletteRoot extends PaletteContainer { + + /** Type Identifier **/ + public static String PALETTE_TYPE_ROOT = "Palette_Root";//$NON-NLS-1$ + private ToolEntry defaultEntry; + + /** + * Creates a new PaletteRoot. + */ + public PaletteRoot() { + super(null, null, null, PALETTE_TYPE_ROOT); + } + + /** + * @see org.eclipse.gef.palette.PaletteContainer#acceptsType(java.lang.Object) + */ + public boolean acceptsType(Object type) { + if (type.equals(ToolEntry.PALETTE_TYPE_TOOL) + || type.equals(PaletteStack.PALETTE_TYPE_STACK)) + return false; + return super.acceptsType(type); + } + + /** + * @return the default ToolEntry + */ + public ToolEntry getDefaultEntry() { + return defaultEntry; + } + + /** + * Sets the default entry to the passed value. This ToolEntry represents the tool that will be + * loaded by default. + * + * @param entry + * the default entry + */ + public void setDefaultEntry(ToolEntry entry) { + this.defaultEntry = entry; + } + + /** + * @see Object#toString() + */ + public String toString() { + return "Palette Root"; //$NON-NLS-1$ + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteSeparator.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteSeparator.java new file mode 100644 index 0000000..7de0497 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteSeparator.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.palette; + +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteMessages; + + +/** + * A separator for the palette
+ *
+ * Separators can also be used as markers. Palettes that expect external code to add entries to it + * can use such markers to indicate where those new entries should be added. For this to happen, a + * separator must be uniquely identified. Unless a separator is not a marker, it is recommended that + * it be given a unique ID. + * + * @author Pratik Shah + */ +public class PaletteSeparator extends PaletteEntry { + + /** Type identifier **/ + public static final Object PALETTE_TYPE_SEPARATOR = "$Palette Separator";//$NON-NLS-1$ + + /** + * Creates a new PaletteSeparator with an empty string as its identifier. + */ + public PaletteSeparator() { + this(""); //$NON-NLS-1$ + } + + /** + * Constructor + * + * @param id + * This Separator's unique ID + */ + public PaletteSeparator(String id) { + super(PaletteMessages.NEW_SEPARATOR_LABEL, "", PALETTE_TYPE_SEPARATOR);//$NON-NLS-1$ + setId(id); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteStack.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteStack.java new file mode 100644 index 0000000..a994419 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteStack.java @@ -0,0 +1,197 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.palette; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.jface.resource.ImageDescriptor; + + +/** + * The model object for a PaletteStack - A stack of tools. A stack should contain only tools and + * should have permissions that are less than or equal to its parent. + * + * @author Whitney Sorenson + * @since 3.0 + */ +public class PaletteStack extends PaletteContainer { + + /** + * Listens to visibility changes of the children palette entries so that the active entry can be + * updated if the current active entry is hidden. + */ + private PropertyChangeListener childListener = new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getPropertyName().equals(PaletteEntry.PROPERTY_VISIBLE) + && evt.getNewValue() == Boolean.FALSE + && activeEntry == evt.getSource()) { + checkActiveEntry(); + } + } + }; + + /** Type identifier **/ + public static final String PALETTE_TYPE_STACK = "$PaletteStack"; //$NON-NLS-1$ + + /** Property name for the active entry **/ + public static final String PROPERTY_ACTIVE_ENTRY = "Active Entry"; //$NON-NLS-1$ + + private PaletteEntry activeEntry; + + /** + * Creates a new PaletteStack with the given name, description, and icon. These will be shown + * only in the customize menu. Any of the given parameter can be null. + * + * @param name + * the stack's name + * @param desc + * the stack's description + * @param icon + * an ImageDescriptor for the stack's small icon + * @see PaletteContainer#PaletteContainer(String, String, ImageDescriptor, Object) + */ + public PaletteStack(String name, String desc, ImageDescriptor icon) { + super(name, desc, icon, PALETTE_TYPE_STACK); + setUserModificationPermission(PERMISSION_LIMITED_MODIFICATION); + } + + /** + * Returns true if this type can be a child of this container Only accepts ToolEntry's. + * + * @param type + * the type being requested + * @return true if this can be a child of this container + */ + public boolean acceptsType(Object type) { + if (!type.equals(ToolEntry.PALETTE_TYPE_TOOL)) + return false; + return super.acceptsType(type); + } + + /** + * @see org.eclipse.gef.palette.PaletteContainer#add(int, org.eclipse.gef.palette.PaletteEntry) + */ + public void add(int index, PaletteEntry entry) { + super.add(index, entry); + checkActiveEntry(); + } + + /** + * @see org.eclipse.gef.palette.PaletteContainer#addAll(java.util.List) + */ + public void addAll(List list) { + super.addAll(list); + checkActiveEntry(); + updateListeners(list, true); + } + + /** + * Checks to make sure the active entry is up-to-date and sets it to the first child if it is + * null. + */ + private void checkActiveEntry() { + PaletteEntry currEntry = activeEntry; + if (!getChildren().contains(activeEntry)) + activeEntry = null; + if (activeEntry == null && getChildren().size() > 0) + activeEntry = (PaletteEntry) getChildren().get(0); + if (activeEntry != null && !activeEntry.isVisible()) { + for (Iterator iterator = getChildren().iterator(); iterator + .hasNext();) { + PaletteEntry child = (PaletteEntry) iterator.next(); + if (child.isVisible()) { + activeEntry = child; + break; + } + activeEntry = null; + } + } + listeners.firePropertyChange(PROPERTY_ACTIVE_ENTRY, currEntry, + activeEntry); + } + + /** + * Returns the PaletteEntry referring to the active entry that should be shown in the palette. + * + * @return active entry to be shown in the palette. + */ + public PaletteEntry getActiveEntry() { + checkActiveEntry(); + return activeEntry; + } + + /** + * @see org.eclipse.gef.palette.PaletteContainer#remove(org.eclipse.gef.palette.PaletteEntry) + */ + public void remove(PaletteEntry entry) { + super.remove(entry); + checkActiveEntry(); + updateListeners(Collections.singletonList(entry), false); + } + + /** + * Sets the "active" child entry to the given PaletteEntry. This entry will be shown on the + * palette and will be checked in the menu. + * + * @param entry + * the entry to show on the palette. + */ + public void setActiveEntry(PaletteEntry entry) { + PaletteEntry oldEntry = activeEntry; + if (activeEntry != null + && (activeEntry.equals(entry) || !getChildren().contains(entry))) + return; + activeEntry = entry; + listeners.firePropertyChange(PROPERTY_ACTIVE_ENTRY, oldEntry, + activeEntry); + } + + public void add(PaletteEntry entry) { + super.add(entry); + updateListeners(Collections.singletonList(entry), true); + } + + public void setChildren(List list) { + updateListeners(getChildren(), false); + super.setChildren(list); + updateListeners(getChildren(), true); + checkActiveEntry(); + } + + /** + * Either adds or remove the childListener to each palette entry in the collection. + * + * @param entries + * a collection of PaletteEntries + * @param add + * true if the lister should be added; false if it should be removed + */ + private void updateListeners(Collection entries, boolean add) { + for (Iterator iterator = entries.iterator(); iterator.hasNext();) { + PaletteEntry child = (PaletteEntry) iterator.next(); + if (add) { + child.addPropertyChangeListener(childListener); + } else { + child.removePropertyChangeListener(childListener); + } + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteTemplateEntry.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteTemplateEntry.java new file mode 100644 index 0000000..a0b1a58 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteTemplateEntry.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.palette; + +import org.eclipse.jface.resource.ImageDescriptor; + + +/** + * @author Eric Bordeau + */ +public class PaletteTemplateEntry extends PaletteEntry { + + private Object template; + + /** Type identifier **/ + public static final String PALETTE_TYPE_TEMPLATE = "$Palette Template"; //$NON-NLS-1$ + + /** + * Creates a new PaletteTemplateEntry with the given template. + * + * @param label + * the entry's name + * @param shortDesc + * the entry's description + * @param template + * the template for this entry + * @param iconSmall + * an ImageDescriptor for the entry's small icon + * @param iconLarge + * an ImageDescriptor for the entry's large icon + * @see PaletteEntry#PaletteEntry(String, String, ImageDescriptor, ImageDescriptor, Object) + */ + public PaletteTemplateEntry(String label, String shortDesc, + Object template, ImageDescriptor iconSmall, + ImageDescriptor iconLarge) { + super(label, shortDesc, iconSmall, iconLarge, PALETTE_TYPE_TEMPLATE); + setTemplate(template); + } + + /** + * @return the user-defined template object + */ + public Object getTemplate() { + return template; + } + + /** + * Sets the template object to the given value + * + * @param template + * the template object + */ + public void setTemplate(Object template) { + this.template = template; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteToolbar.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteToolbar.java new file mode 100644 index 0000000..5e49e6c --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PaletteToolbar.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2008, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.palette; + +import java.util.List; + + +/** + * A PaletteGroup consists of a group of {@link org.eclipse.gef.palette.PaletteEntry} objects that + * are uncollapsible . The user modification level is set to + * {@link PaletteEntry#PERMISSION_NO_MODIFICATION}, meaning that the entries cannot be reordered. + * + * @author crevells + * @since 3.4 + */ +public class PaletteToolbar extends PaletteContainer { + + /** + * Type Identifier for a palette group that looks like a toolbar and only supports icons mode. + * + * @since 3.4 + */ + public static final String PALETTE_TYPE_TOOLBAR_GROUP = "Palette_Toolbar_Group";//$NON-NLS-1$ + + /** + * Creates a new PaletteGroup with the given label + * + * @param label + * the label + */ + public PaletteToolbar(String label) { + super(label, null, null, PALETTE_TYPE_TOOLBAR_GROUP); + setUserModificationPermission(PERMISSION_NO_MODIFICATION); + } + + /** + * Creates a new PaletteGroup with the given label and list of {@link PaletteEntry Palette + * Entries}. + * + * @param label + * the label + * @param children + * the list of PaletteEntry children + */ + public PaletteToolbar(String label, List children) { + this(label); + addAll(children); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PanningSelectionToolEntry.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PanningSelectionToolEntry.java new file mode 100644 index 0000000..45268a6 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/PanningSelectionToolEntry.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.palette; + +import org.eclipse.gef.tools.PanningSelectionTool; + + +/** + * A ToolEntry for a {@link PanningSelectionTool}. + * + * @author msorens + * @since 3.0 + */ +public class PanningSelectionToolEntry extends SelectionToolEntry { + + /** + * Creates a new PanningSelectionToolEntry. + */ + public PanningSelectionToolEntry() { + this(null); + } + + /** + * Constructor for PanningSelectionToolEntry. + * + * @param label + * the label + */ + public PanningSelectionToolEntry(String label) { + this(label, null); + } + + /** + * Constructor for PanningSelectionToolEntry. + * + * @param label + * the label + * @param shortDesc + * the description + */ + public PanningSelectionToolEntry(String label, String shortDesc) { + super(label, shortDesc); + setToolClass(PanningSelectionTool.class); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/SelectionToolEntry.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/SelectionToolEntry.java new file mode 100644 index 0000000..890cb53 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/SelectionToolEntry.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.palette; + +import org.eclipse.gef.SharedImages; +import org.eclipse.gef.internal.GEFMessages; +import org.eclipse.gef.tools.SelectionTool; + + +/** + * A ToolEntry for a {@link SelectionTool}. + * + * @author hudsonr + * @since 2.1 + */ +public class SelectionToolEntry extends ToolEntry { + + /** + * Creates a new SelectionToolEntry. + */ + public SelectionToolEntry() { + this(null); + } + + /** + * Constructor for SelectionToolEntry. + * + * @param label + * the label + */ + public SelectionToolEntry(String label) { + this(label, null); + } + + /** + * Constructor for SelectionToolEntry. + * + * @param label + * the label + * @param shortDesc + * the description + */ + public SelectionToolEntry(String label, String shortDesc) { + super(label, shortDesc, SharedImages.DESC_SELECTION_TOOL_16, + SharedImages.DESC_SELECTION_TOOL_24, SelectionTool.class); + if (label == null || label.length() == 0) + setLabel(GEFMessages.SelectionTool_Label); + setUserModificationPermission(PERMISSION_NO_MODIFICATION); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/ToolEntry.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/ToolEntry.java new file mode 100644 index 0000000..c6b313f --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/ToolEntry.java @@ -0,0 +1,150 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.palette; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.gef.Tool; +import org.eclipse.jface.resource.ImageDescriptor; + + +/** + * A factory for returning Tools. + */ +public abstract class ToolEntry extends PaletteEntry { + + /** Type Identifier **/ + public static final Object PALETTE_TYPE_TOOL = "$Palette Tool";//$NON-NLS-1$ + + private Map map; + private Class toolClass; + + /** + * Creates a new ToolEntry. Any parameter can be null. + * + * @param label + * the entry's name + * @param shortDesc + * the entry's description + * @param iconSmall + * the entry's small icon + * @param iconLarge + * the entry's large icon + */ + public ToolEntry(String label, String shortDesc, ImageDescriptor iconSmall, + ImageDescriptor iconLarge) { + this(label, shortDesc, iconSmall, iconLarge, null); + } + + /** + * Constructor to create a new ToolEntry. Any parameter can be null. + * + * @param label + * the entry's name + * @param description + * the entry's description + * @param iconSmall + * the entry's small icon + * @param iconLarge + * the entry's large icon + * @param tool + * the type of tool that this entry uses + * @since 3.1 + */ + public ToolEntry(String label, String description, + ImageDescriptor iconSmall, ImageDescriptor iconLarge, Class tool) { + super(label, description, iconSmall, iconLarge, PALETTE_TYPE_TOOL); + setToolClass(tool); + } + + /** + * Creates the tool of the type specified by {@link #setToolClass(Class)} for this ToolEntry. + * The tool is also configured with the properties set in + * {@link #setToolProperty(Object, Object)}. Sub-classes overriding this method should ensure + * that their tools are also configured with those properties. + * + * @return the tool for this entry + */ + public Tool createTool() { + if (toolClass == null) + return null; + Tool tool; + try { + tool = (Tool) toolClass.newInstance(); + } catch (IllegalAccessException iae) { + return null; + } catch (InstantiationException ie) { + return null; + } + tool.setProperties(getToolProperties()); + return tool; + } + + /** + * @return the properties set in {@link #setToolProperty(Object, Object)} + * @since 3.1 + */ + protected Map getToolProperties() { + return map; + } + + /** + * Returns the property value for the specified property key. + * + * @param key + * the property key + * @return the value for the requested property + * @since 3.1 + */ + public Object getToolProperty(Object key) { + if (map != null) + return map.get(key); + return null; + } + + /** + * Sets the type of tool to be created. This provides clients with a method of specifying a + * different type of tool to be created without having to sub-class. The provided class should + * have a default constructor for this to work successfully. + * + * @param toolClass + * the type of tool to be created by this entry + * @since 3.1 + */ + public void setToolClass(Class toolClass) { + if (toolClass != null) + Assert.isTrue(Tool.class.isAssignableFrom(toolClass)); + this.toolClass = toolClass; + } + + /** + * Clients can use this method to configure the associated tool without having to sub-class. + * + * @param key + * the property name + * @param value + * a value of type associated with the given property + * @since 3.1 + * @see Tool#setProperties(Map) + */ + public void setToolProperty(Object key, Object value) { + if (map == null) + map = new HashMap(); + map.put(key, value); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/package.html b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/package.html new file mode 100644 index 0000000..132550d --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/palette/package.html @@ -0,0 +1,22 @@ + + + + + + + + + +This package defines and implements the model used by the +{@link org.eclipse.gef.ui.palette.PaletteViewer PaletteViewer}. + + + diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ruler/DesignEditorRulerComposite.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ruler/DesignEditorRulerComposite.java new file mode 100644 index 0000000..c1e1a80 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ruler/DesignEditorRulerComposite.java @@ -0,0 +1,663 @@ +/******************************************************************************* + * Copyright (c) 2003, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-06-17 Jihoon Song (jihoon.song@samsung.com) + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * - set custom EditPartFactory to RulerViewer + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ruler; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.ArrayList; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.draw2d.AbstractBorder; +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.DefaultRangeModel; +import org.eclipse.draw2d.FigureCanvas; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.draw2d.RangeModel; +import org.eclipse.draw2d.Viewport; +import org.eclipse.draw2d.geometry.Insets; +import org.eclipse.gef.DragTracker; +import org.eclipse.gef.EditDomain; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.GraphicalViewer; +import org.eclipse.gef.Handle; +import org.eclipse.gef.RootEditPart; +import org.eclipse.gef.internal.ui.rulers.GuideEditPart; +import org.eclipse.gef.internal.ui.rulers.RulerContextMenuProvider; +import org.eclipse.gef.internal.ui.rulers.RulerEditPart; +import org.eclipse.gef.internal.ui.rulers.RulerRootEditPart; +import org.eclipse.gef.rulers.RulerProvider; +import org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler; +import org.eclipse.gef.ui.parts.ScrollingGraphicalViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.tizen.efluibuilder.ui.editor.ruler.DesignEditorRulerEditPartFactory; + + +/** + * A RulerComposite is used to show rulers to the north and west of the control + * of a given {@link #setGraphicalViewer(ScrollingGraphicalViewer) graphical + * viewer}. The rulers will be shown based on whether or not + * {@link org.eclipse.gef.rulers.RulerProvider#PROPERTY_HORIZONTAL_RULER + * horizontal ruler} and + * {@link org.eclipse.gef.rulers.RulerProvider#PROPERTY_VERTICAL_RULER vertical + * ruler} properties are set on the given viewer, and the value of the + * {@link org.eclipse.gef.rulers.RulerProvider#PROPERTY_RULER_VISIBILITY + * visibility} property. + * + * @author Pratik Shah + * @since 3.0 + */ +public class DesignEditorRulerComposite extends Composite { + + private EditDomain rulerEditDomain; + private GraphicalViewer left, top; + private FigureCanvas editor; + private GraphicalViewer diagramViewer; + private Font font; + private Listener layoutListener; + private PropertyChangeListener propertyListener; + private boolean layingOut = false; + private boolean isRulerVisible = true; + private boolean needToLayout = false; + private Runnable runnable = new Runnable() { + public void run() { + layout(false); + } + }; + + /** + * Constructor + * + * @param parent + * a widget which will be the parent of the new instance (cannot + * be null) + * @param style + * the style of widget to construct + * @see Composite#Composite(org.eclipse.swt.widgets.Composite, int) + */ + public DesignEditorRulerComposite(Composite parent, int style) { + super(parent, style); + addDisposeListener(new DisposeListener() { + public void widgetDisposed(DisposeEvent e) { + disposeResources(); + } + }); + } + + /** + * Calculates the proper trim. Includes scrollbars' sizes only if they're + * visible. + * + * @param canvas + * The canvas. + * @since 3.6 + */ + public static Rectangle calculateEditorTrim(Canvas canvas) { + /* + * Workaround for Bug# 87712 Calculating the trim using the clientArea. + */ + Rectangle bounds = canvas.getBounds(); + Rectangle clientArea = canvas.getClientArea(); + Rectangle result = new Rectangle(0, 0, bounds.width - clientArea.width, + bounds.height - clientArea.height); + if (result.width != 0 || result.height != 0) { + Rectangle trim = canvas.computeTrim(0, 0, 0, 0); + result.x = result.height == 0 ? 0 : trim.x; + result.y = result.width == 0 ? 0 : trim.y; + } + return result; + } + + /** + * Calculates the proper trim for the ruler. + * + * @param canvas + * The canvas. + * @since 3.6 + */ + public static Rectangle calculateRulerTrim(Canvas canvas) { + // IMPORTANT: As stated in bug #314750, this is a Mac Carbon related + // workaround that is not needed on Cocoa. + if ("carbon".equals(SWT.getPlatform())) { //$NON-NLS-1$ + Rectangle trim = canvas.computeTrim(0, 0, 0, 0); + trim.width = 0 - trim.x * 2; + trim.height = 0 - trim.y * 2; + return trim; + } + return new Rectangle(0, 0, 0, 0); + } + + private GraphicalViewer createRulerContainer(int orientation) { + ScrollingGraphicalViewer viewer = new RulerViewer(); + final boolean isHorizontal = orientation == PositionConstants.NORTH + || orientation == PositionConstants.SOUTH; + + // Finish initializing the viewer + viewer.setRootEditPart(new RulerRootEditPart(isHorizontal)); + viewer.setEditPartFactory(new DesignEditorRulerEditPartFactory(diagramViewer)); + viewer.createControl(this); + ((GraphicalEditPart) viewer.getRootEditPart()).getFigure().setBorder( + new RulerBorder(isHorizontal)); + viewer.setProperty(GraphicalViewer.class.toString(), diagramViewer); + + // Configure the viewer's control + FigureCanvas canvas = (FigureCanvas) viewer.getControl(); + canvas.setScrollBarVisibility(FigureCanvas.NEVER); + if (font == null) { + FontData[] data = canvas.getFont().getFontData(); + for (int i = 0; i < data.length; i++) { + data[i].setHeight(data[i].getHeight() - 1); + } + font = new Font(Display.getCurrent(), data); + } + canvas.setFont(font); + if (isHorizontal) { + canvas.getViewport().setHorizontalRangeModel( + editor.getViewport().getHorizontalRangeModel()); + } else { + canvas.getViewport().setVerticalRangeModel( + editor.getViewport().getVerticalRangeModel()); + } + + // Add the viewer to the rulerEditDomain + if (rulerEditDomain == null) { + rulerEditDomain = new EditDomain(); + rulerEditDomain.setCommandStack(diagramViewer.getEditDomain() + .getCommandStack()); + } + rulerEditDomain.addViewer(viewer); + + return viewer; + } + + private void disposeResources() { + if (diagramViewer != null) + diagramViewer.removePropertyChangeListener(propertyListener); + if (font != null) + font.dispose(); + // layoutListener is not being removed from the scroll bars because they + // are already + // disposed at this point. + } + + private void disposeRulerViewer(GraphicalViewer viewer) { + if (viewer == null) + return; + /* + * There's a tie from the editor's range model to the RulerViewport (via + * a listener) to the RulerRootEditPart to the RulerViewer. Break this + * tie so that the viewer doesn't leak and can be garbage collected. + */ + RangeModel rModel = new DefaultRangeModel(); + Viewport port = ((FigureCanvas) viewer.getControl()).getViewport(); + port.setHorizontalRangeModel(rModel); + port.setVerticalRangeModel(rModel); + rulerEditDomain.removeViewer(viewer); + viewer.getControl().dispose(); + } + + /** + * Perform the ruler layout. + * + * @since 3.6 + */ + public void doLayout() { + if (left == null && top == null) { + Rectangle area = getClientArea(); + if (editor != null && !editor.isDisposed() + && !editor.getBounds().equals(area)) + editor.setBounds(area); + return; + } + + int leftWidth = 0, topHeight = 0; + Rectangle leftTrim = null, topTrim = null; + if (left != null) { + leftTrim = calculateRulerTrim((Canvas) left.getControl()); + // Adding the trim width here because FigureCanvas#computeSize() + // does not + leftWidth = left.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT).x + + leftTrim.width; + } + if (top != null) { + topTrim = calculateRulerTrim((Canvas) top.getControl()); + topHeight = top.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT).y + + topTrim.height; + } + + Rectangle editorSize = getClientArea(); + editorSize.x = leftWidth; + editorSize.y = topHeight; + editorSize.width -= leftWidth; + editorSize.height -= topHeight; + editor.setBounds(editorSize); + + /* + * Fix for Bug# 67554 Take trim into account. Some platforms (such as + * MacOS and Motif) leave some trimming around some canvasses. + */ + Rectangle trim = calculateEditorTrim(editor); + if (left != null && leftTrim != null) { + // The - 1 and + 1 are to compensate for the RulerBorder + left.getControl().setBounds(0, topHeight - trim.x + leftTrim.x - 1, + leftWidth, + editorSize.height - trim.height + leftTrim.height + 1); + } + if (top != null && topTrim != null) { + top.getControl().setBounds(leftWidth - trim.y + topTrim.y - 1, 0, + editorSize.width - trim.width + topTrim.width + 1, + topHeight); + } + } + + private GraphicalViewer getRulerContainer(int orientation) { + GraphicalViewer result = null; + switch (orientation) { + case PositionConstants.NORTH: + result = top; + break; + case PositionConstants.WEST: + result = left; + } + return result; + } + + /** + * @see org.eclipse.swt.widgets.Composite#layout(boolean) + */ + public void layout(boolean change) { + if (!layingOut && !isDisposed()) { + checkWidget(); + if (change || needToLayout) { + needToLayout = false; + layingOut = true; + doLayout(); + layingOut = false; + } + } + } + + /** + * Creates rulers for the given graphical viewer. + *

+ * The primaryViewer or its Control cannot be null. The + * primaryViewer's Control should be a FigureCanvas and a child of this + * Composite. This method should only be invoked once. + *

+ * To create ruler(s), simply add the RulerProvider(s) (with the right key: + * RulerProvider.PROPERTY_HORIZONTAL_RULER or + * RulerProvider.PROPERTY_VERTICAL_RULER) as a property on the given viewer. + * It can be done after this method is invoked. + * RulerProvider.PROPERTY_RULER_VISIBILITY can be used to show/hide the + * rulers. + * + * @param primaryViewer + * The graphical viewer for which the rulers have to be created + */ + public void setGraphicalViewer(ScrollingGraphicalViewer primaryViewer) { + // pre-conditions + Assert.isNotNull(primaryViewer); + Assert.isNotNull(primaryViewer.getControl()); + Assert.isTrue(diagramViewer == null); + + diagramViewer = primaryViewer; + editor = (FigureCanvas) diagramViewer.getControl(); + + // layout whenever the scrollbars are shown or hidden, and whenever the + // RulerComposite + // is resized + layoutListener = new Listener() { + public void handleEvent(Event event) { + // @TODO:Pratik If you use Display.asyncExec(runnable) here, + // some flashing + // occurs. You can see it when the palette is in the editor, and + // you hit + // the button to show/hide it. + layout(true); + } + }; + addListener(SWT.Resize, layoutListener); + editor.getHorizontalBar().addListener(SWT.Show, layoutListener); + editor.getHorizontalBar().addListener(SWT.Hide, layoutListener); + editor.getVerticalBar().addListener(SWT.Show, layoutListener); + editor.getVerticalBar().addListener(SWT.Hide, layoutListener); + + propertyListener = new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent evt) { + String property = evt.getPropertyName(); + if (RulerProvider.PROPERTY_HORIZONTAL_RULER.equals(property)) { + setRuler( + (RulerProvider) diagramViewer + .getProperty(RulerProvider.PROPERTY_HORIZONTAL_RULER), + PositionConstants.NORTH); + } else if (RulerProvider.PROPERTY_VERTICAL_RULER + .equals(property)) { + setRuler( + (RulerProvider) diagramViewer + .getProperty(RulerProvider.PROPERTY_VERTICAL_RULER), + PositionConstants.WEST); + } else if (RulerProvider.PROPERTY_RULER_VISIBILITY + .equals(property)) + setRulerVisibility(((Boolean) diagramViewer + .getProperty(RulerProvider.PROPERTY_RULER_VISIBILITY)) + .booleanValue()); + } + }; + diagramViewer.addPropertyChangeListener(propertyListener); + Boolean rulerVisibility = (Boolean) diagramViewer + .getProperty(RulerProvider.PROPERTY_RULER_VISIBILITY); + if (rulerVisibility != null) + setRulerVisibility(rulerVisibility.booleanValue()); + setRuler( + (RulerProvider) diagramViewer + .getProperty(RulerProvider.PROPERTY_HORIZONTAL_RULER), + PositionConstants.NORTH); + setRuler( + (RulerProvider) diagramViewer + .getProperty(RulerProvider.PROPERTY_VERTICAL_RULER), + PositionConstants.WEST); + } + + private void setRuler(RulerProvider provider, int orientation) { + Object ruler = null; + if (isRulerVisible && provider != null) + // provider.getRuler() might return null (at least the API does not + // prevent that) + ruler = provider.getRuler(); + + if (ruler == null) { + // Ruler is not visible or is not present + setRulerContainer(null, orientation); + // Layout right-away to prevent an empty control from showing + layout(true); + return; + } + + GraphicalViewer container = getRulerContainer(orientation); + if (container == null) { + container = createRulerContainer(orientation); + setRulerContainer(container, orientation); + } + if (container.getContents() != ruler) { + container.setContents(ruler); + needToLayout = true; + Display.getCurrent().asyncExec(runnable); + } + } + + private void setRulerContainer(GraphicalViewer container, int orientation) { + if (orientation == PositionConstants.NORTH) { + if (top == container) + return; + disposeRulerViewer(top); + top = container; + } else if (orientation == PositionConstants.WEST) { + if (left == container) + return; + disposeRulerViewer(left); + left = container; + } + } + + private void setRulerVisibility(boolean isVisible) { + if (isRulerVisible != isVisible) { + isRulerVisible = isVisible; + if (diagramViewer != null) { + setRuler( + (RulerProvider) diagramViewer + .getProperty(RulerProvider.PROPERTY_HORIZONTAL_RULER), + PositionConstants.NORTH); + setRuler( + (RulerProvider) diagramViewer + .getProperty(RulerProvider.PROPERTY_VERTICAL_RULER), + PositionConstants.WEST); + } + } + } + + private static class RulerBorder extends AbstractBorder { + private static final Insets H_INSETS = new Insets(0, 1, 0, 0); + private static final Insets V_INSETS = new Insets(1, 0, 0, 0); + private boolean horizontal; + + /** + * Constructor + * + * @param isHorizontal + * whether or not the ruler being bordered is horizontal or + * not + */ + public RulerBorder(boolean isHorizontal) { + horizontal = isHorizontal; + } + + /** + * @see org.eclipse.draw2d.Border#getInsets(org.eclipse.draw2d.IFigure) + */ + public Insets getInsets(IFigure figure) { + return horizontal ? H_INSETS : V_INSETS; + } + + /** + * @see org.eclipse.draw2d.Border#paint(org.eclipse.draw2d.IFigure, + * org.eclipse.draw2d.Graphics, org.eclipse.draw2d.geometry.Insets) + */ + public void paint(IFigure figure, Graphics graphics, Insets insets) { + graphics.setForegroundColor(ColorConstants.buttonDarker); + if (horizontal) { + graphics.drawLine( + figure.getBounds().getTopLeft(), + figure.getBounds() + .getBottomLeft() + .translate( + new org.eclipse.draw2d.geometry.Point( + 0, -4))); + } else { + graphics.drawLine( + figure.getBounds().getTopLeft(), + figure.getBounds() + .getTopRight() + .translate( + new org.eclipse.draw2d.geometry.Point( + -4, 0))); + } + } + } + + /** + * Custom graphical viewer intended to be used for rulers. + * + * @author Pratik Shah + * @since 3.0 + */ + private static class RulerViewer extends ScrollingGraphicalViewer { + /** + * Constructor + */ + public RulerViewer() { + super(); + init(); + } + + /** + * @see org.eclipse.gef.EditPartViewer#appendSelection(org.eclipse.gef.EditPart) + */ + public void appendSelection(EditPart editpart) { + if (editpart instanceof RootEditPart) + editpart = ((RootEditPart) editpart).getContents(); + setFocus(editpart); + super.appendSelection(editpart); + } + + /** + * @see org.eclipse.gef.GraphicalViewer#findHandleAt(org.eclipse.draw2d.geometry.Point) + */ + public Handle findHandleAt(org.eclipse.draw2d.geometry.Point p) { + final GraphicalEditPart gep = (GraphicalEditPart) findObjectAtExcluding( + p, new ArrayList()); + if (gep == null || !(gep instanceof GuideEditPart)) + return null; + return new Handle() { + public DragTracker getDragTracker() { + return ((GuideEditPart) gep).getDragTracker(null); + } + + public org.eclipse.draw2d.geometry.Point getAccessibleLocation() { + return null; + } + }; + } + + /** + * @see org.eclipse.gef.ui.parts.AbstractEditPartViewer#init() + */ + protected void init() { + setContextMenu(new RulerContextMenuProvider(this)); + setKeyHandler(new RulerKeyHandler(this)); + } + + /** + * Requests to reveal a ruler are ignored since that causes undesired + * scrolling to the origin of the ruler + * + * @see org.eclipse.gef.EditPartViewer#reveal(org.eclipse.gef.EditPart) + */ + public void reveal(EditPart part) { + if (part != getContents()) + super.reveal(part); + } + + /** + * + * @see org.eclipse.gef.ui.parts.GraphicalViewerImpl#handleFocusGained(org.eclipse.swt.events.FocusEvent) + */ + protected void handleFocusGained(FocusEvent fe) { + if (focusPart == null) { + setFocus(getContents()); + } + super.handleFocusGained(fe); + } + + /** + * + * @see org.eclipse.gef.ui.parts.GraphicalViewerImpl#handleFocusLost(org.eclipse.swt.events.FocusEvent) + */ + protected void handleFocusLost(FocusEvent fe) { + super.handleFocusLost(fe); + if (focusPart == getContents()) { + setFocus(null); + } + } + + /** + * Custom KeyHandler intended to be used with a RulerViewer + * + * @author Pratik Shah + * @since 3.0 + */ + protected static class RulerKeyHandler extends + GraphicalViewerKeyHandler { + /** + * Constructor + * + * @param viewer + * The viewer for which this handler processes keyboard + * input + */ + public RulerKeyHandler(GraphicalViewer viewer) { + super(viewer); + } + + /** + * @see org.eclipse.gef.KeyHandler#keyPressed(org.eclipse.swt.events.KeyEvent) + */ + public boolean keyPressed(KeyEvent event) { + if (event.keyCode == SWT.DEL) { + // If a guide has focus, delete it + if (getFocusEditPart() instanceof GuideEditPart) { + RulerEditPart parent = (RulerEditPart) getFocusEditPart() + .getParent(); + getViewer() + .getEditDomain() + .getCommandStack() + .execute( + parent.getRulerProvider() + .getDeleteGuideCommand( + getFocusEditPart() + .getModel())); + event.doit = false; + return true; + } + return false; + } else if (((event.stateMask & SWT.ALT) != 0) + && (event.keyCode == SWT.ARROW_UP)) { + // ALT + UP_ARROW pressed + // If a guide has focus, give focus to the ruler + EditPart parent = getFocusEditPart().getParent(); + if (parent instanceof RulerEditPart) + navigateTo(getFocusEditPart().getParent(), event); + return true; + } + return super.keyPressed(event); + } + } + } + + /** + * Retrieve the left ruler graphical viewer. + * + * @return The left ruler graphical viewer. + * @since 3.6 + */ + protected GraphicalViewer getLeft() { + return left; + } + + /** + * Retrieve the top ruler graphical viewer. + * + * @return The top ruler graphical viewer. + * @since 3.6 + */ + protected GraphicalViewer getTop() { + return top; + } + + /** + * Retrieve the editor figure canvas. + * + * @return The editor figure canvas. + * @since 3.6 + */ + protected FigureCanvas getEditor() { + return editor; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/actions/SetActivePaletteToolAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/actions/SetActivePaletteToolAction.java new file mode 100644 index 0000000..6c6422e --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/actions/SetActivePaletteToolAction.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.actions; + +import org.eclipse.gef.EditPart; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.resource.ImageDescriptor; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.ToolEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewer; + + +/** + * This action sets a Tool to be the active entry in the PaletteViewer. + */ +public class SetActivePaletteToolAction extends Action { + + private PaletteViewer viewer; + private ToolEntry entry; + + /** + * Creates a new SetActivePaletteToolAction with the given entry to set, as well as a label, + * icon, and isChecked to be used in a menu. + * + * @param viewer + * the PaletteViewer + * @param label + * the label to show in the menu for this entry. + * @param icon + * the icon to show in the menu for this entry. + * @param isChecked + * whether or not this is the current active entry. + * @param entry + * the entry to set if this action is invoked. + */ + public SetActivePaletteToolAction(PaletteViewer viewer, String label, + ImageDescriptor icon, boolean isChecked, ToolEntry entry) { + super(label, icon); + this.viewer = viewer; + this.entry = entry; + setChecked(isChecked); + } + + /** + * @see org.eclipse.jface.action.IAction#run() + */ + public void run() { + if (viewer != null) { + viewer.setActiveTool(entry); + + // The PaletteViewerKeyHandler will not pick up key events when the + // context menu is open for palette stacks so we need to indicate + // that the focus needs to change to the tool entry that the user + // has just selected. See GraphicalViewerKeyHandler.procesSelect(). + EditPart part = (EditPart) viewer.getEditPartRegistry().get(entry); + viewer.appendSelection(part); + viewer.setFocus(part); + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/ChangeIconSizeAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/ChangeIconSizeAction.java new file mode 100644 index 0000000..6da6fc3 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/ChangeIconSizeAction.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette; + +import org.eclipse.jface.action.Action; + + +/** + * This action toggles the "Use Large Icons" option for the current layout mode of the palette. + * + * @author Pratik Shah + */ +public class ChangeIconSizeAction extends Action { + + private PaletteViewerPreferences prefs; + + /** + * Constructor + * + * @param prefs + * The PaletteViewerPreferences object that this action is manipulating + */ + public ChangeIconSizeAction(PaletteViewerPreferences prefs) { + super(PaletteMessages.SETTINGS_USE_LARGE_ICONS_LABEL_CAPS); + this.prefs = prefs; + setChecked(prefs.useLargeIcons()); + } + + /** + * Toggles the "Use Large Icons" option for the current layout mode. + * + * @see org.eclipse.jface.action.Action#run() + */ + public void run() { + prefs.setCurrentUseLargeIcons(!prefs.useLargeIcons()); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/CustomizeAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/CustomizeAction.java new file mode 100644 index 0000000..7e43d69 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/CustomizeAction.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette; + +import java.util.List; + +import org.eclipse.gef.EditPart; +import org.eclipse.jface.action.Action; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteRoot; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.customize.PaletteCustomizerDialog; + + +/** + * This action launches the PaletteCustomizerDialog for the given palette. + * + * @author Pratik Shah + */ +public class CustomizeAction extends Action { + + private PaletteViewer paletteViewer; + + /** + * Constructor + * + * @param palette + * the palette which has to be customized when this action is run + */ + public CustomizeAction(PaletteViewer palette) { + super(); + setText(PaletteMessages.MENU_OPEN_CUSTOMIZE_DIALOG); + paletteViewer = palette; + } + + /** + * Opens the Customizer Dialog for the palette + * + * @see org.eclipse.jface.action.IAction#run() + */ + public void run() { + PaletteCustomizerDialog dialog = paletteViewer.getCustomizerDialog(); + List list = paletteViewer.getSelectedEditParts(); + if (!list.isEmpty()) { + PaletteEntry selection = (PaletteEntry) ((EditPart) list.get(0)) + .getModel(); + if (!(selection instanceof PaletteRoot)) { + dialog.setDefaultSelection(selection); + } + } + dialog.open(); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/DefaultPaletteViewerPreferences.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/DefaultPaletteViewerPreferences.java new file mode 100644 index 0000000..32be45e --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/DefaultPaletteViewerPreferences.java @@ -0,0 +1,365 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 2016-09-06 Byoungchang Son sonbc121.son@samsung.com + * Modified by S-Core Co.Ltd. + * 1. Internalization of Code in Tizen SDK + * 1) update package name + * 2) apply new UI + * - disable menu items (List and Icons Only) of in the context menu + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; + +import org.eclipse.gef.internal.InternalGEFPlugin; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.swt.graphics.FontData; + + +/** + * This is the default implementation for PaletteViewerPreferences. It uses a single + * IPreferenceStore to load and save the palette viewer settings. + *

+ * It is recommended that the default constructor be used (which will use the preference store in + * the GEF plugin) as that will cause the preferences to be shared across different types of + * editors. If the client does not wish to share one of the existing preferences for their editor + * (say the auto-collapse setting), they will have to sub-class this class and override the + * necessary methods (in this case, {@link #getAutoCollapseSetting()} and + * {@link #setAutoCollapseSetting(int)}) and save that preference in some other preference store. + * Sub-classes can add newer preferences to the store by using {@link #getPreferenceStore()}. + *

+ * + * @author Pratik Shah + */ +public class DefaultPaletteViewerPreferences implements + PaletteViewerPreferences { + + private static final String DEFAULT_FONT = "Default"; //$NON-NLS-1$ + + private PreferenceStoreListener listener; + private IPropertyChangeListener fontListener; + private FontData fontData; + private PropertyChangeSupport listeners = new PropertyChangeSupport(this); + private IPreferenceStore store; + /* ECLIPSE: original menus) { */ + // private int[] supportedModes = { LAYOUT_COLUMNS, LAYOUT_LIST, LAYOUT_ICONS, + // LAYOUT_DETAILS }; + /* } ECLIPSE */ + /* TIZEN: disable menu items (List and Icons Only) of in the context menu { */ + private int[] supportedModes = { LAYOUT_COLUMNS, LAYOUT_DETAILS }; + /* } TIZEN */ + + /** + * Default Constructor + *

+ * Uses the GEF Plugin's IPreferenceStore to store the preferences. + *

+ */ + public DefaultPaletteViewerPreferences() { + this(InternalGEFPlugin.getDefault().getPreferenceStore()); + } + + /** + * Constructor + * + * @param store + * The IPreferenceStore where the settings are to be saved. + */ + public DefaultPaletteViewerPreferences(final IPreferenceStore store) { + this.store = store; + store.setDefault(PREFERENCE_DETAILS_ICON_SIZE, false); + store.setDefault(PREFERENCE_COLUMNS_ICON_SIZE, true); + store.setDefault(PREFERENCE_ICONS_ICON_SIZE, true); + store.setDefault(PREFERENCE_LIST_ICON_SIZE, false); + store.setDefault(PREFERENCE_LAYOUT, LAYOUT_LIST); + store.setDefault(PREFERENCE_AUTO_COLLAPSE, COLLAPSE_AS_NEEDED); + store.setDefault(PREFERENCE_FONT, DEFAULT_FONT); + + listener = new PreferenceStoreListener(); + store.addPropertyChangeListener(listener); + + fontListener = new IPropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + if (JFaceResources.DIALOG_FONT.equals(event.getProperty())) { + if (getPreferenceStore().getString(PREFERENCE_FONT).equals( + DEFAULT_FONT)) { + setFontData(JFaceResources.getDialogFont() + .getFontData()[0]); + handlePreferenceStorePropertyChanged(PREFERENCE_FONT); + } + } + } + }; + JFaceResources.getFontRegistry().addListener(fontListener); + } + + /** + * NOTE: The oldValue field of the PropertyChangeEvent used to notify + * listeners will always be null. + * + * @see org.eclipse.gef.ui.palette.PaletteViewerPreferences#addPropertyChangeListener(PropertyChangeListener) + */ + public void addPropertyChangeListener(PropertyChangeListener listener) { + listeners.addPropertyChangeListener(listener); + } + + /** + * This is a convenience method that converts the given layout mode to the matching preference + * name. + * + *
    + *
  • int <-> String
  • + *
  • LAYOUT_LIST <-> PREFERENCE_LIST_ICON_SIZE
  • + *
  • LAYOUT_COLUMNS <-> PREFERENCE_COLUMNS_ICON_SIZE
  • + *
  • LAYOUT_ICONS <-> PREFERENCE_ICONS_ICON_SIZE
  • + *
  • LAYOUT_DETAILS <-> PREFERENCE_DETAILS_ICON_SIZE
  • + *
+ * + * @param layout + * LAYOUT_LIST, LAYOUT_DETAILS, LAYOUT_COLUMNS, or LAYOUT_ICONS + * @return The corresponding preference String + */ + public static String convertLayoutToPreferenceName(int layout) { + String key = ""; //$NON-NLS-1$ + switch (layout) { + case LAYOUT_COLUMNS: + key = PREFERENCE_COLUMNS_ICON_SIZE; + break; + case LAYOUT_LIST: + key = PREFERENCE_LIST_ICON_SIZE; + break; + case LAYOUT_ICONS: + key = PREFERENCE_ICONS_ICON_SIZE; + break; + case LAYOUT_DETAILS: + key = PREFERENCE_DETAILS_ICON_SIZE; + break; + } + return key; + } + + /** + * This convenience method converts the given preference to the matching layout mode. + * + *
    + *
  • int <-> String
  • + *
  • LAYOUT_LIST <-> PREFERENCE_LIST_ICON_SIZE
  • + *
  • LAYOUT_COLUMNS <-> PREFERENCE_COLUMNS_ICON_SIZE
  • + *
  • LAYOUT_ICONS <-> PREFERENCE_ICONS_ICON_SIZE
  • + *
  • LAYOUT_DETAILS <-> PREFERENCE_DETAILS_ICON_SIZE
  • + *
+ * + * @param preference + * PREFERENCE_DETAILS_ICON_SIZE, PREFERENCE_COLUMNS_ICON_SIZE, + * PREFERENCE_ICONS_ICON_SIZE or PREFERENCE_LIST_ICON_SIZE + * @return The corresponding layout code + */ + public static int convertPreferenceNameToLayout(String preference) { + int layout = -1; + if (preference.equals(PREFERENCE_DETAILS_ICON_SIZE)) { + layout = LAYOUT_DETAILS; + } else if (preference.equals(PREFERENCE_COLUMNS_ICON_SIZE)) { + layout = LAYOUT_COLUMNS; + } else if (preference.equals(PREFERENCE_ICONS_ICON_SIZE)) { + layout = LAYOUT_ICONS; + } else if (preference.equals(PREFERENCE_LIST_ICON_SIZE)) { + layout = LAYOUT_LIST; + } + return layout; + } + + /** + * The oldValue of the PropertyChangeEvent that is fired will always be null. + * + * @param property + * The programmatic name of the property that was changed + * @param newVal + * The new value of the property + * @see java.beans.PropertyChangeSupport#firePropertyChange(java.lang.String, java.lang.Object, + * java.lang.Object) + */ + protected void firePropertyChanged(String property, Object newVal) { + listeners.firePropertyChange(property, null, newVal); + } + + /** + * @see org.eclipse.gef.ui.palette.PaletteViewerPreferences#getAutoCollapseSetting() + */ + public int getAutoCollapseSetting() { + return getPreferenceStore().getInt(PREFERENCE_AUTO_COLLAPSE); + } + + /** + * @see org.eclipse.gef.ui.palette.PaletteViewerPreferences#getFontData() + */ + public FontData getFontData() { + if (fontData == null) { + String value = getPreferenceStore().getString(PREFERENCE_FONT); + if (value.equals(DEFAULT_FONT)) { + fontData = JFaceResources.getDialogFont().getFontData()[0]; + } else { + fontData = new FontData(value); + } + } + return fontData; + } + + /** + * @see org.eclipse.gef.ui.palette.PaletteViewerPreferences#getLayoutSetting() + */ + public int getLayoutSetting() { + return getPreferenceStore().getInt(PREFERENCE_LAYOUT); + } + + /** + * @see org.eclipse.gef.ui.palette.PaletteViewerPreferences#getSupportedLayoutModes() + */ + public int[] getSupportedLayoutModes() { + return supportedModes; + } + + /** + * This method is invoked when the preference store fires a property change. + * + * @param property + * The property String used for the change fired by the preference store + */ + protected void handlePreferenceStorePropertyChanged(String property) { + if (property.equals(PREFERENCE_LAYOUT)) { + firePropertyChanged(property, new Integer(getLayoutSetting())); + } else if (property.equals(PREFERENCE_AUTO_COLLAPSE)) { + firePropertyChanged(property, new Integer(getAutoCollapseSetting())); + } else if (property.equals(PREFERENCE_FONT)) { + firePropertyChanged(property, getFontData()); + } else { + firePropertyChanged(property, new Boolean( + useLargeIcons(convertPreferenceNameToLayout(property)))); + } + } + + /** + * @return The IPreferenceStore used by this class to store the preferences. + */ + protected IPreferenceStore getPreferenceStore() { + return store; + } + + /** + * @see org.eclipse.gef.ui.palette.PaletteViewerPreferences#isSupportedLayoutMode(int) + */ + public boolean isSupportedLayoutMode(int layout) { + for (int i = 0; i < supportedModes.length; i++) { + if (supportedModes[i] == layout) { + return true; + } + } + return false; + } + + /** + * @see org.eclipse.gef.ui.palette.PaletteViewerPreferences#removePropertyChangeListener(PropertyChangeListener) + */ + public void removePropertyChangeListener(PropertyChangeListener listener) { + listeners.removePropertyChangeListener(listener); + } + + /** + * @see org.eclipse.gef.ui.palette.PaletteViewerPreferences#setAutoCollapseSetting(int) + */ + public void setAutoCollapseSetting(int newVal) { + getPreferenceStore().setValue(PREFERENCE_AUTO_COLLAPSE, newVal); + } + + /** + * @see org.eclipse.gef.ui.palette.PaletteViewerPreferences#setFontData(FontData) + */ + public void setFontData(FontData data) { + fontData = data; + String value = data.toString(); + if (fontData.equals(JFaceResources.getDialogFont().getFontData()[0])) { + value = DEFAULT_FONT; + } + getPreferenceStore().setValue(PREFERENCE_FONT, value); + } + + /** + * @see org.eclipse.gef.ui.palette.PaletteViewerPreferences#setLayoutSetting(int) + */ + public void setLayoutSetting(int newVal) { + getPreferenceStore().setValue(PREFERENCE_LAYOUT, newVal); + } + + /** + * @see org.eclipse.gef.ui.palette.PaletteViewerPreferences#setCurrentUseLargeIcons(boolean) + */ + public void setCurrentUseLargeIcons(boolean newVal) { + setUseLargeIcons(getLayoutSetting(), newVal); + } + + /** + * NOTE: Restricting the layout modes here does not in any way restrict those values from being + * stored in the preference store. Instead, it is the responsibility of all clients manipulating + * the layout settings to check to see if a particular layout mode is supported before + * manipulating it, or allowing the end user to manipulate it. + * + * @see org.eclipse.gef.ui.palette.PaletteViewerPreferences#setSupportedLayoutModes(int[]) + */ + public void setSupportedLayoutModes(int[] modes) { + supportedModes = modes; + if (!isSupportedLayoutMode(getPreferenceStore().getDefaultInt( + PREFERENCE_LAYOUT))) { + getPreferenceStore().setDefault(PREFERENCE_LAYOUT, + supportedModes[0]); + } + if (!isSupportedLayoutMode(getPreferenceStore().getInt( + PREFERENCE_LAYOUT))) { + setLayoutSetting(supportedModes[0]); + } + } + + /** + * @see org.eclipse.gef.ui.palette.PaletteViewerPreferences#setUseLargeIcons(int, boolean) + */ + public void setUseLargeIcons(int layout, boolean newVal) { + getPreferenceStore().setValue(convertLayoutToPreferenceName(layout), + newVal); + } + + /** + * @see org.eclipse.gef.ui.palette.PaletteViewerPreferences#useLargeIcons(int) + */ + public boolean useLargeIcons(int layout) { + return getPreferenceStore().getBoolean( + convertLayoutToPreferenceName(layout)); + } + + /** + * @see org.eclipse.gef.ui.palette.PaletteViewerPreferences#useLargeIcons() + */ + public boolean useLargeIcons() { + return useLargeIcons(getLayoutSetting()); + } + + private class PreferenceStoreListener implements IPropertyChangeListener { + /** + * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) + */ + public void propertyChange(PropertyChangeEvent evt) { + handlePreferenceStorePropertyChanged(evt.getProperty()); + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/FlyoutPaletteComposite.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/FlyoutPaletteComposite.java new file mode 100644 index 0000000..a911a7c --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/FlyoutPaletteComposite.java @@ -0,0 +1,1672 @@ +/******************************************************************************* + * Copyright (c) 2004, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * 1) update package name + * 2) apply new UI + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Plugin; +import org.eclipse.core.runtime.Preferences; +import org.eclipse.draw2d.ActionEvent; +import org.eclipse.draw2d.ActionListener; +import org.eclipse.draw2d.Border; +import org.eclipse.draw2d.Button; +import org.eclipse.draw2d.ButtonBorder; +import org.eclipse.draw2d.FocusEvent; +import org.eclipse.draw2d.FocusListener; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.LightweightSystem; +import org.eclipse.draw2d.MarginBorder; +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.draw2d.Triangle; +import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.gef.GraphicalViewer; +import org.eclipse.gef.SharedCursors; +import org.eclipse.gef.dnd.TemplateTransfer; +import org.eclipse.gef.internal.GEFMessages; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.TransferDropTargetListener; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.ACC; +import org.eclipse.swt.accessibility.AccessibleAdapter; +import org.eclipse.swt.accessibility.AccessibleControlAdapter; +import org.eclipse.swt.accessibility.AccessibleControlEvent; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.dnd.DropTargetEvent; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseMoveListener; +import org.eclipse.swt.events.MouseTrackAdapter; +import org.eclipse.swt.events.MouseTrackListener; +import org.eclipse.swt.graphics.Cursor; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Canvas; +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.Listener; +import org.eclipse.swt.widgets.Tracker; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.IPerspectiveDescriptor; +import org.eclipse.ui.IPerspectiveListener; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.IViewReference; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.XMLMemento; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.PaletteColorUtil; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.views.palette.PaletteView; +import org.tizen.efluibuilder.ui.editor.palette.PaletteConstants; +import org.tizen.efluibuilder.ui.resources.ColorResources; +import org.tizen.efluibuilder.ui.resources.FontResources; + + +/** + * The FlyoutPaletteComposite is used to show a flyout palette alongside another control. The flyout + * palette auto-hides (thus maximizing space) when not in use, but can also be pinned open if so + * desired. It will only be visible when the PaletteView is not. + * + * @author Pratik Shah + * @since 3.0 + */ +public class FlyoutPaletteComposite extends Composite { + + private static final FontManager FONT_MGR = new FontManager(); + + private static final String PROPERTY_PALETTE_WIDTH = "org.eclipse.gef.ui.palette.fpa.paletteWidth"; //$NON-NLS-1$ + private static final String PROPERTY_STATE = "org.eclipse.gef.ui.palette.fpa.state"; //$NON-NLS-1$ + private static final String PROPERTY_DOCK_LOCATION = "org.eclipse.gef.ui.palette.fpa.dock"; //$NON-NLS-1$ + + private static final int DEFAULT_PALETTE_SIZE = 125; + private static final int MIN_PALETTE_SIZE = 20; + private static final int MAX_PALETTE_SIZE = 500; + + private static final int STATE_HIDDEN = 8; + private static final int STATE_EXPANDED = 1; + + /* ECLIPSE */ + /* + * private static final Dimension ARROW_SIZE = new Dimension(6, 11); + */ + /* TIZEN: 6 -> 11 */ + private static final Dimension ARROW_SIZE = new Dimension(11, 11); + + private static final int SASH_BUTTON_WIDTH = 11; + + /** + * One of the two possible initial states of the flyout palette. This is the default one. When + * in this state, only the flyout palette's sash is visible. + */ + public static final int STATE_COLLAPSED = 2; + /** + * One of the two possible initial states of the flyout palette. When in this state, the flyout + * palette is completely visible and pinned open so that it doesn't disappear when the user + * wanders away from the flyout. + */ + public static final int STATE_PINNED_OPEN = 4; + + private PropertyChangeSupport listeners = new PropertyChangeSupport(this); + private Composite paletteContainer; + private PaletteViewer pViewer, externalViewer; + private IMemento capturedPaletteState; + private Control graphicalControl; + private Composite sash; + private PaletteViewerProvider provider; + private FlyoutPreferences prefs; + private Point cachedBounds = new Point(0, 0); + /* + * Fix for Bug# 71525 transferFocus is used to transfer focus from the button in the vertical + * sash title to the button in the horizontal paletteComposite title. When either button is + * pressed it is set to true, and when either the sash or the paletteComposite gets notified of + * the change in state, they transfer the focus to their button if this flag is set to true and + * if that button is visible. + */ + private boolean transferFocus = false; + private int dock = PositionConstants.EAST; + private int paletteState = STATE_HIDDEN; + private int paletteWidth = DEFAULT_PALETTE_SIZE; + private int minWidth = MIN_PALETTE_SIZE; + private int cachedSize = -1, cachedState = -1, cachedLocation = -1; + private int cachedTitleHeight = 24; // give it a default value + + private IPerspectiveListener perspectiveListener = new IPerspectiveListener() { + public void perspectiveActivated(IWorkbenchPage page, + IPerspectiveDescriptor perspective) { + handlePerspectiveActivated(page, perspective); + } + + public void perspectiveChanged(IWorkbenchPage page, + IPerspectiveDescriptor perspective, String changeId) { + handlePerspectiveChanged(page, perspective, changeId); + } + }; + + /** + * Constructor + * + * @param parent + * The parent Composite + * @param style + * The style of the widget to construct; only SWT.BORDER is allowed + * @param page + * The current workbench page + * @param pvProvider + * The provider that is to be used to create the flyout palette + * @param preferences + * To save/retrieve the preferences for the flyout + */ + public FlyoutPaletteComposite(Composite parent, int style, + IWorkbenchPage page, PaletteViewerProvider pvProvider, + FlyoutPreferences preferences) { + super(parent, style | SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE + | SWT.DOUBLE_BUFFERED); + provider = pvProvider; + prefs = preferences; + sash = createSash(); + paletteContainer = createPaletteContainer(); + hookIntoWorkbench(page.getWorkbenchWindow()); + + // Initialize the state properly + if (prefs.getPaletteWidth() <= 0) + prefs.setPaletteWidth(DEFAULT_PALETTE_SIZE); + setPaletteWidth(prefs.getPaletteWidth()); + setDockLocation(prefs.getDockLocation()); + updateState(page); + + addListener(SWT.Resize, new Listener() { + public void handleEvent(Event event) { + Rectangle area = getClientArea(); + /* + * @TODO:Pratik Sometimes, the editor is resized to 1,1 or 0,0 (depending on the + * platform) when the editor is closed or maximized. We have to ignore such resizes. + * See Bug# 62748 + */ + if (area.width > minWidth) + layout(true); + } + }); + + listeners.addPropertyChangeListener(new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent evt) { + String property = evt.getPropertyName(); + if (property.equals(PROPERTY_PALETTE_WIDTH)) + prefs.setPaletteWidth(paletteWidth); + else if (property.equals(PROPERTY_DOCK_LOCATION)) + prefs.setDockLocation(dock); + else if (property.equals(PROPERTY_STATE)) + if (paletteState == STATE_COLLAPSED + || paletteState == STATE_PINNED_OPEN) + prefs.setPaletteState(paletteState); + } + }); + } + + private void addListenerToCtrlHierarchy(Control parent, int eventType, + Listener listener) { + parent.addListener(eventType, listener); + if (!(parent instanceof Composite)) + return; + Control[] children = ((Composite) parent).getChildren(); + for (int i = 0; i < children.length; i++) { + addListenerToCtrlHierarchy(children[i], eventType, listener); + } + } + + private IMemento capturePaletteState(PaletteViewer viewer) { + IMemento memento = XMLMemento.createWriteRoot("paletteState"); //$NON-NLS-1$ + try { + viewer.saveState(memento); + } catch (RuntimeException re) { + // Bug 74843 -- See comment #1 + // If there's a problem with saving the palette's state, it simply + // won't be + // transferred to the new palette + memento = null; + /* + * @TODO:Pratik You should log this exception. + */ + } + return memento; + } + + private Control createFlyoutControlButton(Composite parent) { + return new ButtonCanvas(parent); + } + + /** + * This is a convenient method to get a default FlyoutPreferences object. The returned + * FlyoutPreferences does not save any changes made to the given {@link Preferences Preferences} + * . It's upto the owner plugin to {@link Plugin#savePluginPreferences() save} the changes + * before it {@link Plugin#stop(org.osgi.framework.BundleContext) stops}. + * + * @param prefs + * {@link Plugin#getPluginPreferences() a plugin's Preferences} + * @return a default implementation of FlyoutPreferences that stores the settings in the given + * Preferences + * @since 3.2 + */ + public static FlyoutPreferences createFlyoutPreferences(Preferences prefs) { + return new DefaultFlyoutPreferences(prefs); + } + + private Composite createPaletteContainer() { + return new PaletteComposite(this, SWT.NO_BACKGROUND + | SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED); + } + + private Composite createSash() { + return new Sash(this, SWT.NONE); + } + + private Control createTitle(Composite parent, boolean isHorizontal) { + return new TitleCanvas(parent, isHorizontal); + } + + private Control getPaletteViewerControl() { + Control result = null; + if (pViewer != null) + result = pViewer.getControl(); + // Fix for bug 101703 -- pViewer.getControl().getParent() might be + // parented + // by paletteContainer + if (result != null && !result.isDisposed() + && result.getParent() != paletteContainer) + result = result.getParent(); + return result; + } + + private void handlePerspectiveActivated(IWorkbenchPage page, + IPerspectiveDescriptor perspective) { + updateState(page); + } + + private void handlePerspectiveChanged(IWorkbenchPage page, + IPerspectiveDescriptor perspective, String changeId) { + if (changeId.equals(IWorkbenchPage.CHANGE_VIEW_SHOW) + || changeId.equals(IWorkbenchPage.CHANGE_VIEW_HIDE)) + updateState(page); + } + + // Will return false if the ancestor or descendant is null + private boolean isDescendantOf(Control ancestor, Control descendant) { + if (ancestor == null || descendant == null) + return false; + while (descendant != null) { + if (ancestor == descendant) + return true; + descendant = descendant.getParent(); + } + return false; + } + + private boolean isInState(int state) { + return (paletteState & state) != 0; + } + + private boolean isMirrored() { + return (getStyle() & SWT.MIRRORED) != 0; + } + + /** + * @see Composite#layout(boolean) + */ + public void layout(boolean changed) { + if (graphicalControl == null || graphicalControl.isDisposed()) + return; + + Rectangle area = getClientArea(); + if (area.width == 0 || area.height == 0) + return; + + int sashWidth = sash.computeSize(-1, -1).x; + int pWidth = paletteWidth; + int maxWidth = Math.min(area.width / 2, MAX_PALETTE_SIZE); + maxWidth = Math.max(maxWidth, minWidth); + pWidth = Math.max(pWidth, minWidth); + pWidth = Math.min(pWidth, maxWidth); + + /* + * Fix for Bug# 65892 Laying out only when necessary helps reduce flicker on GTK in the case + * where the flyout palette is being resized past its maximum size. + */ + if (paletteState == cachedState && pWidth == cachedSize + && cachedLocation == dock && cachedBounds == getSize()) + return; + cachedState = paletteState; + cachedSize = pWidth; + cachedLocation = dock; + cachedBounds = getSize(); + + // #65892 on Mac Cocoa, the redraw causes great flickering, therefore we + // skip it there + String ws = Platform.getWS(); + if (ws != null && !ws.equals(Platform.WS_COCOA)) { + setRedraw(false); + } + if (isInState(STATE_HIDDEN)) { + sash.setVisible(false); + paletteContainer.setVisible(false); + graphicalControl.setBounds(area); + } else if (dock == PositionConstants.EAST) + layoutComponentsEast(area, sashWidth, pWidth); + else + layoutComponentsWest(area, sashWidth, pWidth); + sash.layout(); + // #65892 see above + if (ws != null && !ws.equals(Platform.WS_COCOA)) { + setRedraw(true); + } + update(); + } + + private void layoutComponentsEast(Rectangle area, int sashWidth, int pWidth) { + if (isInState(STATE_COLLAPSED)) { + paletteContainer.setVisible(false); + sash.setBounds(area.x + area.width - sashWidth, area.y, sashWidth, + area.height); + sash.setVisible(true); + graphicalControl.setBounds(area.x, area.y, area.width - sashWidth, + area.height); + } else if (isInState(STATE_EXPANDED)) { + paletteContainer.moveAbove(graphicalControl); + sash.moveAbove(paletteContainer); + sash.setBounds(area.x + area.width - pWidth - sashWidth, area.y, + sashWidth, area.height); + paletteContainer.setBounds(area.x + area.width - pWidth, area.y, + pWidth, area.height); + sash.setVisible(true); + paletteContainer.setVisible(true); + graphicalControl.setBounds(area.x, area.y, area.width - sashWidth, + area.height); + } else if (isInState(STATE_PINNED_OPEN)) { + sash.setBounds(area.x + area.width - pWidth - sashWidth, area.y, + sashWidth, area.height); + paletteContainer.setBounds(area.x + area.width - pWidth, area.y, + pWidth, area.height); + sash.setVisible(true); + paletteContainer.setVisible(true); + graphicalControl.setBounds(area.x, area.y, area.width - sashWidth + - pWidth, area.height); + } + } + + private void layoutComponentsWest(Rectangle area, int sashWidth, int pWidth) { + if (isInState(STATE_COLLAPSED)) { + paletteContainer.setVisible(false); + sash.setBounds(area.x, area.y, sashWidth, area.height); + sash.setVisible(true); + graphicalControl.setBounds(area.x + sashWidth, area.y, area.width + - sashWidth, area.height); + } else if (isInState(STATE_EXPANDED)) { + paletteContainer.setVisible(true); + paletteContainer.moveAbove(graphicalControl); + sash.moveAbove(paletteContainer); + sash.setBounds(area.x + pWidth, area.y, sashWidth, area.height); + paletteContainer.setBounds(area.x, area.y, pWidth, area.height); + sash.setVisible(true); + graphicalControl.setBounds(area.x + sashWidth, area.y, area.width + - sashWidth, area.height); + } else if (isInState(STATE_PINNED_OPEN)) { + paletteContainer.setVisible(true); + sash.setBounds(area.x + pWidth, area.y, sashWidth, area.height); + paletteContainer.setBounds(area.x, area.y, pWidth, area.height); + sash.setVisible(true); + graphicalControl.setBounds(area.x + pWidth + sashWidth, area.y, + area.width - sashWidth - pWidth, area.height); + } + } + + private void hookIntoWorkbench(final IWorkbenchWindow window) { + window.addPerspectiveListener(perspectiveListener); + addDisposeListener(new DisposeListener() { + public void widgetDisposed(DisposeEvent e) { + window.removePerspectiveListener(perspectiveListener); + perspectiveListener = null; + } + }); + } + + private boolean restorePaletteState(PaletteViewer newPalette, IMemento state) { + if (state != null) { + try { + return newPalette.restoreState(state); + } catch (RuntimeException re) { + /* + * @TODO:Pratik You should log this exception + */ + } + } + return false; + } + + /** + * If an external palette viewer is provided, palette state (that is captured in + * {@link PaletteViewer#saveState(IMemento)} -- active tool, drawer expansion state, drawer pin + * state, etc.) will be maintained when switching between the two viewers. Providing an external + * viewer, although recommended, is optional. + * + * @param viewer + * The palette viewer used in the PaletteView + */ + public void setExternalViewer(PaletteViewer viewer) { + if (viewer == null && externalViewer != null) + capturedPaletteState = capturePaletteState(externalViewer); + externalViewer = viewer; + if (externalViewer != null && pViewer != null) + transferState(pViewer, externalViewer); + } + + private void setDockLocation(int position) { + if (position != PositionConstants.EAST + && position != PositionConstants.WEST) + return; + if (position != dock) { + int oldPosition = dock; + dock = position; + listeners.firePropertyChange(PROPERTY_DOCK_LOCATION, oldPosition, + dock); + if (pViewer != null) + layout(true); + } + } + + private void setPaletteWidth(int newSize) { + if (paletteWidth != newSize) { + int oldValue = paletteWidth; + paletteWidth = newSize; + listeners.firePropertyChange(PROPERTY_PALETTE_WIDTH, oldValue, + paletteWidth); + if (pViewer != null) + layout(true); + } + } + + /** + * Sets the control along the side of which the palette is to be displayed. The given Control + * should be a child of this Composite. This method should only be invoked once. + * + * @param graphicalViewer + * the control of the graphical viewer; cannot be null + */ + public void setGraphicalControl(Control graphicalViewer) { + Assert.isTrue(graphicalViewer != null); + Assert.isTrue(graphicalViewer.getParent() == this); + Assert.isTrue(graphicalControl == null); + graphicalControl = graphicalViewer; + addListenerToCtrlHierarchy(graphicalControl, SWT.MouseEnter, + new Listener() { + public void handleEvent(Event event) { + if (!isInState(STATE_EXPANDED)) + return; + Display.getCurrent().timerExec(250, new Runnable() { + public void run() { + if (isDescendantOf(graphicalControl, Display + .getCurrent().getCursorControl()) + && isInState(STATE_EXPANDED)) + setState(STATE_COLLAPSED); + } + }); + } + }); + } + + /* + * @TODO:Pratik For 4.0, change the parameter of this method to be EditpartViewer instead of + * GraphicalViewer. + */ + /** + * This method hooks a DropTargetListener that collapses the flyout patette when the user drags + * something from the palette and moves the cursor to the primary viewer's control. If the + * auto-hide feature of the palette is to work properly when dragging, this method should be + * called before any other drop target listeners are added to the primary viewer. + * + * @param viewer + * the primary viewer + */ + public void hookDropTargetListener(GraphicalViewer viewer) { + viewer.addDropTargetListener(new TransferDropTargetListener() { + public void dragEnter(DropTargetEvent event) { + } + + public void dragLeave(DropTargetEvent event) { + } + + public void dragOperationChanged(DropTargetEvent event) { + } + + public void dragOver(DropTargetEvent event) { + } + + public void drop(DropTargetEvent event) { + } + + public void dropAccept(DropTargetEvent event) { + } + + public Transfer getTransfer() { + return TemplateTransfer.getInstance(); + } + + public boolean isEnabled(DropTargetEvent event) { + if (isInState(STATE_EXPANDED)) + setState(STATE_COLLAPSED); + return false; + } + }); + } + + /* + * If the given state is invalid (as could be the case when FlyoutPreferences.getPaletteState() + * is invoked for the first time), it will be defaulted to STATE_COLLAPSED. + */ + private void setState(int newState) { + /* + * Fix for Bug# 69617 and Bug# 81248 FlyoutPreferences.getPaletteState() could return an + * invalid state if none is stored. In that case, we use the default state: STATE_COLLAPSED. + */ + if (newState != STATE_HIDDEN && newState != STATE_PINNED_OPEN + && newState != STATE_EXPANDED) + newState = STATE_COLLAPSED; + if (paletteState == newState) + return; + int oldState = paletteState; + paletteState = newState; + switch (paletteState) { + case STATE_EXPANDED: + case STATE_COLLAPSED: + case STATE_PINNED_OPEN: + if (pViewer == null) { + pViewer = provider.createPaletteViewer(paletteContainer); + if (externalViewer != null) + transferState(externalViewer, pViewer); + else + restorePaletteState(pViewer, capturedPaletteState); + capturedPaletteState = null; + minWidth = Math.max(pViewer.getControl().computeSize(0, 0).x, + MIN_PALETTE_SIZE); + } + break; + case STATE_HIDDEN: + if (pViewer == null) + break; + if (externalViewer != null) { + ((TizenEditDomain) provider.getEditDomain()).setTizenPaletteViewer(externalViewer); + transferState(pViewer, externalViewer); + } + if (((TizenEditDomain) provider.getEditDomain()).getTizenPaletteViewer() == pViewer) + provider.getEditDomain().setPaletteViewer(null); + + Control pViewerCtrl = getPaletteViewerControl(); + if (pViewerCtrl != null && !pViewerCtrl.isDisposed()) + pViewerCtrl.dispose(); + pViewer = null; + } + /* + * Fix for Bug# 63901 When the flyout collapses, if the palette has focus, throw focus to + * the graphical control. That way, hitting ESC will still deactivate the current tool and + * load the default one. Note that focus is being set on RulerComposite and not + * GraphicalViewer's control. But this is okay since RulerComposite passes the focus on to + * its first child, which is the graphical viewer's control. + */ + if (paletteState == STATE_COLLAPSED + && pViewer.getControl().isFocusControl()) + graphicalControl.setFocus(); + layout(true); + listeners.firePropertyChange(PROPERTY_STATE, oldState, newState); + } + + private void transferState(PaletteViewer src, PaletteViewer dest) { + restorePaletteState(dest, capturePaletteState(src)); + } + + private void updateState(IWorkbenchPage page) { + IViewReference view = page.findViewReference(PaletteView.ID); + if (view == null && isInState(STATE_HIDDEN)) + setState(prefs.getPaletteState()); + if (view != null && !isInState(STATE_HIDDEN)) + setState(STATE_HIDDEN); + } + + /** + * FlyoutPreferences is used to save/load the preferences for the flyout palette. + * + * @author Pratik Shah + * @since 3.0 + */ + public interface FlyoutPreferences { + /** + * Should return {@link PositionConstants#EAST} or {@link PositionConstants#WEST}. Any other + * int will be ignored and the default dock location (EAST) will be used instead. + * + * @return the saved dock location of the Palette + */ + int getDockLocation(); + + /** + * When there is no saved state, this method can return any non-positive int (which will + * result in the palette using the default state -- collapsed), or + * {@link FlyoutPaletteComposite#STATE_COLLAPSED}, or + * {@link FlyoutPaletteComposite#STATE_PINNED_OPEN} + * + * @return the saved state of the palette + */ + int getPaletteState(); + + /** + * When there is no saved width, this method can return any int (preferrably a non-positive + * int). Returning a non-positive int will cause the palette to be sized to the default + * size, whereas returning a postive int will find the closest match in the valid range (>= + * minimum and <= maximum) + * + * @return the saved width of the flyout palette + */ + int getPaletteWidth(); + + /** + * This method is invoked when the flyout palette's dock location is changed. The provided + * dock location should be persisted and returned in {@link #getDockLocation()}. + * + * @param location + * {@link PositionConstants#EAST} or {@link PositionConstants#WEST} + */ + void setDockLocation(int location); + + /** + * This method is invoked when the flyout palette's state is changed (the new state becomes + * the default). The provided state should be persisted and returned in + * {@link #getPaletteState()}. + * + * @param state + * {@link FlyoutPaletteComposite#STATE_COLLAPSED} or + * {@link FlyoutPaletteComposite#STATE_PINNED_OPEN} + */ + void setPaletteState(int state); + + /** + * This method is invoked when the flyout palette is resized. The provided width should be + * persisted and returned in {@link #getPaletteWidth()}. + * + * @param width + * the new size of the flyout palette + */ + void setPaletteWidth(int width); + } + + private class Sash extends Composite { + private Control button; + + public Sash(Composite parent, int style) { + super(parent, style); + button = createFlyoutControlButton(this); + new SashDragManager(); + + addMouseTrackListener(new MouseTrackAdapter() { + public void mouseHover(MouseEvent e) { + if (isInState(STATE_COLLAPSED)) + setState(STATE_EXPANDED); + } + }); + + addListener(SWT.Paint, new Listener() { + public void handleEvent(Event event) { + paintSash(event.gc); + } + }); + + addListener(SWT.Resize, new Listener() { + public void handleEvent(Event event) { + layout(true); + } + }); + + listeners.addPropertyChangeListener(new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getPropertyName().equals(PROPERTY_STATE)) + updateState(); + } + }); + } + + public Point computeSize(int wHint, int hHint, boolean changed) { + if (isInState(STATE_PINNED_OPEN)) + return new Point(3, 3); + + // button size plus two pixels for the two lines to be drawn + return new Point(SASH_BUTTON_WIDTH + 2, cachedTitleHeight); + } + + private void handleSashDragged(int shiftAmount) { + int newSize = paletteContainer.getBounds().width + + (dock == PositionConstants.EAST ? -shiftAmount + : shiftAmount); + setPaletteWidth(newSize); + } + + public void layout(boolean changed) { + if (button == null) + return; + + if (isInState(STATE_PINNED_OPEN)) { + button.setVisible(false); + return; + } + + button.setVisible(true); + Rectangle area = getClientArea(); + button.setBounds(area.x + 1, area.y + 1, SASH_BUTTON_WIDTH, + cachedTitleHeight - 1); + + if (transferFocus) { + transferFocus = false; + button.setFocus(); + } + } + + private void paintSash(GC gc) { + Rectangle bounds = getBounds(); + if (isInState(STATE_PINNED_OPEN)) { + gc.setBackground(PaletteColorUtil.WIDGET_BACKGROUND); + gc.fillRectangle(0, 0, bounds.width, bounds.height); + + gc.setForeground(PaletteColorUtil.WIDGET_LIST_BACKGROUND); + gc.drawLine(0, 0, bounds.width, 0); + gc.setForeground(PaletteColorUtil.WIDGET_NORMAL_SHADOW); + gc.drawLine(0, bounds.height - 1, bounds.width - 1, + bounds.height - 1); + gc.setForeground(PaletteColorUtil.WIDGET_LIST_BACKGROUND); + gc.drawLine(0, 0, 0, bounds.height); + gc.setForeground(PaletteColorUtil.WIDGET_NORMAL_SHADOW); + gc.drawLine(bounds.width - 1, 0, bounds.width - 1, + bounds.height - 1); + } else { + gc.setForeground(PaletteColorUtil.WIDGET_NORMAL_SHADOW); + gc.drawLine(0, 0, 0, bounds.height); + gc.drawLine(bounds.width - 1, 0, bounds.width - 1, + bounds.height); + + gc.setForeground(PaletteColorUtil.WIDGET_LIST_BACKGROUND); + gc.drawLine(1, 0, 1, bounds.height); + + gc.setForeground(PaletteColorUtil.WIDGET_BACKGROUND_LIST_BACKGROUND_85); + gc.drawLine(2, 0, 2, bounds.height); + } + } + + private void updateState() { + setCursor(isInState(STATE_EXPANDED | STATE_PINNED_OPEN) ? SharedCursors.SIZEWE + : null); + } + + private class SashDragManager extends MouseAdapter implements + MouseMoveListener { + protected boolean dragging = false; + protected boolean correctState = false; + protected boolean mouseDown = false; + protected int origX; + protected Listener keyListener = new Listener() { + public void handleEvent(Event event) { + if (event.keyCode == SWT.ALT || event.keyCode == SWT.ESC) { + dragging = false; + Display.getCurrent().removeFilter(SWT.KeyDown, this); + } + event.doit = false; + event.type = SWT.None; + } + }; + + public SashDragManager() { + Sash.this.addMouseMoveListener(this); + Sash.this.addMouseListener(this); + } + + public void mouseDown(MouseEvent me) { + if (me.button != 1) + return; + mouseDown = true; + correctState = isInState(STATE_EXPANDED | STATE_PINNED_OPEN); + origX = me.x; + Display.getCurrent().addFilter(SWT.KeyDown, keyListener); + } + + public void mouseMove(MouseEvent me) { + if (mouseDown) + dragging = true; + if (dragging && correctState) + handleSashDragged(me.x - origX); + } + + public void mouseUp(MouseEvent me) { + Display.getCurrent().removeFilter(SWT.KeyDown, keyListener); + if (!dragging && me.button == 1) { + if (isInState(STATE_COLLAPSED)) + setState(STATE_EXPANDED); + else if (isInState(STATE_EXPANDED)) + setState(STATE_COLLAPSED); + } + dragging = false; + correctState = false; + mouseDown = false; + } + } + } + + private class ResizeAction extends Action { + public ResizeAction() { + super(PaletteMessages.RESIZE_LABEL); + } + + public boolean isEnabled() { + return !isInState(STATE_COLLAPSED); + } + + public void run() { + final Tracker tracker = new Tracker(FlyoutPaletteComposite.this, + SWT.RIGHT | SWT.LEFT); + Rectangle[] rects = new Rectangle[1]; + rects[0] = sash.getBounds(); + tracker.setCursor(SharedCursors.SIZEE); + tracker.setRectangles(rects); + if (tracker.open()) { + int deltaX = sash.getBounds().x - tracker.getRectangles()[0].x; + if (dock == PositionConstants.WEST) + deltaX = -deltaX; + setPaletteWidth(paletteContainer.getBounds().width + deltaX); + } + tracker.dispose(); + } + } + + private class TitleDragManager extends MouseAdapter implements Listener, + MouseTrackListener { + protected boolean switchDock = false; + protected boolean dragging = false; + protected int threshold; + + public TitleDragManager(Control ctrl) { + ctrl.addListener(SWT.DragDetect, this); + ctrl.addMouseListener(this); + ctrl.addMouseTrackListener(this); + } + + public void handleEvent(Event event) { + dragging = true; + switchDock = false; + threshold = dock == PositionConstants.EAST ? Integer.MAX_VALUE / 2 + : -1; + final Composite flyout = FlyoutPaletteComposite.this; + final Rectangle flyoutBounds = flyout.getBounds(); + final int switchThreshold = flyoutBounds.x + + (flyoutBounds.width / 2); + Rectangle bounds = sash.getBounds(); + if (paletteContainer.getVisible()) + bounds = bounds.union(paletteContainer.getBounds()); + final Rectangle origBounds = Display.getCurrent().map(flyout, null, + bounds); + final Tracker tracker = new Tracker(Display.getDefault(), SWT.NULL); + tracker.setRectangles(new Rectangle[] { origBounds }); + tracker.setStippled(true); + tracker.addListener(SWT.Move, new Listener() { + public void handleEvent(final Event evt) { + Display.getCurrent().syncExec(new Runnable() { + public void run() { + Control ctrl = Display.getCurrent() + .getCursorControl(); + Point pt = flyout.toControl(evt.x, evt.y); + switchDock = isDescendantOf(graphicalControl, ctrl) + && ((dock == PositionConstants.WEST && pt.x > threshold - 10) || (dock == PositionConstants.EAST && pt.x < threshold + 10)); + boolean invalid = false; + if (!switchDock) + invalid = !isDescendantOf( + FlyoutPaletteComposite.this, ctrl); + if (switchDock) { + if (dock == PositionConstants.WEST) { + threshold = Math.max(threshold, pt.x); + threshold = Math.min(threshold, + switchThreshold); + } else { + threshold = Math.min(threshold, pt.x); + threshold = Math.max(threshold, + switchThreshold); + } + } + Rectangle placeHolder = origBounds; + if (switchDock) { + if (dock == PositionConstants.EAST) + placeHolder = new Rectangle(0, 0, + origBounds.width, origBounds.height); + else + placeHolder = new Rectangle( + flyoutBounds.width + - origBounds.width, + 0, + origBounds.width, origBounds.height); + placeHolder = Display.getCurrent().map(flyout, + null, placeHolder); + } + // update the cursor + int cursor; + if (invalid) + cursor = DragCursors.INVALID; + else if ((!switchDock && dock == PositionConstants.EAST) + || (switchDock && dock == PositionConstants.WEST)) + cursor = DragCursors.RIGHT; + else + cursor = DragCursors.LEFT; + if (isMirrored()) { + if (cursor == DragCursors.RIGHT) + cursor = DragCursors.LEFT; + else if (cursor == DragCursors.LEFT) + cursor = DragCursors.RIGHT; + } + tracker.setCursor(DragCursors.getCursor(cursor)); + // update the rectangle only if it has changed + if (!tracker.getRectangles()[0].equals(placeHolder)) + tracker.setRectangles(new Rectangle[] { placeHolder }); + } + }); + } + }); + if (tracker.open()) { + if (switchDock) + setDockLocation(PositionConstants.EAST_WEST & ~dock); + // mouse up is received by the tracker and by this listener, so + // we set dragging + // to be false + dragging = false; + } + tracker.dispose(); + } + + public void mouseEnter(MouseEvent e) { + } + + public void mouseExit(MouseEvent e) { + } + + public void mouseHover(MouseEvent e) { + /* + * @TODO:Pratik Mouse hover events are received if the hover occurs just before you + * finish or cancel the drag. Open a bugzilla about it? + */ + if (isInState(STATE_COLLAPSED)) + setState(STATE_EXPANDED); + } + + public void mouseUp(MouseEvent me) { + if (me.button != 1) + return; + if (isInState(STATE_COLLAPSED)) + setState(STATE_EXPANDED); + else if (isInState(STATE_EXPANDED)) + setState(STATE_COLLAPSED); + } + } + + private class PaletteComposite extends Composite { + protected Control button, title; + + public PaletteComposite(Composite parent, int style) { + super(parent, style); + createComponents(); + + listeners.addPropertyChangeListener(new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getPropertyName().equals(PROPERTY_STATE)) + updateState(); + else if (evt.getPropertyName().equals( + PROPERTY_DOCK_LOCATION)) + if (getVisible()) + layout(true); + } + }); + + addListener(SWT.Resize, new Listener() { + public void handleEvent(Event event) { + layout(true); + } + }); + + updateState(); + } + + protected void createComponents() { + title = createTitle(this, true); + button = createFlyoutControlButton(this); + } + + public void layout(boolean changed) { + Control pCtrl = getPaletteViewerControl(); + if (pCtrl == null || pCtrl.isDisposed()) + return; + + Rectangle area = getClientArea(); + boolean buttonVisible = button.getVisible(); + Point titleSize = title.computeSize(-1, -1); + Point buttonSize = buttonVisible ? button.computeSize(-1, -1) + : new Point(0, 0); + cachedTitleHeight = Math.max(titleSize.y, buttonSize.y); + if (buttonVisible) { + buttonSize.x = Math.max(cachedTitleHeight, buttonSize.x); + } + if (dock == PositionConstants.EAST) { + /* ECLIPSE */ + /* int buttonX = area.width - buttonSize.x; */ + /* TIZEN: add offset { */ + int offset = -1; // // advux - UI Tunning + int buttonX = area.width - buttonSize.x + offset; + /* TIZEN } */ + button.setBounds(buttonX, 0, buttonSize.x, cachedTitleHeight); + title.setBounds(0, 0, buttonX, cachedTitleHeight); + } else { + int titleX = buttonSize.x; + button.setBounds(0, 0, buttonSize.x, cachedTitleHeight); + title.setBounds(titleX, 0, area.width - titleX, + cachedTitleHeight); + } + area.y += cachedTitleHeight; + area.height -= cachedTitleHeight; + pCtrl.setBounds(area); + } + + protected void updateState() { + button.setVisible(isInState(STATE_PINNED_OPEN)); + if (transferFocus && button.getVisible()) { + transferFocus = false; + button.setFocus(); + } + layout(true); + } + } + + private static class TitleLabel extends Label { + protected static final Border BORDER = new MarginBorder(4, 3, 4, 3); + protected static final Border TOOL_TIP_BORDER = new MarginBorder(0, 2, + 0, 2); + + public TitleLabel(boolean isHorizontal) { + /* ECLIPSE { */ + // super(GEFMessages.Palette_Label, InternalImages + // .get(InternalImages.IMG_PALETTE)); + /* ECLIPSE } */ + + /* TIZEN { */ + super(GEFMessages.Palette_Label, PaletteConstants.imgDescTitle.createImage()); + /* TIZEN } */ + + setLabelAlignment(PositionConstants.LEFT); + setBorder(BORDER); + Label tooltip = new Label(getText()); + tooltip.setBorder(TOOL_TIP_BORDER); + setToolTip(tooltip); + /* ECLIPSE { */ + // setForegroundColor(ColorConstants.listForeground); + /* ECLIPSE } */ + + /* TIZEN { */ + setForegroundColor(ColorResources.PALETTE_TITLE); + /* TIZEN } */ + } + + public IFigure getToolTip() { + if (isTextTruncated()) + return super.getToolTip(); + return null; + } + + protected void paintFigure(Graphics graphics) { + + // paint the gradient + graphics.pushState(); + org.eclipse.draw2d.geometry.Rectangle r = org.eclipse.draw2d.geometry.Rectangle.SINGLETON; + r.setBounds(getBounds()); + graphics.setForegroundColor(PaletteColorUtil.WIDGET_LIST_BACKGROUND); + /* ECLIPSE { */ + // graphics.setBackgroundColor(PaletteColorUtil.WIDGET_BACKGROUND); + // graphics.fillGradient(r, true); + /* ECLIPSE } */ + + /* TIZEN { */ + graphics.setBackgroundColor(ColorResources.PALETTE_TITLE_BACKGROUND); + graphics.fillRectangle(r); + /* TIZEN } */ + + // draw bottom border + graphics.setForegroundColor(PaletteColorUtil.WIDGET_NORMAL_SHADOW); + graphics.drawLine(r.getBottomLeft().getTranslated(0, -1), r + .getBottomRight().getTranslated(0, -1)); + + graphics.popState(); + + // paint the text and icon + super.paintFigure(graphics); + + // paint the focus rectangle around the text + if (hasFocus()) { + org.eclipse.draw2d.geometry.Rectangle textBounds = getTextBounds(); + // We reduce the width by 1 because FigureUtilities grows it by + // 1 unnecessarily + textBounds.width--; + graphics.drawFocus(bounds.getResized(-1, -1).intersect( + textBounds.getExpanded(getInsets()))); + } + } + } + + private class ButtonCanvas extends Canvas { + private LightweightSystem lws; + + public ButtonCanvas(Composite parent) { + super(parent, SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND); + init(); + provideAccSupport(); + } + + public Point computeSize(int wHint, int hHint, boolean changed) { + Dimension size = lws.getRootFigure().getPreferredSize(wHint, hHint); + size.union(new Dimension(wHint, hHint)); + return new org.eclipse.swt.graphics.Point(size.width, size.height); + } + + private int getArrowDirection() { + int direction = PositionConstants.EAST; + if (isInState(STATE_EXPANDED | STATE_PINNED_OPEN)) + direction = dock == PositionConstants.WEST ? PositionConstants.WEST + : PositionConstants.EAST; + else + direction = dock == PositionConstants.WEST ? PositionConstants.EAST + : PositionConstants.WEST; + if (isMirrored()) { + if (direction == PositionConstants.WEST) + direction = PositionConstants.EAST; + else + direction = PositionConstants.WEST; + } + return direction; + } + + private String getButtonTooltipText() { + if (isInState(STATE_COLLAPSED)) + return PaletteMessages.PALETTE_SHOW; + return PaletteMessages.PALETTE_HIDE; + } + + private void init() { + setCursor(SharedCursors.ARROW); + lws = new LightweightSystem(); + lws.setControl(this); + final ArrowButton b = new ArrowButton(getArrowDirection()); + b.setRolloverEnabled(true); + b.setBorder(new ButtonBorder(ButtonBorder.SCHEMES.TOOLBAR)); + b.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + transferFocus = true; + if (isInState(STATE_COLLAPSED)) + setState(STATE_PINNED_OPEN); + else + setState(STATE_COLLAPSED); + } + }); + listeners.addPropertyChangeListener(new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getPropertyName().equals(PROPERTY_STATE)) { + b.setDirection(getArrowDirection()); + setToolTipText(getButtonTooltipText()); + } else if (evt.getPropertyName().equals( + PROPERTY_DOCK_LOCATION)) + b.setDirection(getArrowDirection()); + } + }); + lws.setContents(b); + } + + private void provideAccSupport() { + getAccessible().addAccessibleListener(new AccessibleAdapter() { + public void getDescription(AccessibleEvent e) { + e.result = PaletteMessages.ACC_DESC_PALETTE_BUTTON; + } + + public void getHelp(AccessibleEvent e) { + getDescription(e); + } + + public void getName(AccessibleEvent e) { + e.result = getToolTipText(); + } + }); + getAccessible().addAccessibleControlListener( + new AccessibleControlAdapter() { + public void getRole(AccessibleControlEvent e) { + e.detail = ACC.ROLE_PUSHBUTTON; + } + }); + } + + private class ArrowButton extends Button { + + private Triangle triangle; + + /** + * Creates a new instance + * + * @param direction + * the direction the arrow should face (PositionConstants.RIGHT or + * PositionConstants.LEFT) + */ + public ArrowButton(int direction) { + super(); + setDirection(direction); + + triangle = new Triangle(); + triangle.setOutline(true); + /* ECLIPSE { */ + // triangle.setBackgroundColor(PaletteColorUtil.WIDGET_LIST_BACKGROUND); + // triangle.setForegroundColor(PaletteColorUtil.WIDGET_DARK_SHADOW); + /* ECLIPSE } */ + + /* TIZEN { */ + triangle.setBackgroundColor(ColorResources.PALETTE_TITLE); + triangle.setForegroundColor(ColorResources.PALETTE_TITLE); + /* TIZEN } */ + setContents(triangle); + } + + public void setDirection(int direction) { + if (triangle != null) { + triangle.setDirection(direction); + } + } + + protected void layout() { + org.eclipse.draw2d.geometry.Rectangle clientArea = getBounds(); + triangle.setBounds(new org.eclipse.draw2d.geometry.Rectangle(clientArea.getCenter().getTranslated(-ARROW_SIZE.width / 2, + -ARROW_SIZE.height / 2), + ARROW_SIZE)); + } + + protected void paintFigure(Graphics graphics) { + super.paintFigure(graphics); + + // paint the gradient + graphics.pushState(); + org.eclipse.draw2d.geometry.Rectangle r = org.eclipse.draw2d.geometry.Rectangle.SINGLETON; + r.setBounds(getBounds()); + graphics.setForegroundColor(PaletteColorUtil.WIDGET_LIST_BACKGROUND); + + /* ECLIPSE { */ + // graphics.setBackgroundColor(PaletteColorUtil.WIDGET_BACKGROUND); + // graphics.fillGradient(r, true); + /* ECLIPSE } */ + + /* TIZEN { */ + graphics.setBackgroundColor(ColorResources.PALETTE_TITLE_BACKGROUND); + graphics.fillRectangle(r); + /* TIZEN } */ + + graphics.popState(); + + // draw bottom border + graphics.setForegroundColor(PaletteColorUtil.WIDGET_NORMAL_SHADOW); + graphics.drawLine(r.getBottomLeft().getTranslated(0, -1), r + .getBottomRight().getTranslated(0, -1)); + } + } + } + + private class TitleCanvas extends Canvas { + private LightweightSystem lws; + + public TitleCanvas(Composite parent, boolean horizontal) { + super(parent, SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND); + init(horizontal); + provideAccSupport(); + } + + /** + * @see org.eclipse.swt.widgets.Control#computeSize(int, int, boolean) + */ + public Point computeSize(int wHint, int hHint, boolean changed) { + Dimension size = lws.getRootFigure().getPreferredSize(wHint, hHint); + size.union(new Dimension(wHint, hHint)); + return new org.eclipse.swt.graphics.Point(size.width, size.height); + } + + private void init(boolean isHorizontal) { + final IFigure contents = new TitleLabel(true); + contents.setRequestFocusEnabled(true); + contents.setFocusTraversable(true); + contents.addFocusListener(new FocusListener() { + public void focusGained(FocusEvent fe) { + fe.gainer.repaint(); + } + + public void focusLost(FocusEvent fe) { + fe.loser.repaint(); + } + }); + + lws = new LightweightSystem(); + lws.setControl(this); + lws.setContents(contents); + setCursor(SharedCursors.SIZEALL); + FONT_MGR.register(this); + new TitleDragManager(this); + /* TIZEN { Remove unnecessary context menu */ + // final MenuManager manager = new MenuManager(); + // MenuManager mgr = new MenuManager(PaletteMessages.DOCK_LABEL); + // mgr.add(new ChangeDockAction(PaletteMessages.LEFT_LABEL, + // PositionConstants.WEST)); + // mgr.add(new ChangeDockAction(PaletteMessages.RIGHT_LABEL, + // PositionConstants.EAST)); + // manager.add(new ResizeAction()); + // manager.add(mgr); + // setMenu(manager.createContextMenu(this)); + // mgr.addMenuListener(new IMenuListener() { + // public void menuAboutToShow(IMenuManager menuMgr) { + // IContributionItem[] items = menuMgr.getItems(); + // for (int i = 0; i < items.length; i++) { + // ((ActionContributionItem) items[i]).update(); + // } + // } + // }); + + // addDisposeListener(new DisposeListener() { + // public void widgetDisposed(DisposeEvent e) { + // FONT_MGR.unregister(TitleCanvas.this); + // manager.dispose(); + // } + // }); + /* TIZEN } */ + } + + private void provideAccSupport() { + getAccessible().addAccessibleListener(new AccessibleAdapter() { + public void getDescription(AccessibleEvent e) { + e.result = PaletteMessages.ACC_DESC_PALETTE_TITLE; + } + + public void getHelp(AccessibleEvent e) { + getDescription(e); + } + + public void getName(AccessibleEvent e) { + e.result = GEFMessages.Palette_Label; + } + }); + getAccessible().addAccessibleControlListener( + new AccessibleControlAdapter() { + public void getRole(AccessibleControlEvent e) { + e.detail = ACC.ROLE_LABEL; + } + }); + } + + public void setFont(Font font) { + ((IFigure) lws.getRootFigure().getChildren().get(0)).setFont(font); + if (isVisible()) { + /* + * If this canvas is in the sash, we want the FlyoutPaletteComposite to layout + * (which will cause the sash to be resized and laid out). However, if this canvas + * is in the paletteContainer, the paletteContainer's bounds won't change, and hence + * it won't layout. Thus, we also invoke getParent().layout(). + */ + FlyoutPaletteComposite.this.layout(true); + getParent().layout(true); + } + } + } + + private class ChangeDockAction extends Action { + private int position; + + /** + * Constructor + * + * @param text + * this action's text + * @param position + * the dock side that this action represents: PositionConstants.EAST or + * PositionConstants.WEST + */ + public ChangeDockAction(String text, int position) { + super(text, IAction.AS_RADIO_BUTTON); + this.position = position; + } + + /** + * This Action is checked when the palette is docked on the side this action represents + * + * @see org.eclipse.jface.action.IAction#isChecked() + */ + public boolean isChecked() { + return dock == position; + } + + /** + * Changes the palette's dock location to the side this action represents + * + * @see org.eclipse.jface.action.IAction#run() + */ + public void run() { + setDockLocation(position); + } + } + + private static class FontManager { + private final String fontName = getFontType(); + private List registrants = new ArrayList(); + private Font titleFont; + private final IPropertyChangeListener fontListener = new IPropertyChangeListener() { + public void propertyChange( + org.eclipse.jface.util.PropertyChangeEvent event) { + if (fontName.equals(event.getProperty())) + handleFontChanged(); + } + }; + + private FontManager() { + } + + protected final Font createTitleFont() { + return JFaceResources.getFont(fontName); + } + + protected void dispose() { + titleFont = null; + JFaceResources.getFontRegistry().removeListener(fontListener); + } + + protected String getFontType() { + return JFaceResources.DIALOG_FONT; + } + + protected void handleFontChanged() { + if (titleFont == null) + return; + Font oldFont = titleFont; + titleFont = createTitleFont(); + for (Iterator iter = registrants.iterator(); iter.hasNext();) + ((Control) iter.next()).setFont(titleFont); + oldFont.dispose(); + } + + protected void init() { + titleFont = createTitleFont(); + JFaceResources.getFontRegistry().addListener(fontListener); + } + + public void register(Control ctrl) { + if (titleFont == null) + init(); + /* ECLIPSE { */ + // ctrl.setFont(titleFont); + /* ECLIPSE } */ + + /* TIZEN { */ + ctrl.setFont(FontResources.PALETTE_TITLE_BOLD); + /* TIZEN } */ + + registrants.add(ctrl); + } + + public void unregister(Control ctrl) { + registrants.remove(ctrl); + if (registrants.isEmpty()) + dispose(); + } + } + + /** + * Default implementation of FlyoutPreferences that stores the flyout palette settings in the + * given Preferences. + * + * @author Pratik Shah + * @since 3.2 + */ + private static class DefaultFlyoutPreferences implements FlyoutPreferences { + /* + * There's no need to set the default for these properties since the default-default of 0 + * for ints will suffice. + */ + private static final String PALETTE_DOCK_LOCATION = "org.eclipse.gef.pdock"; //$NON-NLS-1$ + private static final String PALETTE_SIZE = "org.eclipse.gef.psize"; //$NON-NLS-1$ + private static final String PALETTE_STATE = "org.eclipse.gef.pstate"; //$NON-NLS-1$ + + private Preferences prefs; + + private DefaultFlyoutPreferences(Preferences preferences) { + prefs = preferences; + } + + public int getDockLocation() { + return prefs.getInt(PALETTE_DOCK_LOCATION); + } + + public int getPaletteState() { + return prefs.getInt(PALETTE_STATE); + } + + public int getPaletteWidth() { + return prefs.getInt(PALETTE_SIZE); + } + + public void setDockLocation(int location) { + prefs.setValue(PALETTE_DOCK_LOCATION, location); + } + + public void setPaletteState(int state) { + prefs.setValue(PALETTE_STATE, state); + } + + public void setPaletteWidth(int width) { + prefs.setValue(PALETTE_SIZE, width); + } + } + + private static class DragCursors { + public static final int INVALID = 0; + + public static final int LEFT = 1; + + public static final int RIGHT = 2; + + private final static Cursor cursors[] = new Cursor[3]; + + /** + * Return the cursor for a drop scenario, as identified by code. Code must be one of + * INVALID, LEFT, RIGHT. If the code is not found default to INVALID. Note that since these + * three cursors are static, they will only be created once for the lifetime of the eclipse + * session and shared (i.e this is not an image leak). + * + * @param code + * the code + * @return the cursor + */ + public static Cursor getCursor(int code) { + Display display = Display.getCurrent(); + if (cursors[code] == null) { + ImageDescriptor source = null; + ImageDescriptor mask = null; + switch (code) { + case LEFT: + source = PlatformUI + .getWorkbench() + .getSharedImages() + .getImageDescriptor( + ISharedImages.IMG_OBJS_DND_LEFT_SOURCE); + mask = PlatformUI + .getWorkbench() + .getSharedImages() + .getImageDescriptor( + ISharedImages.IMG_OBJS_DND_LEFT_MASK); + cursors[LEFT] = new Cursor(display, source.getImageData(), + mask.getImageData(), 16, 16); + break; + case RIGHT: + source = PlatformUI + .getWorkbench() + .getSharedImages() + .getImageDescriptor( + ISharedImages.IMG_OBJS_DND_RIGHT_SOURCE); + mask = PlatformUI + .getWorkbench() + .getSharedImages() + .getImageDescriptor( + ISharedImages.IMG_OBJS_DND_RIGHT_MASK); + cursors[RIGHT] = new Cursor(display, source.getImageData(), + mask.getImageData(), 16, 16); + break; + default: + case INVALID: + source = PlatformUI + .getWorkbench() + .getSharedImages() + .getImageDescriptor( + ISharedImages.IMG_OBJS_DND_INVALID_SOURCE); + mask = PlatformUI + .getWorkbench() + .getSharedImages() + .getImageDescriptor( + ISharedImages.IMG_OBJS_DND_INVALID_MASK); + cursors[INVALID] = new Cursor(display, + source.getImageData(), mask.getImageData(), 16, 16); + break; + } + } + return cursors[code]; + } + + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/LayoutAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/LayoutAction.java new file mode 100644 index 0000000..7aebc88 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/LayoutAction.java @@ -0,0 +1,176 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.gef.internal.Internal; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.ActionContributionItem; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuCreator; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Menu; + + +/** + * This action allows to switch between the various supported layout modes for the given palette. + * + * @author Pratik Shah + */ +public class LayoutAction extends Action implements IMenuCreator { + + private PaletteViewerPreferences prefs; + private List actions; + + /** + * Constructor + * + * @param prefs + * PaletteViewerPreferences object where the settings can be saved + */ + public LayoutAction(PaletteViewerPreferences prefs) { + this(prefs, false); + } + + /** + * Constructor + * + * @param hasIcon + * True if this action should associate an icon with itself + * @param prefs + * PaletteViewerPreferences object where the settings can be saved + */ + public LayoutAction(PaletteViewerPreferences prefs, boolean hasIcon) { + super(PaletteMessages.LAYOUT_MENU_LABEL); + this.prefs = prefs; + actions = createActions(); + setMenuCreator(this); + + if (hasIcon) + setImageDescriptor(ImageDescriptor.createFromFile(Internal.class, + "icons/palette_layout.gif")); //$NON-NLS-1$ + + setToolTipText(PaletteMessages.LAYOUT_MENU_LABEL); + } + + /** + * Helper method that wraps the given action in an ActionContributionItem and then adds it to + * the given menu. + * + * @param parent + * The menu to which the given action is to be added + * @param action + * The action that is to be added to the given menu + */ + protected void addActionToMenu(Menu parent, IAction action) { + ActionContributionItem item = new ActionContributionItem(action); + item.fill(parent, -1); + } + + /** + * @return A list of actions that can switch to one of the supported layout modes + */ + protected List createActions() { + ArrayList list = new ArrayList(); + int[] modes = prefs.getSupportedLayoutModes(); + + Action action; + for (int i = 0; i < modes.length; i++) { + switch (modes[i]) { + case PaletteViewerPreferences.LAYOUT_COLUMNS: + action = new LayoutChangeAction( + PaletteViewerPreferences.LAYOUT_COLUMNS); + action.setText(PaletteMessages.SETTINGS_COLUMNS_VIEW_LABEL); + list.add(action); + break; + case PaletteViewerPreferences.LAYOUT_LIST: + action = new LayoutChangeAction( + PaletteViewerPreferences.LAYOUT_LIST); + action.setText(PaletteMessages.SETTINGS_LIST_VIEW_LABEL); + list.add(action); + break; + case PaletteViewerPreferences.LAYOUT_ICONS: + action = new LayoutChangeAction( + PaletteViewerPreferences.LAYOUT_ICONS); + action.setText(PaletteMessages.SETTINGS_ICONS_VIEW_LABEL_CAPS); + list.add(action); + break; + case PaletteViewerPreferences.LAYOUT_DETAILS: + action = new LayoutChangeAction( + PaletteViewerPreferences.LAYOUT_DETAILS); + action.setText(PaletteMessages.SETTINGS_DETAILS_VIEW_LABEL); + list.add(action); + break; + } + } + return list; + } + + /** + * Empty method + * + * @see org.eclipse.jface.action.IMenuCreator#dispose() + */ + public void dispose() { + } + + private Menu fillMenu(Menu menu) { + for (Iterator iter = actions.iterator(); iter.hasNext();) { + LayoutChangeAction action = (LayoutChangeAction) iter.next(); + action.setChecked(prefs.getLayoutSetting() == action + .getLayoutSetting()); + addActionToMenu(menu, action); + } + + setEnabled(!actions.isEmpty()); + + return menu; + } + + /** + * @see org.eclipse.jface.action.IMenuCreator#getMenu(Control) + */ + public Menu getMenu(Control parent) { + return fillMenu(new Menu(parent)); + } + + /** + * @see org.eclipse.jface.action.IMenuCreator#getMenu(Menu) + */ + public Menu getMenu(Menu parent) { + return fillMenu(new Menu(parent)); + } + + private class LayoutChangeAction extends Action { + private int value; + + public LayoutChangeAction(int layoutSetting) { + value = layoutSetting; + } + + public int getLayoutSetting() { + return value; + } + + public void run() { + prefs.setLayoutSetting(value); + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/PaletteContextMenuProvider.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/PaletteContextMenuProvider.java new file mode 100644 index 0000000..517a3cd --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/PaletteContextMenuProvider.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette; + +import org.eclipse.gef.ContextMenuProvider; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.ui.actions.GEFActionConstants; +import org.eclipse.jface.action.IMenuManager; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.editparts.IPinnableEditPart; + + +/** + * Provides the context menu for a palette. + * + * @author Pratik Shah + */ +public class PaletteContextMenuProvider extends ContextMenuProvider { + + /** + * Constructor + * + * @param palette + * the palette viewer for which the context menu has to be created + */ + public PaletteContextMenuProvider(PaletteViewer palette) { + super(palette); + } + + /** + * @return the palette viewer + */ + protected PaletteViewer getPaletteViewer() { + return (PaletteViewer) getViewer(); + } + + /** + * This is the method that builds the context menu. + * + * @param menu + * The IMenuManager to which actions for the palette's context menu can be added. + * @see ContextMenuProvider#buildContextMenu(org.eclipse.jface.action.IMenuManager) + */ + public void buildContextMenu(IMenuManager menu) { + GEFActionConstants.addStandardActionGroups(menu); + + EditPart selectedPart = (EditPart) getPaletteViewer() + .getSelectedEditParts().get(0); + IPinnableEditPart pinnablePart = selectedPart.getAdapter(IPinnableEditPart.class); + if (pinnablePart != null && pinnablePart.canBePinned()) { + menu.appendToGroup(GEFActionConstants.MB_ADDITIONS, + new PinDrawerAction(pinnablePart)); + } + menu.appendToGroup(GEFActionConstants.GROUP_VIEW, new LayoutAction( + getPaletteViewer().getPaletteViewerPreferences())); + menu.appendToGroup(GEFActionConstants.GROUP_VIEW, + new ChangeIconSizeAction(getPaletteViewer() + .getPaletteViewerPreferences())); + if (getPaletteViewer().getCustomizer() != null) { + menu.appendToGroup(GEFActionConstants.GROUP_REST, + new CustomizeAction(getPaletteViewer())); + } + menu.appendToGroup(GEFActionConstants.GROUP_REST, new SettingsAction( + getPaletteViewer())); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/PaletteCustomizer.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/PaletteCustomizer.java new file mode 100644 index 0000000..9edf083 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/PaletteCustomizer.java @@ -0,0 +1,322 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette; + +import java.util.ArrayList; +import java.util.List; + +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteContainer; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteDrawer; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.customize.DefaultEntryPage; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.customize.DrawerEntryPage; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.customize.EntryPage; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.customize.PaletteDrawerFactory; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.customize.PaletteSeparatorFactory; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.customize.PaletteStackFactory; + + +/** + * PaletteCustomizer is the PaletteCustomizerDialog's interface to the + * model. This class is responsible for propogating to the model changes made in the dialog. + * + * @author Pratik Shah + */ +public abstract class PaletteCustomizer { + + /** + * Return true if this container can accept this entry as a new child. By default, this method + * checks to see first if the container has full permissions, then checks to see if this + * container can accept the type of the entry. + * + * @param container + * the container that will be the parent of this entry + * @param entry + * the entry to add to the container + * @return true if this container can hold this entry + */ + protected boolean canAdd(PaletteContainer container, PaletteEntry entry) { + return container.getUserModificationPermission() == PaletteEntry.PERMISSION_FULL_MODIFICATION + && container.acceptsType(entry.getType()); + } + + /** + * Indicates whether the given entry can be deleted from the model or not. Whether or not an + * entry can be deleted depends on its permsission ( + * {@link PaletteEntry#getUserModificationPermission()}). + *

+ * This method will be invoked by PaletteCustomizerDialog to determine whether or + * not to enable the "Delete" action. + *

+ * + * @param entry + * The selected palette entry. It'll never be null. + * @return true if the given entry can be deleted + * + * @see #performDelete(PaletteEntry) + */ + public boolean canDelete(PaletteEntry entry) { + return entry.getUserModificationPermission() == PaletteEntry.PERMISSION_FULL_MODIFICATION; + } + + /** + * Indicates whether the given entry can be moved down or not. Whether or not an entry can be + * moved down or not is determined by its parent's user modification permission ( + * {@link PaletteEntry#getUserModificationPermission()}). + *

+ * Will be called by PaletteCustomizerDialog to determine whether or not to enable the + * "Move Down" action. + *

+ * + * @param entry + * The selected palette entry (it'll never be null) + * @return true if the given entry can be moved down + * + * @see #performMoveDown(PaletteEntry) + */ + public boolean canMoveDown(PaletteEntry entry) { + PaletteContainer parent = entry.getParent(); + int parentPermission = parent.getUserModificationPermission(); + if (parentPermission < PaletteEntry.PERMISSION_LIMITED_MODIFICATION) { + return false; + } + + if (parent.getChildren().indexOf(entry) + 1 != parent.getChildren() + .size()) { + return true; + } else { + // The given entry is the last child in its parent. + if (parentPermission != PaletteEntry.PERMISSION_FULL_MODIFICATION + || parent.getParent() == null) + return false; + + // try to place in grand parent + if (canAdd(parent.getParent(), entry)) + return true; + + // walk parent siblings till we find one it can go into. + List children = parent.getParent().getChildren(); + int parentIndex = children.indexOf(parent); + PaletteEntry parentSibling = null; + + for (int i = parentIndex + 1; i < children.size(); i++) { + parentSibling = (PaletteEntry) children.get(i); + if (parentSibling instanceof PaletteContainer) { + if (canAdd((PaletteContainer) parentSibling, entry)) + return true; + } + } + + return false; + + } + } + + /** + * Indicates whether the given entry can be moved up or not. Whether or not an entry can be + * moved up or not is determined by its parent's user modification permission ( + * {@link PaletteEntry#getUserModificationPermission()}). + *

+ * Will be called by PaletteCustomizerDialog to determine whether or not to enable the "Move Up" + * action. + *

+ * + * @param entry + * The selected palette entry (it'll never be null) + * @return true if the given entry can be moved up + * + * @see #performMoveUp(PaletteEntry) + */ + public boolean canMoveUp(PaletteEntry entry) { + PaletteContainer parent = entry.getParent(); + int parentPermission = parent.getUserModificationPermission(); + if (parentPermission < PaletteEntry.PERMISSION_LIMITED_MODIFICATION) { + return false; + } + + if (parent.getChildren().indexOf(entry) != 0) { + return true; + } else { + // The given entry is the first child in its parent + if (parentPermission != PaletteEntry.PERMISSION_FULL_MODIFICATION + || parent.getParent() == null) + return false; + + // try to place in grand parent + if (canAdd(parent.getParent(), entry)) + return true; + + // walk parent siblings till we find one it can go into. + List children = parent.getParent().getChildren(); + int parentIndex = children.indexOf(parent); + PaletteEntry parentSibling = null; + + for (int i = parentIndex - 1; i >= 0; i--) { + parentSibling = (PaletteEntry) children.get(i); + if (parentSibling instanceof PaletteContainer) { + if (canAdd((PaletteContainer) parentSibling, entry)) + return true; + } + } + + return false; + } + } + + /** + * Returns the list of PaletteEntryFactories that can be used to create new palette entries. The + * String returned by the getText() method of each PaletteEntryFactory will be used to populate + * the "New" drop-down. getImageDescriptor() will be used to set the icons on the drop down. + * This method can return null if there are no PaletteEntryFactories available. + * + * @return The List of PaletteEntryFactories + */ + public List getNewEntryFactories() { + List list = new ArrayList(4); + list.add(new PaletteSeparatorFactory()); + list.add(new PaletteStackFactory()); + list.add(new PaletteDrawerFactory()); + return list; + } + + /** + * Returns an EntryPage that will display the custom properties of the given entry. Can return + * null if there are no custom properties. + * + * @param entry + * The PaletteEntry whose properties page needs to be displayed (it'll never be + * null) + * @return The EntryPage to represent the given entry + */ + public EntryPage getPropertiesPage(PaletteEntry entry) { + if (entry instanceof PaletteDrawer) { + return new DrawerEntryPage(); + } + return new DefaultEntryPage(); + } + + /** + * Updates the model by deleting the given entry from it.
+ * Called when the "Delete" action in the PaletteCustomizerDialog is executed. + * + * @param entry + * The selected palette entry (it'll never be null) + * + * @see #canDelete(PaletteEntry) + */ + public void performDelete(PaletteEntry entry) { + entry.getParent().remove(entry); + } + + /** + * Updates the model by moving the entry down.
+ * Called when the "Move Down" action in the PaletteCustomizerDialog is invoked. + * + * @param entry + * The selected palette entry (it'll never be null) + * + * @see #canMoveDown(PaletteEntry) + */ + public void performMoveDown(PaletteEntry entry) { + PaletteContainer parent = entry.getParent(); + if (!parent.moveDown(entry)) { + // This is the case of a PaletteEntry that is its parent's last + // child + // and will have to move down into the next slot in the grandparent + PaletteEntry parentSibling = null; + PaletteContainer newParent = parent.getParent(); + int insertionIndex = 0; + + if (canAdd(newParent, entry)) + insertionIndex = newParent.getChildren().indexOf(parent) + 1; + else { + List parents = newParent.getChildren(); + + for (int i = parents.indexOf(parent) + 1; i < parents.size(); i++) { + parentSibling = (PaletteEntry) parents.get(i); + if (parentSibling instanceof PaletteContainer) { + newParent = (PaletteContainer) parentSibling; + if (canAdd(newParent, entry)) + break; + } + } + } + + parent.remove(entry); + + newParent.add(insertionIndex, entry); + } + } + + /** + * Updates the model by moving the entry up.
+ * Called when the "Move Up" action in the PaletteCustomizerDialog is invoked. + * + * @param entry + * The selected palette entry (it'll never be null) + * + * @see #canMoveUp(PaletteEntry) + */ + public void performMoveUp(PaletteEntry entry) { + PaletteContainer parent = entry.getParent(); + if (!parent.moveUp(entry)) { + // This is the case of a PaletteEntry that is its parent's first + // child + // and we should move up in the grand parent. + PaletteEntry parentSibling = null; + PaletteContainer newParent = parent.getParent(); + int insertionIndex = 0; + + if (canAdd(newParent, entry)) + insertionIndex = newParent.getChildren().indexOf(parent); + else { + List parents = newParent.getChildren(); + + for (int i = parents.indexOf(parent) - 1; i >= 0; i--) { + parentSibling = (PaletteEntry) parents.get(i); + if (parentSibling instanceof PaletteContainer) { + newParent = (PaletteContainer) parentSibling; + if (canAdd(newParent, entry)) { + insertionIndex = newParent.getChildren().size(); + break; + } + } + } + } + + parent.remove(entry); + + newParent.add(insertionIndex, entry); + } + } + + /** + * Undoes the changes made to the model since the last save. + *

+ * This method is invoked when the "Cancel" is selected in the + * PaletteCustomizerDialog. + *

+ */ + public abstract void revertToSaved(); + + /** + * Persists the changes made to the model. + *

+ * Called when "OK" or "Apply" are selected in the PaletteCustomizerDialog. + *

+ */ + public abstract void save(); + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/PaletteEditPartFactory.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/PaletteEditPartFactory.java new file mode 100644 index 0000000..7cec6ce --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/PaletteEditPartFactory.java @@ -0,0 +1,187 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPartFactory; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.DrawerEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.GroupEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.PaletteStackEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.PinnablePaletteStackEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.SeparatorEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.SliderPaletteEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.TemplateEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.ToolEntryEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.ToolbarEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteContainer; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteDrawer; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteGroup; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteRoot; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteSeparator; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteStack; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteTemplateEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteToolbar; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.editparts.PaletteEditPart; + + +/** + * Factory to create EditParts for different PaletteEntries. + * + * @author Pratik Shah + */ +public class PaletteEditPartFactory implements EditPartFactory { + + /** + * Create DrawerEditPart - edit part for PaletteDrawer + * + * @param parentEditPart + * the parent of the new editpart to be created + * @param model + * the PaletteDrawer + * @return the newly created EditPart + */ + protected EditPart createDrawerEditPart(EditPart parentEditPart, + Object model) { + return new DrawerEditPart((PaletteDrawer) model); + } + + /** + * @see org.eclipse.gef.EditPartFactory#createEditPart(EditPart, Object) + */ + public EditPart createEditPart(EditPart parentEditPart, Object model) { + if (model instanceof PaletteRoot) + return createMainPaletteEditPart(parentEditPart, model); + if (model instanceof PaletteStack) + return createStackEditPart(parentEditPart, model); + if (model instanceof PaletteContainer) { + Object type = ((PaletteContainer) model).getType(); + if (PaletteDrawer.PALETTE_TYPE_DRAWER.equals(type)) + return createDrawerEditPart(parentEditPart, model); + if (PaletteGroup.PALETTE_TYPE_GROUP.equals(type) + || PaletteContainer.PALETTE_TYPE_UNKNOWN.equals(type)) + return createGroupEditPart(parentEditPart, model); + if (PaletteToolbar.PALETTE_TYPE_TOOLBAR_GROUP.equals(type)) + return createToolbarEditPart(parentEditPart, model); + } + if (model instanceof PaletteTemplateEntry) + return createTemplateEditPart(parentEditPart, model); + if (model instanceof PaletteSeparator) + return createSeparatorEditPart(parentEditPart, model); + if (model instanceof PaletteEntry) + return createEntryEditPart(parentEditPart, model); + return null; + } + + /** + * Create SeparatorEditPart - edit part for PaletteSeparator + * + * @param parentEditPart + * the parent of the new editpart to be created + * @param model + * the PaletteSeparator + * @return the newly created EditPart + */ + protected EditPart createSeparatorEditPart(EditPart parentEditPart, + Object model) { + return new SeparatorEditPart((PaletteSeparator) model); + } + + /** + * Create PaletteStackEditPart - edit part for PaletteStack + * + * @param parentEditPart + * the parent of the new editpart to be created + * @param model + * the PaletteStack + * @return the newly created EditPart + */ + protected EditPart createStackEditPart(EditPart parentEditPart, Object model) { + if (parentEditPart instanceof PaletteEditPart + && ((PaletteEditPart) parentEditPart).isToolbarItem()) { + return new PaletteStackEditPart((PaletteStack) model); + } + return new PinnablePaletteStackEditPart((PaletteStack) model); + } + + /** + * Create ToolEntryEditPart - edit part for ToolEntry + * + * @param parentEditPart + * the parent of the new editpart to be created + * @param model + * the ToolEntry + * @return the newly created EditPart + */ + protected EditPart createEntryEditPart(EditPart parentEditPart, Object model) { + return new ToolEntryEditPart((PaletteEntry) model); + } + + /** + * Create GroupEditPart - edit part for PaletteGroup + * + * @param parentEditPart + * the parent of the new editpart to be created + * @param model + * the PaletteGroup + * @return the newly created EditPart + */ + protected EditPart createGroupEditPart(EditPart parentEditPart, Object model) { + return new GroupEditPart((PaletteContainer) model); + } + + /** + * Create ToolbarEditPart - edit part for PaletteToolbar + * + * @param parentEditPart + * the parent of the new editpart to be created + * @param model + * the PaletteToolbar + * @return the newly created EditPart + */ + protected EditPart createToolbarEditPart(EditPart parentEditPart, + Object model) { + return new ToolbarEditPart((PaletteToolbar) model); + } + + /** + * Create SliderPaletteEditPart - edit part for PaletteRoot + * + * @param parentEditPart + * the parent of the new editpart to be created + * @param model + * the PaletteRoot + * @return the newly created EditPart + */ + protected EditPart createMainPaletteEditPart(EditPart parentEditPart, + Object model) { + return new SliderPaletteEditPart((PaletteRoot) model); + } + + /** + * Create TemplateEditPart - edit part for PaletteTemplateEntry + * + * @param parentEditPart + * the parent of the new editpart to be created + * @param model + * the PaletteTemplateEntry + * @return the newly created EditPart + */ + protected EditPart createTemplateEditPart(EditPart parentEditPart, + Object model) { + return new TemplateEditPart((PaletteTemplateEntry) model); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/PaletteMessages.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/PaletteMessages.java new file mode 100644 index 0000000..96f3633 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/PaletteMessages.java @@ -0,0 +1,309 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette; + +import org.eclipse.osgi.util.NLS; + + +/** + * @author Pratik Shah + */ +public class PaletteMessages extends NLS { + + /** + * The String "Customize Palette" + */ + public static String CUSTOMIZE_DIALOG_TITLE; + /** + * The String "Drawer options: " + */ + public static String COLLAPSE_OPTIONS_TITLE; + /** + * The String "Layout options" + */ + public static String SETTINGS_LAYOUT_OPTIONS_TITLE; + /** + * The String "&Apply" + */ + public static String APPLY_LABEL; + /** + * The String "Move &Up" + */ + public static String MOVE_UP_LABEL; + /** + * The String "Move Do&wn" + */ + public static String MOVE_DOWN_LABEL; + /** + * The String "&Delete" + */ + public static String DELETE_LABEL; + /** + * The String "&New" + */ + public static String NEW_LABEL; + /** + * The String "&Columns" + */ + public static String SETTINGS_COLUMNS_VIEW_LABEL; + /** + * The String "&List" + */ + public static String SETTINGS_LIST_VIEW_LABEL; + /** + * The String "&Use large icons" + */ + public static String SETTINGS_USE_LARGE_ICONS_LABEL; + /** + * The String "&Use Large Icons" + */ + public static String SETTINGS_USE_LARGE_ICONS_LABEL_CAPS; + /** + * The String "&Icons only" + */ + public static String SETTINGS_ICONS_VIEW_LABEL; + /** + * The String "&Icons Only" + */ + public static String SETTINGS_ICONS_VIEW_LABEL_CAPS; + /** + * The String "&Never close" + */ + public static String COLLAPSE_NEVER_LABEL; + /** + * The String "&Always close when opening another drawer" + */ + public static String COLLAPSE_ALWAYS_LABEL; + /** + * The String "Close automatically &when there is not enough room" + */ + public static String COLLAPSE_AS_NEEDED_LABEL; + /** + * The String "Nothing Selected" + */ + public static String NO_SELECTION_TITLE; + /** + * The String "Na&me: " + */ + public static String NAME_LABEL; + /** + * The String "Des&cription: " + */ + public static String DESCRIPTION_LABEL; + /** + * The String "&Hide" + */ + public static String HIDDEN_LABEL; + /** + * The String "No description is available." + */ + public static String NO_DESCRIPTION_AVAILABLE; + /** + * The String "Select a node from the tree on the left." + */ + public static String NO_SELECTION_MADE; + /** + * The String "Cus&tomize..." + */ + public static String MENU_OPEN_CUSTOMIZE_DIALOG; + /** + * The String "Drawer" + */ + public static String MODEL_TYPE_DRAWER; + /** + * The String "Separator" + */ + public static String MODEL_TYPE_SEPARATOR; + /** + * The String "Stack" + */ + public static String MODEL_TYPE_STACK; + /** + * The String "Separates entries in a palette container" + */ + public static String NEW_SEPARATOR_DESC; + /** + * The String "New Drawer" + */ + public static String NEW_DRAWER_LABEL; + /** + * The String "[Separator]" + */ + public static String NEW_SEPARATOR_LABEL; + /** + * The String "New Stack" + */ + public static String NEW_STACK_LABEL; + /** + * The String "Group" + */ + public static String MODEL_TYPE_GROUP; + /** + * The String "New Group" + */ + public static String NEW_GROUP_LABEL; + /** + * The String "&Layout" + */ + public static String LAYOUT_MENU_LABEL; + /** + * The String "Could Not Accept Changes" + */ + public static String ERROR; + /** + * The String "The currently displayed page contains invalid values." + */ + public static String ABORT_PAGE_FLIPPING_MESSAGE; + /** + * The String "&Settings..." + */ + public static String MENU_OPEN_SETTINGS_DIALOG; + /** + * The String "Palette Settings" + */ + public static String SETTINGS_DIALOG_TITLE; + /** + * The String "&Details" + */ + public static String SETTINGS_DETAILS_VIEW_LABEL; + /** + * The String "Font" + */ + public static String SETTINGS_FONT_TITLE; + /** + * The String "C&hange..." + */ + public static String SETTINGS_FONT_CHANGE; + /** + * The String "Font: " + */ + public static String SETTINGS_FONT_CURRENT; + /** + * The String "Layout: " + */ + public static String SETTINGS_LAYOUT_TITLE; + /** + * The String "Drawer Options" + */ + public static String SETTINGS_DRAWER_OPTIONS_TITLE; + /** + * The String "&Open drawer at start-up" + */ + public static String EXPAND_DRAWER_AT_STARTUP_LABEL; + /** + * The String "Columns layout options" + */ + public static String SETTINGS_OPTIONS_COLUMNS; + /** + * The String "List layout options" + */ + public static String SETTINGS_OPTIONS_LIST; + /** + * The String " layout options" + */ + public static String SETTINGS_OPTIONS_ICONS_ONLY; + /** + * The String "Details layout options" + */ + public static String SETTINGS_OPTIONS_DETAILS; + /** + * The String "&Override default column width settings" + */ + public static String SETTINGS_LAYOUT_COLUMNS_OVERRIDE_WIDTH; + /** + * The String "Colu&mn width (in pixels): " + */ + public static String SETTINGS_LAYOUT_COLUMNS_WIDTH; + /** + * The String "&Pin drawer open at start-up" + */ + public static String DRAWER_PIN_AT_STARTUP; + /** + * The String "&Restore Default" + */ + public static String SETTINGS_DEFAULT_FONT; + /** + * The String "" + */ + public static String SETTINGS_WORKBENCH_FONT_LABEL; + /** + * The String "-" + */ + public static String NAME_DESCRIPTION_SEPARATOR; + /** + * The String "&Pinned" + */ + public static String PINNED; + /** + * The String "Pin Open" + */ + public static String TOOLTIP_PIN_FIGURE; + + /** + * The String "Unpin" + */ + public static String TOOLTIP_UNPIN_FIGURE; + + /** + * The String "&Dock On" + */ + public static String DOCK_LABEL; + + /** + * The String "&Left" + */ + public static String LEFT_LABEL; + + /** + * The String "&Right" + */ + public static String RIGHT_LABEL; + + /** + * The String "&Resize" + */ + public static String RESIZE_LABEL; + + /** + * Show Palette + */ + public static String PALETTE_SHOW; + + /** + * Hide Palette + */ + public static String PALETTE_HIDE; + + /** + * This button is used to show or hide the palette. + */ + public static String ACC_DESC_PALETTE_BUTTON; + + /** + * The palette can be moved or resized through the context menu for this control. + */ + public static String ACC_DESC_PALETTE_TITLE; + + static { + /* TIZEN { */ + NLS.initializeMessages( + "org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.messages", PaletteMessages.class); //$NON-NLS-1$ + /* } TIZEN */ + /* ECLIPSE { */ + // "org.eclipse.gef.ui.palette.messages", PaletteMessages.class); //$NON-NLS-1$ + /* } ECLIPSE */ + } + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/PaletteViewer.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/PaletteViewer.java new file mode 100644 index 0000000..fa81f3a --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/PaletteViewer.java @@ -0,0 +1,502 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + * - add setCategoryState method + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.draw2d.FigureCanvas; +import org.eclipse.draw2d.IFigure; +import org.eclipse.gef.EditDomain; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.editparts.SimpleRootEditPart; +import org.eclipse.gef.ui.parts.ScrollingGraphicalViewer; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IMemento; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.PaletteSelectionTool; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.DrawerEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.DrawerFigure; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.PaletteStackEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.ToolEntryEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteDrawer; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteListener; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteRoot; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteStack; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.ToolEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.customize.PaletteCustomizerDialog; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.editparts.PaletteEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.parts.PaletteViewerKeyHandler; +import org.tizen.efluibuilder.ui.editor.palette.PaletteConstants; + + +/** + * Graphical viewer for the GEF palette. + * + * @author Randy Hudson + * @author Pratik Shah + */ +public class PaletteViewer extends ScrollingGraphicalViewer { + + private class PreferenceListener implements PropertyChangeListener { + /** + * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) + */ + public void propertyChange(PropertyChangeEvent evt) { + String property = evt.getPropertyName(); + EditPart root = getRootEditPart().getContents(); + if (property.equals(PaletteViewerPreferences.PREFERENCE_FONT)) { + updateFont(); + refreshAllEditParts(root); + } else if (property + .equals(PaletteViewerPreferences.PREFERENCE_LAYOUT) + || property + .equals(PaletteViewerPreferences.PREFERENCE_AUTO_COLLAPSE) + || property + .equals(DefaultPaletteViewerPreferences + .convertLayoutToPreferenceName(getPaletteViewerPreferences() + .getLayoutSetting()))) { + refreshAllEditParts(root); + } + } + + private void refreshAllEditParts(EditPart part) { + part.refresh(); + List children = part.getChildren(); + for (Iterator iter = children.iterator(); iter.hasNext();) { + EditPart child = (EditPart) iter.next(); + refreshAllEditParts(child); + } + } + } + + private static final PaletteViewerPreferences PREFERENCE_STORE = new DefaultPaletteViewerPreferences(); + private ToolEntry activeEntry = null; + private PaletteCustomizer customizer = null; + private PaletteCustomizerDialog customizerDialog = null; + private boolean globalScrollbar = false; + private List paletteListeners = new ArrayList(); + private PaletteRoot paletteRoot = null; + private PreferenceListener prefListener = new PreferenceListener(); + private PaletteViewerPreferences prefs = PREFERENCE_STORE; + private Font font = null; + private boolean categoryState = false; + + /** + * Constructor + */ + public PaletteViewer() { + EditDomain domain = new EditDomain(); + // TizenEditDomain domain = new TizenEditDomain(); + + domain.setDefaultTool(new PaletteSelectionTool()); + domain.loadDefaultTool(); + setEditDomain(domain); + setKeyHandler(new PaletteViewerKeyHandler(this)); + setEditPartFactory(new PaletteEditPartFactory()); + } + + /** + * Adds the given PaletteListener as the one to be notified when the active tool on the palette + * changes. + * + * @param paletteListener + * The listener that needs to be notified of active tool changes on the palette + */ + public void addPaletteListener(PaletteListener paletteListener) { + if (paletteListeners != null) + paletteListeners.add(paletteListener); + } + + /** + * @see org.eclipse.gef.ui.parts.GraphicalViewerImpl#createDefaultRoot() + */ + protected void createDefaultRoot() { + setRootEditPart(new SimpleRootEditPart()); + } + + private void disposeFont() { + if (font != null) { + font.dispose(); + font = null; + } + } + + /** + * Indicates that the palette should scroll using a native vertical scrollbar as opposed to + * individual lightweight buttons that appear dynamically on each drawer. The default settings + * is false. Enabling this setting requires additional horizontal screen space for + * the scrollbar. Therefore, its use is discouraged. + *

+ * This setting must be changed prior to calling + * {@link ScrollingGraphicalViewer#createControl(org.eclipse.swt.widgets.Composite)} . After the + * control is created, changing this setting will have no effect. + *

+ * + * @param value + * true if a vertical scrollbar should be displayed + */ + public void enableVerticalScrollbar(boolean value) { + this.globalScrollbar = value; + } + + /** + * @return the DrawerEditPart that has the given part; part, if part is a drawer; null, if part + * is not in a drawer + */ + private DrawerEditPart findContainingDrawer(EditPart part) { + if (part == null) + return null; + if (part instanceof DrawerEditPart) + return (DrawerEditPart) part; + return findContainingDrawer(part.getParent()); + } + + /** + * Notifies registered listeners of change in the active tool on the palette + */ + protected void fireModeChanged() { + if (paletteListeners == null) + return; + for (int listener = 0; listener < paletteListeners.size(); listener++) + ((PaletteListener) paletteListeners.get(listener)) + .activeToolChanged(this, activeEntry); + } + + /** + * @return the customizer + */ + public PaletteCustomizer getCustomizer() { + return customizer; + } + + /** + * NOTE: A PaletteCustomizer must be set for this viewer using the + * {@link #setCustomizer(PaletteCustomizer)} method before this method is invoked. + * + * @return The dialog that can be used to customize entries on the palette + */ + public PaletteCustomizerDialog getCustomizerDialog() { + if (customizerDialog == null) { + customizerDialog = new PaletteCustomizerDialog(getControl() + .getShell(), getCustomizer(), getPaletteRoot()); + } + return customizerDialog; + } + + /** + * @return the entry for the currently active tool + */ + public ToolEntry getActiveTool() { + return activeEntry; + } + + /** + * Returns the palette's root model. + * + * @return the palette root + */ + public PaletteRoot getPaletteRoot() { + return paletteRoot; + } + + /** + * @return The PaletteViewerPreferences that this palette is using to store its preferences (if + * none has been set, it returns the default one, which uses the GEF preference store) + */ + public PaletteViewerPreferences getPaletteViewerPreferences() { + return prefs; + } + + private ToolEntryEditPart getToolEntryEditPart(ToolEntry entry) { + return (ToolEntryEditPart) getEditPartRegistry().get(entry); + } + + /** + * @see org.eclipse.gef.ui.parts.GraphicalViewerImpl#handleDispose(org.eclipse.swt.events.DisposeEvent) + */ + protected void handleDispose(DisposeEvent e) { + super.handleDispose(e); + disposeFont(); + } + + /** + * @see org.eclipse.gef.ui.parts.GraphicalViewerImpl#handleFocusGained(FocusEvent) + */ + protected void handleFocusGained(FocusEvent fe) { + super.handleFocusGained(fe); + /* + * Fix for Bug# 63297 When the palette gets focus, the LWS will take care of setting focus + * on the correct figure. However, when the user clicks on an entry, the focus is + * "thrown away." In that case, the LWS would set focus on the first focusable figure. We + * override that here and set focus on the correct/selected figure. Invoking + * getFocusEditPart().setFocus(true) does not work because that editpart thinks it already + * has focus (it's not aware of focus being thrown away) and does nothing. + */ + if (focusPart == null) { + IFigure fig = ((GraphicalEditPart) getFocusEditPart()).getFigure(); + fig.internalGetEventDispatcher().requestFocus(fig); + } + } + + /** + * @see org.eclipse.gef.ui.parts.GraphicalViewerImpl#hookControl() + */ + protected void hookControl() { + super.hookControl(); + FigureCanvas canvas = getFigureCanvas(); + canvas.getViewport().setContentsTracksWidth(true); + canvas.getViewport().setContentsTracksHeight(!globalScrollbar); + canvas.setHorizontalScrollBarVisibility(FigureCanvas.NEVER); + canvas.setVerticalScrollBarVisibility(globalScrollbar ? FigureCanvas.ALWAYS + : FigureCanvas.AUTOMATIC); + if (prefs != null) + prefs.addPropertyChangeListener(prefListener); + updateFont(); + } + + /** + * Returns true if the given PaletteDrawer is expanded + * + * @param drawer + * the PaletteDrawer + * @return true if expanded + */ + public boolean isExpanded(PaletteDrawer drawer) { + EditPart ep = (EditPart) getEditPartRegistry().get(drawer); + if (ep instanceof DrawerEditPart) + return ((DrawerEditPart) ep).isExpanded(); + return false; + } + + /** + * Returns true if the given PaletteDrawer is pinned + * + * @param drawer + * the PaletteDrawer + * @return true if pinned + */ + public boolean isPinned(PaletteDrawer drawer) { + EditPart ep = (EditPart) getEditPartRegistry().get(drawer); + if (ep instanceof DrawerEditPart) + return ((DrawerEditPart) ep).isPinnedOpen(); + return false; + } + + /** + * The given PaletteListener will not be notified of active tool changes in the palette. + * + * @param paletteListener + * the PaletteListener which doesn't want to be notified of active tool changes in + * the palette anymore + */ + public void removePaletteListener(PaletteListener paletteListener) { + paletteListeners.remove(paletteListener); + } + + /** + * Tries to apply the state of the given IMemento to the contents of this viewer. It fails + * silently, i.e. no exceptions are thrown if the given state could not be applied. + * + * @param memento + * The memento that has the state to be applied to the contents of this viewer + * @return a boolean indicating whether or not the given memento was successfully applied + * @since 3.0 + */ + public boolean restoreState(IMemento memento) { + try { + PaletteEditPart part = (PaletteEditPart) getEditPartRegistry().get( + getPaletteRoot()); + if (part != null) + part.restoreState(memento); + } catch (RuntimeException re) { + /* + * @TODO:Pratik Perhaps you should log this exception. Or not catch it at all. + */ + return false; + } + return true; + } + + /** + * @see ScrollingGraphicalViewer#reveal(EditPart) + */ + public void reveal(EditPart part) { + // If the given part is a drawer, we don't need to expand it. Hence, + // when invoking + // findContainingDrawer(), we use part.getParent() + DrawerEditPart drawer = findContainingDrawer(part.getParent()); + if (drawer != null && !drawer.isExpanded()) + drawer.setExpanded(true); + // if the part is inside a stack, set it to be the top level item of the + // stack. + if (part.getParent() != null + && part.getParent() instanceof PaletteStackEditPart) + ((PaletteStack) part.getParent().getModel()) + .setActiveEntry((PaletteEntry) part.getModel()); + super.reveal(part); + } + + /** + * Captures the state of the contents of this viewer in the given memento + * + * @param memento + * the IMemento in which the state is to be saved + * @since 3.0 + */ + public void saveState(IMemento memento) { + // Bug# 69026 - The PaletteRoot can be null initially for VEP + PaletteEditPart base = (PaletteEditPart) getEditPartRegistry().get( + getPaletteRoot()); + if (base != null) + base.saveState(memento); + } + + /** + * Sets the customizer. + * + * @param customizer + * the customizer to be set + */ + public void setCustomizer(PaletteCustomizer customizer) { + this.customizer = customizer; + } + + /** + * Sets the active entry for this palette. The Editpart for the given entry will be activated + * (selected). + * + * @param newMode + * the ToolEntry whose EditPart has to be set as the active tool in this palette + */ + public void setActiveTool(ToolEntry newMode) { + if (newMode == null) + newMode = getPaletteRoot().getDefaultEntry(); + if (activeEntry != null) + getToolEntryEditPart(activeEntry).setToolSelected(false); + activeEntry = newMode; + if (activeEntry != null) { + ToolEntryEditPart editpart = getToolEntryEditPart(activeEntry); + if (editpart != null) { + editpart.setToolSelected(true); + } + } + fireModeChanged(); + } + + /** + * Sets the root for this palette. + * + * @param root + * the PaletteRoot for this palette + */ + public void setPaletteRoot(PaletteRoot root) { + if (root == paletteRoot) + return; + paletteRoot = root; + if (paletteRoot != null) { + EditPart palette = getEditPartFactory().createEditPart( + getRootEditPart(), root); + getRootEditPart().setContents(palette); + } + } + + /** + * This palette will use the given PaletteViewerPreferences to store all its preferences. + *

+ * NOTE: This method should be invoked by a client only once (before the first time + * {@link #getPaletteViewerPreferences()} is invoked). Trying to invoke this method after that + * could lead to problems where some preferences would still be stored in the old preference + * store. + *

+ * + * @param prefs + * the PaletteViewerPreferences that is to be used to store all the preferences for + * this palette + */ + public void setPaletteViewerPreferences(PaletteViewerPreferences prefs) { + if (this.prefs != null) + this.prefs.removePropertyChangeListener(prefListener); + this.prefs = prefs; + if (getControl() != null && !getControl().isDisposed()) + this.prefs.addPropertyChangeListener(prefListener); + } + + /** + * @see org.eclipse.gef.ui.parts.AbstractEditPartViewer#unhookControl() + */ + protected void unhookControl() { + super.unhookControl(); + disposeFont(); + if (prefs != null) + prefs.removePropertyChangeListener(prefListener); + } + + private void updateFont() { + disposeFont(); + + if (getControl() == null || getControl().isDisposed()) + return; + + font = new Font(Display.getCurrent(), getPaletteViewerPreferences() + .getFontData()); + getControl().setFont(font); + getFigureCanvas().getViewport().invalidateTree(); + getFigureCanvas().getViewport().revalidate(); + getFigureCanvas().redraw(); + } + + /* + * TIZEN: add new UI: This shows a dynamically categories { + * + * The empty view state cases show only UI Container. Otherwise it shows all. + * + * @param bEmptyViewSate (empty) view state of current view + */ + public void setCategoryState(boolean bEmptyViewSate) { + if (this.categoryState == bEmptyViewSate) { + return; + } + this.categoryState = bEmptyViewSate; + EditPart root = getRootEditPart().getContents(); + + List categoryEditPartList = root.getChildren(); + DrawerEditPart categoryEditPart = null; + for (Object categoryObj : categoryEditPartList) { + if (categoryObj instanceof DrawerEditPart) { + categoryEditPart = (DrawerEditPart) categoryObj; + DrawerFigure drawerFigure = categoryEditPart.getDrawerFigure(); + if (bEmptyViewSate) { + PaletteDrawer drawer = categoryEditPart.getDrawer(); + if (!drawer.getDescription().equals(PaletteConstants.CATEGORY_NAME_UI_CONTAINERS)) { + drawerFigure.setVisible(false); + } + } else { + drawerFigure.setVisible(true); + } + } + } + } // end of setCategoryState + /* TIZEN } */ + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/PaletteViewerPreferences.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/PaletteViewerPreferences.java new file mode 100644 index 0000000..ede293d --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/PaletteViewerPreferences.java @@ -0,0 +1,306 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette; + +import java.beans.PropertyChangeListener; + +import org.eclipse.swt.graphics.FontData; + + +/** + * PaletteViewerPreferences is used to store/persist the various settings of a GEF + * palette. + *

+ * IMPORTANT: This interface is not intended to be implemented by clients. Clients + * should inherit from {@link DefaultPaletteViewerPreferences}. New methods may be added in the + * future. + * + * @author Pratik Shah + */ +public interface PaletteViewerPreferences { + + /** + * This is a constant for one of the auto-collapse options.
+ * Indicates that containers should always auto-collapse. + */ + int COLLAPSE_ALWAYS = 2; + + /** + * This is a constant for one of the auto-collapse options.
+ * Indicates that containers should never auto-collapse. + */ + int COLLAPSE_NEVER = 1; + + /** + * This is a constant for one of the auto-collapse options.
+ * Indicates that containers should auto-collapse only when there is not enough room on the + * palette. This is the default auto-collapse setting. + */ + int COLLAPSE_AS_NEEDED = 0; + + /** + * This is a constant for one of the layout options.
+ * Indicates that the palette should be displayed in the columns mode. + */ + int LAYOUT_COLUMNS = 1; + + /** + * @deprecated Use LAYOUT_COLUMNS instead. + */ + int LAYOUT_FOLDER = LAYOUT_COLUMNS; + + /** + * This is a constant for one of the layout options.
+ * Indicates that the palette should be displayed in the list mode. This is the default layout + * setting. + */ + int LAYOUT_LIST = 0; + + /** + * This is a constant for one of the layout options.
+ * Indicates that the palette should be displayed in the icons only mode. + */ + int LAYOUT_ICONS = 2; + + /** + * This is a constant for one of the layout options.
+ * Indicates that the palette should be displayed in the details mode. + */ + int LAYOUT_DETAILS = 3; + + /** + * Property name for the layout setting. If the PropertyChangeEvent fired has this property + * name, it means that the layout setting was changed. + */ + String PREFERENCE_LAYOUT = "Layout Setting"; //$NON-NLS-1$ + + /** + * Property name for the auto-collapse setting. If the PropertyChangeEvent fired has this + * property name, it means that the auto-collapse setting was changed. + */ + String PREFERENCE_AUTO_COLLAPSE = "Auto-Collapse Setting"; //$NON-NLS-1$ + + /** + * Property name for the large icon setting for columns layout. If the PropertyChangeEvent fired + * has this property name, it means that the large icon setting was changed for columns layout. + * Large icons are default. + */ + String PREFERENCE_COLUMNS_ICON_SIZE = "Use Large Icons - Columns"; //$NON-NLS-1$ + + /** + * @deprecated Use PREFERENCE_COLUMNS_ICON_SIZE instead. + */ + String PREFERENCE_FOLDER_ICON_SIZE = PREFERENCE_COLUMNS_ICON_SIZE; + + /** + * Property name for the large icon setting for list layout. If the PropertyChangeEvent fired + * has this property name, it means that the large icon setting was changed for list layout. + * Small icons are default. + */ + String PREFERENCE_LIST_ICON_SIZE = "Use Large Icons - List"; //$NON-NLS-1$ + + /** + * Property name for the large icon setting for icons only layout. If the PropertyChangeEvent + * fired has this property name, it means that the large icon setting was changed for icons only + * layout. Large icons are default. + */ + String PREFERENCE_ICONS_ICON_SIZE = "Use Large Icons - Icons"; //$NON-NLS-1$ + + /** + * Property name for the large icon setting for details layout. If the PropertyChangeEvent fired + * has this property name, it means that the large icon setting was changed for details layout. + * Small icons are default. + */ + String PREFERENCE_DETAILS_ICON_SIZE = "Use Large Icons - Details"; //$NON-NLS-1$ + + /** + * Property name for the palette font setting. If the PropertyChangeEvent fired has this + * property name, it means that the palette font was changed. + */ + String PREFERENCE_FONT = "Palette Font"; //$NON-NLS-1$ + + /** + * @param listener + * the PropertyChangeListener to be notified of changes + * @see java.beans.PropertyChangeSupport#addPropertyChangeListener(java.beans.PropertyChangeListener) + */ + void addPropertyChangeListener(PropertyChangeListener listener); + + /** + * Returns the current auto-collapse setting. + *

+ * Possible values returned: + *

    + *
  • COLLAPSE_ALWAYS (Always collapse)
  • + *
  • COLLAPSE_AS_NEEDED (Collapse when needed)
  • + *
  • COLLAPSE_NEVER (Never collapse)
  • + *
+ * + * @return One of the above-mentioned constants + */ + int getAutoCollapseSetting(); + + /** + * @return The FontData for the font to be used in the palette. + */ + FontData getFontData(); + + /** + * Returns the current layout setting. + *

+ * Possible values returned: + *

    + *
  • LAYOUT_COLUMNS (columns View)
  • + *
  • LAYOUT_LIST (List View)
  • + *
  • LAYOUT_ICONS (Icons Only View)
  • + *
  • LAYOUT_DETAILS (Details View)
  • + *
+ * + * @return One of the above-mentioned constants + */ + int getLayoutSetting(); + + /** + * Returns the layout modes that are supported. All four layout modes -- LAYOUT_COLUMNS, + * LAYOUT_LIST, LAYOUT_ICONS, LAYOUT_DETAILS -- are supported by default. + * + * @return The layout modes that are supported + * @see #setSupportedLayoutModes(int[]) + */ + int[] getSupportedLayoutModes(); + + /** + * This is a convenience method. Instead of getting the supported layout modes and checking to + * see if a certain layout is supported, you can call this method. + * + * @param layout + * LAYOUT_COLUMNS, LAYOUT_LIST, LAYOUT_ICONS, or LAYOUT_DETAILS + * @return true if the given layout is a supported mode + */ + boolean isSupportedLayoutMode(int layout); + + /** + * @param listener + * the PropertyChangeListener that should not be notified hereafter + * @see java.beans.PropertyChangeSupport#removePropertyChangeListener(java.beans.PropertyChangeListener) + */ + void removePropertyChangeListener(PropertyChangeListener listener); + + /** + * Sets the auto-collapse setting. + *

+ * Possible values: + *

    + *
  • COLLAPSE_ALWAYS (Always collapse)
  • + *
  • COLLAPSE_AS_NEEDED (Collapse when needed)
  • + *
  • COLLAPSE_NEVER (Never collapse)
  • + *
+ * + * @param newVal + * One of the above-mentioned constants + */ + void setAutoCollapseSetting(int newVal); + + /** + * Sets the FontData for the palette. + * + * @param data + * The FontData for the font to be used in the palette + */ + void setFontData(FontData data); + + /** + * Sets the given setting as the current layout. + *

+ * Possible values: + *

    + *
  • LAYOUT_COLUMNS (Columns View)
  • + *
  • LAYOUT_LIST (List View)
  • + *
  • LAYOUT_ICONS (Icons Only View)
  • + *
  • LAYOUT_DETAILS (Details View)
  • + *
+ * + * @param newVal + * One of the above-mentioned constants + */ + void setLayoutSetting(int newVal); + + /** + * Sets the "Use Large Icons" option for the currently active layout. + * + * @param newVal + * true if large icons are to be used with the current layout setting + */ + void setCurrentUseLargeIcons(boolean newVal); + + /** + * The client can restrict the modes that the palette supports using this method. By default, + * the palette will support all layout modes: LAYOUT_ICONS, LAYOUT_DETAILS, LAYOUT_COLUMNS, + * LAYOUT_LIST. Should the client wish to not support all these modes, they can call this method + * with an array of the desired modes. This method should be called during set-up as soon as the + * preferences are created, and not later. + *

+ * If the default layout mode and/or the current layout mode are not in the given array, the + * first layout mode in the given array will be set to be the default/current layout. + *

+ *

+ * NOTE: The given array of layout modes should have at least one, and is recommended to have at + * least two, of the recognized layout modes. + *

+ * + * @param modes + * an array of layout modes desired + */ + void setSupportedLayoutModes(int[] modes); + + /** + * Sets the "Use Large Icons" option for the given layout.
+ * The defaults are as follows: + *
    + *
  • LAYOUT_COLUMNS - true
  • + *
  • LAYOUT_LIST - false
  • + *
  • LAYOUT_ICONS - true
  • + *
  • LAYOUT_DETAILS - false
  • + *
+ * + * @param layout + * any of the above-mentioned constants + * @param newVal + * true if large icons are to be used with the given layout + */ + void setUseLargeIcons(int layout, boolean newVal); + + /** + * Indicated whether large icons should be used with the given layout mode.
+ * The defaults are as follows: + *
    + *
  • LAYOUT_COLUMNS - true
  • + *
  • LAYOUT_LIST - false
  • + *
  • LAYOUT_ICONS - true
  • + *
  • LAYOUT_DETAILS - false
  • + *
+ * + * @param layout + * any of the above-mentioned constants + * @return true if large icons are to be used with the given layout + */ + boolean useLargeIcons(int layout); + + /** + * @return true if large icons are to be used with the currently active layout + */ + boolean useLargeIcons(); + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/PaletteViewerProvider.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/PaletteViewerProvider.java new file mode 100644 index 0000000..245a1be --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/PaletteViewerProvider.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2004, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.gef.EditDomain; +import org.eclipse.swt.widgets.Composite; + + +/** + * PaletteViewerProvider provides a standard way of creating palette viewers that can be shared + * across different clients that need to create a palette (PaletteViewerPage and + * FlyoutPaletteComposite, for instance). + * + * @author Pratik Shah + * @since 3.0 + */ +public class PaletteViewerProvider { + + private TizenEditDomain graphicalViewerEditDomain; + + /** + * Constructor + * + * @param graphicalViewerDomain + * The EditDomain with which each newly created PaletteViewer will be registered + */ + public PaletteViewerProvider(EditDomain graphicalViewerDomain) { + Assert.isNotNull(graphicalViewerDomain); + graphicalViewerEditDomain = (TizenEditDomain) graphicalViewerDomain; + } + + /** + * This method is invoked from {@link #createPaletteViewer(Composite)}. It configures the given + * viewer's settings. + * + * @param viewer + * the viewer that is to be configured + */ + protected void configurePaletteViewer(PaletteViewer viewer) { + viewer.setContextMenu(new PaletteContextMenuProvider(viewer)); + } + + /** + * Creates a PaletteViewer on the given Composite + * + * @param parent + * the control for the PaletteViewer + * @return the newly created PaletteViewer + */ + public PaletteViewer createPaletteViewer(Composite parent) { + PaletteViewer pViewer = new PaletteViewer(); + pViewer.createControl(parent); + configurePaletteViewer(pViewer); + hookPaletteViewer(pViewer); + return pViewer; + } + + /** + * @return the EditDomain provided during creation of this PaletteViewerProvider + */ + public final EditDomain getEditDomain() { + return graphicalViewerEditDomain; + } + + /** + * This method is invoked from {@link #createPaletteViewer(Composite)}. It is a step in the + * process of setting up the PaletteViewer after it has been created. + * + * @param viewer + * the viewer that is to be configured + */ + protected void hookPaletteViewer(PaletteViewer viewer) { + ((TizenEditDomain) getEditDomain()).setTizenPaletteViewer(viewer); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/PinDrawerAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/PinDrawerAction.java new file mode 100644 index 0000000..efce168 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/PinDrawerAction.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette; + +import org.eclipse.jface.action.Action; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.DrawerEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.editparts.IPinnableEditPart; + + +/** + * An action that can be used to pin the given pinnable palette editpart (drawer or stack) open. + * + * @author Pratik Shah + */ +public class PinDrawerAction extends Action { + + private IPinnableEditPart pinnableEditPart; + + /** + * Constructor + * + * @param drawer + * The EditPart for the drawer that this action pins/unpins + */ + public PinDrawerAction(DrawerEditPart drawer) { + this.pinnableEditPart = drawer; + setChecked(drawer.isPinnedOpen()); + setEnabled(drawer.isExpanded()); + setText(PaletteMessages.PINNED); + } + + /** + * Constructor + * + * @param pinnableEditPart + * the pinnable palette editpart + * @since 3.4 + */ + public PinDrawerAction(IPinnableEditPart pinnableEditPart) { + this.pinnableEditPart = pinnableEditPart; + setChecked(pinnableEditPart.isPinnedOpen()); + setEnabled(pinnableEditPart.isExpanded()); + setText(PaletteMessages.PINNED); + } + + /** + * Toggles the pinned open status of the pinnable palette editpart. + * + * @see org.eclipse.jface.action.Action#run() + */ + public void run() { + pinnableEditPart.setPinnedOpen(!pinnableEditPart.isPinnedOpen()); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/SettingsAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/SettingsAction.java new file mode 100644 index 0000000..d1e59a3 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/SettingsAction.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.dialogs.Dialog; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.customize.PaletteSettingsDialog; + + +/** + * An action to launch the Settings dialog for the given palette. + * + * @author Pratik Shah + */ +public class SettingsAction extends Action { + + private PaletteViewer paletteViewer; + + /** + * Constructor + * + * @param palette + * The Palette which has to be customized when this action is run + */ + public SettingsAction(PaletteViewer palette) { + super(); + setText(PaletteMessages.MENU_OPEN_SETTINGS_DIALOG); + paletteViewer = palette; + } + + /** + * Opens the Settings dialog + * + * @see org.eclipse.jface.action.Action#run() + */ + public void run() { + Dialog settings = new PaletteSettingsDialog(paletteViewer.getControl() + .getShell(), paletteViewer.getPaletteViewerPreferences()); + settings.open(); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/TizenEditDomain.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/TizenEditDomain.java new file mode 100644 index 0000000..da01129 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/TizenEditDomain.java @@ -0,0 +1,486 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * 1) update package name + * 2) apply new UI + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.gef.DefaultEditDomain; +import org.eclipse.gef.EditPartViewer; +import org.eclipse.gef.Tool; +import org.eclipse.gef.tools.SelectionTool; +import org.eclipse.swt.dnd.DragSourceEvent; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.TraverseEvent; +import org.eclipse.swt.widgets.Event; +import org.eclipse.ui.IEditorPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteListener; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteRoot; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.ToolEntry; + + +/** + * The collective state of a GEF "application", loosely defined by a CommandStack, one or more + * EditPartViewers, and the active Tool. An EditDomain is usually tied with an Eclipse + * {@link org.eclipse.ui.IEditorPart IEditorPart}). However, the distinction between EditorPart and + * EditDomain was made to allow for much flexible use of the Graphical Editing Framework. + */ +public class TizenEditDomain extends DefaultEditDomain { + + private Tool defaultTool; + private PaletteViewer paletteViewer; + private PaletteRoot paletteRoot; + private Tool activeTool; + private List viewers = new ArrayList(); + + /** + * Listens to the PaletteViewer for changes in selection, and sets the Domain's Tool + * accordingly. + */ + private PaletteListener paletteListener = new PaletteListener() { + /* TIZEN */ + @Override + public void activeToolChanged(org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewer palette, + ToolEntry tool) { + handlePaletteToolChanged(); // TIZEN - click and drop + } + }; + + /** + * Constructs an EditDomain and loads the default tool. + */ + public TizenEditDomain(IEditorPart editorPart) { + super(editorPart); + } + + /** + * Adds an EditPartViewer into the EditDomain. A viewer is most likely placed in a + * {@link org.eclipse.ui.IWorkbenchPart WorkbenchPart} of some form, such as the IEditorPart or + * an IViewPart. + * + * @param viewer + * The EditPartViewer + */ + // public void addViewer(EditPartViewer viewer) { + // viewer.setEditDomain(this); + // if (!viewers.contains(viewer)) + // viewers.add(viewer); + // } + public void addViewer(PaletteViewer viewer) { + viewer.setEditDomain(this); + if (!viewers.contains(viewer)) + viewers.add(viewer); + } + + /** + * Called when one of the EditDomain's Viewers receives keyboard focus. + * + * @param event + * The SWT focus event + * @param viewer + * the Viewer that received the event. + */ + public void focusGained(FocusEvent event, EditPartViewer viewer) { + Tool tool = getActiveTool(); + if (tool != null) + tool.focusGained(event, viewer); + } + + /** + * Called when one of the EditDomain's Viewers is losing keyboard focus. + * + * @param event + * The SWT focus event + * @param viewer + * the Viewer that received the event. + */ + public void focusLost(FocusEvent event, EditPartViewer viewer) { + Tool tool = getActiveTool(); + if (tool != null) + tool.focusLost(event, viewer); + } + + /** + * Returns the active Tool + * + * @return the active Tool + */ + public Tool getActiveTool() { + return activeTool; + } + + /** + * Returns the CommandStack. Command stacks could potentially be shared across domains depending + * on the application. + * + * @return The command stack + */ + // public CommandStack getCommandStack() { + // return commandStack; + // } + + /** + * Returns the default tool for this edit domain. This will be a + * {@link org.eclipse.gef.tools.SelectionTool} unless specifically replaced using + * {@link #setDefaultTool(Tool)}. + * + * @return The default Tool for this domain + */ + public Tool getDefaultTool() { + if (defaultTool == null) + defaultTool = new SelectionTool(); + return defaultTool; + } + + /** + * Returns the palette viewer currently associated with this domain. + * + * @since 1.0 + * @return The current palette viewer + */ + + public org.eclipse.gef.ui.palette.PaletteViewer getPaletteViewer() { + // return (ScrollingGraphicalViewer)paletteViewer; + return null; + } + + public PaletteViewer getTizenPaletteViewer() { + // return (ScrollingGraphicalViewer)paletteViewer; + return paletteViewer; + } + + private void handlePaletteToolChanged() { + PaletteViewer paletteViewer = getTizenPaletteViewer(); + if (paletteViewer != null) { + ToolEntry entry = paletteViewer.getActiveTool(); + if (entry != null) + setActiveTool(entry.createTool()); + else + setActiveTool(getDefaultTool()); + } + } + + /** + * Called when a key is pressed on a Viewer. + * + * @param keyEvent + * The SWT key event + * @param viewer + * The source of the event. + */ + public void keyDown(KeyEvent keyEvent, EditPartViewer viewer) { + Tool tool = getActiveTool(); + if (tool != null) + tool.keyDown(keyEvent, viewer); + } + + /** + * Called when a traversal occurs on a viewer. + * + * @param traverseEvent + * the SWT traverse event + * @param viewer + * the source of the event + * @since 3.1 + */ + public void keyTraversed(TraverseEvent traverseEvent, EditPartViewer viewer) { + Tool tool = getActiveTool(); + if (tool != null) + tool.keyTraversed(traverseEvent, viewer); + } + + /** + * Called when a key is released on a Viewer. + * + * @param keyEvent + * The SWT key event + * @param viewer + * the source of the event. + */ + public void keyUp(KeyEvent keyEvent, EditPartViewer viewer) { + Tool tool = getActiveTool(); + if (tool != null) + tool.keyUp(keyEvent, viewer); + } + + /** + * Loads the default Tool. If a palette has been provided and that palette has a default, then + * that tool is loaded. If not, the EditDomain's default tool is loaded. By default, this is the + * {@link org.eclipse.gef.tools.SelectionTool}. + */ + public void loadDefaultTool() { + setActiveTool(null); + PaletteViewer paletteViewer = getTizenPaletteViewer(); + if (paletteRoot != null && paletteViewer != null) { + if (paletteRoot.getDefaultEntry() != null) { + paletteViewer.setActiveTool(paletteRoot.getDefaultEntry()); + return; + } else + paletteViewer.setActiveTool(null); + } + setActiveTool(getDefaultTool()); + } + + /** + * Called when the mouse button has been double-clicked on a Viewer. + * + * @param mouseEvent + * The SWT mouse event + * @param viewer + * The source of the event. + */ + public void mouseDoubleClick(MouseEvent mouseEvent, EditPartViewer viewer) { + Tool tool = getActiveTool(); + if (tool != null) + tool.mouseDoubleClick(mouseEvent, viewer); + } + + /** + * Called when the mouse button has been pressed on a Viewer. + * + * @param mouseEvent + * The SWT mouse event + * @param viewer + * The source of the event. + */ + public void mouseDown(MouseEvent mouseEvent, EditPartViewer viewer) { + Tool tool = getActiveTool(); + if (tool != null) + tool.mouseDown(mouseEvent, viewer); + } + + /** + * Called when the mouse has been dragged within a Viewer. + * + * @param mouseEvent + * The SWT mouse event + * @param viewer + * The source of the event. + */ + public void mouseDrag(MouseEvent mouseEvent, EditPartViewer viewer) { + Tool tool = getActiveTool(); + if (tool != null) + tool.mouseDrag(mouseEvent, viewer); + } + + /** + * Called when the mouse has hovered on a Viewer. + * + * @param mouseEvent + * The SWT mouse event + * @param viewer + * The source of the event. + */ + public void mouseHover(MouseEvent mouseEvent, EditPartViewer viewer) { + Tool tool = getActiveTool(); + if (tool != null) + tool.mouseHover(mouseEvent, viewer); + } + + /** + * Called when the mouse has been moved on a Viewer. + * + * @param mouseEvent + * The SWT mouse event + * @param viewer + * The viewer that the mouse event is over. + */ + public void mouseMove(MouseEvent mouseEvent, EditPartViewer viewer) { + Tool tool = getActiveTool(); + if (tool != null) + tool.mouseMove(mouseEvent, viewer); + } + + /** + * Called when the mouse button has been released on a Viewer. + * + * @param mouseEvent + * The SWT mouse event + * @param viewer + * The source of the event. + */ + public void mouseUp(MouseEvent mouseEvent, EditPartViewer viewer) { + Tool tool = getActiveTool(); + if (tool != null) + tool.mouseUp(mouseEvent, viewer); + } + + /** + * Called by the DomainEventDispatcher when the mouse wheel has been scrolled. + * + * @param event + * The SWT event + * @param viewer + * The source of the event + */ + public void mouseWheelScrolled(Event event, EditPartViewer viewer) { + Tool tool = getActiveTool(); + if (tool != null) + tool.mouseWheelScrolled(event, viewer); + } + + /** + * Called when a native drag has finished on a Viewer. + * + * @param event + * The DragSourceEvent + * @param viewer + * The viewer where the drag finished + */ + public void nativeDragFinished(DragSourceEvent event, EditPartViewer viewer) { + Tool tool = getActiveTool(); + if (tool != null) + tool.nativeDragFinished(event, viewer); + } + + /** + * Called when a native drag has started on a Viewer. + * + * @param event + * The DragSourceEvent + * @param viewer + * The viewer where the drag started + */ + public void nativeDragStarted(DragSourceEvent event, EditPartViewer viewer) { + Tool tool = getActiveTool(); + if (tool != null) + tool.nativeDragStarted(event, viewer); + } + + /** + * Removes a previously added viewer from the EditDomain. A Viewer that is removed from the + * EditDomain will no longer forward input to the domain and its active Tool. + * + * @param viewer + * the Viewer being removed + */ + public void removeViewer(EditPartViewer viewer) { + if (viewers.remove(viewer)) + viewer.setEditDomain(null); + } + + /** + * Sets the CommandStack. + * + * @param stack + * the CommandStack + */ + // public void setCommandStack(CommandStack stack) { + // commandStack = stack; + // } + + /** + * Sets the default Tool, which is used if the Palette does not provide a default + * + * @param tool + * null or a Tool + */ + public void setDefaultTool(Tool tool) { + defaultTool = tool; + } + + /** + * Sets the PalatteRoot for this EditDomain. If the EditDomain already knows about a + * PaletteViewer, this root will be set into the palette viewer also. Loads the default Tool + * after the root has been set. + *

+ * It is recommended that the palette root not be set multiple times. Some components (such as + * the PaletteCustomizerDialog for the PaletteViewer) might still hold on to the old root. If + * the input has changed or needs to be refreshed, just remove all the children from the root + * and add the new ones. + * + * @param root + * the palette's root + */ + public void setPaletteRoot(PaletteRoot root) { + if (paletteRoot == root) + return; + paletteRoot = root; + if (getTizenPaletteViewer() != null) { + getTizenPaletteViewer().setPaletteRoot(paletteRoot); + loadDefaultTool(); + } + } + + /** + * Sets the PaletteViewer for this EditDomain + * + * @param palette + * the PaletteViewer + */ + public void setTizenPaletteViewer(PaletteViewer palette) { + if (palette == paletteViewer) + return; + if (paletteViewer != null) + paletteViewer.removePaletteListener(paletteListener); + paletteViewer = palette; + if (paletteViewer != null) { + palette.addPaletteListener(paletteListener); + if (paletteRoot != null) { + paletteViewer.setPaletteRoot(paletteRoot); + loadDefaultTool(); + } + } + } + + /** + * Sets the active Tool for this EditDomain. If a current Tool is active, it is deactivated. The + * new Tool is told its EditDomain, and is activated. + * + * @param tool + * the Tool + */ + public void setActiveTool(Tool tool) { + if (activeTool != null) + activeTool.deactivate(); + activeTool = tool; + if (activeTool != null) { + activeTool.setEditDomain(this); + activeTool.activate(); + } + } + + /** + * Called when the mouse enters a Viewer. + * + * @param mouseEvent + * the SWT mouse event + * @param viewer + * the Viewer being entered + */ + public void viewerEntered(MouseEvent mouseEvent, EditPartViewer viewer) { + Tool tool = getActiveTool(); + if (tool != null) + tool.viewerEntered(mouseEvent, viewer); + } + + /** + * Called when the mouse exits a Viewer. + * + * @param mouseEvent + * the SWT mouse event + * @param viewer + * the Viewer being exited + */ + public void viewerExited(MouseEvent mouseEvent, EditPartViewer viewer) { + Tool tool = getActiveTool(); + if (tool != null) + tool.viewerExited(mouseEvent, viewer); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/DefaultEntryPage.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/DefaultEntryPage.java new file mode 100644 index 0000000..e256df4 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/DefaultEntryPage.java @@ -0,0 +1,303 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.customize; + +import org.eclipse.draw2d.FigureUtilities; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.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; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteSeparator; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteMessages; + + +/** + * This is a default implementation of the {@link EntryPage} interface. It displays the entry's + * label, description and visible fields (and allows for their modification). It is live in the + * sense that the model is updated with the changes immediately (on every keystroke). + * + * @author Pratik Shah + */ +public class DefaultEntryPage implements EntryPage { + + private EntryPageContainer container; + + /** + * This is the panel that is created by {@link #createControl(Composite, PaletteEntry)}. It will + * be null if that method hasn't been invoked yet. + */ + private Composite panel; + /** + * This is the PaletteEntry that this page represents. It will be null + * until {@link #createControl(Composite, PaletteEntry)} is invoked. + */ + private PaletteEntry entry; + + /** + * Being live, this method is completely ignored. Model is updated with every keystroke. So, + * there is no need to wait for this method to be called to actually make the changes to the + * model. + */ + public final void apply() { + } + + /** + * @see org.eclipse.gef.ui.palette.customize.EntryPage#createControl(Composite, PaletteEntry) + */ + public void createControl(Composite parent, PaletteEntry entry) { + this.entry = entry; + + panel = new Composite(parent, SWT.NONE); + panel.setFont(parent.getFont()); + GridLayout gridLayout = new GridLayout(1, false); + gridLayout.marginWidth = 0; + gridLayout.marginHeight = 0; + panel.setLayout(gridLayout); + Control[] tablist = new Control[3]; + + createLabel(panel, SWT.NONE, PaletteMessages.NAME_LABEL); + tablist[0] = createNameText(panel); + + createLabel(panel, SWT.NONE, PaletteMessages.DESCRIPTION_LABEL); + tablist[1] = createDescText(panel); + + tablist[2] = createHiddenCheckBox(panel); + + panel.setTabList(tablist); + } + + /** + * Creates the Text where the description of the entry is to be displayed. + * + * @param panel + * The Composite in which the Text is to be created + * @return The newly created Text + */ + protected Text createDescText(Composite panel) { + String desc = entry.getDescription(); + Text description = createText(panel, SWT.MULTI | SWT.WRAP | SWT.BORDER + | SWT.V_SCROLL, desc); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.widthHint = 150; + data.heightHint = description.computeTrim(0, 0, 10, FigureUtilities + .getFontMetrics(description.getFont()).getHeight() * 2).height; + description.setLayoutData(data); + if (getPermission() >= PaletteEntry.PERMISSION_LIMITED_MODIFICATION) { + description.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + handleDescriptionChanged(((Text) e.getSource()).getText()); + } + }); + } + return description; + } + + /** + * Creates the Button (CheckBox) for indicating the hidden status of the entry. It + * initializes it with the current hidden state of entry. + * + * @param panel + * The Composite in which the Button is to be created + * @return The newly created Button + */ + protected Button createHiddenCheckBox(Composite panel) { + Button hidden = new Button(panel, SWT.CHECK); + hidden.setFont(panel.getFont()); + hidden.setText(PaletteMessages.HIDDEN_LABEL); + hidden.setSelection(!entry.isVisible()); + + if (getPermission() == PaletteEntry.PERMISSION_NO_MODIFICATION) { + hidden.setEnabled(false); + } else { + hidden.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleHiddenSelected(((Button) e.getSource()) + .getSelection()); + } + }); + } + + return hidden; + } + + /** + * Creates a label + * + * @param panel + * The Composite in which the Label is to be created + * @param style + * The stylebits for the Label + * @param text + * The Label's text + * @return Label - The newly created Label + */ + protected Label createLabel(Composite panel, int style, String text) { + Label label = new Label(panel, style); + label.setFont(panel.getFont()); + label.setText(text); + return label; + } + + /** + * Creates the Text where the name of the entry is to be displayed. + * + * @param panel + * The Composite in which the Text is to be created + * @return Text - The newly created Text + */ + protected Text createNameText(Composite panel) { + Text name = createText(panel, SWT.SINGLE | SWT.BORDER, entry.getLabel()); + if (getPermission() >= PaletteEntry.PERMISSION_LIMITED_MODIFICATION) { + name.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + handleNameChanged(((Text) e.getSource()).getText()); + } + }); + } + name.setVisible(true); + return name; + } + + /** + * Creates a Text. This method is mainly a result of code-factoring. + * + * @param panel + * The Composite in which the Text is to be created + * @param style + * The stylebits for the Text + * @param text + * The text to be displayed in the Text + * @return a text widget with griddata constraint + */ + protected Text createText(Composite panel, int style, String text) { + if (getEntry() instanceof PaletteSeparator + || getPermission() < PaletteEntry.PERMISSION_LIMITED_MODIFICATION) { + style = style | SWT.READ_ONLY; + } + + Text textBox = new Text(panel, style); + textBox.setFont(panel.getFont()); + if (text != null) + textBox.setText(text); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.widthHint = 200; + textBox.setLayoutData(data); + return textBox; + } + + /** + * @see org.eclipse.gef.ui.palette.customize.EntryPage#getControl() + */ + public Control getControl() { + return panel; + } + + /** + * Provides sub-classes with access to the entry this class is monitoring. + * + * @return PaletteEntry - The entry this class is monitoring + */ + protected PaletteEntry getEntry() { + return entry; + } + + /** + * Sub-classes should override this method to provide appropriate error notification messages. + * + * @return The message to be used when notifying listeners about a state change + */ + protected String getMessage() { + return ""; //$NON-NLS-1$ + } + + /** + * @return The EntryPageContainer to which this page can report errors. + */ + protected EntryPageContainer getPageContainer() { + return container; + } + + /** + *

+ * Updates the model with the change in the entry's description, and updates the state of the + * page. + *

+ *

+ * This method is invoked on every keystroke in the Text displaying the description of the + * entry. + *

+ * + * @param text + * The new description + */ + protected void handleDescriptionChanged(String text) { + getEntry().setDescription(text.trim()); + } + + /** + *

+ * Updates the model with the change in the entry's hidden state, and updates the state of the + * page. + *

+ *

+ * This method is invokes whenever the "Hidden" checkbox is selected. + *

+ * + * @param isChecked + * The new selection value + */ + protected void handleHiddenSelected(boolean isChecked) { + getEntry().setVisible(!isChecked); + } + + /** + *

+ * Updates the model with the change in the entry's name, and updates the state of the page. + *

+ *

+ * This method is invoked on every keystroke in the Text displaying the entry's name. + *

+ * + * @param text + * The new name + */ + protected void handleNameChanged(String text) { + getEntry().setLabel(text.trim()); + } + + /** + * @return the user permission on the entry + */ + protected int getPermission() { + return getEntry().getUserModificationPermission(); + } + + /** + * @see org.eclipse.gef.ui.palette.customize.EntryPage#setPageContainer(EntryPageContainer) + */ + public void setPageContainer(EntryPageContainer pageContainer) { + container = pageContainer; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/DrawerEntryPage.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/DrawerEntryPage.java new file mode 100644 index 0000000..10facbe --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/DrawerEntryPage.java @@ -0,0 +1,187 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.customize; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteDrawer; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteMessages; + + +/** + * The default entry page for drawers. + * + * @author Pratik Shah + */ +public class DrawerEntryPage extends DefaultEntryPage { + + private Button openDrawerOption, pinDrawerOption; + + private boolean contains(Object[] array, Object obj) { + for (int i = array.length - 1; i >= 0; i--) { + if (obj == array[i]) { + return true; + } + } + return false; + } + + /** + * @see org.eclipse.gef.ui.palette.customize.EntryPage#createControl(Composite, PaletteEntry) + */ + public void createControl(Composite parent, PaletteEntry entry) { + super.createControl(parent, entry); + + openDrawerOption = createOpenDrawerInitiallyOption(getComposite()); + pinDrawerOption = createPinDrawerInitiallyOption(getComposite()); + + Control[] oldTablist = getComposite().getTabList(); + if (!contains(oldTablist, openDrawerOption)) { + // This means that the super class must've set a specific tab order + // on this + // composite. We need to add the two newly created controls to this + // tab order. + Control[] newTablist = new Control[oldTablist.length + 2]; + System.arraycopy(oldTablist, 0, newTablist, 0, oldTablist.length); + newTablist[newTablist.length - 2] = openDrawerOption; + newTablist[newTablist.length - 1] = pinDrawerOption; + getComposite().setTabList(newTablist); + } + } + + /** + * Creates the button that provides the option to pin a drawer open at start-up. + * + * @param panel + * The parent Composite + * @return The button for the new option + */ + protected Button createOpenDrawerInitiallyOption(Composite panel) { + Button b = new Button(panel, SWT.CHECK); + b.setFont(panel.getFont()); + b.setText(PaletteMessages.EXPAND_DRAWER_AT_STARTUP_LABEL); + b.setSelection(getDrawer().isInitiallyOpen()); + if (getPermission() >= PaletteEntry.PERMISSION_LIMITED_MODIFICATION) { + b.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleOpenSelected(((Button) e.getSource()).getSelection()); + } + }); + } else { + b.setEnabled(false); + } + + return b; + } + + /** + * Creates the button that provides the option to have a drawer open at start-up. + * + * @param panel + * The parent Composite + * @return The button for the new option + */ + protected Button createPinDrawerInitiallyOption(Composite panel) { + Button pinOption = new Button(panel, SWT.CHECK); + pinOption.setFont(panel.getFont()); + pinOption.setText(PaletteMessages.DRAWER_PIN_AT_STARTUP); + GridData data = new GridData(); + data.horizontalIndent = 15; + pinOption.setLayoutData(data); + pinOption.setEnabled(openDrawerOption.getSelection() + && openDrawerOption.isEnabled()); + pinOption.setSelection(getDrawer().isInitiallyPinned()); + if (getPermission() >= PaletteEntry.PERMISSION_LIMITED_MODIFICATION) { + pinOption.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handlePinSelected(((Button) e.getSource()).getSelection()); + } + }); + } + return pinOption; + } + + private Composite getComposite() { + return (Composite) getControl(); + } + + /** + * Convenience method that provides access to the PaletteDrawer. + * + * @return the entry as a PaletteDrawer + */ + protected PaletteDrawer getDrawer() { + return (PaletteDrawer) getEntry(); + } + + /** + * Returns the checkbox button which controls whether the drawer is initially open. + * + * @return the checkbox button which controls the initially open setting. + */ + protected Button getOpenDrawerInitiallyButton() { + return openDrawerOption; + } + + /** + * Returns the checkbox button which controls whether the drawer is initially pinned. + * + * @return the checkbox button which controls the initially pinned setting. + */ + protected Button getPinDrawerInitiallyButton() { + return pinDrawerOption; + } + + /** + * This method is invoked when the selection state of the option to open drawer at start-up is + * toggled. + *

+ * It sets the initial state of the drawer accordingly. + * + * @param selection + * true if that option is now selected + */ + protected void handleOpenSelected(boolean selection) { + int status = selection ? PaletteDrawer.INITIAL_STATE_OPEN + : PaletteDrawer.INITIAL_STATE_CLOSED; + getDrawer().setInitialState(status); + pinDrawerOption.setEnabled(selection); + if (!selection) { + pinDrawerOption.setSelection(false); + } + } + + /** + * This method is invoked when the selection state of the option to pin a drawer open at + * start-up is toggled. + *

+ * It sets the initial state of the drawer accordingly. + * + * @param selection + * true if that option is now selected + */ + protected void handlePinSelected(boolean selection) { + int status = selection ? PaletteDrawer.INITIAL_STATE_PINNED_OPEN + : PaletteDrawer.INITIAL_STATE_OPEN; + getDrawer().setInitialState(status); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/EntryPage.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/EntryPage.java new file mode 100644 index 0000000..1a45ca6 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/EntryPage.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.customize; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteEntry; + + +/** + * An EntryPage displays properties of a PaletteEntry. Listeners can be + * added to a page + * + * @author Pratik Shah + */ +public interface EntryPage { + + /** + * Sets the page container for this page. This page will report its errors to the given page + * container. + * + * @param pageContainer + * The EntryPageContainer to which this page can report errors + */ + void setPageContainer(EntryPageContainer pageContainer); + + /** + * This method is called when changes made to properties need to be reflected in the model. + */ + void apply(); + + /** + * Creates the Control that displays the properties of the given entry. This method will only be + * called once. The parent Composite's Font is set to the Workbench Dialog Font. The page's + * Controls should use the Workbench Dialog Font where appropriate. + * + * @param parent + * The Composite in which the Control has to be created + * @param entry + * The entry whose properties have to be displayed + */ + void createControl(Composite parent, PaletteEntry entry); + + /** + * Returns the Panel (Control) that displays the properties of the entry. This is the same + * Control that was created in {@link #createControl(Composite,PaletteEntry)}. + * + * @return the Control that displays the properties of the entry + * @see #createControl(Composite, PaletteEntry) + */ + Control getControl(); + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/EntryPageContainer.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/EntryPageContainer.java new file mode 100644 index 0000000..aeef816 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/EntryPageContainer.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.customize; + +/** + * An EntryPageContainer allows an EntryPage to report errors to it. + * + * @author Pratik Shah + */ +public interface EntryPageContainer { + + /** + * Clears the error. + */ + void clearProblem(); + + /** + * Shows the error to the user. + * + * @param description + * A description of the problem. Should be as brief as possible. + */ + void showProblem(String description); + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteContainerFactory.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteContainerFactory.java new file mode 100644 index 0000000..22ba42e --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteContainerFactory.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.customize; + +import java.util.List; + +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteContainer; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteRoot; + + +/** + * Abstract factory for PaletteContainers + * + *

+ * This class does not create PaletteContainers within other + * PaletteContainers. The necessary methods may be overridden should such functionality be + * desired. + *

+ * + * @author Pratik Shah + */ +public abstract class PaletteContainerFactory extends PaletteEntryFactory { + + /** + * @see PaletteEntryFactory#determineContainerForNewEntry(PaletteEntry) + */ + protected PaletteContainer determineContainerForNewEntry( + PaletteEntry selected) { + if (selected instanceof PaletteRoot) + return (PaletteContainer) selected; + PaletteContainer current = selected.getParent(); + while (!(current instanceof PaletteRoot)) + current = current.getParent(); + return current; + } + + /** + * @see PaletteEntryFactory#determineIndexForNewEntry(PaletteContainer, PaletteEntry) + */ + protected int determineIndexForNewEntry(PaletteContainer parent, + PaletteEntry selected) { + if (parent == selected) { + return 0; + } + + List children = parent.getChildren(); + PaletteEntry current = selected; + while (!children.contains(current)) { + current = current.getParent(); + } + return children.indexOf(current) + 1; + } + + /** + * You can always create a new container. So, this method always returns true. + * + * @see org.eclipse.gef.ui.palette.customize.PaletteEntryFactory#canCreate(PaletteEntry) + */ + public boolean canCreate(PaletteEntry selected) { + return true; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteCustomizationAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteCustomizationAction.java new file mode 100644 index 0000000..5fa0291 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteCustomizationAction.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.customize; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.resource.ImageDescriptor; + + +/** + * PaletteCustomizationActions are used to manipulate the palette model. They can + * enable and disable themselves when needed. + * + *

+ * This class is mainly a result of code-factoring. + *

+ * + * @author Pratik Shah + */ +public abstract class PaletteCustomizationAction extends Action { + + /** + * Call this method to have the action update its state and enable or disable itself. + */ + public abstract void update(); + + /** + * @see org.eclipse.jface.action.Action#setImageDescriptor(ImageDescriptor) + */ + public void setImageDescriptor(ImageDescriptor newImage) { + super.setImageDescriptor(newImage); + setHoverImageDescriptor(newImage); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteCustomizerDialog.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteCustomizerDialog.java new file mode 100644 index 0000000..23183ad --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteCustomizerDialog.java @@ -0,0 +1,1347 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.customize; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.widgets.MultiLineLabel; +import org.eclipse.gef.internal.Internal; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.ActionContributionItem; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuCreator; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.JFaceColors; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.custom.StackLayout; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Color; +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.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.ToolItem; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.swt.widgets.Widget; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.part.PageBook; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.ToolbarDropdownContributionItem; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteRoot; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteCustomizer; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteMessages; + + +/** + * This class implements a default dialog that allows customization of the different entries/items + * on a GEF palette, i.e. the model behind the palette. + *

+ * The construction of the dialog is broken down into different methods in order to allow clients to + * further customize the appearance of the dialog, if so desired. + *

+ *

+ * This dialog can be re-used, i.e., it can be re-opened once closed. There is no need to create a + * new PaletteCustomizerDialog everytime a palette needs to be customized. + *

+ * + * @author Pratik Shah + * @see org.eclipse.gef.palette.PaletteEntry + * @see org.eclipse.gef.ui.palette.PaletteCustomizer + */ +public class PaletteCustomizerDialog extends Dialog implements + EntryPageContainer { + + /** + * The unique ID for the Apply Button. It can be used to retrieve that widget from the internal + * map (using {@link #getWidget(int)} or {@link #getButton(int)}), or to identify that widget in + * {@link #buttonPressed(int)}. + */ + protected static final int APPLY_ID = IDialogConstants.CLIENT_ID + 1; + + /** + * Sub-classes that need to create their own unique IDs should do so by adding to this ID. + */ + protected static final int CLIENT_ID = 16; + + private HashMap widgets = new HashMap(); + private HashMap entriesToPages = new HashMap(); + private List actions; + + private String errorMessage; + private Tree tree; + private Composite titlePage, errorPage; + private PageBook propertiesPanelContainer; + // This PageBook is used to switch the title of the properties panel to + // either an error + // message or the currently active entry's label + private PageBook titleSwitcher; + private PaletteCustomizer customizer; + private EntryPage activePage, noSelectionPage; + private CLabel title; + private MultiLineLabel errorTitle; + private Image titleImage; + private TreeViewer treeviewer; + private ILabelProvider treeViewerLabelProvider; + private PaletteEntry activeEntry; + private PaletteEntry initialSelection; + private PaletteRoot root; + private PropertyChangeListener titleUpdater = new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent evt) { + if (title == null) { + return; + } + + title.setText(((PaletteEntry) evt.getSource()).getLabel()); + } + }; + private ISelectionChangedListener pageFlippingPreventer = new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + treeviewer.removePostSelectionChangedListener(this); + treeviewer.setSelection(new StructuredSelection(activeEntry)); + } + }; + private boolean isSetup = true; + + /** + * Constructs a new customizer dialog. + * + * @param shell + * the parent Shell + * @param customizer + * the customizer + * @param root + * the palette root + */ + public PaletteCustomizerDialog(Shell shell, PaletteCustomizer customizer, + PaletteRoot root) { + super(shell); + this.customizer = customizer; + this.root = root; + setShellStyle(getShellStyle() | SWT.RESIZE); + } + + /** + * This method will be invoked whenever any Button created using + * {@link #createButton(Composite, int, String, int, ImageDescriptor)} or + * {@link Dialog#createButton(Composite, int, String, boolean)} is selected. + * + * @see Dialog#buttonPressed(int) + */ + protected void buttonPressed(int buttonId) { + if (APPLY_ID == buttonId) { + handleApplyPressed(); + } else { + super.buttonPressed(buttonId); + } + } + + /** + * This method should be invoked by EntryPages when an error that they had earlier reported + * (using {@link #showProblem(String)}) is fixed. This will hide the error message, enable the + * OK and Apply buttons and re-allow changing selection in the outline tree. + * + * @see org.eclipse.gef.ui.palette.customize.EntryPageContainer#clearProblem() + * @see #showProblem(String) + */ + public void clearProblem() { + if (errorMessage != null) { + titleSwitcher.showPage(titlePage); + Button okBtn = getButton(IDialogConstants.OK_ID); + if (okBtn != null) { + okBtn.setEnabled(true); + } + Button applyBtn = getButton(APPLY_ID); + if (applyBtn != null) { + applyBtn.setEnabled(true); + } + errorMessage = null; + } + } + + /** + *

+ * NOTE: This dialog can be re-opened. + *

+ * + * @see org.eclipse.jface.window.Window#close() + */ + public boolean close() { + // Remove listeners + if (activeEntry != null) { + activeEntry.removePropertyChangeListener(titleUpdater); + } + + // Save or dump changes + // This needs to be done here and not in the handle methods because the + // user can + // also close the dialog with the 'X' in the top right of the window + // (which + // corresponds to a cancel). + if (getReturnCode() == OK) { + save(); + } else { + revertToSaved(); + } + + // Close the dialog + boolean returnVal = super.close(); + + // Reset variables + entriesToPages.clear(); + widgets.clear(); + actions = null; + activePage = null; + tree = null; + propertiesPanelContainer = null; + titleSwitcher = null; + titlePage = null; + errorPage = null; + title = null; + errorTitle = null; + treeviewer = null; + noSelectionPage = null; + initialSelection = null; + activeEntry = null; + errorMessage = null; + isSetup = true; + + return returnVal; + } + + /** + * @see org.eclipse.jface.window.Window#configureShell(Shell) + */ + protected void configureShell(Shell newShell) { + newShell.setText(PaletteMessages.CUSTOMIZE_DIALOG_TITLE); + super.configureShell(newShell); + } + + /** + * This method should not be used to create buttons for the button bar. Use + * {@link Dialog#createButton(Composite, int, String, boolean)} for that. This method can be + * used to create any other button in the dialog. The parent Composite must have a + * GridLayout. These buttons will be available through {@link #getButton(int)} and + * {@link #getWidget(int)}. Ensure that the various buttons created by this method are given + * unique IDs. Pass in a null image descriptor if you don't want the button to have + * an icon. This method will take care of disposing the images that it creates. + * {@link #buttonPressed(int)} will be called when any of the buttons created by this method are + * clicked (selected). + * + * @param parent + * The composite in which the button is to be created + * @param id + * The button's unique ID + * @param label + * The button's text + * @param stylebits + * The style bits for creating the button (eg., SWT.PUSH or + * SWT.CHECK) + * @param descriptor + * The ImageDescriptor from which the image/icon for this button should be created + * @return The newly created button for convenience + */ + protected Button createButton(Composite parent, int id, String label, + int stylebits, ImageDescriptor descriptor) { + Button button = new Button(parent, stylebits); + button.setText(label); + button.setFont(parent.getFont()); + GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + button.setLayoutData(data); + + button.setData(new Integer(id)); + button.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + buttonPressed(((Integer) event.widget.getData()).intValue()); + } + }); + widgets.put(new Integer(id), button); + + if (descriptor != null) { + button.setImage(new Image(parent.getDisplay(), descriptor + .getImageData())); + button.addDisposeListener(new DisposeListener() { + public void widgetDisposed(DisposeEvent e) { + Image img = ((Button) e.getSource()).getImage(); + if (img != null && !img.isDisposed()) { + img.dispose(); + } + } + }); + } + + return button; + } + + /** + * Creates the OK, Cancel and Apply buttons + * + * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(Composite) + */ + protected void createButtonsForButtonBar(Composite parent) { + super.createButtonsForButtonBar(parent); + createButton(parent, APPLY_ID, PaletteMessages.APPLY_LABEL, false); + } + + /** + * The dialog area contains the following: + *
    + *
  • Outline ({@link #createOutline(Composite)})
  • + *
  • Properties Panel ({@link #createPropertiesPanel(Composite)})
  • + *
+ * + *

+ * It is recommended that this method not be overridden. Override one of the methods that this + * method calls in order to customize the appearance of the dialog. + *

+ * + * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(Composite) + */ + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + GridLayout gridLayout = (GridLayout) composite.getLayout(); + gridLayout.numColumns = 2; + gridLayout.horizontalSpacing = 10; + + // Create the tree + Control child = createOutline(composite); + GridData data = new GridData(GridData.VERTICAL_ALIGN_FILL); + data.verticalSpan = 2; + child.setLayoutData(data); + + // Create the panel where the properties of the selected palette entry + // will + // be shown + child = createPropertiesPanel(composite); + child.setLayoutData(new GridData(GridData.FILL_BOTH)); + + // Create the separator b/w the dialog area and the button bar + Label label = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL); + data = new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan = 2; + label.setLayoutData(data); + + // Select an element in the outline and set focus on the outline. + if (initialSelection == null) { + // We have to manually select the first item in the tree, because + // otherwise the + // will scroll to show the last item, and then will select the first + // visible item. + List children = getPaletteRoot().getChildren(); + if (!children.isEmpty()) { + initialSelection = (PaletteEntry) children.get(0); + } + } + if (initialSelection != null) { + treeviewer.setSelection(new StructuredSelection(initialSelection)); + } else { + setActiveEntry(null); + } + isSetup = false; + tree.setFocus(); + + return composite; + } + + /** + * Creates the outline part of the dialog. + * + *

+ * The outline creates the following: + *

    + *
  • ToolBar ({@link #createOutlineToolBar(Composite)})
  • + *
  • TreeViewer ({@link #createOutlineTreeViewer(Composite)})
  • + *
  • Context menu ({@link #createOutlineContextMenu()})
  • + *
+ *

+ * + * @param container + * The Composite within which the outline has to be created + * @return The newly created Control that has the outline + */ + protected Control createOutline(Composite container) { + // Create the Composite that will contain the outline + Composite composite = new Composite(container, SWT.NONE); + composite.setFont(container.getFont()); + GridLayout layout = new GridLayout(); + layout.horizontalSpacing = 0; + layout.verticalSpacing = 0; + layout.marginHeight = 0; + layout.marginWidth = 0; + composite.setLayout(layout); + + // Create the ToolBar + createOutlineToolBar(composite); + + // Create the actual outline (TreeViewer) + treeviewer = createOutlineTreeViewer(composite); + tree = treeviewer.getTree(); + + // Create the context menu for the Tree + tree.setMenu(createOutlineContextMenu()); + + return composite; + } + + /** + * Creates the actions that manipulate the palette model. These actions will populate the + * toolbar and the outline's context menu. + * + *

+ * IMPORTANT: All the elements in the returned List MUST be + * PaletteCustomizationActions. + *

+ * + * @return A List of {@link PaletteCustomizationAction PaletteCustomizationActions} + */ + protected List createOutlineActions() { + List actions = new ArrayList(); + actions.add(new NewAction()); + actions.add(new DeleteAction()); + actions.add(new MoveDownAction()); + actions.add(new MoveUpAction()); + return actions; + } + + /** + * Uses a MenuManager to create the context menu for the outline. The + * IActions used to create the context menu are those created in + * {@link #createOutlineActions()}. + * + * @return The newly created Menu + */ + protected Menu createOutlineContextMenu() { + // MenuManager for the tree's context menu + final MenuManager outlineMenu = new MenuManager(); + + List actions = getOutlineActions(); + // Add all the actions to the context menu + for (Iterator iter = actions.iterator(); iter.hasNext();) { + IAction action = (IAction) iter.next(); + if (action instanceof IMenuCreator) + outlineMenu.add(new ActionContributionItem(action) { + public boolean isDynamic() { + return true; + } + }); + else + outlineMenu.add(action); + // Add separators after new and delete + if (action instanceof NewAction || action instanceof DeleteAction) { + outlineMenu.add(new Separator()); + } + } + + outlineMenu.addMenuListener(new IMenuListener() { + public void menuAboutToShow(IMenuManager manager) { + outlineMenu.update(true); + } + }); + + outlineMenu.createContextMenu(tree); + return outlineMenu.getMenu(); + } + + /** + * Uses a ToolBarManager to create the ToolBar in the outline part of the dialog. The Actions + * used in the ToolBarManager are those that are created in {@link #createOutlineActions()}. + * + * @param parent + * The Composite to which the ToolBar is to be added + * @return The newly created ToolBar + */ + protected Control createOutlineToolBar(Composite parent) { + // A customized composite for the toolbar + final Composite composite = new Composite(parent, SWT.NONE) { + public Rectangle getClientArea() { + Rectangle area = super.getClientArea(); + area.x += 2; + area.y += 2; + area.height -= 2; + area.width -= 4; + return area; + } + + public Point computeSize(int wHint, int hHint, boolean changed) { + Point size = super.computeSize(wHint, hHint, changed); + size.x += 4; + size.y += 2; + return size; + } + }; + composite.setFont(parent.getFont()); + composite.setLayout(new FillLayout()); + + // A paint listener that draws an etched border around the toolbar + composite.addPaintListener(new PaintListener() { + public void paintControl(PaintEvent e) { + Rectangle area = composite.getBounds(); + GC gc = e.gc; + gc.setLineStyle(SWT.LINE_SOLID); + gc.setForeground(ColorConstants.buttonDarker); + gc.drawLine(area.x, area.y, area.x + area.width - 2, area.y); + gc.drawLine(area.x, area.y, area.x, area.y + area.height - 1); + gc.drawLine(area.x + area.width - 2, area.y, area.x + + area.width - 2, area.y + area.height - 1); + gc.setForeground(ColorConstants.buttonLightest); + gc.drawLine(area.x + 1, area.y + 1, area.x + area.width - 3, + area.y + 1); + gc.drawLine(area.x + area.width - 1, area.y + 1, area.x + + area.width - 1, area.y + area.height - 1); + gc.drawLine(area.x + 1, area.y + 1, area.x + 1, area.y + + area.height - 1); + } + }); + + // Create the ToolBarManager and add all the actions to it + ToolBarManager tbMgr = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL); + List actions = getOutlineActions(); + for (int i = 0; i < actions.size(); i++) { + tbMgr.add(new ToolbarDropdownContributionItem(((IAction) actions + .get(i)))); + } + tbMgr.createControl(composite); + tbMgr.getControl().setFont(composite.getFont()); + + // By default, the ToolBarManager does not set text on ToolItems. Since, + // we want to display the text, we will have to do it manually. + ToolItem[] items = tbMgr.getControl().getItems(); + for (int i = 0; i < items.length; i++) { + ToolItem item = items[i]; + item.setText(((IAction) actions.get(i)).getText()); + } + + return tbMgr.getControl(); + } + + /** + * Creates the TreeViewer that is the outline of the model. + * + * @param composite + * The Composite to which the ToolBar is to be added + * @return The newly created TreeViewer + */ + protected TreeViewer createOutlineTreeViewer(Composite composite) { + Tree treeForViewer = new Tree(composite, SWT.BORDER); + treeForViewer.setFont(composite.getFont()); + GridData data = new GridData(GridData.FILL_VERTICAL + | GridData.HORIZONTAL_ALIGN_FILL); + data.widthHint = 185; + // Make the tree this tall even when there is nothing in it. This will + // keep the + // dialog from shrinking to an unusually small size. + data.heightHint = 200; + treeForViewer.setLayoutData(data); + TreeViewer viewer = new TreeViewer(treeForViewer) { + protected void preservingSelection(Runnable updateCode) { + if ((getTree().getStyle() & SWT.SINGLE) != 0) + updateCode.run(); + else + super.preservingSelection(updateCode); + } + }; + viewer.setContentProvider(new PaletteTreeProvider(viewer)); + treeViewerLabelProvider = new PaletteLabelProvider(viewer); + viewer.setLabelProvider(treeViewerLabelProvider); + viewer.setInput(getPaletteRoot()); + viewer.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + handleOutlineSelectionChanged(); + } + }); + + return viewer; + } + + /** + * Creates the part of the dialog where the properties of the element selected in the outline + * will be displayed. + * + *

+ * The properties panel contains the following: + *

    + *
  • Title ({@link #createPropertiesPanelTitle(Composite)})
  • + *
+ * The rest of the panel is constructed in this method. + *

+ * + * @param container + * The Composite to which this part is to be added + * @return The properties panel + */ + protected Control createPropertiesPanel(Composite container) { + Composite composite = new Composite(container, SWT.NONE); + composite.setFont(container.getFont()); + GridLayout layout = new GridLayout(1, false); + layout.horizontalSpacing = 0; + layout.marginWidth = 0; + layout.marginHeight = 0; + layout.verticalSpacing = 0; + composite.setLayout(layout); + + titleSwitcher = createPropertiesPanelTitle(composite); + + propertiesPanelContainer = new PageBook(composite, SWT.NONE); + propertiesPanelContainer.setFont(composite.getFont()); + GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL + | GridData.FILL_VERTICAL); + data.horizontalSpan = 2; + propertiesPanelContainer.setLayoutData(data); + propertiesPanelContainer.addListener(SWT.Resize, new Listener() { + public void handleEvent(Event event) { + if (activePage != null) { + propertiesPanelContainer.layout(); + } + } + }); + + return composite; + } + + /** + * Creates the title for the properties panel. It is a PageBook that can switch between showing + * the regular title (the selected entry's label and icon) and an error message if an error has + * occured. + * + * @param parent + * The parent composite + * @return The newly created PageBook title + */ + protected PageBook createPropertiesPanelTitle(Composite parent) { + GridLayout layout; + PageBook book = new PageBook(parent, SWT.NONE); + book.setFont(parent.getFont()); + book.setLayoutData(new GridData(GridData.FILL_HORIZONTAL + | GridData.VERTICAL_ALIGN_FILL)); + + titlePage = new Composite(book, SWT.NONE); + titlePage.setFont(book.getFont()); + layout = new GridLayout(2, false); + layout.horizontalSpacing = 0; + layout.marginWidth = 0; + layout.marginHeight = 0; + layout.verticalSpacing = 0; + titlePage.setLayout(layout); + title = createSectionTitle(titlePage, + PaletteMessages.NO_SELECTION_TITLE); + + errorPage = new Composite(book, SWT.NONE); + errorPage.setFont(book.getFont()); + layout = new GridLayout(1, false); + layout.horizontalSpacing = 0; + layout.marginWidth = 0; + layout.marginHeight = 0; + layout.verticalSpacing = 0; + errorPage.setLayout(layout); + Composite intermediary = new Composite(errorPage, SWT.NONE) { + public Point computeSize(int wHint, int hHint, boolean changed) { + Rectangle bounds = title.getBounds(); + return new Point(bounds.width, bounds.height); + } + }; + intermediary.setLayoutData(new GridData(GridData.FILL_HORIZONTAL + | GridData.VERTICAL_ALIGN_FILL)); + StackLayout stackLayout = new StackLayout(); + intermediary.setLayout(stackLayout); + errorTitle = new MultiLineLabel(intermediary); + stackLayout.topControl = errorTitle; + errorTitle.setImage(JFaceResources.getImage(DLG_IMG_MESSAGE_ERROR)); + errorTitle.setFont(errorPage.getFont()); + Label separator = new Label(errorPage, SWT.SEPARATOR | SWT.HORIZONTAL); + separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + book.showPage(titlePage); + return book; + } + + /** + * A convenient method to create CLabel titles (like the ones used in the Preferences dialog in + * the Eclipse workbench) throughout the dialog. + * + * @param composite + * The composite in which the title is to be created (it must have a GridLayout with + * two columns). + * @param text + * The title to be displayed + * @return The newly created CLabel for convenience + */ + protected CLabel createSectionTitle(Composite composite, String text) { + CLabel cTitle = new CLabel(composite, SWT.LEFT); + Color background = JFaceColors.getBannerBackground(composite + .getDisplay()); + Color foreground = JFaceColors.getBannerForeground(composite + .getDisplay()); + JFaceColors.setColors(cTitle, foreground, background); + cTitle.setFont(JFaceResources.getBannerFont()); + cTitle.setText(text); + cTitle.setLayoutData(new GridData(GridData.FILL_HORIZONTAL + | GridData.VERTICAL_ALIGN_FILL)); + + if (titleImage == null) { + titleImage = new Image(composite.getDisplay(), ImageDescriptor + .createFromFile(Internal.class, + "icons/customizer_dialog_title.gif") //$NON-NLS-1$ + .getImageData()); + composite.addDisposeListener(new DisposeListener() { + public void widgetDisposed(DisposeEvent e) { + titleImage.dispose(); + titleImage = null; + } + }); + } + + Label imageLabel = new Label(composite, SWT.LEFT); + imageLabel.setBackground(background); + imageLabel.setImage(titleImage); + imageLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL + | GridData.VERTICAL_ALIGN_FILL)); + + Label separator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL); + GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + data.horizontalSpan = 2; + separator.setLayoutData(data); + + return cTitle; + } + + /** + * Returns the Button with the given id; or null if none was found. + * + * @see org.eclipse.jface.dialogs.Dialog#getButton(int) + */ + protected Button getButton(int id) { + Button button = null; + Widget widget = getWidget(id); + if (widget instanceof Button) { + button = (Button) widget; + } + + return button; + } + + /** + * @return The customizer that is responsible for handling the various tasks and updating the + * model. + */ + protected PaletteCustomizer getCustomizer() { + return customizer; + } + + /** + * Returns the EntryPage for the given PaletteEntry. The + * EntryPage is retrieved from the customizer. If the given entry is + * null, null will be returned. If the customizer returns + * null for the valid entry, a default page will be created and returned. + * + * @param entry + * The PaletteEntry whose properties need to be displayed + * @return The EntryPage with the properties of the given PaletteEntry + */ + protected EntryPage getEntryPage(PaletteEntry entry) { + if (entry == null) { + return null; + } + + if (entriesToPages.containsKey(entry)) { + return (EntryPage) entriesToPages.get(entry); + } + + EntryPage page = getCustomizer().getPropertiesPage(entry); + if (page == null) { + page = new DefaultEntryPage(); + } + page.createControl(propertiesPanelContainer, entry); + page.setPageContainer(this); + entriesToPages.put(entry, page); + + return page; + } + + /** + * Provides access to the actions that are used to manipulate the model. The actions will be + * created, if they haven't been yet. + * + * @return the list of PaletteCustomizationActions + * @see #createOutlineActions() + */ + protected final List getOutlineActions() { + if (actions == null) { + actions = createOutlineActions(); + } + return actions; + } + + /** + * Provides sub-classes with access to the PaletteRoot + * + * @return the palette root + */ + protected PaletteRoot getPaletteRoot() { + return root; + } + + /** + * @return The PaletteEntry that is currently selected in the Outline Tree; null if + * none is selected + */ + protected PaletteEntry getSelectedPaletteEntry() { + TreeItem item = getSelectedTreeItem(); + if (item != null) { + return (PaletteEntry) item.getData(); + } + return null; + + } + + /** + * @return The TreeItem that is currently selected in the Outline Tree; null if + * none is selected + */ + protected TreeItem getSelectedTreeItem() { + TreeItem[] items = tree.getSelection(); + if (items.length > 0) { + return items[0]; + } + return null; + } + + /** + * The Widgets that were created with a unique ID and added to this class' internal + * map can be retrieved through this method. + * + * @param id + * The unique ID of the Widget that you wish to retrieve + * @return The Widget, if one with the given id exists; null otherwise + */ + protected Widget getWidget(int id) { + Widget widget = (Widget) widgets.get(new Integer(id)); + if (widget == null) { + widget = super.getButton(id); + } + + return widget; + } + + /** + * This method is invoked when the Apply button is pressed + *

+ * IMPORTANT: It is recommended that you not override this method. Closing the dialog with the + * 'X' at the top right of the window, or by hitting 'Esc' or any other way, corresponds to a + * "Cancel." That will, however, not result in this method being invoked. To handle such cases, + * saving or rejecting the changes is handled in {@link #close()}. Override {@link #save()} and + * {@link #revertToSaved()} to add to what needs to be done when saving or cancelling. + *

+ */ + protected final void handleApplyPressed() { + save(); + } + + /** + * This method is called when the "Delete" action is run (either through the context menu or the + * toolbar). It deletes the selected palette entry. + */ + protected void handleDelete() { + PaletteEntry entry = getSelectedPaletteEntry(); + if (entry != null) { + getCustomizer().performDelete(entry); + } + handleOutlineSelectionChanged(); + } + + /** + * This method is called when the "Move Down" action is run (either through the context menu or + * the toolbar). It moves the selected palette entry down. + */ + protected void handleMoveDown() { + PaletteEntry entry = getSelectedPaletteEntry(); + if (entry != null) { + getCustomizer().performMoveDown(entry); + treeviewer.setSelection(new StructuredSelection(entry), true); + } + updateActions(); + } + + /** + * This method is called when the "Move Up" action is run (either through the context menu or + * the toolbar). It moves the selected entry up. + */ + protected void handleMoveUp() { + PaletteEntry entry = getSelectedPaletteEntry(); + if (entry != null) { + getCustomizer().performMoveUp(entry); + treeviewer.setSelection(new StructuredSelection(entry), true); + } + updateActions(); + } + + /** + * This is the method that is called everytime the selection in the outline (treeviewer) + * changes. + */ + protected void handleOutlineSelectionChanged() { + PaletteEntry entry = getSelectedPaletteEntry(); + + if (activeEntry == entry) { + return; + } + + if (errorMessage != null) { + MessageDialog dialog = new MessageDialog(getShell(), + PaletteMessages.ERROR, + null, + PaletteMessages.ABORT_PAGE_FLIPPING_MESSAGE + + "\n" + errorMessage, //$NON-NLS-1$ + MessageDialog.ERROR, + new String[] { IDialogConstants.OK_LABEL }, 0); + dialog.open(); + treeviewer.addPostSelectionChangedListener(pageFlippingPreventer); + } else { + setActiveEntry(entry); + } + updateActions(); + } + + /** + * This method is invoked when the changes made since the last save need to be cancelled. + */ + protected void revertToSaved() { + getCustomizer().revertToSaved(); + } + + /** + * This method is invoked when the changes made since the last save need to be saved. + */ + protected void save() { + if (activePage != null) { + activePage.apply(); + } + getCustomizer().save(); + } + + /** + * This methods sets the active entry. Based on the selection, this method will appropriately + * enable or disable the ToolBar items, will change the CLabel heading of the propreties panel, + * and will show the properties of the selected item in the properties panel. + * + * @param entry + * The new active entry, i.e., the new selected entry (it can be null) + */ + protected void setActiveEntry(PaletteEntry entry) { + if (activeEntry != null) { + activeEntry.removePropertyChangeListener(titleUpdater); + } + + activeEntry = entry; + + if (entry != null) { + title.setText(entry.getLabel()); + Image img = treeViewerLabelProvider.getImage(entry); + if (img == null) { + TreeItem treeItem = getSelectedTreeItem(); + if (treeItem != null) { + img = treeItem.getImage(); + } + } + title.setImage(img); + entry.addPropertyChangeListener(titleUpdater); + EntryPage panel = getEntryPage(entry); + setActiveEntryPage(panel); + } else { + title.setImage(null); + title.setText(PaletteMessages.NO_SELECTION_TITLE); + // Lazy creation + if (noSelectionPage == null) { + noSelectionPage = new EntryPage() { + private Text text; + + public void apply() { + } + + public void createControl(Composite parent, + PaletteEntry entry) { + text = new Text(parent, SWT.READ_ONLY); + text.setFont(parent.getFont()); + text.setText(PaletteMessages.NO_SELECTION_MADE); + } + + public Control getControl() { + return text; + } + + public void setPageContainer( + EntryPageContainer pageContainer) { + } + }; + noSelectionPage.createControl(propertiesPanelContainer, null); + } + setActiveEntryPage(noSelectionPage); + } + } + + /** + * Sets the given EntryPage as the top page in the PageBook that shows the properties of the + * item selected in the Outline. If the given EntryPage is null, nothing will be shown. + * + * @param page + * The EntryPage to be shown + */ + protected void setActiveEntryPage(EntryPage page) { + // Have the currently displayed page save its changes + if (activePage != null) { + activePage.apply(); + } + + if (page == null) { + // No page available to display, so hide the panel container + propertiesPanelContainer.setVisible(false); + } else { + // Show the page and grow the shell, if necessary, so that the page + // is + // completely visible + Point oldSize = getShell().getSize(); + propertiesPanelContainer.showPage(page.getControl()); + + /* + * Fix for bug #34748 There's no need to resize the Shell if initializeBounds() hasn't + * been called yet. It will automatically resize the Shell so that everything fits in + * the Dialog. After that, we can resize the Shell whenever there's an entry page that + * cannot fit in the dialog. + */ + if (!isSetup) { + Point newSize = getShell().computeSize(SWT.DEFAULT, + SWT.DEFAULT, true); + int x = newSize.x - oldSize.x; + x = (x < 0) ? 0 : x; + int y = newSize.y - oldSize.y; + y = (y < 0) ? 0 : y; + if (x > 0 || y > 0) { + getShell().setSize(oldSize.x + x, oldSize.y + y); + } + } + + // Show the property panel container if it was hidden + if (!propertiesPanelContainer.isVisible()) { + propertiesPanelContainer.setVisible(true); + } + } + + activePage = page; + } + + /** + * Sets the given PaletteEntry as the one to be selected when the dialog opens. It is discarded + * when the dialog is closed. + * + * @param entry + * The PaletteEntry that should be selected when the dialog is opened + */ + public void setDefaultSelection(PaletteEntry entry) { + initialSelection = entry; + } + + /** + * This method should be invoked by EntryPages when there is an error. It will show the given + * error in the title of the properties panel. OK and Apply buttons will be disabled. Selecting + * some other entry in the outline tree will not be allowed until the error is fixed. + * + * @see org.eclipse.gef.ui.palette.customize.EntryPageContainer#showProblem(String) + */ + public void showProblem(String error) { + Assert.isNotNull(error); + errorTitle.setText(error); + titleSwitcher.showPage(errorPage); + Button okBtn = getButton(IDialogConstants.OK_ID); + if (okBtn != null) { + okBtn.setEnabled(false); + } + Button applyBtn = getButton(APPLY_ID); + if (applyBtn != null) { + applyBtn.setEnabled(false); + } + + errorMessage = error; + } + + /** + * Updates the actions created in {@link #createOutlineActions()}, enabling or disabling them as + * necessary. + */ + protected void updateActions() { + List actions = getOutlineActions(); + for (Iterator iter = actions.iterator(); iter.hasNext();) { + PaletteCustomizationAction action = (PaletteCustomizationAction) iter + .next(); + action.update(); + } + } + + /* + * Delete Action + */ + private class DeleteAction extends PaletteCustomizationAction { + public DeleteAction() { + setEnabled(false); + setText(PaletteMessages.DELETE_LABEL); + ISharedImages sharedImages = PlatformUI.getWorkbench() + .getSharedImages(); + setImageDescriptor(sharedImages + .getImageDescriptor(ISharedImages.IMG_TOOL_DELETE)); + setDisabledImageDescriptor(sharedImages + .getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED)); + } + + public void run() { + handleDelete(); + } + + public void update() { + boolean enabled = false; + PaletteEntry entry = getSelectedPaletteEntry(); + if (entry != null) { + enabled = getCustomizer().canDelete(entry); + } + setEnabled(enabled); + } + } + + /* + * Move Down Action + */ + private class MoveDownAction extends PaletteCustomizationAction { + public MoveDownAction() { + setEnabled(false); + setText(PaletteMessages.MOVE_DOWN_LABEL); + setImageDescriptor(ImageDescriptor.createFromFile(Internal.class, + "icons/next_nav.gif"));//$NON-NLS-1$ + setDisabledImageDescriptor(ImageDescriptor.createFromFile( + Internal.class, "icons/move_down_disabled.gif"));//$NON-NLS-1$ + } + + public void run() { + handleMoveDown(); + } + + public void update() { + boolean enabled = false; + PaletteEntry entry = getSelectedPaletteEntry(); + if (entry != null) { + enabled = getCustomizer().canMoveDown(entry); + } + setEnabled(enabled); + } + } + + /* + * Move Up Action + */ + private class MoveUpAction extends PaletteCustomizationAction { + public MoveUpAction() { + setEnabled(false); + setText(PaletteMessages.MOVE_UP_LABEL); + setImageDescriptor(ImageDescriptor.createFromFile(Internal.class, + "icons/prev_nav.gif"));//$NON-NLS-1$ + setDisabledImageDescriptor(ImageDescriptor.createFromFile( + Internal.class, "icons/move_up_disabled.gif")); //$NON-NLS-1$ + } + + public void run() { + handleMoveUp(); + } + + public void update() { + boolean enabled = false; + PaletteEntry entry = getSelectedPaletteEntry(); + if (entry != null) { + enabled = getCustomizer().canMoveUp(entry); + } + setEnabled(enabled); + } + } + + /* + * New Action + */ + private class NewAction extends PaletteCustomizationAction implements + IMenuCreator { + private List factories; + private MenuManager menuMgr; + + public NewAction() { + factories = wrap(getCustomizer().getNewEntryFactories()); + if (factories.isEmpty()) { + setEnabled(false); + } else { + setMenuCreator(this); + } + + setText(PaletteMessages.NEW_LABEL); + setImageDescriptor(ImageDescriptor.createFromFile(Internal.class, + "icons/add.gif")); //$NON-NLS-1$ + setDisabledImageDescriptor(ImageDescriptor.createFromFile( + Internal.class, "icons/add-disabled.gif")); //$NON-NLS-1$ + } + + private void addActionToMenu(Menu parent, IAction action) { + ActionContributionItem item = new ActionContributionItem(action); + item.fill(parent, -1); + } + + public void dispose() { + if (menuMgr != null) { + menuMgr.dispose(); + menuMgr = null; + } + } + + public Menu getMenu(Control parent) { + // Create the menu manager and add all the NewActions to it + if (menuMgr == null) { + // Lazily create the manager + menuMgr = new MenuManager(); + menuMgr.createContextMenu(parent); + } + + updateMenuManager(menuMgr); + return menuMgr.getMenu(); + } + + public Menu getMenu(Menu parent) { + Menu menu = new Menu(parent); + for (Iterator iter = factories.iterator(); iter.hasNext();) { + FactoryWrapperAction action = (FactoryWrapperAction) iter + .next(); + if (action.isEnabled()) { + addActionToMenu(menu, action); + } + } + + return menu; + } + + public void run() { + } + + public void update() { + boolean enabled = false; + PaletteEntry entry = getSelectedPaletteEntry(); + if (entry == null) { + entry = getPaletteRoot(); + } + // Enable or disable the FactoryWrapperActions + for (Iterator iter = factories.iterator(); iter.hasNext();) { + FactoryWrapperAction action = (FactoryWrapperAction) iter + .next(); + action.setEnabled(action.canCreate(entry)); + enabled = enabled || action.isEnabled(); + } + + // Enable this action IFF at least one of the new actions is enabled + setEnabled(enabled); + } + + protected void updateMenuManager(MenuManager manager) { + manager.removeAll(); + for (Iterator iter = factories.iterator(); iter.hasNext();) { + FactoryWrapperAction action = (FactoryWrapperAction) iter + .next(); + if (action.isEnabled()) { + manager.add(action); + } + } + } + + private List wrap(List list) { + List newList = new ArrayList(); + if (list != null) { + for (Iterator iter = list.iterator(); iter.hasNext();) { + PaletteEntryFactory element = (PaletteEntryFactory) iter + .next(); + newList.add(new FactoryWrapperAction(element)); + } + } + + return newList; + } + } + + /* + * FactoryWrapperAction class + */ + private class FactoryWrapperAction extends Action { + private PaletteEntryFactory factory; + + public FactoryWrapperAction(PaletteEntryFactory factory) { + this.factory = factory; + setText(factory.getLabel()); + setImageDescriptor(factory.getImageDescriptor()); + setHoverImageDescriptor(factory.getImageDescriptor()); + } + + public boolean canCreate(PaletteEntry entry) { + return factory.canCreate(entry); + } + + public void run() { + PaletteEntry selected = getSelectedPaletteEntry(); + if (selected == null) + selected = getPaletteRoot(); + PaletteEntry newEntry = factory + .createNewEntry(getShell(), selected); + treeviewer.setSelection(new StructuredSelection(newEntry), true); + updateActions(); + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteDrawerFactory.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteDrawerFactory.java new file mode 100644 index 0000000..54f43d0 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteDrawerFactory.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.customize; + +import org.eclipse.swt.widgets.Shell; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteDrawer; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteMessages; + + +/** + * Factory to create {@link org.eclipse.gef.palette.PaletteDrawer categories} + * + * @author Pratik Shah + */ +public class PaletteDrawerFactory extends PaletteContainerFactory { + + /** + * Constructor + */ + public PaletteDrawerFactory() { + setLabel(PaletteMessages.MODEL_TYPE_DRAWER); + } + + /** + * @see org.eclipse.gef.ui.palette.customize.PaletteEntryFactory#createNewEntry(Shell) + */ + protected PaletteEntry createNewEntry(Shell shell) { + PaletteEntry entry = new PaletteDrawer(PaletteMessages.NEW_DRAWER_LABEL); + entry.setUserModificationPermission(PaletteEntry.PERMISSION_FULL_MODIFICATION); + return entry; + } + + /** + * @see org.eclipse.gef.ui.palette.customize.PaletteEntryFactory#determineTypeForNewEntry(org.eclipse.gef.palette.PaletteEntry) + */ + protected Object determineTypeForNewEntry(PaletteEntry selected) { + return PaletteDrawer.PALETTE_TYPE_DRAWER; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteEntryFactory.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteEntryFactory.java new file mode 100644 index 0000000..dc14cf7 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteEntryFactory.java @@ -0,0 +1,199 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.customize; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.widgets.Shell; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteContainer; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteRoot; + + +/** + * A PaletteEntryFactory creates certain type of {@link org.eclipse.gef.palette.PaletteEntry + * PaletteEntries}. + * + *

+ * This class only creates {@link org.eclipse.gef.palette.PaletteEntry PaletteEntries} in + * {@link org.eclipse.gef.palette.PaletteContainer PaletteContainers} and not directly in the + * {@link org.eclipse.gef.palette.PaletteRoot root}. It is recommended that sub-classes not do that + * either. + *

+ * + *

+ * To keep palette customization consistent across different types of editors, it is recommended + * that a new entry be created after the currently selected entry. If the new entry needs to be + * created inside the currently selected entry (i.e., if the currently selected entry is a + * PaletteContainer), it should be added as the last child. Look at + * {@link #determineContainerForNewEntry(PaletteEntry)} and + * {@link #determineIndexForNewEntry(PaletteContainer, PaletteEntry)} in this class and + * {@link org.eclipse.gef.ui.palette.customize.PaletteContainerFactory} to see what the general + * guidelines are for creating containers and leaf entries. + *

+ * + * @author Pratik Shah + * @see org.eclipse.gef.ui.palette.PaletteCustomizer + * @see org.eclipse.gef.ui.palette.customize.PaletteCustomizerDialog + */ +public abstract class PaletteEntryFactory { + + private String label; + private ImageDescriptor imageDescriptor; + + /** + * This method is called when a new palette entry of the type supported by this + * PaletteEntryFactory is to be created. + * + * @param shell + * The Shell of the PaletteCustomizerDialog + * @param selected + * The PaletteEntry that was selected in the outline when this action + * was launched. Will never be null . + * @return PaletteEntry The newly created PaletteEntry + */ + public PaletteEntry createNewEntry(Shell shell, PaletteEntry selected) { + PaletteContainer parent = determineContainerForNewEntry(selected); + int index = determineIndexForNewEntry(parent, selected); + PaletteEntry entry = createNewEntry(shell); + parent.add(index, entry); + return entry; + } + + /** + * Create the PaletteEntry + * + * @param shell + * The Shell of the PaletteCustomizerDialog; it can be used + * to create another warning or information dialog. + * @return The newly created entry + */ + protected abstract PaletteEntry createNewEntry(Shell shell); + + /** + * This method is called by the PaletteCustomizerDialog to determine whether to + * enable or disable this action on the toolbar and the context menu. + *

+ * This default implementation allows the creation of a new entry only in + * PaletteContainers with the following user permission: + * PERMISSION_FULL_MODIFICATION + * + * @param selected + * The selected PaletteEntry (Will never be null) + * @return true if, given the current selection, this + * PaletteEntryFactory can create a new PaletteEntry + */ + public boolean canCreate(PaletteEntry selected) { + if (selected instanceof PaletteRoot) + return false; + + PaletteContainer parent; + if (selected instanceof PaletteContainer) + parent = (PaletteContainer) selected; + else + parent = selected.getParent(); + + return parent.getUserModificationPermission() == PaletteEntry.PERMISSION_FULL_MODIFICATION + && parent.acceptsType(determineTypeForNewEntry(selected)); + } + + /** + * Given the current selection, this method determines the parent for the new entry to be + * created. + * + *

+ * Sub-classes may override this method. + *

+ * + * @param selected + * The selected entry + * @return The parent of the new entry to be created + */ + protected PaletteContainer determineContainerForNewEntry( + PaletteEntry selected) { + if (selected instanceof PaletteContainer) + return (PaletteContainer) selected; + return selected.getParent(); + } + + /** + * Given the current selection, this method determines the type of the new entry to be created. + * + *

+ * Sub-classes may override this method. + *

+ * + * @param selected + * The selected entry + * @return The type of the new entry to be created + */ + protected Object determineTypeForNewEntry(PaletteEntry selected) { + return PaletteEntry.PALETTE_TYPE_UNKNOWN; + } + + /** + * Calculates the index at which the new entry is to be created, given the current selection. + * + *

+ * Sub-classes may override this method. + *

+ * + * @param c + * The parent container + * @param selected + * The selected entry + * @return the index at which the new entry should be added in the given container (-1 indicates + * add at the end) + */ + protected int determineIndexForNewEntry(PaletteContainer c, + PaletteEntry selected) { + return c.getChildren().indexOf(selected) + 1; + } + + /** + * @return ImageDescriptor used to create the image to represent this factory + */ + public ImageDescriptor getImageDescriptor() { + return imageDescriptor; + } + + /** + * @return This factory's name + */ + public String getLabel() { + return label; + } + + /** + * Sets the ImageDescriptor used to create the image to represent this factory + * + * @param imgDesc + * The new ImageDescriptor + */ + public void setImageDescriptor(ImageDescriptor imgDesc) { + imageDescriptor = imgDesc; + } + + /** + * Sets this factory's name. It will be used to list this factory in the toolbar, context menu, + * etc. + * + * @param newLabel + * The new name for this factory + */ + public void setLabel(String newLabel) { + label = newLabel; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteGroupFactory.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteGroupFactory.java new file mode 100644 index 0000000..39158ea --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteGroupFactory.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.customize; + +import org.eclipse.swt.widgets.Shell; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteGroup; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteMessages; + + +/** + * Factory to create {@link org.eclipse.gef.palette.PaletteGroup groups} + * + * @author Pratik Shah + */ +public class PaletteGroupFactory extends PaletteContainerFactory { + + /** + * Constructor + */ + public PaletteGroupFactory() { + setLabel(PaletteMessages.MODEL_TYPE_GROUP); + } + + /** + * @see org.eclipse.gef.ui.palette.customize.PaletteEntryFactory#createNewEntry(Shell) + */ + protected PaletteEntry createNewEntry(Shell shell) { + PaletteGroup group = new PaletteGroup(PaletteMessages.NEW_GROUP_LABEL); + group.setUserModificationPermission(PaletteEntry.PERMISSION_FULL_MODIFICATION); + return group; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteLabelProvider.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteLabelProvider.java new file mode 100644 index 0000000..311ebf6 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteLabelProvider.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.customize; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.gef.internal.InternalImages; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.IColorProvider; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteContainer; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteSeparator; + + +/** + * This class is the ILabelProvider for the {@link org.eclipse.jface.viewers.TreeViewer} used in + * {@link org.eclipse.gef.ui.palette.customize.PaletteCustomizerDialog}. + * + * @author Pratik Shah + */ +class PaletteLabelProvider implements ILabelProvider, IColorProvider { + + private Map imageCache = new HashMap(); + + /** + * Constructor + * + * @param viewer + * The TreeViewer for which this instance is a LabelProvider + */ + public PaletteLabelProvider(TreeViewer viewer) { + } + + /** + * @see org.eclipse.jface.viewers.IColorProvider#getBackground(Object) + */ + public Color getBackground(Object element) { + return null; + } + + private Image getCachedImage(ImageDescriptor descriptor) { + Image image = (Image) imageCache.get(descriptor); + if (image == null) { + image = descriptor.createImage(); + imageCache.put(descriptor, image); + } + return image; + } + + /** + * @see org.eclipse.jface.viewers.IColorProvider#getForeground(Object) + */ + public Color getForeground(Object element) { + PaletteEntry entry = (PaletteEntry) element; + if (!entry.isVisible() || !entry.getParent().isVisible()) { + return ColorConstants.gray; + } + return null; + } + + /** + * @see org.eclipse.jface.viewers.ILabelProvider#getImage(Object) + */ + public Image getImage(Object element) { + PaletteEntry entry = (PaletteEntry) element; + ImageDescriptor descriptor = entry.getSmallIcon(); + if (descriptor == null) { + if (entry instanceof PaletteContainer) { + descriptor = InternalImages.DESC_FOLDER_OPEN; + } else if (entry instanceof PaletteSeparator) { + descriptor = InternalImages.DESC_SEPARATOR; + } else { + return null; + } + } + return getCachedImage(descriptor); + } + + /** + * @see org.eclipse.jface.viewers.ILabelProvider#getText(Object) + */ + public String getText(Object element) { + return ((PaletteEntry) element).getLabel(); + } + + /** + * Not implemented + * + * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(ILabelProviderListener) + */ + public void addListener(ILabelProviderListener listener) { + } + + /** + * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose() + */ + public void dispose() { + Iterator images = imageCache.values().iterator(); + while (images.hasNext()) + ((Image) images.next()).dispose(); + imageCache = null; + } + + /** + * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(Object, String) + */ + public boolean isLabelProperty(Object element, String property) { + return false; + } + + /** + * Not implemented + * + * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(ILabelProviderListener) + */ + public void removeListener(ILabelProviderListener listener) { + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteSeparatorFactory.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteSeparatorFactory.java new file mode 100644 index 0000000..7e312c9 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteSeparatorFactory.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.customize; + +import org.eclipse.swt.widgets.Shell; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteSeparator; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteMessages; + + +/** + * Factory to create {@link org.eclipse.gef.palette.PaletteSeparator PaletteSeparators}. + * + * @author Pratik Shah + */ +public class PaletteSeparatorFactory extends PaletteEntryFactory { + + /** + * Constructor + */ + public PaletteSeparatorFactory() { + setLabel(PaletteMessages.MODEL_TYPE_SEPARATOR); + } + + /** + * @see org.eclipse.gef.ui.palette.customize.PaletteEntryFactory#createNewEntry(Shell) + */ + public PaletteEntry createNewEntry(Shell shell) { + PaletteSeparator separator = new PaletteSeparator(); + return separator; + } + + /** + * @see org.eclipse.gef.ui.palette.customize.PaletteEntryFactory#determineTypeForNewEntry(org.eclipse.gef.palette.PaletteEntry) + */ + protected Object determineTypeForNewEntry(PaletteEntry selected) { + return PaletteSeparator.PALETTE_TYPE_SEPARATOR; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteSettingsDialog.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteSettingsDialog.java new file mode 100644 index 0000000..b2f8f28 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteSettingsDialog.java @@ -0,0 +1,837 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.customize; + +import java.util.HashMap; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.resource.StringConverter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +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; +import org.eclipse.swt.widgets.FontDialog; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Widget; +import org.eclipse.ui.part.PageBook; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteMessages; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewerPreferences; + + +/** + * @author Pratik Shah + */ +public class PaletteSettingsDialog extends Dialog { + + private PaletteViewerPreferences prefs; + private Label fontName; + private PageBook book; + private Control columnsPanel, detailsPanel, iconsPanel, listPanel; + private HashMap widgets = new HashMap(); + + /** + * A HashMap to cache the various settings displayed in this dialog + */ + protected HashMap settings = new HashMap(); + + /** + * HashMap keys used for caching the various settings displayed in this dialog. + */ + protected static final String CACHE_LAYOUT = "layout setting", //$NON-NLS-1$ + CACHE_COLUMNS_ICON_SIZE = "columns - use large icons", //$NON-NLS-1$ + CACHE_LIST_ICON_SIZE = "list - use large icons", //$NON-NLS-1$ + CACHE_ICONS_ICON_SIZE = "icons only - use large icons", //$NON-NLS-1$ + CACHE_DETAILS_ICON_SIZE = "details - use large icons", //$NON-NLS-1$ + CACHE_FONT = "font", //$NON-NLS-1$ + CACHE_COLLAPSE = "auto-collapse setting"; //$NON-NLS-1$ + + /** + * The unique IDs for the various widgets. These IDs can be used to retrieve these widgets from + * the internal map (using {@link #getWidget(int)}), or to identify widgets in + * {@link #buttonPressed(int)}. + */ + protected static final int LAYOUT_COLUMNS_VIEW_ID = IDialogConstants.CLIENT_ID + 1, + LAYOUT_LIST_VIEW_ID = IDialogConstants.CLIENT_ID + 2, + LAYOUT_ICONS_VIEW_ID = IDialogConstants.CLIENT_ID + 3, + LAYOUT_COLUMNS_ICON_SIZE_ID = IDialogConstants.CLIENT_ID + 4, + LAYOUT_LIST_ICON_SIZE_ID = IDialogConstants.CLIENT_ID + 5, + LAYOUT_ICONS_ICON_SIZE_ID = IDialogConstants.CLIENT_ID + 6, + LAYOUT_DETAILS_ICON_SIZE_ID = IDialogConstants.CLIENT_ID + 7, + COLLAPSE_NEVER_ID = IDialogConstants.CLIENT_ID + 8, + COLLAPSE_ALWAYS_ID = IDialogConstants.CLIENT_ID + 9, + COLLAPSE_NEEDED_ID = IDialogConstants.CLIENT_ID + 10, + APPLY_ID = IDialogConstants.CLIENT_ID + 11, + LAYOUT_DETAILS_VIEW_ID = IDialogConstants.CLIENT_ID + 12, + FONT_CHANGE_ID = IDialogConstants.CLIENT_ID + 13, + DEFAULT_FONT_ID = IDialogConstants.CLIENT_ID + 14; + + /** + * Sub - classes that need to create their own unique IDs should do so by adding to this ID. + */ + protected static final int CLIENT_ID = 16; + + /** + * Constructor + * + * @param parentShell + * The parent shell, or null to create a top - level shell + * @param prefs + * The PaletteViewerPreferences object that can provide access to and allow + * modification of the palette's settings. It cannot be null. + */ + public PaletteSettingsDialog(Shell parentShell, + PaletteViewerPreferences prefs) { + super(parentShell); + this.prefs = prefs; + setShellStyle(getShellStyle() | SWT.RESIZE | SWT.MAX); + } + + /** + * This method will be invoked whenever any Button created using + * {@link #createButton(Composite, int, String, int, ImageDescriptor)} or + * {@link Dialog#createButton(Composite, int, String, boolean)} is selected. + * + * @see Dialog#buttonPressed(int) + */ + protected void buttonPressed(int buttonId) { + Button b = getButton(buttonId); + + if (FONT_CHANGE_ID == buttonId) { + handleChangeFontPressed(); + } else if (COLLAPSE_ALWAYS_ID == buttonId) { + handleAutoCollapseSettingChanged(PaletteViewerPreferences.COLLAPSE_ALWAYS); + } else if (COLLAPSE_NEVER_ID == buttonId) { + handleAutoCollapseSettingChanged(PaletteViewerPreferences.COLLAPSE_NEVER); + } else if (COLLAPSE_NEEDED_ID == buttonId) { + handleAutoCollapseSettingChanged(PaletteViewerPreferences.COLLAPSE_AS_NEEDED); + } else if (LAYOUT_COLUMNS_VIEW_ID == buttonId) { + handleLayoutSettingChanged(PaletteViewerPreferences.LAYOUT_COLUMNS); + } else if (LAYOUT_ICONS_VIEW_ID == buttonId) { + handleLayoutSettingChanged(PaletteViewerPreferences.LAYOUT_ICONS); + } else if (LAYOUT_LIST_VIEW_ID == buttonId) { + handleLayoutSettingChanged(PaletteViewerPreferences.LAYOUT_LIST); + } else if (LAYOUT_DETAILS_VIEW_ID == buttonId) { + handleLayoutSettingChanged(PaletteViewerPreferences.LAYOUT_DETAILS); + } else if (LAYOUT_DETAILS_ICON_SIZE_ID == buttonId && b != null) { + handleIconSizeChanged(b.getSelection()); + } else if (LAYOUT_COLUMNS_ICON_SIZE_ID == buttonId && b != null) { + handleIconSizeChanged(b.getSelection()); + } else if (LAYOUT_ICONS_ICON_SIZE_ID == buttonId && b != null) { + handleIconSizeChanged(b.getSelection()); + } else if (LAYOUT_LIST_ICON_SIZE_ID == buttonId && b != null) { + handleIconSizeChanged(b.getSelection()); + } else if (DEFAULT_FONT_ID == buttonId) { + handleDefaultFontRequested(); + } else { + super.buttonPressed(buttonId); + } + } + + /** + * This method saves the various settings in this dialog, so that they can be restored later on + * if "Cancel" is pressed. + * + * @see #restoreSettings() + */ + protected void cacheSettings() { + settings.put(CACHE_LAYOUT, new Integer(prefs.getLayoutSetting())); + settings.put(CACHE_COLLAPSE, + new Integer(prefs.getAutoCollapseSetting())); + settings.put(CACHE_FONT, prefs.getFontData()); + settings.put( + CACHE_DETAILS_ICON_SIZE, + new Boolean(prefs + .useLargeIcons(PaletteViewerPreferences.LAYOUT_DETAILS))); + settings.put( + CACHE_ICONS_ICON_SIZE, + new Boolean(prefs + .useLargeIcons(PaletteViewerPreferences.LAYOUT_ICONS))); + settings.put( + CACHE_COLUMNS_ICON_SIZE, + new Boolean(prefs + .useLargeIcons(PaletteViewerPreferences.LAYOUT_COLUMNS))); + settings.put( + CACHE_LIST_ICON_SIZE, + new Boolean(prefs + .useLargeIcons(PaletteViewerPreferences.LAYOUT_LIST))); + } + + /** + * @see org.eclipse.jface.window.Window#close() + */ + public boolean close() { + // Save or dump changes + // This needs to be done here and not in the handle methods because the + // user can + // also close the dialog with the 'X' in the top right of the window + // (which + // corresponds to a cancel). + if (getReturnCode() != OK) { + handleCancelPressed(); + } + + return super.close(); + } + + /** + * @see org.eclipse.jface.window.Window#configureShell(Shell) + */ + protected void configureShell(Shell newShell) { + newShell.setText(PaletteMessages.SETTINGS_DIALOG_TITLE); + super.configureShell(newShell); + } + + /** + * This method should not be used to create buttons for the button bar. Use + * {@link Dialog#createButton(Composite, int, String, boolean)} for that. This method can be + * used to create any other button in the dialog. The parent Composite must have a + * GridLayout. These buttons will be available through {@link #getButton(int)} and + * {@link #getWidget(int)}. Ensure that the various buttons created by this method are given + * unique IDs. Pass in a null image descriptor if you don't want the button to have an icon. + * This method will take care of disposing the images that it creates. + * {@link #buttonPressed(int)} will be called when any of the buttons created by this method are + * clicked (selected). + * + * @param parent + * The composite in which the button is to be created + * @param id + * The button's unique ID + * @param label + * The button's text + * @param stylebits + * The style bits for creating the button (eg., SWT.PUSH + * SWT.CHECK) + * @param descriptor + * The ImageDescriptor from which the image/icon for this button should be created + * @return The newly created button for convenience + */ + protected Button createButton(Composite parent, int id, String label, + int stylebits, ImageDescriptor descriptor) { + Button button = new Button(parent, stylebits); + button.setText(label); + button.setFont(parent.getFont()); + GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + button.setLayoutData(data); + + button.setData(new Integer(id)); + button.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + buttonPressed(((Integer) event.widget.getData()).intValue()); + } + }); + widgets.put(new Integer(id), button); + + if (descriptor != null) { + button.setImage(new Image(parent.getDisplay(), descriptor + .getImageData())); + button.addDisposeListener(new DisposeListener() { + public void widgetDisposed(DisposeEvent e) { + Image img = ((Button) e.getSource()).getImage(); + if (img != null && !img.isDisposed()) { + img.dispose(); + } + } + }); + } + + return button; + } + + /** + * Creates and initializes (i.e., loads the current value from the PaletteViewerPreferences) the + * part of the dialog where the options to close drawers will be displayed. + * + * @param container + * The parent composite + * @return The newly created Control which has the drawer collapse options + */ + protected Control createDrawerCollapseOptions(Composite container) { + Composite composite = new Composite(container, SWT.NONE); + composite.setFont(container.getFont()); + GridLayout layout = new GridLayout(1, false); + composite.setLayout(layout); + + Label label = new Label(composite, SWT.NONE); + label.setFont(composite.getFont()); + label.setText(PaletteMessages.COLLAPSE_OPTIONS_TITLE); + GridData data = new GridData(); + label.setLayoutData(data); + + Button b = createButton(composite, COLLAPSE_ALWAYS_ID, + PaletteMessages.COLLAPSE_ALWAYS_LABEL, SWT.RADIO, null); + ((GridData) b.getLayoutData()).horizontalIndent = 5; + + b = createButton(composite, COLLAPSE_NEEDED_ID, + PaletteMessages.COLLAPSE_AS_NEEDED_LABEL, SWT.RADIO, null); + ((GridData) b.getLayoutData()).horizontalIndent = 5; + + b = createButton(composite, COLLAPSE_NEVER_ID, + PaletteMessages.COLLAPSE_NEVER_LABEL, SWT.RADIO, null); + ((GridData) b.getLayoutData()).horizontalIndent = 5; + + // Load auto - collapse settings + b = null; + int collapse = prefs.getAutoCollapseSetting(); + switch (collapse) { + case PaletteViewerPreferences.COLLAPSE_ALWAYS: + b = getButton(COLLAPSE_ALWAYS_ID); + break; + case PaletteViewerPreferences.COLLAPSE_AS_NEEDED: + b = getButton(COLLAPSE_NEEDED_ID); + break; + case PaletteViewerPreferences.COLLAPSE_NEVER: + b = getButton(COLLAPSE_NEVER_ID); + } + if (b == null) { + return null; + } + b.setSelection(true); + + return composite; + } + + /** + * Creates and initializes (i.e. loads the current settings from PaletteViewerPreferences) the + * options for details layout. + * + * @param parent + * the parent composite + * @return the newly created Control + */ + protected Control createDetailsOptions(Composite parent) { + Control contents = createOptionsPage(parent, + PaletteMessages.SETTINGS_OPTIONS_DETAILS, + LAYOUT_DETAILS_ICON_SIZE_ID); + + if (getButton(LAYOUT_DETAILS_ICON_SIZE_ID) != null) { + getButton(LAYOUT_DETAILS_ICON_SIZE_ID).setSelection( + prefs.useLargeIcons(PaletteViewerPreferences.LAYOUT_DETAILS)); + } + return contents; + } + + /** + * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(Composite) + */ + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + GridLayout layout = (GridLayout) composite.getLayout(); + layout.horizontalSpacing = 0; + layout.numColumns = 2; + + Control child = createFontSettings(composite); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan = 2; + data.horizontalIndent = 5; + child.setLayoutData(data); + + Label label = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL); + data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + data.horizontalSpan = 2; + label.setLayoutData(data); + + child = createLayoutSettings(composite); + data = new GridData(GridData.HORIZONTAL_ALIGN_FILL + | GridData.FILL_VERTICAL); + data.horizontalSpan = 2; + data.horizontalIndent = 5; + child.setLayoutData(data); + + label = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL); + data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + data.horizontalSpan = 2; + label.setLayoutData(data); + + child = createDrawerCollapseOptions(composite); + if (child != null) { + data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + data.horizontalSpan = 2; + data.horizontalIndent = 5; + child.setLayoutData(data); + } + + label = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL); + data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + data.horizontalSpan = 2; + label.setLayoutData(data); + + cacheSettings(); + + return composite; + } + + /** + * Creates and initializes (i.e. loads the current settings from PaletteViewerPreferences) the + * options for columns layout. + * + * @param parent + * the parent composite + * @return the newly created Control + */ + protected Control createColumnsOptions(Composite parent) { + Composite contents = (Composite) createOptionsPage(parent, + PaletteMessages.SETTINGS_OPTIONS_COLUMNS, + LAYOUT_COLUMNS_ICON_SIZE_ID); + + if (getButton(LAYOUT_COLUMNS_ICON_SIZE_ID) != null) { + getButton(LAYOUT_COLUMNS_ICON_SIZE_ID).setSelection( + prefs.useLargeIcons(PaletteViewerPreferences.LAYOUT_COLUMNS)); + } + + // final Button button = createButton(contents, -1, + // PaletteMessages.SETTINGS_LAYOUT_COLUMNS_OVERRIDE_WIDTH, SWT.CHECK, + // null); + // ((GridData)button.getLayoutData()).horizontalSpan = 2; + // + // Composite container = new Composite(contents, SWT.NONE); + // container.setFont(contents.getFont()); + // GridLayout layout = new GridLayout(2, false); + // container.setLayout(layout); + // GridData data = new GridData(GridData.FILL_HORIZONTAL | + // GridData.VERTICAL_ALIGN_FILL); + // data.horizontalSpan = 2; + // container.setLayoutData(data); + // + // final Label label = new Label(container, SWT.NONE); + // label.setFont(container.getFont()); + // label.setText(PaletteMessages.SETTINGS_LAYOUT_COLUMNS_WIDTH); + // data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING + // | GridData.VERTICAL_ALIGN_BEGINNING); + // label.setLayoutData(data); + // label.setEnabled(false); + // + // final Text box = new Text(container, SWT.SINGLE | SWT.BORDER); + // box.setFont(container.getFont()); + // // box.setText("30"); + // box.setEnabled(false); + // data = new GridData(GridData.FILL_HORIZONTAL | + // GridData.VERTICAL_ALIGN_BEGINNING); + // data.widthHint = 50; + // box.setLayoutData(data); + // + // button.addSelectionListener(new SelectionListener() { + // public void widgetSelected(SelectionEvent e) { + // label.setEnabled(!label.isEnabled()); + // box.setEnabled(!box.isEnabled()); + // } + // public void widgetDefaultSelected(SelectionEvent e) { + // } + // }); + + return contents; + } + + /** + * Creates and initializes (i.e. loads the current settings from PaletteViewerPreferences) the + * part of the dialog that displays the font settings. + * + * @param parent + * the parent composite + * @return the newly created Control + */ + protected Control createFontSettings(Composite parent) { + Composite container = new Composite(parent, SWT.NONE); + container.setFont(parent.getFont()); + GridLayout layout = new GridLayout(2, false); + container.setLayout(layout); + + fontName = new Label(container, SWT.LEFT | SWT.WRAP); + fontName.setFont(container.getFont()); + GridData data = new GridData(GridData.FILL_BOTH); + data.verticalSpan = 2; + fontName.setLayoutData(data); + updateFontName(); + + createButton(container, FONT_CHANGE_ID, + PaletteMessages.SETTINGS_FONT_CHANGE, SWT.PUSH, null); + + createButton(container, DEFAULT_FONT_ID, + PaletteMessages.SETTINGS_DEFAULT_FONT, SWT.PUSH, null); + + return container; + } + + /** + * Creates and initializes (i.e. loads the current settings from PaletteViewerPreferences) the + * options for icons layout. + * + * @param parent + * the parent composite + * @return the newly created Control + */ + protected Control createIconsOnlyOptions(Composite parent) { + Control contents = createOptionsPage(parent, + PaletteMessages.SETTINGS_OPTIONS_ICONS_ONLY, + LAYOUT_ICONS_ICON_SIZE_ID); + + if (getButton(LAYOUT_ICONS_ICON_SIZE_ID) != null) { + getButton(LAYOUT_ICONS_ICON_SIZE_ID).setSelection( + prefs.useLargeIcons(PaletteViewerPreferences.LAYOUT_ICONS)); + } + return contents; + } + + /** + * Creates the part of the dialog that displays the various options for the selected layout. + * + * @param parent + * the parent composite + * @return the newly created Control + */ + protected Control createLayoutOptions(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + composite.setFont(parent.getFont()); + GridLayout layout = new GridLayout(1, false); + layout.marginWidth = 0; + layout.marginHeight = 0; + composite.setLayout(layout); + + Label label = new Label(composite, SWT.NONE); + label.setFont(composite.getFont()); + label.setText(PaletteMessages.SETTINGS_LAYOUT_TITLE); + GridData data = new GridData(); + label.setLayoutData(data); + + Button b = null; + int[] modes = prefs.getSupportedLayoutModes(); + for (int i = 0; i < modes.length; i++) { + switch (modes[i]) { + case PaletteViewerPreferences.LAYOUT_COLUMNS: + b = createButton(composite, LAYOUT_COLUMNS_VIEW_ID, + PaletteMessages.SETTINGS_COLUMNS_VIEW_LABEL, SWT.RADIO, + null); + ((GridData) b.getLayoutData()).horizontalIndent = 5; + break; + case PaletteViewerPreferences.LAYOUT_LIST: + b = createButton(composite, LAYOUT_LIST_VIEW_ID, + PaletteMessages.SETTINGS_LIST_VIEW_LABEL, SWT.RADIO, + null); + ((GridData) b.getLayoutData()).horizontalIndent = 5; + break; + case PaletteViewerPreferences.LAYOUT_ICONS: + b = createButton(composite, LAYOUT_ICONS_VIEW_ID, + PaletteMessages.SETTINGS_ICONS_VIEW_LABEL, SWT.RADIO, + null); + ((GridData) b.getLayoutData()).horizontalIndent = 5; + break; + case PaletteViewerPreferences.LAYOUT_DETAILS: + b = createButton(composite, LAYOUT_DETAILS_VIEW_ID, + PaletteMessages.SETTINGS_DETAILS_VIEW_LABEL, SWT.RADIO, + null); + ((GridData) b.getLayoutData()).horizontalIndent = 5; + break; + } + } + + // Load layout settings + int layoutSetting = prefs.getLayoutSetting(); + switch (layoutSetting) { + case PaletteViewerPreferences.LAYOUT_COLUMNS: + b = getButton(LAYOUT_COLUMNS_VIEW_ID); + break; + case PaletteViewerPreferences.LAYOUT_ICONS: + b = getButton(LAYOUT_ICONS_VIEW_ID); + break; + case PaletteViewerPreferences.LAYOUT_LIST: + b = getButton(LAYOUT_LIST_VIEW_ID); + break; + case PaletteViewerPreferences.LAYOUT_DETAILS: + b = getButton(LAYOUT_DETAILS_VIEW_ID); + break; + } + if (b == null) { + return null; + } + b.setSelection(true); + b.setFocus(); + + return composite; + } + + /** + * Creates the part of the dialog that displays the lists the available layout modes. + * + * @param parent + * the parent composite + * @return the newly created Control + */ + protected Control createLayoutSettings(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + composite.setFont(parent.getFont()); + GridLayout layout = new GridLayout(2, false); + composite.setLayout(layout); + + GridData data = new GridData(GridData.VERTICAL_ALIGN_BEGINNING); + Control layoutOptions = createLayoutOptions(composite); + if (layoutOptions != null) { + layoutOptions.setLayoutData(data); + } + + book = new PageBook(composite, SWT.NONE); + book.setFont(composite.getFont()); + data = new GridData(GridData.FILL_BOTH); + book.setLayoutData(data); + + columnsPanel = createColumnsOptions(book); + listPanel = createListOptions(book); + iconsPanel = createIconsOnlyOptions(book); + detailsPanel = createDetailsOptions(book); + + // Show the right page in the book + handleLayoutSettingChanged(prefs.getLayoutSetting()); + + return composite; + } + + /** + * Creates and initializes (i.e. loads the current settings from PaletteViewerPreferences) the + * options for list layout. + * + * @param parent + * the parent composite + * @return the newly created Control + */ + protected Control createListOptions(Composite parent) { + Control composite = createOptionsPage(parent, + PaletteMessages.SETTINGS_OPTIONS_LIST, LAYOUT_LIST_ICON_SIZE_ID); + if (getButton(LAYOUT_LIST_ICON_SIZE_ID) != null) { + getButton(LAYOUT_LIST_ICON_SIZE_ID).setSelection( + prefs.useLargeIcons(PaletteViewerPreferences.LAYOUT_LIST)); + } + return composite; + } + + /** + * This helper method is a result of code-factoring. It creates a Group displaying the given + * title and creates a "Use Large Icons" checkbox with the given buttonId in it. This method is + * used to create the options for the different layout modes. + * + * @param parent + * the parent composite + * @param title + * The title for the group to be created. + * @param buttonId + * The ID for the "Use Large Icons" checkbox to be created in the group. + * @return the newly created Group + */ + protected Control createOptionsPage(Composite parent, String title, + int buttonId) { + Group contents = new Group(parent, SWT.NONE); + contents.setFont(parent.getFont()); + GridLayout layout = new GridLayout(1, false); + contents.setLayout(layout); + GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL + | GridData.VERTICAL_ALIGN_FILL); + data.heightHint = 0; + contents.setLayoutData(data); + contents.setText(title); + + createButton(contents, buttonId, + PaletteMessages.SETTINGS_USE_LARGE_ICONS_LABEL, SWT.CHECK, null); + + return contents; + } + + /** + * Returns the Button with the given id; or null if none was found. + * + * @see org.eclipse.jface.dialogs.Dialog#getButton(int) + */ + protected Button getButton(int id) { + Button button = null; + Widget widget = getWidget(id); + if (widget instanceof Button) { + button = (Button) widget; + } + + return button; + } + + /** + * The Widgets that were created with a unique ID and added to this class' internal + * map can be retrieved through this method. + * + * @param id + * The unique ID of the Widget that you wish to retrieve + * @return The Widget, if one with the given id exists. null otherwise. + */ + protected Widget getWidget(int id) { + Widget widget = (Widget) widgets.get(new Integer(id)); + if (widget == null) { + widget = super.getButton(id); + } + + return widget; + } + + /** + * Called when any one of the "Auto - Collapse" radio buttons is clicked. It changes the setting + * in the {@link org.eclipse.gef.ui.palette.PaletteViewerPreferences} object. + * + * @param newSetting + * The flag for the new setting + */ + protected void handleAutoCollapseSettingChanged(int newSetting) { + prefs.setAutoCollapseSetting(newSetting); + } + + /** + * This method is invoked when "Cancel" is invoked on the dialog. It simply restores the + * settings, thus undoing any changes made in this Dialog. + */ + protected void handleCancelPressed() { + restoreSettings(); + } + + /** + * This method is invoked when the user selects the "Change" font button. It opens the + * FontDialog to allow the user to change the font. + */ + protected void handleChangeFontPressed() { + FontDialog dialog = new FontDialog(getShell()); + FontData data = prefs.getFontData(); + dialog.setFontList(new FontData[] { data }); + data = dialog.open(); + if (data != null) { + prefs.setFontData(data); + } + updateFontName(); + } + + /** + * This method is invoked when the user selects the "Restore Default" font button. It changes + * the font, in case it was different, to the default one, which is the Workbench Dialog font. + */ + protected void handleDefaultFontRequested() { + prefs.setFontData(JFaceResources.getDialogFont().getFontData()[0]); + updateFontName(); + } + + /** + * This method is invoked when the "Use Large Icons" checkbox is selected/deselected for the + * currently active layout mode. + * + * @param selection + * indicates whether large icons are to be used or not. + */ + protected void handleIconSizeChanged(boolean selection) { + prefs.setCurrentUseLargeIcons(selection); + } + + /** + * This method is called when any one of the "Layout" radio buttons is clicked. It changes the + * setting in the {@link org.eclipse.gef.ui.palette.PaletteViewerPreferences} object. + * + * @param newSetting + * The flag for the new setting + */ + protected void handleLayoutSettingChanged(int newSetting) { + prefs.setLayoutSetting(newSetting); + switch (newSetting) { + case PaletteViewerPreferences.LAYOUT_COLUMNS: + showLayoutOptionsPage(columnsPanel); + break; + case PaletteViewerPreferences.LAYOUT_LIST: + showLayoutOptionsPage(listPanel); + break; + case PaletteViewerPreferences.LAYOUT_ICONS: + showLayoutOptionsPage(iconsPanel); + break; + case PaletteViewerPreferences.LAYOUT_DETAILS: + showLayoutOptionsPage(detailsPanel); + break; + default: + break; + } + } + + /** + * Restores the cached settings, thus undoing any changes made since the last caching of + * settings. + * + * @see #cacheSettings() + */ + protected void restoreSettings() { + prefs.setFontData((FontData) settings.get(CACHE_FONT)); + prefs.setAutoCollapseSetting(((Integer) settings.get(CACHE_COLLAPSE)) + .intValue()); + prefs.setLayoutSetting(((Integer) settings.get(CACHE_LAYOUT)) + .intValue()); + prefs.setUseLargeIcons(PaletteViewerPreferences.LAYOUT_DETAILS, + ((Boolean) settings.get(CACHE_DETAILS_ICON_SIZE)) + .booleanValue()); + prefs.setUseLargeIcons(PaletteViewerPreferences.LAYOUT_ICONS, + ((Boolean) settings.get(CACHE_ICONS_ICON_SIZE)).booleanValue()); + prefs.setUseLargeIcons(PaletteViewerPreferences.LAYOUT_LIST, + ((Boolean) settings.get(CACHE_LIST_ICON_SIZE)).booleanValue()); + prefs.setUseLargeIcons(PaletteViewerPreferences.LAYOUT_COLUMNS, + ((Boolean) settings.get(CACHE_COLUMNS_ICON_SIZE)) + .booleanValue()); + } + + /** + * This helper method is mainly a result of code-factoring. It shows the given page (which + * should be one of the controls showing the layout options) in the PageBook and grows the + * dialog if necessary. + * + * @param page + * One of the controls showing the layout options that already belongs to the + * PageBook book. + */ + protected void showLayoutOptionsPage(Control page) { + // Show the page and grow the shell (if necessary) so that the page is + // completely + // visible + Point oldSize = getShell().getSize(); + book.showPage(page); + Point newSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT, true); + int x = newSize.x - oldSize.x; + x = (x < 0) ? 0 : x; + int y = newSize.y - oldSize.y; + y = (y < 0) ? 0 : y; + if (x > 0 || y > 0) { + getShell().setSize(oldSize.x + x, oldSize.y + y); + } + } + + /** + * Updates the label showing the font's name to show the name of the current font. + */ + protected void updateFontName() { + String name; + if (prefs.getFontData().equals( + (JFaceResources.getDialogFont().getFontData()[0]))) { + name = PaletteMessages.SETTINGS_WORKBENCH_FONT_LABEL; + } else { + name = StringConverter.asString(prefs.getFontData()); + } + fontName.setText(PaletteMessages.SETTINGS_FONT_CURRENT + name); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteStackFactory.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteStackFactory.java new file mode 100644 index 0000000..505b249 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteStackFactory.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.customize; + +import org.eclipse.swt.widgets.Shell; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteContainer; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteStack; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.ToolEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteMessages; + + +/** + * Factory to create {@link org.eclipse.gef.palette.PaletteStack} + * + * @author Whitney Sorenson + * @since 3.0 + */ +public class PaletteStackFactory extends PaletteEntryFactory { + + /** + * Creates a new PaletteStackFactory with label PaletteMessages.MODEL_TYPE_STACK + */ + public PaletteStackFactory() { + setLabel(PaletteMessages.MODEL_TYPE_STACK); + } + + /** + * @see org.eclipse.gef.ui.palette.customize.PaletteEntryFactory#canCreate(org.eclipse.gef.palette.PaletteEntry) + */ + public boolean canCreate(PaletteEntry selected) { + if (!(selected instanceof ToolEntry) + || selected.getParent() instanceof PaletteStack) + return false; + return super.canCreate(selected); + } + + /** + * @see org.eclipse.gef.ui.palette.customize.PaletteEntryFactory#createNewEntry(Shell) + */ + protected PaletteEntry createNewEntry(Shell shell) { + return new PaletteStack(PaletteMessages.NEW_STACK_LABEL, null, null); + } + + /** + * @see org.eclipse.gef.ui.palette.customize.PaletteEntryFactory#createNewEntry(org.eclipse.swt.widgets.Shell, + * org.eclipse.gef.palette.PaletteEntry) + */ + public PaletteEntry createNewEntry(Shell shell, PaletteEntry selected) { + PaletteContainer parent = determineContainerForNewEntry(selected); + int index = determineIndexForNewEntry(parent, selected); + PaletteEntry entry = createNewEntry(shell); + parent.remove(selected); + parent.add(index - 1, entry); + ((PaletteStack) entry).add(selected); + entry.setUserModificationPermission(PaletteEntry.PERMISSION_FULL_MODIFICATION); + return entry; + } + + /** + * @see org.eclipse.gef.ui.palette.customize.PaletteEntryFactory#determineTypeForNewEntry(org.eclipse.gef.palette.PaletteEntry) + */ + protected Object determineTypeForNewEntry(PaletteEntry selected) { + return PaletteStack.PALETTE_TYPE_STACK; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteTreeProvider.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteTreeProvider.java new file mode 100644 index 0000000..4c0f4f4 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/customize/PaletteTreeProvider.java @@ -0,0 +1,166 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.customize; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteContainer; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteRoot; + + +/** + * This is the {@link org.eclipse.jface.viewers.IContentProvider} for the + * {@link org.eclipse.jface.viewers.TreeViewer} used in + * {@link org.eclipse.gef.ui.palette.customize.PaletteCustomizerDialog}. + * + * @author Pratik Shah + * @see org.eclipse.jface.viewer.TreeViewer + * @see org.eclipse.gef.ui.palette.customize.PaletteCustomizerDialog + */ +class PaletteTreeProvider implements ITreeContentProvider { + + private TreeViewer viewer; + private PaletteRoot root; + private PropertyChangeListener modelListener = new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent evt) { + handlePropertyChanged(evt); + } + }; + + /** + * Constructor + * + * @param treeviewer + * The TreeViewer whose ContentProvider this PaletteTreeProvider is + */ + public PaletteTreeProvider(TreeViewer treeviewer) { + this.viewer = treeviewer; + } + + /** + * Stops listening to the model + * + * @see org.eclipse.jface.viewers.IContentProvider#dispose() + */ + public void dispose() { + traverseModel(root, false); + } + + /** + * If the given element does not have any children, this method should return null. + * This fixes the problem where a "+" sign is incorrectly placed next to an empty container in + * the tree. + * + * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(Object) + */ + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof PaletteContainer) { + List children = ((PaletteContainer) parentElement).getChildren(); + if (!children.isEmpty()) { + return children.toArray(); + } + } + return null; + } + + /** + * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(Object) + */ + public boolean hasChildren(Object element) { + return getChildren(element) != null; + } + + /** + * This method should not return null. + * + * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(Object) + */ + public Object[] getElements(Object inputElement) { + Object[] elements = getChildren(inputElement); + if (elements == null) { + elements = new Object[0]; + } + return elements; + } + + /** + * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(Object) + */ + public Object getParent(Object element) { + return ((PaletteEntry) element).getParent(); + } + + /** + * This method is invoked whenever there is any change in the model. It updates the viewer with + * the changes that were made to the model. Sub-classes may override this method to change or + * extend its functionality. + * + * @param evt + * The {@link PropertyChangeEvent} that was fired from the model + */ + protected void handlePropertyChanged(PropertyChangeEvent evt) { + PaletteEntry entry = ((PaletteEntry) evt.getSource()); + String property = evt.getPropertyName(); + if (property.equals(PaletteEntry.PROPERTY_LABEL) + || property.equals(PaletteEntry.PROPERTY_SMALL_ICON)) { + viewer.update(entry, null); + } else if (property.equals(PaletteEntry.PROPERTY_VISIBLE)) { + viewer.refresh(entry); + } else if (property.equals(PaletteContainer.PROPERTY_CHILDREN)) { + viewer.refresh(entry); + List oldChildren = (List) evt.getOldValue(); + for (Iterator iter = oldChildren.iterator(); iter.hasNext();) { + PaletteEntry child = (PaletteEntry) iter.next(); + traverseModel(child, false); + } + traverseModel(entry, true); + } + } + + /** + * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(Viewer, Object, Object) + */ + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + if (root != null) + traverseModel(root, false); + if (newInput != null) { + root = (PaletteRoot) newInput; + traverseModel(root, true); + } + } + + private void traverseModel(PaletteEntry entry, boolean isHook) { + if (isHook) { + entry.addPropertyChangeListener(modelListener); + } else { + entry.removePropertyChangeListener(modelListener); + } + + if (hasChildren(entry)) { + Object[] children = getChildren(entry); + for (int i = 0; i < children.length; i++) { + traverseModel((PaletteEntry) children[i], isHook); + } + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/editparts/IPinnableEditPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/editparts/IPinnableEditPart.java new file mode 100644 index 0000000..920c7a0 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/editparts/IPinnableEditPart.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2008, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.editparts; + +/** + * This interface is used to identify and work with a pinnable palette editpart (e.g. drawers, + * stacks). + * + * @author crevells + * @since 3.4 + */ +public interface IPinnableEditPart { + + /** + * Returns true if the palette editpart is pinned open. + * + * @return boolean + */ + public boolean isPinnedOpen(); + + /** + * @return true if the palette editpart can be pinned open. + */ + public boolean canBePinned(); + + /** + * Sets the palette editpart's pinned state to the specified value. + * + * @param pinned + * true if the palette editpart should be pinned when opened + */ + public void setPinnedOpen(boolean pinned); + + /** + * Returns the expansion state of the palette editpart + * + * @return true if the palette editpart is expanded; false otherwise + */ + public boolean isExpanded(); + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/editparts/PaletteAnimator.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/editparts/PaletteAnimator.java new file mode 100644 index 0000000..42fd9b5 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/editparts/PaletteAnimator.java @@ -0,0 +1,151 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.editparts; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.LayoutAnimator; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.DrawerEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.DrawerFigure; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewerPreferences; + + +/** + * An animator for the layout of the palette. + * + * @author Randy Hudson, Pratik Shah + */ +public class PaletteAnimator extends LayoutAnimator { + + private List drawers = new ArrayList(); + private PaletteViewerPreferences prefs; + + /** + * Constructor for a PaletteAnimator + * + * @param prefs + * The palette PaletteViewerPreferencesPreferences + */ + public PaletteAnimator(PaletteViewerPreferences prefs) { + this.prefs = prefs; + } + + /** + * Add a drawer to the palette. + * + * @param drawer + * the drawer. + */ + public void addDrawer(DrawerEditPart drawer) { + drawers.add(drawer.getFigure()); + } + + /** + * Collapse the provided drawer if the automatoc collapse setting is enabled. + * + * @param openDrawer + * The drawer to collapse. + * @since 3.2 + */ + protected void autoCollapse(DrawerFigure openDrawer) { + int autoCollapseMode = prefs.getAutoCollapseSetting(); + + // Collapse never + if (autoCollapseMode == PaletteViewerPreferences.COLLAPSE_NEVER) + return; + + DrawerFigure drawer; + + // Collapse always + if (autoCollapseMode == PaletteViewerPreferences.COLLAPSE_ALWAYS) { + for (Iterator iter = drawers.iterator(); iter.hasNext();) { + drawer = (DrawerFigure) iter.next(); + if (drawer != openDrawer) + drawer.setExpanded(false); + } + return; + } + + // Collapse as needed + int wHint = openDrawer.getParent().getClientArea().width; + int availableHeight = openDrawer.getParent().getSize().height; + int requiredHeight = 0; + List closable = new ArrayList(); + for (Iterator iter = openDrawer.getParent().getChildren().iterator(); iter + .hasNext();) { + IFigure sibling = (IFigure) iter.next(); + int height = sibling.getPreferredSize(wHint, -1).height; + requiredHeight += height; + if (!(sibling instanceof DrawerFigure) || sibling == openDrawer) + continue; + drawer = (DrawerFigure) sibling; + if (drawer.isExpanded() && !drawer.isPinnedOpen()) + closable.add(drawer); + } + + // Start closing until requiredHeight <= available + for (int i = closable.size() - 1; i >= 0 + && requiredHeight > availableHeight; i--) { + drawer = (DrawerFigure) closable.get(i); + int expandedHeight = drawer.getPreferredSize(wHint, -1).height; + drawer.setExpanded(false); + int collapsedHeight = drawer.getPreferredSize(wHint, -1).height; + requiredHeight -= (expandedHeight - collapsedHeight); + } + } + + /** + * @see org.eclipse.draw2d.Animator#playbackStarting(org.eclipse.draw2d.IFigure) + */ + public void playbackStarting(IFigure figure) { + if (figure instanceof DrawerFigure) + ((DrawerFigure) figure).setAnimating(true); + } + + /** + * Remove the drawer. + * + * @param drawer + * the drawer. + */ + public void removeDrawer(DrawerEditPart drawer) { + drawers.remove(drawer.getFigure()); + } + + /** + * @see org.eclipse.draw2d.Animator#init(org.eclipse.draw2d.IFigure) + */ + public void init(IFigure figure) { + if (figure instanceof DrawerFigure) { + DrawerFigure drawer = (DrawerFigure) figure; + if (drawer.isExpanded()) + autoCollapse(drawer); + return; + } + super.init(figure); + } + + /** + * @see org.eclipse.draw2d.Animator#tearDown(org.eclipse.draw2d.IFigure) + */ + public void tearDown(IFigure figure) { + if (figure instanceof DrawerFigure) + ((DrawerFigure) figure).setAnimating(false); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/editparts/PaletteEditPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/editparts/PaletteEditPart.java new file mode 100644 index 0000000..58a58e0 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/editparts/PaletteEditPart.java @@ -0,0 +1,491 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.editparts; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.eclipse.draw2d.Border; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.MarginBorder; +import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.draw2d.text.FlowPage; +import org.eclipse.draw2d.text.TextFlow; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.DragTracker; +import org.eclipse.gef.Request; +import org.eclipse.gef.editparts.AbstractGraphicalEditPart; +import org.eclipse.gef.tools.SelectEditPartTracker; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IMemento; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteContainer; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteSeparator; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteMessages; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewer; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewerPreferences; + + +/** + * The abstract implementation of palette edit parts. All edit parts used in the palette must extend + * this class. + */ +public abstract class PaletteEditPart extends AbstractGraphicalEditPart + implements PropertyChangeListener { + + /** + * The name of each entry in the palette, used to restore the state. + */ + public static final String XML_NAME = "entry"; //$NON-NLS-1$ + private static final Border TOOLTIP_BORDER = new MarginBorder(0, 2, 1, 0); + private static ImageCache globalImageCache; + private AccessibleEditPart acc; + private PropertyChangeListener childListener = new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getPropertyName().equals(PaletteEntry.PROPERTY_VISIBLE)) { + refreshChildren(); + } + } + }; + private Image image; + private ImageDescriptor imgDescriptor; + + /** + * Constructor for the PaletteEditPart. + * + * @param model + * The model element for this edit part. + */ + public PaletteEditPart(PaletteEntry model) { + setModel(model); + } + + /** + * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#activate() + */ + public void activate() { + super.activate(); + PaletteEntry model = (PaletteEntry) getModel(); + model.addPropertyChangeListener(this); + traverseChildren(model, true); + } + + /** + * returns the AccessibleEditPart for this EditPart. This method is called lazily from + * {@link #getAccessibleEditPart()}. + * + * @return the AccessibleEditPart. + */ + protected AccessibleEditPart createAccessible() { + return null; + } + + /** + * @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies() + */ + public void createEditPolicies() { + } + + /** + * Create the tool tip for this palette edit part. + * + * @return the tool tip figure. + */ + protected IFigure createToolTip() { + String message = getToolTipText(); + if (message == null || message.length() == 0) + return null; + + FlowPage fp = new FlowPage() { + public Dimension getPreferredSize(int w, int h) { + Dimension d = super.getPreferredSize(-1, -1); + if (d.width > 150) + d = super.getPreferredSize(150, -1); + return d; + } + }; + fp.setOpaque(true); + fp.setBorder(TOOLTIP_BORDER); + TextFlow tf = new TextFlow(); + tf.setText(message); + fp.add(tf); + return fp; + } + + /** + * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#deactivate() + */ + public void deactivate() { + PaletteEntry model = (PaletteEntry) getModel(); + model.removePropertyChangeListener(this); + traverseChildren(model, false); + if (image != null) { + image.dispose(); + image = null; + } + super.deactivate(); + } + + /** + * @see org.eclipse.gef.editparts.AbstractEditPart#getAccessibleEditPart() + */ + protected AccessibleEditPart getAccessibleEditPart() { + if (acc == null) + acc = createAccessible(); + return acc; + } + + /** + * A selection tracker for the edit part. + */ + public class SingleSelectionTracker extends SelectEditPartTracker { + /** + * Constructor for a SingleSelectionTracker. + */ + public SingleSelectionTracker() { + super(PaletteEditPart.this); + } + + /** + * @see org.eclipse.gef.tools.SelectEditPartTracker#performSelection() + */ + protected void performSelection() { + if (hasSelectionOccurred()) + return; + setFlag(FLAG_SELECTION_PERFORMED, true); + getCurrentViewer().select(getSourceEditPart()); + } + } + + /** + * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#getDragTracker(Request) + */ + public DragTracker getDragTracker(Request request) { + return new SingleSelectionTracker(); + } + + /** + * Returns the image cache. The cache is global, and is shared by all palette edit parts. This + * has the disadvantage that once an image is allocated, it is never freed until the display is + * disposed. However, it has the advantage that the same image in different palettes is only + * ever created once. + * + * @return the image cache. + */ + protected static ImageCache getImageCache() { + ImageCache cache = globalImageCache; + if (cache == null) { + globalImageCache = cache = new ImageCache(); + Display display = Display.getDefault(); + if (display != null) { + display.disposeExec(new Runnable() { + public void run() { + if (globalImageCache != null) { + globalImageCache.dispose(); + globalImageCache = null; + } + } + }); + } + } + return cache; + } + + /** + * @see org.eclipse.gef.editparts.AbstractEditPart#getModelChildren() + */ + public List getModelChildren() { + List modelChildren; + if (getModel() instanceof PaletteContainer) + modelChildren = new ArrayList( + ((PaletteContainer) getModel()).getChildren()); + else + return Collections.EMPTY_LIST; + + PaletteEntry prevVisibleEntry = null; + for (Iterator iter = modelChildren.iterator(); iter.hasNext();) { + PaletteEntry entry = (PaletteEntry) iter.next(); + if (!entry.isVisible()) + // not visible + iter.remove(); + else if (entry instanceof PaletteSeparator + && prevVisibleEntry == null) + // first visible item in a group is a separator, don't need it + iter.remove(); + else if (entry instanceof PaletteSeparator + && prevVisibleEntry instanceof PaletteSeparator) + // previous visible entry was a separator, don't need it + iter.remove(); + else + prevVisibleEntry = entry; + } + // check to see if last visible entry was a separator, and thus should + // be hidden + if (prevVisibleEntry instanceof PaletteSeparator) + modelChildren.remove(prevVisibleEntry); + + return modelChildren; + } + + /** + * Get the model element for this palette edit part. + * + * @return the model element. + */ + protected PaletteEntry getPaletteEntry() { + return (PaletteEntry) getModel(); + } + + /** + * Get the palette viewer for this palette edit part. + * + * @return the palette viewer. + */ + protected PaletteViewer getPaletteViewer() { + return (PaletteViewer) getViewer(); + } + + /** + * Get the palette viewer preferences for this palette edit part. + * + * @return the palette viewer preferences. + */ + protected PaletteViewerPreferences getPreferenceSource() { + return ((PaletteViewer) getViewer()).getPaletteViewerPreferences(); + } + + /** + * Get the tool tip figure for this palette edit part. + * + * @return the tool tip figure. + */ + protected IFigure getToolTipFigure() { + return getFigure(); + } + + /** + * Get the tool tip text for this palette edit part. + * + * @return the tool tip text. + */ + protected String getToolTipText() { + String text = null; + PaletteEntry entry = (PaletteEntry) getModel(); + String desc = entry.getDescription(); + boolean needName = nameNeededInToolTip(); + if (desc == null || desc.trim().equals(entry.getLabel()) + || desc.trim().equals("")) { //$NON-NLS-1$ + if (needName) + text = entry.getLabel(); + } else { + if (needName) + text = entry.getLabel() + + " " //$NON-NLS-1$ + + PaletteMessages.NAME_DESCRIPTION_SEPARATOR + + " " + desc; //$NON-NLS-1$ + else + text = desc; + } + if (text != null && text.trim().equals(""))//$NON-NLS-1$ + return null; + return text; + } + + // /** + // * Overwritten because palette edit parts are not bound to the constraint + // * that their figure has to be visible (they may get selected while being + // * stacked). + // * + // * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#isSelectable() + // */ + // public boolean isSelectable() { + // return true; + // } + + /** + * Determine if the name is needed in the tool tip. + * + * @return true if the name is needed in the tool tip. + * @since 3.2 + */ + protected boolean nameNeededInToolTip() { + return getLayoutSetting() == PaletteViewerPreferences.LAYOUT_ICONS; + } + + /** + * @see java.beans.PropertyChangeListener#propertyChange(PropertyChangeEvent) + */ + public void propertyChange(PropertyChangeEvent evt) { + String property = evt.getPropertyName(); + if (property.equals(PaletteContainer.PROPERTY_CHILDREN)) { + traverseChildren((List) evt.getOldValue(), false); + refreshChildren(); + traverseChildren((List) evt.getNewValue(), true); + } else if (property.equals(PaletteEntry.PROPERTY_LABEL) + || property.equals(PaletteEntry.PROPERTY_SMALL_ICON) + || property.equals(PaletteEntry.PROPERTY_LARGE_ICON) + || property.equals(PaletteEntry.PROPERTY_DESCRIPTION)) + refreshVisuals(); + } + + /** + * Restore the state of the palette entry. + * + * @param memento + * the saved state of the palette entry. + */ + public void restoreState(IMemento memento) { + Iterator iter = getChildren().iterator(); + IMemento[] childMementos = memento.getChildren(XML_NAME); + int index = 0; + while (iter.hasNext()) + ((PaletteEditPart) iter.next()) + .restoreState(childMementos[index++]); + } + + /** + * Save the state of the palette entry. + * + * @param memento + * the saved state of the palette entry. + */ + public void saveState(IMemento memento) { + Iterator iter = getChildren().iterator(); + while (iter.hasNext()) + ((PaletteEditPart) iter.next()).saveState(memento + .createChild(XML_NAME)); + } + + /** + * Set the image for this palette edit part. + * + * @param desc + * the image descriptor. + */ + protected void setImageDescriptor(ImageDescriptor desc) { + if (desc == imgDescriptor) + return; + imgDescriptor = desc; + setImageInFigure(getImageCache().getImage(imgDescriptor)); + } + + /** + * Set the image to be used in the figure for this edit edit. + * + * @param image + * the image + */ + protected void setImageInFigure(Image image) { + } + + private void traverseChildren(PaletteEntry parent, boolean add) { + if (!(parent instanceof PaletteContainer)) + return; + PaletteContainer container = (PaletteContainer) parent; + traverseChildren(container.getChildren(), add); + } + + private void traverseChildren(List children, boolean add) { + for (Iterator iter = children.iterator(); iter.hasNext();) { + PaletteEntry entry = (PaletteEntry) iter.next(); + if (add) { + entry.addPropertyChangeListener(childListener); + } else { + entry.removePropertyChangeListener(childListener); + } + } + } + + /** + * The image cache for this edit part. + */ + protected static class ImageCache { + /** Map from ImageDescriptor to Image */ + private Map images = new HashMap(11); + + Image getImage(ImageDescriptor desc) { + if (desc == null) { + return null; + } + Image img = null; + Object obj = images.get(desc); + if (obj != null) { + img = (Image) obj; + } else { + img = desc.createImage(); + images.put(desc, img); + } + return img; + } + + Image getMissingImage() { + return getImage(ImageDescriptor.getMissingImageDescriptor()); + } + + void dispose() { + for (Iterator i = images.values().iterator(); i.hasNext();) { + Image img = (Image) i.next(); + img.dispose(); + } + images.clear(); + } + } + + /** + * Returns the current layout setting. + * + * @return the current layout setting. + * @see PaletteViewerPreferences#getLayoutSetting() + * @since 3.4 + */ + protected int getLayoutSetting() { + if (getParent() instanceof PaletteEditPart) { + return ((PaletteEditPart) getParent()).getLayoutSetting(); + } + return getPreferenceSource().getLayoutSetting(); + } + + /** + * Overwritten to ensure palette entries are always selectable, even if their figure is not + * showing). + * + * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#isSelectable() + */ + public boolean isSelectable() { + // bug #349124 + return true; + } + + /** + * Returns true if this item is on the palette toolbar. + * + * @return true if this item is on the palette toolbar; false otherwise + * @since 3.4 + */ + public boolean isToolbarItem() { + if (getParent() instanceof PaletteEditPart) { + return ((PaletteEditPart) getParent()).isToolbarItem(); + } + return false; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/editparts/PaletteToolbarLayout.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/editparts/PaletteToolbarLayout.java new file mode 100644 index 0000000..224635d --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/editparts/PaletteToolbarLayout.java @@ -0,0 +1,200 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.editparts; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.ToolbarLayout; +import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.draw2d.geometry.Rectangle; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.DrawerFigure; + + +/** + * A ToolbarLayout-like layout for the palette. This layout only works when vertically oriented. + * + * @author Pratik Shah + */ +public class PaletteToolbarLayout extends ToolbarLayout { + + /** + * A figure is growing if it's an expanded drawer. + * + * @param child + * The figure that is to be marked as growing or non-growing + * @return true if the given child is considered growing + */ + protected boolean isChildGrowing(IFigure child) { + return child instanceof DrawerFigure + && ((DrawerFigure) child).isExpanded(); + } + + /** + * @see org.eclipse.draw2d.ToolbarLayout#layout(org.eclipse.draw2d.IFigure) + */ + public void layout(IFigure parent) { + List children = parent.getChildren(); + List childrenGrabbingVertical = new ArrayList(); + int numChildren = children.size(); + Rectangle clientArea = parent.getClientArea(); + int x = clientArea.x; + int y = clientArea.y; + int availableHeight = clientArea.height; + boolean stretching; + Dimension prefSizes[] = new Dimension[numChildren]; + Dimension minSizes[] = new Dimension[numChildren]; + int totalHeight = 0, totalMinHeight = 0, heightOfNonGrowingChildren = 0, heightPerChild = 0, excessHeight = 0; + + /* + * Determine hints. + */ + int wHint = clientArea.width; + int hHint = -1; + + /* + * Store the preferred and minimum sizes of all figures. Determine which figures can be + * stretched/shrunk. + */ + for (int i = 0; i < numChildren; i++) { + IFigure child = (IFigure) children.get(i); + + prefSizes[i] = child.getPreferredSize(wHint, hHint); + minSizes[i] = child.getMinimumSize(wHint, hHint); + + totalHeight += prefSizes[i].height; + totalMinHeight += minSizes[i].height; + + if (isChildGrowing(child)) { + childrenGrabbingVertical.add(child); + } else { + heightOfNonGrowingChildren += prefSizes[i].height; + } + } + totalHeight += (numChildren - 1) * getSpacing(); + totalMinHeight += (numChildren - 1) * getSpacing(); + + /* + * This is the algorithm that determines which figures need to be compressed/stretched and + * by how much. + */ + stretching = totalHeight - Math.max(availableHeight, totalMinHeight) < 0; + if (stretching) { + /* + * We only want the last child to stretch. So, we mark all but the last growing child as + * non-growing. + */ + for (int i = 0; i < childrenGrabbingVertical.size() - 1; i++) { + int index = children.indexOf(childrenGrabbingVertical.get(i)); + heightOfNonGrowingChildren += prefSizes[index].height; + } + if (!childrenGrabbingVertical.isEmpty()) { + Object last = childrenGrabbingVertical + .get(childrenGrabbingVertical.size() - 1); + childrenGrabbingVertical.clear(); + childrenGrabbingVertical.add(last); + heightPerChild = availableHeight - heightOfNonGrowingChildren; + } + } else if (!childrenGrabbingVertical.isEmpty()) { + /* + * So long as there is at least one child that can be grown, figure out how much height + * should be given to each growing child. + */ + boolean childrenDiscarded; + // spaceToConsume is the space height available on the palette that + // is to be + // shared by the growing children. + int spaceToConsume = availableHeight - heightOfNonGrowingChildren; + // heightPerChild is the height that each growing child is to be + // grown up to + heightPerChild = spaceToConsume / childrenGrabbingVertical.size(); + // excessHeight is the space leftover at the bottom of the palette + // after each + // growing child has been grown by heightPerChild. + excessHeight = spaceToConsume + - (heightPerChild * childrenGrabbingVertical.size()); + do { + childrenDiscarded = false; + for (Iterator iter = childrenGrabbingVertical.iterator(); iter + .hasNext();) { + IFigure childFig = (IFigure) iter.next(); + int i = childFig.getParent().getChildren() + .indexOf(childFig); + // In the case of shrinking, if the child's height is less + // than + // heightPerChild, mark that child as non-growing + if (prefSizes[i].height < heightPerChild) { + spaceToConsume -= prefSizes[i].height; + heightOfNonGrowingChildren += prefSizes[i].height; + iter.remove(); + if (!childrenGrabbingVertical.isEmpty()) { + childrenDiscarded = true; + heightPerChild = spaceToConsume + / childrenGrabbingVertical.size(); + excessHeight = spaceToConsume + - (heightPerChild * childrenGrabbingVertical + .size()); + } + break; + } + } + } while (childrenDiscarded); + } + + /* + * Do the actual layout, i.e. set the bounds of all the figures. + */ + for (int i = 0; i < numChildren; i++) { + IFigure child = (IFigure) children.get(i); + Rectangle newBounds = new Rectangle(x, y, prefSizes[i].width, + prefSizes[i].height); + + if (childrenGrabbingVertical.contains(child)) { + // Set the height of growing children. If this is the last one, + // give it + // the excess height. + childrenGrabbingVertical.remove(child); + if (childrenGrabbingVertical.isEmpty()) + newBounds.height = heightPerChild + excessHeight; + else + newBounds.height = heightPerChild; + } + + if (getStretchMinorAxis()) + newBounds.width = clientArea.width; + else + newBounds.width = Math + .min(prefSizes[i].width, clientArea.width); + + int adjust = clientArea.width - newBounds.width; + switch (getMinorAlignment()) { + case ALIGN_TOPLEFT: + adjust = 0; + break; + case ALIGN_CENTER: + adjust /= 2; + break; + case ALIGN_BOTTOMRIGHT: + break; + } + newBounds.x += adjust; + child.setBounds(newBounds); + y += newBounds.height + getSpacing(); + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/messages.properties b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/messages.properties new file mode 100644 index 0000000..e91b510 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/messages.properties @@ -0,0 +1,78 @@ +############################################################################### +# Copyright (c) 2002, 2008 IBM Corporation and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# IBM Corporation - initial API and implementation +# 1. Internalization of Code in Tizen SDK +# - update message (LAYOUT_MENU_LABEL=&Layout -> LAYOUT_MENU_LABEL=&View) +############################################################################### +CUSTOMIZE_DIALOG_TITLE=Customize Palette +COLLAPSE_OPTIONS_TITLE=Drawer options: +SETTINGS_LAYOUT_OPTIONS_TITLE=Layout options +MOVE_UP_LABEL=Move &Up +MOVE_DOWN_LABEL=Move Do&wn +DELETE_LABEL=&Delete +NEW_LABEL=&New +SETTINGS_COLUMNS_VIEW_LABEL=&Columns +SETTINGS_LIST_VIEW_LABEL=&List +SETTINGS_USE_LARGE_ICONS_LABEL=&Use large icons +SETTINGS_USE_LARGE_ICONS_LABEL_CAPS=&Use Large Icons +SETTINGS_ICONS_VIEW_LABEL=&Icons only +COLLAPSE_NEVER_LABEL=&Never close +COLLAPSE_ALWAYS_LABEL=&Always close when opening another drawer +COLLAPSE_AS_NEEDED_LABEL=Close automatically &when there is not enough room +NO_SELECTION_TITLE=Nothing selected +NAME_LABEL=Na&me: +DESCRIPTION_LABEL=Des&cription: +HIDDEN_LABEL=&Hide +NO_DESCRIPTION_AVAILABLE=No description is available. +NO_SELECTION_MADE=Select a node from the tree on the left. +MENU_OPEN_CUSTOMIZE_DIALOG=Cus&tomize... +MODEL_TYPE_DRAWER=Drawer +MODEL_TYPE_SEPARATOR=Separator +MODEL_TYPE_STACK=Stack +NEW_SEPARATOR_DESC=Separates entries in a palette container +NEW_DRAWER_LABEL=New Drawer +NEW_SEPARATOR_LABEL=[Separator] +NEW_STACK_LABEL=New Stack +APPLY_LABEL=&Apply +MODEL_TYPE_GROUP=Group +NEW_GROUP_LABEL=New Group +LAYOUT_MENU_LABEL=&View +ERROR=Could Not Accept Changes +ABORT_PAGE_FLIPPING_MESSAGE=The currently displayed page contains invalid values. +MENU_OPEN_SETTINGS_DIALOG=&Settings... +SETTINGS_DIALOG_TITLE=Palette Settings +SETTINGS_DETAILS_VIEW_LABEL=&Details +SETTINGS_FONT_TITLE=Font +SETTINGS_FONT_CHANGE=C&hange... +SETTINGS_FONT_CURRENT=Font: +SETTINGS_LAYOUT_TITLE=Layout: +SETTINGS_DRAWER_OPTIONS_TITLE=Drawer Options +EXPAND_DRAWER_AT_STARTUP_LABEL=&Open drawer at start-up +SETTINGS_OPTIONS_DETAILS=Details layout options +SETTINGS_OPTIONS_ICONS_ONLY=Icons only layout options +SETTINGS_OPTIONS_LIST=List layout options +SETTINGS_OPTIONS_COLUMNS=Columns layout options +SETTINGS_LAYOUT_COLUMNS_WIDTH=Colu&mn width (in pixels): +SETTINGS_LAYOUT_COLUMNS_OVERRIDE_WIDTH=&Override default column width settings +DRAWER_PIN_AT_STARTUP=&Pin drawer open at start-up +SETTINGS_DEFAULT_FONT=&Restore Default +SETTINGS_WORKBENCH_FONT_LABEL= +NAME_DESCRIPTION_SEPARATOR=- +SETTINGS_ICONS_VIEW_LABEL_CAPS=&Icons Only +PINNED=&Pinned +TOOLTIP_PIN_FIGURE=Pin Open +TOOLTIP_UNPIN_FIGURE=Unpin +DOCK_LABEL=&Dock On +LEFT_LABEL=&Left +RIGHT_LABEL=&Right +RESIZE_LABEL=&Resize +PALETTE_SHOW=Show Palette +PALETTE_HIDE=Hide Palette +ACC_DESC_PALETTE_BUTTON=Press to show or hide the palette +ACC_DESC_PALETTE_TITLE=Use the context menu to move or resize the Palette diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/package.html b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/package.html new file mode 100644 index 0000000..ef6f058 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/palette/package.html @@ -0,0 +1,21 @@ + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/parts/PaletteViewerKeyHandler.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/parts/PaletteViewerKeyHandler.java new file mode 100644 index 0000000..b7c0ca7 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/parts/PaletteViewerKeyHandler.java @@ -0,0 +1,335 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.parts; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyEvent; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.DrawerEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.GroupEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.IPaletteStackEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.PaletteStackEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.PinnablePaletteStackEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.TemplateEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.ToolEntryEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteStack; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewer; + + +/** + * KeyHandler for the {@link org.eclipse.gef.ui.palette.PaletteViewer Palette}. Handles selection + * traversal of Palette entries and collapse/expand of categories. + */ +public class PaletteViewerKeyHandler extends GraphicalViewerKeyHandler { + + /** + * Constructs a key handler for the specified palette viewer. + * + * @param viewer + * the palette viewer + */ + public PaletteViewerKeyHandler(PaletteViewer viewer) { + super(viewer); + } + + private boolean acceptCollapseDrawer(KeyEvent event) { + boolean result = isViewerMirrored() ? event.keyCode == SWT.ARROW_RIGHT + : event.keyCode == SWT.ARROW_LEFT; + return result && isExpandedDrawer(getFocusEditPart()); + } + + private boolean acceptExpandDrawer(KeyEvent event) { + boolean result = isViewerMirrored() ? event.keyCode == SWT.ARROW_LEFT + : event.keyCode == SWT.ARROW_RIGHT; + return result && isCollapsedDrawer(getFocusEditPart()); + } + + private boolean acceptIntoExpandedDrawer(KeyEvent event) { + boolean result = event.keyCode == SWT.ARROW_DOWN; + result = result + || (isViewerMirrored() ? event.keyCode == SWT.ARROW_LEFT + : event.keyCode == SWT.ARROW_RIGHT); + return result && isExpandedDrawer(getFocusEditPart()); + } + + private boolean acceptExpandStack(KeyEvent event) { + return event.keyCode == SWT.ARROW_DOWN + && (event.stateMask & SWT.ALT) > 0 + && isCollapsedStack(getFocusEditPart()); + } + + private boolean acceptCollapseStack(KeyEvent event) { + return event.keyCode == SWT.ARROW_UP && (event.stateMask & SWT.ALT) > 0 + && isExpandedStack(getFocusEditPart()); + } + + private boolean acceptSetFocusOnDrawer(KeyEvent event) { + boolean result = isViewerMirrored() ? event.keyCode == SWT.ARROW_RIGHT + : event.keyCode == SWT.ARROW_LEFT; + return (result || event.keyCode == SWT.ARROW_UP) + && (getFocusEditPart().getParent() instanceof DrawerEditPart || (getFocusEditPart() + .getParent() instanceof IPaletteStackEditPart && getFocusEditPart() + .getParent().getParent() instanceof DrawerEditPart)); + } + + private boolean acceptNextContainer(KeyEvent event) { + return event.keyCode == SWT.ARROW_DOWN; + } + + private void buildNavigationList(EditPart palettePart, EditPart exclusion, + ArrayList navList, EditPart stackPart) { + if (palettePart != exclusion) { + if (isCollapsedDrawer(palettePart)) { + navList.add(palettePart); + return; + } else if (stackPart instanceof PaletteStackEditPart + && stackPart.getChildren().contains(palettePart)) { + // we only want to add the top level item to the navlist + if (((PaletteStack) stackPart.getModel()).getActiveEntry() + .equals(palettePart.getModel())) + navList.add(palettePart); + } else if (stackPart instanceof PinnablePaletteStackEditPart + && stackPart.getChildren().contains(palettePart)) { + // we only want to add the top level item to the navlist unless + // the palette stack is expanded + if (((PinnablePaletteStackEditPart) stackPart).isExpanded() + || ((PaletteStack) stackPart.getModel()) + .getActiveEntry() + .equals(palettePart.getModel())) { + navList.add(palettePart); + } + } else if ((palettePart instanceof ToolEntryEditPart + || palettePart instanceof DrawerEditPart || palettePart instanceof TemplateEditPart)) { + navList.add(palettePart); + } + } + + List children = palettePart.getChildren(); + for (int k = 0; k < children.size(); k++) { + EditPart ep = (EditPart) children.get(k); + if (ep instanceof IPaletteStackEditPart) + stackPart = ep; + buildNavigationList(ep, exclusion, navList, stackPart); + } + } + + private void collapseDrawer() { + DrawerEditPart drawer = (DrawerEditPart) getFocusEditPart(); + drawer.setExpanded(false); + } + + private void expandDrawer() { + DrawerEditPart drawer = (DrawerEditPart) getFocusEditPart(); + drawer.setExpanded(true); + } + + /** + * Figures' navigation points are used to determine their direction compared to one another, and + * the distance between them. + * + * @param figure + * the figure whose navigation point is to be returned + * @return the top-left of the given figure + */ + protected Point getNavigationPoint(IFigure figure) { + return figure.getBounds().getTopLeft(); + } + + /** + * @return a list of {@link org.eclipse.gef.EditPart EditParts} that can be traversed to from + * the current {@link GraphicalViewerKeyHandler#getFocusEditPart() focus part} + */ + protected List getNavigationSiblings() { + ArrayList siblingsList = new ArrayList(); + EditPart focusPart = getFocusEditPart(); + EditPart parent = focusPart.getParent(); + if (parent == null) { + siblingsList.add(focusPart); + return siblingsList; + } + if (parent instanceof GroupEditPart + || parent instanceof IPaletteStackEditPart) { + EditPart grandParent = parent.getParent(); + buildNavigationList(grandParent, grandParent, siblingsList, + grandParent); + } else + buildNavigationList(parent, parent, siblingsList, parent); + return siblingsList; + } + + /** + * Returns true if the passed Editpart is a collapsed + * {@link org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.DrawerEditPart + * Drawer}, false otherwise. + */ + boolean isCollapsedDrawer(EditPart part) { + return part instanceof DrawerEditPart + && !((DrawerEditPart) part).isExpanded(); + } + + /** + * Returns true if the passed Editpart is an expanded + * {@link org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.DrawerEditPart + * Drawer}, false otherwise. + */ + boolean isExpandedDrawer(EditPart part) { + return part instanceof DrawerEditPart + && ((DrawerEditPart) part).isExpanded(); + } + + /** + * Returns true if the passed focusPart is a collapsed pinnable palette stack, + * false otherwise. + */ + boolean isCollapsedStack(EditPart focusPart) { + EditPart parent = focusPart.getParent(); + return parent instanceof PaletteStackEditPart + || (parent instanceof PinnablePaletteStackEditPart && !((PinnablePaletteStackEditPart) parent) + .isExpanded()); + } + + /** + * Returns true if the passed focusPart is an expanded pinnable palette stack, + * false otherwise. + */ + boolean isExpandedStack(EditPart focusPart) { + EditPart parent = focusPart.getParent(); + return parent instanceof PaletteStackEditPart + || (parent instanceof PinnablePaletteStackEditPart && ((PinnablePaletteStackEditPart) parent) + .isExpanded()); + } + + /** + * Extends keyPressed to look for palette navigation keys. + * + * @see org.eclipse.gef.KeyHandler#keyPressed(org.eclipse.swt.events.KeyEvent) + */ + public boolean keyPressed(KeyEvent event) { + + if (acceptExpandDrawer(event)) { + expandDrawer(); + return true; + } + if (acceptCollapseDrawer(event)) { + collapseDrawer(); + return true; + } + if (acceptExpandStack(event)) { + expandStack(); + return true; + } + if (acceptCollapseStack(event)) { + collapseStack(event); + return true; + } + if (acceptIntoExpandedDrawer(event)) { + if (navigateIntoExpandedDrawer(event)) + return true; + } + if (super.keyPressed(event)) + return true; + if (acceptSetFocusOnDrawer(event)) { + if (navigateToDrawer(event)) + return true; + } + if (acceptNextContainer(event)) { + if (navigateToNextContainer(event)) + return true; + } + return false; + } + + private boolean navigateIntoExpandedDrawer(KeyEvent event) { + ArrayList potentials = new ArrayList(); + EditPart focusPart = getFocusEditPart(); + buildNavigationList(focusPart, focusPart, potentials, focusPart); + if (!potentials.isEmpty()) { + navigateTo((EditPart) potentials.get(0), event); + return true; + } + return false; + } + + /** + * @see GraphicalViewerKeyHandler#navigateTo(EditPart, KeyEvent) + */ + protected void navigateTo(EditPart part, KeyEvent event) { + if (part == null) + return; + if (part instanceof IPaletteStackEditPart) { + PaletteEntry activeEntry = ((PaletteStack) part.getModel()) + .getActiveEntry(); + part = (EditPart) getViewer().getEditPartRegistry() + .get(activeEntry); + } + getViewer().select(part); + getViewer().reveal(part); + } + + private boolean navigateToDrawer(KeyEvent event) { + boolean found = false; + EditPart parent = getFocusEditPart().getParent(); + while (parent != null && !found) { + if (parent instanceof DrawerEditPart) { + navigateTo(parent, event); + found = true; + } + parent = parent.getParent(); + } + return false; + } + + private boolean navigateToNextContainer(KeyEvent event) { + EditPart current = getFocusEditPart(); + while (current != null) { + if (current instanceof DrawerEditPart + || current instanceof GroupEditPart) { + List siblings = current.getParent().getChildren(); + int index = siblings.indexOf(current); + if (index != -1 && siblings.size() > index + 1) { + EditPart part = (EditPart) siblings.get(index + 1); + if (part instanceof GroupEditPart + && part.getChildren().size() > 0) { + EditPart child = (EditPart) part.getChildren().get(0); + navigateTo(child, event); + } else + navigateTo(part, event); + return true; + } + return false; + } + current = current.getParent(); + } + return false; + } + + private void expandStack() { + ((IPaletteStackEditPart) getFocusEditPart().getParent()).openMenu(); + } + + private void collapseStack(KeyEvent event) { + ((PinnablePaletteStackEditPart) getFocusEditPart().getParent()) + .setExpanded(false); + navigateTo(getFocusEditPart().getParent(), event); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/parts/package.html b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/parts/package.html new file mode 100644 index 0000000..ef6f058 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/parts/package.html @@ -0,0 +1,21 @@ + + + + + + + + + + + + + diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/views/palette/PalettePage.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/views/palette/PalettePage.java new file mode 100644 index 0000000..35d2720 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/views/palette/PalettePage.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2003, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.views.palette; + +import org.eclipse.ui.part.IPageBookViewPage; + + +/** + * An interface representing a page to be used in the PaletteView. PalettePage.class is passed as + * the argument to the getAdapter(Object) method of a GEF-based editor (or view) to retrieve the + * page to be displayed in the PaletteView. + * + * @author Pratik Shah + * @since 3.0 + */ +public interface PalettePage extends IPageBookViewPage { +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/views/palette/PaletteView.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/views/palette/PaletteView.java new file mode 100644 index 0000000..dc157ef --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/views/palette/PaletteView.java @@ -0,0 +1,153 @@ +/******************************************************************************* + * Copyright (c) 2003, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.views.palette; + +import org.eclipse.gef.internal.GEFMessages; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IPerspectiveDescriptor; +import org.eclipse.ui.IPerspectiveListener; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.part.IPage; +import org.eclipse.ui.part.IPageBookViewPage; +import org.eclipse.ui.part.MessagePage; +import org.eclipse.ui.part.PageBook; +import org.eclipse.ui.part.PageBookView; + + +/** + * The GEF palette view + * + * @author Pratik Shah + * @since 3.0 + */ +public class PaletteView extends PageBookView { + + private boolean viewInPage = true; + + /** + * The ID for this view. This is the same as the String used to register this view with the + * platform's extension point. + */ + public static final String ID = "org.eclipse.gef.ui.palette_view"; //$NON-NLS-1$ + // public static final String ID = + // "org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette_view"; //$NON-NLS-1$ + + private IPerspectiveListener perspectiveListener = new IPerspectiveListener() { + public void perspectiveChanged(IWorkbenchPage page, + IPerspectiveDescriptor perspective, String changeId) { + } + + // fix for bug 109245 and 69098 - fake a partActivated when the + // perpsective is switched + public void perspectiveActivated(IWorkbenchPage page, + IPerspectiveDescriptor perspective) { + viewInPage = page.findViewReference(ID) != null; + // getBootstrapPart could return null; but isImportant() can handle + // null + partActivated(getBootstrapPart()); + } + }; + + /** + * Creates a default page saying that a palette is not available. + * + * @see org.eclipse.ui.part.PageBookView#createDefaultPage(org.eclipse.ui.part.PageBook) + */ + protected IPage createDefaultPage(PageBook book) { + MessagePage page = new MessagePage(); + initPage(page); + page.createControl(book); + page.setMessage(GEFMessages.Palette_Not_Available); + return page; + } + + /** + * Add a perspective listener so the palette view can be updated when the perspective is + * switched. + * + * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) + */ + public void createPartControl(Composite parent) { + super.createPartControl(parent); + getSite().getPage().getWorkbenchWindow() + .addPerspectiveListener(perspectiveListener); + } + + /** + * Remove the perspective listener. + * + * @see org.eclipse.ui.IWorkbenchPart#dispose() + */ + public void dispose() { + getSite().getPage().getWorkbenchWindow() + .removePerspectiveListener(perspectiveListener); + super.dispose(); + } + + /** + * @see org.eclipse.ui.part.PageBookView#doCreatePage(org.eclipse.ui.IWorkbenchPart) + */ + protected PageRec doCreatePage(IWorkbenchPart part) { + // Try to get a custom palette page + Object obj = part.getAdapter(PalettePage.class); + + if (obj != null && obj instanceof IPage) { + IPage page = (IPage) obj; + page.createControl(getPageBook()); + initPage((IPageBookViewPage) page); + return new PageRec(part, page); + } + // Use the default page by returning null + return null; + } + + /** + * @see PageBookView#doDestroyPage(org.eclipse.ui.IWorkbenchPart, + * org.eclipse.ui.part.PageBookView.PageRec) + */ + protected void doDestroyPage(IWorkbenchPart part, PageRec rec) { + rec.page.dispose(); + } + + /** + * The view shows the palette associated with the active editor. + * + * @see PageBookView#getBootstrapPart() + */ + protected IWorkbenchPart getBootstrapPart() { + IWorkbenchPage page = getSite().getPage(); + if (page != null) + return page.getActiveEditor(); + return null; + } + + /** + * Only editors in the same perspective as the view are important. + * + * @see PageBookView#isImportant(org.eclipse.ui.IWorkbenchPart) + */ + protected boolean isImportant(IWorkbenchPart part) { + // Workaround for Bug# 69098 -- This should be removed when/if Bug# + // 70510 is fixed + // We only want a palette page to be created when this view is visible + // in the current + // perspective, i.e., when both this view and the given editor are on + // the same page. + return viewInPage && part instanceof IEditorPart; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/views/palette/PaletteViewerPage.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/views/palette/PaletteViewerPage.java new file mode 100644 index 0000000..f29a9bc --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/internal/gef/ui/views/palette/PaletteViewerPage.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * Copyright (c) 2004, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * 1. Internalization of Code in Tizen SDK + * - update package name + *******************************************************************************/ + + +package org.tizen.efluibuilder.ui.editor.internal.gef.ui.views.palette; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.draw2d.IFigure; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.part.Page; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewer; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewerProvider; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.TizenEditDomain; + + +/** + * The default page for the PaletteView that works in conjunction with a PaletteViewerProvider. + * + * @author Pratik Shah + * @since 3.0 + */ +public class PaletteViewerPage extends Page implements PalettePage, IAdaptable { + + /** + * The PaletteViewerProvider that is used to create the PaletteViewer + */ + protected PaletteViewerProvider provider; + + /** + * The PaletteViewer created for this page + */ + protected PaletteViewer viewer; + + /** + * Constructor + * + * @param pvProvider + * the provider used to create the palette viewer + */ + public PaletteViewerPage(PaletteViewerProvider pvProvider) { + Assert.isNotNull(pvProvider); + provider = pvProvider; + } + + /** + * Creates the palette viewer and its control. + * + * @see Page#createControl(org.eclipse.swt.widgets.Composite) + */ + public void createControl(Composite parent) { + viewer = provider.createPaletteViewer(parent); + } + + /** + * Releases the palette viewer from the edit domain + * + * @see Page#dispose() + */ + public void dispose() { + TizenEditDomain tizenEditDomain = null; + if (!(provider.getEditDomain() instanceof TizenEditDomain)) { + return; + } + tizenEditDomain = (TizenEditDomain) provider.getEditDomain(); + + if (tizenEditDomain.getTizenPaletteViewer() == viewer) + provider.getEditDomain().setPaletteViewer(null); + super.dispose(); + viewer = null; + } + + /** + * @see IAdaptable#getAdapter(java.lang.Class) + */ + public Object getAdapter(Class adapter) { + if (adapter == EditPart.class && viewer != null) + return viewer.getEditPartRegistry().get(viewer.getPaletteRoot()); + if (adapter == IFigure.class && viewer != null) { + Object obj = viewer.getEditPartRegistry().get( + viewer.getPaletteRoot()); + if (obj instanceof GraphicalEditPart) + return ((GraphicalEditPart) obj).getFigure(); + } + return null; + } + + /** + * @return the palette viewer's control + * @see Page#getControl() + */ + public Control getControl() { + return viewer.getControl(); + } + + /** + * Sets focus on the palette's control + * + * @see Page#setFocus() + */ + public void setFocus() { + getControl().setFocus(); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/palette/ContextMenu.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/palette/ContextMenu.java new file mode 100644 index 0000000..70d5ec4 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/palette/ContextMenu.java @@ -0,0 +1,100 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.palette; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.ui.actions.GEFActionConstants; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.ui.actions.ActionFactory; +import org.tizen.common.util.Assert; +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.ui.editor.Messages; +import org.tizen.efluibuilder.ui.editor.action.DeleteSnippetAction; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.CombinedTemplateCreationEntry; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteDrawer; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.LayoutAction; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteContextMenuProvider; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewer; + + +public final class ContextMenu extends PaletteContextMenuProvider { + public static final String PALETTE_ENTRY = "Palette Entry"; //$NON-NLS-1$ + public static final String PALETTE_ENTRY2 = PALETTE_ENTRY + BuilderConstants.SPACE + BuilderConstants.OPEN_BRACKET; + + public ContextMenu(PaletteViewer palette) { + super(palette); + } + + private EditPart getSelectedEditPart() { + // Design Editor Palette has only single selection + EditPart editPart = (EditPart) getPaletteViewer().getSelectedEditParts().get(0); + return editPart; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.gef.ui.palette.PaletteContextMenuProvider#buildContextMenu + * (org.eclipse.jface.action.IMenuManager) + */ + @Override + public void buildContextMenu(IMenuManager menu) { + GEFActionConstants.addStandardActionGroups(menu); + EditPart editPart = getSelectedEditPart(); + Object model = editPart.getModel(); + Assert.notNull(model); + + PaletteViewer paletteViewer = getPaletteViewer(); + // Layout + menu.appendToGroup(GEFActionConstants.GROUP_VIEW, new LayoutAction(paletteViewer.getPaletteViewerPreferences())); + + /* + * if (model instanceof PaletteDrawer) { // group menu // Pined // IPinnableEditPart + * pinnablePart = editPart.getAdapter(IPinnableEditPart.class); // + * Assert.notNull(pinnablePart); // Assert.isTrue(pinnablePart.canBePinned()); + * + * // menu.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, new // + * PinDrawerAction(pinnablePart)); // disabled PinDraweraction + * + * // ImportSnippetAction importAction = new ImportSnippetAction(appManager); // + * ExportSnippetAction exportAction = new ExportSnippetAction(); // + * menu.appendToGroup(GEFActionConstants.GROUP_REST, importAction); // + * menu.appendToGroup(GEFActionConstants.GROUP_REST, exportAction); } else + */ + if (model instanceof CombinedTemplateCreationEntry) { // entry menu + EditPart parentEditPart = editPart.getParent(); + Object parentModel = parentEditPart.getModel(); + Assert.isTrue(parentModel instanceof PaletteDrawer); + PaletteDrawer paletteDrawer = (PaletteDrawer) parentModel; + if (paletteDrawer.getDescription().equals(Messages.PALETTE_GROUP_SNIPPET)) { + DeleteSnippetAction deleteAction = new DeleteSnippetAction(paletteViewer); + deleteAction.setId(ActionFactory.DELETE.getId()); + deleteAction.setText(Messages.ACTION_DELETE_SNIPPET); + deleteAction.update(); + menu.appendToGroup(GEFActionConstants.GROUP_REST, deleteAction); + } + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/palette/DesignEditorPaletteViewer.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/palette/DesignEditorPaletteViewer.java new file mode 100644 index 0000000..3a3b921 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/palette/DesignEditorPaletteViewer.java @@ -0,0 +1,87 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.palette; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.widgets.Control; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewer; + + +public final class DesignEditorPaletteViewer extends PaletteViewer { + + private KeyAdapter keyAdaptor = null; + + public DesignEditorPaletteViewer() { + super(); + } + + @Override + public void setControl(Control control) { + removeKeyEventListener(); + super.setControl(control); + if (control != null) { + addKeyEventListener(); + } + } + + @Override + protected void createDefaultRoot() { + setRootEditPart(new PaletteRootEditPart()); + } + + private void addKeyEventListener() { + if (getControl() != null) { + this.keyAdaptor = new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if (e.keyCode == SWT.ESC) { + setActiveTool(getPaletteRoot().getDefaultEntry()); + } + } + }; + getControl().addKeyListener(keyAdaptor); + } + } + + private void removeKeyEventListener() { + if (this.keyAdaptor != null && this.getControl() != null) { + this.getControl().removeKeyListener(keyAdaptor); + this.keyAdaptor = null; + } + } + + @Override + protected void handleDispose(DisposeEvent event) { + super.handleDispose(event); + removeKeyEventListener(); + } + + public void setEnabled(boolean enabled) { + ((PaletteRootEditPart) getRootEditPart()).setEnabled(enabled); + getControl().setEnabled(enabled); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/palette/DesignEditorPaletteViewerProvider.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/palette/DesignEditorPaletteViewerProvider.java new file mode 100644 index 0000000..cc7f848 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/palette/DesignEditorPaletteViewerProvider.java @@ -0,0 +1,66 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.palette; + +import org.eclipse.gef.EditDomain; +import org.eclipse.swt.widgets.Composite; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewer; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewerProvider; + + +public final class DesignEditorPaletteViewerProvider extends PaletteViewerProvider { + + public DesignEditorPaletteViewerProvider(EditDomain domain) { + super(domain); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.gef.ui.palette.PaletteViewerProvider#createPaletteViewer(org.eclipse.swt.widgets + * .Composite) + */ + public PaletteViewer createPaletteViewer(Composite parent) { + PaletteViewer pViewer = new DesignEditorPaletteViewer(); // advux start + pViewer.createControl(parent); + configurePaletteViewer(pViewer); + hookPaletteViewer(pViewer); + return pViewer; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.gef.ui.palette.PaletteViewerProvider#configurePaletteViewer(org.eclipse.gef.ui + * .palette.PaletteViewer) + */ + @Override + protected void configurePaletteViewer(PaletteViewer viewer) { + viewer.setContextMenu(new ContextMenu(viewer)); + viewer.setKeyHandler(new KeyHandler(viewer)); + viewer.addDragSourceListener(new PaletteTemplateTransferDragSourceListener(viewer)); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/palette/KeyHandler.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/palette/KeyHandler.java new file mode 100644 index 0000000..9bd99b6 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/palette/KeyHandler.java @@ -0,0 +1,74 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.palette; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyEvent; +import org.tizen.efluibuilder.ui.editor.action.AbstractPaletteAction; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.palette.PaletteViewer; +import org.tizen.efluibuilder.ui.editor.internal.gef.ui.parts.PaletteViewerKeyHandler; + + +public final class KeyHandler extends PaletteViewerKeyHandler { + public KeyHandler(PaletteViewer viewer) { + super(viewer); + } + + /* + * (non-Javadoc) + * + * @see + * + * org.eclipse.gef.ui.parts.PaletteViewerKeyHandler#keyPressed(org.eclipse.swt.events.KeyEvent) + */ + public boolean keyReleased(KeyEvent event) { + if (acceptDelete(event)) { + delete(); + return true; + } + + return super.keyReleased(event); + } + + protected void perform(AbstractPaletteAction action) { + action.update(); + if (!action.isEnabled()) { + return; + } + action.run(); + return; + } + + private void delete() { + // GraphicalViewer viewer = getViewer(); + // Assert.isTrue(viewer instanceof PaletteViewer); + // PaletteViewer paletteViewer = (PaletteViewer) viewer; + // DeleteSnippetAction action = new DeleteSnippetAction(paletteViewer); + // perform(action); + } + + private boolean acceptDelete(KeyEvent event) { + return (event.character == SWT.DEL); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/palette/PaletteConstants.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/palette/PaletteConstants.java new file mode 100644 index 0000000..e29ffe7 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/palette/PaletteConstants.java @@ -0,0 +1,87 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.palette; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.tizen.efluibuilder.BuilderPlugin; +import org.tizen.efluibuilder.ui.resources.ImageResources; + + +/** + * A OutlinePage constants + */ +public final class PaletteConstants { + // dependency on + // "org.tizen.efluibuilder.descriptor/res/$profile-$version/tizen.uicomponent.categories.xml" + public static final String CATEGORY_NAME_UI_VIEWS = "Views"; //$NON-NLS-1$ + public static final String CATEGORY_NAME_UI_CONTAINERS = "UI containers"; //$NON-NLS-1$ + public static final String CATEGORY_NAME_UI_COMPONENTS = "UI components"; //$NON-NLS-1$ + public static final String CATEGORY_NAME_UI_SNIPPETS = "Snippets"; //$NON-NLS-1$ + + public enum CATEGORY_ICON { + UI_VIEW(ImageResources.PALETTE_CATEGORY_ICON_UI_VIEW, ImageResources.PALETTE_CATEGORY_ICON_UI_VIEW_SELECTED, + CATEGORY_NAME_UI_VIEWS), + UI_CONTAINER(ImageResources.PALETTE_CATEGORY_ICON_UI_CONTAINER, ImageResources.PALETTE_CATEGORY_ICON_UI_CONTAINER_SELECTED, + CATEGORY_NAME_UI_CONTAINERS), + UI_COMPONENT(ImageResources.PALETTE_CATEGORY_ICON_UI_COMPONENT, + ImageResources.PALETTE_CATEGORY_ICON_UI_COMPONENT_SELECTED, + CATEGORY_NAME_UI_COMPONENTS), + UI_SNIPPET(ImageResources.PALETTE_CATEGORY_ICON_UI_SNIPPET, + ImageResources.PALETTE_CATEGORY_ICON_UI_SNIPPET_SELECTED, CATEGORY_NAME_UI_SNIPPETS); + + private final ImageDescriptor cache; + private final String category; + + CATEGORY_ICON(String path, String selectedImagePath, String category) { + this.cache = AbstractUIPlugin.imageDescriptorFromPlugin(BuilderPlugin.PLUGIN_ID, path); + AbstractUIPlugin.imageDescriptorFromPlugin(BuilderPlugin.PLUGIN_ID, selectedImagePath); + this.category = category; + } + + public ImageDescriptor getImageDescriptor(boolean isSelected) { + return this.cache; + } + + public String getCategoryName() { + return this.category; + } + + public static CATEGORY_ICON get(String category) { + for (CATEGORY_ICON ui : CATEGORY_ICON.values()) { + if (ui.getCategoryName().equals(category)) { + return ui; + } + } + + return null; + } + /* + * caller: CATEGORY_ICON_UI.UI_COMPONENT.getImageDescriptor() + */ + + } + + public static final ImageDescriptor imgDescTitle = AbstractUIPlugin.imageDescriptorFromPlugin(BuilderPlugin.PLUGIN_ID, ImageResources.PALETTE_TITLE_ICON); +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/palette/PaletteRootEditPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/palette/PaletteRootEditPart.java new file mode 100644 index 0000000..3812c3a --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/palette/PaletteRootEditPart.java @@ -0,0 +1,57 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.palette; + +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.Figure; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.StackLayout; +import org.eclipse.gef.editparts.SimpleRootEditPart; + + +public class PaletteRootEditPart extends SimpleRootEditPart { + private boolean enabled = true; + + @Override + public IFigure createFigure() { + IFigure figure = new Figure() { + @Override + public void paintBorder(Graphics graphics) { + if (!enabled) { + graphics.setAlpha(90); + graphics.setBackgroundColor(ColorConstants.white); + graphics.fillRectangle(this.getClientArea()); + } + } + }; + figure.setLayoutManager(new StackLayout()); + return figure; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + getFigure().repaint(); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/palette/PaletteTemplateTransferDragSourceListener.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/palette/PaletteTemplateTransferDragSourceListener.java new file mode 100644 index 0000000..54e7481 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/palette/PaletteTemplateTransferDragSourceListener.java @@ -0,0 +1,86 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.palette; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPartViewer; +import org.eclipse.gef.dnd.AbstractTransferDragSourceListener; +import org.eclipse.gef.dnd.TemplateTransfer; +import org.eclipse.swt.dnd.DragSourceEvent; +import org.tizen.efluibuilder.ui.editor.internal.gef.dnd.TemplateTransferDragSourceListener; +import org.tizen.efluibuilder.ui.editor.internal.gef.internal.ui.palette.editparts.ToolEntryEditPart; +import org.tizen.efluibuilder.ui.editor.internal.gef.palette.PaletteTemplateEntry; + + +public class PaletteTemplateTransferDragSourceListener extends + TemplateTransferDragSourceListener { + + /** + * Constructs a new listener for the specified EditPartViewer. The provided Viewer should be one + * that is displaying a Palette. The TemplateTransferDragSourceListener will only be enabled + * when a single EditPart is selected, and the EditPart's model is a + * {@link PaletteTemplateEntry}. + * + * @param viewer + * the EditPartViewer that is the drag source + */ + public PaletteTemplateTransferDragSourceListener(EditPartViewer viewer) { + super(viewer, TemplateTransfer.getInstance()); + } + + /** + * Cancels the drag if the selected item does not represent a PaletteTemplateEntry. + * + * @see org.eclipse.swt.dnd.DragSourceListener#dragStart(DragSourceEvent) + */ + public void dragStart(DragSourceEvent event) { + Object template = getTemplate(); + if (template == null) { + event.doit = false; + } else { + EditPart editpart = (EditPart) getViewer().getSelectedEditParts().get(0); + if (editpart instanceof ToolEntryEditPart) { + ToolEntryEditPart toolEntryEditpart = (ToolEntryEditPart) editpart; + toolEntryEditpart.setSelected(EditPart.SELECTED_PRIMARY); + event.image = toolEntryEditpart.getCachedImage(); + } + } + TemplateTransfer.getInstance().setTemplate(template); + } + + /** + * @see AbstractTransferDragSourceListener#dragFinished(DragSourceEvent) + */ + @Override + public void dragFinished(DragSourceEvent event) { + EditPart editpart = (EditPart) getViewer().getSelectedEditParts().get(0); + if (editpart instanceof ToolEntryEditPart) { + ToolEntryEditPart toolEntryEditpart = (ToolEntryEditPart) editpart; + toolEntryEditpart.setSelected(EditPart.SELECTED_NONE); + toolEntryEditpart.setFocus(false); + } + event.image = null; + super.dragFinished(event); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/palette/internal/ArrowButton.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/palette/internal/ArrowButton.java new file mode 100644 index 0000000..286844c --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/palette/internal/ArrowButton.java @@ -0,0 +1,98 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.palette.internal; + +import org.eclipse.draw2d.Figure; +import org.eclipse.draw2d.ImageFigure; +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.draw2d.StackLayout; +import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.swt.graphics.Image; +import org.tizen.efluibuilder.ui.resources.ImageResources; + + +public class ArrowButton extends Figure { + + public static final int TRIANGLE_SIZE = 11; + private static final Dimension ARROW_SIZE = new Dimension(TRIANGLE_SIZE, TRIANGLE_SIZE); + + public static final int DIRECTION_EXPANDED = PositionConstants.SOUTH; + public static final int DIRECTION_COLLAPSED = PositionConstants.EAST; + + public static final int DIRECTION_DOWN = DIRECTION_EXPANDED; // for scrollbar + public static final int DIRECTION_UP = DIRECTION_COLLAPSED; // for scrollbar + + private Image imgExpanded = null; + private Image imgcollapsed = null; + + private ImageFigure triangle; + + /** + * Creates a new instance + * + * @param direction + * the direction the arrow should face (PositionConstants.RIGHT or + * PositionConstants.LEFT) + */ + public ArrowButton(int direction) { + super(); + + imgExpanded = ImageResources.getImage(ImageResources.PALETTE_ICON_FILE_ARROW_DOWN); + imgcollapsed = ImageResources.getImage(ImageResources.PALETTE_ICON_FILE_ARROW_UP); + + triangle = new ImageFigure(); + setDirection(direction); + + setLayoutManager(new StackLayout()); + add(triangle); + } + + public void dispose() { + if (triangle != null) { + this.remove(triangle); + triangle = null; + } + } + + public void setDirection(int direction) { + if (triangle != null) { + if (direction == DIRECTION_EXPANDED) { + triangle.setImage(imgExpanded); + } else { + triangle.setImage(imgcollapsed); + } + } + } + + protected void layout() { + Rectangle clientArea = getBounds(); + + triangle.setBounds(new Rectangle(clientArea.getCenter().getTranslated(-ARROW_SIZE.width / 2, -ARROW_SIZE.height / 2), ARROW_SIZE)); + } + + public void setLayout() { + this.layout(); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/DesignEditorRulerEditPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/DesignEditorRulerEditPart.java new file mode 100644 index 0000000..9753a47 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/DesignEditorRulerEditPart.java @@ -0,0 +1,44 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.ruler; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.gef.internal.ui.rulers.RulerEditPart; + + +public class DesignEditorRulerEditPart extends RulerEditPart { + + public DesignEditorRulerEditPart(Object model) { + super(model); + } + + @Override + protected IFigure createFigure() { + DesignEditorRulerFigure ruler = new DesignEditorRulerFigure(isHorizontal(), getRulerProvider().getUnit()); + if (ruler.getUnit() == 2) + ruler.setInterval(100, 2); + return ruler; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/DesignEditorRulerEditPartFactory.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/DesignEditorRulerEditPartFactory.java new file mode 100644 index 0000000..e080844 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/DesignEditorRulerEditPartFactory.java @@ -0,0 +1,42 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.ruler; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.GraphicalViewer; +import org.eclipse.gef.internal.ui.rulers.RulerEditPartFactory; + + +public class DesignEditorRulerEditPartFactory extends RulerEditPartFactory { + + public DesignEditorRulerEditPartFactory(GraphicalViewer primaryViewer) { + super(primaryViewer); + } + + @Override + protected EditPart createRulerEditPart(EditPart parentEditPart, Object model) { + return new DesignEditorRulerEditPart(model); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/DesignEditorRulerFigure.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/DesignEditorRulerFigure.java new file mode 100644 index 0000000..c4b9072 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/DesignEditorRulerFigure.java @@ -0,0 +1,284 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.ruler; + +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.FigureUtilities; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.ImageUtilities; +import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.internal.ui.rulers.RulerFigure; +import org.eclipse.gef.rulers.RulerProvider; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.RGB; +import org.tizen.common.util.cache.ColorCache; + + +public class DesignEditorRulerFigure extends RulerFigure { + + public static final RGB COLOR_RULER = new RGB(0xc0, 0xc0, 0xc0); + + // for paintFigure() + private static final int BORDER_WIDTH = 3; + private int interval, divisions; + + public DesignEditorRulerFigure(boolean isHorizontal, int measurementUnit) { + super(isHorizontal, measurementUnit); + + setForegroundColor(ColorCache.getColorFromRGB(COLOR_RULER)); + } + + /* + * This method have some contributions in the original code + */ + @Override + protected void paintFigure(Graphics graphics) { + /* + * @TODO:Pratik maybe you can break this method into a few methods. that might + * make it a little easier to read and understand. plus, sub-classes could customize + * certain parts. + */ + double dotsPerUnit = getDPU(); + Rectangle clip = transposer.t(graphics.getClip(Rectangle.SINGLETON)); + Rectangle figClientArea = transposer.t(getClientArea()); + // Use the x and width of the client area, but the y and height of the clip as the + // bounds of the area which is to be repainted. This will increase performance as the + // entire ruler will not be repainted everytime. + Rectangle clippedBounds = clip; + clippedBounds.x = figClientArea.x; + clippedBounds.width = figClientArea.width - BORDER_WIDTH; + + // Paint the background + if (isOpaque()) { + graphics.fillRectangle(transposer.t(clippedBounds)); + } + + /* + * A major mark is one that goes all the way from the left edge to the right edge of + * a ruler and for which a number is displayed. Determine the minimum number of + * pixels that are to be left between major marks. This will, in turn, help + * determine how many units are to be displayed per major mark. A major mark should + * have at least enough pixels to display the text and its padding. We take into the + * consideration the max of text's width and height so that for horizontal and + * vertical rulers that are of the same height, the number of units per major mark is + * the same. + */ + int unitsPerMajorMark = (int) (minPixelsBetweenMajorMarks / dotsPerUnit); + if (minPixelsBetweenMajorMarks % dotsPerUnit != 0.0) { + unitsPerMajorMark++; + } + if (interval > 0) { + /* + * If the client specified how many units are to be displayed per major mark, use + * that. If, however, showing that many units wouldn't leave enough room for the + * text, than take its smallest multiple that would leave enough room. + */ + int intervalMultiple = interval; + while (intervalMultiple < unitsPerMajorMark) { + intervalMultiple += interval; + } + unitsPerMajorMark = intervalMultiple; + } else if (unitsPerMajorMark != 1 && unitsPerMajorMark % 2 != 0) { + // if the number of units per major mark is calculated dynamically, ensure that + // it is an even number. + unitsPerMajorMark++; + } + + /* + * divsPerMajorMark indicates the number of divisions that a major mark should be + * divided into. for eg., a value of 2 would mean that a major mark would be shown + * as having two parts. that means that there would be a marker showing the beginning + * and end of the major marker and another right in the middle. + */ + int divsPerMajorMark; + if (divisions > 0 + && dotsPerUnit * unitsPerMajorMark / divisions >= minPixelsBetweenMarks) { + /* + * If the client has specified the number of divisions per major mark, use that + * unless it would cause the minimum space between marks to be less than + * minPixelsBetweenMarks + */ + divsPerMajorMark = divisions; + } else { + /* + * If the client hasn't specified the number of divisions per major mark or the + * one that the client has specified is invalid, then calculate it dynamically. + * This algorithm will try to display 10 divisions per CM, and 16 per INCH. + * However, if that puts the marks too close together (i.e., the space between + * them is less than minPixelsBetweenMarks), then it keeps decreasing the number + * of divisions by a factor of 2 until there is enough space between them. + */ + divsPerMajorMark = 2; + if (getUnit() == RulerProvider.UNIT_CENTIMETERS) { + divsPerMajorMark = 10; + } else if (getUnit() == RulerProvider.UNIT_INCHES) { + divsPerMajorMark = 8; + } + while (dotsPerUnit * unitsPerMajorMark / divsPerMajorMark < minPixelsBetweenMarks) { + divsPerMajorMark /= 2; + if (divsPerMajorMark == 0) { + break; + } + } + // This should never happen unless the client has specified a + // minPixelsBetweenMarks that is larger than minPixelsBetweenMajorMarks (which + // is calculated using the text's size -- size of the largest number to be + // displayed). + if (divsPerMajorMark == 0) { + divsPerMajorMark = 1; + } + } + + /* + * mediumMarkerDivNum is used to determine which mark (line drawn to indicate a + * point on the ruler) in a major mark will be of medium size. If its value is 1 then + * every mark will be of medium size. If its value is 5, then every 5th mark will + * be of medium size (the rest being of small size). + */ + int mediumMarkerDivNum = 1; + switch (divsPerMajorMark) { + case 20: + case 10: + case 5: + mediumMarkerDivNum = 5; + break; + case 16: + case 8: + mediumMarkerDivNum = 4; + break; + case 4: + mediumMarkerDivNum = 2; + break; + case 2: + mediumMarkerDivNum = 1; + } + + /* + * dotsPerDivision = number of pixels between each mark = number of pixels in a + * division + */ + double dotsPerDivision = dotsPerUnit * unitsPerMajorMark / divsPerMajorMark; + /* + * startMark is the division/mark from which we are going to start painting. It + * should be the last major mark (one for which a number is displayed) that is before + * the top of the clip rectangle. + */ + int startMark = (int) (clippedBounds.y / (dotsPerUnit * unitsPerMajorMark)) + * divsPerMajorMark; + if (clippedBounds.y < 0) { + // -2 / 10 = 0, not -1. so, if the top of the clip is negative, we need to move + // the startMark back by a whole major mark. + startMark -= divsPerMajorMark; + } + // endMark is the first non-visible mark (doesn't have to be a major mark) that is + // beyond the end of the clip region + int endMark = (int) (((clippedBounds.y + clippedBounds.height) / dotsPerDivision)) + 1; + int leading = FigureUtilities.getFontMetrics(getFont()).getLeading(); + Rectangle forbiddenZone = new Rectangle(); + for (int div = startMark; div <= endMark; div++) { + // y is the vertical position of the mark + int y = (int) (div * dotsPerDivision); + if (div % divsPerMajorMark == 0) { + String num = "" + (div / divsPerMajorMark) * unitsPerMajorMark; //$NON-NLS-1$ + if (isHorizontal()) { + Dimension numSize = FigureUtilities.getStringExtents(num, getFont()); + /* + * If the width is even, we want to increase it by 1. This will ensure + * that when marks are erased because they are too close to the + * number, they are erased from both sides of that number. + */ + if (numSize.width % 2 == 0) + numSize.width++; + Point textLocation = new Point(y - (numSize.width / 2), + clippedBounds.x + textMargin - leading); + forbiddenZone.setLocation(textLocation); + forbiddenZone.setSize(numSize); + forbiddenZone.expand(1, 1); + graphics.fillRectangle(forbiddenZone); + // Uncomment the following line of code if you want to see a line at + // the exact position of the major mark + + // Tizen: Contribute an exact position in text + graphics.drawLine(y, clippedBounds.x, y, clippedBounds.x + 2); + graphics.drawLine(y, clippedBounds.x + clippedBounds.width - 2, y, clippedBounds.x + clippedBounds.width); + + graphics.drawText(num, textLocation); + } else { + Image numImage = ImageUtilities.createRotatedImageOfString(num, getFont(), + getForegroundColor(), getBackgroundColor()); + Point textLocation = new Point(clippedBounds.x + textMargin, + y - (numImage.getBounds().height / 2)); + forbiddenZone.setLocation(textLocation); + forbiddenZone.setSize(numImage.getBounds().width, + numImage.getBounds().height); + forbiddenZone.expand(1, 1 + (numImage.getBounds().height % 2 == 0 ? 1 : 0)); + graphics.fillRectangle(forbiddenZone); + graphics.drawImage(numImage, textLocation); + + // Tizen: Contribute an exact position in text + graphics.drawLine(clippedBounds.x, y, clippedBounds.x + 2, y); + graphics.drawLine(clippedBounds.x + clippedBounds.width - 2, y, clippedBounds.x + clippedBounds.width, y); + + numImage.dispose(); + } + } else if ((div % divsPerMajorMark) % mediumMarkerDivNum == 0) { + // this is a medium mark, so its length should be longer than the small marks + Point start = transposer.t( + new Point((clippedBounds.getRight().x - mediumMarkWidth) / 2, y)); + Point end = transposer.t(new Point(((clippedBounds.getRight().x + - mediumMarkWidth) / 2) + mediumMarkWidth, y)); + if (!forbiddenZone.contains(start)) { + graphics.drawLine(start, end); + } + } else { + // small mark + Point start = transposer.t( + new Point((clippedBounds.getRight().x - smallMarkWidth) / 2, y)); + Point end = transposer.t(new Point(((clippedBounds.getRight().x + - smallMarkWidth) / 2) + smallMarkWidth, y)); + if (!forbiddenZone.contains(start)) { + graphics.drawLine(start, end); + } + } + } + // paint the border + clippedBounds.expand(BORDER_WIDTH, 0); + graphics.setForegroundColor(ColorConstants.buttonDarker); + graphics.drawLine(transposer.t(clippedBounds.getTopRight().translate(-1, -1)), + transposer.t(clippedBounds.getBottomRight().translate(-1, -1))); + } + + /* + * for paintFigure() + */ + @Override + public void setInterval(int unitsPerMajorMark, int divisionsPerMajorMark) { + interval = unitsPerMajorMark; + divisions = divisionsPerMajorMark; + repaint(); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/DesignerGuide.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/DesignerGuide.java new file mode 100644 index 0000000..bcefad1 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/DesignerGuide.java @@ -0,0 +1,216 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.ruler; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.io.Serializable; +import java.util.Hashtable; +import java.util.Map; +import java.util.Set; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.tizen.efluibuilder.model.part.Part; + + +public class DesignerGuide implements Serializable { + + /** + * Property used to notify listeners when the parts attached to a guide are changed + */ + public static final String PROPERTY_CHILDREN = "subparts changed"; + /** + * Property used to notify listeners when the guide is re-positioned + */ + public static final String PROPERTY_POSITION = "position changed"; + + static final long serialVersionUID = 1; + + protected PropertyChangeSupport listeners = new PropertyChangeSupport(this); + private Map map; + private int position; + private boolean horizontal; + + /** + * Empty default constructor + */ + public DesignerGuide() { + // empty constructor + } + + /** + * Constructor + * + * @param isHorizontal + * true if the guide is horizontal (i.e., placed on a vertical ruler) + */ + public DesignerGuide(boolean isHorizontal) { + setHorizontal(isHorizontal); + } + + /** + * @see PropertyChangeSupport#addPropertyChangeListener(java.beans.PropertyChangeListener) + */ + public void addPropertyChangeListener(PropertyChangeListener listener) { + listeners.addPropertyChangeListener(listener); + } + + /* + * @TODO:Pratik use PositionConstants here + */ + /** + * Attaches the given part along the given edge to this guide. The LogicSubpart is also updated + * to reflect this attachment. + * + * @param part + * The part that is to be attached to this guide; if the part is already attached, + * its alignment is updated + * @param alignment + * -1 is left or top; 0, center; 1, right or bottom + */ + public void attachElement(Part element, int alignment) { + if (getMap().containsKey(element) && getAlignment(element) == alignment) + return; + + // getMap().put(element, alignment); + // DesignerGuide parent = isHorizontal() ? element.getHorizontalGuide() + // : element + // .getVerticalGuide(); + // if (parent != null && parent != this) { + // parent.detachElement(element); + // } + // if (isHorizontal()) { + // element.setHorizontalGuide(this); + // } else { + // element.setVerticalGuide(this); + // } + listeners.firePropertyChange(PROPERTY_CHILDREN, null, element); + } + + /** + * Detaches the given part from this guide. The LogicSubpart is also updated to reflect this + * change. + * + * @param part + * the part that is to be detached from this guide + */ + public void detachElement(Part element) { + if (getMap().containsKey(element)) { + // getMap().remove(element); + // if (isHorizontal()) { + // element.setHorizontalGuide(null); + // } else { + // element.setVerticalGuide(null); + // } + listeners.firePropertyChange(PROPERTY_CHILDREN, null, element); + } + } + + /** + * This methods returns the edge along which the given part is attached to this guide. This + * information is used by + * {@link org.eclipse.gef.examples.logicdesigner.edit.LogicXYLayoutEditPolicy + * LogicXYLayoutEditPolicy} to determine whether to attach or detach a part from a guide during + * resize operations. + * + * @param part + * The part whose alignment has to be found + * @return an int representing the edge along which the given part is attached to this guide; 1 + * is bottom or right; 0, center; -1, top or left; -2 if the part is not attached to + * this guide + * @see org.eclipse.gef.examples.logicdesigner.edit.LogicXYLayoutEditPolicy#createChangeConstraintCommand(ChangeBoundsRequest, + * EditPart, Object) + */ + public int getAlignment(Part element) { + if (getMap().get(element) != null) + return ((Integer) getMap().get(element)).intValue(); + return -2; + } + + /** + * @return The Map containing all the parts attached to this guide, and their alignments; the + * keys are LogicSubparts and values are Integers + */ + public Map getMap() { + if (map == null) { + map = new Hashtable(); + } + return map; + } + + /** + * @return the set of all the parts attached to this guide; a set is used because a part can + * only be attached to a guide along one edge. + */ + public Set getParts() { + return getMap().keySet(); + } + + /** + * @return the position/location of the guide (in pixels) + */ + public int getPosition() { + return position; + } + + /** + * @return true if the guide is horizontal (i.e., placed on a vertical ruler) + */ + public boolean isHorizontal() { + return horizontal; + } + + /** + * @see PropertyChangeSupport#removePropertyChangeListener(java.beans.PropertyChangeListener) + */ + public void removePropertyChangeListener(PropertyChangeListener listener) { + listeners.removePropertyChangeListener(listener); + } + + /** + * Sets the orientation of the guide + * + * @param isHorizontal + * true if this guide is to be placed on a vertical ruler + */ + public void setHorizontal(boolean isHorizontal) { + horizontal = isHorizontal; + } + + /** + * Sets the location of the guide + * + * @param offset + * The location of the guide (in pixels) + */ + public void setPosition(int offset) { + if (position != offset) { + int oldValue = position; + position = offset; + listeners.firePropertyChange(PROPERTY_POSITION, Integer.valueOf(oldValue), Integer.valueOf(position)); + } + } + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/DesignerRuler.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/DesignerRuler.java new file mode 100644 index 0000000..edce8c2 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/DesignerRuler.java @@ -0,0 +1,106 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.ruler; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.gef.rulers.RulerProvider; + + +public class DesignerRuler implements Serializable { + + public static final String PROPERTY_CHILDREN = "children changed"; + public static final String PROPERTY_UNIT = "units changed"; + + static final long serialVersionUID = 1; + + protected PropertyChangeSupport listeners = new PropertyChangeSupport(this); + private int unit; + private boolean horizontal; + private List guides = new ArrayList(); + + public DesignerRuler(boolean isHorizontal) { + this(isHorizontal, RulerProvider.UNIT_PIXELS); + } + + public DesignerRuler(boolean isHorizontal, int unit) { + horizontal = isHorizontal; + setUnit(unit); + } + + public void addGuide(DesignerGuide guide) { + if (!guides.contains(guide)) { + guide.setHorizontal(!isHorizontal()); + guides.add(guide); + listeners.firePropertyChange(PROPERTY_CHILDREN, null, guide); + } + } + + public void addPropertyChangeListener(PropertyChangeListener listener) { + listeners.addPropertyChangeListener(listener); + } + + // the returned list should not be modified + public List getGuides() { + return guides; + } + + public int getUnit() { + return unit; + } + + public boolean isHidden() { + return false; + } + + public boolean isHorizontal() { + return horizontal; + } + + public void removeGuide(DesignerGuide guide) { + if (guides.remove(guide)) { + listeners.firePropertyChange(PROPERTY_CHILDREN, null, guide); + } + } + + public void removePropertyChangeListener(PropertyChangeListener listener) { + listeners.removePropertyChangeListener(listener); + } + + public void setHidden(boolean isHidden) { + } + + public void setUnit(int newUnit) { + if (unit != newUnit) { + int oldUnit = unit; + unit = newUnit; + listeners.firePropertyChange(PROPERTY_UNIT, oldUnit, newUnit); + } + } + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/DesignerRulerProvider.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/DesignerRulerProvider.java new file mode 100644 index 0000000..dd2fb4b --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/DesignerRulerProvider.java @@ -0,0 +1,141 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.ruler; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.rulers.RulerChangeListener; +import org.eclipse.gef.rulers.RulerProvider; +import org.tizen.efluibuilder.ui.editor.ruler.commands.CreateGuideCommand; +import org.tizen.efluibuilder.ui.editor.ruler.commands.DeleteGuideCommand; +import org.tizen.efluibuilder.ui.editor.ruler.commands.MoveGuideCommand; + + +public class DesignerRulerProvider extends RulerProvider { + + private DesignerRuler ruler; + private PropertyChangeListener rulerListener = new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getPropertyName().equals(DesignerRuler.PROPERTY_CHILDREN)) { + DesignerGuide guide = (DesignerGuide) evt.getNewValue(); + if (getGuides().contains(guide)) { + guide.addPropertyChangeListener(guideListener); + } else { + guide.removePropertyChangeListener(guideListener); + } + for (int i = 0; i < listeners.size(); i++) { + ((RulerChangeListener) listeners.get(i)).notifyGuideReparented(guide); + } + } else { + for (int i = 0; i < listeners.size(); i++) { + ((RulerChangeListener) listeners.get(i)).notifyUnitsChanged(ruler.getUnit()); + } + } + } + }; + private PropertyChangeListener guideListener = new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getPropertyName().equals(DesignerGuide.PROPERTY_CHILDREN)) { + for (int i = 0; i < listeners.size(); i++) { + ((RulerChangeListener) listeners.get(i)).notifyPartAttachmentChanged(evt.getNewValue(), evt.getSource()); + } + } else { + for (int i = 0; i < listeners.size(); i++) { + ((RulerChangeListener) listeners.get(i)).notifyGuideMoved(evt.getSource()); + } + } + } + }; + + public DesignerRulerProvider(DesignerRuler ruler) { + this.ruler = ruler; + this.ruler.addPropertyChangeListener(rulerListener); + List guides = getGuides(); + for (int i = 0; i < guides.size(); i++) { + ((DesignerGuide) guides.get(i)).addPropertyChangeListener(guideListener); + } + } + + @Override + public List getAttachedModelObjects(Object guide) { + return new ArrayList(((DesignerGuide) guide).getParts()); + } + + @Override + public Command getCreateGuideCommand(int position) { + return new CreateGuideCommand(ruler, position); + } + + @Override + public Command getDeleteGuideCommand(Object guide) { + return new DeleteGuideCommand((DesignerGuide) guide, ruler); + } + + @Override + public Command getMoveGuideCommand(Object guide, int pDelta) { + return new MoveGuideCommand((DesignerGuide) guide, pDelta); + } + + @Override + public int[] getGuidePositions() { + List guides = getGuides(); + int[] result = new int[guides.size()]; + for (int i = 0; i < guides.size(); i++) { + result[i] = ((DesignerGuide) guides.get(i)).getPosition(); + } + return result; + } + + @Override + public Object getRuler() { + return ruler; + } + + @Override + public int getUnit() { + return ruler.getUnit(); + } + + @Override + public void setUnit(int newUnit) { + ruler.setUnit(newUnit); + } + + @Override + public int getGuidePosition(Object guide) { + return ((DesignerGuide) guide).getPosition(); + } + + @Override + public List getGuides() { + return ruler.getGuides(); + } + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/commands/CreateGuideCommand.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/commands/CreateGuideCommand.java new file mode 100644 index 0000000..97dbbb9 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/commands/CreateGuideCommand.java @@ -0,0 +1,61 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.ruler.commands; + +import org.eclipse.gef.commands.Command; +import org.tizen.efluibuilder.ui.editor.ruler.DesignerGuide; +import org.tizen.efluibuilder.ui.editor.ruler.DesignerRuler; + + +public class CreateGuideCommand extends Command { + + private DesignerGuide guide; + private DesignerRuler parent; + private int position; + + public CreateGuideCommand(DesignerRuler parent, int position) { + super("Create guide"); + this.parent = parent; + this.position = position; + } + + @Override + public boolean canUndo() { + return true; + } + + @Override + public void execute() { + if (guide == null) + guide = new DesignerGuide(!parent.isHorizontal()); + guide.setPosition(position); + parent.addGuide(guide); + } + + @Override + public void undo() { + parent.removeGuide(guide); + } + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/commands/DeleteGuideCommand.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/commands/DeleteGuideCommand.java new file mode 100644 index 0000000..44ef990 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/commands/DeleteGuideCommand.java @@ -0,0 +1,72 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.ruler.commands; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.gef.commands.Command; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.ui.editor.ruler.DesignerGuide; +import org.tizen.efluibuilder.ui.editor.ruler.DesignerRuler; + + +public class DeleteGuideCommand extends Command { + + private DesignerRuler parent; + private DesignerGuide guide; + private Map oldParts; + + public DeleteGuideCommand(DesignerGuide guide, DesignerRuler parent) { + super("Delete guide"); + this.guide = guide; + this.parent = parent; + } + + @Override + public boolean canUndo() { + return true; + } + + @Override + public void execute() { + oldParts = new HashMap(guide.getMap()); + Iterator iter = oldParts.keySet().iterator(); + while (iter.hasNext()) { + guide.detachElement((Part) iter.next()); + } + parent.removeGuide(guide); + } + + @Override + public void undo() { + parent.addGuide(guide); + Iterator iter = oldParts.keySet().iterator(); + while (iter.hasNext()) { + Part element = (Part) iter.next(); + guide.attachElement(element, ((Integer) oldParts.get(element)).intValue()); + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/commands/MoveGuideCommand.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/commands/MoveGuideCommand.java new file mode 100644 index 0000000..97e792d --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/ruler/commands/MoveGuideCommand.java @@ -0,0 +1,66 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.ruler.commands; + +import org.eclipse.gef.commands.Command; +import org.tizen.efluibuilder.ui.editor.ruler.DesignerGuide; + + +public class MoveGuideCommand extends Command { + + private int pDelta; + private DesignerGuide guide; + + public MoveGuideCommand(DesignerGuide guide, int positionDelta) { + super("Move guide"); + this.guide = guide; + pDelta = positionDelta; + } + + @Override + public void execute() { + guide.setPosition(guide.getPosition() + pDelta); + /* + * Iterator iter = guide.getParts().iterator(); while (iter.hasNext()) { Part element = + * (Part) iter.next(); Rectangle layout = element.getPositionProperty().getCopy(); if + * (guide.isHorizontal()) { layout.y += pDelta; } else { layout.x += pDelta; } + * element.setPosition(layout); } + */ + + } + + @Override + public void undo() { + guide.setPosition(guide.getPosition() - pDelta); + /* + * Iterator iter = guide.getParts().iterator(); + * + * while (iter.hasNext()) { Part element = (Part) iter.next(); Rectangle layout = + * element.getPositionProperty().getCopy(); if (guide.isHorizontal()) { layout.y -= pDelta; + * } else { layout.x -= pDelta; } element.setPosition(layout); } + */ + + } + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/DOM2PartAdapter.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/DOM2PartAdapter.java new file mode 100644 index 0000000..e468522 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/DOM2PartAdapter.java @@ -0,0 +1,490 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.texteditor; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter; +import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; +import org.eclipse.wst.xml.core.internal.document.AttrImpl; +import org.eclipse.wst.xml.core.internal.document.DocumentImpl; +import org.eclipse.wst.xml.core.internal.document.ElementImpl; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.DocumentPart; +import org.tizen.efluibuilder.model.part.MScreenPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.part.ViewPart; +import org.tizen.efluibuilder.model.part.ViewsPart; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.editor.designeditor.DesignEditCommandStack; +import org.tizen.efluibuilder.utility.DOMUtil; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + + +public class DOM2PartAdapter implements INodeAdapter { + protected final Logger logger = LoggerFactory.getLogger(getClass()); + + private NotificationWatchDog watchDog; + + public DOM2PartAdapter(NotificationWatchDog watchDog) { + this.watchDog = watchDog; + } + + @Override + public boolean isAdapterForType(Object type) { + return this.getClass().equals(type); + } + + public void updatePartFromWYSIWYG(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, + Object newValue) { + Node parentNode = (Node) notifier; + + Part parentPart = PartUtil.getPartFrom(parentNode); // It can be NULL + Part childPart = null; + + switch (eventType) { + case INodeNotifier.CHANGE: + if (parentPart != null) { + if (changedFeature instanceof IDOMAttr) { + IDOMAttr changedAttr = (IDOMAttr) changedFeature; + + String key = changedAttr.getName(); + if (newValue == null) { + // if newValue is null , property is removed. + parentPart.removeProperty(key); + } else if (newValue instanceof String) { + // if newValue is not null, property is added or + // updated. + parentPart.setPropertyValue(key, (String) newValue); + } + } + } + break; + case INodeNotifier.ADD: + if (parentPart != null) { + if (newValue instanceof ElementImpl) { + ElementImpl newElementImpl = (ElementImpl) newValue; + childPart = PartUtil.getPartFrom(newElementImpl); + if (childPart == null) { + ComponentDescriptor descriptor = getComponentDescriptor(parentPart); + childPart = writePartbyElement(newElementImpl, parentPart.getOwnerDocumentPart(), parentPart, + descriptor); + } + + if (childPart != null && childPart != parentPart + && parentPart.getChildren().contains(childPart) == false) { + if (newElementImpl.isClosed()) { + Part nextSiblingPart = getNextPart(newElementImpl.getNextSibling()); + parentPart.insertChildBefore(childPart, nextSiblingPart); + } + } + } + } + break; + case INodeNotifier.REMOVE: + if (parentPart != null) { + if (oldValue instanceof Element) { + Element oldElement = (Element) oldValue; + childPart = PartUtil.getPartFrom(oldElement); + if (childPart != null) { + Document document = DOMUtil.getDocument(parentNode); + if (childPart == PartUtil.getPartFrom(document)) { // Remove + // + for (int i = 0; i < childPart.getChildren().size(); i++) { + Part part = childPart.getChildren().get(i); + if (part instanceof MScreenPart || part instanceof ViewsPart) { + part.removeAllChildren(); + } + } + } else if (childPart instanceof MScreenPart || childPart instanceof ViewsPart) { + childPart.removeAllChildren(); + } else { + parentPart.removeChild(childPart); + } + } + } + } + break; + default: + break; + } + } + + public void updatePartFromXMLEditor(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, + Object newValue) { + Node parentNode = (Node) notifier; + Part parentPart = PartUtil.getPartFrom(parentNode); + if (parentPart == null) { + return; + } + + switch (eventType) { + case INodeNotifier.CHANGE: + if (changedFeature instanceof IDOMAttr) { + IDOMAttr changedAttr = (IDOMAttr) changedFeature; + + String key = changedAttr.getName(); + if (newValue == null) { + // if newValue is null , property is removed. + parentPart.removeProperty(key); + } else if (newValue instanceof String) { + // if newValue is not null, property is added or + // updated. + parentPart.setPropertyValue(key, (String) newValue); + } + } + break; + case INodeNotifier.STRUCTURE_CHANGED: + if (parentPart instanceof DocumentPart) { + for (int i = 0; i < parentPart.getChildren().size(); i++) { + Part part = parentPart.getChildren().get(i); + if (part instanceof MScreenPart || part instanceof ViewsPart) { + part.removeAllChildren(); + } + } + } else { + parentPart.removeAllChildren(); + } + + ComponentDescriptor descriptor = getComponentDescriptor(parentPart); + NodeList childrenNodes = parentNode.getChildNodes(); + for (int i = 0; i < childrenNodes.getLength(); i++) { + Node childNode = childrenNodes.item(i); + if (childNode instanceof ElementImpl) { + Part childPart = writePartbyElement((ElementImpl) childNode, parentPart.getOwnerDocumentPart(), parentPart, + descriptor); + if (childPart != null && childPart != parentPart) { + parentPart.insertChildBefore(childPart, null); + } + } + } + break; + default: + break; + } + } + + @Override + public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, + Object newValue, int pos) { + // For debug, uncomment. + // printLog(notifier, eventType, changedFeature, oldValue, newValue, pos); + Node parentNode = (Node) notifier; + + switch (eventType) { + case INodeNotifier.ADD: + if (newValue instanceof ElementImpl) { + addAdapter((IDOMNode) newValue, true); + } + break; + case INodeNotifier.REMOVE: + if (oldValue instanceof ElementImpl) { + removeAdapter((IDOMNode) oldValue, true); + } + break; + } + + if (DesignEditCommandStack.isPartCommandMode(parentNode)) { + updatePartFromWYSIWYG(notifier, eventType, changedFeature, oldValue, newValue); + } else { + Document document = DOMUtil.getDocument(parentNode); + + List domChangeInfoList = (List) document.getUserData("DOM_CHANGE_INFO_LIST"); + if (domChangeInfoList == null) { + domChangeInfoList = new ArrayList(); + document.setUserData("DOM_CHANGE_INFO_LIST", domChangeInfoList, null); + } + + DOMChangeInfo domChangeInfo = new DOMChangeInfo(notifier, eventType, changedFeature, oldValue, newValue, + pos); + /* + * Extract useful DOM change event. + */ + boolean isUseful = true; + switch (eventType) { + case INodeNotifier.ADD: + case INodeNotifier.REMOVE: + if ((INodeNotifier.ADD == eventType && newValue instanceof ElementImpl == false) || + (INodeNotifier.REMOVE == eventType && oldValue instanceof ElementImpl == false)) { + isUseful = false; + } else { + Part parentPart = PartUtil.getPartFrom((Node) notifier); + if (parentPart != null) { + Iterator iter = domChangeInfoList.iterator(); + while (iter.hasNext()) { + DOMChangeInfo changeInfo = iter.next(); + Part changePart = PartUtil.getPartFrom((Node) changeInfo.notifier); + if (changeInfo.eventType == INodeNotifier.STRUCTURE_CHANGED) { + if (isAncestorPart(changePart, parentPart) && changePart != parentPart) { + isUseful = false; + } else if (isAncestorPart(parentPart, changePart)) { + iter.remove(); + } + } else if (changeInfo.eventType == INodeNotifier.CHANGE) { + if (isAncestorPart(parentPart, changePart) && parentPart != changePart) { + iter.remove(); + } + } + } + domChangeInfo.eventType = INodeNotifier.STRUCTURE_CHANGED; + } else { + isUseful = false; + } + } + break; + case INodeNotifier.CHANGE: + if (changedFeature instanceof AttrImpl == false) { + isUseful = false; + } else { + Part parentPart = PartUtil.getPartFrom((Node) notifier); + if (parentPart != null) { + Iterator iter = domChangeInfoList.iterator(); + while (iter.hasNext()) { + DOMChangeInfo changeInfo = iter.next(); + if (changeInfo.eventType == INodeNotifier.STRUCTURE_CHANGED) { + Part changePart = PartUtil.getPartFrom((Node) changeInfo.notifier); + if (isAncestorPart(changePart, parentPart) && changePart != parentPart) { + isUseful = false; + } + } else if (changeInfo.eventType == INodeNotifier.CHANGE) { + if (changeInfo.notifier == notifier && changeInfo.changedFeature == changedFeature) { + iter.remove(); + } + } + } + } else { + isUseful = false; + } + } + break; + default: + isUseful = false; + break; + } + if (isUseful) { + domChangeInfoList.add(domChangeInfo); + } + this.watchDog.resetWatchDog(document, this); + } + } + + private boolean isAncestorPart(Part ancestorPart, Part childPart) { + if (ancestorPart == null) { + return false; + } + Part currentPart = childPart; + while (currentPart != null) { + if (currentPart == ancestorPart) { + return true; + } + currentPart = currentPart.getParent(); + } + return false; + } + + private Part getNextPart(Node node) { + if (node == null) { + return null; + } else if (node instanceof ElementImpl) { + return PartUtil.getPartFrom(node); + } + return getNextPart(node.getNextSibling()); + } + + private ComponentDescriptor getComponentDescriptor(Part part) { + DocumentPart documentPart = part.getOwnerDocumentPart(); + if (documentPart != null) { + return documentPart.getComponentDescriptor(); + } + + return null; + } + + public void addAdapter(IDOMNode node, boolean traverseChild) { + if (node.getExistingAdapter(this) == null) { + node.addAdapter(this); + } + + if (traverseChild) { + for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { + if (child instanceof IDOMNode) { + this.addAdapter((IDOMNode) child, traverseChild); + } + } + } + } + + public void removeAdapter(IDOMNode node, boolean traverseChild) { + if (traverseChild) { + for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { + if (child instanceof IDOMNode) { + this.removeAdapter((IDOMNode) child, traverseChild); + } + } + } + + if (node.getExistingAdapter(this) != null) { + node.removeAdapter(this); + } + } + + private void copyAttributesToPart(Node node, Part part) { + NamedNodeMap attrList = node.getAttributes(); + for (int i = 0, length = attrList.getLength(); i < length; i++) { + Attr attr = (Attr) attrList.item(i); + part.setPropertyValue(attr.getName(), attr.getValue()); + } + } + + private Part writePartbyElement(Element element, DocumentPart docPart, Part parentPart, + ComponentDescriptor descriptor) { + String tagName = element.getTagName(); + + Part part = null; + + if (tagName.equals(LayoutSchemaConstants.DOCUMENT)) { + part = docPart; + } else if (tagName.equals(LayoutSchemaConstants.MSCREEN)) { + if (parentPart != null && parentPart instanceof DocumentPart) { + // Find MScreenPart from documentPart + for (int i = 0; i < parentPart.getChildren().size(); i++) { + if (parentPart.getChildren().get(i) instanceof MScreenPart) { + part = parentPart.getChildren().get(i); + break; + } + } + } + } else if (tagName.equals(LayoutSchemaConstants.VIEWS)) { + if (parentPart != null && parentPart instanceof DocumentPart) { + // Find ViewsPart from documentPart + for (int i = 0; i < parentPart.getChildren().size(); i++) { + if (parentPart.getChildren().get(i) instanceof ViewsPart) { + part = parentPart.getChildren().get(i); + break; + } + } + } + } else if (tagName.equals(LayoutSchemaConstants.CONFIGURATION)) { + if (parentPart == null || parentPart instanceof MScreenPart) { + part = PartUtil.createPartWithInitValue(docPart, PartType.CONFIGURATION, parentPart, tagName); + } + } else if (tagName.equals(LayoutSchemaConstants.VIEW)) { + if (parentPart == null || parentPart instanceof ViewsPart) { + part = PartUtil.createPartWithInitValue(docPart, PartType.VIEW, parentPart, tagName); + } + } else if (tagName.equals(LayoutSchemaConstants.EVENT)) { + if (parentPart == null || parentPart instanceof ComponentPart) { + part = PartUtil.createPartWithInitValue(docPart, PartType.EVENT, parentPart, tagName); + } + } else if (tagName.equals(LayoutSchemaConstants.VARIATION)) { + if (parentPart == null || parentPart instanceof ComponentPart) { + part = PartUtil.createPartWithInitValue(docPart, PartType.VARIATION, parentPart, tagName); + } + } else { + // assume component + if (parentPart == null || (parentPart instanceof ViewPart) || (parentPart instanceof ComponentPart)) { + if (docPart == null) { + return null; + } + if (docPart.getComponentDescriptor().getWidgetDescriptor(tagName) != null) { + part = PartUtil.createPartWithInitValue(docPart, PartType.COMPONENT, parentPart, tagName); + } + } + } + + if (part == null) + return null; + + copyAttributesToPart(element, part); + + // traverse child + for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) { + if (child instanceof ElementImpl) { + ElementImpl childElementImpl = (ElementImpl) child; + Part childPart = writePartbyElement(childElementImpl, docPart, part, descriptor); + + if (childPart != null && part.getChildren().contains(childPart) == false) { + if (childElementImpl.isClosed()) { + // connect part tree + part.insertChildBefore(childPart, null); + } + } + } + } + + part.setElement(element); + PartUtil.setPartToElement(element, part); + + return part; + } + + // For Debug + private void printLog(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, + Object newValue, int pos) { + if (!(notifier instanceof ElementImpl || notifier instanceof DocumentImpl)) { + return; + } + logger.debug("=============================================="); + logger.debug("notifier : " + notifier.getClass().getName() + " (" + notifier + ")" + " (" + + notifier.hashCode() + ")"); + if (notifier instanceof ElementImpl) { + logger.debug("\tElementName : " + ((ElementImpl) notifier).getNodeName()); + } + logger.debug("event : " + eventType); + logger.debug("changedFeature : " + ((changedFeature == null) ? "null" + : changedFeature.getClass().getName() + " (" + changedFeature + ")" + " (" + changedFeature.hashCode() + + ")")); + if (changedFeature instanceof ElementImpl) { + logger.debug("\tElementName : " + ((ElementImpl) changedFeature).getNodeName()); + } + logger.debug("oldValue : " + ((oldValue == null) ? "null" + : oldValue.getClass().getName() + " (" + oldValue + ")" + " (" + oldValue.hashCode() + ")")); + if (oldValue instanceof ElementImpl) { + logger.debug("\tElementName : " + ((ElementImpl) oldValue).getNodeName()); + logger.debug("\tEndTag : " + ((ElementImpl) oldValue).isStartTagClosed()); + } + logger.debug("newValue : " + ((newValue == null) ? "null" + : newValue.getClass().getName() + " (" + newValue + ")" + " (" + newValue.hashCode() + ")")); + if (newValue instanceof ElementImpl) { + logger.debug("\tElementName : " + ((ElementImpl) newValue).getNodeName()); + logger.debug("\tEndTag : " + ((ElementImpl) newValue).isEndTag()); + } + logger.debug("pos : " + pos); + logger.debug("=============================================="); + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/DOMChangeInfo.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/DOMChangeInfo.java new file mode 100644 index 0000000..524fc74 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/DOMChangeInfo.java @@ -0,0 +1,45 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.texteditor; + +import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; + + +class DOMChangeInfo { + INodeNotifier notifier; + int eventType; + Object changedFeature; + Object oldValue; + Object newValue; + int pos; + + DOMChangeInfo(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) { + this.notifier = notifier; + this.eventType = eventType; + this.changedFeature = changedFeature; + this.oldValue = oldValue; + this.newValue = newValue; + this.pos = pos; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/DataBindingModelListener.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/DataBindingModelListener.java new file mode 100644 index 0000000..9aa0182 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/DataBindingModelListener.java @@ -0,0 +1,134 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.editor.texteditor; + +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.model.part.IPartChangedListener; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartMutation; +import org.tizen.efluibuilder.model.part.PartObserver; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; + +@SuppressWarnings("restriction") +public final class DataBindingModelListener implements IPartChangedListener { + + protected final Logger logger = LoggerFactory.getLogger(getClass()); + + private PartObserver observer = null; + + public void initContents(Part documentPart, Document model) { + + // Assert.notNull(model); + + observer = new PartObserver(this); + observer.observe(documentPart); + } + + public void dispose() { + } + + private void addChild(Element parentElement, Part childPart) { + Part siblingPart = childPart.getNextSibling(); + Element siblingElement = null; + if (siblingPart != null) + siblingElement = siblingPart.getElement(); + + TextEditorUtil.insertElement(parentElement, siblingElement, childPart); + } + + private void removeChild(Element parentElement, Part childPart) { + Element removedElement = childPart.getElement(); + // TODO FIXME : add for undo/redo + childPart.setElement(null); + + NodeList nodes = parentElement.getChildNodes(); + for (int i = 0; i < nodes.getLength(); i++) { + if (!(nodes.item(i) instanceof Element)) + continue; + + Element childElement = (Element) nodes.item(i); + if (childElement.getNodeName() != null && childElement.getNodeName().equals(removedElement.getNodeName()) + && childElement.getAttribute(LayoutSchemaConstants.ID).equals(removedElement.getAttribute(LayoutSchemaConstants.ID))) { + parentElement.removeChild(childElement); + + // remove unnecessary line region + if (i > 0) { + removeEmptyText(nodes.item(i - 1)); + } + break; + } + } + } + + private void removeEmptyText(Node node) { + if (node instanceof Text) { // It must be the text node + String textContent = ((Text) node).getTextContent(); + if (textContent != null && textContent.trim().isEmpty()) { // It must be unnecessary + Node parentTextNode = node.getParentNode(); + if (parentTextNode != null) { // It must have a parent + parentTextNode.removeChild(node); + } + } + } + } + + @Override + public void partsChanged(List mutations, PartObserver observer, String sender) { + + for (PartMutation mutation : mutations) { + Part targetPart = mutation.getTargetPart(); + if (targetPart == null) { + continue; + } + + String mutationType = mutation.getType(); + Element parentElement = targetPart.getElement(); + if (PartMutation.PARTS_ADDED.equals(mutationType) || PartMutation.CONFIGURES_ADDED.equals(mutationType)) { + for (Part child : mutation.getAddedParts()) { + addChild(parentElement, child); + } + } else if (PartMutation.PARTS_REMOVED.equals(mutationType) || PartMutation.CONFIGURES_REMOVED.equals(mutationType)) { + for (Part child : mutation.getRemovedParts()) { + removeChild(parentElement, child); + } + } else if (PartMutation.PROPERTY_CHANGED.equals(mutationType) || PartMutation.CONFIGURE_PROPERTY_CHANGED.equals(mutationType)) { + if (parentElement != null) { + parentElement.setAttribute(mutation.getPropertyName(), mutation.getOldValue()); + } + } else if (PartMutation.PARTS_ORDER_CHANGED.equals(mutationType)) { + for (Part child : mutation.getOrderChangedParts()) { + removeChild(parentElement, child); + addChild(parentElement, child); + } + } + } + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/NotificationWatchDog.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/NotificationWatchDog.java new file mode 100644 index 0000000..ce1352b --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/NotificationWatchDog.java @@ -0,0 +1,133 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.texteditor; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.InputStream; +import java.util.List; + +import org.eclipse.core.runtime.URIUtil; +import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; +import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; +import org.eclipse.wst.xml.core.internal.document.DocumentImpl; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; +import org.eclipse.wst.xml.core.internal.validation.XMLValidationReport; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.model.part.DocumentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartObserver; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.editor.texteditor.TextEditorWatchdog.IWatchdocRunner; +import org.tizen.efluibuilder.ui.editor.texteditor.validation.LayoutValidator; +import org.tizen.efluibuilder.ui.editor.texteditor.validation.NonSchemaBasedLayoutValidator; +import org.w3c.dom.Document; + + +public class NotificationWatchDog implements IWatchdocRunner { + + protected final Logger logger = LoggerFactory.getLogger(getClass()); + + private final long delay = 500; // 500ms + + private TextEditorWatchdog asyncChecker = new TextEditorWatchdog(this); + private Document ownerDocument; + private DOM2PartAdapter adapter; + + public NotificationWatchDog() { + this.asyncChecker.start(this.delay); + } + + public void dispose() { + this.asyncChecker.stop(); + } + + public void resetWatchDog(Document ownerDocument, DOM2PartAdapter adapter) { + logger.debug("Reset NotificationWatchDog"); + + this.ownerDocument = ownerDocument; + this.adapter = adapter; + + this.asyncChecker.reset(); + this.asyncChecker.enableModified(); + } + + @Override + public void processJob() { + logger.debug("Run watchDog"); + Part documentPart = PartUtil.getPartFrom(ownerDocument); + if (documentPart == null) { + logger.warn("documentPart is null."); + return; + } + // PartUpdate + if (isValidDocument()) { + if (PartUtil.findViewsPart(documentPart).getChildren().isEmpty()) { + // Case: After invalid layout.xml is opened, the xml is fixed. + adapter.updatePartFromXMLEditor((DocumentImpl)ownerDocument, INodeNotifier.STRUCTURE_CHANGED, null, null, null); + } else { + List domChangeInfoList = (List) ownerDocument.getUserData("DOM_CHANGE_INFO_LIST"); + if (domChangeInfoList != null) { + for (int i = 0; i < domChangeInfoList.size(); i++) { + DOMChangeInfo info = domChangeInfoList.get(i); + adapter.updatePartFromXMLEditor(info.notifier, info.eventType, info.changedFeature, info.oldValue, info.newValue); + } + domChangeInfoList.clear(); + } + } + ((DocumentPart)documentPart).setValidDocument(true); + documentPart.notifyObservers(PartObserver.MESSAGE_VALID_XML); + ((DocumentPart)documentPart).updateID(); + } else { + ((DocumentPart)documentPart).setValidDocument(false); + documentPart.notifyObservers(PartObserver.MESSAGE_INVALID_XML); + logger.debug("Invalid XML!!!!!"); + } + } + + private boolean isValidDocument() { + IDOMModel model = ((DocumentImpl) ownerDocument).getModel(); + + if (model == null) { + return false; + } + + // get current XML + IStructuredDocument structuredDocument = model.getStructuredDocument(); + InputStream is = new ByteArrayInputStream(structuredDocument.get().getBytes()); + + String fileBaseLocation = model.getResolver().getFileBaseLocation(); + String uri = URIUtil.toUnencodedString(new File(fileBaseLocation).toURI()); + + // validate + XMLValidationReport report = LayoutValidator.validateXml(uri, is); + boolean isValid = report.isValid(); + if (isValid) { + String errorMsg = new NonSchemaBasedLayoutValidator().validate(structuredDocument); + isValid = (errorMsg != null && errorMsg.isEmpty()); + } + return isValid; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/TextEditor.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/TextEditor.java new file mode 100644 index 0000000..7d72f4c --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/TextEditor.java @@ -0,0 +1,351 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.texteditor; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.InputStream; +import java.util.Iterator; + +import org.eclipse.core.runtime.URIUtil; +import org.eclipse.gef.EditDomain; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.MouseWheelHandler; +import org.eclipse.gef.SnapToGrid; +import org.eclipse.gef.ui.parts.SelectionSynchronizer; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.TextSelection; +import org.eclipse.jface.viewers.IPostSelectionProvider; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorSite; +import org.eclipse.ui.PartInitException; +import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; +import org.eclipse.wst.sse.ui.StructuredTextEditor; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; +import org.eclipse.wst.xml.core.internal.validation.XMLValidationReport; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.DocumentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.ModelConstants; +import org.tizen.efluibuilder.model.util.PartUnmarshaller; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.efluibuilder.ui.editor.MouseWheelZoomHandler; +import org.tizen.efluibuilder.ui.editor.texteditor.TextEditorWatchdog.IWatchdocRunner; +import org.tizen.efluibuilder.ui.editor.texteditor.preview.PreviewComposite; +import org.tizen.efluibuilder.ui.editor.texteditor.preview.PreviewViewer; +import org.tizen.efluibuilder.ui.editor.texteditor.validation.LayoutValidator; +import org.tizen.efluibuilder.ui.editor.texteditor.validation.NonSchemaBasedLayoutValidator; +import org.tizen.efluibuilder.ui.editor.toolbar.PreviewToolbar; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import graphicalDataManager.GraphicalDataManager; + + +@SuppressWarnings("restriction") +public class TextEditor extends StructuredTextEditor implements IWatchdocRunner, ISelectionChangedListener { + + protected final Logger logger = LoggerFactory.getLogger(getClass()); + + private PreviewViewer previewViewer = new PreviewViewer(this); + private PreviewToolbar previewToolbar = null; + private NotificationWatchDog notiWatchDog = new NotificationWatchDog(); + + private DOM2PartAdapter adapter; + + private Part currentFocusedPart = null; + + private TextEditorWatchdog asyncChecker = null; + private static final long AnalyzeDelayTime = 500; + + private SelectionSynchronizer selectionSynchronizer = null; + private CombineEditorPart parentEditor = null; + Composite toolbarComposite = null; + + public TextEditor() { + super(); + this.asyncChecker = new TextEditorWatchdog(this); + this.asyncChecker.start(AnalyzeDelayTime); + } + + public void initContents(CombineEditorPart editorPart, Part documentPart, IEditorInput editorInput, EditDomain editDomain, + SelectionSynchronizer selectionSynchronizer, GraphicalDataManager graphicalDataManager) { + this.selectionSynchronizer = selectionSynchronizer; + + previewViewer.initContents(documentPart, editorInput, editDomain, graphicalDataManager); + // editorPart.addProjectResourceChangeListener(previewViewer); + this.parentEditor = editorPart; + selectionSynchronizer.addViewer(previewViewer); + + previewToolbar = new PreviewToolbar(toolbarComposite, parentEditor, previewViewer); + // previewToolbar.createToolItem(); + previewToolbar.initContents(previewViewer); + + IDOMDocument document = getDomModel().getDocument(); + PartUtil.setPartToElement(document, documentPart); + + if (((DocumentPart) documentPart).isValidDocument() == false) { + previewViewer.setEnabled(false); + } + } + + @Override + public void dispose() { + stopDoDocumentProcess(); + + removePostSelectionProvider(); + // removeModelStateListener(); + + if (selectionSynchronizer != null) { + selectionSynchronizer.removeViewer(previewViewer); + } + + if (this.notiWatchDog != null) { + this.notiWatchDog.dispose(); + } + + if (this.adapter != null) { + IDOMNode rootElement = getDomModel().getDocument(); + this.adapter.removeAdapter(rootElement, true); + } + + super.dispose(); + } + + private void createPreviewViewer(Composite parent) { + toolbarComposite = new Composite(parent, SWT.NONE); + toolbarComposite.setLayout(new FormLayout()); + FormData data = new FormData(); + data.top = new FormAttachment(parent, 0); + data.bottom = new FormAttachment(100, 0); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(100, 0); + + // previewToolbar = new PreviewToolbar(toolbarComposite, parentEditor, previewViewer); + // previewToolbar.createToolItem(); + + Composite previewComposite = new Composite(parent, SWT.NONE); + previewComposite.setLayout(new FillLayout()); + + // You can set configurations of viewer + boolean bGridEnable = false; + previewViewer.setProperty(SnapToGrid.PROPERTY_GRID_ENABLED, bGridEnable); + previewViewer.setProperty(SnapToGrid.PROPERTY_GRID_VISIBLE, bGridEnable); + // if (bGridEnable) + // previewViewer.setProperty(SnapToGrid.PROPERTY_GRID_SPACING, new Dimension(50, 50)); + + previewViewer.createControl(previewComposite); + previewViewer.setProperty(MouseWheelHandler.KeyGenerator.getKey(SWT.MOD1), MouseWheelZoomHandler.SINGLETON); + } + + private void setCurrentPart(Part target) { + this.currentFocusedPart = target; + } + + private void addPostSelectionProvider() { + ITextViewer textViewer = getTextViewer(); + if (textViewer != null) { + ((IPostSelectionProvider) textViewer).addPostSelectionChangedListener(this); + } + } + + private void removePostSelectionProvider() { + ITextViewer textViewer = getTextViewer(); + if (textViewer != null) { + ((IPostSelectionProvider) textViewer).removePostSelectionChangedListener(this); + } + } + + @Override + public void createPartControl(Composite parent) { + TextEditorComposite rootComposite = new TextEditorComposite(parent, SWT.HORIZONTAL); + PreviewComposite previewPane = new PreviewComposite(rootComposite, SWT.VERTICAL); + Composite editorPane = new Composite(rootComposite, SWT.NONE); + editorPane.setLayout(new FillLayout()); + + super.createPartControl(editorPane); + createPreviewViewer(previewPane); + + // addModelStateListener(); + addPostSelectionProvider(); + } + + public boolean isValidDocument() { + IDOMModel model = getDomModel(); + if (model == null) { + return false; + } + + // get current XML + IStructuredDocument structuredDocument = model.getStructuredDocument(); + InputStream is = new ByteArrayInputStream(structuredDocument.get().getBytes()); + + String fileBaseLocation = model.getResolver().getFileBaseLocation(); + String uri = URIUtil.toUnencodedString(new File(fileBaseLocation).toURI()); + + // validate + XMLValidationReport report = LayoutValidator.validateXml(uri, is); + boolean isValid = report.isValid(); + if (isValid) { + String errorMsg = new NonSchemaBasedLayoutValidator().validate(structuredDocument); + isValid = (errorMsg != null && errorMsg.isEmpty()); + } + + return isValid; + } + + public void setSelection(Part model) { + if (!model.equals(currentFocusedPart)) { + Element targetElement = model.getElement(); + if (targetElement instanceof IDOMNode) { + int offset = ((IDOMNode) targetElement).getStartOffset(); + setCurrentPart(model); + getTextViewer().setSelection(new TextSelection(getTextViewer().getDocument(), offset, 0)); + } + } + } + + public Part createLayoutModel(Part documentPart) { + IDOMModel domModel = getDomModel(); + if (domModel != null) { + IDOMDocument domDoc = domModel.getDocument(); // This is not null always. + Element element = domDoc.getDocumentElement(); + if (element != null) { + Document document = element.getOwnerDocument(); + if (document != null) { + PartUnmarshaller unmarshaller = new PartUnmarshaller(); + unmarshaller.unmarshall((DocumentPart) documentPart, document, true); + ((DocumentPart) documentPart).updateID(); + } + } + } + + return documentPart; + } + + /** + * Get DOMModel from DocumentProvider + * + * @return It can return null. + */ + private IDOMModel getDomModel() { + return (IDOMModel) getModel(); + } + + @Override + public void processJob() { + Part focusedPart = null; + + // find a part of selected element + // FIXED: Improve inaccurate and slow logic + ISelection selection = getSelectionProvider().getSelection(); + if (selection instanceof IStructuredSelection) { + Iterator elementIter = ((IStructuredSelection) selection).iterator(); + Element element = null; + while (elementIter.hasNext()) { + Object iter = elementIter.next(); + if (iter instanceof Attr) { + element = ((Attr) iter).getOwnerElement(); + break; + } else if (iter instanceof Element) { + element = (Element) iter; + } + } + if (element != null) { + Object userData = element.getUserData(ModelConstants.ELEMENT_UD_PART_KEY); + if (userData instanceof Part) { + focusedPart = (Part) userData; + } + } + } + + if (focusedPart == null || focusedPart instanceof ComponentPart == false) { + previewViewer.setInitCurrentActivatedView(); + } + + // select to viewer + if (focusedPart != null) { + if (!focusedPart.equals(currentFocusedPart)) { + EditPart focusedEditPart = (EditPart) previewViewer.getEditPartRegistry().get(focusedPart.getUniqueId()); + if (focusedEditPart != null) { + setCurrentPart(focusedPart); + previewViewer.select(focusedEditPart); + } + } + } else if (this.currentFocusedPart != null) { + setCurrentPart(null); + previewViewer.deselectAll(); + } + } + + public void resetDoDocumentProcess() { + this.asyncChecker.reset(); + this.asyncChecker.enableModified(); + } + + private void stopDoDocumentProcess() { + if (this.asyncChecker != null) { + this.asyncChecker.stop(); + } + } + + @Override + public void selectionChanged(SelectionChangedEvent event) { + if (parentEditor.getDocumentPart() != null && ((DocumentPart) parentEditor.getDocumentPart()).isValidDocument()) { + if (event.getSelection() instanceof TextSelection) { + resetDoDocumentProcess(); + } + } + } + + @Override + public void init(IEditorSite site, IEditorInput input) throws PartInitException { + super.init(site, input); + + IDOMNode rootElement = getDomModel().getDocument(); + this.adapter = new DOM2PartAdapter(this.notiWatchDog); + this.adapter.addAdapter(rootElement, true); + } + + public void setPreviewToolbarEnabled(boolean enabled) { + previewToolbar.setEnabled(enabled); + } + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/TextEditorComposite.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/TextEditorComposite.java new file mode 100644 index 0000000..ca9a7fb --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/TextEditorComposite.java @@ -0,0 +1,248 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.texteditor; + +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Sash; +import org.tizen.efluibuilder.ui.resources.ColorResources; + + +public class TextEditorComposite extends Composite { + + private static final int DEFAULT_SASH_WIDTH = 5; + private static final int DRAG_MINIMUM = 50; + private static final String MAINTAIN_SIZE = "maintain size"; //$NON-NLS-1$ + + private int fixedSize = 50; + private int orientation = SWT.HORIZONTAL; + private Sash[] sashes = new Sash[0]; + private Control[] controls = new Control[0]; + private Listener sashListener; + + class SashPainter implements Listener { + public void handleEvent(Event e) { + paint((Sash) e.widget, e.gc); + } + } + + public TextEditorComposite(final Composite parent, int style) { + super(parent, style & SWT.BORDER); + + if ((style & SWT.HORIZONTAL) != 0) + orientation = SWT.HORIZONTAL; + + this.addListener(SWT.Resize, new Listener() { + public void handleEvent(Event e) { + layout(true); + } + }); + sashListener = new Listener() { + public void handleEvent(Event event) { + onDragSash(event); + } + }; + } + + private void setFixedSize(int newSize) { + if (newSize == fixedSize) { + return; + } + } + + private Control[] getControls(boolean onlyVisible) { + Control[] children = getChildren(); + Control[] controls = new Control[0]; + for (int i = 0; i < children.length; i++) { + if (children[i] instanceof Sash) + continue; + if (onlyVisible && !children[i].getVisible()) + continue; + + Control[] newControls = new Control[controls.length + 1]; + System.arraycopy(controls, 0, newControls, 0, controls.length); + newControls[controls.length] = children[i]; + controls = newControls; + } + return controls; + } + + private void paint(Sash sash, GC gc) { + Point size = sash.getSize(); + if (getOrientation() == SWT.HORIZONTAL) { + gc.setForeground(ColorResources.PREVIEW_SPLITTER); + gc.drawLine(DEFAULT_SASH_WIDTH - 1, 0, DEFAULT_SASH_WIDTH - 1, size.y); + gc.setForeground(ColorConstants.buttonLightest); + gc.drawLine(0, 0, 0, size.y); + } else { + gc.setForeground(ColorConstants.buttonDarker); + gc.drawLine(0, 0, size.x, 0); + gc.drawLine(0, DEFAULT_SASH_WIDTH - 1, size.x, DEFAULT_SASH_WIDTH - 1); + gc.setForeground(ColorConstants.buttonLightest); + gc.drawLine(0, 1, size.x, 1); + } + } + + private void onDragSash(Event event) { + if (event.detail == SWT.DRAG) { + // constrain feedback + Rectangle area = getClientArea(); + if (orientation == SWT.HORIZONTAL) { + if (controls[0].getData(MAINTAIN_SIZE) != null) { + event.x = Math.max(event.x, DRAG_MINIMUM); + } else { + event.x = Math.min(event.x, area.width - DRAG_MINIMUM - DEFAULT_SASH_WIDTH); + } + } else { + event.y = Math.min(event.y, area.height - DRAG_MINIMUM - DEFAULT_SASH_WIDTH); + } + return; + } + + Sash sash = (Sash) event.widget; + int sashIndex = -1; + for (int i = 0; i < sashes.length; i++) { + if (sashes[i] == sash) { + sashIndex = i; + break; + } + } + if (sashIndex == -1) + return; + + Control c1 = controls[sashIndex]; + Control c2 = controls[sashIndex + 1]; + Rectangle b1 = c1.getBounds(); + Rectangle b2 = c2.getBounds(); + controls = getControls(true); + + Rectangle sashBounds = sash.getBounds(); + if (orientation == SWT.HORIZONTAL) { + int shift = event.x - sashBounds.x; + b1.width += shift; + b2.x += shift; + b2.width -= shift; + } else { + int shift = event.y - sashBounds.y; + b1.height += shift; + b2.y += shift; + b2.height -= shift; + } + + c1.setBounds(b1); + sash.setBounds(event.x, event.y, event.width, event.height); + c2.setBounds(b2); + + if (c1.getData(MAINTAIN_SIZE) != null) { + setFixedSize(c1.getBounds().width); + } else { + setFixedSize(c2.getBounds().width); + } + } + + @Override + public int getOrientation() { + return orientation; + } + + @Override + public void layout(boolean changed) { + Rectangle area = getClientArea(); + if (area.width == 0 || area.height == 0) + return; + + Control[] newControls = getControls(true); + if (controls.length == 0 && newControls.length == 0) + return; + controls = newControls; + + if (sashes.length < controls.length - 1) { + Sash[] newSashes = new Sash[controls.length - 1]; + System.arraycopy(sashes, 0, newSashes, 0, sashes.length); + int sashOrientation = (orientation == SWT.HORIZONTAL) ? SWT.VERTICAL : SWT.HORIZONTAL; + for (int i = sashes.length; i < newSashes.length; i++) { + newSashes[i] = new Sash(this, sashOrientation); + newSashes[i].setBackground(ColorConstants.button); + newSashes[i].addListener(SWT.Paint, new SashPainter()); + newSashes[i].addListener(SWT.Selection, sashListener); + } + sashes = newSashes; + } + if (sashes.length > controls.length - 1) { + if (controls.length == 0) { + for (int i = 0; i < sashes.length; i++) { + sashes[i].dispose(); + } + sashes = new Sash[0]; + } else { + Sash[] newSashes = new Sash[controls.length - 1]; + System.arraycopy(sashes, 0, newSashes, 0, newSashes.length); + for (int i = controls.length - 1; i < sashes.length; i++) { + sashes[i].dispose(); + } + sashes = newSashes; + } + } + + if (controls.length == 0) + return; + int x = area.x; + int width = 0; + for (int i = 0; i < controls.length; i++) { + + Control control = controls[i]; + + // if (i == 0) { + // width = (area.width / 3) - DEFAULT_SASH_WIDTH; + // control.setBounds(x, area.y, width, area.height); + // } else if (i == 1) { + // x += (width + DEFAULT_SASH_WIDTH); + // width = (area.width / 3) * 2 - DEFAULT_SASH_WIDTH; + // control.setBounds(x, area.y, width, area.height); + // } else { + // break; + // } + + if (i == 0) { + width = (area.width / 2) - DEFAULT_SASH_WIDTH; + control.setBounds(x, area.y, width, area.height); + } else if (i == 1) { + x += (width + DEFAULT_SASH_WIDTH); + width = (area.width / 2) - DEFAULT_SASH_WIDTH; + control.setBounds(x, area.y, width, area.height); + } else { + break; + } + } + if (sashes.length > 0) + sashes[0].setBounds(controls[0].getBounds().x + controls[0].getBounds().width, area.y, DEFAULT_SASH_WIDTH, area.height); + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/TextEditorUtil.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/TextEditorUtil.java new file mode 100644 index 0000000..cc74a5b --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/TextEditorUtil.java @@ -0,0 +1,117 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.texteditor; + +import org.tizen.efluibuilder.model.part.EventPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.ModelConstants; +import org.tizen.efluibuilder.model.util.PartMarshaller; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + + +@SuppressWarnings("restriction") +public class TextEditorUtil { + + // public static void replaceConnectionElement(Connection connection) { + // Element sourceParentElement = connection.getSource().getParent().getElement(); + // replaceElement(sourceParentElement, connection.getSource()); + // } + + public static void insertElement(Element parentElement, Element refElement, Part childPart) { + if (parentElement == null) { + return; + } + + // APPEND + // Element newElement = PartSerializer.write(childPart, parentElement.getOwnerDocument(), + // true); + PartMarshaller marshller = new PartMarshaller(); + Element newElement = marshller.marshall(parentElement.getOwnerDocument(), childPart); + + // Uniqueness must be guaranteed for the signal attribute for event element + String uniqueAttr = (childPart instanceof EventPart) + ? LayoutSchemaConstants.EVENT_SIGNAL + : LayoutSchemaConstants.ID; + String nodeName = newElement.getNodeName(); + String attribute = newElement.getAttribute(uniqueAttr); + + // find existing element and reuse it. + NodeList nodes = parentElement.getChildNodes(); + for (int i = 0, length = nodes.getLength(); i < length; i++) { + Node item = nodes.item(i); + if (item instanceof Element) { + Element childElement = (Element) item; + + // if same tag & ID, + if (childElement.getNodeName().equals(nodeName) + && childElement.getAttribute(uniqueAttr).equals(attribute)) { + // assign existing element + assignElement(childPart, childElement); + return; + } + } + } + + // insert new element + if (refElement != null) { + parentElement.insertBefore(newElement, refElement); + } else { + parentElement.appendChild(newElement); + } + + // assign new element + assignElement(childPart, newElement); + + // FIXED: (sw83.shim@samsung.com) New child elements are not assigned to each part + assignChildElements(newElement, childPart); + } + + private static void assignElement(Part part, Element element) { + part.setElement(element); + element.setUserData(ModelConstants.ELEMENT_UD_PART_KEY, part, null); + } + + private static void assignChildElements(Element element, Part part) { + NodeList childNodes = element.getChildNodes(); + for (int i = 0, length = childNodes.getLength(); i < length; i++) { + Node item = childNodes.item(i); + if (item instanceof Element) { + Element childElement = (Element) item; + + for (Part child : part.getChildren()) { + if (child.isSameWith(childElement)) { + // assign existing element + assignElement(child, childElement); + + // traverse childs + assignChildElements(childElement, child); + } + } + } + } + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/TextEditorWatchdog.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/TextEditorWatchdog.java new file mode 100644 index 0000000..81224be --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/TextEditorWatchdog.java @@ -0,0 +1,107 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.texteditor; + +import java.util.Timer; +import java.util.TimerTask; + +import org.eclipse.swt.widgets.Display; + + +class ProcessValidateTask extends TimerTask { + + TextEditorWatchdog validator = null; + + @Override + public void run() { + validator.checkJob(); + } + + ProcessValidateTask(TextEditorWatchdog validator) { + this.validator = validator; + } +} + + +class TextEditorWatchdog { + public interface IWatchdocRunner { + public void processJob(); + } + + long until = System.currentTimeMillis(); + long checkDelay = 0; + long timerTick = 200;// 0.2S + IWatchdocRunner runner; + private Timer analyzeTimer = new Timer(); + private ProcessValidateTask analyzeTimerTask = null; + private boolean bModified = false; + + public void reset() { + this.until = System.currentTimeMillis() + this.checkDelay; + } + + public void enableModified() { + this.bModified = true; + } + + public void start(long checkDelay) { + this.checkDelay = checkDelay; + this.analyzeTimerTask = new ProcessValidateTask(this); + this.reset(); + this.analyzeTimer.scheduleAtFixedRate(this.analyzeTimerTask, 0, timerTick); + + } + + public void processJob() { + final IWatchdocRunner runner = this.runner; + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + runner.processJob(); + } + }); + bModified = false; + } + + public void checkJob() { + if (System.currentTimeMillis() >= this.until && bModified) { + this.processJob(); + this.reset(); + } + } + + public void stop() { + if (this.analyzeTimerTask != null) { + this.analyzeTimerTask.cancel(); + this.analyzeTimer.purge(); + this.analyzeTimerTask = null; + } + } + + TextEditorWatchdog(IWatchdocRunner runner) { + this.analyzeTimer = new Timer(); + this.runner = runner; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/PreviewComposite.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/PreviewComposite.java new file mode 100644 index 0000000..729e3d7 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/PreviewComposite.java @@ -0,0 +1,321 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.texteditor.preview; + +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Sash; +import org.tizen.efluibuilder.ui.editor.toolbar.ToolBarConstants; + + +public class PreviewComposite extends Composite { + + private static final int DEFAULT_SASH_WIDTH = 5; + private static final int DRAG_MINIMUM = 50; + private static final String MAINTAIN_SIZE = "maintain size"; //$NON-NLS-1$ + + private int fixedSize = 50; + private int orientation = SWT.VERTICAL; + private Sash[] sashes = new Sash[0]; + private Control[] controls = new Control[0]; + private Listener sashListener; + + class SashPainter implements Listener { + public void handleEvent(Event e) { + paint((Sash) e.widget, e.gc); + } + } + + public PreviewComposite(Composite parent, int style) { + super(parent, style & SWT.BORDER); + + if ((style & SWT.VERTICAL) != 0) + orientation = SWT.VERTICAL; + + this.addListener(SWT.Resize, new Listener() { + public void handleEvent(Event e) { + layout(true); + } + }); + + sashListener = new Listener() { + public void handleEvent(Event e) { + onDragSash(e); + } + }; + } + + private void setFixedSize(int newSize) { + if (newSize == fixedSize) { + return; + } + } + + private Control[] getControls(boolean onlyVisible) { + Control[] children = getChildren(); + Control[] controls = new Control[0]; + for (int i = 0; i < children.length; i++) { + if (children[i] instanceof Sash) + continue; + if (onlyVisible && !children[i].getVisible()) + continue; + + Control[] newControls = new Control[controls.length + 1]; + System.arraycopy(controls, 0, newControls, 0, controls.length); + newControls[controls.length] = children[i]; + controls = newControls; + } + return controls; + } + + private void paint(Sash sash, GC gc) { + Point size = sash.getSize(); + if (getOrientation() == SWT.HORIZONTAL) { + gc.setForeground(ColorConstants.red); + gc.drawLine(DEFAULT_SASH_WIDTH - 1, 0, DEFAULT_SASH_WIDTH - 1, size.y); + gc.setForeground(ColorConstants.buttonLightest); + gc.drawLine(0, 0, 0, size.y); + } else { + gc.setForeground(ColorConstants.buttonDarker); + gc.drawLine(0, 0, size.x, 0); + gc.drawLine(0, DEFAULT_SASH_WIDTH - 1, size.x, DEFAULT_SASH_WIDTH - 1); + gc.setForeground(ColorConstants.buttonLightest); + gc.drawLine(0, 1, size.x, 1); + } + } + + private void onDragSash(Event event) { + if (event.detail == SWT.DRAG) { + // constrain feedback + Rectangle area = getClientArea(); + if (orientation == SWT.HORIZONTAL) { + if (controls[0].getData(MAINTAIN_SIZE) != null) { + event.x = Math.max(event.x, DRAG_MINIMUM); + } else { + event.x = Math.min(event.x, area.width - DRAG_MINIMUM - DEFAULT_SASH_WIDTH); + } + } else { + event.y = Math.min(event.y, area.height - DRAG_MINIMUM - DEFAULT_SASH_WIDTH); + } + return; + } + + Sash sash = (Sash) event.widget; + int sashIndex = -1; + for (int i = 0; i < sashes.length; i++) { + if (sashes[i] == sash) { + sashIndex = i; + break; + } + } + if (sashIndex == -1) + return; + + Control c1 = controls[sashIndex]; + Control c2 = controls[sashIndex + 1]; + Rectangle b1 = c1.getBounds(); + Rectangle b2 = c2.getBounds(); + controls = getControls(true); + + Rectangle sashBounds = sash.getBounds(); + if (orientation == SWT.HORIZONTAL) { + int shift = event.x - sashBounds.x; + b1.width += shift; + b2.x += shift; + b2.width -= shift; + } else { + int shift = event.y - sashBounds.y; + b1.height += shift; + b2.y += shift; + b2.height -= shift; + } + + c1.setBounds(b1); + sash.setBounds(event.x, event.y, event.width, event.height); + c2.setBounds(b2); + + if (c1.getData(MAINTAIN_SIZE) != null) { + setFixedSize(c1.getBounds().width); + } else { + setFixedSize(c2.getBounds().width); + } + } + + @Override + public int getOrientation() { + return orientation; + } + + @Override + public void layout(boolean changed) { + Rectangle area = getClientArea(); + if (area.width == 0 || area.height == 0) + return; + + Control[] newControls = getControls(true); + if (controls.length == 0 && newControls.length == 0) + return; + controls = newControls; + + if (sashes.length < controls.length - 1) { + Sash[] newSashes = new Sash[controls.length - 1]; + System.arraycopy(sashes, 0, newSashes, 0, sashes.length); + int sashOrientation = (orientation == SWT.HORIZONTAL) ? SWT.VERTICAL : SWT.HORIZONTAL; + for (int i = sashes.length; i < newSashes.length; i++) { + newSashes[i] = new Sash(this, sashOrientation); + newSashes[i].setBackground(ColorConstants.button); + newSashes[i].addListener(SWT.Paint, new SashPainter()); + newSashes[i].addListener(SWT.Selection, sashListener); + } + sashes = newSashes; + } + if (sashes.length > controls.length - 1) { + if (controls.length == 0) { + for (int i = 0; i < sashes.length; i++) { + sashes[i].dispose(); + } + sashes = new Sash[0]; + } else { + Sash[] newSashes = new Sash[controls.length - 1]; + System.arraycopy(sashes, 0, newSashes, 0, newSashes.length); + for (int i = controls.length - 1; i < sashes.length; i++) { + sashes[i].dispose(); + } + sashes = newSashes; + } + } + + if (controls.length == 0) + return; + int y = area.y; + int height = 0; + for (int i = 0; i < controls.length; i++) { + + Control control = controls[i]; + + if (i == 0) { + height = ToolBarConstants.TOOLBAR_HEIGHT; + control.setBounds(area.x, y, area.width, height); + } else if (i == 1) { + y += (height + DEFAULT_SASH_WIDTH); + height = (area.height - ToolBarConstants.TOOLBAR_HEIGHT) - DEFAULT_SASH_WIDTH; + control.setBounds(area.x, y, area.width, height); + } else { + break; + } + + } + if (sashes.length > 0) + sashes[0].setBounds(controls[0].getBounds().x + controls[0].getBounds().width, area.y, DEFAULT_SASH_WIDTH, area.height); + + } + + public void layout1(boolean changed) { + Rectangle area = getClientArea(); + if (area.width == 0 || area.height == 0) + return; + + Control[] newControls = getControls(true); + if (controls.length == 0 && newControls.length == 0) + return; + controls = newControls; + + // keep just the right number of sashes + if (sashes.length < controls.length - 1) { + Sash[] newSashes = new Sash[controls.length - 1]; + System.arraycopy(sashes, 0, newSashes, 0, sashes.length); + int sashOrientation = (orientation == SWT.HORIZONTAL) ? SWT.VERTICAL : SWT.HORIZONTAL; + for (int i = sashes.length; i < newSashes.length; i++) { + newSashes[i] = new Sash(this, sashOrientation); + newSashes[i].setBackground(ColorConstants.button); + newSashes[i].addListener(SWT.Paint, new SashPainter()); + newSashes[i].addListener(SWT.Selection, sashListener); + } + sashes = newSashes; + } + if (sashes.length > controls.length - 1) { + if (controls.length == 0) { + for (int i = 0; i < sashes.length; i++) { + sashes[i].dispose(); + } + sashes = new Sash[0]; + } else { + Sash[] newSashes = new Sash[controls.length - 1]; + System.arraycopy(sashes, 0, newSashes, 0, newSashes.length); + for (int i = controls.length - 1; i < sashes.length; i++) { + sashes[i].dispose(); + } + sashes = newSashes; + } + } + + if (controls.length == 0) + return; + int x = area.x; + int width; + for (int i = 0; i < controls.length; i++) { + Control control = controls[i]; + if (control.getData(MAINTAIN_SIZE) != null) { + width = fixedSize; + if (width > area.width) { + width = area.width - DEFAULT_SASH_WIDTH; + } + control.setBounds(x, area.y, width, area.height); + x += width + DEFAULT_SASH_WIDTH; + } else { + width = Math.max(area.width - fixedSize - DEFAULT_SASH_WIDTH, 0); + control.setBounds(x, area.y, width, area.height); + x += (width + DEFAULT_SASH_WIDTH); + } + } + if (sashes.length > 0) + sashes[0].setBounds(controls[0].getBounds().x + controls[0].getBounds().width, area.y, DEFAULT_SASH_WIDTH, area.height); + } + + // @Override + // public void setOrientation(int orientation) { + // if (this.orientation == orientation) + // return; + // if (orientation != SWT.HORIZONTAL && orientation != SWT.VERTICAL) { + // SWT.error(SWT.ERROR_INVALID_ARGUMENT); + // } + // this.orientation = orientation; + // + // int sashOrientation = (orientation == SWT.HORIZONTAL) ? SWT.VERTICAL : SWT.HORIZONTAL; + // for (int i = 0; i < sashes.length; i++) { + // sashes[i].dispose(); + // sashes[i] = new Sash(this, sashOrientation); + // sashes[i].setBackground(ColorConstants.buttonLightest); + // sashes[i].addListener(SWT.Selection, sashListener); + // } + // layout(); + // } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/PreviewViewer.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/PreviewViewer.java new file mode 100644 index 0000000..5ae387e --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/PreviewViewer.java @@ -0,0 +1,554 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.texteditor.preview; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.draw2d.FigureCanvas; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.gef.EditDomain; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.ui.parts.ScrollingGraphicalViewer; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.ui.IEditorInput; +import org.tizen.efluibuilder.core.configuration.device.Device; +import org.tizen.efluibuilder.gef.layers.CustomLayerConstants; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.IPartChangedListener; +import org.tizen.efluibuilder.model.part.MScreenPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartMutation; +import org.tizen.efluibuilder.model.part.PartObserver; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.part.ViewPart; +import org.tizen.efluibuilder.model.util.ModelConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.mscreen.configurator.IScreenConfigurationSelectionChangedListener; +import org.tizen.efluibuilder.mscreen.configurator.MScreenQualifierManager; +import org.tizen.efluibuilder.mscreen.configurator.MscreenConstants; +import org.tizen.efluibuilder.renderer.Position; +import org.tizen.efluibuilder.ui.editor.IProjectResourceFileChangeListener; +import org.tizen.efluibuilder.ui.editor.texteditor.TextEditor; +import org.tizen.efluibuilder.ui.editor.texteditor.preview.editparts.PreviewEditPartFactory; +import org.tizen.efluibuilder.ui.editor.texteditor.preview.editparts.PreviewRootEditPart; +import org.tizen.efluibuilder.ui.editor.texteditor.preview.editparts.UIComponentEditPart; +import org.tizen.efluibuilder.ui.editor.texteditor.preview.figures.DeviceImageFigure; +import org.tizen.efluibuilder.ui.editor.texteditor.preview.figures.PreviewImageFigure; +import org.tizen.efluibuilder.ui.resources.ColorResources; + +import graphicalDataManager.ComponentGraphicalData; +import graphicalDataManager.GraphicalDataChangedEvent; +import graphicalDataManager.GraphicalDataInitializeFailedException; +import graphicalDataManager.GraphicalDataManager; +import graphicalDataManager.IGraphicalDataChangedListener; + + +public final class PreviewViewer extends ScrollingGraphicalViewer implements Listener, IGraphicalDataChangedListener, + IScreenConfigurationSelectionChangedListener, ISelectionChangedListener, IPartChangedListener, IProjectResourceFileChangeListener { + + private int PADDING_SIZE = 100; + private GraphicalDataManager graphicalDataManager = null; + private MScreenQualifierManager screenQualifierMgr = null; + private EditPart currentActivatedViewEditPart = null; + private TextEditor parentEditor = null; + + private Device currentDevice = null; + private String currentOrientation = null; + private String currentLocale = null; + + private PartObserver observer = null; + private boolean enabled = true; + + public PreviewViewer(TextEditor parentEditor) { + this.parentEditor = parentEditor; + + this.setEditPartFactory(new PreviewEditPartFactory()); + } + + public void initContents(Part documentPart, IEditorInput editorInput, EditDomain editDomain, GraphicalDataManager graphicalDataManager) { + this.observer = new PartObserver(this); + observer.observe(documentPart); + + setEditDomain(editDomain); + + createMScreenQualifierManager(editorInput, documentPart); + setGraphicalDataManager(graphicalDataManager); + setContents(documentPart); + + reqNewPageGraphicData(); + + updateDeviceSize(); + updateViewLocation(); + updateAutoZoom(); + + addSelectionChangedListener(this); + } + + private void createMScreenQualifierManager(IEditorInput editorInput, Part documentPart) { + Part doc = documentPart; + for (Part part : doc.getChildren()) { + if (part instanceof MScreenPart) { + screenQualifierMgr = new MScreenQualifierManager((MScreenPart) part, editorInput); + screenQualifierMgr.addConfigureSelectionChangedListener(this); + } + } + + currentDevice = screenQualifierMgr.getCurrentDevice(); + currentOrientation = screenQualifierMgr.getCurrentOrientation(); + currentLocale = screenQualifierMgr.getCurrentLocale(); + } + + private void reqNewPageGraphicData(boolean bForce) { + if ((graphicalDataManager != null) && (this.getCurrentViewPart() != null)) { + try { + ComponentGraphicalData graphicalData = + graphicalDataManager.getGraphicalData(getCurrentViewPart().getUniqueId(), currentDevice, currentOrientation, currentLocale, bForce); + if (graphicalData != null) { + if (graphicalData.imageDescriptor != null) { + this.updatePageImageData(graphicalData.imageDescriptor); + } + + if (graphicalData.componentPositionMap != null) { + this.updataPageComponentPositions(graphicalData.componentPositionMap); + } + } + } catch (GraphicalDataInitializeFailedException e) { + // TODO : IMPL + } + } + } + + private void reqNewPageGraphicData() { + reqNewPageGraphicData(false); + } + + private void bindToGraphicalDataManager() { + if (this.graphicalDataManager != null) { + this.graphicalDataManager.addEventListener(this); + } + } + + private void unbindFromGraphicalDataManager() { + if (this.graphicalDataManager != null) { + this.graphicalDataManager.removeEventListener(this); + this.graphicalDataManager = null; + } + } + + private void updateDeviceSize() { + Point screenSize = this.getCurrentScreenSize(); + int width = screenSize.x; + int height = screenSize.y; + + DeviceImageFigure deviceFigure = (DeviceImageFigure) ((UIComponentEditPart) getContents()).getFigure(); + deviceFigure.setViewBounds(new org.eclipse.draw2d.geometry.Rectangle(0, 0, width, height)); + deviceFigure.setProfile(getProfile()); + } + + private void setPaddingSizeByDeviceCondition() { + String calculatedDeviceName = currentDevice.getName().toLowerCase(); + if (calculatedDeviceName.contains(ModelConstants.SHAPE_SQUARE) || calculatedDeviceName.contains(ModelConstants.SHAPE_CIRCLE)) { + PADDING_SIZE = 100; + } else { + PADDING_SIZE = 300; + } + } + + private void updateViewLocation() { + if (getControl() == null) + return; + Point screenSize = this.getCurrentScreenSize(); + int srcW = screenSize.x; + int srcH = screenSize.y; + int dstW = getControl().getSize().x; + int dstH = getControl().getSize().y; + + PreviewRootEditPart rootEditPart = (PreviewRootEditPart) getRootEditPart(); + + if (rootEditPart != null) { + rootEditPart.updateBrowserSize(srcW, srcH, dstW, dstH); + + Rectangle editorBound = new Rectangle(0, 0, dstW, dstH); + double zoomValue = rootEditPart.getZoomManager().getZoom(); + int x = 0, y = 0; + + x = (int) ((zoomValue * srcW - editorBound.width) / 2); + y = (int) ((zoomValue * srcH - editorBound.height) / 2); + rootEditPart.getZoomManager().setViewLocation(new Point(x, y)); + } + } + + public void updateAutoZoom() { + setPaddingSizeByDeviceCondition(); + + Point screenSize = this.getCurrentScreenSize(); + int srcW = screenSize.x + PADDING_SIZE; + int srcH = screenSize.y + PADDING_SIZE; + int dstW = getControl().getSize().x; + int dstH = getControl().getSize().y; + if ((dstW != 0) || (dstH != 0)) { + double zoomValue = (double) dstW / (double) srcW; + if (srcH * zoomValue > dstH) { + zoomValue = (double) dstH / (double) srcH; + } + ((PreviewRootEditPart) getRootEditPart()).getZoomManager().setZoom(zoomValue); + } + } + + private void setGraphicalDataManager(GraphicalDataManager graphicalDataManager) { + if (this.graphicalDataManager != null) { + this.unbindFromGraphicalDataManager(); + } + this.graphicalDataManager = graphicalDataManager; + this.bindToGraphicalDataManager(); + } + + @Override + protected void handleDispose(DisposeEvent e) { + removeSelectionChangedListener(this); + unbindFromGraphicalDataManager(); + super.handleDispose(e); + } + + @Override + protected void createDefaultRoot() { + setRootEditPart(new PreviewRootEditPart()); + } + + @Override + public void setContents(Object contents) { + Part viewsPart = PartUtil.findViewsPart((Part) contents); + super.setContents(viewsPart); + + // FIXME + if (getRootEditPart().getContents().getChildren().isEmpty() == false) { + currentActivatedViewEditPart = (EditPart) getRootEditPart().getContents().getChildren().get(0); + } + } + + public void setInitCurrentActivatedView() { + if (getRootEditPart().getContents().getChildren().contains(currentActivatedViewEditPart) == false) { + currentActivatedViewEditPart = (EditPart) getRootEditPart().getContents().getChildren().get(0); + this.reqNewPageGraphicData(); + } + } + + @Override + public void setControl(Control control) { + super.setControl(control); + + if (control != null) { + control.setBackground(ColorResources.PREVIEW_BACKGROUND); + control.addListener(SWT.Resize, this); + + this.addSelectionChangedListener(new ISelectionChangedListener() { + + @Override + public void selectionChanged(SelectionChangedEvent event) { + for (Object child : ((StructuredSelection) event.getSelection()).toList()) { + EditPart editPart = (EditPart) child; + Part part = (Part) editPart.getModel(); + Part viewPart; + viewPart = PartUtil.findViewPart(part); + if (viewPart != null) { + EditPart newViewEdit = (EditPart) getEditPartRegistry().get(viewPart.getUniqueId()); + if (!newViewEdit.equals(currentActivatedViewEditPart) + && ((Part) newViewEdit.getModel()).getParent() != null // prevent + // dangling + ) { + if (currentActivatedViewEditPart != null) { + ((UIComponentEditPart) currentActivatedViewEditPart).getFigure().setVisible(false); + } + currentActivatedViewEditPart = newViewEdit; + reqNewPageGraphicData(); + } + break; + } + } + } + }); + } + } + + @Override + public void handleEvent(Event event) { + if (SWT.Resize == event.type) { + updateAutoZoom(); + updateDeviceSize(); + updateViewLocation(); + } + } + + private UIComponentEditPart getCurrentViewEditPart() { + return (UIComponentEditPart) currentActivatedViewEditPart; + } + + private Part getCurrentViewPart() { + UIComponentEditPart viewEditPart = this.getCurrentViewEditPart(); + if (viewEditPart != null) { + return (Part) viewEditPart.getModel(); + } + return null; + } + + private boolean isMyGraphicalData(GraphicalDataChangedEvent event) { + UIComponentEditPart viewEditPart = this.getCurrentViewEditPart(); + if (viewEditPart != null) { + Part viewPart = (Part) viewEditPart.getModel(); + if (viewPart.getUniqueId().equals(event.viewId) && event.deviceName.equals(currentDevice.getName()) && event.orientation.equals(currentOrientation) + && event.locale.equals(currentLocale)) { + return true; + } + } + return false; + } + + private void updatePageImageData(ImageDescriptor imageDescriptor) { + UIComponentEditPart viewEditPart = this.getCurrentViewEditPart(); + ((PreviewImageFigure) viewEditPart.getFigure()).setImageDescriptor(imageDescriptor); + } + + private void updataPageComponentPositions(final Map componentPositionMap) { + final UIComponentEditPart viewEditPart = getCurrentViewEditPart(); + // TODO Need to check what is viewEditPart + Display.getDefault().syncExec(new Runnable() { + public void run() { + if (null != viewEditPart) { + PreviewImageFigure figure = (PreviewImageFigure) viewEditPart.getFigure(); + figure.setVisible(false); // To refresh a ViewFigure (false -> true) + updateComponentPosition(viewEditPart, componentPositionMap, true); + + figure.setVisible(true); + } + } + }); + } + + private void updateComponentPosition(UIComponentEditPart editPart, Map componentPositionMap, boolean isFireEvent) { + if (editPart != null) { + Part part = (Part) editPart.getModel(); + if (part.getUniqueId() != null && !part.getUniqueId().isEmpty()) { + Position componentPosition = componentPositionMap.get(part.getUniqueId()); + if (componentPosition != null) { + editPart.setPosition(componentPosition); + editPart.refresh(); + } + } + + List children = editPart.getChildren(); + for (int i = 0; i < children.size(); i++) { + UIComponentEditPart childEditPart = (UIComponentEditPart) children.get(i); + updateComponentPosition(childEditPart, componentPositionMap, isFireEvent); + } + } + } + + private void handleComponentImageDataChanged(GraphicalDataChangedEvent event) { + if (isMyGraphicalData(event) == true) { + this.updatePageImageData(event.graphicData.imageDescriptor); + } + } + + private void handleComponentPositionDataChanged(GraphicalDataChangedEvent event) { + if (isMyGraphicalData(event) == true) { + updataPageComponentPositions(event.graphicData.componentPositionMap); + } + } + + @Override + public void componentImageDataChanged(GraphicalDataChangedEvent event) { + this.handleComponentImageDataChanged(event); + } + + @Override + public void componentPositionDataChanged(GraphicalDataChangedEvent event) { + this.handleComponentPositionDataChanged(event); + + } + + @Override + public void placeholderPositionDataChanged(GraphicalDataChangedEvent event) { + } + + public String getProfile() { + if (currentDevice != null) { + return currentDevice.getName().toLowerCase(); + } + return ""; + } + + private Point getCurrentScreenSize() { + if (currentDevice == null) { + return new Point(1, 1); + } + if (currentOrientation.equals(MscreenConstants.ORIENTATION_PORTRAIT)) { + return new Point(currentDevice.getWidth(), currentDevice.getHeight()); + } else { + return new Point(currentDevice.getHeight(), currentDevice.getWidth()); + } + } + + public MScreenQualifierManager getScreenQualifierManager() { + return this.screenQualifierMgr; + } + + public void reqNewPageGraphicDataFromQualifiers(Device device, String orientation, String locale) { + if (device == null || orientation == null || locale == null) { + return; + } + currentDevice = device; + currentOrientation = orientation; + currentLocale = locale; + + updateAutoZoom(); + + updateDeviceSize(); + updateViewLocation(); + this.reqNewPageGraphicData(); + + } + + @Override + public void configurationSelected(MScreenQualifierManager mscreenManager) { + this.reqNewPageGraphicData(); + } + + @Override + public void selectionChanged(SelectionChangedEvent event) { + StructuredSelection selection = (StructuredSelection) event.getSelection(); + // Must have to check size of selection + if (selection.size() == 1) { + EditPart editPart = (EditPart) selection.getFirstElement(); + + // FIXED: If remove a selected part, the cursor of TextEditor is moved suddenly + // because selection was changed to parent. + if (editPart != null) { + Object model = editPart.getModel(); + if (model instanceof Part) { + int type = ((Part) model).getType(); + if (type == PartType.COMPONENT || type == PartType.VIEW) { + parentEditor.setSelection((Part) editPart.getModel()); + } + } + } + } + } + + @Override + public void partsChanged(List mutations, PartObserver observer, String sender) { + if (sender.equals(PartObserver.MESSAGE_VALID_XML)) { + setEnabled(true); + } else if (sender.equals(PartObserver.MESSAGE_INVALID_XML)) { + setEnabled(false); + return; + } + + Map partMapToRefresh = new HashMap(); + boolean isViewChanged = false; + + for (PartMutation mutation : mutations) { + String mutationType = mutation.getType(); + if (mutationType.equals(PartMutation.PARTS_ADDED)) { + for (Part part : mutation.getAddedParts()) { + if (part instanceof ViewPart) { + isViewChanged = true; + break; + } + } + } else if (mutationType.equals(PartMutation.PARTS_REMOVED)) { + for (Part part : mutation.getRemovedParts()) { + if (part instanceof ViewPart) { + isViewChanged = true; + break; + } + } + } + if (mutationType.equals(PartMutation.PARTS_ADDED) || + mutationType.equals(PartMutation.PARTS_REMOVED) + || mutationType.equals(PartMutation.PARTS_ORDER_CHANGED)) { + if (mutation.getTargetPart() instanceof ComponentPart) { + partMapToRefresh.put(mutation.getTargetPart(), ""); + } + } + } + + if (isViewChanged) { + getContents().refresh(); + } + for (Part child : partMapToRefresh.keySet()) { + UIComponentEditPart editPart = (UIComponentEditPart) getEditPartRegistry().get(child.getUniqueId()); + if (editPart != null) { + refreshEditPart(editPart); + } + } + reqNewPageGraphicData(); + } + + @Override + public void projectResourceFileChanged(ArrayList changedFiles) { + // TODO FIXME + this.reqNewPageGraphicData(); + + } + + private void refreshEditPart(EditPart editPart) { + editPart.refresh(); + List children = editPart.getChildren(); + for (int i = 0; i < children.size(); i++) { + UIComponentEditPart childEditPart = (UIComponentEditPart) children.get(i); + refreshEditPart(childEditPart); + } + + } + + public Device getCurrentDevice() { + return currentDevice; + } + + public void setEnabled(boolean enabled) { + if (this.enabled == enabled) { + return; + } + this.enabled = enabled; + getLayerManager().getLayer(CustomLayerConstants.BLOCK_LAYER).setVisible(!enabled); + getControl().setEnabled(enabled); + parentEditor.setPreviewToolbarEnabled(enabled); + int isScrollBarShown = enabled ? FigureCanvas.AUTOMATIC : FigureCanvas.NEVER; + this.getFigureCanvas().setScrollBarVisibility(isScrollBarShown); + } + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/editparts/PreviewEditPartFactory.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/editparts/PreviewEditPartFactory.java new file mode 100644 index 0000000..c87c36d --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/editparts/PreviewEditPartFactory.java @@ -0,0 +1,49 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.texteditor.preview.editparts; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPartFactory; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; + + +public class PreviewEditPartFactory implements EditPartFactory { + + @Override + public EditPart createEditPart(EditPart context, Object model) { + UIComponentEditPart retValue = null; + if (model instanceof Part) { + Part partModel = (Part) model; + + if (partModel.getType() == PartType.VIEWS || partModel.getType() == PartType.VIEW || partModel.getType() == PartType.COMPONENT) { + retValue = new UIComponentEditPart(); + retValue.setModel(model); + } + + } + + return retValue; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/editparts/PreviewRootEditPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/editparts/PreviewRootEditPart.java new file mode 100644 index 0000000..9258828 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/editparts/PreviewRootEditPart.java @@ -0,0 +1,91 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.texteditor.preview.editparts; + +import org.eclipse.draw2d.DelegatingLayout; +import org.eclipse.draw2d.FigureCanvas; +import org.eclipse.draw2d.Layer; +import org.eclipse.draw2d.LayeredPane; +import org.eclipse.draw2d.ScalableFreeformLayeredPane; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.editparts.ScalableFreeformRootEditPart; +import org.tizen.efluibuilder.gef.editparts.utility.VirtualLayer; +import org.tizen.efluibuilder.gef.layers.BlockLayer; +import org.tizen.efluibuilder.gef.layers.CustomLayerConstants; +import org.tizen.efluibuilder.ui.editor.ZoomUtil; + + +public class PreviewRootEditPart extends ScalableFreeformRootEditPart { + + private static final String NAME_VIRTUAL_LAYER = "virtual"; + + public PreviewRootEditPart() { + super(); + getZoomManager().setZoomLevels(ZoomUtil.zoomLevels); + ((BlockLayer)getLayer(CustomLayerConstants.BLOCK_LAYER)).setViewPort(getZoomManager().getViewport()); + } + + @Override + protected void createLayers(LayeredPane layeredPane) { + super.createLayers(layeredPane); + + BlockLayer blockLayer = new BlockLayer(); + blockLayer.setVisible(false); + layeredPane.add(blockLayer, CustomLayerConstants.BLOCK_LAYER); + + Layer layer = (Layer) getLayer(HANDLE_LAYER); + layer.setLayoutManager(new DelegatingLayout()); + } + + @Override + protected ScalableFreeformLayeredPane createScaledLayers() { + ScalableFreeformLayeredPane layers = super.createScaledLayers(); + VirtualLayer layer = new VirtualLayer(); + layers.add(layer, NAME_VIRTUAL_LAYER); + return layers; + } + + public void updateBrowserSize(int srcW, int srcH, int dstW, int dstH) { + VirtualLayer virtualLayer = (VirtualLayer) getLayer(NAME_VIRTUAL_LAYER); + Rectangle bounds = new Rectangle(-(srcW / 2), -(srcH / 2), srcW * 2, srcH * 2); + virtualLayer.setVirtualSize(bounds); + virtualLayer.revalidate(); + virtualLayer.repaint(); + getScaledLayers().revalidate(); + } + + public void updateScrollbar(int srcW, int srcH, int dstW, int dstH) { + Rectangle contentBounds = new Rectangle(0, 0, srcW, srcH); + contentBounds.performScale(getZoomManager().getZoom()); + + FigureCanvas canvas = (FigureCanvas) getViewer().getControl(); + if ((dstW < contentBounds.width()) || (dstH < contentBounds.height())) { + canvas.setHorizontalScrollBarVisibility(FigureCanvas.AUTOMATIC); + canvas.setVerticalScrollBarVisibility(FigureCanvas.AUTOMATIC); + } else { + canvas.setHorizontalScrollBarVisibility(FigureCanvas.NEVER); + canvas.setVerticalScrollBarVisibility(FigureCanvas.NEVER); + } + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/editparts/UIComponentEditPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/editparts/UIComponentEditPart.java new file mode 100644 index 0000000..bc1a9c5 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/editparts/UIComponentEditPart.java @@ -0,0 +1,151 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.texteditor.preview.editparts; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.gef.Disposable; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPartViewer; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.editparts.AbstractGraphicalEditPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.ViewPart; +import org.tizen.efluibuilder.model.part.ViewsPart; +import org.tizen.efluibuilder.renderer.Position; +import org.tizen.efluibuilder.ui.editor.texteditor.preview.PreviewViewer; +import org.tizen.efluibuilder.ui.editor.texteditor.preview.figures.DeviceImageFigure; +import org.tizen.efluibuilder.ui.editor.texteditor.preview.figures.PreviewImageFigure; +import org.tizen.efluibuilder.ui.editor.texteditor.preview.figures.ProfileFigure; +import org.tizen.efluibuilder.ui.editor.texteditor.preview.figures.UIComponentFigure; +import org.tizen.efluibuilder.ui.editor.texteditor.preview.policies.PreviewSelectionPolicy; + + +public class UIComponentEditPart extends AbstractGraphicalEditPart { + + Position position = null; + + @Override + public void activate() { + super.activate(); + } + + @Override + public void deactivate() { + IFigure iFigure = getFigure(); + if (iFigure instanceof Disposable) { + ((Disposable) iFigure).dispose(); + } + + super.deactivate(); + } + + @Override + protected IFigure createFigure() { + Part part = (Part) getModel(); + if (part instanceof ViewsPart) { + DeviceImageFigure figure = new DeviceImageFigure(); + figure.setProfile(((PreviewViewer) getViewer()).getProfile()); + return figure; + } else if (part instanceof ViewPart) { + return new PreviewImageFigure(); + } else { + return new UIComponentFigure(); + } + } + + private String getId() { + Part part = ((Part) getModel()); + if (part != null) { + return part.getUniqueId(); + } else { + return null; + } + } + + @SuppressWarnings("unchecked") + @Override + protected void registerModel() { + getViewer().getEditPartRegistry().put(getId(), this); + } + + @Override + protected void createEditPolicies() { + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new PreviewSelectionPolicy()); + } + + @Override + protected List getModelChildren() { + if (getModel() instanceof Part) { + return ((Part) getModel()).getComponentChildren(); + } + return new ArrayList(); + } + + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + + IFigure figure = getFigure(); + if (figure != null && position != null) + figure.setBounds(position.getBounds()); + + if (figure instanceof ProfileFigure) { + // FIXED: NPE problem. viewer can be null. + EditPartViewer viewer = getViewer(); + if (viewer instanceof PreviewViewer) { + ((ProfileFigure) figure).setProfile(((PreviewViewer) viewer).getProfile()); + } + } + } + + @Override + public void setSelected(int value) { + super.setSelected(value); + + if (getFigure() instanceof UIComponentFigure) { + UIComponentFigure figure = (UIComponentFigure) getFigure(); + boolean bSelected = false; + if (value != EditPart.SELECTED_NONE) + bSelected = true; + figure.setSelect(bSelected); + figure.repaint(); + } + } + + public Position getPosition() { + return position; + } + + public void setPosition(Position position) { + this.position = position; + } + + @Override + public boolean isSelectable() { + return true; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/figures/DeviceImageFigure.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/figures/DeviceImageFigure.java new file mode 100644 index 0000000..fea61fe --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/figures/DeviceImageFigure.java @@ -0,0 +1,87 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.texteditor.preview.figures; + +import org.eclipse.draw2d.FreeformLayer; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.tizen.efluibuilder.ui.resources.ImageResources; + + +public class DeviceImageFigure extends FreeformLayer { + private Rectangle viewBounds = null; + private String profile = null; + + public void setViewBounds(Rectangle bounds) { + viewBounds = bounds; + repaint(); + } + + @Override + protected void paintFigure(Graphics graphics) { + graphics.pushState(); + if (ImageFigureConstants.WEARABLE_CIRCLE_DPI.equals(profile)) { + paintWearableMobile(graphics, ImageResources.PREVIEW_CIRCLE); + } else if (ImageFigureConstants.WEARABLE_RECTANGLE_HDPI_DPI.equals(profile)) { + paintWearableMobile(graphics, ImageResources.PREVIEW_WEARABLE_RECT_320); + } else if (ImageFigureConstants.WEARABLE_RECTANGLE_MDPI_DPI.equals(profile)) { + paintWearableMobile(graphics, ImageResources.PREVIEW_WEARABLE_RECT_360); + } else if (ImageFigureConstants.MOBILE_HD_DPI.equals(profile)) { + if (viewBounds.width() <= viewBounds.height()) { + paintWearableMobile(graphics, ImageResources.PREVIEW_MOBILE_HD_PORTRAIT); + } else { + paintWearableMobile(graphics, ImageResources.PREVIEW_MOBILE_HD_LANDSCAPE); + } + } else if (ImageFigureConstants.MOBILE_WVGA_DPI.equals(profile)) { + if (viewBounds.width() <= viewBounds.height()) { + paintWearableMobile(graphics, ImageResources.PREVIEW_MOBILE_WVGA_PORTRAT); + } else { + paintWearableMobile(graphics, ImageResources.PREVIEW_MOBILE_WVGA_LANDSCAPE); + + } + } + + graphics.popState(); + } + + private void paintWearableMobile(Graphics graphics, String imageResourcePath) { + if (viewBounds == null) { + return; + } + graphics.setAntialias(SWT.ON); + Image backgroundImage = ImageResources.getImage(imageResourcePath); + if (backgroundImage != null) { + int destX = -(backgroundImage.getImageData().width - viewBounds.width()) / 2; + int destY = -(backgroundImage.getImageData().height - viewBounds.height()) / 2; + graphics.drawImage(backgroundImage, destX, destY); + } + } + + public void setProfile(String profile) { + this.profile = profile; + } + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/figures/ImageFigureConstants.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/figures/ImageFigureConstants.java new file mode 100644 index 0000000..9030578 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/figures/ImageFigureConstants.java @@ -0,0 +1,32 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.texteditor.preview.figures; + +public class ImageFigureConstants { + public static final String WEARABLE_CIRCLE_DPI = "circle_360x360";//$NON-NLS-1$ + public static final String WEARABLE_RECTANGLE_HDPI_DPI = "square_320x320";//$NON-NLS-1$ + public static final String WEARABLE_RECTANGLE_MDPI_DPI = "square_360x480";//$NON-NLS-1$ + public static final String MOBILE_HD_DPI = "hd";//$NON-NLS-1$ + public static final String MOBILE_WVGA_DPI = "wvga";//$NON-NLS-1$ +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/figures/PreviewImageFigure.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/figures/PreviewImageFigure.java new file mode 100644 index 0000000..f8dc6ce --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/figures/PreviewImageFigure.java @@ -0,0 +1,74 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.texteditor.preview.figures; + +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.Disposable; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Path; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.utility.CachedImage; +import org.tizen.efluibuilder.utility.ImageUtil; + + +public class PreviewImageFigure extends ProfileFigure implements Disposable { + + private Logger logger = LoggerFactory.getLogger(this.getClass()); + + private ImageDescriptor imageDescriptor = null; + private final CachedImage cache = new CachedImage(); + + public void setImageDescriptor(ImageDescriptor imageDescriptor) { + this.imageDescriptor = imageDescriptor; + } + + @Override + protected void paintFigure(Graphics graphics) { + if (imageDescriptor == null) { + return; + } + + Image image = this.cache.get(imageDescriptor); + if (image == null) { + logger.error(this.getClass().getName() + " image is not created."); + return; + } + + graphics.pushState(); + if (getProfile().equals(ImageFigureConstants.WEARABLE_CIRCLE_DPI)) { + Path circlePath = ImageUtil.createCirclePath(getBounds().x, getBounds().y, getBounds().width(), getBounds().height()); + graphics.clipPath(circlePath); + } + graphics.drawImage(image, new Rectangle(image.getBounds()), getBounds()); + graphics.popState(); + } + + @Override + public void dispose() { + this.cache.dispose(); + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/figures/ProfileFigure.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/figures/ProfileFigure.java new file mode 100644 index 0000000..b6d4bf4 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/figures/ProfileFigure.java @@ -0,0 +1,40 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.texteditor.preview.figures; + +import org.eclipse.draw2d.Figure; + + +public abstract class ProfileFigure extends Figure { + + private String devProfile = null; + + public void setProfile(String devProfile) { + this.devProfile = devProfile; + } + + protected String getProfile() { + return this.devProfile; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/figures/UIComponentFigure.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/figures/UIComponentFigure.java new file mode 100644 index 0000000..bf01966 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/figures/UIComponentFigure.java @@ -0,0 +1,55 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.texteditor.preview.figures; + +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.Figure; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.geometry.Rectangle; + + +public class UIComponentFigure extends Figure { + + boolean isSelected = false; + + public void setSelect(boolean value) { + this.isSelected = value; + } + + @Override + protected void paintFigure(Graphics graphics) { + if (isSelected) { + graphics.setBackgroundColor(ColorConstants.black); + graphics.setLineStyle(Graphics.LINE_DOT); + graphics.setLineWidth(3); + Rectangle bounds = getBounds().getCopy(); + bounds.x += 2; + bounds.y += 2; + bounds.width -= 4; + bounds.height -= 4; + graphics.drawRectangle(bounds); + } + } + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/policies/PreviewSelectionPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/policies/PreviewSelectionPolicy.java new file mode 100644 index 0000000..073e006 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/preview/policies/PreviewSelectionPolicy.java @@ -0,0 +1,107 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.texteditor.preview.policies; + +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.RectangleFigure; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.editpolicies.SelectionEditPolicy; +import org.tizen.efluibuilder.ui.editor.texteditor.preview.editparts.PreviewRootEditPart; +import org.tizen.efluibuilder.ui.editor.texteditor.preview.figures.DeviceImageFigure; + + +public class PreviewSelectionPolicy extends SelectionEditPolicy { + + private RectangleFigure hoverFeedback; + + public PreviewSelectionPolicy() { + super(); + } + + @Override + public void activate() { + super.activate(); + + if (hoverFeedback == null) { + hoverFeedback = new RectangleFigure(); + hoverFeedback.setAlpha(50); + hoverFeedback.setFill(true); + hoverFeedback.setOutline(true); + hoverFeedback.setLineWidth(3); + hoverFeedback.setLineStyle(Graphics.LINE_DOT); + hoverFeedback.setBounds(new Rectangle(0, 0, 0, 0)); + hoverFeedback.setVisible(false); + hoverFeedback.setBackgroundColor(ColorConstants.blue); + getFeedbackLayer().add(hoverFeedback); + } + } + + @Override + public void deactivate() { + if (hoverFeedback != null) { + getFeedbackLayer().remove(hoverFeedback); + hoverFeedback = null; + } + super.deactivate(); + } + + @Override + public void showTargetFeedback(Request request) { + + GraphicalEditPart targetEditPart = (GraphicalEditPart) getHost(); + if (targetEditPart != null && targetEditPart.getFigure() != null) { + if (targetEditPart.getFigure() instanceof DeviceImageFigure) + return; + + Rectangle figureBounds = targetEditPart.getFigure().getBounds().getCopy(); + double zoomSize = ((PreviewRootEditPart) getHost().getRoot()).getZoomManager().getZoom(); + figureBounds.performScale(zoomSize); + hoverFeedback.setBounds(figureBounds); + hoverFeedback.setVisible(true); + } + return; + } + + @Override + public void eraseTargetFeedback(Request request) { + hoverFeedback.setVisible(false); + return; + } + + @Override + protected void hideSelection() { + // TODO Auto-generated method stub + + } + + @Override + protected void showSelection() { + // TODO Auto-generated method stub + + } + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/validation/LayoutSchemaProvider.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/validation/LayoutSchemaProvider.java new file mode 100644 index 0000000..52df703 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/validation/LayoutSchemaProvider.java @@ -0,0 +1,114 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.texteditor.validation; + +import java.io.File; +import java.net.URI; +import java.text.MessageFormat; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.URIUtil; +import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.IExternalSchemaLocationProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.BuilderPlugin; +import org.tizen.efluibuilder.model.app.AppManager; +import org.tizen.efluibuilder.utility.ResourceUtil; + + +@SuppressWarnings("restriction") +public class LayoutSchemaProvider implements IExternalSchemaLocationProvider { + protected final Logger logger = LoggerFactory.getLogger(getClass()); + + private final static String schemaFile = "layout.xsd"; //$NON-NLS-1$ + private final static String layoutFile = "layout.xml"; //$NON-NLS-1$ + + private boolean isLayoutFile(URI fileUri) { + String filename = new File(fileUri).getName(); + return layoutFile.equalsIgnoreCase(filename); + } + + private IProject getProjectFrom(URI fileUri) { + // find a folder in workspace + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IContainer[] containers = root.findContainersForLocationURI(fileUri); + if (containers.length == 0) { + return null; + } + + return containers[0].getProject(); + } + + private Map createLocationMap(URI uri) { + // FIXED: The URI argument type of Map MUST be String for XMLValidator. + Map value = new HashMap(); + value.put(SCHEMA_LOCATION, URIUtil.toUnencodedString(uri)); + value.put(NO_NAMESPACE_SCHEMA_LOCATION, URIUtil.toUnencodedString(uri)); + return value; + } + + @Override + public Map getExternalSchemaLocation(URI fileURI) { + // check 'layout.xml' + if (!isLayoutFile(fileURI)) { + return null; + } + + // find a project of 'layout.xml' + IProject project = getProjectFrom(fileURI); + if (project == null) { + String msg = MessageFormat.format("[{0}] Failed to find a project from URI: {1}", + getClass().getSimpleName(), fileURI); + logger.debug(msg); + return null; + } + + // find a schema file of the project from this plugin + String schemaLocation = AppManager.getAppManager(project).getSchemaLocation(); + if (schemaLocation == null) { + return null; + } + + // BugFix: Extract included schemas in Plugin + // TODO: If schemas will be moved to platform directory, remove this code. + ResourceUtil.getURI(BuilderPlugin.PLUGIN_ID, schemaLocation); + + IPath path = new Path(schemaLocation).append(schemaFile); + URI schemaFileURI = ResourceUtil.getURI(BuilderPlugin.PLUGIN_ID, path.toString()); + if (schemaFileURI == null) { + String msg = MessageFormat.format("[{0}] Failed to find a schema file from plugin: {1}", + getClass().getSimpleName(), path); + logger.debug(msg); + return null; + } + return createLocationMap(schemaFileURI.normalize()); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/validation/LayoutValidator.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/validation/LayoutValidator.java new file mode 100644 index 0000000..a114793 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/validation/LayoutValidator.java @@ -0,0 +1,283 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.texteditor.validation; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.URIUtil; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.wst.sse.core.StructuredModelManager; +import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; +import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; +import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; +import org.eclipse.wst.sse.ui.internal.reconcile.validator.ISourceValidator; +import org.eclipse.wst.validation.internal.core.Message; +import org.eclipse.wst.validation.internal.core.ValidationException; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; +import org.eclipse.wst.validation.internal.provisional.core.IReporter; +import org.eclipse.wst.validation.internal.provisional.core.IValidationContext; +import org.eclipse.wst.validation.internal.provisional.core.IValidator; +import org.eclipse.wst.xml.core.internal.validation.XMLValidationConfiguration; +import org.eclipse.wst.xml.core.internal.validation.XMLValidationReport; +import org.eclipse.wst.xml.core.internal.validation.XMLValidator; +import org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; + + +@SuppressWarnings("restriction") +public class LayoutValidator implements ISourceValidator, IValidator { + + private static Logger logger = LoggerFactory.getLogger(LayoutValidator.class); + + // Internal class + protected static class LocalizedMessage extends Message { + + private String _message = null; + + public LocalizedMessage(int severity, String messageText) { + this(severity, messageText, null); + } + + public LocalizedMessage(int severity, String messageText, IResource targetObject) { + this(severity, messageText, (Object) targetObject); + } + + public LocalizedMessage(int severity, String messageText, Object targetObject) { + super(null, severity, null); + setLocalizedMessage(messageText); + setTargetObject(targetObject); + } + + public void setLocalizedMessage(String message) { + _message = message; + } + + public String getLocalizedMessage() { + return _message; + } + + public String getText() { + return getLocalizedMessage(); + } + + public String getText(ClassLoader cl) { + return getLocalizedMessage(); + } + + public String getText(Locale l) { + return getLocalizedMessage(); + } + + public String getText(Locale l, ClassLoader cl) { + return getLocalizedMessage(); + } + } + + // Attributes + private static XMLValidator validator = new XMLValidator(); + private static XMLValidationConfiguration valConfig = new XMLValidationConfiguration(); + + /** + * Constructor + */ + static { + try { + validator.setURIResolver(new SchemaURIResolver()); + // FIXED: No grammar warning is shown always at first line. Remove it. + valConfig.setFeature(XMLValidationConfiguration.INDICATE_NO_GRAMMAR, 0); + + // FIXED: No document element warning is not shown always. Add it. + valConfig.setFeature(XMLValidationConfiguration.INDICATE_NO_DOCUMENT_ELEMENT, 1); + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + } + + @Override + public void connect(IDocument document) { + } + + @Override + public void disconnect(IDocument document) { + } + + public static synchronized XMLValidationReport validateXml(String uriPath, InputStream is) { + XMLValidationReport report = validator.validate(uriPath, is, valConfig); + logger.debug("Layout validation result: " + report.isValid()); + return report; + } + + public static List validateXml(IFile layoutMetaFile) { + List validationInfo = new ArrayList(); + String uriPath = URIUtil.toUnencodedString(layoutMetaFile.getLocationURI()); + IStructuredModel model = null; + InputStream is = null; + try { + model = StructuredModelManager.getModelManager().getModelForRead(layoutMetaFile); + IStructuredDocument structuredDoc = model.getStructuredDocument(); + String content = structuredDoc.get(); + is = new ByteArrayInputStream(content.getBytes()); + + XMLValidationReport report = validator.validate(uriPath, is, valConfig); + for (ValidationMessage message : report.getValidationMessages()) { + validationInfo.add(new ValidationInfo(message.getLineNumber(), message.getMessage())); + } + if (report.isValid()) { + String errorMsg = new NonSchemaBasedLayoutValidator().validate(structuredDoc); + if (errorMsg != null && errorMsg.isEmpty() == false) { + int offset = structuredDoc.getText().indexOf(LayoutSchemaConstants.MSCREEN); + validationInfo.add(new ValidationInfo(structuredDoc.getLineOfOffset(offset), errorMsg)); + } + } + } catch (IOException | CoreException e) { + logger.error(e.getMessage(), e); + } finally { + if(is != null) { + try { + is.close(); + } catch (IOException e) { + logger.error(e.getMessage(), e); + } + } + if (model != null) { + model.releaseFromRead(); + } + } + return validationInfo; + } + + @Override + public void validate(IRegion dirtyRegion, IValidationContext helper, IReporter reporter) { + } + + @Override + public void cleanup(IReporter reporter) { + reporter.removeAllMessages(this); + } + + @Override + public void validate(IValidationContext helper, IReporter reporter) throws ValidationException { + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + for (String uri : helper.getURIs()) { + String uriPath = "file://layout.xml"; // old default path + + // find current uri + IResource member = root.findMember(new Path(uri)); + IFile file = null; + if (member instanceof IFile) { + file = (IFile) member; + uriPath = URIUtil.toUnencodedString(file.getLocationURI()); + } else { + logger.warn("Stopped validation. URI is not file: " + uri); + continue; + } + + IStructuredModel model = null; + try { + // load model + model = StructuredModelManager.getModelManager().getModelForRead(file); + if (model == null) { + logger.error("Stopped validation. Cannot load structured model."); + continue; + } + + // convert to InputStream + IStructuredDocument structuredDoc = model.getStructuredDocument(); + String content = structuredDoc.get(); + final InputStream is = new ByteArrayInputStream(content.getBytes()); + + // validate + XMLValidationReport report = validateXml(uriPath, is); + + // add messages + for (ValidationMessage message : report.getValidationMessages()) { + // FIXED: When XML header was incorrect and then it is corrected, + // problem info is not hided. + IMessage m = new LocalizedMessage(IMessage.HIGH_SEVERITY, message.getMessage()); + + int docLine = structuredDoc.getNumberOfLines(); + int messageLine = message.getLineNumber(); + + IStructuredDocumentRegion region = null; + if (messageLine >= docLine) { + region = structuredDoc.getLastStructuredDocumentRegion(); + } else { + region = structuredDoc.getRegionAtCharacterOffset(structuredDoc.getLineOffset(messageLine) - 2); + } + int startOffset = region != null ? region.getStartOffset() : 0; + int length = region != null ? region.getLength() : 0; + m.setOffset(startOffset); + m.setLength(length); + m.setLineNo(messageLine); + + logger.debug(MessageFormat.format("[Line: {0}, Offset: {1}, Length: {2}] {3}", + m.getLineNumber(), + m.getOffset(), + m.getLength(), + m.getText())); + reporter.addMessage(this, m); + } + + if (report.isValid()) { + String errorMsg = new NonSchemaBasedLayoutValidator().validate(structuredDoc); + if (errorMsg != null && errorMsg.isEmpty() == false) { + IMessage m = new LocalizedMessage(IMessage.HIGH_SEVERITY, errorMsg); + int offset = structuredDoc.getText().indexOf(LayoutSchemaConstants.MSCREEN); + IStructuredDocumentRegion region = structuredDoc.getRegionAtCharacterOffset(offset); + m.setOffset(region.getStartOffset()); + m.setLength(region.getLength()); + m.setLineNo(structuredDoc.getLineOfOffset(offset)); + reporter.addMessage(this, m); + } + } + } catch (IOException e) { + logger.error(e.getMessage(), e); + } catch (CoreException e) { + logger.error(e.getMessage(), e); + } catch (BadLocationException e) { + logger.error(e.getMessage(), e); + } finally { + if (model != null) { + model.releaseFromRead(); + } + } + } + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/validation/Messages.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/validation/Messages.java new file mode 100644 index 0000000..1313d4b --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/validation/Messages.java @@ -0,0 +1,40 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.texteditor.validation; + +import org.eclipse.osgi.util.NLS; + + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.tizen.efluibuilder.ui.editor.texteditor.validation.messages"; //$NON-NLS-1$ + public static String NonSchemaBasedLayoutValidator_DuplicatedCommonType; + public static String NonSchemaBasedLayoutValidator_NoCommonType; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/validation/NonSchemaBasedLayoutValidator.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/validation/NonSchemaBasedLayoutValidator.java new file mode 100644 index 0000000..b31163d --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/validation/NonSchemaBasedLayoutValidator.java @@ -0,0 +1,117 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.texteditor.validation; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.eclipse.jface.text.IDocument; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + + +public class NonSchemaBasedLayoutValidator { + + private Logger logger = LoggerFactory.getLogger(this.getClass()); + + private Document getDocument(IDocument doc) throws SAXException, IOException, ParserConfigurationException { + DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + InputStream bais = new ByteArrayInputStream(doc.get().getBytes()); + return docBuilder.parse(bais); + } + + private Element[] getElement(Element parent, String tagName) { + NodeList nodeList = parent.getElementsByTagName(tagName); + + int length = nodeList.getLength(); + + Element[] childs = new Element[length]; + for (int i = 0; i < length; i++) { + childs[i] = (Element) nodeList.item(i); + } + + return childs; + } + + private boolean hasAttributeValue(Element element, String attr, String value) { + return value.equals(element.getAttribute(attr)); + } + + public String validate(IDocument doc) { + Document document = null; + try { + document = getDocument(doc); + } catch (SAXException e) { + logger.error(e.getMessage(), e); + return null; // In this case, XML structure is broken. + } catch (IOException e) { + logger.error(e.getMessage(), e); + return null; // In this case, XML structure is broken. + } catch (ParserConfigurationException e) { + logger.error(e.getMessage(), e); + return null; + } + + // + Element documentElement = document.getDocumentElement(); + /* documentElement is not null by schema based validation */ + + // + Element[] mscreenElements = getElement(documentElement, LayoutSchemaConstants.MSCREEN); + /* mscreenElements has at least one mscreen element by schema based validation */ + + // + Element[] configElements = getElement(mscreenElements[0], LayoutSchemaConstants.CONFIGURATION); + /* configElements has at least one configuration element by schema based validation */ + + // POLICY: Children of mscreen MUST have a configuration with a common type attribute. + boolean hasCommonConfiguration = false; + for (Element configElement : configElements) { + if (hasAttributeValue(configElement, + LayoutSchemaConstants.TYPE, + LayoutSchemaConstants.CONFIGURATION_TYPE_COMMON)) { + if (hasCommonConfiguration) { // if has common type already + return Messages.NonSchemaBasedLayoutValidator_DuplicatedCommonType; + } + hasCommonConfiguration = true; + } + } + if (hasCommonConfiguration == false) { // if no common type + return Messages.NonSchemaBasedLayoutValidator_NoCommonType; + } + + return ""; // No error + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/validation/SchemaURIResolver.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/validation/SchemaURIResolver.java new file mode 100644 index 0000000..4ce9bcf --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/validation/SchemaURIResolver.java @@ -0,0 +1,62 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.texteditor.validation; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +@SuppressWarnings("restriction") +public final class SchemaURIResolver implements URIResolver { + + protected final Logger logger = LoggerFactory.getLogger(getClass()); + private String SCHEMA_EXTENSION = ".xsd"; + + @Override + public String resolve(String baseLocation, String publicId, String systemId) { + // baseLocation is the location of the resource that contains the uri + // systemId is relative path for xsd that is included in baseLocation + if (baseLocation == null) { + return null; + } + + if (!baseLocation.contains(SCHEMA_EXTENSION)) { + return null; + } + IPath path = new Path(baseLocation); + IPath xsdDirectory = path.removeLastSegments(1); // get directory's absolute path from + // paramString1 + IPath absolutePath = xsdDirectory.append(systemId); + + return absolutePath.toString(); + } + + @Override + public String resolvePhysicalLocation(String baseLocation, String publicId, String systemId ) { + // just return systemId + return systemId; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/validation/ValidationInfo.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/validation/ValidationInfo.java new file mode 100644 index 0000000..ea23abc --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/validation/ValidationInfo.java @@ -0,0 +1,34 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.texteditor.validation; + +public class ValidationInfo { + public final int lineNum; + public final String message; + + public ValidationInfo(int lineNum, String message) { + this.lineNum = lineNum; + this.message = message; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/validation/messages.properties b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/validation/messages.properties new file mode 100644 index 0000000..59a9beb --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/texteditor/validation/messages.properties @@ -0,0 +1,2 @@ +NonSchemaBasedLayoutValidator_DuplicatedCommonType='type' attribute with 'common' value is duplicated in configuration elements +NonSchemaBasedLayoutValidator_NoCommonType=No 'type' attribute with 'common' value in configuration elements diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/AbstractToolbar.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/AbstractToolbar.java new file mode 100644 index 0000000..56a5a57 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/AbstractToolbar.java @@ -0,0 +1,50 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.toolbar; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.ToolBar; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; + + +public abstract class AbstractToolbar { + + private ToolBar toolBar = null; + private CombineEditorPart editor = null; + + public AbstractToolbar(Composite parent, CombineEditorPart editor) { + super(); + this.editor = editor; + this.toolBar = new ToolBar(parent, SWT.FLAT); + } + + protected ToolBar getControl() { + return toolBar; + } + + protected CombineEditorPart getEditor() { + return editor; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/DesignEditorToolbar.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/DesignEditorToolbar.java new file mode 100644 index 0000000..bcb5926 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/DesignEditorToolbar.java @@ -0,0 +1,211 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.toolbar; + +import org.eclipse.jface.action.ActionContributionItem; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.jface.layout.RowLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.layout.RowData; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Layout; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.ui.IEditorActionBarContributor; +import org.tizen.common.util.SWTUtil; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.efluibuilder.ui.editor.designeditor.DesignEditorActionBarContributor; + + +public class DesignEditorToolbar extends AbstractToolbar { + private static final int UNKNOWN = -1; + + private ZoomControlToolbar designZoomControlToolbar = null; + private ZoomControlToolbar storyboardZoomControlToolbar = null; + private ScreenDesignToolbar mscreenDesignToolbar = null; + private EditorModeToolbar editorModeToolbar = null; + private StoryboardAutoLayoutToolbar storyboardAutoLayoutToolbar = null; + + private ToolBar actionsToolbar = null; + private int type = UNKNOWN; + + private Composite parent = null; + + public DesignEditorToolbar(Composite parent, CombineEditorPart editor) { + super(parent, editor); + this.parent = parent; + } + + public void setType(int type) { + this.type = type; + } + + public int getType() { + return this.type; + } + + public Composite create() { + // replace parent layout + Layout parentLayout = this.parent.getLayout(); + this.parent.setLayout(new FormLayout()); + + // FIXME: The bottom margin of ToolBar for Windows is different with other OS. + // It should find a better solution. + + // toolbar layout data + FormData formData = new FormData(); + formData.top = new FormAttachment(0, ToolBarConstants.TOOLBAR_TOP_MARGIN); + formData.left = new FormAttachment(0); + formData.height = ToolBarConstants.TOOLBAR_HEIGHT; + formData.right = new FormAttachment(100); + getControl().setLayoutData(formData); + + RowLayoutFactory fillDefaults = RowLayoutFactory.fillDefaults(); + fillDefaults.wrap(false); + RowLayout rowLayout = fillDefaults.create(); + rowLayout.center = true; + getControl().setLayout(rowLayout); + + // line seperator + Label lineSeperator = new Label(this.parent, SWT.HORIZONTAL | SWT.SEPARATOR); + formData = new FormData(); + formData.top = new FormAttachment(getControl()); + formData.left = new FormAttachment(0, 0); + formData.right = new FormAttachment(100, 0); + lineSeperator.setLayoutData(formData); + + // another layout data + Composite childComposite = new Composite(this.parent, SWT.NONE); + formData = new FormData(); + formData.top = new FormAttachment(lineSeperator); + formData.left = new FormAttachment(0, 0); + formData.right = new FormAttachment(100, 0); + formData.bottom = new FormAttachment(100, 0); + childComposite.setLayoutData(formData); + childComposite.setLayout(parentLayout); // restore parent layout + + initialize(); + + return childComposite; + } + + private void initialize() { + switch (getType()) { + case CombineEditorPart.DESIGN_TAB: + this.editorModeToolbar = new EditorModeToolbar(getControl(), getEditor()); + editorModeToolbar.setType(type); + editorModeToolbar.createControl(); + ToolbarUtil.addBlankItem(this.editorModeToolbar.getControl(), new RowData(SWT.DEFAULT, ToolBarConstants.TOOLBAR_HEIGHT)); + ToolbarUtil.addSeparatorItem(this.editorModeToolbar.getControl()); + + this.designZoomControlToolbar = new ZoomControlToolbar(getControl(), getEditor()); + ToolbarUtil.addBlankItem(this.designZoomControlToolbar.getControl(), new RowData(SWT.DEFAULT, ToolBarConstants.TOOLBAR_HEIGHT)); + ToolbarUtil.addSeparatorItem(this.designZoomControlToolbar.getControl()); + + this.mscreenDesignToolbar = new ScreenDesignToolbar(getControl(), getEditor()); + ToolbarUtil.addBlankItem(this.mscreenDesignToolbar.getControl(), new RowData(SWT.DEFAULT, ToolBarConstants.TOOLBAR_HEIGHT)); + ToolbarUtil.addSeparatorItem(this.mscreenDesignToolbar.getControl()); + getEditor().getDesignEditor().getViewer().addMScreenToolbar(mscreenDesignToolbar); + + this.storyboardAutoLayoutToolbar = new StoryboardAutoLayoutToolbar(getControl(), getEditor()); + ToolbarUtil.addBlankItem(this.storyboardAutoLayoutToolbar.getControl(), new RowData(SWT.DEFAULT, ToolBarConstants.TOOLBAR_HEIGHT)); + ToolbarUtil.addSeparatorItem(this.storyboardAutoLayoutToolbar.getControl()); + + this.actionsToolbar = new ToolBar(getControl(), SWT.FLAT); + this.actionsToolbar.setLayoutData(new RowData(SWT.DEFAULT, ToolBarConstants.TOOLBAR_HEIGHT)); + + boolean useColorIconsInToolbars = ActionContributionItem.getUseColorIconsInToolbars(); + try { + // set UseColorIcons preferences setting for hover image. + ActionContributionItem.setUseColorIconsInToolbars(false); + + IToolBarManager actionsToolbarManager = new ToolBarManager(this.actionsToolbar); + IEditorActionBarContributor editorActionBarContributor = getEditor().getEditorSite().getActionBarContributor(); + if (editorActionBarContributor instanceof DesignEditorActionBarContributor) { + DesignEditorActionBarContributor actionBarContributor = (DesignEditorActionBarContributor) editorActionBarContributor; + actionBarContributor.contributeToCustomToolBar(actionsToolbarManager); + actionsToolbarManager.update(true); + } + } finally { + // This is a global setting. Restore it. + ActionContributionItem.setUseColorIconsInToolbars(useColorIconsInToolbars); + } + break; + default: + } + + // mscreenPreviewToolbar = new ScreenPreviewToolbar(parent, getEditor()); + } + + public void dispose() { + if (mscreenDesignToolbar != null) { + mscreenDesignToolbar.dispose(); + mscreenDesignToolbar = null; + } + + if (designZoomControlToolbar != null) { + designZoomControlToolbar.dispose(); + designZoomControlToolbar = null; + } + + if (storyboardZoomControlToolbar != null) { + storyboardZoomControlToolbar.dispose(); + storyboardZoomControlToolbar = null; + } + + if (editorModeToolbar != null) { + editorModeToolbar.dispose(); + editorModeToolbar = null; + } + + if (storyboardAutoLayoutToolbar != null) { + storyboardAutoLayoutToolbar.dispose(); + storyboardAutoLayoutToolbar = null; + } + + SWTUtil.tryDispose(this.actionsToolbar); + } + + public void initContents() { + switch (getType()) { + case CombineEditorPart.DESIGN_TAB: + this.designZoomControlToolbar.setViewer(getEditor().getDesignEditor().getViewer()); + break; + default: + break; + } + } + + public void setEnabled(boolean enabled) { + mscreenDesignToolbar.setEnabled(enabled); + designZoomControlToolbar.setEnabled(enabled); + editorModeToolbar.setEnabled(enabled); + storyboardAutoLayoutToolbar.setEnabled(enabled); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/EditorModeToolbar.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/EditorModeToolbar.java new file mode 100644 index 0000000..4e78dac --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/EditorModeToolbar.java @@ -0,0 +1,107 @@ + + +package org.tizen.efluibuilder.ui.editor.toolbar; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.RowData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.ToolItem; +import org.tizen.efluibuilder.nl.BuilderMessages; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.efluibuilder.ui.resources.ColorResources; +import org.tizen.efluibuilder.ui.resources.ImageResources; + + +public class EditorModeToolbar extends AbstractToolbar { + private static final int UNKNOWN = -1; + private ToolItem designModeItem = null; + private ToolItem sourceModeItem = null; + private int type = UNKNOWN; + private Button sourceMode = null; + private Button designMode = null; + private static final int MODE_BUTTON_WIDTH = 36; + + public EditorModeToolbar(Composite parent, CombineEditorPart editor) { + super(parent, editor); + } + + public void setType(int type) { + this.type = type; + } + + public int getType() { + return this.type; + } + + public void createControl() { + if (getControl() == null) { + return; + } + + getControl().setLayoutData(new RowData(SWT.DEFAULT, ToolBarConstants.TOOLBAR_HEIGHT)); + + // FIXME: If Combobox height can change using pack function(this function cannot work), + // Change this code(From now this code used fakeImage). + ToolItem tempToolItem = new ToolItem(getControl(), SWT.PUSH); + tempToolItem.setEnabled(false); + tempToolItem.setImage(ImageResources.getImage(ImageResources.PREVIEW_TOOLBAR_DUMMY)); + + ToolbarUtil.addBlankItem(getControl(), 18, new RowData(SWT.DEFAULT, ToolBarConstants.TOOLBAR_HEIGHT)); + + sourceMode = new Button(getControl(), SWT.PUSH); + sourceMode.setToolTipText(BuilderMessages.SOURCE_MODE); + + sourceModeItem = new ToolItem(getControl(), SWT.SEPARATOR); + sourceModeItem.setControl(sourceMode); + sourceModeItem.setWidth(MODE_BUTTON_WIDTH); + + designMode = new Button(getControl(), SWT.PUSH); + designMode.setToolTipText(BuilderMessages.DESIGN_MODE); + + designModeItem = new ToolItem(getControl(), SWT.SEPARATOR); + designModeItem.setControl(designMode); + designModeItem.setWidth(MODE_BUTTON_WIDTH); + + switch (getType()) { + case CombineEditorPart.DESIGN_TAB: + designMode.setBackground(ColorResources.TOOLBAR_EDITOR_SWITCH_BACKGROUND); + designMode.setImage(ImageResources.getImage(ImageResources.TOOLBAR_DESIGN_SEL)); + sourceMode.setImage(ImageResources.getImage(ImageResources.TOOLBAR_SOURCE_NOR)); + break; + case CombineEditorPart.TEXTEDITOR_TAB: + sourceMode.setBackground(ColorResources.TOOLBAR_EDITOR_SWITCH_BACKGROUND); + sourceMode.setImage(ImageResources.getImage(ImageResources.TOOLBAR_SOURCE_SEL)); + designMode.setImage(ImageResources.getImage(ImageResources.TOOLBAR_DESIGN_NOR)); + break; + } + + widgetEvent(); + } + + private void widgetEvent() { + + this.sourceMode.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + getEditor().setActivePage(CombineEditorPart.TEXTEDITOR_TAB); + } + }); + + this.designMode.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + getEditor().setActivePage(CombineEditorPart.DESIGN_TAB); + } + }); + } + + public void dispose() { + } + + public void setEnabled(boolean enabled) { + + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/IZoomToolbar.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/IZoomToolbar.java new file mode 100644 index 0000000..34c8d01 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/IZoomToolbar.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.ui.editor.toolbar; + +import org.eclipse.gef.editparts.ZoomListener; +import org.tizen.efluibuilder.gef.viewer.IScalableViewer; + + +public interface IZoomToolbar extends ZoomListener { + public boolean isFitMode(); + + public void setFitMode(boolean isFit); + + public void setViewer(IScalableViewer viewer); +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/PreviewToolbar.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/PreviewToolbar.java new file mode 100644 index 0000000..7643226 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/PreviewToolbar.java @@ -0,0 +1,339 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.ui.editor.toolbar; + +import java.util.Collection; +import java.util.Iterator; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.FocusAdapter; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.RowData; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.ToolItem; +import org.tizen.efluibuilder.core.configuration.device.Device; +import org.tizen.efluibuilder.model.app.AppManager; +import org.tizen.efluibuilder.model.part.ConfigurationPart; +import org.tizen.efluibuilder.model.util.ModelConstants; +import org.tizen.efluibuilder.mscreen.configurator.MScreenQualifierManager; +import org.tizen.efluibuilder.mscreen.configurator.MscreenConstants; +import org.tizen.efluibuilder.mscreen.rm.ResourceManagerUtil; +import org.tizen.efluibuilder.nl.BuilderMessages; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.efluibuilder.ui.editor.texteditor.preview.PreviewViewer; +import org.tizen.efluibuilder.ui.resources.ImageResources; + + +public class PreviewToolbar extends AbstractToolbar { + + private ToolItem locale = null; + private Combo localeCombo; + private String localeText = "Locale"; //$NON-NLS-1$ + + private ToolItem device = null; + private Combo deviceCombo; + private String deviceText = "Device"; //$NON-NLS-1$ + + private ToolItem orientation = null; + private Combo orientationCombo; + private String orientationText = "Orientation"; //$NON-NLS-1$ + + private PreviewViewer previewViewer = null; + private EditorModeToolbar editorModeToolbar = null; + + private MScreenQualifierManager mscreenQualifierManager = null; + + private Collection devices = null; + private String[] locales = null; + + private int comboBoxTopMargin = 1; + private int editorModeButtonTopMargin = 1; + + // FIXME: The top margin of Toolbar for windows is differenct each OS(Windows, Mac, Ubuntu) + // It should find a better solution. + private void setPreviewToolItemTopMargin() { + if (Platform.OS_WIN32.equals(Platform.getOS())) { + editorModeButtonTopMargin = 6; + comboBoxTopMargin = 6; + } else if (Platform.OS_MACOSX.equals(Platform.getOS())) { + editorModeButtonTopMargin = 5; + comboBoxTopMargin = 5; + } else { // Ubuntu Case + editorModeButtonTopMargin = 1; + comboBoxTopMargin = 1; + } + } + + public PreviewToolbar(Composite parent, CombineEditorPart parentEditor, PreviewViewer previewViewer) { + super(parent, parentEditor); + + devices = AppManager.getAppManager(parentEditor.getProject()).getDeviceManager().getDevices(); + locales = getLocales(); + + editorModeToolbar = new EditorModeToolbar(parent, parentEditor); + editorModeToolbar.setType(CombineEditorPart.TEXTEDITOR_TAB); + editorModeToolbar.createControl(); + } + + private String[] getLocales() { + CombineEditorPart editor = getEditor(); + if (editor == null) { + return null; + } + ResourceManagerUtil resourceManager = new ResourceManagerUtil(editor.getProject()); + String[] locales = resourceManager.getLocales(); + + // translate "ALL" to "All Locales" + final String allLocales = ResourceManagerUtil.RM_LOCALE_ALL.getName(); + for (int i = 0; i < locales.length; i++) { + if (allLocales.equals(locales[i])) { + locales[i] = ToolBarConstants.ALL_LOCALES; + } + } + + return locales; + } + + private void createItemLocale() { + localeCombo = new Combo(getControl(), SWT.DROP_DOWN | SWT.READ_ONLY); + localeCombo.setToolTipText(BuilderMessages.MS_PREVIEW_LOCALE); + localeCombo.setVisibleItemCount(5); + localeCombo.setText(localeText); + localeCombo.setItems(locales); + localeCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Combo combo = (Combo) e.widget; + String text = combo.getText(); + + // translate "All Locales" to "ALL" + if (ToolBarConstants.ALL_LOCALES.equals(text)) { + text = ResourceManagerUtil.RM_LOCALE_ALL.getName(); + } + + mscreenQualifierManager.setLocale(text); + localeText = combo.getText(); + setConfiguration(); + } + }); + localeCombo.addFocusListener(new FocusAdapter() { + @Override + public void focusGained(FocusEvent e) { + locales = getLocales(); + localeCombo.setItems(locales); + localeCombo.setText(localeText); + } + }); + locale = new ToolItem(getControl(), SWT.SEPARATOR); + locale.setControl(localeCombo); + setItemWidth(localeCombo, locale); + } + + private void setItemWidth(Control control, ToolItem item) { + control.pack(); + item.setWidth(control.getSize().x); + } + + private void createItemOrientation() { + orientationCombo = new Combo(getControl(), SWT.DROP_DOWN | SWT.READ_ONLY); + orientationCombo.setToolTipText(BuilderMessages.MS_PREVIEW_ORIENTATION); + orientationCombo.setVisibleItemCount(5); + orientationCombo.setText(orientationText); + orientationCombo.setItems(MscreenConstants.ORIENTATIONS); + + orientationCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Combo combo = (Combo) e.widget; + orientationText = combo.getText(); + setConfiguration(); + } + }); + + orientation = new ToolItem(getControl(), SWT.SEPARATOR); + orientation.setControl(orientationCombo); + setItemWidth(orientationCombo, orientation); + } + + private void createItemDevice() { + deviceCombo = new Combo(getControl(), SWT.DROP_DOWN | SWT.READ_ONLY); + deviceCombo.setToolTipText(BuilderMessages.MS_PREVIEW_DEVICE); + deviceCombo.setVisibleItemCount(5); + for (Device device : devices) { + deviceCombo.add(device.getDisplayName()); + + } + + if (previewViewer.getCurrentDevice() != null) { + deviceCombo.setText(previewViewer.getCurrentDevice().getDisplayName()); + } + + deviceCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Combo combo = (Combo) e.widget; + deviceText = combo.getText(); + setConfiguration(); + } + }); + + device = new ToolItem(getControl(), SWT.SEPARATOR); + device.setControl(deviceCombo); + setItemWidth(deviceCombo, device); + } + + private void resetMenuText() { + if (devices.size() > 0) { + Iterator iterator = devices.iterator(); + Device device = iterator.next(); + deviceText = device.getDisplayName(); + } else { + deviceText = ""; + } + + if (locales.length > 0) { + localeText = locales[0]; + } else { + localeText = ""; + } + orientationText = MscreenConstants.ORIENTATIONS[0]; + } + + private void setOrientationComboDisabledByCondition() { + ConfigurationPart configPart = mscreenQualifierManager.getCurrentConfigurePart(); + if ((configPart == null) || (configPart.getProperties().containsKey(MscreenConstants.DEVICE) == false)) { + return; + } + + String orientationValue = mscreenQualifierManager.getCurrentConfigurePart().getProperties().get(MscreenConstants.DEVICE).toLowerCase(); + if (orientationValue.contains(ModelConstants.SHAPE_SQUARE) || orientationValue.contains(ModelConstants.SHAPE_CIRCLE)) { + orientationCombo.setEnabled(false); + } else { + orientationCombo.setEnabled(true); + } + } + + private void setConfiguration() { + deviceCombo.setText(deviceText); + orientationCombo.setText(orientationText); + deviceCombo.getParent().pack(); + orientationCombo.getParent().pack(); + localeCombo.getParent().pack(); + + setOrientationComboDisabledByCondition(); + this.previewViewer.reqNewPageGraphicDataFromQualifiers(this.getCurrentDevice(), this.getCurrentOrientation(), this.getCurrentLocale()); + + getControl().getParent().pack(); + } + + private void createToolItem() { + if (getControl() == null) { + return; + } + getControl().setLayoutData(new RowData(SWT.DEFAULT, ToolBarConstants.TOOLBAR_HEIGHT)); + + ToolbarUtil.addBlankItem(this.editorModeToolbar.getControl(), new RowData(SWT.DEFAULT, ToolBarConstants.TOOLBAR_HEIGHT)); + ToolbarUtil.addSeparatorItem(this.editorModeToolbar.getControl()); + ToolbarUtil.addBlankItem(this.editorModeToolbar.getControl(), new RowData(SWT.DEFAULT, ToolBarConstants.TOOLBAR_HEIGHT)); + + setPreviewToolItemTopMargin(); + createItemDevice(); + createItemOrientation(); + createItemLocale(); + + // FIXME: If Combobox height can change using pack function(this function cannot work), + // Change this code(From now this code used fakeImage). + ToolItem tempToolItem = new ToolItem(getControl(), SWT.NONE); + tempToolItem.setEnabled(false); + Image changeComboboxHeightImage = ImageResources.getImage(ImageResources.PREVIEW_TOOLBAR_DUMMY); + tempToolItem.setImage(changeComboboxHeightImage); + + resetMenuText(); + + deviceCombo.setText(deviceText); + orientationCombo.setText(orientationText); + localeCombo.setText(localeText); + + setOrientationComboDisabledByCondition(); + FormData data = new FormData(); + + // editorSwitchToolbarLayout(Left) + data.top = new FormAttachment(0, editorModeButtonTopMargin); + data.height = ToolBarConstants.TOOLBAR_HEIGHT; + data.left = new FormAttachment(0); + editorModeToolbar.getControl().setLayoutData(data); + + // comboBoxlayout(center) + data = new FormData(); + data.top = new FormAttachment(0, comboBoxTopMargin); + data.height = ToolBarConstants.TOOLBAR_HEIGHT; + data.left = new FormAttachment(editorModeToolbar.getControl(), 0); + getControl().setLayoutData(data); + } + + public String getCurrentLocale() { + return this.localeText; + } + + public Device getCurrentDevice() { + for (Device device : devices) { + if (device.getDisplayName().equals(deviceText)) { + return device; + } + } + return null; + } + + public String getCurrentOrientation() { + return this.orientationText; + } + + public ConfigurationPart getCurrentConfigurationPart() { + return this.mscreenQualifierManager.getCurrentConfigurePart(); + } + + public void initContents(PreviewViewer previewViewer) { + this.previewViewer = previewViewer; + mscreenQualifierManager = previewViewer.getScreenQualifierManager(); + createToolItem(); + } + + public void setEnabled(boolean enabled) { + localeCombo.setEnabled(enabled); + deviceCombo.setEnabled(enabled); + orientationCombo.setEnabled(enabled); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/ScreenDesignToolbar.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/ScreenDesignToolbar.java new file mode 100644 index 0000000..3a74367 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/ScreenDesignToolbar.java @@ -0,0 +1,300 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.toolbar; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.gef.commands.Command; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.FocusAdapter; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.RowData; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.ToolItem; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.model.part.ConfigurationPart; +import org.tizen.efluibuilder.mscreen.configurator.MScreenQualifierManager; +import org.tizen.efluibuilder.mscreen.configurator.MsConfiguratorWizard; +import org.tizen.efluibuilder.mscreen.configurator.ScreenConfiguration; +import org.tizen.efluibuilder.mscreen.rm.ResourceManagerUtil; +import org.tizen.efluibuilder.nl.BuilderMessages; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.efluibuilder.ui.resources.ImageResources; + + +public class ScreenDesignToolbar extends AbstractToolbar { + + protected final Logger logger = LoggerFactory.getLogger(getClass()); + + private MScreenQualifierManager mscreenManager = null; + + private Combo msConfigCombo; + private ToolItem mscreenConfiguration = null; + private Combo localeCombo; + private ToolItem locale = null; + private MsConfiguratorWizard msConfiguratorWizard = null; + + public ScreenDesignToolbar(Composite parent, CombineEditorPart editor) { + super(parent, editor); + draw(); + } + + public void dispose() { + } + + public void setMscreenManager(MScreenQualifierManager mscreenManager) { + this.mscreenManager = mscreenManager; + + setScreenConfigurationItems(); + setLocaleComboItems(); + } + + private void setLocaleComboItems() { + ResourceManagerUtil resUtil = new ResourceManagerUtil(this.getEditor().getProject()); + String[] locales = resUtil.getLocales(); + + // translate "ALL" to "All Locales" + final String allLocales = ResourceManagerUtil.RM_LOCALE_ALL.getName(); + for (int i = 0; i < locales.length; i++) { + if (allLocales.equals(locales[i])) { + locales[i] = ToolBarConstants.ALL_LOCALES; + } + } + + this.localeCombo.setItems(locales); + } + + private void draw() { + if (getControl() == null) { + return; + } + + getControl().setLayoutData(new RowData(SWT.DEFAULT, ToolBarConstants.TOOLBAR_HEIGHT)); + + // FIXME: If Combobox height can change using pack function(this function cannot work), + // Change this code(From now this code used fakeImage). + ToolItem tempToolItem = new ToolItem(getControl(), SWT.PUSH); + tempToolItem.setEnabled(false); + tempToolItem.setImage(ImageResources.getImage(ImageResources.PREVIEW_TOOLBAR_DUMMY)); + + this.msConfigCombo = new Combo(getControl(), SWT.DROP_DOWN | SWT.READ_ONLY); + this.msConfigCombo.setToolTipText(BuilderMessages.MS_DESIGN_CONFIGURATION); + this.msConfigCombo.setVisibleItemCount(5); + + this.msConfigCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Combo combo = (Combo) e.widget; + // for new GUI [START] + if (combo.getSelectionIndex() == combo.getItemCount() - 1) { + ConfigurationPart configPart = mscreenManager.getCurrentConfigurePart(); + if (configPart == null) { + return; + } + String configName = configPart.getName(); + for (ScreenConfiguration config : mscreenManager.getScreenConfiguration()) { + if (configName != null && configName.equals(config.getName())) { + msConfigCombo.setText(config.getDisplayName()); + openMsConfiguratorWizard(); + return; + } + } + } + // for new GUI [END] + + String selectedConfig = combo.getItem(combo.getSelectionIndex()); + ScreenConfiguration config = getScreenConfiguration(selectedConfig); + if (config != null) { + ConfigurationPart configurePart = mscreenManager.getConfigurePartFromScreenConfiguration(config); + if (configurePart != null) { + mscreenManager.setCurrentConfigurePart(configurePart); + } + } + + layout(combo, mscreenConfiguration); + } + + private ScreenConfiguration getScreenConfiguration(String selectedConfig) { + for (ScreenConfiguration config : mscreenManager.getScreenConfiguration()) { + if (config.getDisplayName().equals(selectedConfig)) { + return config; + } + } + + return null; + } + }); + + mscreenConfiguration = new ToolItem(getControl(), SWT.SEPARATOR); + mscreenConfiguration.setControl(this.msConfigCombo); + setItemWidth(this.msConfigCombo, mscreenConfiguration); + + this.localeCombo = new Combo(getControl(), SWT.DROP_DOWN | SWT.READ_ONLY); + this.localeCombo.setToolTipText(BuilderMessages.MS_PREVIEW_LOCALE); + this.localeCombo.setVisibleItemCount(5); + this.localeCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Combo combo = (Combo) e.widget; + String text = combo.getText(); + + // translate "All Locales" to "ALL" + if (ToolBarConstants.ALL_LOCALES.equals(text)) { + text = ResourceManagerUtil.RM_LOCALE_ALL.getName(); + } + + mscreenManager.setLocale(text); + + layout(combo, locale); + } + }); + + locale = new ToolItem(getControl(), SWT.SEPARATOR); + locale.setControl(this.localeCombo); + localeCombo.addFocusListener(new FocusAdapter() { + @Override + public void focusGained(FocusEvent e) { + setLocaleComboItems(); + updateLocaleItem(mscreenManager.getCurrentLocale()); + } + }); + setItemWidth(this.localeCombo, locale); + } + + public void refreshContents(ConfigurationPart configurePart) { + if (configurePart == null) { + logger.warn("Cannot refresh ScreenDesignToolbar for part"); + return; + } + + ScreenConfiguration configuration = new ScreenConfiguration(configurePart); + + String currentConfigurationDisplayName = configuration.getDisplayName(); + updateScreenConfigurationItem(currentConfigurationDisplayName); + updateLocaleItem(this.mscreenManager.getCurrentLocale()); + setScreenConfigurationItems(); + } + + public void setEnabled(boolean enabled) { + getControl().setEnabled(enabled); + msConfigCombo.setEnabled(enabled); + localeCombo.setEnabled(enabled); + } + + // for new GUI + private void openMsConfiguratorWizard() { + if (msConfiguratorWizard != null) { + return; + } + + msConfigCombo.getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + msConfiguratorWizard = new MsConfiguratorWizard(); + try { + msConfiguratorWizard.setModel(mscreenManager.getMScreenPart()); + + Shell shell = Display.getDefault().getActiveShell(); + WizardDialog dialog = new WizardDialog(shell, msConfiguratorWizard); + int result = dialog.open(); + + if (result == Dialog.OK) { + Command cmd = msConfiguratorWizard.getCommand(); + if (cmd != null) { + getEditor().getDesignEditor().getViewer().getEditDomain().getCommandStack().execute(cmd); + setScreenConfigurationItems(); + } + } + } finally { + msConfiguratorWizard.dispose(); + msConfiguratorWizard = null; + } + } + }); + } + + private void updateLocaleItem(String item) { + if (this.localeCombo == null || this.locale == null) { + return; + } + + // translate "ALL" to "All Locales" + final String allLocales = ResourceManagerUtil.RM_LOCALE_ALL.getName(); + if (allLocales.equals(item)) { + item = ToolBarConstants.ALL_LOCALES; + } + + this.localeCombo.setText(item); + layout(this.localeCombo, this.locale); + } + + private void updateScreenConfigurationItem(String item) { + if (this.msConfigCombo == null || this.mscreenConfiguration == null) { + return; + } + + this.msConfigCombo.setText(item); + layout(this.msConfigCombo, this.mscreenConfiguration); + } + + private void setScreenConfigurationItems() { + if (this.msConfigCombo == null || this.mscreenManager == null) { + return; + } + + String currentSelection = this.msConfigCombo.getText(); + this.msConfigCombo.setItems(getScreenConfigurations(this.mscreenManager)); + this.msConfigCombo.add(BuilderMessages.MS_DESIGN_LAUNCH_CONFIGURATION); // for new GUI + this.msConfigCombo.setText(currentSelection); + } + + private String[] getScreenConfigurations(MScreenQualifierManager mscreenManager) { + List configList = new ArrayList(); + for (ScreenConfiguration config : mscreenManager.getScreenConfiguration()) { + configList.add(config.getDisplayName()); + } + + return configList.toArray(new String[0]); + } + + private void setItemWidth(Control control, ToolItem item) { + control.pack(); + item.setWidth(control.getSize().x); + } + + private void layout(Control control, ToolItem item) { + setItemWidth(control, item); + getControl().getParent().layout(); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/ScreenPreviewToolbar.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/ScreenPreviewToolbar.java new file mode 100644 index 0000000..1eab82a --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/ScreenPreviewToolbar.java @@ -0,0 +1,252 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.ui.editor.toolbar; +// +// import java.util.Collection; +// import java.util.HashMap; +// import java.util.Iterator; +// import java.util.Map; +// +// import org.eclipse.jface.resource.ImageDescriptor; +// import org.eclipse.swt.SWT; +// import org.eclipse.swt.custom.CLabel; +// import org.eclipse.swt.events.SelectionAdapter; +// import org.eclipse.swt.events.SelectionEvent; +// import org.eclipse.swt.graphics.Image; +// import org.eclipse.swt.widgets.Composite; +// import org.eclipse.swt.widgets.Menu; +// import org.eclipse.swt.widgets.MenuItem; +// import org.eclipse.swt.widgets.ToolItem; +// import org.eclipse.ui.plugin.AbstractUIPlugin; +// import org.tizen.efluibuilder.BuilderPlugin; +// import org.tizen.efluibuilder.core.configuration.device.Device; +// import org.tizen.efluibuilder.internal.renderer.command.GetAllWidgetPositionsCommand; +// import org.tizen.efluibuilder.model.app.AppManager; +// import org.tizen.efluibuilder.mscreen.configurator.MscreenConstants; +// import org.tizen.efluibuilder.mscreen.configurator.ScreenConfiguration; +// import org.tizen.efluibuilder.nl.BuilderMessages; +// import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +// +// +// public class ScreenPreviewToolbar extends AbstractToolbar { +// +// public ScreenPreviewToolbar(Composite parent, CombineEditorPart editor) { +// super(parent, editor); +// appManager = AppManager.getAppManager(editor.getEditorInput()); +// draw(); +// resetMenuText(); +// // TODO Auto-generated constructor stub +// } +// +// private ToolItem locale = null; +// private ToolItem localeItem = null; +// private CLabel localeText = null; +// +// private ToolItem device = null; +// private ToolItem deviceItem = null; +// private CLabel deviceText = null; +// +// private ToolItem orientation = null; +// private ToolItem orientationItem = null; +// private CLabel orientationText = null; +// private AppManager appManager = null; +// +// public void dispose() { +// // TODO Auto-generated method stub +// +// } +// +// private void draw() { +// if (getControl() == null) { +// return; +// } +// +// ToolItem separator = null; +// +// separator = new ToolItem(getControl(), SWT.SEPARATOR); +// separator.setWidth(5); +// +// ImageDescriptor imageDescriptor = null; +// Image image = null; +// +// // == draw orientation +// orientation = new ToolItem(getControl(), SWT.PUSH); +// // FIXME : temporary ICON +// imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(BuilderPlugin.PLUGIN_ID, +/// "res/icons/editor/down_arrow.png"); +// image = imageDescriptor.createImage(); +// orientation.setImage(image); +// orientation.setToolTipText(BuilderMessages.MS_PREVIEW_ORIENTATION); +// +// orientationText = new CLabel(getControl(), SWT.LEFT_TO_RIGHT | SWT.RIGHT); +// orientationText.pack(); +// orientationItem = new ToolItem(getControl(), SWT.SEPARATOR); +// orientationItem.setControl(orientationText); +// orientationItem.setWidth(90); +// orientation.setEnabled(true); +// orientation.addSelectionListener(new SelectionAdapter() { +// @Override +// public void widgetSelected(SelectionEvent e) { +// Menu menu = ToolbarUtil.drawMenu(getControl(), orientationText, orientationItem); +// insertOrientation(menu); +// } +// }); +// +// // == draw device +// device = new ToolItem(getControl(), SWT.PUSH); +// // FIXME : temporary ICON +// imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(BuilderPlugin.PLUGIN_ID, +/// "res/icons/editor/down_arrow.png"); +// image = imageDescriptor.createImage(); +// device.setImage(image); +// device.setToolTipText(BuilderMessages.MS_PREVIEW_DEVICE); +// +// deviceText = new CLabel(getControl(), SWT.LEFT_TO_RIGHT | SWT.RIGHT); +// deviceText.pack(); +// deviceItem = new ToolItem(getControl(), SWT.SEPARATOR); +// deviceItem.setControl(deviceText); +// deviceItem.setWidth(100); +// device.setEnabled(true); +// device.addSelectionListener(new SelectionAdapter() { +// @Override +// public void widgetSelected(SelectionEvent e) { +// Menu menu = ToolbarUtil.drawMenu(getControl(), deviceText, deviceItem); +// insertDevices(menu); +// } +// }); +// +// // == draw locale +// locale = new ToolItem(getControl(), SWT.PUSH); +// // FIXME : temporary ICON +// imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(BuilderPlugin.PLUGIN_ID, +/// "res/icons/editor/down_arrow.png"); +// image = imageDescriptor.createImage(); +// locale.setImage(image); +// locale.setToolTipText(BuilderMessages.MS_PREVIEW_LOCALE); +// +// localeText = new CLabel(getControl(), SWT.LEFT_TO_RIGHT | SWT.RIGHT); +// localeText.pack(); +// localeItem = new ToolItem(getControl(), SWT.SEPARATOR); +// localeItem.setControl(localeText); +// localeItem.setWidth(90); +// locale.setEnabled(true); +// locale.addSelectionListener(new SelectionAdapter() { +// @Override +// public void widgetSelected(SelectionEvent e) { +// Menu menu = ToolbarUtil.drawMenu(getControl(), localeText, localeItem); +// insertLocale(menu); +// } +// }); +// +// separator = new ToolItem(getControl(), SWT.SEPARATOR); +// separator.setWidth(5); +// } +// +// +// private void resetMenuText() { +// Collection devices = appManager.getDeviceManager().getDevices(); +// +//// Collection devices = getEditor().getViewManager().getDevices(); +// Iterator iterator = devices.iterator(); +// Device device = iterator.next(); +// deviceText.setText(device.getName()); +// orientationText.setText(MscreenConstants.ORIENTATION_PORTRAIT); +//// localeText.setText(MscreenConstants.DEFAULT_LOCALE); +// } +// +// private void insertLocale(Menu menu) { +// // insert po/rm locale +//// String[] locales = +/// getEditor().getViewManager().getMscreenManager().getRmWrapper().getLocales(); +//// for (int i = 0; i < locales.length; i++) { +//// insertLocale(menu, locales[i]); +//// } +// } +// +// private void insertLocale(Menu menu, String locale) { +// final MenuItem item = new MenuItem(menu, SWT.PUSH); +// item.setData(locale); +// item.setText(locale); +// item.addSelectionListener(new SelectionAdapter() { +// @Override +// public void widgetSelected(SelectionEvent e) { +// String locale = (String) item.getData(); +// localeText.setText(locale); +// setConfiguration(); +// } +// }); +// } +// +// private void insertDevices(Menu menu) { +//// Collection devices = getEditor().getViewManager().getDevices(); +//// for (Device device : devices) { +//// final MenuItem item = new MenuItem(menu, SWT.PUSH); +//// item.setData(device.getName()); +//// item.setText(device.getDisplayName()); +//// item.addSelectionListener(new SelectionAdapter() { +//// @Override +//// public void widgetSelected(SelectionEvent e) { +//// String device = (String) item.getData(); +//// deviceText.setText(device); +//// setConfiguration(); +//// } +//// }); +//// } +// } +// +// private void insertOrientation(Menu menu) { +//// for (int i = 0; i < MscreenManager.ORIENTATION.length; i++) { +//// final MenuItem item = new MenuItem(menu, SWT.PUSH); +//// item.setData(MscreenManager.ORIENTATION[i]); +//// item.setText(MscreenManager.ORIENTATION[i]); +//// item.addSelectionListener(new SelectionAdapter() { +//// @Override +//// public void widgetSelected(SelectionEvent e) { +//// String orientation = (String) item.getData(); +//// orientationText.setText(orientation); +//// setConfiguration(); +//// } +//// }); +//// } +// } +// +// private void setConfiguration() { +//// IViewManager iViewManager = getEditor().getViewManager(); +//// if (iViewManager instanceof AbstractViewManager) { +//// AbstractViewManager viewManager = (AbstractViewManager) iViewManager; +//// viewManager.setConfiguration(getQualifiers()); +//// } +// } +// +// public Map getQualifiers() { +// Map qualifiers = new HashMap(); +// qualifiers.put(ScreenConfiguration.LOCALE, localeText.getText()); +// qualifiers.put(ScreenConfiguration.DEVICE, deviceText.getText()); +// qualifiers.put(ScreenConfiguration.ORIENTATION, orientationText.getText()); +// return qualifiers; +// } +// } diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/StoryboardAutoLayoutToolbar.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/StoryboardAutoLayoutToolbar.java new file mode 100644 index 0000000..d88bf46 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/StoryboardAutoLayoutToolbar.java @@ -0,0 +1,72 @@ + + +package org.tizen.efluibuilder.ui.editor.toolbar; + +import org.eclipse.gef.RootEditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.RowData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.ToolItem; +import org.tizen.efluibuilder.gef.editparts.DesignRootEditPart; +import org.tizen.efluibuilder.gef.viewer.DesignStoryboardUtil; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.nl.BuilderMessages; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.efluibuilder.ui.resources.ImageResources; + + +public class StoryboardAutoLayoutToolbar extends AbstractToolbar { + + private ToolItem autoLayoutBtn = null; + + public StoryboardAutoLayoutToolbar(Composite parent, CombineEditorPart editor) { + super(parent, editor); + createControl(); + widgetEvent(); + } + + private void createControl() { + getControl().setLayoutData(new RowData(SWT.DEFAULT, ToolBarConstants.TOOLBAR_HEIGHT)); + this.autoLayoutBtn = new ToolItem(getControl(), SWT.PUSH); + this.autoLayoutBtn.setImage(ImageResources.getImage(ImageResources.TOOLBAR_AUTO_LAYOUT_NOR)); + this.autoLayoutBtn.setDisabledImage(ImageResources.getImage(ImageResources.TOOLBAR_AUTO_LAYOUT_DIM)); + this.autoLayoutBtn.setHotImage(ImageResources.getImage(ImageResources.TOOLBAR_AUTO_LAYOUT_MV)); + this.autoLayoutBtn.setToolTipText(BuilderMessages.AUTO_LAYOUT); + } + + private void widgetEvent() { + this.autoLayoutBtn.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + DesignViewer viewer = getEditor().getDesignEditor().getViewer(); + RootEditPart rootEditPart = viewer.getRootEditPart(); + + if (((DesignRootEditPart) rootEditPart).getContents().getChildren().size() > 0) { + Command cmd = + DesignStoryboardUtil.getStoryboardReconstructCommand((Part) ((DesignRootEditPart) rootEditPart).getContents().getModel(), + viewer.getMScreenQualifierManager().getScreenSize()); + if (cmd != null) { + CommandStack cmdStack = rootEditPart.getViewer().getEditDomain().getCommandStack(); + cmdStack.execute(cmd); + } + if (rootEditPart.getViewer() instanceof DesignViewer) { + ((DesignViewer) rootEditPart.getViewer()).setFitMode(true); + } + } + } + }); + } + + public void setEnabled(boolean enabled) { + autoLayoutBtn.setEnabled(enabled); + } + + public void dispose() { + + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/ToolBarConstants.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/ToolBarConstants.java new file mode 100644 index 0000000..b44b144 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/ToolBarConstants.java @@ -0,0 +1,80 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.toolbar; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Display; + + +public class ToolBarConstants { + + public static final String ALL_LOCALES = "All locales"; + + public static final int TOOLBAR_HEIGHT = 35; // UX Guide is 32, but clipped. + public static final int TOOLBAR_TOP_MARGIN; // for Windows + + public static final int TOOLITEM_WIDTH_MARGIN; // for Windows + public static final int TOOLITEM_SCALE_WIDTH = 100; + public static final int TOOLITEM_SEPARATOR_WIDTH; // UX Guide is 20 * 2 + public static final int TOOLITEM_BLANK_WIDTH = 10; // closed blank is 10, + // category blank is 18 or 20 + + public static final RGB COLOR_NORMAL = new RGB(0x58, 0x58, 0x58); + public static final RGB COLOR_SELECT = new RGB(0x00, 0x8a, 0xee); + + static { + String currentOs = Platform.getOS(); + + if (Platform.OS_WIN32.equals(currentOs)) { + TOOLBAR_TOP_MARGIN = 4; + TOOLITEM_WIDTH_MARGIN = 3; + TOOLITEM_SEPARATOR_WIDTH = 10; + } else if (Platform.OS_MACOSX.equals(currentOs)) { + TOOLBAR_TOP_MARGIN = 4; + TOOLITEM_WIDTH_MARGIN = 3; + TOOLITEM_SEPARATOR_WIDTH = 10; + } else { + TOOLBAR_TOP_MARGIN = 0; + TOOLITEM_WIDTH_MARGIN = 0; + TOOLITEM_SEPARATOR_WIDTH = 20; + } + } + + public static int getFontSize() { + String currentOs = Platform.getOS(); + + Font font = Display.getDefault().getSystemFont(); + int systemFontSize = font.getFontData()[0].getHeight(); + + if (Platform.OS_WIN32.equals(currentOs)) { + return systemFontSize - 2; + } else if (Platform.OS_MACOSX.equals(currentOs)) { + return systemFontSize + 4; + } else { + return systemFontSize; + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/ToolbarUtil.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/ToolbarUtil.java new file mode 100644 index 0000000..4eb51cf --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/ToolbarUtil.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.ui.editor.toolbar; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; +import org.tizen.efluibuilder.utility.PlatformUtil; + + +public class ToolbarUtil { + + public static Menu drawMenu(Composite composite, Rectangle parentBounds) { + Point menuPoint = composite.toDisplay(new Point((parentBounds.x + parentBounds.width - 18), parentBounds.y + parentBounds.height)); + Menu menu = new Menu(composite.getShell(), SWT.NONE); + menu.setLocation(menuPoint); + menu.setVisible(true); + return menu; + } + + public static Menu drawMenu(Composite composite, CLabel parentText, ToolItem parent) { + Menu menu = null; + if (PlatformUtil.getOS().equals(PlatformUtil.OS_MACOSX)) { + menu = drawDetailMenu(composite, parent); + } else { + menu = drawDetailMenu(composite, parentText); + } + return menu; + } + + public static Menu drawDetailMenu(Composite composite, CLabel parentText) { + Rectangle rect = parentText.getBounds(); + Point menuPoint = composite.toDisplay(new Point(rect.x + rect.width, rect.y + rect.height)); + Menu menu = new Menu(composite.getShell(), SWT.POP_UP); + menu.setLocation(menuPoint); + menu.setVisible(true); + return menu; + } + + public static Menu drawDetailMenu(Composite composite, ToolItem parent) { + Rectangle rect = parent.getBounds(); + Point menuPoint = composite.toDisplay(new Point(rect.x, rect.y + rect.height)); + Menu menu = new Menu(composite.getShell(), SWT.POP_UP); + menu.setLocation(menuPoint); + menu.setVisible(true); + return menu; + } + + public static void addSeparatorItem(ToolBar toolBar) { + ToolItem separator = new ToolItem(toolBar, SWT.SEPARATOR); + separator.setWidth(ToolBarConstants.TOOLITEM_SEPARATOR_WIDTH); + } + + public static void addBlankItem(ToolBar toolBar, int width, Object layoutData) { + Canvas blank = new Canvas(toolBar, SWT.NONE); + blank.setSize(width, ToolBarConstants.TOOLBAR_HEIGHT); + blank.setLayout(new FillLayout()); + blank.setLayoutData(layoutData); + + ToolItem separator = new ToolItem(toolBar, SWT.SEPARATOR); + separator.setControl(blank); + separator.setWidth(width); + } + + public static void addBlankItem(ToolBar toolBar, Object layoutData) { + addBlankItem(toolBar, ToolBarConstants.TOOLITEM_BLANK_WIDTH, layoutData); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/ViewNavigationToolbar.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/ViewNavigationToolbar.java new file mode 100644 index 0000000..61874cd --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/ViewNavigationToolbar.java @@ -0,0 +1,188 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.toolbar; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.ToolItem; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.ViewPart; +import org.tizen.efluibuilder.model.part.ViewsPart; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.nl.BuilderMessages; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.efluibuilder.ui.resources.ColorResources; +import org.tizen.efluibuilder.ui.resources.FontResources; +import org.tizen.efluibuilder.ui.resources.ImageResources; + + +public class ViewNavigationToolbar extends AbstractToolbar { + + public static final int PREV_VIEW = -1; + public static final int NEXT_VIEW = 1; + + private ToolItem prevButton = null; + private ToolItem nextButton = null; + private ToolItem viewCombo = null; + private ToolItem viewItem = null; + private CLabel viewTextLabel = null; + + private Part viewsPart = null; + + public ViewNavigationToolbar(Composite parent, CombineEditorPart editor) { + super(parent, editor); + + nextButton = new ToolItem(getControl(), SWT.PUSH); + + nextButton.setImage(ImageResources.getImage(ImageResources.TOOLBAR_NAVI_RIGHT_ARROW)); + nextButton.setData(NEXT_VIEW); + nextButton.setToolTipText(BuilderMessages.NEXT_VIEW); + + prevButton = new ToolItem(getControl(), SWT.PUSH); + prevButton.setImage(ImageResources.getImage(ImageResources.TOOLBAR_NAVI_LEFT_ARROW)); + prevButton.setData(PREV_VIEW); + prevButton.setToolTipText(BuilderMessages.PREV_VIEW); + + ToolItem separator = new ToolItem(getControl(), SWT.SEPARATOR); + separator.setWidth(5); + + viewCombo = new ToolItem(getControl(), SWT.PUSH); + viewCombo.setImage(ImageResources.getImage(ImageResources.TOOLBAR_NAVI_DOWN_ARROW)); + viewCombo.setToolTipText(BuilderMessages.SELECT_VIEW); + + viewTextLabel = new CLabel(getControl(), SWT.CENTER); + viewTextLabel.setBackground(ColorResources.TOOLBAR_VIEW_TEXT_LABEL); + viewTextLabel.pack(); + viewTextLabel.setFont(FontResources.TOOLBAR_VIEW_NAVIGATION_LABEL); + + viewItem = new ToolItem(getControl(), SWT.SEPARATOR); + viewItem.setControl(viewTextLabel); + viewItem.setWidth(80); + addListeners(); + } + + public void dispose() { + removeListeners(); + } + + public void refreshContents() { + Part viewPart = getViewer().getCurrentViewPart(); + if (viewPart != null) { + viewTextLabel.setText(viewPart.getPropertyValue(LayoutSchemaConstants.ID)); + } + } + + public void initContents(ViewsPart viewsPart) { + this.viewsPart = viewsPart; + this.refreshContents(); + } + + private DesignViewer getViewer() { + return getEditor().getDesignEditor().getViewer(); + } + + private void addListeners() { + + prevButton.addSelectionListener(buttonSelectionListener); + nextButton.addSelectionListener(buttonSelectionListener); + viewCombo.addSelectionListener(comboSelectionListener); + } + + private void removeListeners() { + + if (!prevButton.isDisposed()) { + prevButton.removeSelectionListener(buttonSelectionListener); + } + + if (!nextButton.isDisposed()) { + nextButton.removeSelectionListener(buttonSelectionListener); + } + + if (!viewCombo.isDisposed()) { + viewCombo.removeSelectionListener(comboSelectionListener); + } + + } + + private SelectionListener comboSelectionListener = new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent arg0) { + Menu menu = ToolbarUtil.drawMenu(getControl(), viewTextLabel, viewCombo); + insertViews(menu); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }; + + private SelectionListener buttonSelectionListener = new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent e) { + ToolItem item = (ToolItem) e.widget; + int data = (Integer) item.getData(); + if (viewsPart == null) { + return; + } + Part currentViewPart = getEditor().getDesignEditor().getViewer().getCurrentViewPart(); + DesignViewer viewer = getEditor().getDesignEditor().getViewer(); + if (currentViewPart != null) { + if (data == PREV_VIEW && (currentViewPart.getPreviousSibling() != null)) { + viewer.selectView((ViewPart) currentViewPart.getPreviousSibling()); + } else if (data == NEXT_VIEW && (currentViewPart.getNextSibling() != null)) { + viewer.selectView((ViewPart) currentViewPart.getNextSibling()); + } + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }; + + private void insertViews(Menu menu) { + if ((null == menu) || (viewsPart == null)) { + return; + } + for (Part view : viewsPart.getChildren()) { + final MenuItem item = new MenuItem(menu, SWT.PUSH); + item.setText(view.getPropertyValue(LayoutSchemaConstants.ID)); + item.setData(view); + item.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + ViewPart viewPart = (ViewPart) item.getData(); + getEditor().getDesignEditor().getViewer().selectView(viewPart); + } + }); + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/ZoomControlToolbar.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/ZoomControlToolbar.java new file mode 100644 index 0000000..bf422b2 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/editor/toolbar/ZoomControlToolbar.java @@ -0,0 +1,344 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.editor.toolbar; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.FocusAdapter; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseTrackAdapter; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.VerifyEvent; +import org.eclipse.swt.events.VerifyListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.RowData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.ToolItem; +import org.tizen.efluibuilder.gef.viewer.IScalableViewer; +import org.tizen.efluibuilder.model.util.ModelConstants; +import org.tizen.efluibuilder.nl.BuilderMessages; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.efluibuilder.ui.editor.ZoomUtil; +import org.tizen.efluibuilder.ui.resources.ImageResources; +import org.tizen.efluibuilder.ui.widgets.TizenScale; + + +public class ZoomControlToolbar extends AbstractToolbar implements IZoomToolbar { + + // private static final String ICON_FIT = "res/icons/editor/fit.png"; + // //$NON-NLS-1$ + + // private static final int FIT_ITEM_WIDTH = 30; + + private TizenScale scale; + private ToolItem scaleItem; + private ToolItem fitItem; + + private ToolItem zoomValueItem; + private Text zoomValueText; + + private String oldZoom = null; + + private IScalableViewer viewer = null; + + public ZoomControlToolbar(Composite parent, CombineEditorPart editor) { + super(parent, editor); + draw(); + // layout(); // It is replaced to RowLayout + widgetEvent(); + } + + public void updateZoomControl(double value) { + + int zoom = (int) Math.round(value * 100); + + scale.setSelection(zoom); + zoomValueText.setText(Integer.toString(zoom)); + oldZoom = Integer.toString(zoom); + } + + public void dispose() { + } + + private void draw() { + if (getControl() == null) { + return; + } + + getControl().setLayoutData(new RowData(SWT.DEFAULT, ToolBarConstants.TOOLBAR_HEIGHT)); + + fitItem = new ToolItem(getControl(), SWT.BUTTON1); + fitItem.setToolTipText(BuilderMessages.AUTO_FIT); + fitItem.setImage(ImageResources.getImage(ImageResources.TOOLBAR_AUTO_FIT_NOR)); + fitItem.setDisabledImage(ImageResources.getImage(ImageResources.TOOLBAR_AUTO_FIT_DIM)); + fitItem.setHotImage(ImageResources.getImage(ImageResources.TOOLBAR_AUTO_FIT_MV)); + + ToolbarUtil.addBlankItem(getControl(), new RowData(SWT.DEFAULT, ToolBarConstants.TOOLBAR_HEIGHT)); + + Label minusLabel = new Label(getControl(), SWT.NONE); + minusLabel.setImage(ImageResources.getImage(ImageResources.TOOLBAR_ZOOM_OUT_NOR)); + minusLabel.addMouseListener(new MouseAdapter() { + @Override + public void mouseDown(MouseEvent e) { + String text = zoomValueText.getText(); + int nextScale = Integer.parseInt(text) - ZoomUtil.ZOOM_INCREMENT; + setZoomScale(Integer.toString(nextScale)); + } + }); + minusLabel.addMouseTrackListener(new MouseTrackAdapter() { + private Image oldImage = null; + + @Override + public void mouseEnter(MouseEvent e) { + Label label = (Label) e.widget; + if (this.oldImage == null) { + this.oldImage = label.getImage(); + label.setImage(ImageResources.getImage(ImageResources.TOOLBAR_ZOOM_OUT_MV)); + } + } + + @Override + public void mouseExit(MouseEvent e) { + Label label = (Label) e.widget; + if (this.oldImage != null) { + label.setImage(this.oldImage); + this.oldImage = null; + } + } + }); + ToolItem minusItem = new ToolItem(getControl(), SWT.SEPARATOR); + minusItem.setControl(minusLabel); + minusItem.setWidth(minusLabel.getSize().x); + + scale = new TizenScale(getControl(), SWT.HORIZONTAL); + scale.setMaximum(ZoomUtil.MAX_ZOOM_PERCENT); + scale.setMinimum(ZoomUtil.MIN_ZOOM_PERCENT); + scale.setPageIncrement(ZoomUtil.ZOOM_INCREMENT); + scale.setOrientation(SWT.LEFT_TO_RIGHT); + scaleItem = new ToolItem(getControl(), SWT.SEPARATOR); + scaleItem.setControl(scale); + scaleItem.setWidth(ToolBarConstants.TOOLITEM_SCALE_WIDTH); + + Label plusLabel = new Label(getControl(), SWT.NONE); + plusLabel.setImage(ImageResources.getImage(ImageResources.TOOLBAR_ZOOM_IN_NOR)); + plusLabel.addMouseListener(new MouseAdapter() { + @Override + public void mouseDown(MouseEvent e) { + String text = zoomValueText.getText(); + int nextScale = Integer.parseInt(text) + ZoomUtil.ZOOM_INCREMENT; + setZoomScale(Integer.toString(nextScale)); + } + }); + plusLabel.addMouseTrackListener(new MouseTrackAdapter() { + private Image oldImage = null; + + @Override + public void mouseEnter(MouseEvent e) { + Label label = (Label) e.widget; + if (this.oldImage == null) { + this.oldImage = label.getImage(); + label.setImage(ImageResources.getImage(ImageResources.TOOLBAR_ZOOM_IN_MV)); + } + } + + @Override + public void mouseExit(MouseEvent e) { + Label label = (Label) e.widget; + if (this.oldImage != null) { + label.setImage(this.oldImage); + this.oldImage = null; + } + } + }); + ToolItem plusItem = new ToolItem(getControl(), SWT.SEPARATOR); + plusItem.setControl(plusLabel); + plusItem.setWidth(plusLabel.getSize().x); + + ToolbarUtil.addBlankItem(getControl(), 10, new RowData(SWT.DEFAULT, ToolBarConstants.TOOLBAR_HEIGHT)); + + zoomValueText = new Text(getControl(), SWT.LEFT_TO_RIGHT | SWT.RIGHT | SWT.BORDER); + zoomValueText.pack(); + zoomValueItem = new ToolItem(getControl(), SWT.SEPARATOR); + zoomValueItem.setControl(zoomValueText); + zoomValueItem.setWidth(40); + + ToolbarUtil.addBlankItem(getControl(), 5, new RowData(SWT.DEFAULT, ToolBarConstants.TOOLBAR_HEIGHT)); + + Label percentLabel = new Label(getControl(), SWT.NONE); + percentLabel.setImage(ImageResources.getImage(ImageResources.TOOLBAR_PERCENT_NOR)); + percentLabel.pack(); + ToolItem percentItem = new ToolItem(getControl(), SWT.SEPARATOR); + percentItem.setControl(percentLabel); + percentItem.setWidth(percentLabel.getSize().x + ToolBarConstants.TOOLITEM_WIDTH_MARGIN); + } + + private void widgetEvent() { + if (getControl() == null) { + return; + } + + zoomValueText.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetDefaultSelected(SelectionEvent event) { + String text = ((Text) event.widget).getText(); + setZoomScale(text); + } + }); + + zoomValueText.addFocusListener(new FocusAdapter() { + + @Override + public void focusLost(FocusEvent event) { + zoomValueText.setText(oldZoom); + } + }); + + zoomValueText.addVerifyListener(new VerifyListener() { + @Override + public void verifyText(VerifyEvent event) { + char character = event.character; + if (character == '\0') { + return; + } + + if (event.keyCode == SWT.BS || event.keyCode == SWT.DEL || Character.isDigit(character)) { + event.doit = true; + } else { + event.doit = false; + } + } + }); + + scale.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + int sel = ((TizenScale) e.getSource()).getSelection(); + setZoomScale(Integer.toString(sel)); + } + }); + + fitItem.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (viewer != null) { + viewer.setFitMode(true); + } + // updateFitButtonToolTip(); + } + }); + } + + private boolean isValidate(String zoom) { + if (zoom == null || zoom.isEmpty()) { + zoomValueText.setText(oldZoom); + return false; + } + + if (!zoom.matches(ModelConstants.INTEGERVALUE)) { + return false; + } + + if (oldZoom.equals(ZoomUtil.getMinZoom()) && ZoomUtil.isLTMinZoom(zoom)) { + zoomValueText.setText(oldZoom); + return false; + } + + if (oldZoom.equals(ZoomUtil.getMaxZoom()) && ZoomUtil.isGTMaxZoom(zoom)) { + zoomValueText.setText(oldZoom); + return false; + } + + return true; + } + + private void setZoomScale(String zoom) { + if (viewer == null) { + return; + } + + if (!isValidate(zoom)) { + return; + } + + if (isFitMode()) { + setFitMode(false); + } + + double value = Double.parseDouble(zoom) / 100; + viewer.setZoomScale(value); + } + + // private void updateFitButtonToolTip() { + // String toolTip = null; + // if (isFitMode()) { + // toolTip = BuilderMessages.AUTO_FIT_OFF; + // } else { + // toolTip = BuilderMessages.AUTO_FIT_ON; + // } + // fitItem.setToolTipText(toolTip); + // + // } + + @Override + public void setFitMode(boolean isFit) { + fitItem.setSelection(isFit); + // updateFitButtonToolTip(); + if (viewer != null) { + viewer.setFitMode(isFit); + } + } + + @Override + public boolean isFitMode() { + return viewer.getFitMode(); + } + + @Override + public void zoomChanged(double value) { + updateZoomControl(value); + } + + @Override + public void setViewer(IScalableViewer viewer) { + if (this.viewer != null) { + this.viewer.removeZoomScaleChangedListener(this); + } + this.viewer = viewer; + if (this.viewer != null) { + this.viewer.addZoomScaleChangedListener(this); + this.viewer.setZoomControlToolbar(this); + this.updateZoomControl(viewer.getZoomScale()); + } + } + + public void setEnabled(boolean enabled) { + getControl().setEnabled(enabled); + scale.setEnabled(enabled); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/resources/ColorResources.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/resources/ColorResources.java new file mode 100644 index 0000000..110df65 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/resources/ColorResources.java @@ -0,0 +1,150 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.resources; + +import org.eclipse.jface.resource.ColorRegistry; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.graphics.RGBA; + + +public class ColorResources { + private static ColorRegistry colorRegistry = new ColorRegistry(); + private static int key; + + /* + * Do not dispose following Colors explicitly + */ + /* + * GEF Policy + */ + public static final Color POLICY_INFO_FEEDBACK = getColor(new RGB(0xff, 0xff, 0xff)); + public static final Color POLICY_HOVER_FEEDBACK = getColor(new RGB(0x00, 0x00, 0xff)); + + /* + * M-Screen + */ + public static final Color MSCREEN_CONFIGURATOR_ORIENT_BG = getColor(new RGB(0xff, 0xff, 0xff));// $NON-NLS-1$ + + /* + * WYSIWYG Toolbar + */ + public static final Color TOOLBAR_VIEW_TEXT_LABEL = getColor(new RGB(0xff, 0xff, 0xff));// $NON-NLS-1$ + public static final Color TOOLBAR_EDITOR_SWITCH_BACKGROUND = getColor(new RGB(0x00, 0x8a, 0xee));// $NON-NLS-1$ + + /* + * WYSIWYG Palette + */ + public static final Color PALETTE_TITLE = getColor(new RGB(0x00, 0x8a, 0xee));// $NON-NLS-1$ + public static final Color PALETTE_TITLE_BACKGROUND = getColor(new RGB(0xff, 0xff, 0xff));// $NON-NLS-1$ + public static final Color PALETTE_CATEGORY_NORMAL = getColor(new RGB(0x58, 0x58, 0x58));// $NON-NLS-1$ + public static final Color PALETTE_CATEGORY_SELECT = PALETTE_CATEGORY_NORMAL;// $NON-NLS-1$ + public static final Color PALETTE_CATEGORY_TRIANGLE = PALETTE_CATEGORY_NORMAL;// $NON-NLS-1$ + public static final Color PALETTE_CATEGORY_BACKGROUND = getColor(new RGB(0xe1, 0xe1, 0xe1));// $NON-NLS-1$ + public static final Color PALETTE_UI_COMPONENT_NORMAL = PALETTE_CATEGORY_NORMAL;// $NON-NLS-1$ + public static final Color PALETTE_UI_COMPONENT_SELECT = getColor(new RGB(0x00, 0x8a, 0xee));// $NON-NLS-1$ + public static final Color PALETTE_SCROLLBAR_TRIANGLE_BACKGROUND = getColor(new RGB(0x33, 0x33, 0x33));// $NON-NLS-1$ + + /* + * Preview + */ + public static final Color PREVIEW_BACKGROUND = getColor(new RGB(0xd7, 0xd7, 0xd7));// $NON-NLS-1$ + public static final Color PREVIEW_SPLITTER = getColor(new RGB(0x58, 0x58, 0x58));// $NON-NLS-1$ + + /* + * Outline view + */ + public static final Color OUTLINE_BACKGROUND = getColor(new RGB(0xf8, 0xf8, 0xf8));// $NON-NLS-1$ + + /* + * Properties view + */ + public static final Color PROPERTIES_TITLE_BG = getColor(new RGB(0xe1, 0xe1, 0xe1));// $NON-NLS-1$ + public static final Color PROPERTIES_CONTENT_BG = getColor(new RGB(0xf8, 0xf8, 0xf8));// $NON-NLS-1$ + public static final Color PROPERTIES_SEPERARTOR = getColor(new RGB(0xaa, 0xaa, 0xaa));// $NON-NLS-1$ + public static final Color PROPERTIES_ATTR_SEPERATOR = getColor(new RGB(0xd1, 0xd1, 0xd1));// $NON-NLS-1$ + public static final Color PROPERTIES_EVENT_LABEL = getColor(new RGB(0x46, 0x46, 0x46));// $NON-NLS-1$ + public static final Color PROPERTIES_ATTR_LABEL = getColor(new RGB(0x46, 0x46, 0x46));// $NON-NLS-1$ + public static final Color PROPERTIES_ATTR_LABEL_DIM = getColor(new RGB(0xd0, 0xd0, 0xd0));// $NON-NLS-1$ + public static final Color PROPERTIES_CD_DESCRIPTOR = getColor(new RGB(0x33, 0x33, 0x33));// $NON-NLS-1$ + + /* + * Tizen Scale + */ + public static final Color TIZEN_SCALE_THUMB_NOR = getColor(new RGB(0x00, 0x8a, 0xee));// $NON-NLS-1$ + public static final Color TIZEN_SCALE_THUMB_DIM = getColor(new RGB(0xd0, 0xd0, 0xd0));// $NON-NLS-1$ + public static final Color TIZEN_SCALE_AREA_NOR = getColor(new RGB(0xa6, 0xa6, 0xa6));// $NON-NLS-1$ + public static final Color TIZEN_SCALE_AREA_DIM = getColor(new RGB(0xd0, 0xd0, 0xd0));// $NON-NLS-1$ + + /* + * Dialog View + */ + public static final Color DIALOG_TABLE_BG = getColor(new RGB(0xff, 0xff, 0xff));// $NON-NLS-1$ + public static final Color DIALOG_IMAGECOMPOSITE_BG_COLOR = getColor(new RGB(0xd7, 0xd7, 0xd7));// $NON-NLS-1$ + public static final Color DIALOG_IMAGE_BORDER_COLOR = getColor(new RGB(0xCC, 0xCC, 0xCC));// $NON-NLS-1$ + public static final Color DIALOG_NEW_VIEW_ID_LABEL = getColor(new RGB(0x33, 0x33, 0x33));// $NON-NLS-1$ + public static final Color DIALOG_NEW_VIEW_NAME_TEXT_BG = getColor(new RGB(0xf8, 0xf8, 0xf8));// $NON-NLS-1$ + public static final Color DIALOG_NEW_VIEW_TEMPLATE_LINE = getColor(new RGB(0xaa, 0xaa, 0xaa));// $NON-NLS-1$ + + /* + * WYSIWYG Design Editor + */ + public static final Color DESIGN_EDITOR_SELECTION_LINE_COLOR = getColor(new RGB(0x00, 0x88, 0xEE));// $NON-NLS-1$ + public static final Color DESIGN_EDITOR_REISIZE_HANDLE_FILL_COLOR = getColor(new RGB(0xFF, 0xFF, 0xFF));// $NON-NLS-1$ + public static final Color DESIGN_EDITOR_REISIZE_HANDLE_LINE_COLOR = DESIGN_EDITOR_SELECTION_LINE_COLOR;// $NON-NLS-1$ + public static final Color DESIGN_EDITOR_CONTAINER_LINE_COLOR = getColor(new RGB(0xFF, 0xF8, 0x80));// $NON-NLS-1$ + public static final Color DESIGN_EDITOR_COMPONENT_HOVER_COLOR = getColor(new RGB(0x00, 0x7F, 0xD6));// $NON-NLS-1$ + public static final Color DESIGN_EDITOR_PLACEHOLDER_LINE_COLOR = getColor(new RGB(0xFF, 0xFF, 0xFF));// $NON-NLS-1$ + public static final Color DESIGN_EDITOR_CHANGE_BOUND_FEEDBACK_LINE_COLOR = getColor(new RGB(0x00, 0x8A, 0xEE));// $NON-NLS-1$ + public static final Color DESIGN_EDITOR_CHANGE_BOUND_FEEDBACK_FILL_COLOR = new Color(null, new RGBA(0x00, 0x7F, 0xD6, 0x33));// $NON-NLS-1$ + public static final Color DESIGN_EDITOR_SNAP_FEEDBACK_LINE_COLOR = getColor(new RGB(0xFF, 0x58, 0xDA));// $NON-NLS-1$ + public static final Color DESIGN_EDITOR_CREATION_BOUND_FEEDBACK_COLOR = getColor(new RGB(0x00, 0x8A, 0xEE));// $NON-NLS-1$ + + public static final Color DESIGN_EDITOR_VIEW_FIGURE_BG_NORMAL_COLOR = getColor(new RGB(0x4B, 0x4B, 0x4B));// $NON-NLS-1$ + public static final Color DESIGN_EDITOR_VIEW_FIGURE_BG_SELECTED_COLOR = getColor(new RGB(0x00, 0x8A, 0xEE));// $NON-NLS-1$ + public static final Color DESIGN_EDITOR_VIEW_FIGURE_FONT_NORMAL_COLOR = getColor(new RGB(0xFF, 0xFF, 0xFF));// $NON-NLS-1$ + public static final Color DESIGN_EDITOR_VIEW_FIGURE_FONT_SELECTED_COLOR = getColor(new RGB(0xFF, 0xFF, 0xFF));// $NON-NLS-1$ + public static final Color DESIGN_EDITOR_CONNECTION_SELECTED_COLOR = getColor(new RGB(0x00, 0x8A, 0xEE));// $NON-NLS-1$ + public static final Color DESIGN_EDITOR_CONNECTION_UNSELECTED_COLOR = getColor(new RGB(0x4B, 0x4B, 0x4B));// $NON-NLS-1$ + public static final Color DESIGN_EDITOR_BACKGROUND = getColor(new RGB(0xd7, 0xd7, 0xd7));// $NON-NLS-1$ + + /* + * Project Migration Wizard + */ + public static final Color PROJECT_MIGRATER_USERVIEW_ERROR_COLOR = getColor(new RGB(0xff, 0x01, 0x01));// $NON-NLS-1$ + + private static Color getColor(RGB rgb) { + String key_ = Integer.toString(++key); + colorRegistry.put(key_, rgb); + return colorRegistry.get(key_); + } + + /* + * Invalid XML dialog + */ + public static final Color DIALOG_INVALID_XML_BG = getColor(new RGB(0x00, 0x00, 0x00));// $NON-NLS-1$ + public static final Color DIALOG_INVALID_XML_LABEL = getColor(new RGB(0xff, 0xff, 0xff));// $NON-NLS-1$ + public static final Color EDITOR_INVALID_XML_BG = getColor(new RGB(0xff, 0x00, 0x00));// $NON-NLS-1$ + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/resources/FontResources.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/resources/FontResources.java new file mode 100644 index 0000000..4285ba0 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/resources/FontResources.java @@ -0,0 +1,99 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.resources; + +import org.eclipse.jface.resource.FontRegistry; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.ui.PlatformUI; + + +public class FontResources { + private static FontRegistry fontRegistry = new FontRegistry(); + private static final Font defaultFont = getDefaultFont(); + private static int key; + + /* + * Do not dispose following Fonts explicitly + */ + /* + * Common + */ + public static final Font BOLD = getFont(SWT.BOLD); + + /* + * WYSIWYG Palette + */ + public static final Font PALETTE_COMPONENT_NORMAL = getFont(SWT.NONE, (int) (11.0f * 0.75));// $NON-NLS-1$ + public static final Font PALETTE_COMPONENT_BOLD = getFont(SWT.BOLD, (int) (11.0f * 0.75));// $NON-NLS-1$ + public static final Font PALETTE_CATEGORY_NORMAL = getFont(SWT.NONE, (int) (13.0f * 0.75));// $NON-NLS-1$ + public static final Font PALETTE_CATEGORY_BOLD = getFont(SWT.BOLD, (int) (13.0f * 0.75));// $NON-NLS-1$ + public static final Font PALETTE_TITLE_BOLD = getFont(SWT.BOLD, (int) (13.0f * 0.75));// $NON-NLS-1$ + public static final Font TOOLBAR_VIEW_NAVIGATION_LABEL = getFont(SWT.BOLD | SWT.ITALIC, 9);// $NON-NLS-1$ + public static final Font WYSIWYG_INVALID_XML_TITLE = getFont(SWT.BOLD, (int) (13.0f * .75));// $NON-NLS-1$ + public static final Font WYSIWYG_INVALID_XML_TITLE_DESCRIPTION = getFont(SWT.NONE, (int) (13.0f * 0.75));// $NON-NLS-1$ + + /** + * Gets default(System) font. + * + * Do not dispose this System fonts. The System fonts will be disposing in a release method of + * the Display. + * + * @return default(System) font + * @see org.eclipse.swt.graphics.Device#release() + */ + public static Font getDefaultFont() { + return PlatformUI.getWorkbench().getDisplay().getSystemFont(); + } + + private static Font getFont(int style) { + return getFont(null, style, -1); + } + + private static Font getFont(int style, int size) { + return getFont(null, style, size); + } + + private static Font getFont(String name, int style, int size) { + String key_ = Integer.toString(key++); + FontData[] fontData = getFontDataFromDefault(name, style, size); + fontRegistry.put(key_, fontData); + return fontRegistry.get(key_); + } + + private static FontData[] getFontDataFromDefault(String name, int style, int size) { + FontData[] fontData = defaultFont.getFontData().clone(); + for (int i = 0; i < fontData.length; i++) { + fontData[i].setStyle(style); + if (size >= 0) { + fontData[i].setHeight(size); + } + if (name != null) { + fontData[i].setName(name); + } + } + return fontData; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/resources/ImageResources.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/resources/ImageResources.java new file mode 100644 index 0000000..df22ad6 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/resources/ImageResources.java @@ -0,0 +1,277 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.resources; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.swt.graphics.Image; +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.BuilderPlugin; + + +public class ImageResources { + private static ImageRegistry imageRegistry = BuilderPlugin.getDefault().getImageRegistry(); + /* + * WYSIWYG Toolbar + */ + public static final String TOOLBAR_AUTO_FIT_NOR = BuilderConstants.ICON_DIR + "editor/toolbar/tool_autofit_nor.png"; //$NON-NLS-1$ + public static final String TOOLBAR_AUTO_FIT_DIM = BuilderConstants.ICON_DIR + "editor/toolbar/tool_autofit_dim.png"; //$NON-NLS-1$ + public static final String TOOLBAR_AUTO_FIT_MV = BuilderConstants.ICON_DIR + "editor/toolbar/tool_autofit_mv.png"; //$NON-NLS-1$ + public static final String TOOLBAR_AUTO_FIT_SEL = BuilderConstants.ICON_DIR + "editor/toolbar/tool_autofit_sel.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ZOOM_IN_NOR = BuilderConstants.ICON_DIR + "editor/toolbar/tool_zoom_in_nor.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ZOOM_IN_MV = BuilderConstants.ICON_DIR + "editor/toolbar/tool_zoom_in_mv.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ZOOM_IN_SEL = BuilderConstants.ICON_DIR + "editor/toolbar/tool_zoom_in_sel.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ZOOM_OUT_NOR = BuilderConstants.ICON_DIR + "editor/toolbar/tool_zoom_out_nor.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ZOOM_OUT_MV = BuilderConstants.ICON_DIR + "editor/toolbar/tool_zoom_out_mv.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ZOOM_OUT_SEL = BuilderConstants.ICON_DIR + "editor/toolbar/tool_zoom_out_sel.png"; //$NON-NLS-1$ + public static final String TOOLBAR_DESIGN_NOR = BuilderConstants.ICON_DIR + "editor/toolbar/tool_design_nor.png"; //$NON-NLS-1$ + public static final String TOOLBAR_DESIGN_SEL = BuilderConstants.ICON_DIR + "editor/toolbar/tool_design_sel.png"; //$NON-NLS-1$ + public static final String TOOLBAR_SOURCE_NOR = BuilderConstants.ICON_DIR + "editor/toolbar/tool_source_nor.png"; //$NON-NLS-1$ + public static final String TOOLBAR_SOURCE_SEL = BuilderConstants.ICON_DIR + "editor/toolbar/tool_source_sel.png"; //$NON-NLS-1$ + public static final String TOOLBAR_AUTO_LAYOUT_NOR = BuilderConstants.ICON_DIR + "editor/toolbar/tool_match_auto_layout_nor.png"; //$NON-NLS-1$ + public static final String TOOLBAR_AUTO_LAYOUT_MV = BuilderConstants.ICON_DIR + "editor/toolbar/tool_match_auto_layout_mv.png"; //$NON-NLS-1$ + public static final String TOOLBAR_AUTO_LAYOUT_SEL = BuilderConstants.ICON_DIR + "editor/toolbar/tool_match_auto_layout_sel.png"; //$NON-NLS-1$ + public static final String TOOLBAR_AUTO_LAYOUT_DIM = BuilderConstants.ICON_DIR + "editor/toolbar/tool_match_auto_layout_dim.png"; //$NON-NLS-1$ + + // Action + public static final String TOOLBAR_ALIGN_LEFT_NOR = BuilderConstants.ICON_DIR + "editor/toolbar/tool_align_left_nor.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_LEFT_DIM = BuilderConstants.ICON_DIR + "editor/toolbar/tool_align_left_dim.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_LEFT_MV = BuilderConstants.ICON_DIR + "editor/toolbar/tool_align_left_mv.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_LEFT_SEL = BuilderConstants.ICON_DIR + "editor/toolbar/tool_align_left_sel.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_CENTER_NOR = BuilderConstants.ICON_DIR + "editor/toolbar/tool_align_center_nor.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_CENTER_DIM = BuilderConstants.ICON_DIR + "editor/toolbar/tool_align_center_dim.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_CENTER_MV = BuilderConstants.ICON_DIR + "editor/toolbar/tool_align_center_mv.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_CENTER_SEL = BuilderConstants.ICON_DIR + "editor/toolbar/tool_align_center_sel.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_RIGHT_NOR = BuilderConstants.ICON_DIR + "editor/toolbar/tool_align_right_nor.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_RIGHT_DIM = BuilderConstants.ICON_DIR + "editor/toolbar/tool_align_right_dim.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_RIGHT_MV = BuilderConstants.ICON_DIR + "editor/toolbar/tool_align_right_mv.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_RIGHT_SEL = BuilderConstants.ICON_DIR + "editor/toolbar/tool_align_right_sel.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_TOP_NOR = BuilderConstants.ICON_DIR + "editor/toolbar/tool_align_top_nor.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_TOP_DIM = BuilderConstants.ICON_DIR + "editor/toolbar/tool_align_top_dim.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_TOP_MV = BuilderConstants.ICON_DIR + "editor/toolbar/tool_align_top_mv.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_TOP_SEL = BuilderConstants.ICON_DIR + "editor/toolbar/tool_align_top_sel.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_MIDDLE_NOR = BuilderConstants.ICON_DIR + "editor/toolbar/tool_align_middle_nor.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_MIDDLE_DIM = BuilderConstants.ICON_DIR + "editor/toolbar/tool_align_middle_dim.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_MIDDLE_MV = BuilderConstants.ICON_DIR + "editor/toolbar/tool_align_middle_mv.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_MIDDLE_SEL = BuilderConstants.ICON_DIR + "editor/toolbar/tool_align_middle_sel.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_BOTTOM_NOR = BuilderConstants.ICON_DIR + "editor/toolbar/tool_align_bottom_nor.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_BOTTOM_DIM = BuilderConstants.ICON_DIR + "editor/toolbar/tool_align_bottom_dim.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_BOTTOM_MV = BuilderConstants.ICON_DIR + "editor/toolbar/tool_align_bottom_mv.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_BOTTOM_SEL = BuilderConstants.ICON_DIR + "editor/toolbar/tool_align_bottom_sel.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_WIDTH_NOR = BuilderConstants.ICON_DIR + "editor/toolbar/tool_match_width_nor.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_WIDTH_DIM = BuilderConstants.ICON_DIR + "editor/toolbar/tool_match_width_dim.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_WIDTH_MV = BuilderConstants.ICON_DIR + "editor/toolbar/tool_match_width_mv.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_WIDTH_SEL = BuilderConstants.ICON_DIR + "editor/toolbar/tool_match_width_sel.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_HEIGHT_NOR = BuilderConstants.ICON_DIR + "editor/toolbar/tool_match_height_nor.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_HEIGHT_DIM = BuilderConstants.ICON_DIR + "editor/toolbar/tool_match_height_dim.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_HEIGHT_MV = BuilderConstants.ICON_DIR + "editor/toolbar/tool_match_height_mv.png"; //$NON-NLS-1$ + public static final String TOOLBAR_ALIGN_HEIGHT_SEL = BuilderConstants.ICON_DIR + "editor/toolbar/tool_match_height_sel.png"; //$NON-NLS-1$ + public static final String TOOLBAR_PERCENT_NOR = BuilderConstants.ICON_DIR + "editor/toolbar/tool_percent_nor.png"; //$NON-NLS-1$ + // View navigation + public static final String TOOLBAR_NAVI_RIGHT_ARROW = BuilderConstants.ICON_DIR + "editor/right_arrow.png"; //$NON-NLS-1$ + public static final String TOOLBAR_NAVI_LEFT_ARROW = BuilderConstants.ICON_DIR + "editor/toolbar/left_arrow.png"; //$NON-NLS-1$ + public static final String TOOLBAR_NAVI_DOWN_ARROW = BuilderConstants.ICON_DIR + "editor/toolbar/down_arrow.png"; //$NON-NLS-1$ + // editor + public static final String EDITOR_OPEN_EDC_EDITOR = BuilderConstants.ICON_DIR + "editor/icon_link_to_edc.png"; //$NON-NLS-1$ + public static final String EDITOR_CONNECTION_END_POINT_SEL_V = BuilderConstants.ICON_DIR + "editor/connection_line_sel_v.png"; //$NON-NLS-1$ + public static final String EDITOR_CONNECTION_END_POINT_SEL_H = BuilderConstants.ICON_DIR + "editor/connection_line_sel_h.png"; //$NON-NLS-1$ + public static final String EDITOR_CONNECTION_END_POINT_NOR_V = BuilderConstants.ICON_DIR + "editor/connection_line_nor_v.png"; //$NON-NLS-1$ + public static final String EDITOR_CONNECTION_END_POINT_NOR_H = BuilderConstants.ICON_DIR + "editor/connection_line_nor_h.png"; //$NON-NLS-1$ + public static final String EDITOR_STARTUP_VIEW_HOME_B = BuilderConstants.ICON_DIR + "editor/ic_view_startup_b.png"; //$NON-NLS-1$ + public static final String EDITOR_STARTUP_VIEW_HOME_W = BuilderConstants.ICON_DIR + "editor/ic_view_startup_w.png"; //$NON-NLS-1$ + + /* + * WYSIWYG Palette + */ + public static final String PALETTE_TITLE_ICON = BuilderConstants.ICON_DIR + "editor/palette/pal_title.png"; //$NON-NLS-1$ + public static final String PALETTE_CATEGORY_ICON_UI_VIEW = BuilderConstants.ICON_DIR + "editor/palette/pal_title_view_nor.png"; //$NON-NLS-1$ + public static final String PALETTE_CATEGORY_ICON_UI_CONTAINER = BuilderConstants.ICON_DIR + "editor/palette/pal_title_uicontainer_nor.png"; //$NON-NLS-1$ + public static final String PALETTE_CATEGORY_ICON_UI_COMPONENT = BuilderConstants.ICON_DIR + "editor/palette/pal_title_uicomponent_nor.png"; //$NON-NLS-1$ + public static final String PALETTE_CATEGORY_ICON_UI_SNIPPET = BuilderConstants.ICON_DIR + "editor/palette/pal_title_snippet_nor.png"; //$NON-NLS-1$ + + public static final String PALETTE_CATEGORY_ICON_UI_VIEW_SELECTED = BuilderConstants.ICON_DIR + "editor/palette/pal_title_view_nor.png"; //$NON-NLS-1$ + public static final String PALETTE_CATEGORY_ICON_UI_CONTAINER_SELECTED = BuilderConstants.ICON_DIR + "editor/palette/pal_title_uicontainer_nor.png"; //$NON-NLS-1$ + public static final String PALETTE_CATEGORY_ICON_UI_COMPONENT_SELECTED = BuilderConstants.ICON_DIR + "editor/palette/pal_title_uicomponent_nor.png"; //$NON-NLS-1$ + public static final String PALETTE_CATEGORY_ICON_UI_SNIPPET_SELECTED = BuilderConstants.ICON_DIR + "editor/palette/pal_title_snippet_nor.png"; //$NON-NLS-1$ + public static final String PALETTE_ICON_FILE_ARROW_DOWN = BuilderConstants.ICON_DIR + "editor/palette/pal_title_arrow_down_nor.png"; + public static final String PALETTE_ICON_FILE_ARROW_UP = BuilderConstants.ICON_DIR + "editor/palette/pal_title_arrow_up_nor.png"; + + /* + * M-Screen + */ + public static final String MSCREEN_ICON_FILE_DELETE = BuilderConstants.ICON_DIR + "editor/ms_config_delete.png"; //$NON-NLS-1$ + public static final String MSCREEN_ICON_FILE_PORT_ON = BuilderConstants.ICON_DIR + "editor/ms_config_port_on.png"; //$NON-NLS-1$ + public static final String MSCREEN_ICON_FILE_PORT_OFF = BuilderConstants.ICON_DIR + "editor/ms_config_port_off.png"; //$NON-NLS-1$ + public static final String MSCREEN_ICON_FILE_LAND_ON = BuilderConstants.ICON_DIR + "editor/ms_config_land_on.png"; //$NON-NLS-1$ + public static final String MSCREEN_ICON_FILE_LAND_OFF = BuilderConstants.ICON_DIR + "editor/ms_config_land_off.png"; //$NON-NLS-1$ + + /* + * Snippet + */ + public static final String SNIPPET_DEFAULT_SNIPPET_IMAGE = BuilderConstants.ICON_DIR + "snippet/default_snippet.png"; //$NON-NLS-1$ + + /* + * Preview + */ + public static final String PREVIEW_MOBILE_HD_PORTRAIT = BuilderConstants.ICON_DIR + "preview/mobile_HD/mobile_HD.png"; //$NON-NLS-1$ + public static final String PREVIEW_MOBILE_HD_LANDSCAPE = BuilderConstants.ICON_DIR + "preview/mobile_HD/mobile_HD_landscape.png"; //$NON-NLS-1$ + public static final String PREVIEW_MOBILE_WVGA_PORTRAT = BuilderConstants.ICON_DIR + "preview/mobile_WVGA/mobile_WVGA.png"; //$NON-NLS-1$ + public static final String PREVIEW_MOBILE_WVGA_LANDSCAPE = BuilderConstants.ICON_DIR + "preview/mobile_WVGA/mobile_WVGA_landscape.png"; //$NON-NLS-1$ + public static final String PREVIEW_CIRCLE = BuilderConstants.ICON_DIR + "preview/wearable_circle.png"; //$NON-NLS-1$ + public static final String PREVIEW_WEARABLE_RECT_320 = BuilderConstants.ICON_DIR + "preview/wearable_320.png"; //$NON-NLS-1$ + public static final String PREVIEW_WEARABLE_RECT_360 = BuilderConstants.ICON_DIR + "preview/wearable_360.png"; //$NON-NLS-1$ + public static final String PREVIEW_TOOLBAR_DUMMY = BuilderConstants.ICON_DIR + "transparent_dummy.png"; //$NON-NLS-1$ + + /* + * Properties view + */ + public static final String PROPERTIES_EVENT_ARROW = BuilderConstants.ICON_DIR + "event/event_arrow.png"; //$NON-NLS-1$ + public static final String PROPERTIES_EVENT_PLUS_NOR = BuilderConstants.ICON_DIR + "event/event_plus_nor.png"; //$NON-NLS-1$ + public static final String PROPERTIES_EVENT_PLUS_SEL = BuilderConstants.ICON_DIR + "event/event_plus_sel.png"; //$NON-NLS-1$ + public static final String PROPERTIES_EVENT_PLUS_MV = BuilderConstants.ICON_DIR + "event/event_plus_mv.png"; //$NON-NLS-1$ + public static final String PROPERTIES_EVENT_PLUS_DIM = BuilderConstants.ICON_DIR + "event/event_plus_dim.png"; //$NON-NLS-1$ + public static final String PROPERTIES_EVENT_ARROW_BTN_NOR = BuilderConstants.ICON_DIR + "event/event_arrow_btn_nor.png"; //$NON-NLS-1$ + public static final String PROPERTIES_EVENT_ARROW_BTN_SEL = BuilderConstants.ICON_DIR + "event/event_arrow_btn_sel.png"; //$NON-NLS-1$ + public static final String PROPERTIES_EVENT_ARROW_BTN_MV = BuilderConstants.ICON_DIR + "event/event_arrow_btn_mv.png"; //$NON-NLS-1$ + public static final String PROPERTIES_EVENT_DELETE_NOR = BuilderConstants.ICON_DIR + "event/event_delete_nor.png"; //$NON-NLS-1$ + public static final String PROPERTIES_EVENT_DELETE_SEL = BuilderConstants.ICON_DIR + "event/event_delete_sel.png"; //$NON-NLS-1$ + public static final String PROPERTIES_EVENT_DELETE_MV = BuilderConstants.ICON_DIR + "event/event_delete_mv.png"; //$NON-NLS-1$ + public static final String PROPERTIES_BTN_IC_LOCATION_NOR = BuilderConstants.ICON_DIR + "properties/btn_ic_location_nor.png"; //$NON-NLS-1$ + public static final String PROPERTIES_BTN_IC_LOCATION_SEL = BuilderConstants.ICON_DIR + "properties/btn_ic_location_sel.png"; //$NON-NLS-1$ + public static final String PROPERTIES_BTN_IC_LOCATION_OVER = BuilderConstants.ICON_DIR + "properties/btn_ic_location_over.png"; //$NON-NLS-1$ + public static final String PROPERTIES_CD_ICON = BuilderConstants.ICON_DIR + "properties/cd_icon.png"; //$NON-NLS-1$ + // TODO Check that following is unnecessary. + public static final String PROPERTIES_HANDLER_GO_ICON = BuilderConstants.ICON_DIR + "go.png"; + public static final String PROPERTIES_SECOND_FOLDING_CLOSED = BuilderConstants.ICON_DIR + "second_folding_closed.png"; + public static final String PROPERTIES_ANIMATOR_ACTION_ADD_NOR = BuilderConstants.ICON_DIR + "animator_action_add_normal.png.png"; //$NON-NLS-1$ + public static final String PROPERTIES_ANIMATOR_ACTION_ADD_PUSH = BuilderConstants.ICON_DIR + "animator_action_add_push.png"; //$NON-NLS-1$ + public static final String PROPERTIES_ANIMATOR_ACTION_ADD_HOVER = BuilderConstants.ICON_DIR + "animator_action_add_hover.png"; //$NON-NLS-1$ + public static final String PROPERTIES_ANIMATOR_ACTION_DELETE_NOR = BuilderConstants.ICON_DIR + "animator_action_delete_normal.png"; //$NON-NLS-1$ + public static final String PROPERTIES_ANIMATOR_ACTION_DELETE_PUSH = BuilderConstants.ICON_DIR + "animator_action_delete_push.png"; //$NON-NLS-1$ + public static final String PROPERTIES_ANIMATOR_ACTION_DELETE_HOVER = BuilderConstants.ICON_DIR + "animator_action_delete_hover.png"; //$NON-NLS-1$ + public static final String PROPERTIES_DOWN_ARROW = BuilderConstants.ICON_DIR + "properties/down_arrow.png"; //$NON-NLS-1$ + public static final String PROPERTIES_UP_ARROW = BuilderConstants.ICON_DIR + "properties/up_arrow.png"; //$NON-NLS-1$ + + /* + * Method in Properties view + */ + public static final String METHOD_LEFT_ARROW_IMG_PATH = BuilderConstants.ICON_DIR + "style_clip_left_arrow.png"; + public static final String METHOD_RIGHT_ARROW_IMG_PATH = BuilderConstants.ICON_DIR + "style_clip_right_arrow.png"; + public static final String METHOD_UP_ARROW_IMG_PATH = BuilderConstants.ICON_DIR + "style_clip_up_arrow.png"; + public static final String METHOD_DOWN_ARROW_PATH = BuilderConstants.ICON_DIR + "style_clip_down_arrow.png"; + public static final String METHOD_IMAGE = BuilderConstants.ICON_DIR + "properties/image.png"; + public static final String METHOD_RESET = BuilderConstants.ICON_DIR + "properties/reset.png"; + public static final String METHOD_BOLD = BuilderConstants.ICON_DIR + "properties/bold.png"; + public static final String METHOD_ITALIC = BuilderConstants.ICON_DIR + "properties/italic.png"; + public static final String METHOD_UNDER_LINE = BuilderConstants.ICON_DIR + "properties/underline.png"; + public static final String METHOD_CANCEL_LINE = BuilderConstants.ICON_DIR + "properties/cancelline.png"; + public static final String METHOD_ALIGN_LEFT = BuilderConstants.ICON_DIR + "properties/align_left.png"; + public static final String METHOD_ALIGN_CENTER = BuilderConstants.ICON_DIR + "properties/align_center.png"; + public static final String METHOD_ALIGN_RIGHT = BuilderConstants.ICON_DIR + "properties/align_right.png"; + public static final String METHOD_ICON_FILE_LABEL_ITEM = BuilderConstants.ICON_DIR + "properties/ms_key_autocomplete.png"; + public static final String METHOD_COLOR_RESET_NOR = PROPERTIES_EVENT_DELETE_NOR; + public static final String METHOD_COLOR_RESET_SEL = PROPERTIES_EVENT_DELETE_SEL; + public static final String METHOD_COLOR_RESET_MV = PROPERTIES_EVENT_DELETE_MV; + + /* + * WYSIWYG Dialog + */ + public static final String DIALOG_DEVICE_MOBILE_PORTRAIT_DIM = BuilderConstants.ICON_DIR + "editor/dialog/device_mobile_s_dim.png"; + public static final String DIALOG_DEVICE_MOBILE_PORTRAIT_NOR = BuilderConstants.ICON_DIR + "editor/dialog/device_mobile_s_nor.png"; + public static final String DIALOG_DEVICE_MOBILE_LANDSCAPE_DIM = BuilderConstants.ICON_DIR + "editor/dialog/device_mobile_sv_dim.png"; + public static final String DIALOG_DEVICE_MOBILE_LANDSCAPE_NOR = BuilderConstants.ICON_DIR + "editor/dialog/device_mobile_sv_nor.png"; + public static final String DIALOG_PROFILE_DELETE_NOR = BuilderConstants.ICON_DIR + "editor/dialog/profile_delete_nor.png"; + public static final String DIALOG_PROFILE_DELETE_OVER = BuilderConstants.ICON_DIR + "editor/dialog/profile_delete_over.png"; + public static final String DIALOG_PROFILE_DELETE_SEL = BuilderConstants.ICON_DIR + "editor/dialog/profile_delete_sel.png"; + public static final String DIALOG_SC_BG = BuilderConstants.ICON_DIR + "editor/dialog/sc_bg.png"; + public static final String DIALOG_STORYBOARD_ARROW_LEFT = BuilderConstants.ICON_DIR + "editor/dialog/storyboard_arrow_left.png"; + public static final String DIALOG_STORYBOARD_ARROW_RIGHT = BuilderConstants.ICON_DIR + "editor/dialog/storyboard_arrow_right.png"; + public static final String DIALOG_VIEW_TAB_HELP_MV = BuilderConstants.ICON_DIR + "editor/dialog/view_tab_help_mv.png"; + public static final String DIALOG_VIEW_TAB_HELP_NOR = BuilderConstants.ICON_DIR + "editor/dialog/view_tab_help_nor.png"; + + /* + * UIB Converter Wizard + */ + public static final String UIB_CONVERTER_WIZARD_PAGE_IMAGE_MAIN = BuilderConstants.ICON_DIR + "uibconverter/wizard_page_main/uib_screenshot.png"; + public static final String UIB_CONVERTER_WIZARD_PAGE_IMAGE_SHAPE_CIRCLE = + BuilderConstants.ICON_DIR + "uibconverter/wizard_page_shape_type/wearable_circle.png"; + public static final String UIB_CONVERTER_WIZARD_PAGE_IMAGE_SHAPE_SQUARE = + BuilderConstants.ICON_DIR + "uibconverter/wizard_page_shape_type/wearable_square.png"; + public static final String UIB_CONVERTER_WIZARD_PAGE_IMAGE_APPENTRY_LEGACY = + BuilderConstants.ICON_DIR + "uibconverter/wizard_page_app_entry/code_legacy.png"; + public static final String UIB_CONVERTER_WIZARD_PAGE_IMAGE_APPENTRY_UIB = + BuilderConstants.ICON_DIR + "uibconverter/wizard_page_app_entry/code_uib.png"; + + public static final String UIB_CONVERTER_WIZARD_PAGE_IMAGE_USERVIEWS_SETSTARTUP_SEL = + BuilderConstants.ICON_DIR + "uibconverter/wizard_page_user_view/userviews_setasstartup_sel.png"; + public static final String UIB_CONVERTER_WIZARD_PAGE_IMAGE_USERVIEWS_SETSTARTUP_NOR = + BuilderConstants.ICON_DIR + "uibconverter/wizard_page_user_view/userviews_setasstartup_nor.png"; + public static final String UIB_CONVERTER_WIZARD_PAGE_IMAGE_USERVIEWS_SETSTARTUP_OVER = + BuilderConstants.ICON_DIR + "uibconverter/wizard_page_user_view/userviews_setasstartup_over.png"; + + public static final String UIB_CONVERTER_WIZARD_PAGE_IMAGE_USERVIEWS_DELETE_SEL = + BuilderConstants.ICON_DIR + "uibconverter/wizard_page_user_view/userviews_delete_sel.png"; + public static final String UIB_CONVERTER_WIZARD_PAGE_IMAGE_USERVIEWS_DELETE_NOR = + BuilderConstants.ICON_DIR + "uibconverter/wizard_page_user_view/userviews_delete_nor.png"; + public static final String UIB_CONVERTER_WIZARD_PAGE_IMAGE_USERVIEWS_DELETE_OVER = + BuilderConstants.ICON_DIR + "uibconverter/wizard_page_user_view/userviews_delete_over.png"; + + /* + * Invalid xml + */ + public static final String INVALID_XML_ERROR = BuilderConstants.ICON_DIR + "ic_error.png"; + + /** + * This method return cached image object. Do not dispose returned image. + * + * @param imagePath + * @return SWT image object + */ + public static Image getImage(String imagePath) { + // get data from cache + Image image = imageRegistry.get(imagePath); + if (image == null || image.isDisposed()) { + // create data + ImageDescriptor descriptor = BuilderPlugin.imageDescriptorFromPlugin(BuilderPlugin.PLUGIN_ID, imagePath); + if (descriptor == null) { + throw new IllegalArgumentException("Cannot load image: " + imagePath); + } + imageRegistry.put(imagePath, descriptor); + image = imageRegistry.get(imagePath); + } + return image; + } + + public static ImageDescriptor getImageDescriptor(String imagePath) { + ImageDescriptor descriptor = imageRegistry.getDescriptor(imagePath); + if (descriptor == null) { + descriptor = BuilderPlugin.imageDescriptorFromPlugin(BuilderPlugin.PLUGIN_ID, imagePath); + if (descriptor == null) { + throw new IllegalArgumentException("Cannot load image: " + imagePath); + } + imageRegistry.put(imagePath, descriptor); + } + return descriptor; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/Activator.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/Activator.java new file mode 100644 index 0000000..375bc63 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/Activator.java @@ -0,0 +1,72 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + + +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.tizen.efluibuilder.ui.view.databinding"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (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 Activator getDefault() { + return plugin; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/DataBindingDnDManager.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/DataBindingDnDManager.java new file mode 100644 index 0000000..f1c4e50 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/DataBindingDnDManager.java @@ -0,0 +1,547 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding; + +import org.eclipse.gef.dnd.TemplateTransfer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DragSource; +import org.eclipse.swt.dnd.DragSourceEffect; +import org.eclipse.swt.dnd.DragSourceEvent; +import org.eclipse.swt.dnd.DragSourceListener; +import org.eclipse.swt.dnd.DropTarget; +import org.eclipse.swt.dnd.DropTargetAdapter; +import org.eclipse.swt.dnd.DropTargetEvent; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.tizen.efluibuilder.gef.dnd.model.DataBindingTemplate; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingData; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingObject; +import org.tizen.efluibuilder.ui.view.databinding.model.TreeItemData; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; +import org.tizen.efluibuilder.ui.view.databinding.utils.ResourceManager; + +public class DataBindingDnDManager { + /** + * Adds a drag listener to the data source tree. + * + * @param tree + */ + public static void addDragListenerToDataSourceTree(final Tree tree) { + + Transfer[] transferTypes = new Transfer[] { TreeItemTransfer.getInstance() }; + int dndOperations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK; + + final DragSource dragSource = new DragSource(tree, dndOperations); + dragSource.setTransfer(transferTypes); + final TreeItem[] dragSourceItem = new TreeItem[1]; + dragSource.addDragListener(new DragSourceListener() { + + @Override + public void dragStart(DragSourceEvent dragSourceEvent) { + TreeItem[] selectedTreeItems = tree.getSelection(); + if (selectedTreeItems.length == 1) {// && + // selection[0].getItemCount() + // == + // 0) { + TreeItem dataSource = getRootItemFromTree(selectedTreeItems[0]); + + if (dataSource == null) + return; + + if (dataSource.equals(selectedTreeItems[0])) { + dragSourceEvent.doit = true; + dragSourceItem[0] = selectedTreeItems[0]; // TODO + // multiselect + } else { + dragSourceEvent.doit = false; + } + } else { + dragSourceEvent.doit = false; + } + } + + @Override + public void dragSetData(DragSourceEvent dragSourceEvent) { + // event.data = dragSourceItem[0].getText(); + dragSourceEvent.data = dragSourceItem[0]; + } + + @Override + public void dragFinished(DragSourceEvent dragSourceEvent) { + if ((dragSourceEvent.detail == DND.DROP_MOVE) && (dragSourceEvent.doit)) { + dragSourceItem[0].dispose(); + } + dragSourceItem[0] = null; + } + }); + } + + /** + * Adds a drag and drop listener to the view model tree. + * + * @param tree + * @param dataBindingView + * @param dataBindingPage + */ + public static void addDragAndDropListenerToDataModelTree(final Tree tree, final DataBindingView dataBindingView, + final DataBindingPage dataBindingPage) { + + Transfer[] transferTypes = new Transfer[] { TemplateTransfer.getInstance() }; + int dndOperations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK; + + final DragSource dragSource = new DragSource(tree, dndOperations); + dragSource.setTransfer(transferTypes); + final TreeItem[] dragSourceItem = new TreeItem[1]; + + dragSource.setDragSourceEffect(new DragSourceEffect(tree) { + @Override + public void dragStart(DragSourceEvent dragSourceEvent) { + dragSourceEvent.image = null; + } + }); + + dragSource.addDragListener(new DragSourceListener() { + + @Override + public void dragStart(DragSourceEvent dragSourceEvent) { + TreeItem[] selectedTreeItems = tree.getSelection(); + if (selectedTreeItems.length == 1 && selectedTreeItems[0].getParentItem() != null) { + dragSourceEvent.doit = true; + dragSourceItem[0] = selectedTreeItems[0]; // TODO multiselect + TreeItemData treeItemData = (TreeItemData) selectedTreeItems[0].getData("TREEITEMDATA"); + BindingObject bindingObject = (BindingObject) selectedTreeItems[0].getData("BINDING_OBJECT"); + + if (bindingObject != null && treeItemData != null && treeItemData.getObjectType() != null + && (treeItemData.getObjectType().equals("Object") || + (bindingObject.getChildren().size() > 0 && bindingObject.getChildren().get(0).getPropertyValue("type").equals("IndexObject")))) { + dragSourceEvent.doit = false; + return; + } + if(treeItemData == null){ + return; + } + String sourceType = null; + BindingData source = dataBindingPage.getDataSource(treeItemData.getModel().getSourceName()); + if (source != null) { + sourceType = source.getPropertyValue(BuilderConstants.ATTRIBUTE_SOURCE_TYPE); + } + String dataType = treeItemData.getObjectType(); + String allowedBindingType = treeItemData.getAllowedBindingType(); + String viewModelInfo = (String) selectedTreeItems[0].getData("path"); + int index = viewModelInfo.indexOf(BuilderConstants.SLASH); + DataBindingTemplate dataBindingTemplate = new DataBindingTemplate(viewModelInfo.substring(0, index), viewModelInfo.substring(index+1), + dataType, allowedBindingType, sourceType); + TemplateTransfer.getInstance().setTemplate(dataBindingTemplate); + } else { + dragSourceEvent.doit = false; + } + + } + + @Override + public void dragSetData(DragSourceEvent dragSourceEvent) { + // event.data = dragSourceItem[0]; + dragSourceEvent.data = TemplateTransfer.getInstance().getTemplate(); + } + + @Override + public void dragFinished(DragSourceEvent dragSourceEvent) { + // TODO only copy? +// if ((dragSourceEvent.detail == DND.DROP_MOVE) && (dragSourceEvent.doit)) { +// dragSourceItem[0].dispose(); +// } + + if (dataBindingPage != null) { + dataBindingPage.refreshBindingInfos(); + } + + dragSourceItem[0] = null; + TemplateTransfer.getInstance().setTemplate(null); + } + }); + + DropTarget dropTarget = new DropTarget(tree, dndOperations); + transferTypes = new Transfer[] { DataModelTreeItemTransfer.getInstance(), TreeItemTransfer + .getInstance(), /* + * TemplateTransfer.getInstance() + */ }; + dropTarget.setTransfer(transferTypes); + dropTarget.addDropListener(new DropTargetAdapter() { + public void dragOver(DropTargetEvent dropTargetEvent) { + dropTargetEvent.feedback = DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL; + if (dropTargetEvent.item != null) { + TreeItem dropTargetItem = (TreeItem) dropTargetEvent.item; + TreeItem viewModel = getRootItemFromTree(dropTargetItem); + + if (viewModel == null) + return; + + if (TreeItemTransfer.getInstance().isSupportedType(dropTargetEvent.currentDataType)) { + if (viewModel.equals(dropTargetItem)) { + dropTargetEvent.feedback |= DND.FEEDBACK_SELECT; + } + } else if (DataModelTreeItemTransfer.getInstance().isSupportedType(dropTargetEvent.currentDataType)) { + TreeItemData treeItemData = (TreeItemData) viewModel.getData("TREEITEMDATA"); + + if ((treeItemData == null) || (treeItemData.getModel() == null) + || (treeItemData.getModel().getModelType()) == null) { + return; + } else if (treeItemData.getModel().getModelType() + .equals(BuilderConstants.DATABINDING_TYPE_STATIC)) { + Point dropTargetPoint = tree.getDisplay().map(null, tree, dropTargetEvent.x, dropTargetEvent.y); + Rectangle itemRectBounds = dropTargetItem.getBounds(); + if (dropTargetPoint.y < itemRectBounds.y + itemRectBounds.height / 3) { + dropTargetEvent.feedback |= DND.FEEDBACK_INSERT_BEFORE; + } else if (dropTargetPoint.y > itemRectBounds.y + 2 * itemRectBounds.height / 3) { + dropTargetEvent.feedback |= DND.FEEDBACK_INSERT_AFTER; + } else { + dropTargetEvent.feedback |= DND.FEEDBACK_SELECT; + } + } + } + } + } + + public void drop(DropTargetEvent dropTargetEvent) { + + if (dropTargetEvent.data == null) { + dropTargetEvent.detail = DND.DROP_NONE; + return; + } + + TreeItem sourceTreeItem = (TreeItem) dropTargetEvent.data; + + if (sourceTreeItem.equals(dropTargetEvent.item)) { + dropTargetEvent.detail = DND.DROP_NONE; + return; + } + + if (TreeItemTransfer.getInstance().isSupportedType(dropTargetEvent.currentDataType)) { + if (dropTargetEvent.item == null) { + BindingData dataSource = dataBindingPage.getDataSource(sourceTreeItem.getText()); + dataBindingPage.setDataSourceToDataModel(dataSource, null); + + dropTargetEvent.detail = DND.DROP_COPY; + } else if (dropTargetEvent.item.equals(getRootItemFromTree((TreeItem) dropTargetEvent.item))) { + TreeItem item = (TreeItem) dropTargetEvent.item; + TreeItem parent = item.getParentItem(); + if (parent != null) { + dropTargetEvent.detail = DND.DROP_NONE; + } else { + BindingData viewModel = dataBindingPage.getDataModelByItemName(item.getText()); + BindingData dataSource = dataBindingPage.getDataSource(sourceTreeItem.getText()); + dataBindingPage.setDataSourceToDataModel(dataSource, viewModel); + + dropTargetEvent.detail = DND.DROP_COPY; + } + } else { + dropTargetEvent.detail = DND.DROP_NONE; + } + } else if (DataModelTreeItemTransfer.getInstance().isSupportedType(dropTargetEvent.currentDataType)) { + BindingData dataModel = null; + if (dropTargetEvent.item != null) { + TreeItem treeItem = getRootItemFromTree((TreeItem) dropTargetEvent.item); + if (treeItem != null) { + TreeItemData treeItemData = (TreeItemData) treeItem.getData("TREEITEMDATA"); + if (treeItemData != null) + dataModel = treeItemData.getModel(); + } + } + if ((dataModel != null) + && (dataModel.getModelType().equals(BuilderConstants.DATABINDING_TYPE_STATIC))) { + TreeItem eventTreeItem = (TreeItem) dropTargetEvent.item; + Point dropPoint = tree.getDisplay().map(null, tree, dropTargetEvent.x, dropTargetEvent.y); + Rectangle treeItemBounds = eventTreeItem.getBounds(); + TreeItem parent = eventTreeItem.getParentItem(); + if (parent != null) { + TreeItem[] parentItems = parent.getItems(); + int itemIndex = 0; + for (int i = 0; i < parentItems.length; i++) { + if (parentItems[i] == eventTreeItem) { + itemIndex = i; + break; + } + } + if (dropPoint.y < treeItemBounds.y + treeItemBounds.height / 3) { + TreeItem newTreeItem = new TreeItem(parent, SWT.NONE, itemIndex); + setValuesOfItem(newTreeItem, sourceTreeItem); + } else if (dropPoint.y > treeItemBounds.y + 2 * treeItemBounds.height / 3) { + TreeItem newTreeItem = new TreeItem(parent, SWT.NONE, itemIndex + 1); + setValuesOfItem(newTreeItem, sourceTreeItem); + } else { + TreeItem newTreeItem = new TreeItem(eventTreeItem, SWT.NONE); + setValuesOfItem(newTreeItem, sourceTreeItem); + } + + } else { + TreeItem[] items = tree.getItems(); + int itemIndex = 0; + for (int i = 0; i < items.length; i++) { + if (items[i] == eventTreeItem) { + itemIndex = i; + break; + } + } + if (dropPoint.y < treeItemBounds.y + treeItemBounds.height / 3) { + TreeItem newTreeItem = new TreeItem(tree, SWT.NONE, itemIndex); + setValuesOfItem(newTreeItem, sourceTreeItem); + } else if (dropPoint.y > treeItemBounds.y + 2 * treeItemBounds.height / 3) { + TreeItem newTreeItem = new TreeItem(tree, SWT.NONE, itemIndex + 1); + setValuesOfItem(newTreeItem, sourceTreeItem); + } else { + TreeItem newTreeItem = new TreeItem(eventTreeItem, SWT.NONE); + setValuesOfItem(newTreeItem, sourceTreeItem); + } + } + } else { + dropTargetEvent.detail = DND.DROP_NONE; + } + } else { + dropTargetEvent.detail = DND.DROP_NONE; + } + } + }); + } + + /** + * Adds a drag and drop listener to the SetSourceDialog tree. + * + * @param tree + */ + public static void addDragAndDropListenerToTree(final Tree tree) { + Transfer[] transferTypes = new Transfer[] { TreeItemTransfer.getInstance() }; + int dndOperations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK; + + final DragSource dragSource = new DragSource(tree, dndOperations); + dragSource.setTransfer(transferTypes); + final TreeItem[] dragSourceItem = new TreeItem[1]; + dragSource.addDragListener(new DragSourceListener() { + + @Override + public void dragStart(DragSourceEvent dragSourceEvent) { + TreeItem[] treeSelection = tree.getSelection(); + if (treeSelection.length == 1) { // > 0 && + // selection[0].getItemCount() + // == 0) { + dragSourceEvent.doit = true; + dragSourceItem[0] = treeSelection[0]; + } else { + dragSourceEvent.doit = false; + } + + } + + @Override + public void dragSetData(DragSourceEvent dragSourceEvent) { + dragSourceEvent.data = dragSourceItem[0]; + } + + @Override + public void dragFinished(DragSourceEvent dragSourceEvent) { + if ((dragSourceEvent.detail == DND.DROP_MOVE) && (dragSourceEvent.doit)) { + dragSourceItem[0].dispose(); + } + dragSourceItem[0] = null; + } + }); + + DropTarget dropTarget = new DropTarget(tree, dndOperations); + dropTarget.setTransfer(transferTypes); + dropTarget.addDropListener(new DropTargetAdapter() { + public void dragOver(DropTargetEvent dropTargetEvent) { + dropTargetEvent.feedback = DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL; + if (dropTargetEvent.item != null) { + TreeItem treeItem = (TreeItem) dropTargetEvent.item; + Point dropPoint = tree.getDisplay().map(null, tree, dropTargetEvent.x, dropTargetEvent.y); + Rectangle bounds = treeItem.getBounds(); + if (dropPoint.y < bounds.y + bounds.height / 3) { + dropTargetEvent.feedback |= DND.FEEDBACK_INSERT_BEFORE; + } else if (dropPoint.y > bounds.y + 2 * bounds.height / 3) { + dropTargetEvent.feedback |= DND.FEEDBACK_INSERT_AFTER; + } else { + dropTargetEvent.feedback |= DND.FEEDBACK_SELECT; + } + } + } + + public void drop(DropTargetEvent dropEvent) { + if (dropEvent.data == null) { + dropEvent.detail = DND.DROP_NONE; + return; + } + + TreeItem sourceItem = (TreeItem) dropEvent.data; + + if (sourceItem.equals(dropEvent.item)) {// || + // (sourceItem.getData("VIEWMODELNODE") + // != null) + // ) { + dropEvent.detail = DND.DROP_NONE; + return; + } + + if (dropEvent.item == null) { + TreeItem newTreeItem = new TreeItem(tree, SWT.NONE); + setValuesOfItem(newTreeItem, sourceItem); + } else { + TreeItem treeItem = (TreeItem) dropEvent.item; + Point dropPoint = tree.getDisplay().map(null, tree, dropEvent.x, dropEvent.y); + Rectangle bounds = treeItem.getBounds(); + TreeItem parentTreeItem = treeItem.getParentItem(); + if (parentTreeItem != null) { + TreeItem[] items = parentTreeItem.getItems(); + int index = 0; + for (int i = 0; i < items.length; i++) { + if (items[i] == treeItem) { + index = i; + break; + } + } + if (dropPoint.y < bounds.y + bounds.height / 3) { + TreeItem newTreeItem = new TreeItem(parentTreeItem, SWT.NONE, index); + setValuesOfItem(newTreeItem, sourceItem); + } else if (dropPoint.y > bounds.y + 2 * bounds.height / 3) { + TreeItem newTreeItem = new TreeItem(parentTreeItem, SWT.NONE, index + 1); + setValuesOfItem(newTreeItem, sourceItem); + } else { + TreeItem newTreeItem = new TreeItem(treeItem, SWT.NONE); + setValuesOfItem(newTreeItem, sourceItem); + } + + } else { + TreeItem[] items = tree.getItems(); + int treeItemIndex = 0; + for (int i = 0; i < items.length; i++) { + if (items[i] == treeItem) { + treeItemIndex = i; + break; + } + } + if (dropPoint.y < bounds.y + bounds.height / 3) { + TreeItem newTreeItem = new TreeItem(tree, SWT.NONE, treeItemIndex); + setValuesOfItem(newTreeItem, sourceItem); + } else if (dropPoint.y > bounds.y + 2 * bounds.height / 3) { + TreeItem newTreeItem = new TreeItem(tree, SWT.NONE, treeItemIndex + 1); + setValuesOfItem(newTreeItem, sourceItem); + } else { + TreeItem newTreeItem = new TreeItem(treeItem, SWT.NONE); + setValuesOfItem(newTreeItem, sourceItem); + } + } + + } + } + }); + + } + + private static TreeItem getRootItemFromTree(TreeItem treeItem) { + + if (treeItem == null) + return null; + + while (true) { + if (treeItem == null || treeItem.getParentItem() == null) + break; + + treeItem = treeItem.getParentItem(); + } + + return treeItem; + } + + private static void setValuesOfItem(TreeItem newTreeItem, TreeItem sourceTreeItem) { + TreeItemData treeItemData = new TreeItemData(); + TreeItemData sourceTreeItemData = (TreeItemData) sourceTreeItem.getData("TREEITEMDATA"); + if (sourceTreeItemData == null) { + return; + } + String text = sourceTreeItem.getText(); + + treeItemData.setObjectValue(sourceTreeItemData.getObjectValue()); + treeItemData.setObjectType(sourceTreeItemData.getObjectType()); + + newTreeItem.setText(text); + + newTreeItem.setData("TREEITEMDATA", treeItemData); + + if ((treeItemData.getObjectType() != null) && (treeItemData.getObjectType().equals("Array"))) { + newTreeItem.setImage( + ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_ARRAY_ICON)); + } + + setChildItems(newTreeItem, sourceTreeItem.getItems()); + } + + /** + * Creates a new TreeItem and child items. + * + * @param parentTreeItem + * @param treeItems + */ + public static void setChildItems(TreeItem parentTreeItem, TreeItem[] treeItems) { + + if (treeItems.length != 0) { + for (TreeItem treeItem : treeItems) { + TreeItem newTreeItem = new TreeItem(parentTreeItem, SWT.NONE); + TreeItemData treeItemData = new TreeItemData(); + TreeItemData sourceTreeItemData = (TreeItemData) treeItem.getData("TREEITEMDATA"); + + if ((sourceTreeItemData != null) && (sourceTreeItemData.getObjectValue() != null)) { + newTreeItem.setText(new String[] { treeItem.getText(), sourceTreeItemData.getObjectValue() }); + } else { + newTreeItem.setText(treeItem.getText()); + } + + if (sourceTreeItemData == null) { + return; + } + + treeItemData.setObjectValue(sourceTreeItemData.getObjectValue()); + + if ((sourceTreeItemData.getObjectType() != null) + && (sourceTreeItemData.getObjectType().equals("Array"))) { + treeItemData.setObjectType(sourceTreeItemData.getObjectType()); + newTreeItem.setImage(ResourceManager.getImage(BuilderConstants.ICON_DIR, + BuilderConstants.DATABINDING_ARRAY_ICON)); + } else if ((sourceTreeItemData.getObjectType() != null) + && (sourceTreeItemData.getObjectType().equals("Object"))) { + treeItemData.setObjectType(sourceTreeItemData.getObjectType()); + } + + newTreeItem.setData("TREEITEMDATA", treeItemData); + + TreeItem[] treeSubItems = treeItem.getItems(); + if (treeSubItems.length != 0) { + setChildItems(newTreeItem, treeSubItems); + } + + } + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/DataBindingManager.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/DataBindingManager.java new file mode 100644 index 0000000..56cbaa5 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/DataBindingManager.java @@ -0,0 +1,260 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.List; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.part.FileEditorInput; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.part.DataBindingPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.DBPartUnmarshaller; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.efluibuilder.ui.editor.designeditor.DesignEditor; +import org.tizen.efluibuilder.ui.editor.texteditor.DataBindingModelListener; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingData; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingDataSet; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingObject; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + +public class DataBindingManager { + private CombineEditorPart combineEditorPart = null; + private Document dataBindingModel = null; + private String layoutMetaPath = ""; + private BindingDataSet bindingDataSet = null; + + // TODO: Change it to DesignEditor when we need to use DesignEditor specific + // functionalities. Use GraphicalEditor as DesignEditor is not exported by + // contributing package + private DesignEditor designEditor = null; + private DesignViewer designViewer = null; + + public void initializeDataBindingModelListener(Part dataBindingPart) { + DataBindingModelListener modelListener = new DataBindingModelListener(); + modelListener.initContents(dataBindingPart, dataBindingModel); + } + + public void createDataBindingModel(Part dataBindingPart, IEditorInput input) { + try { + String inputPath = ((FileEditorInput) input).getPath().toOSString(); + String inputName = ((FileEditorInput) input).getName(); + layoutMetaPath = inputPath.replace(inputName, BuilderConstants.DATABINDING_LAYOUT_META_XML); + + File fileToOpen = new File(layoutMetaPath); + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + if (fileToOpen.createNewFile()) { + Document doc = dBuilder.newDocument(); + Element rootElement = doc.createElement(BuilderConstants.DATABINDING_ROOT_ELEMENT); + doc.appendChild(rootElement); + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + Transformer transformer = transformerFactory.newTransformer(); + DOMSource source = new DOMSource(doc); + StreamResult result = new StreamResult(fileToOpen); + transformer.transform(source, result); + dataBindingModel = doc; + } else { + dataBindingModel = dBuilder.parse(fileToOpen); + } + if (dataBindingModel != null) { + Element element = dataBindingModel.getDocumentElement(); + if (element != null) { + DBPartUnmarshaller unmarshaller = new DBPartUnmarshaller(); + unmarshaller.unmarshall(dataBindingPart, dataBindingModel, true); + ((DataBindingPart) dataBindingPart).updateID(); + } + } + bindingDataSet = new BindingDataSet(dataBindingPart); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (SAXException e) { + e.printStackTrace(); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (TransformerConfigurationException e) { + e.printStackTrace(); + } catch (TransformerException e) { + e.printStackTrace(); + } + } + + public CombineEditorPart getCombineEditorPart() { + if (PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null && PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() != null + && PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor() != null) { + IEditorPart activeEditorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); + if (activeEditorPart instanceof CombineEditorPart) { + combineEditorPart = (CombineEditorPart) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); + } + } + return combineEditorPart; + } + + public DesignEditor getDesignEditor() { + if (getCombineEditorPart() != null) { + designEditor = getCombineEditorPart().getDesignEditor(); + } + return designEditor; + } + + public BindingDataSet getBindingDataSet() { + return bindingDataSet; + } + + public DesignViewer getDesignViewer() { + if (getDesignEditor() != null) { + designViewer = getDesignEditor().getViewer(); + } + return designViewer; + } + + public List getDataSources() { + return bindingDataSet.getDataSources(); + } + + public BindingData getDataSource(String name) { + return bindingDataSet.getDataSource(name); + } + + public List getDataModels() { + return bindingDataSet.getDataModels(); + } + + public Part getNextSiblingToAddDataSource() { + return bindingDataSet.getNextSiblingToAddDataSource(); + } + + public void addDataSource(BindingData bindingData, Part nextSibling) { + bindingDataSet.addDataSource(bindingData, nextSibling); + } + + public void renameDataSource(BindingData bindingData, String newName) { + bindingDataSet.renameDataSource(bindingData, newName); + } + + public void removeDataSource(BindingData bindingData) { + bindingDataSet.removeDataSource(bindingData); + } + + public BindingData getDataModelByItemName(String name) { + return bindingDataSet.getDataModelByItemName(name); + } + + public BindingData getDataModelByModelName(String name) { + return bindingDataSet.getDataModelByModelName(name); + } + + public BindingObject getDataModelObject(BindingData bindingData, List itemPath) { + return bindingDataSet.getDataModelObject(bindingData, itemPath); + } + + public List getDataModelObjects(BindingData bindingData, List itemPath) { + return bindingDataSet.getBindingObjectsList(bindingData, itemPath); + } + + public void addDataModel(BindingData bindingData, Part nextSibling) { + bindingDataSet.addDataModel(bindingData, nextSibling); + } + + public void addDataModelItem(BindingData bindingData, List itemPath, String childName, String value) { + bindingDataSet.addDataModelItem(bindingData, itemPath, childName, value); + } + + public void addDataModelItems(BindingData bindingData, List nextSiblings, List itemPath, List dataModelObject, String value) { + bindingDataSet.addDataModelItems(bindingData, nextSiblings, itemPath, dataModelObject, value); + } + + public void removeDataModelItems(BindingData bindingData, List itemPath, String childName, String value) { + bindingDataSet.removeDataModelItems(bindingData, itemPath, childName, value); + } + + public void setDataModel(BindingData dataModel, BindingData newDataModel) { + bindingDataSet.setDataModel(dataModel, newDataModel); + } + + public void unlinkDataModel(BindingData dataModel, BindingData newDataModel) { + bindingDataSet.unlinkDataModel(dataModel, newDataModel); + } + + public void renameDataModel(BindingData bindingData, String newName) { + bindingDataSet.renameDataModel(bindingData, newName); + } + + public void renameDataModelItems(BindingData bindingData, String newName, List itemPath) { + bindingDataSet.renameDataModelItems(bindingData, newName, itemPath); + } + + public void removeDataModel(BindingData bindingData) { + bindingDataSet.removeDataModel(bindingData); + } + + public void doSave(SubMonitor newChild) { + try { + // Make a transformer factory to create the Transformer + TransformerFactory tFactory = TransformerFactory.newInstance(); + + // Make the Transformer + Transformer transformer; + + transformer = tFactory.newTransformer(); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); + // Mark the document as a DOM (XML) source + DOMSource source = new DOMSource(dataBindingModel); + + // Say where we want the XML to go + StreamResult result = new StreamResult(layoutMetaPath); + + // Write the XML to file + transformer.transform(source, result); + } catch (TransformerConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (TransformerException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/DataBindingPage.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/DataBindingPage.java new file mode 100644 index 0000000..08c2a05 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/DataBindingPage.java @@ -0,0 +1,1446 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + + +package org.tizen.efluibuilder.ui.view.databinding; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.gef.commands.CompoundCommand; +import org.eclipse.gef.ui.actions.ActionRegistry; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.custom.TreeEditor; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.actions.ActionFactory; +import org.eclipse.ui.part.Page; +import org.tizen.efluibuilder.gef.editparts.DesignEditPart; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.command.SetPropertyPartCommand; +import org.tizen.efluibuilder.model.part.DataBindingPart; +import org.tizen.efluibuilder.model.part.IPartChangedListener; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartMutation; +import org.tizen.efluibuilder.model.part.PartObserver; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.efluibuilder.ui.view.databinding.actions.AddDataSourceAction; +import org.tizen.efluibuilder.ui.view.databinding.actions.AddModelDropDownAction; +import org.tizen.efluibuilder.ui.view.databinding.actions.CollapseAllAction; +import org.tizen.efluibuilder.ui.view.databinding.actions.EditDataSourceAction; +import org.tizen.efluibuilder.ui.view.databinding.actions.RemoveBindingInfoAction; +import org.tizen.efluibuilder.ui.view.databinding.actions.RemoveDataModelAction; +import org.tizen.efluibuilder.ui.view.databinding.actions.RemoveDataSourceAction; +import org.tizen.efluibuilder.ui.view.databinding.actions.RenameDataModelAction; +import org.tizen.efluibuilder.ui.view.databinding.actions.RenameDataSourceAction; +import org.tizen.efluibuilder.ui.view.databinding.actions.SetModelTargetAction; +import org.tizen.efluibuilder.ui.view.databinding.actions.ShowBindingInfoAction; +import org.tizen.efluibuilder.ui.view.databinding.dialog.SetSourcePage; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingData; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingDataSetEvent; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingDataSetEvent.BindingDataSetEventType; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingObject; +import org.tizen.efluibuilder.ui.view.databinding.model.IBindingDataSetListener; +import org.tizen.efluibuilder.ui.view.databinding.model.TreeItemData; +import org.tizen.efluibuilder.ui.view.databinding.model.command.ConfigureDataModelCommand; +import org.tizen.efluibuilder.ui.view.databinding.model.command.DataBindingCommandFactory; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; +import org.tizen.efluibuilder.ui.view.databinding.utils.DataBindingHelper; +import org.tizen.efluibuilder.ui.view.databinding.utils.ResourceManager; + + +public class DataBindingPage extends Page implements IBindingDataSetListener, ISelectionChangedListener, IPartChangedListener { + + private Composite composite; + + private Tree dataSourceTree; + private Tree dataModelTree; + private TreeEditor dataSourceTreeEditor; + private TreeEditor dataModelTreeEditor; + private TableViewer bindingInfoTableViewer; + + private MenuManager dataSourceMenuManager; + private MenuManager dataModelMenuManager; + private MenuManager bindingInfoMenuManager; + + private final DataBindingView dataBindingView; + private ToolBarManager dataSourceToolBarManager; + private ToolBarManager bindingInfoToolBarManager; + private AddDataSourceAction addDataSourceAction; + private EditDataSourceAction editDataSourceAction; + private RemoveDataSourceAction removeDataSourceAction; + private RenameDataSourceAction renameDataSourceAction; + // private AddViewModelItemAction addDataModelAction; + private AddModelDropDownAction addDataModelDorpDownAction; + private RenameDataModelAction renameDataModelAction; + private RemoveDataModelAction removeDataModelAction; + private SetModelTargetAction setModelTargetAction; + private RemoveBindingInfoAction removeBindingInfoAction; + private ShowBindingInfoAction showBindingInfoAction; + private ActionRegistry registry; + private final CombineEditorPart combineEditorPart; + private CollapseAllAction collapseAllModelAction; + private CollapseAllAction collapseAllSourceAction; + + private ToolBarManager viewModelToolBarManager; + + private PartObserver docPartObserver = null; + private PartObserver dataBindingPartObserver = null; + private Part currentViewPart = null; + + public DataBindingPage(DataBindingView dataBindingView, CombineEditorPart editorPart) { + this.dataBindingView = dataBindingView; + this.combineEditorPart = editorPart; + this.setInput(); + } + + public void renameDataModel(TreeItem treeItem) { + renameTreeItem(dataModelTree, dataModelTreeEditor, treeItem); + } + + private boolean checkModelName(String newName) { + List viewModels = combineEditorPart.getDataBindManager().getDataModels(); + for (BindingData viewModel : viewModels) { + if (viewModel.getModelName().equals(newName)) { + return false; + } + } + return true; + } + + public BindingData getDataSource(String name) { + return combineEditorPart.getDataBindManager().getDataSource(name); + } + + public BindingData getDataModelByItemName(String name) { + return combineEditorPart.getDataBindManager().getDataModelByItemName(name); + } + + public Table getInfoTable() { + return bindingInfoTableViewer.getTable(); + } + + private boolean checkModelItemName(BindingData bindingData, List itemPath, String newName) { + if ((itemPath == null) || (itemPath.size() < 2)) { + return false; + } + + List parentItemPath = new ArrayList(); + List childObjects = null; + + for (int i = 1; i < itemPath.size(); i++) { + parentItemPath.add(itemPath.get(i)); + } + + if (parentItemPath.size() == 1) { + childObjects = bindingData.getBindingObjects(); + } else { + BindingObject bindingObject = combineEditorPart.getDataBindManager().getDataModelObject(bindingData, parentItemPath); + if (bindingObject == null) { + return false; + } + childObjects = bindingObject.getBindingObjects(); + } + + for (BindingObject childObject : childObjects) { + if (childObject.getName().equals(newName)) { + return false; + } + } + return true; + } + + public void renameDataModel(TreeItem treeItem, String newName) { + if (treeItem.getParentItem() == null) { + if (!checkModelName(newName)) { + return; + } + BindingData dataModel = combineEditorPart.getDataBindManager().getDataModelByItemName(treeItem.getText()); + Command renameDataModelCommand = DataBindingCommandFactory.createRenameDataModelCommand(combineEditorPart, dataModel, newName); + getCommandStackFromDesignEditor().execute(renameDataModelCommand); + } else { + List itemPath = makeItemPath(treeItem); + BindingData bindingData = combineEditorPart.getDataBindManager().getDataModelByItemName(itemPath.get(itemPath.size() - 1)); + if (!checkModelItemName(bindingData, itemPath, newName)) { + return; + } + Command command = new ConfigureDataModelCommand(BindingDataSetEventType.DATAMODEL_ITEM_RENAMED, combineEditorPart.getDataBindManager(), bindingData, + itemPath, treeItem.getText(), newName, + 0); + getCommandStackFromDesignEditor().execute(command); + } + } + + private void renameTreeItem(final Tree tree, TreeEditor treeEditor, TreeItem treeItem) { + // Determine the item to edit + final TreeItem item; + if (treeItem == null) { + item = tree.getSelection()[0]; + } else { + item = treeItem; + } + if (treeEditor == null) { + return; + } + + Control oldEditor = treeEditor.getEditor(); + if (oldEditor != null) { + oldEditor.dispose(); + } + + // Create a text field to do the editing + final Text text = new Text(tree, SWT.NONE); + + BindingData data = combineEditorPart.getDataBindManager().getDataModelByItemName(item.getText()); + if (data != null) { + text.setText(data.getModelName()); + } else { + data = combineEditorPart.getDataBindManager().getDataSource(item.getText()); + if (data != null) { + text.setText(data.getSourceName()); + } else { + text.setText(item.getText()); + } + } + + text.selectAll(); + text.setFocus(); + + // If they hit Enter, set the text into the tree and end the + // editing + // session. If they hit Escape, ignore the text and end the + // editing + // session + text.addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent event) { + switch (event.keyCode) { + case SWT.CR: + // Enter hit--set the text into the tree and + // drop through + if (tree.equals(getDataSourceTree())) { + renameDataSource(item, text.getText()); + } else { + renameDataModel(item, text.getText()); + } + text.dispose(); + break; + case SWT.KEYPAD_CR: + if (tree.equals(getDataSourceTree())) { + renameDataSource(item, text.getText()); + } else { + renameDataModel(item, text.getText()); + } + text.dispose(); + break; + case SWT.ESC: + // End editing session + text.dispose(); + break; + } + } + }); + text.addFocusListener(new FocusListener() { + + @Override + public void focusLost(FocusEvent arg0) { + // TODO Auto-generated method stub + if (tree.equals(getDataSourceTree())) { + renameDataSource(item, text.getText()); + } else { + renameDataModel(item, text.getText()); + } + text.dispose(); + } + + @Override + public void focusGained(FocusEvent arg0) { + // TODO Auto-generated method stub + + } + }); + // Set the text field into the editor + treeEditor.setEditor(text, item); + } + + private boolean isSourceNameValid(String newName) { + BindingData dataSource = combineEditorPart.getDataBindManager().getDataSource(newName); + if (dataSource != null) { + return false; + } + return true; + } + + public void editDataSource(BindingData dataSource) { + Command editDataSourceCommand = null; + DataBindingPart dataBindingPart = (DataBindingPart) combineEditorPart.getDataBindingPart(); + for (Part bindingData : dataBindingPart.getChildren()) { + if (bindingData.getType() == PartType.DATASOURCE && ((BindingData) bindingData).getSourceName().equals(dataSource.getSourceName())) { + editDataSourceCommand = DataBindingCommandFactory.createEditDataSourceCommand(combineEditorPart, dataSource); + break; + } + } + getCommandStackFromDesignEditor().execute(editDataSourceCommand); + } + + public boolean canRemoveDataSource() { + TreeItem[] treeItems = dataSourceTree.getSelection(); + if ((treeItems == null) || (treeItems.length < 1)) { + return false; + } else { + if (treeItems[0].getParentItem() == null) + return true; + } + return false; + } + + private void createDataModelParentPanel(SashForm parentSashForm) { + SashForm sashForm = new SashForm(parentSashForm, SWT.VERTICAL); + + createDataSourcePanel(sashForm); + createDataModelPanel(sashForm); + } + + @Override + public void createControl(Composite parent) { + composite = new Composite(parent, SWT.NONE); + composite.setLayout(new FillLayout()); + + registry = combineEditorPart.getDesignEditor().getActions(); + + // used to initialize the toolbar buttons + createActions(); + + SashForm sashForm = new SashForm(composite, SWT.VERTICAL); + createDataModelParentPanel(sashForm); + + createBindingInfoPanel(sashForm); + sashForm.setLayoutData(SWT.RESIZE); + refresh(); + } + + public void removeBindingInfo() { + TableItem[] tableItems = bindingInfoTableViewer.getTable().getSelection(); + CompoundCommand cc = new CompoundCommand("removeBindingInfo"); + for (TableItem tableItem : tableItems) { + Part part = (Part) tableItem.getData("PART"); + if (part != null) { + Command command = new SetPropertyPartCommand(part, BuilderConstants.ATTRIBUTE_DATA_BIND, ""); + cc.add(command); + } + } + getCommandStackFromDesignEditor().execute(cc); + refresh(); + } + + public boolean canRemoveBindingInfo() { + TableItem[] tableItems = bindingInfoTableViewer.getTable().getSelection(); + if ((tableItems == null) || (tableItems.length < 1)) { + return false; + } else { + return true; + } + } + + private void createActions() { + // Data Source + addDataSourceAction = new AddDataSourceAction("Add", "Add", dataBindingView); + removeDataSourceAction = new RemoveDataSourceAction("Remove@Del", "Remove", dataBindingView); + editDataSourceAction = new EditDataSourceAction("Edit@DClick", "Edit", dataBindingView, combineEditorPart.getProject()); + renameDataSourceAction = new RenameDataSourceAction("Rename@F2", "Rename", dataBindingView); + collapseAllSourceAction = new CollapseAllAction("Collapse All", "Collapse All"); + // Data Model + // addDataModelAction = new AddViewModelItemAction("ADD Item", "Add + // Item", dataBindingView); + addDataModelDorpDownAction = new AddModelDropDownAction("Add", "Add", dataBindingView, combineEditorPart.getDataBindManager()); + renameDataModelAction = new RenameDataModelAction("Rename@F2", "Rename", dataBindingView); + removeDataModelAction = new RemoveDataModelAction("Remove@Del", "Remove", dataBindingView); + setModelTargetAction = new SetModelTargetAction("Set Target", dataBindingView); + collapseAllModelAction = new CollapseAllAction("Collapse All", "Collapse All"); + + // Binding Info + removeBindingInfoAction = new RemoveBindingInfoAction("Remove@Del", "Remove", dataBindingView); + showBindingInfoAction = new ShowBindingInfoAction("Show", combineEditorPart.getDataBindManager()); + + // Add undo/redo handlers and attach it to designEditors action + // registers so that their command stack gets shared + // http://www.programcreek.com/java-api-examples/index.php?api=org.eclipse.gef.ui.actions.ActionRegistry + IActionBars actionBars = getSite().getActionBars(); + + String id = ActionFactory.UNDO.getId(); + + actionBars.setGlobalActionHandler(id, registry.getAction(id)); + + id = ActionFactory.REDO.getId(); + actionBars.setGlobalActionHandler(id, registry.getAction(id)); + + actionBars.updateActionBars(); + } + + private void createDataSourcePanel(SashForm parentSashForm) { + Composite dataSourcePanel = new Composite(parentSashForm, SWT.BORDER); + + FormLayout layout = new FormLayout(); + + dataSourcePanel.setLayout(layout); + + ToolBar toolBar = makeDataSourcePanelToolbar(dataSourcePanel); + FormData toolBarData = new FormData(); + toolBarData.top = new FormAttachment(0, 0); + toolBarData.right = new FormAttachment(100, 0); + toolBar.setLayoutData(toolBarData); + + dataSourceTree = new Tree(dataSourcePanel, SWT.NONE); + FormData treeData = new FormData(); + treeData.top = new FormAttachment(toolBar, 0); + treeData.bottom = new FormAttachment(100, 0); + treeData.left = new FormAttachment(0, 0); + treeData.right = new FormAttachment(100, 0); + dataSourceTree.setLayoutData(treeData); + collapseAllSourceAction.setTreeItem(dataSourceTree); + dataSourceTreeEditor = new TreeEditor(dataSourceTree); + dataSourceTreeEditor.horizontalAlignment = SWT.LEFT; + dataSourceTreeEditor.grabHorizontal = true; + + dataSourceTree.addMouseListener(new MouseAdapter() { + + @Override + public void mouseDoubleClick(MouseEvent e) { + Point point = new Point(e.x, e.y); + TreeItem treeItem = dataSourceTree.getItem(point); + if (treeItem == null) { + dataSourceTree.deselectAll(); + return; + } + + Rectangle rect = treeItem.getBounds(); + if (rect.contains(point)) { + // renameDataSource(treeItem); + while (treeItem != null && treeItem.getParentItem() != null) { + treeItem = treeItem.getParentItem(); + } + SetSourcePage dlg = new SetSourcePage(Display.getCurrent().getActiveShell(), treeItem, combineEditorPart.getProject()); + BindingData dataSource = dlg.open(); + if (dataSource != null) { + editDataSource(dataSource); + } + } + } + }); + + dataSourceTree.addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent event) { + // Make sure one and only one item is selected when F2 is + // pressed + if (event.keyCode == SWT.F2 && dataSourceTree.getSelectionCount() == 1) { + TreeItem treeItem = dataSourceTree.getSelection()[0]; + if (treeItem.getParentItem() == null) { + renameDataSource(null); + } + } else if (event.keyCode == SWT.DEL) { + removeDataSource(); + } + } + }); + + dataSourceTree.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + updateDataSourceMenus(); + } + }); + + DataBindingDnDManager.addDragListenerToDataSourceTree(dataSourceTree); + createDataSourceContextMenu(); + + } + + private ToolBar makeDataSourcePanelToolbar(Composite dataSourcePanel) { + ToolBar toolBar = new ToolBar(dataSourcePanel, SWT.FLAT); + dataSourceToolBarManager = new ToolBarManager(toolBar); + dataSourceToolBarManager.add(editDataSourceAction); + dataSourceToolBarManager.add(addDataSourceAction); + dataSourceToolBarManager.add(removeDataSourceAction); + dataSourceToolBarManager.add(collapseAllSourceAction); + dataSourceToolBarManager.update(true); + + createToolBarTitle(toolBar, "Data Source"); + + return toolBar; + } + + private void createToolBarTitle(ToolBar toolBar, String title) { + Label viewModelTitle = new Label(toolBar.getParent(), SWT.None); + viewModelTitle.setText(title); + FormData labelData = new FormData(); + labelData.top = new FormAttachment(0, 5); + viewModelTitle.setLayoutData(labelData); + } + + public void updateDataSourceMenus() { + if (renameDataSourceAction != null) + renameDataSourceAction.refresh(); + + if (removeDataSourceAction != null) + removeDataSourceAction.refresh(); + + if (editDataSourceAction != null) + editDataSourceAction.refresh(); + + if (dataSourceMenuManager != null) + dataSourceMenuManager.update(true); + + if (collapseAllSourceAction != null) + collapseAllSourceAction.refresh(); + } + + public void updateDataModelMenus() { + // if (addDataModelAction != null) + // addDataModelAction.refresh(); + if (removeDataModelAction != null) + removeDataModelAction.refresh(); + if (renameDataModelAction != null) + renameDataModelAction.refresh(); + if (viewModelToolBarManager != null) + viewModelToolBarManager.update(true); + if (dataModelMenuManager != null) + dataModelMenuManager.update(true); + if (setModelTargetAction != null) + setModelTargetAction.refresh(); + if (collapseAllModelAction != null) + collapseAllModelAction.refresh(); + } + + public void updateBindingInfoMenus() { + if (removeBindingInfoAction != null) { + removeBindingInfoAction.refresh(); + } + if (bindingInfoToolBarManager != null) { + bindingInfoToolBarManager.update(true); + } + if (bindingInfoMenuManager != null) { + bindingInfoMenuManager.update(true); + } + } + + private void createDataSourceContextMenu() { + dataSourceMenuManager = new MenuManager("#dataSourceMenu"); + dataSourceMenuManager.add(addDataSourceAction); + dataSourceMenuManager.add(editDataSourceAction); + dataSourceMenuManager.add(renameDataSourceAction); + dataSourceMenuManager.add(removeDataSourceAction); + dataSourceMenuManager.update(true); + + Menu menu = dataSourceMenuManager.createContextMenu(dataSourceTree); + dataSourceTree.setMenu(menu); + } + + private ToolBar makeDataModelToolbar(Composite panel) { + ToolBar toolBar = new ToolBar(panel, SWT.FLAT); + viewModelToolBarManager = new ToolBarManager(toolBar); + + // viewModelToolBarManager.add(addDataModelAction); + viewModelToolBarManager.add(addDataModelDorpDownAction); + viewModelToolBarManager.add(removeDataModelAction); + viewModelToolBarManager.add(setModelTargetAction); + viewModelToolBarManager.add(collapseAllModelAction); + viewModelToolBarManager.update(true); + + createToolBarTitle(toolBar, "Data Model"); + + return toolBar; + } + + public void createDataModelPanel(SashForm parentSashForm) { + Composite dataModelPanel = new Composite(parentSashForm, SWT.BORDER); + + FormLayout layout = new FormLayout(); + dataModelPanel.setLayout(layout); + ToolBar toolBar = makeDataModelToolbar(dataModelPanel); + FormData toolBarData = new FormData(); + toolBarData.top = new FormAttachment(0, 0); + toolBarData.right = new FormAttachment(100, 0); + toolBar.setLayoutData(toolBarData); + + dataModelTree = new Tree(dataModelPanel, SWT.NONE); + FormData treeData = new FormData(); + treeData.top = new FormAttachment(toolBar, 0); + treeData.bottom = new FormAttachment(100, 0); + treeData.left = new FormAttachment(0, 0); + treeData.right = new FormAttachment(100, 0); + dataModelTree.setLayoutData(treeData); + collapseAllModelAction.setTreeItem(dataModelTree); + dataModelTreeEditor = new TreeEditor(dataModelTree); + dataModelTreeEditor.horizontalAlignment = SWT.LEFT; + dataModelTreeEditor.grabHorizontal = true; + + dataModelTree.addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent event) { + // Make sure one and only one item is selected when F2 is + // pressed + if (event.keyCode == SWT.F2 && dataModelTree.getSelectionCount() == 1) { + TreeItem treeItem = dataModelTree.getSelection()[0]; + if (treeItem != null && treeItem.getParentItem() == null) { + TreeItemData treeItemData = (TreeItemData) treeItem.getData("TREEITEMDATA"); + if (!treeItemData.getBindedValue()) { + renameDataModel(null); + } + } + } else if (event.keyCode == SWT.DEL) { + removeDataModel(); + } + } + }); + + dataModelTree.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + updateDataModelMenus(); + setSelectionPath(dataModelTree); + } + }); + + DataBindingDnDManager.addDragAndDropListenerToDataModelTree(dataModelTree, dataBindingView, this); + createDataModelContextMenu(null); + } + + /** + * Returns TRUE if tree item name can be set. + * + * @param TreeItem + * + * @param itemName + * a tree item name + * @return true if tree item name can be set + */ + private boolean canSetTreeItemName(TreeItem treeItem, String itemName) { + TreeItem[] childItems = treeItem.getItems(); + for (TreeItem childItem : childItems) { + if (childItem.getText().equals(itemName)) { + return false; + } + } + return true; + } + + public void addDataModelItem() { + + TreeItem[] selectedItems = dataModelTree.getSelection(); + + if (selectedItems.length > 0) { + int idIndex = 0; + while (!canSetTreeItemName(selectedItems[0], BuilderConstants.DATABINDING_DATAMODEL_ITEM_NAME + idIndex)) { + idIndex++; + } + + List itemPath = makeItemPath(selectedItems[0]); + BindingData bindingData = combineEditorPart.getDataBindManager().getDataModelByItemName(itemPath.get(itemPath.size() - 1)); + + Command command = + new ConfigureDataModelCommand(BindingDataSetEventType.DATAMODEL_ITEM_ADDED, combineEditorPart.getDataBindManager(), bindingData, itemPath, + BuilderConstants.DATABINDING_DATAMODEL_ITEM_NAME + idIndex, "", 0); + getCommandStackFromDesignEditor().execute(command); + } + } + + /** + * Removes a tree item in the view model panel. + */ + public void removeDataModel() { + TreeItem[] treeItems = dataModelTree.getSelection(); + Command removeDataModelCommand = null; + for (TreeItem treeItem : treeItems) { + if (treeItem.getParentItem() == null) { + BindingData dataModel = combineEditorPart.getDataBindManager().getDataModelByItemName(treeItem.getText()); + removeDataModelCommand = DataBindingCommandFactory.createRemoveDataModelCommand(combineEditorPart, dataModel); + } else { + List itemPath = new ArrayList<>(); + String path = (String) treeItem.getData("path"); + path = path.replaceAll(BuilderConstants.FILTER_REGEX, BuilderConstants.EMPTY); + String[] split = path.split(BuilderConstants.SLASH_REGEX); + for (int i = split.length - 1; i >= 0; i--) { + itemPath.add(split[i]); + } + BindingData dataModel = combineEditorPart.getDataBindManager().getDataModelByModelName(itemPath.get(itemPath.size() - 1)); + removeDataModelCommand = DataBindingCommandFactory.createRemoveDataModelItemCommand(combineEditorPart, dataModel, itemPath, treeItem.getText()); + } + getCommandStackFromDesignEditor().execute(removeDataModelCommand); + } + } + + public void setModelTarget(Part part, BindingData dataModel, String itemPath, String widgetName) { + Command command = DataBindingCommandFactory.getAddBindingCommand(part, dataModel, itemPath, widgetName); + getCommandStackFromDesignEditor().execute(command); + } + + private List makeItemPath(TreeItem selectedItem) { + + TreeItem item = selectedItem; + + List itemPath = new ArrayList(); + + if (item == null) + return itemPath; + + itemPath.add(item.getText()); + + while ((item = item.getParentItem()) != null) { + itemPath.add(item.getText()); + } + + return itemPath; + } + + private void setSelectionPath(Tree tree) { + if ((tree.getSelection() == null) || (tree.getSelection().length == 0)) { + return; + } + + TreeItem treeItem = tree.getSelection()[0]; + + if (treeItem != null) { + List itemPath = makeItemPath(treeItem); + + while (true) { + if (treeItem == null || treeItem.getParentItem() == null) + break; + + treeItem = treeItem.getParentItem(); + } + + if (treeItem != null && treeItem.getData("TREEITEMDATA") != null) { + TreeItemData treeItemData = (TreeItemData) treeItem.getData("TREEITEMDATA"); + treeItemData.setSelectionPath(itemPath); + treeItem.setData("TREEITEMDATA", treeItemData); + } + + TreeItemData treeData = (TreeItemData) tree.getData("TREEITEMDATA"); + treeData.setSelectionPath(itemPath); + tree.setData("TREEITEMDATA", treeData); + } + + } + + public void createDataModelContextMenu(IMenuManager menuManager) { + if (menuManager == null) { + dataModelMenuManager = new MenuManager("#viewModelMenu"); + dataModelMenuManager.addMenuListener(new IMenuListener() { + @Override + public void menuAboutToShow(IMenuManager manager) { + createDataModelContextMenu(manager); + } + }); + } else { + dataModelMenuManager = (MenuManager) menuManager; + } + dataModelMenuManager.removeAll(); + + dataModelMenuManager.add(removeDataModelAction); + addDataModelDorpDownAction.dispose(); + addDataModelDorpDownAction = new AddModelDropDownAction("Add", "Add", dataBindingView, combineEditorPart.getDataBindManager()); + // dataModelMenuManager.add(addDataModelAction); + dataModelMenuManager.add(renameDataModelAction); + dataModelMenuManager.add(setModelTargetAction); + dataModelMenuManager.add(addDataModelDorpDownAction); + dataModelMenuManager.update(true); + + Menu menu = dataModelMenuManager.createContextMenu(dataModelTree); + dataModelTree.setMenu(menu); + } + + public boolean canRemoveDataModel() { + TreeItem[] treeItems = dataModelTree.getSelection(); + if ((treeItems == null) || (treeItems.length < 1)) { + return false; + } else { + return true; + } + } + + /** + * Adds a tree item in the view model panel. + */ + public void addDataModel() { + BindingData dataModel; + int idIndex = 0; + while (!canSetTreeItemName(dataModelTree, "model" + idIndex)) { + idIndex++; + } + dataModel = (BindingData) PartUtil.createPart(PartType.DATAMODEL, LayoutSchemaConstants.DATAMODEL); + dataModel.setModelType(BuilderConstants.DATABINDING_TYPE_EMPTY); + dataModel.setModelName("model" + idIndex); + dataModel.setItemName(dataModel.getModelName()); + Command addDataModelCommand = DataBindingCommandFactory.createAddDataModelCommand(combineEditorPart, dataModel); + getCommandStackFromDesignEditor().execute(addDataModelCommand); + + } + + public void setDataSourceToDataModel(BindingData dataSource, BindingData dataModel) { + if (dataSource == null) { + return; + } + if (dataModel == null) { + BindingData dataModelToBeAdded = (BindingData) PartUtil.createPart(PartType.DATAMODEL, LayoutSchemaConstants.DATAMODEL); + int idIndex = 0; + while (!canSetTreeItemName(dataModelTree, "model" + idIndex)) { + idIndex++; + } + dataModelToBeAdded.setModelName("model" + idIndex); + dataModelToBeAdded.setSourceName(dataSource.getSourceName()); + dataModelToBeAdded.setModelType(dataSource.getModelType()); + for (BindingObject dataSourceBindingObject : dataSource.getBindingObjects()) { + BindingObject dataModelBindingObject = dataSourceBindingObject.clone(); + dataModelToBeAdded.insertChildBefore(dataModelBindingObject, null); + } + Command addDataModelCommand = DataBindingCommandFactory.createAddDataModelCommand(combineEditorPart, dataModelToBeAdded); + getCommandStackFromDesignEditor().execute(addDataModelCommand); + } else { + + if (dataModel.getSourceName() != null && dataModel.getSourceName().length() > 0) { + MessageBox msgBox = new MessageBox(composite.getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO); + msgBox.setText("Data Binding"); + msgBox.setMessage(dataModel.getModelName() + " is already linked with " + dataModel.getSourceName() + ".\nDo you want to change to " + + dataSource.getSourceName() + " ?"); + if (msgBox.open() == SWT.NO) + return; + } + + BindingData newDataModel = (BindingData) PartUtil.createPart(PartType.DATAMODEL, LayoutSchemaConstants.DATAMODEL); + newDataModel.setSourceName(dataSource.getSourceName()); + newDataModel.setItemName(dataModel.getItemName()); + newDataModel.setModelName(dataModel.getModelName()); + newDataModel.setModelType(dataSource.getModelType()); + for (BindingObject bo : dataSource.getBindingObjects()) { + BindingObject newBo = bo.clone(); + newDataModel.insertChildBefore(newBo, null); + } + + Command setDataModelCommand = DataBindingCommandFactory.createSetDataModelCommand(combineEditorPart, dataModel, newDataModel); + getCommandStackFromDesignEditor().execute(setDataModelCommand); + } + + } + + public void createBindingInfoPanel(SashForm parentSashForm) { + Composite dataInfoPanel = new Composite(parentSashForm, SWT.BORDER); + + FormLayout layout = new FormLayout(); + dataInfoPanel.setLayout(layout); + + ToolBar toolBar = makeBindingInfoToolbar(dataInfoPanel); + FormData toolBarData = new FormData(); + toolBarData.top = new FormAttachment(0, 0); + toolBarData.right = new FormAttachment(100, 0); + + toolBar.setLayoutData(toolBarData); + + bindingInfoTableViewer = new TableViewer(dataInfoPanel, SWT.MULTI); + FormData tableData = new FormData(); + tableData.top = new FormAttachment(toolBar, 0); + tableData.bottom = new FormAttachment(100, 0); + tableData.left = new FormAttachment(0, 0); + tableData.right = new FormAttachment(100, 0); + bindingInfoTableViewer.getTable().setLayoutData(tableData); + + TableColumn tc1 = new TableColumn(bindingInfoTableViewer.getTable(), SWT.LEFT); + TableColumn tc2 = new TableColumn(bindingInfoTableViewer.getTable(), SWT.LEFT); + TableColumn tc3 = new TableColumn(bindingInfoTableViewer.getTable(), SWT.LEFT); + + tc1.setText("Data"); + tc2.setText("UI Component"); + tc3.setText("Binding"); + + tc1.setWidth(150); + tc2.setWidth(100); + tc3.setWidth(60); + + bindingInfoTableViewer.getTable().setHeaderVisible(true); + bindingInfoTableViewer.getTable().setLinesVisible(true); + + bindingInfoTableViewer.getTable().addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent event) { + switch (event.keyCode) { + case SWT.DEL: + removeBindingInfo(); + break; + } + } + }); + + bindingInfoTableViewer.getTable().addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + updateBindingInfoMenus(); + } + }); + createBindingInfoContextMenu(); + } + + private void createBindingInfoContextMenu() { + bindingInfoMenuManager = new MenuManager("#BindingInfoMenu"); + + bindingInfoMenuManager.add(removeBindingInfoAction); + bindingInfoMenuManager.update(true); + + Menu menu = bindingInfoMenuManager.createContextMenu(bindingInfoTableViewer.getTable()); + bindingInfoTableViewer.getTable().setMenu(menu); + } + + private ToolBar makeBindingInfoToolbar(Composite panel) { + ToolBar toolBar = new ToolBar(panel, SWT.FLAT); + bindingInfoToolBarManager = new ToolBarManager(toolBar); + bindingInfoToolBarManager.add(showBindingInfoAction); + bindingInfoToolBarManager.add(new Separator()); + + bindingInfoToolBarManager.add(removeBindingInfoAction); + bindingInfoToolBarManager.update(true); + createToolBarTitle(toolBar, "Binding Information"); + return toolBar; + } + + /* + * DataSouce editions start + */ + + public void addDataSource() { + int idIndex = 0; + while (!canSetTreeItemName(dataSourceTree, "source" + idIndex)) { + idIndex++; + } + + BindingData dataSource = (BindingData) PartUtil.createPart(PartType.DATASOURCE, LayoutSchemaConstants.DATASOURCE); + dataSource.setModelType(BuilderConstants.DATABINDING_TYPE_EMPTY); + dataSource.setSourceName("source" + idIndex); + dataSource.setItemName(dataSource.getSourceName()); + Command addDataSourceCommand = DataBindingCommandFactory.createAddDataSourceCommand(combineEditorPart, dataSource); + getCommandStackFromDesignEditor().execute(addDataSourceCommand); + } + + public void renameDataSource(TreeItem treeItem) { + renameTreeItem(dataSourceTree, dataSourceTreeEditor, treeItem); + } + + public void renameDataSource(TreeItem treeItem, String newName) { + if (treeItem.getParentItem() == null && combineEditorPart.getDataBindManager() != null && isSourceNameValid(newName)) { + BindingData dataSource = combineEditorPart.getDataBindManager().getDataSource(treeItem.getText()); + Command renameDataSourceCommand = DataBindingCommandFactory.createRenameDataSourceCommand(combineEditorPart, dataSource, newName); + getCommandStackFromDesignEditor().execute(renameDataSourceCommand); + } + } + + public void removeDataSource() { + TreeItem[] treeItems = dataSourceTree.getSelection(); + if (combineEditorPart.getDataBindManager() != null) { + for (TreeItem treeItem : treeItems) { + if (treeItem.getParentItem() == null) { + BindingData dataSource = combineEditorPart.getDataBindManager().getDataSource(treeItem.getText()); + Command dataSourceRemoveCommand = DataBindingCommandFactory.createRemoveDataSourceCommand(combineEditorPart, dataSource); + getCommandStackFromDesignEditor().execute(dataSourceRemoveCommand); + } + } + } + } + + /* + * DataSouce editions end + */ + + private CommandStack getCommandStackFromDesignEditor() { + if (combineEditorPart.getDesignEditor() != null) { + return (CommandStack) combineEditorPart.getDesignEditor().getAdapter(CommandStack.class); + } else { + return null; + } + } + + private boolean canSetTreeItemName(Tree tree, String itemName) { + TreeItem[] childItems = tree.getItems(); + for (TreeItem childItem : childItems) { + TreeItemData treeItemData = (TreeItemData) childItem.getData("TREEITEMDATA"); + String originName = null; + String name; + if (treeItemData != null) { + originName = treeItemData.getOriginModelName(); + } + if (originName == null) { + name = childItem.getText(); + } else { + name = originName; + } + + if (name != null) { + if (name.equals(itemName)) { + return false; + } + } + } + return true; + } + + /* + * Method to rename Data Model + */ + public void renameDataModel() { + + } + + public void setInput() { + + // Map uodo redo handlers for DesignEditor to DataBindingPage + + if (combineEditorPart != null && combineEditorPart.getDataBindManager() != null && combineEditorPart.getDataBindManager().getBindingDataSet() != null) { + combineEditorPart.getDataBindManager().getBindingDataSet().addBindingDataListener(this); + combineEditorPart.getDataBindManager().getDesignViewer().addSelectionChangedListener(this); + docPartObserver = new PartObserver(this); + docPartObserver.observe(combineEditorPart.getDocumentPart()); + dataBindingPartObserver = new PartObserver(this); + dataBindingPartObserver.observe(combineEditorPart.getDataBindingPart()); + } + + } + + // TODO: Merge it with page.dispose + public void unHook() { + if (combineEditorPart != null) { + combineEditorPart.getDataBindManager().getBindingDataSet().removeBindingDataListener(this); + combineEditorPart.getDesignEditor().getViewer().removeSelectionChangedListener(this); + docPartObserver.disconnect(); + dataBindingPartObserver.disconnect(); + } + } + + @Override + public Control getControl() { + return composite; + } + + @Override + public void setFocus() { + // TODO Auto-generated method stub + + } + + public Tree getDataSourceTree() { + return dataSourceTree; + } + + public Tree getDataModelTree() { + return dataModelTree; + } + + @Override + public void allDataSourcesReseted(BindingDataSetEvent e) { + + } + + @Override + public void dataSourceAdded(BindingDataSetEvent e) { + } + + public void refresh() { + refreshDataSourceTree(); + refreshDataModelTree(); + refreshBindingInfos(); + refreshMenus(); + } + + public void refreshBindingInfos() { + DesignViewer designViewer = combineEditorPart.getDataBindManager().getDesignViewer(); + showBindingInfoAction.updateActionImage(); + bindingInfoTableViewer.getTable().removeAll(); + DesignEditPart currentViewEditPart = designViewer.getCurrentViewEditPart(); + if (currentViewEditPart != null) { + designViewer.showBindingInfo(currentViewEditPart.isBinded()); + Part currentViewPart = combineEditorPart.getDesignEditor().getViewer().getCurrentViewPart(); + if (currentViewPart != null) { + refreshBindingInfo(currentViewPart.getChildren()); + } + } + } + + private void refreshBindingInfo(List parts) { + if (parts == null) { + return; + } + for (Part part : parts) { + String propertyValue = part.getPropertyValue(BuilderConstants.ATTRIBUTE_DATA_BIND); + if ((propertyValue != null) && (!propertyValue.isEmpty())) { + addInfoTableItem(part, propertyValue.substring(propertyValue.indexOf(":") + 1), part.getPropertyValue(BuilderConstants.PROPERTY_ID), + propertyValue.substring(0, propertyValue.indexOf(":"))); + } + refreshBindingInfo(part.getChildren()); + } + } + + private void refreshMenus() { + updateDataSourceMenus(); + updateDataModelMenus(); + updateBindingInfoMenus(); + } + + private void refreshDataSourceTree() { + // Retaining scrollbar values + int selection = dataSourceTree.getVerticalBar().getSelection(); + int minimum = dataSourceTree.getVerticalBar().getMinimum(); + int maximum = dataModelTree.getVerticalBar().getMaximum(); + int thumb = dataSourceTree.getVerticalBar().getThumb(); + int increment = dataSourceTree.getVerticalBar().getIncrement(); + int pageIncrement = dataSourceTree.getVerticalBar().getIncrement(); + dataSourceTree.removeAll(); + if (combineEditorPart.getDataBindManager() != null) { + List dataSources = combineEditorPart.getDataBindManager().getDataSources(); + + BindingData dataSource; + for (int i = 0; i < dataSources.size(); i++) { + dataSource = dataSources.get(i); + TreeItem treeItem = new TreeItem(dataSourceTree, 0); + TreeItemData treeItemData = new TreeItemData(); + + if ((dataSource.getItemName() == null) || (!dataSource.getItemName().equals(dataSource.getSourceName()))) { + dataSource.setItemName(dataSource.getSourceName()); + } + treeItem.setText(dataSource.getItemName()); + if (dataSource.getPropertyValue(BuilderConstants.ATTRIBUTE_SOURCE_TYPE) != null + && dataSource.getPropertyValue(BuilderConstants.ATTRIBUTE_SOURCE_TYPE).equals(BuilderConstants.JSON)) { + treeItem.setData("path", dataSource.getSourceName() + BuilderConstants.SLASH + "root"); + } else { + treeItem.setData("path", dataSource.getSourceName()); + } + treeItemData.setModel(dataSource); + treeItem.setData("TREEITEMDATA", treeItemData); + + makeSubTreeItem(treeItem, dataSource.getBindingObjects(), null, null); + TreeItemData data = (TreeItemData) dataSourceTree.getData("TREEITEMDATA"); + if (data == null) { + data = new TreeItemData(); + } + // data.setViewModelCount(i + 1); + dataSourceTree.setData("TREEITEMDATA", data); + + String imageName = DataBindingHelper.makeIconPath(dataSource.getModelType()); + if (imageName != null) { + treeItem.setImage(ResourceManager.getImage(BuilderConstants.ICON_DIR, imageName)); + } + } + dataSourceTree.getVerticalBar().setValues(selection, minimum, maximum, thumb, increment, pageIncrement); + } + } + + private void refreshDataModelTree() { + // Retaining scrollbar values + int selection = dataModelTree.getVerticalBar().getSelection(); + int minimum = dataModelTree.getVerticalBar().getMinimum(); + int maximum = dataModelTree.getVerticalBar().getMaximum(); + int thumb = dataModelTree.getVerticalBar().getThumb(); + int increment = dataModelTree.getVerticalBar().getIncrement(); + int pageIncrement = dataModelTree.getVerticalBar().getIncrement(); + String selectedPath = null; + + if (dataModelTree.getSelection().length > 0) + selectedPath = (String) dataModelTree.getSelection()[0].getData("path"); + + ArrayList extendedItems = new ArrayList(); + + DataBindingHelper.getExtendedItems(extendedItems, dataModelTree.getItems()); + + dataModelTree.removeAll(); + + List viewModels = combineEditorPart.getDataBindManager().getDataModels(); + + for (BindingData viewModel : viewModels) { + TreeItem treeItem = new TreeItem(dataModelTree, 0); + treeItem.setData("VIEW_MODEL", viewModel); + TreeItemData treeItemData = new TreeItemData(); + + if ((viewModel.getSourceName() == null) || (viewModel.getSourceName().isEmpty())) { + viewModel.setItemName(viewModel.getModelName()); + } else { + viewModel.setItemName(viewModel.getModelName() + " (" + viewModel.getSourceName() + ")"); + } + + treeItem.setText(viewModel.getItemName()); + BindingData dataSource = null; + if ((viewModel.getSourceName() != null) && (!viewModel.getSourceName().isEmpty())) { + dataSource = combineEditorPart.getDataBindManager().getDataSource(viewModel.getSourceName()); + } + if (dataSource != null && BuilderConstants.JSON.equals(dataSource.getPropertyValue(BuilderConstants.ATTRIBUTE_SOURCE_TYPE))) { + treeItem.setData("path", viewModel.getModelName() + BuilderConstants.SLASH + "root"); + } else { + treeItem.setData("path", viewModel.getModelName()); + } + + treeItemData.setModel(viewModel); + treeItemData.setOriginModelName(viewModel.getModelName()); + treeItem.setData("TREEITEMDATA", treeItemData); + + if (!viewModel.getBindingObjects().isEmpty()) { + if (dataSource != null) { + makeSubTreeItem(treeItem, viewModel.getBindingObjects(), dataSource.getBindingObjects(), null); + } else { + makeSubTreeItem(treeItem, viewModel.getBindingObjects(), null, null); + } + } + + TreeItemData data = (TreeItemData) dataModelTree.getData("TREEITEMDATA"); + if (data == null) { + data = new TreeItemData(); + } + dataModelTree.setData("TREEITEMDATA", data); + + String imageName = null; + if ((viewModel.getSourceName() == null) || (viewModel.getSourceName().isEmpty())) { + imageName = BuilderConstants.DATABINDING_MODEL_EMPTY_ICON; + } else { + imageName = BuilderConstants.DATABINDING_MODEL_NOT_EMPTY_ICON; + } + + if (imageName != null) { + treeItem.setImage(ResourceManager.getImage(BuilderConstants.ICON_DIR, imageName)); + } + } + + DataBindingHelper.extendItems(extendedItems, dataModelTree.getItems(), selectedPath); + dataModelTree.getVerticalBar().setValues(selection, minimum, maximum, thumb, increment, pageIncrement); + } + + private void makeSubTreeItem(TreeItem parentTreeItem, List list, List sourcelist, String allowedBindingType) { + if ((list == null) || (list.isEmpty())) { + return; + } + + // BindingObject sourceItem = null; + for (BindingObject observableObject : list) { + if (observableObject.getName() == null || observableObject.getName().isEmpty()) + continue; + + if (observableObject.getValueType().equals("Array")) { + String nextAllowedBindingType = null; + List firstChildList = new ArrayList(); + firstChildList.add(observableObject.getBindingObjects().get(0)); + if (firstChildList.get(0).getValueType().equals("Index")) { + nextAllowedBindingType = "Array"; + } + TreeItem treeItem = createTreeItem(parentTreeItem, observableObject, nextAllowedBindingType); + makeSubTreeItem(treeItem, firstChildList, sourcelist, nextAllowedBindingType); + } else if (observableObject.getValueType().equals("Index")) { + continue; + } else if (observableObject.getValueType().equals("IndexObject")) { + makeSubTreeItem(parentTreeItem, observableObject.getBindingObjects(), sourcelist, "Array"); + } else if (observableObject.getValueType().equals("Object")) { + TreeItem treeItem = createTreeItem(parentTreeItem, observableObject, null); + makeSubTreeItem(treeItem, observableObject.getBindingObjects(), sourcelist, allowedBindingType); + } else { + createTreeItem(parentTreeItem, observableObject, "Array".equals(allowedBindingType) ? allowedBindingType : "Text"); + } + + } + } + + private TreeItem createTreeItem(TreeItem parentTreeItem, BindingObject observableObject, String allowedBindingType) { + TreeItem treeItem = new TreeItem(parentTreeItem, 0); + treeItem.setData("BINDING_OBJECT", observableObject); + treeItem.setText(observableObject.getName()); + treeItem.setData("path", parentTreeItem.getData("path") + BuilderConstants.SLASH + observableObject.getName()); + if (observableObject.getValueType().equals("Array")) { + treeItem.setData("path", treeItem.getData("path") + "[*]"); + } + TreeItemData treeItemData = new TreeItemData(); + treeItemData.setObjectType(observableObject.getValueType()); + treeItemData.setObjectValue(observableObject.getValue()); + treeItemData.setBindedValue(false); + treeItemData.setAllowedBindingType(allowedBindingType); + treeItemData.setModel(observableObject.getOwnerBindingData()); + treeItem.setData("TREEITEMDATA", treeItemData); + if (treeItemData.getObjectType() != null) { + String imageName = null; + String type = treeItemData.getObjectType(); + if (type.equals("Array")) { + imageName = BuilderConstants.DATABINDING_ARRAY_ICON; + } else if (type.equals("Number")) { + imageName = BuilderConstants.DATABINDING_NUMBER_ICON; + } else if (type.equals("String")) { + imageName = BuilderConstants.DATABINDING_STRING_ICON; + } else if (type.equals("Index")) { + imageName = BuilderConstants.DATABINDING_INDEX_ICON; + } else if (type.equals("Object")) { + imageName = BuilderConstants.DATABINDING_OBJECT_ICON; + } else if (type.equals("Boolean")) { + imageName = BuilderConstants.DATABINDING_BOOLEAN_ICON; + } else { + imageName = BuilderConstants.DATABINDING_UNDEFINED_ICON; + } + + if (imageName != null) { + treeItem.setImage(ResourceManager.getImage(BuilderConstants.ICON_DIR, imageName)); + } + } + return treeItem; + } + + @Override + public void dataSourceRemoved(BindingDataSetEvent e) { + } + + @Override + public void dataSourceRenamed(BindingDataSetEvent e) { + if (combineEditorPart.getDataBindManager() != null) { + List models = combineEditorPart.getDataBindManager().getDataModels(); + for (BindingData model : models) { + if (model.getSourceName() != null && model.getSourceName().equals(e.getOldValue())) { + model.setSourceName(e.getValue()); + } + } + } + } + + @Override + public void dataSourceMoved(BindingDataSetEvent e) { + } + + @Override + public void dataSourceChanged(BindingDataSetEvent e) { + } + + @Override + public void allDataModelReseted(BindingDataSetEvent e) { + } + + @Override + public void dataModelAdded(BindingDataSetEvent e) { + } + + @Override + public void dataModelRemoved(BindingDataSetEvent e) { + } + + @Override + public void dataModelRenamed(BindingDataSetEvent e) { + } + + @Override + public void dataModelMoved(BindingDataSetEvent e) { + } + + @Override + public void dataModelChanged(BindingDataSetEvent e) { + } + + @Override + public void dataModelItemRenamed(BindingDataSetEvent e) { + } + + public boolean checkDuplicatedTableItem(String modelName, String widgetName, String bindingInfoStr) { + TableItem[] items = bindingInfoTableViewer.getTable().getItems(); + for (TableItem item : items) { + if (item.getText(0).equals(modelName)) { + if (item.getText(2).equals(widgetName)) { + if (item.getText(3).equals(bindingInfoStr)) { + return false; + } + } + } + } + + return true; + } + + public void addInfoTableItem(Part part, String modelName, String widgetName, String bindingInfoStr) { + final TableItem item = new TableItem(bindingInfoTableViewer.getTable(), SWT.NONE); + item.setText(new String[] { modelName, widgetName, bindingInfoStr }); + item.setData("PART", part); + } + + @Override + public void selectionChanged(SelectionChangedEvent event) { + Part viewPart = combineEditorPart.getDesignEditor().getViewer().getCurrentViewPart(); + if (currentViewPart == null || currentViewPart != viewPart) { + currentViewPart = viewPart; + refreshBindingInfos(); + } + + TableItem[] tableItems = bindingInfoTableViewer.getTable().getItems(); + List selectTableItems = new ArrayList(); + for (Object child : ((StructuredSelection) event.getSelection()).toList()) { + if (child instanceof EditPart) { + EditPart editPart = (EditPart) child; + Part part = (Part) editPart.getModel(); + String value = part.getPropertyValue(BuilderConstants.ATTRIBUTE_DATA_BIND); + if (value != null && !value.isEmpty()) { + for (TableItem tableItem : tableItems) { + Part tableItemPart = (Part) tableItem.getData("PART"); + if (part == tableItemPart) { + selectTableItems.add(tableItem); + } + } + } + } + } + bindingInfoTableViewer.getTable().setSelection(selectTableItems.toArray(new TableItem[0])); + updateBindingInfoMenus(); + } + + @Override + public void partsChanged(List mutations, PartObserver observer, String sender) { + if (mutations.size() > 0) { + refresh(); + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/DataBindingView.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/DataBindingView.java new file mode 100644 index 0000000..6ff7643 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/DataBindingView.java @@ -0,0 +1,161 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding; + +import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.text.ParseException; +import org.eclipse.core.resources.IProject; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.part.EditorPart; +import org.eclipse.ui.part.IPage; +import org.eclipse.ui.part.MessagePage; +import org.eclipse.ui.part.PageBook; +import org.eclipse.ui.part.PageBookView; +//import org.tizen.webuibuilder.BuilderConstants; +//import org.tizen.efluibuilder.ui.editor.PageDesigner; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.nativecore.ext.manifest.Manifest; +import org.tizen.nativecore.ext.xmlstore.CoreXMLStore; + +/** + * DataBindingView is the data binding plugin's view entry point. + * + * @author mukul.cy + * + */ +public class DataBindingView extends PageBookView { + private static double MIN_SUPPORTED_VERSION = 2.4; + + @Override + protected IPage createDefaultPage(PageBook book) { + MessagePage page = new MessagePage(); + initPage(page); + page.createControl(book); + page.setMessage("Data binding view"); + return page; + } + + @Override + protected PageRec doCreatePage(IWorkbenchPart part) { + IPage page = null; + if (!(part instanceof CombineEditorPart)) { + return null; + } + DataBindingPage dataBindingPage = new DataBindingPage(this, (CombineEditorPart) part); + initPage(dataBindingPage); + if (!isDataBindingSupported(part)) { + page = createNotSupportedPage(); + PageRec pageRecord = new PageRec(part, page); + return pageRecord; + } else { + dataBindingPage.createControl(getPageBook()); + } + + PageRec pageRecord = new PageRec(part, dataBindingPage); + return pageRecord; + } + + private boolean isDataBindingSupported(IWorkbenchPart part) { + boolean isDataBindingSupported = false; + if (part instanceof EditorPart) { + String major_version_str = null; + Number major_version = null; + NumberFormat df = DecimalFormat.getInstance(); + String[] version_sub_str = getAppVersion(part).split("\\."); + major_version_str = version_sub_str[0] + "." + version_sub_str[1]; + try { + major_version = df.parse(major_version_str); + } catch (ParseException e) { + e.printStackTrace(); + } + if ((major_version != null) && (major_version.doubleValue() >= MIN_SUPPORTED_VERSION)) { + isDataBindingSupported = true; + } + } + return isDataBindingSupported; + } + + private String getAppVersion(IWorkbenchPart part) { + IProject project = null; + String version = null; + EditorPart editorPart = (EditorPart) part; + project = ((IFileEditorInput) editorPart.getEditorInput()).getFile().getProject(); + CoreXMLStore coreXmlManager = new CoreXMLStore(project); + coreXmlManager.loadXml(); + Manifest manifestModel = coreXmlManager.getCoreManifest(); + version = manifestModel.getApiVersion(); + return version; + } + + protected IPage createNotSupportedPage() { + MessagePage page = new MessagePage(); + initPage(page); + page.createControl(getPageBook()); + page.setMessage("Databinding is not supported for Tizen platform earlier than 2.4"); + return page; + } + + @Override + protected void doDestroyPage(IWorkbenchPart part, PageRec pageRecord) { + // TODO Auto-generated method stub + if (pageRecord.page instanceof DataBindingPage) + ((DataBindingPage) pageRecord.page).unHook(); + // this.dataBindingPage = null; + pageRecord.page.dispose(); + // this.pageRecord = null; + } + + @Override + protected IWorkbenchPart getBootstrapPart() { + IWorkbench workbench = PlatformUI.getWorkbench(); + if (workbench == null) { + return null; + } + IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); + if (window == null) { + return null; + } + IWorkbenchPage page = window.getActivePage(); + if (page == null) { + return null; + } + IEditorPart editor = page.getActiveEditor(); + if (editor == null) { + return null; + } + + return editor; + } + + @Override + protected boolean isImportant(IWorkbenchPart part) { + return part instanceof CombineEditorPart; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/DataModelTreeItemTransfer.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/DataModelTreeItemTransfer.java new file mode 100644 index 0000000..b4479fc --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/DataModelTreeItemTransfer.java @@ -0,0 +1,95 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding; + +import java.nio.charset.Charset; + +import org.eclipse.swt.dnd.ByteArrayTransfer; +import org.eclipse.swt.dnd.TransferData; +import org.eclipse.swt.widgets.TreeItem; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; + +public class DataModelTreeItemTransfer extends ByteArrayTransfer { + + private static final DataModelTreeItemTransfer INSTANCE = new DataModelTreeItemTransfer(); + private static final String TYPE_NAME = "TreeItem Transfer"//$NON-NLS-1$ + + System.currentTimeMillis() + ":" + INSTANCE.hashCode();//$NON-NLS-1$ + private static final int TYPEID = registerType(TYPE_NAME); + + private TreeItem treeItem; + private long startTime; + + public static DataModelTreeItemTransfer getInstance() { + return INSTANCE; + } + + private DataModelTreeItemTransfer() { + } + + @Override + protected int[] getTypeIds() { + return new int[] { TYPEID }; + } + + @Override + protected String[] getTypeNames() { + return new String[] { TYPE_NAME }; + } + + @Override + public void javaToNative(Object object, TransferData transferData) { + setTreeItem((TreeItem) object); + startTime = System.currentTimeMillis(); + if (transferData != null) + super.javaToNative(String.valueOf(startTime).getBytes(Charset.forName(BuilderConstants.ENCODING)), + transferData); + } + + @Override + public Object nativeToJava(TransferData transferData) { + byte bytes[] = (byte[]) super.nativeToJava(transferData); + if (bytes == null) { + return null; + } + long startTime = Long.parseLong(new String(bytes, Charset.forName(BuilderConstants.ENCODING))); + return (this.startTime == startTime) ? getTreeItem() : null; + } + + /** + * Gets a tree item. + * + * @return tree item + */ + public TreeItem getTreeItem() { + return treeItem; + } + + /** + * Sets a tree item. + * + * @param item + */ + public void setTreeItem(TreeItem item) { + this.treeItem = item; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/TreeItemTransfer.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/TreeItemTransfer.java new file mode 100644 index 0000000..6df0440 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/TreeItemTransfer.java @@ -0,0 +1,95 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding; + +import java.nio.charset.Charset; + +import org.eclipse.swt.dnd.ByteArrayTransfer; +import org.eclipse.swt.dnd.TransferData; +import org.eclipse.swt.widgets.TreeItem; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; + +public class TreeItemTransfer extends ByteArrayTransfer { + + private static final TreeItemTransfer INSTANCE = new TreeItemTransfer(); + private static final String TYPE_NAME = "TreeItem Transfer"//$NON-NLS-1$ + + System.currentTimeMillis() + ":" + INSTANCE.hashCode();//$NON-NLS-1$ + private static final int TYPEID = registerType(TYPE_NAME); + + private TreeItem treeItem; + private long startTime; + + public static TreeItemTransfer getInstance() { + return INSTANCE; + } + + private TreeItemTransfer() { + } + + @Override + protected int[] getTypeIds() { + return new int[] { TYPEID }; + } + + @Override + protected String[] getTypeNames() { + return new String[] { TYPE_NAME }; + } + + @Override + public void javaToNative(Object object, TransferData transferData) { + setTreeItem((TreeItem) object); + startTime = System.currentTimeMillis(); + if (transferData != null) + super.javaToNative(String.valueOf(startTime).getBytes(Charset.forName(BuilderConstants.ENCODING)), + transferData); + } + + @Override + public Object nativeToJava(TransferData transferData) { + byte bytes[] = (byte[]) super.nativeToJava(transferData); + if (bytes == null) { + return null; + } + long startTime = Long.parseLong(new String(bytes, Charset.forName(BuilderConstants.ENCODING))); + return (this.startTime == startTime) ? getTreeItem() : null; + } + + /** + * Gets a tree item. + * + * @return tree item + */ + public TreeItem getTreeItem() { + return treeItem; + } + + /** + * Sets a tree item. + * + * @param item + */ + public void setTreeItem(TreeItem item) { + this.treeItem = item; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/AddDataModelAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/AddDataModelAction.java new file mode 100644 index 0000000..49681d6 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/AddDataModelAction.java @@ -0,0 +1,83 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.actions; + +import org.eclipse.gef.ui.actions.SelectionAction; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.part.IPage; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingPage; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingView; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingData; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; +import org.tizen.efluibuilder.ui.view.databinding.utils.ResourceManager; + +public class AddDataModelAction extends SelectionAction { + + private DataBindingView view; + private BindingData model; + + /** + * Constructor. + * + * @param text + * @param view + */ + public AddDataModelAction(DataBindingView view, BindingData model) { + super(null); + + if (model != null) + setText(model.getSourceName()); + else + setText("Empty Model"); + + this.view = view; + this.model = model; + Image img = ResourceManager.getImage(BuilderConstants.ICON_DIR, + BuilderConstants.DATABINDING_DATAMODEL_ADD_ICON); + ImageDescriptor imgDesc = ImageDescriptor.createFromImage(img); + setImageDescriptor(imgDesc); + } + + @Override + protected boolean calculateEnabled() { + if (view == null) { + return false; + } + return true; + } + + @Override + public void run() { + IPage page = view.getCurrentPage(); + if (!(page instanceof DataBindingPage)) { + return; + } + DataBindingPage dataBindingPage = (DataBindingPage) page; + if (model != null) + dataBindingPage.setDataSourceToDataModel(model, null); + else + dataBindingPage.addDataModel(); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/AddDataModelItemAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/AddDataModelItemAction.java new file mode 100644 index 0000000..af738fc --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/AddDataModelItemAction.java @@ -0,0 +1,86 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.actions; + +import org.eclipse.gef.ui.actions.SelectionAction; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.part.IPage; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingPage; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingView; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; +import org.tizen.efluibuilder.ui.view.databinding.utils.ResourceManager; + +public class AddDataModelItemAction extends SelectionAction { + + protected DataBindingView view; + + /** + * Constructor. + * + * @param text + * @param view + */ + public AddDataModelItemAction(String text, String tooltipText, DataBindingView view) { + super(null); + setText(text); + setToolTipText(tooltipText); + this.view = view; + Image img = ResourceManager.getImage(BuilderConstants.ICON_DIR, + BuilderConstants.DATABINDING_DATAMODELITEM_ADD_ICON); + ImageDescriptor imgDesc = ImageDescriptor.createFromImage(img); + setImageDescriptor(imgDesc); + } + + @Override + protected boolean calculateEnabled() { + if (view == null) { + return false; + } + + IPage page = view.getCurrentPage(); + if (!(page instanceof DataBindingPage)) { + return false; + } + DataBindingPage dataBindingPage = (DataBindingPage) page; + if (!dataBindingPage.canRemoveDataModel()) { + return false; + } + return true; + } + + public void refresh() { + setEnabled(calculateEnabled()); + } + + @Override + public void run() { + IPage page = view.getCurrentPage(); + if (!(page instanceof DataBindingPage)) { + return; + } + DataBindingPage dataBindingPage = (DataBindingPage) page; + dataBindingPage.addDataModelItem(); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/AddDataSourceAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/AddDataSourceAction.java new file mode 100644 index 0000000..d46070c --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/AddDataSourceAction.java @@ -0,0 +1,93 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.actions; + +import org.eclipse.gef.ui.actions.SelectionAction; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.part.IPage; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingPage; +/*import org.tizen.webuibuilder.BuilderConstants; +import org.tizen.webuibuilder.ui.views.databinding.DataBindingPage; +import org.tizen.webuibuilder.ui.views.databinding.DataBindingView; +import org.tizen.webuibuilder.ui.views.databinding.dialog.SetSourcePage; +import org.tizen.webuibuilder.ui.views.databinding.model.BindingData; +import org.tizen.webuibuilder.utility.ResourceManager;*/ +import org.tizen.efluibuilder.ui.view.databinding.DataBindingView; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; +import org.tizen.efluibuilder.ui.view.databinding.utils.ResourceManager; + + +public class AddDataSourceAction extends SelectionAction { + + protected DataBindingView view; + /** + * Constructor. + * + * @param text + * @param view + */ + public AddDataSourceAction(String text, String toolTipText, DataBindingView view) { + super(null); + setText(text); + setToolTipText(toolTipText); + this.view = view; + Image img = ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_DATASOURCE_ADD_ICON); + ImageDescriptor imgDesc = ImageDescriptor.createFromImage(img); + setImageDescriptor(imgDesc); + } + + private TreeItem getSelectedTreeItem() { + IPage page = view.getCurrentPage(); + if (!(page instanceof DataBindingPage)) { + return null; + } + DataBindingPage dataBindingPage = (DataBindingPage) page; + Tree tree = dataBindingPage.getDataSourceTree(); + TreeItem[] treeItem = tree.getSelection(); + + if ((treeItem == null) || (treeItem.length == 0)) { + return null; + } + + // 0 .. multi select + return treeItem[0]; + } + + @Override + protected boolean calculateEnabled() { + return true; + } + + @Override + public void run() { + IPage page = view.getCurrentPage(); + if (!(page instanceof DataBindingPage)) { + return; + } + DataBindingPage dataBindingPage = (DataBindingPage) page; + dataBindingPage.addDataSource(); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/AddModelDropDownAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/AddModelDropDownAction.java new file mode 100644 index 0000000..f39d823 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/AddModelDropDownAction.java @@ -0,0 +1,116 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.actions; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.ActionContributionItem; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuCreator; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.ui.part.IPage; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingManager; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingPage; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingView; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingData; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; +import org.tizen.efluibuilder.ui.view.databinding.utils.ResourceManager; + +public class AddModelDropDownAction extends Action implements IMenuCreator { + private Menu contextMenu; + private Menu toolbartMenu; + private DataBindingView view; + private DataBindingManager dataBindingManager; + + public AddModelDropDownAction(String text, String tooltipText, DataBindingView view, DataBindingManager dataBindingManager) { + super(text, IAction.AS_DROP_DOWN_MENU | SWT.NONE); + + setToolTipText(tooltipText); + this.view = view; + this.dataBindingManager = dataBindingManager; + + Image img = ResourceManager.getImage(BuilderConstants.ICON_DIR, + BuilderConstants.DATABINDING_DATAMODEL_ADD_ICON); + ImageDescriptor imgDesc = ImageDescriptor.createFromImage(img); + setImageDescriptor(imgDesc); + + setMenuCreator(this); + } + + @Override + public void dispose() { + if (contextMenu != null) { + contextMenu.dispose(); + contextMenu = null; + } + + if (toolbartMenu != null) { + toolbartMenu.dispose(); + toolbartMenu = null; + } + } + + @Override + public Menu getMenu(Control parent) { + if (contextMenu != null) + contextMenu.dispose(); + + contextMenu = new Menu(parent.getShell(), SWT.POP_UP | SWT.NONE); + + return createMenu(contextMenu); + } + + @Override + public Menu getMenu(Menu parent) { + if (toolbartMenu != null) + toolbartMenu.dispose(); + + toolbartMenu = new Menu(parent); + + return createMenu(toolbartMenu); + } + + public Menu createMenu(Menu menu) { + ActionContributionItem baseItem = new ActionContributionItem(new AddDataModelAction(view, null)); + baseItem.fill(menu, -1); + + for (BindingData data : dataBindingManager.getDataSources()) { + + ActionContributionItem item = new ActionContributionItem(new AddDataModelAction(view, data)); + item.fill(menu, -1); + } + return menu; + } + + public void run() { + IPage page = view.getCurrentPage(); + if (!(page instanceof DataBindingPage)) { + return; + } + DataBindingPage dataBindingPage = (DataBindingPage) page; + dataBindingPage.addDataModel(); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/CollapseAllAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/CollapseAllAction.java new file mode 100644 index 0000000..6f87de3 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/CollapseAllAction.java @@ -0,0 +1,71 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.actions; + +import org.eclipse.gef.ui.actions.SelectionAction; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; +import org.tizen.efluibuilder.ui.view.databinding.utils.ResourceManager; + +public class CollapseAllAction extends SelectionAction { + private Tree dataTree = null; + public CollapseAllAction(String text, String toolTipText) { + super(null); + setText(text); + setToolTipText(toolTipText); + Image img = ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_COLLAPSEALL); + ImageDescriptor imgDesc = ImageDescriptor.createFromImage(img); + setImageDescriptor(imgDesc); + } + + @Override + protected boolean calculateEnabled() { + return true; + } + + public void refresh() { + setEnabled(calculateEnabled()); + } + + @Override + public void run() { + if(dataTree == null) return; + for (TreeItem treeItem : dataTree.getItems()) { + collapseTreeItem(treeItem); + } + } + + private void collapseTreeItem(TreeItem treeItems) { + treeItems.setExpanded(false); + for (TreeItem treeItem : treeItems.getItems()) { + collapseTreeItem(treeItem); + } + } + + public void setTreeItem(Tree tree){ + this.dataTree = tree; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/EditDataSourceAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/EditDataSourceAction.java new file mode 100644 index 0000000..94a4008 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/EditDataSourceAction.java @@ -0,0 +1,121 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.actions; + +import org.eclipse.core.resources.IProject; +import org.eclipse.gef.ui.actions.SelectionAction; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.part.IPage; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingPage; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingView; +import org.tizen.efluibuilder.ui.view.databinding.dialog.SetSourcePage; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingData; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; +import org.tizen.efluibuilder.ui.view.databinding.utils.ResourceManager; + +public class EditDataSourceAction extends SelectionAction { + protected DataBindingView view; + private IProject project; + + /** + * Constructor. + * + * @param text + * @param view + */ + public EditDataSourceAction(String text, String toolTipText, DataBindingView view, IProject project) { + super(null); + setText(text); + setToolTipText(toolTipText); + this.view = view; + Image img = ResourceManager.getImage(BuilderConstants.ICON_DIR, + BuilderConstants.DATABINDING_DATASOURCE_DIALOG_ICON); + ImageDescriptor imgDesc = ImageDescriptor.createFromImage(img); + setImageDescriptor(imgDesc); + this.project = project; + + } + + private TreeItem getSelectedTreeItem() { + IPage page = view.getCurrentPage(); + if (!(page instanceof DataBindingPage)) { + return null; + } + DataBindingPage dataBindingPage = (DataBindingPage) page; + Tree tree = dataBindingPage.getDataSourceTree(); + TreeItem[] treeItem = tree.getSelection(); + + if ((treeItem == null) || (treeItem.length == 0)) { + return null; + } + + // 0 .. multi select + return treeItem[0]; + } + + @Override + protected boolean calculateEnabled() { + if (view == null) { + return false; + } + + if (getSelectedTreeItem() == null) { + return false; + } + + return true; + } + + public void refresh() { + setEnabled(calculateEnabled()); + } + + @Override + public void run() { + TreeItem treeItem = getSelectedTreeItem(); + if (treeItem == null) { + return; + } + + while (treeItem.getParentItem() != null) { + treeItem = treeItem.getParentItem(); + } + + SetSourcePage dlg = new SetSourcePage(Display.getCurrent().getActiveShell(), treeItem, project); + BindingData dataSource = dlg.open(); + + if (dataSource != null) { + IPage page = view.getCurrentPage(); + if (!(page instanceof DataBindingPage)) { + return; + } + DataBindingPage dataBindingPage = (DataBindingPage) page; + dataBindingPage.editDataSource(dataSource); + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/RemoveBindingInfoAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/RemoveBindingInfoAction.java new file mode 100644 index 0000000..46dc129 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/RemoveBindingInfoAction.java @@ -0,0 +1,80 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.actions; + +import org.eclipse.gef.ui.actions.SelectionAction; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.part.IPage; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingPage; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingView; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; +import org.tizen.efluibuilder.ui.view.databinding.utils.ResourceManager; + +public class RemoveBindingInfoAction extends SelectionAction { + + protected DataBindingView view; + + public RemoveBindingInfoAction(String text, String toolTipText, DataBindingView view) { + super(null); + setText(text); + setToolTipText(toolTipText); + this.view = view; + Image img = ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_DELETE_ICON); + ImageDescriptor imgDesc = ImageDescriptor.createFromImage(img); + setImageDescriptor(imgDesc); + } + + @Override + protected boolean calculateEnabled() { + if (view == null) { + return false; + } + + IPage page = view.getCurrentPage(); + if (!(page instanceof DataBindingPage)) { + return false; + } + DataBindingPage dataBindingPage = (DataBindingPage) page; + if (!dataBindingPage.canRemoveBindingInfo()) { + return false; + } + + return true; + } + + public void refresh() { + setEnabled(calculateEnabled()); + } + + @Override + public void run() { + IPage page = view.getCurrentPage(); + if (!(page instanceof DataBindingPage)) { + return; + } + DataBindingPage dataBindingPage = (DataBindingPage) page; + dataBindingPage.removeBindingInfo(); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/RemoveDataModelAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/RemoveDataModelAction.java new file mode 100644 index 0000000..bba6e6d --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/RemoveDataModelAction.java @@ -0,0 +1,85 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.actions; + +import org.eclipse.gef.ui.actions.SelectionAction; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.part.IPage; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingPage; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingView; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; +import org.tizen.efluibuilder.ui.view.databinding.utils.ResourceManager; + +public class RemoveDataModelAction extends SelectionAction { + + protected DataBindingView view; + + /** + * Constructor. + * + * @param text + * @param view + */ + public RemoveDataModelAction(String text, String toolTipText, DataBindingView view) { + super(null); + setText(text); + setToolTipText(toolTipText); + this.view = view; + Image img = ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_DATAMODEL_DELETE_ICON); + ImageDescriptor imgDesc = ImageDescriptor.createFromImage(img); + setImageDescriptor(imgDesc); + } + + @Override + protected boolean calculateEnabled() { + if (view == null) { + return false; + } + + IPage page = view.getCurrentPage(); + if (!(page instanceof DataBindingPage)) { + return false; + } + DataBindingPage dataBindingPage = (DataBindingPage) page; + if (!dataBindingPage.canRemoveDataModel()) { + return false; + } + + return true; + } + + public void refresh() { + setEnabled(calculateEnabled()); + } + + @Override + public void run() { + IPage page = view.getCurrentPage(); + if (!(page instanceof DataBindingPage)) { + return; + } + DataBindingPage dataBindingPage = (DataBindingPage) page; + dataBindingPage.removeDataModel(); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/RemoveDataSourceAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/RemoveDataSourceAction.java new file mode 100644 index 0000000..6b604f8 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/RemoveDataSourceAction.java @@ -0,0 +1,86 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.actions; + +import org.eclipse.gef.ui.actions.SelectionAction; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.part.IPage; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingPage; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingView; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; +import org.tizen.efluibuilder.ui.view.databinding.utils.ResourceManager; + +public class RemoveDataSourceAction extends SelectionAction { + + protected DataBindingView view; + + /** + * Constructor. + * + * @param text + * @param view + */ + public RemoveDataSourceAction(String text, String toolTipText, DataBindingView view) { + super(null); + setText(text); + setToolTipText(toolTipText); + this.view = view; + Image img = ResourceManager.getImage(BuilderConstants.ICON_DIR, + BuilderConstants.DATABINDING_DATASOURCE_DELETE_ICON); + ImageDescriptor imgDesc = ImageDescriptor.createFromImage(img); + setImageDescriptor(imgDesc); + } + + @Override + protected boolean calculateEnabled() { + if (view == null) { + return false; + } + + IPage page = view.getCurrentPage(); + if (!(page instanceof DataBindingPage)) { + return false; + } + DataBindingPage dataBindingPage = (DataBindingPage) page; + if (!dataBindingPage.canRemoveDataSource()) { + return false; + } + + return true; + } + + public void refresh() { + setEnabled(calculateEnabled()); + } + + @Override + public void run() { + IPage page = view.getCurrentPage(); + if (!(page instanceof DataBindingPage)) { + return; + } + DataBindingPage dataBindingPage = (DataBindingPage) page; + dataBindingPage.removeDataSource(); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/RenameDataModelAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/RenameDataModelAction.java new file mode 100644 index 0000000..c6ebd6b --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/RenameDataModelAction.java @@ -0,0 +1,117 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.actions; + +import org.eclipse.gef.ui.actions.SelectionAction; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.part.IPage; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingPage; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingView; +import org.tizen.efluibuilder.ui.view.databinding.model.TreeItemData; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; +import org.tizen.efluibuilder.ui.view.databinding.utils.ResourceManager; + +public class RenameDataModelAction extends SelectionAction { + + protected DataBindingView view; + + /** + * Constructor. + * + * @param text + * @param view + */ + public RenameDataModelAction(String text, String toolTipText, DataBindingView view) { + super(null); + setText(text); + setToolTipText(toolTipText); + this.view = view; + Image img = ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_RENAME_ICON); + ImageDescriptor imgDesc = ImageDescriptor.createFromImage(img); + setImageDescriptor(imgDesc); + } + + private TreeItem getSelectedTreeItem() { + IPage page = view.getCurrentPage(); + if (!(page instanceof DataBindingPage)) { + return null; + } + DataBindingPage dataBindingPage = (DataBindingPage) page; + Tree tree = dataBindingPage.getDataModelTree(); + TreeItem[] treeItem = tree.getSelection(); + + if ((treeItem == null) || (treeItem.length == 0)) { + return null; + } + + // 0 .. multi select + return treeItem[0]; + } + + private boolean checkTreeItem(TreeItem selectedTreeItem) { + + TreeItemData treeItemData = (TreeItemData) selectedTreeItem.getData("TREEITEMDATA"); + if (treeItemData.getBindedValue()) { + return true; + } + + return false; + } + + @Override + protected boolean calculateEnabled() { + if (view == null) { + return false; + } + + if (getSelectedTreeItem() == null) { + return false; + } + + if (checkTreeItem(getSelectedTreeItem())) { + return false; + } + + if (getSelectedTreeItem().getParentItem() != null) + return false; + + return true; + } + + public void refresh() { + setEnabled(calculateEnabled()); + } + + @Override + public void run() { + IPage page = view.getCurrentPage(); + if (!(page instanceof DataBindingPage)) { + return; + } + DataBindingPage dataBindingPage = (DataBindingPage) page; + dataBindingPage.renameDataModel(null); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/RenameDataSourceAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/RenameDataSourceAction.java new file mode 100644 index 0000000..a6234ca --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/RenameDataSourceAction.java @@ -0,0 +1,96 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.actions; + +import org.eclipse.gef.ui.actions.SelectionAction; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.part.IPage; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingPage; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingView; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; +import org.tizen.efluibuilder.ui.view.databinding.utils.ResourceManager; + +public class RenameDataSourceAction extends SelectionAction { + + protected DataBindingView view; + + private TreeItem getSelectedTreeItem() { + IPage page = view.getCurrentPage(); + if (!(page instanceof DataBindingPage)) { + return null; + } + DataBindingPage dataBindingPage = (DataBindingPage) page; + Tree tree = dataBindingPage.getDataSourceTree(); + TreeItem[] treeItem = tree.getSelection(); + + if ((treeItem == null) || (treeItem.length == 0)) { + return null; + } + return treeItem[0]; + } + + /** + * Constructor. + * + * @param text + * @param view + */ + public RenameDataSourceAction(String text, String toolTipText, DataBindingView view) { + super(null); + setText(text); + setToolTipText(toolTipText); + this.view = view; + Image img = ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_RENAME_ICON); + ImageDescriptor imgDesc = ImageDescriptor.createFromImage(img); + setImageDescriptor(imgDesc); + } + + public void refresh() { + setEnabled(calculateEnabled()); + } + + @Override + protected boolean calculateEnabled() { + if (view == null) + return false; + if (getSelectedTreeItem() == null) + return false; + if (getSelectedTreeItem().getParentItem() != null) + return false; + return true; + } + + @Override + public void run() { + IPage page = view.getCurrentPage(); + if (!(page instanceof DataBindingPage)) { + return; + } + DataBindingPage dataBindingPage = (DataBindingPage) page; + dataBindingPage.renameDataSource(null); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/SetModelTargetAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/SetModelTargetAction.java new file mode 100644 index 0000000..3faeb54 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/SetModelTargetAction.java @@ -0,0 +1,262 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.actions; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.gef.ui.actions.SelectionAction; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.part.IPage; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingManager; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingPage; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingView; +import org.tizen.efluibuilder.ui.view.databinding.dialog.SetModelTargetDialog; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingData; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingObject; +import org.tizen.efluibuilder.ui.view.databinding.model.DataBindingPartProperty; +import org.tizen.efluibuilder.ui.view.databinding.model.TreeItemData; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; +import org.tizen.efluibuilder.ui.view.databinding.utils.DataBindingHelper; +import org.tizen.efluibuilder.ui.view.databinding.utils.ResourceManager; + +/** + * + * @author mukul.cy + * + */ +public class SetModelTargetAction extends SelectionAction { + + private final DataBindingView dataBindingView; + private final CombineEditorPart combineEditorPart; + + private SetModelTargetDialog setTargetDialog; + private final String dialogWindowHeader; + /** + * List of ID's of part falling under selected part's hierarchy + */ + private final List idList = new ArrayList(); + /** + * List of corresponding part which maps to idList's elements + */ + private final List partList = new ArrayList(); + private DataBindingManager dataBindingManager; + private final TreeItem treeItem; + + public SetModelTargetAction(String text, DataBindingView view) { + super(view.getSite().getPart()); + setText(text); + Image img = ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_SET_TARGET_ICON); + ImageDescriptor imgDesc = ImageDescriptor.createFromImage(img); + setImageDescriptor(imgDesc); + this.dataBindingView = view; + dialogWindowHeader = text; + combineEditorPart = (CombineEditorPart) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() + .getActiveEditor(); + if (combineEditorPart != null) { + dataBindingManager = combineEditorPart.getDataBindManager(); + } + treeItem = getSelectedTreeItem(); + } + + public void refresh() { + setEnabled(calculateEnabled()); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.action.Action#run() + */ + @Override + public void run() { + // Create dialog window for set target operation + setTargetDialog = new SetModelTargetDialog(Display.getCurrent().getActiveShell()); + // make list of widgets on current page + makeWidgetsList(); + + // update binding view with user entry/update + + if (setTargetDialog.open() != Window.OK) { + return; + } + + String selectedWidgetPropertyName = setTargetDialog.getSelectedWidgetPropertyName(); + Part selectedPart = setTargetDialog.getSelectedPart(); + TreeItem treeItem = getSelectedTreeItem(); + addBindingToTarget(selectedPart, selectedWidgetPropertyName, treeItem); + } + + /** + * Add binding info to binding info viewer model + * + * @param part + * @param widgetName + * Bound UI widget name + * @param treeItem + * treeItem information value + */ + private void addBindingToTarget(Part part, String widgetName, TreeItem treeItem) { + DataBindingManager dataBindManager = combineEditorPart.getDataBindManager(); + DataBindingPage dataBindingPage = (DataBindingPage)dataBindingView.getCurrentPage(); + String path = (String) treeItem.getData("path"); + BindingObject bindingObject = (BindingObject) treeItem.getData("BINDING_OBJECT"); + TreeItemData treeItemData = (TreeItemData) treeItem.getData("TREEITEMDATA"); + String bindingInfoStr = widgetName + ": " + path; + if (dataBindingPage != null && bindingObject != null) { + if (dataBindingPage.checkDuplicatedTableItem(path, widgetName, bindingInfoStr)) { + String itemPath = path.substring(path.indexOf(BuilderConstants.SLASH) + 1); + ComponentPart componentPart = (ComponentPart) part; + String modelName = path.substring(0, path.indexOf(BuilderConstants.SLASH)); + BindingData dataModel = dataBindManager.getDataModelByModelName(modelName); + String allowedBinding = treeItemData.getAllowedBindingType(); + BindingData dataSource = dataBindingPage.getDataSource(treeItemData.getModel().getSourceName()); + if (dataSource != null) { + String sourceType = dataSource.getPropertyValue(BuilderConstants.ATTRIBUTE_SOURCE_TYPE); + DataBindingPartProperty property = new DataBindingPartProperty(modelName, itemPath, bindingObject.getValueType(), allowedBinding, sourceType); + if (dataModel == null || !DataBindingHelper.checkDataBinding(componentPart, property)) { + return; + } + dataBindingPage.setModelTarget(part, dataModel, itemPath, widgetName); + } + } + } + } + + /** + * Make list of widgets on current view. + * + */ + private void makeWidgetsList() { + IPage page = dataBindingView.getCurrentPage(); + if (!(page instanceof DataBindingPage)) { + return; + } + /* DataBindingPage dataBindingPage = (DataBindingPage) page; */ + + idList.clear(); + partList.clear(); + dataBindingManager.getDesignEditor().getViewer().getCurrentViewPart(); + if (dataBindingManager.getDesignViewer() == null) { + // ViewManager not initialized + return; + } + DesignViewer designViewer = dataBindingManager.getDesignViewer(); + // get current page view's data + Part currentViewPart = designViewer.getCurrentViewPart(); + // makeSubWidgetList(currentViewPart.getChildren(), idList, partList); + setTargetDialog.setWidgetContents(currentViewPart); + /* + * for (int i = 0; i < views.size(); i++) { part = + * views.get(i).getRootPart().getChildren(); makeSubWidgetList(part, + * idList, partList); } + */ + } + + private void makeSubWidgetList(List parts, List idList, List partList) { + if (parts.size() == 0) { + return; + } else { + for (int j = 0; j < parts.size(); j++) { + if (parts.get(j).getType() == PartType.COMPONENT) { + idList.add(parts.get(j).getUniqueId()); + partList.add(parts.get(j)); + List subParts = parts.get(j).getChildren(); + makeSubWidgetList(subParts, idList, partList); + } + } + } + } + + private String makePropertyValue(TreeItem treeItem) { + String str = ""; + while (treeItem != null && treeItem.getParentItem() != null) { + if (str.isEmpty()) { + str = treeItem.getText(); + } else { + str = treeItem.getText() + "." + str; + } + treeItem = treeItem.getParentItem(); + } + if(treeItem != null) + str = treeItem.getData("DEFAULTTEXT") + "." + str; + return str; + } + + private TreeItem getSelectedTreeItem() { + DataBindingPage dataBindingPage = (DataBindingPage) getDataBindingPage(); + if (dataBindingPage == null) { + return null; + } + + Tree tree = dataBindingPage.getDataModelTree(); + TreeItem[] treeItem = tree.getSelection(); + + if (treeItem == null || treeItem.length == 0 || (treeItem[0].getParentItem() == null)) { + return null; + } + + // 0 .. multi select + return treeItem[0]; + } + + private IPage getDataBindingPage() { + IPage page = dataBindingView.getCurrentPage(); + if (!(page instanceof DataBindingPage)) { + return null; + } + return page; + } + + @Override + protected boolean calculateEnabled() { + if (dataBindingView == null) { + return false; + } + + if (getSelectedTreeItem() == null) { + return false; + } + + TreeItemData treeItemData = (TreeItemData) getSelectedTreeItem().getData("TREEITEMDATA"); + + if (treeItemData != null && treeItemData.getObjectType() != null + && treeItemData.getObjectType().equals("Object")) { + return false; + } + + return true; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/ShowBindingInfoAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/ShowBindingInfoAction.java new file mode 100644 index 0000000..c40d788 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/actions/ShowBindingInfoAction.java @@ -0,0 +1,84 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + + +package org.tizen.efluibuilder.ui.view.databinding.actions; + +import org.eclipse.gef.ui.actions.SelectionAction; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.tizen.efluibuilder.gef.editparts.DesignEditPart; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingManager; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; +import org.tizen.efluibuilder.ui.view.databinding.utils.ResourceManager; + + +public class ShowBindingInfoAction extends SelectionAction { + + protected DataBindingManager dataBindManager; + + public ShowBindingInfoAction(String text, DataBindingManager dataBindManager) { + super(null); + setText(text); + this.dataBindManager = dataBindManager; + Image img = ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_SHOW_ICON); + ImageDescriptor imgDesc = ImageDescriptor.createFromImage(img); + setImageDescriptor(imgDesc); + setText("show data binding info"); + } + + @Override + protected boolean calculateEnabled() { + // TODO Auto-generated method stub + return true; + } + + public void updateActionImage() { + DesignEditPart currentViewEditPart = dataBindManager.getDesignViewer().getCurrentViewEditPart(); + if (currentViewEditPart == null) { + return; + } + boolean showBindInfo = currentViewEditPart.isBinded(); + Image img = null; + if (showBindInfo) { + img = ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_HIDE_ICON); + setText("hide data binding info"); + } else { + img = ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_SHOW_ICON); + setText("show data binding info"); + } + ImageDescriptor imgDesc = ImageDescriptor.createFromImage(img); + setImageDescriptor(imgDesc); + } + + @Override + public void run() { + DesignEditPart currentViewEditPart = dataBindManager.getDesignViewer().getCurrentViewEditPart(); + if (currentViewEditPart == null) { + return; + } + boolean showBindInfo = currentViewEditPart.isBinded(); + showBindInfo = !showBindInfo; + dataBindManager.getDesignViewer().showBindingInfo(showBindInfo); + updateActionImage(); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/CallHistorySubPage.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/CallHistorySubPage.java new file mode 100644 index 0000000..7e83bbb --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/CallHistorySubPage.java @@ -0,0 +1,321 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + + +package org.tizen.efluibuilder.ui.view.databinding.dialog; + +import java.io.File; +import java.io.FileInputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.resources.IProject; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +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; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingData; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; +import org.tizen.efluibuilder.ui.view.databinding.utils.DataBindingHelper; +import org.tizen.efluibuilder.ui.view.databinding.utils.Helper; +import org.tizen.efluibuilder.ui.view.databinding.utils.ResourceManager; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; + +public class CallHistorySubPage implements SourceDialogSubPage { + + private static final String CALL_HISTORY_PRIVILEGE = "http://tizen.org/privilege/callhistory.read"; +// private SetSourcePage parent; + private Group parentGroup; + private Tree parentDataTree; + private Composite settingComposite; + + private CCombo typeCombo; + private CCombo directionCombo; + private CCombo orderCombo; + private Button loadButton; + + private Label descContents; + private IProject project; + + private static Gson prettyGson; + private static Gson normalGson; + private static String[] typeItems; + private static String[] directionItems; + private static String[] orderItems; + private static List requiredPrivileges; + + static{ + typeItems = new String[]{"ALL", "TELL", "XMPP","SIP"}; + directionItems = new String[] {"ALL", "DIALED", "RECEIVED", "MISSEDNEW", "MISSED", "BLOCKED", "REJECTED" }; + orderItems = new String[] { "DESC", "ASC" }; + prettyGson = new GsonBuilder().setPrettyPrinting().serializeNulls().create(); + normalGson = new GsonBuilder().serializeNulls().create(); + } + + public CallHistorySubPage( SetSourcePage setSourcePage, Group dataGroup, Tree dialogTree, IProject project){ +// parent = setSourcePage; + parentGroup = dataGroup; + parentDataTree = dialogTree; + this.project = project; + } + + @Override + public BindingData getData() { + BindingData dataModel = (BindingData) PartUtil.createPart(PartType.DATASOURCE, LayoutSchemaConstants.DATASOURCE); + + dataModel.setCallHistoryType( typeCombo.getText() ); + dataModel.setCallHistoryDirection( directionCombo.getText() ); + dataModel.setCallHistoryStartTimeOrder( orderCombo.getText() ); + + JsonObject root = new JsonObject(); + TreeItem[] items = parentDataTree.getItems(); + + if( parentDataTree.getItemCount() == 0){ + Event e = new Event(); + e.item = loadButton; + e.widget = loadButton; + e.type = SWT.Selection; + loadButton.notifyListeners(SWT.Selection, e); + } + + for (TreeItem item : items) { + Helper.makeJsonFromTree( item, root); + } + + dataModel.setJsonData( normalGson.toJson(root) ); + //// TODO + ////dataSource.setStaticFilePath(jsonFile); + dataModel.setSourceType(typeCombo.getText().toLowerCase()); + requiredPrivileges = new ArrayList(Arrays.asList(CALL_HISTORY_PRIVILEGE)); + Helper.addPrivileges(settingComposite.getShell(), requiredPrivileges, project); + + return dataModel; + } + + @Override + public Composite getSettingComposite() { + if( settingComposite == null ){ + createSettingComposite(); + } + return settingComposite; + } + + private void createSettingComposite() { + settingComposite = new Composite(parentGroup, SWT.None); + FormLayout layout = new FormLayout(); + + settingComposite.setLayout(layout); + layout.marginWidth = 5; + layout.marginHeight = 5; + FormData data = new FormData(); + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(0, 0); + settingComposite.setLayoutData(data); + + Composite typeComposite = Helper.makeInputCombo(settingComposite, "Type", typeItems ); + + data = new FormData(); + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(100, 0); + typeComposite.setLayoutData(data); + + typeCombo = (CCombo) typeComposite.getData(); + typeCombo.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + int index = typeCombo.getSelectionIndex(); + + String descText = ""; + + switch(index){ + case 0: + descText = ""; + break; + case 1: + descText = "For all protocols with phone number addressing (PSTN, GSM, CDMA, LTE, etc.)"; + break; + case 2: + descText = "For generic XMPP calls."; + break; + case 3: + descText = "For generic SIP calls."; + break; + } + descContents.setText( descText ); + + settingComposite.layout(); + } + }); + + Composite directionComposite = Helper.makeInputCombo(settingComposite, "Direction", directionItems); + directionCombo = (CCombo) directionComposite.getData(); + + data = new FormData(); + data.top = new FormAttachment(typeComposite, 5); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(100, 0); + directionComposite.setLayoutData(data); + + Composite orderComposite = Helper.makeInputCombo(settingComposite, "StartTime Order", orderItems); + orderCombo = (CCombo) orderComposite.getData(); + + data = new FormData(); + data.top = new FormAttachment(directionComposite, 5); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(100, 0); + orderComposite.setLayoutData(data); + + loadButton = new Button(settingComposite, SWT.PUSH | SWT.FLAT); + loadButton.setImage( ResourceManager.getImage( BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_RELOAD_ICON ) ); + loadButton.setToolTipText( "Load" ); + + data = new FormData(29, 29); + data.bottom = new FormAttachment(100, -2); + data.right = new FormAttachment(100, -2); + + loadButton.setLayoutData(data); + final SourceDialogSubPage subPage = this; + loadButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + for( Control control : parentDataTree.getChildren() ){ + control.dispose(); + } + parentDataTree.removeAll(); + + String path = DataBindingHelper.getAbsolutePath( BuilderConstants.DATABINDING_DIR_JSON + "callHistory.json" ); + JsonObject json; + try { + json = Helper.readJsonFromStream( new FileInputStream( new File( path ) ) ); + Helper.makeTreeItem( json, parentDataTree, null, true, subPage); + } catch (Exception e1) { + e1.printStackTrace(); + } + } + }); + + Composite descComposite = new Composite(settingComposite, SWT.NONE ); + descComposite.setLayout(new GridLayout(1, false)); + + data = new FormData(); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(loadButton, -10); + data.bottom = new FormAttachment(100, -20); + + descComposite.setLayoutData(data); + + Label descTitle = new Label(descComposite, SWT.NONE ); + descTitle.setText("Summary"); + FontData[] fD = descTitle.getFont().getFontData(); + fD[0].setHeight(16); + fD[0].setStyle( SWT.BOLD|SWT.UNDERLINE_LINK ); + descTitle.setFont( new Font( Display.getCurrent(), fD[0] ) ); + + descContents = new Label(descComposite, SWT.WRAP ); + + fD = descContents.getFont().getFontData(); + fD[0].setHeight(12); + descContents.setFont( new Font( Display.getCurrent(), fD[0] ) ); + + descContents.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); + } + + @Override + public void setButtonsState(Map dataButtonMap) { + dataButtonMap.get( "addTreeItem" ).setEnabled(false); + dataButtonMap.get( "upTreeItem" ).setEnabled(false); + dataButtonMap.get( "downTreeItem" ).setEnabled(false); + dataButtonMap.get( "removeTreeItem" ).setEnabled(false); + dataButtonMap.get( "removeAllTreeItem" ).setEnabled(false); + Button conversionTreeAndText = dataButtonMap.get("conversionTreeAndText"); + + if( conversionTreeAndText.getSelection() ){ + conversionTreeAndText.setSelection(false); + Event e = new Event(); + e.item = conversionTreeAndText; + e.widget = conversionTreeAndText; + e.type = SWT.Selection; + conversionTreeAndText.notifyListeners(SWT.Selection, e); + } + + conversionTreeAndText.setVisible(false); + } + + @Override + public void loadData(BindingData dataModel) { + int typeIndex = Arrays.asList( typeItems ).indexOf(dataModel.getCallHistoryType() ); + typeCombo.select( typeIndex ); + directionCombo.select( Arrays.asList( directionItems ).indexOf(dataModel.getCallHistoryDirection() ) ); + orderCombo.select( Arrays.asList( orderItems ).indexOf(dataModel.getCallHistoryStartTimeOrder() ) ); + + String descText = ""; + + switch(typeIndex){ + case 0: + descText = ""; + break; + case 1: + descText = "For all protocols with phone number addressing (PSTN, GSM, CDMA, LTE, etc.)"; + break; + case 2: + descText = "For generic XMPP calls."; + break; + case 3: + descText = "For generic SIP calls."; + break; + } + descContents.setText( descText ); + + JsonObject json = prettyGson.fromJson(dataModel.getJsonData(), JsonObject.class ); + Helper.makeTreeItem(json, parentDataTree, null, true, this); + Event e = new Event(); + e.item = loadButton; + e.widget = loadButton; + e.type = SWT.Selection; + loadButton.notifyListeners(SWT.Selection, e); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/ContactSubPage.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/ContactSubPage.java new file mode 100644 index 0000000..46e0584 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/ContactSubPage.java @@ -0,0 +1,320 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + + +package org.tizen.efluibuilder.ui.view.databinding.dialog; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.resources.IProject; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +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; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +////import org.tizen.webuibuilder.BuilderConstants; +////import org.tizen.webuibuilder.ui.views.databinding.model.BindingData; +////import org.tizen.webuibuilder.utility.ResourceManager; +////import org.tizen.webuibuilder.utility.ResourceUtil; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingData; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; +import org.tizen.efluibuilder.ui.view.databinding.utils.DataBindingHelper; +import org.tizen.efluibuilder.ui.view.databinding.utils.Helper; +import org.tizen.efluibuilder.ui.view.databinding.utils.ResourceManager; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; + +public class ContactSubPage implements SourceDialogSubPage { + + private static final String CONTACT_PRIVILEGE = "http://tizen.org/privilege/contact.read"; + +// private SetSourcePage parent; + private Group parentGroup; + private Tree parentDataTree; + private Composite settingComposite; + + private CCombo runtimeApiSettingCombo; + private Composite idComposite; + private Text addressbookID; + private Label descContents; + private Button loadButton; + private IProject project; + + private static Gson prettyGson, normalGson; + private static String[] nameItems; + private List requiredPrivileges; + + static{ + nameItems = new String[] { "ALL", "UNIFIED","DEFAULT", "SELECTED_ADDRESSBOOKID" }; + prettyGson = new GsonBuilder().setPrettyPrinting().serializeNulls().create(); + normalGson = new GsonBuilder().serializeNulls().create(); + } + + public ContactSubPage( SetSourcePage setSourcePage, Group dataGroup, Tree dialogTree, IProject project){ +// parent = setSourcePage; + parentGroup = dataGroup; + parentDataTree = dialogTree; + this.project = project; + } + + @Override + public BindingData getData() { + BindingData dataModel = (BindingData) PartUtil.createPart(PartType.DATASOURCE, LayoutSchemaConstants.DATASOURCE); + + dataModel.setMethod(runtimeApiSettingCombo.getText()); + ////dataModel.setRuntimeApiName( runtimeApiSettingCombo.getText() ); + + if( idComposite.getVisible() ) + dataModel.setRuntimeApiAddressBookID( addressbookID.getText() ); + + if( parentDataTree.getItemCount() == 0){ + Event e = new Event(); + e.item = loadButton; + e.widget = loadButton; + e.type = SWT.Selection; + loadButton.notifyListeners(SWT.Selection, e); + } + + JsonObject root = new JsonObject(); + TreeItem[] items = parentDataTree.getItems(); + for (TreeItem item : items) { + Helper.makeJsonFromTree( item, root); + } + + dataModel.setJsonData( normalGson.toJson(root) ); + requiredPrivileges = new ArrayList(Arrays.asList(CONTACT_PRIVILEGE)); + Helper.addPrivileges(settingComposite.getShell(), requiredPrivileges, project ); + + return dataModel; + } + + @Override + public Composite getSettingComposite() { + if( settingComposite == null ){ + createSettingComposite(); + } + return settingComposite; + } + + private void createSettingComposite() { + settingComposite = new Composite(parentGroup, SWT.None); + FormLayout layout = new FormLayout(); + + settingComposite.setLayout(layout); + layout.marginWidth = 5; + layout.marginHeight = 5; + FormData data = new FormData(); + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(0, 0); + settingComposite.setLayoutData(data); + + Composite apiComposite = Helper.makeInputCombo(settingComposite, "AddressBook Type", nameItems); + + data = new FormData(); + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(100, 0); + apiComposite.setLayoutData(data); + + runtimeApiSettingCombo = (CCombo) apiComposite.getData(); + runtimeApiSettingCombo.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + boolean isVisible = false; + int index = runtimeApiSettingCombo.getSelectionIndex(); + if( index == 3 ) + isVisible = true; + + idComposite.setVisible(isVisible); + String descText = ""; + + switch(index){ + case 0: + descText = "Gets the available address books."; + break; + case 1: + descText = "Gets the aggregation of all address books."; + break; + case 2: + descText = "Gets the default address book."; + break; + case 3: + descText = "Gets the address book with the specified identifier."; + break; + } + descContents.setText( descText ); + } + }); + + idComposite = Helper.makeInputText(settingComposite, "Addressbook ID"); + addressbookID = (Text) idComposite.getData(); + + idComposite.setVisible( false ); + + data = new FormData(); + data.top = new FormAttachment(apiComposite, 5); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(100, 0); + idComposite.setLayoutData(data); + + loadButton = new Button(settingComposite, SWT.PUSH | SWT.FLAT); + loadButton.setImage( ResourceManager.getImage( BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_RELOAD_ICON ) ); + loadButton.setToolTipText( "Load" ); + + data = new FormData(29, 29); + data.bottom = new FormAttachment(100, -2); + data.right = new FormAttachment(100, -2); + + loadButton.setLayoutData(data); + final SourceDialogSubPage subPage = this; + loadButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + for( Control control : parentDataTree.getChildren() ){ + control.dispose(); + } + parentDataTree.removeAll(); + + String path = DataBindingHelper.getAbsolutePath( BuilderConstants.DATABINDING_DIR_JSON + "contact.json" ); + JsonObject json; + try { + json = Helper.readJsonFromStream( new FileInputStream( new File( path ) ) ); + Helper.makeTreeItem( json, parentDataTree, null, true, subPage); + } catch (FileNotFoundException e1) { + e1.printStackTrace(); + } + } + }); + + Composite descComposite = new Composite(settingComposite, SWT.NONE ); + descComposite.setLayout(new GridLayout(1, false)); + + data = new FormData(); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(loadButton, -10); + data.bottom = new FormAttachment(100, -20); + + descComposite.setLayoutData(data); + + Label descTitle = new Label(descComposite, SWT.NONE ); + descTitle.setText("Summary"); + FontData[] fD = descTitle.getFont().getFontData(); + fD[0].setHeight(16); + fD[0].setStyle( SWT.BOLD|SWT.UNDERLINE_LINK ); + descTitle.setFont( new Font( Display.getCurrent(), fD[0] ) ); + + descContents = new Label(descComposite, SWT.WRAP ); + descContents.setText("Gets the available address books."); + fD = descContents.getFont().getFontData(); + fD[0].setHeight(12); + descContents.setFont( new Font( Display.getCurrent(), fD[0] ) ); + + descContents.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); + } + + @Override + public void setButtonsState(Map dataButtonMap) { + dataButtonMap.get( "addTreeItem" ).setEnabled(false); + dataButtonMap.get( "upTreeItem" ).setEnabled(false); + dataButtonMap.get( "downTreeItem" ).setEnabled(false); + dataButtonMap.get( "removeTreeItem" ).setEnabled(false); + dataButtonMap.get( "removeAllTreeItem" ).setEnabled(false); + Button conversionTreeAndText = dataButtonMap.get("conversionTreeAndText"); + + if( conversionTreeAndText.getSelection() ){ + conversionTreeAndText.setSelection(false); + Event e = new Event(); + e.item = conversionTreeAndText; + e.widget = conversionTreeAndText; + e.type = SWT.Selection; + conversionTreeAndText.notifyListeners(SWT.Selection, e); + } + + conversionTreeAndText.setVisible(false); + } + + @Override + public void loadData(BindingData dataModel) { + int index = Arrays.asList(nameItems).indexOf(dataModel.getRuntimeApiName()); + runtimeApiSettingCombo.select( index ); + + if( index == 3 ){ + idComposite.setVisible(true); + addressbookID.setText(dataModel.getRuntimeApiAddressBookID()); + } + + String descText = ""; + + switch(index){ + case 0: + descText = "Gets the available address books."; + break; + case 1: + descText = "Gets the aggregation of all address books."; + break; + case 2: + descText = "Gets the default address book."; + break; + case 3: + descText = "Gets the address book with the specified identifier."; + break; + } + + descContents.setText( descText ); + +// JsonObject json = gson.fromJson(dataModel.getJsonData(), JsonObject.class ); +// Helper.makeTreeItem(json, parentDataTree, null, false, this); + + Event e = new Event(); + e.item = loadButton; + e.widget = loadButton; + e.type = SWT.Selection; + loadButton.notifyListeners(SWT.Selection, e); + } + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/DataBindingFilterDialog.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/DataBindingFilterDialog.java new file mode 100644 index 0000000..1bbfb5b --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/DataBindingFilterDialog.java @@ -0,0 +1,509 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.dialog; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.fieldassist.ControlDecoration; +import org.eclipse.jface.fieldassist.FieldDecoration; +import org.eclipse.jface.fieldassist.FieldDecorationRegistry; +import org.eclipse.jface.layout.TableColumnLayout; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.ColumnWeightData; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.jface.viewers.ViewerCell; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.TableEditor; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +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.Table; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingData; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingObject; +import org.tizen.efluibuilder.ui.view.databinding.model.DataBindingPartProperty; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; +import org.tizen.efluibuilder.ui.view.databinding.utils.ResourceManager; + +public class DataBindingFilterDialog extends Dialog { + + private static final String FILTER_MSG = "This {0} supports \"{1}\" binding. Apply atleast {2} filters. \n (Each Level filtering should result in one Object.)"; + private static final String HEADER = "(L{0}) {1}"; + private static final String ERROR_MSG = "Enter valid data!"; + private static final String DIALOG_HEADER = "Apply filter"; + + private final Color WHITE_COLOR = new Color(null, 255, 255, 255); + + private DataBindingPartProperty property; + + private Composite container; + + private String filterPath; + private String widgetName; + private String bindingType; + private String modelName; + private int defaultLevel; + private HashMap> filterMap = new HashMap>(); + private List filterPathItems; + private int level = 1; + + public DataBindingFilterDialog(Shell parent, DataBindingPartProperty property, int defaultLevel, String widgetName, String bindingType) { + super(parent); + this.property = property; + this.defaultLevel = defaultLevel; + this.widgetName = widgetName; + this.bindingType = bindingType; + this.modelName = property.getModelName(); + } + + @Override + protected Control createDialogArea(Composite parent) { + + Composite composite = new Composite(parent, SWT.NONE); + composite.setBackground(WHITE_COLOR); + composite.setLayout(new GridLayout()); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + + Label label = new Label(composite, SWT.NONE | SWT.BOLD); + label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + label.setBackground(WHITE_COLOR); + label.setText(MessageFormat.format(FILTER_MSG, widgetName, bindingType, defaultLevel)); + + GridLayout gridLayout = new GridLayout(); + gridLayout.numColumns = 2; + gridLayout.makeColumnsEqualWidth = true; + gridLayout.horizontalSpacing = 10; + gridLayout.verticalSpacing = 10; + gridLayout.marginLeft = 5; + gridLayout.marginRight = 5; + container = new Composite(parent, SWT.NONE); + container.setLayout(gridLayout); + container.setBackground(WHITE_COLOR); + GridData compositegridData = new GridData(SWT.FILL, SWT.FILL, true, true); + compositegridData.heightHint = SWT.DEFAULT; + container.setLayoutData(compositegridData); + + IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if (workbenchWindow == null) { + return null; + } + IWorkbenchPage activePage = workbenchWindow.getActivePage(); + if (activePage == null) { + return null; + } + CombineEditorPart combineEditorPart = (CombineEditorPart) activePage.getActiveEditor(); + BindingData bindingData = null; + if (combineEditorPart != null) { + bindingData = combineEditorPart.getDataBindManager().getDataModelByModelName(modelName); + } + filterPathItems = Arrays.asList(property.getViewItemName().replaceAll(BuilderConstants.ARRAY_REGEX, BuilderConstants.EMPTY).split(BuilderConstants.SLASH_REGEX)); + if (bindingData != null) { + if (property.getSourceType().equals(BuilderConstants.JSON)) { + createFilters(bindingData.getBindingObjects(), null, 1, modelName + BuilderConstants.SLASH + "root"); + } else { + createFilters(bindingData.getBindingObjects(), null, 0, modelName); + } + } + return composite; + } + + @Override + protected void okPressed() { + List items = Arrays.asList((property.getViewItemName()).split(BuilderConstants.SLASH_REGEX)); + StringBuilder path = new StringBuilder(modelName); + for (Entry> entry : filterMap.entrySet()) { + int index = 1; + StringBuilder arrayValue = new StringBuilder(BuilderConstants.OPEN_SQUARE_BRACKET); + for (Entry map : entry.getValue().entrySet()) { + + arrayValue.append(map.getKey()).append(BuilderConstants.EQUAL).append(BuilderConstants.APOSTROPHE_MARK).append(map.getValue()).append(BuilderConstants.APOSTROPHE_MARK); + + if (entry.getValue().size() > 1 && entry.getValue().size() != index) { + arrayValue.append(" and "); + } + index++; + } + arrayValue.append(BuilderConstants.CLOSE_SQUARE_BRACKET); + String[] str = entry.getKey().split(BuilderConstants.SLASH_REGEX); + String item = items.get(str.length - 2).replaceAll(BuilderConstants.ARRAY_REGEX, arrayValue.toString()); + items.set(str.length - 2, item); + } + for (String item : items) { + path = path.append(BuilderConstants.SLASH).append(item); + } + setFilterPath(path.toString()); + super.okPressed(); + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText(DIALOG_HEADER); + } + + @Override + protected void createButtonsForButtonBar(Composite parent) { + super.createButtonsForButtonBar(parent); + Button ok = getButton(IDialogConstants.OK_ID); + if (ok != null) { + ok.setEnabled(false); + ok.setFocus(); + } + } + + private void createFilters(List list, String parent, int index, String path) { + if ((list == null) || (list.isEmpty())) { + return; + } + for (BindingObject observableObject : list) { + if (observableObject.getName() == null || observableObject.getName().isEmpty()) + continue; + if (observableObject.getValueType().equals(BuilderConstants.ARRAY) && observableObject.getName().equals(filterPathItems.get(index))) { + List firstChildList = new ArrayList(); + firstChildList.add(observableObject.getBindingObjects().get(0)); + createFilters(firstChildList, observableObject.getName(), index, (path + BuilderConstants.SLASH + filterPathItems.get(index))); + } else if (observableObject.getValueType().equals(BuilderConstants.INDEX)) { + List ComboItems = new ArrayList(); + ComboItems.add(new CustumTableItem(parent, BuilderConstants.EMPTY)); + if (!ComboItems.isEmpty()) { + createDropDownComposite(container, ComboItems.toArray(new CustumTableItem[ComboItems.size()]), path, true); + } + } else if (observableObject.getValueType().equals(BuilderConstants.INDEXOBJECT)) { + List ComboItems = new ArrayList(); + for (BindingObject bindingObject : observableObject.getBindingObjects()) { + if (bindingObject.getValueType().equals(BuilderConstants.STRING) || bindingObject.getValueType().equals(BuilderConstants.NUMBER) + || bindingObject.getValueType().equals(BuilderConstants.BOOLEAN)) + ComboItems.add(new CustumTableItem(bindingObject.getName(), bindingObject.getValueType())); + } + if (!ComboItems.isEmpty()) { + createDropDownComposite(container, ComboItems.toArray(new CustumTableItem[ComboItems.size()]), path, false); + } + createFilters(observableObject.getBindingObjects(), parent, index + 1, path); + } else if (observableObject.getValueType().equals(BuilderConstants.OBJECT) && observableObject.getName().equals(filterPathItems.get(index))) { + createFilters(observableObject.getBindingObjects(), parent, index + 1, (path + BuilderConstants.SLASH + filterPathItems.get(index))); + } + } + } + + private static class CustumTableItem { + String value; + String type; + + public String getValue() { + return value; + } + + public String getType() { + return type; + } + + public CustumTableItem(String value, String type) { + super(); + this.value = value; + this.type = type; + } + } + + private void createDropDownComposite(Composite parent, CustumTableItem[] items, final String labelStr, final Boolean isPrimitiveArray) { + + Composite composite = new Composite(parent, SWT.BORDER); + composite.setLayout(new GridLayout(1, true)); + GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); + gridData.widthHint = 250; + gridData.heightHint = SWT.DEFAULT; + composite.setBackground(WHITE_COLOR); + composite.setLayoutData(gridData); + + // Filter Path + Label label = new Label(composite, SWT.WRAP | SWT.CENTER); + label.setBackground(WHITE_COLOR); + label.setText(MessageFormat.format(HEADER, level++, labelStr)); + gridData = new GridData(SWT.FILL, SWT.FILL, true, false); + gridData.widthHint = SWT.DEFAULT; + gridData.heightHint = SWT.DEFAULT; + label.setLayoutData(gridData); + + Composite tableComposite = new Composite(composite, SWT.NONE); + TableColumnLayout tableColumnLayout = new TableColumnLayout(); + tableComposite.setLayout(tableColumnLayout); + gridData = new GridData(SWT.FILL, SWT.FILL, true, false); + gridData.widthHint = SWT.DEFAULT; + gridData.heightHint = 120; + tableComposite.setLayoutData(gridData); + + // Filter Options + final TableViewer viewer = new TableViewer(tableComposite, SWT.BORDER | SWT.FULL_SELECTION); + TableViewerColumn imageCol = new TableViewerColumn(viewer, SWT.NONE); + imageCol.getColumn().setWidth(75); + imageCol.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + if (element instanceof CustumTableItem) { + CustumTableItem current = (CustumTableItem) element; + return current.getValue(); + } + return super.getText(element); + } + + @Override + public Image getImage(Object element) { + if (element instanceof CustumTableItem) { + CustumTableItem current = (CustumTableItem) element; + if (current.getType().equals(BuilderConstants.STRING)) { + return ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_STRING_ICON); + } else if (current.getType().equals(BuilderConstants.NUMBER)) { + return ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_NUMBER_ICON); + } else if (current.getType().equals(BuilderConstants.BOOLEAN)) { + return ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_BOOLEAN_ICON); + } + } + return super.getImage(element); + } + }); + TableViewerColumn inputBox = new TableViewerColumn(viewer, SWT.NONE); + inputBox.setLabelProvider(new ColumnLabelProvider() { + @Override + public void update(ViewerCell cell) { + cell.setText(BuilderConstants.EMPTY); + } + + }); + inputBox.getColumn().setWidth(75); + final Table table = viewer.getTable(); + table.setLinesVisible(true); + final TableEditor editor = new TableEditor(table); + editor.horizontalAlignment = SWT.LEFT; + editor.grabHorizontal = true; + editor.minimumWidth = 50; + final int EDITABLECOLUMNINDEX = 1; + table.addListener(SWT.MeasureItem, new Listener() { + + @Override + public void handleEvent(Event e) { + e.height = 30; + } + }); + table.addSelectionListener(new SelectionListener() { + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + Control oldEditor = editor.getEditor(); + if (oldEditor != null) + oldEditor.dispose(); + + final TableItem item = (TableItem) e.item; + if (item == null) + return; + + IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); + CustumTableItem tItem = (CustumTableItem) selection.getFirstElement(); + final String type = tItem.getType(); + + if (!type.equals(BuilderConstants.BOOLEAN)) { + final Text newEditor = new Text(table, SWT.BORDER); + newEditor.setText(item.getText(EDITABLECOLUMNINDEX)); + + final ControlDecoration txtDecorator = new ControlDecoration(newEditor, SWT.TOP | SWT.LEFT); + FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR); + Image img = null; + if(fieldDecoration != null) + img = fieldDecoration.getImage(); + txtDecorator.setImage(img); + txtDecorator.setDescriptionText(ERROR_MSG); + txtDecorator.hide(); + + newEditor.addFocusListener(new FocusListener() { + + @Override + public void focusLost(FocusEvent e) { + if (!validate(type, newEditor.getText())) { + newEditor.setText(BuilderConstants.EMPTY); + } + newEditor.dispose(); + } + + @Override + public void focusGained(FocusEvent e) { + } + }); + newEditor.addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent arg0) { + String string = newEditor.getText(); + editor.getItem().setText(EDITABLECOLUMNINDEX, string); + boolean isValid = false; + if (!isPrimitiveArray) { + isValid = validate(type, string); + if (isValid) { + txtDecorator.hide(); + updateMap(labelStr, string, item, isPrimitiveArray); + } else { + txtDecorator.show(); + } + } else { + isValid = true; + updateMap(labelStr, string, item, isPrimitiveArray); + } + + Button ok = getButton(IDialogConstants.OK_ID); + if (filterMap.size() >= defaultLevel && isValid) { + ok.setEnabled(true); + } else { + ok.setEnabled(false); + } + + } + }); + newEditor.selectAll(); + newEditor.setFocus(); + editor.setEditor(newEditor, item, EDITABLECOLUMNINDEX); + } else { + final Combo combo = new Combo(table, SWT.NONE | SWT.READ_ONLY); + combo.setItems(new String[] { BuilderConstants.EMPTY, BuilderConstants.TRUE, BuilderConstants.FALSE }); + combo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Combo newcombo = combo; + editor.getItem().setText(EDITABLECOLUMNINDEX, newcombo.getText()); + updateMap(labelStr, combo.getItem(combo.getSelectionIndex()), item, isPrimitiveArray); + Button ok = getButton(IDialogConstants.OK_ID); + if (filterMap.size() >= defaultLevel) { + ok.setEnabled(true); + } else { + ok.setEnabled(false); + } + } + + }); + combo.addFocusListener(new FocusListener() { + + @Override + public void focusLost(FocusEvent e) { + combo.dispose(); + } + + @Override + public void focusGained(FocusEvent e) { + + } + }); + combo.setFocus(); + editor.setEditor(combo, item, EDITABLECOLUMNINDEX); + } + } + + @Override + public void widgetSelected(SelectionEvent e) { + widgetDefaultSelected(e); + } + }); + viewer.setContentProvider(new ArrayContentProvider()); + viewer.setInput(items); + viewer.setSelection(new StructuredSelection(viewer.getElementAt(0)), true); + tableColumnLayout.setColumnData(imageCol.getColumn(), new ColumnWeightData(1, true)); + tableColumnLayout.setColumnData(inputBox.getColumn(), new ColumnWeightData(1, true)); + } + + private void updateMap(String labelStr, String text, TableItem item, boolean isPrimitiveArray) { + HashMap map = new HashMap(); + for (Entry> entry : filterMap.entrySet()) { + if (entry.getKey().equals(labelStr)) { + map = entry.getValue(); + } + } + if (text.isEmpty()) { + map.remove(item.getText(0)); + if (map.size() == 0) { + filterMap.remove(labelStr); + } else { + filterMap.put(labelStr, map); + } + } else { + if (isPrimitiveArray) { + map.put(BuilderConstants.AT, text); + } else { + map.put(item.getText(0), text); + } + filterMap.put(labelStr, map); + } + } + + private boolean validate(String type, String value) { + boolean flag = false; + if (value == null || value.isEmpty()) { + flag = true; + } else if (type.equals(BuilderConstants.NUMBER)) { + try { + Integer.parseInt(value); + flag = true; + } catch (NumberFormatException ex) { + + } + } else if (type.equals(BuilderConstants.STRING)) { + flag = true; + } + return flag; + } + + public String getFilterPath() { + return filterPath; + } + + public void setFilterPath(String filterPath) { + this.filterPath = filterPath; + } + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/Helper.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/Helper.java new file mode 100644 index 0000000..4f1cd6f --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/Helper.java @@ -0,0 +1,530 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.dialog; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.StringReader; +import java.math.BigDecimal; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.HashMap; +import java.util.Map.Entry; +import java.util.Set; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.tizen.efluibuilder.ui.view.databinding.model.TreeItemData; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; + +public class Helper { + + private enum DataType { + OBJECT, ARRAY, PRIMITIVE + } + + private static final String xmlConvertAttrPrifix = ""; + private static final String xmlConvertTextPrifix = ""; + private static final String xmlConvertTextName = "text"; + + private static Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls().create(); + + public static String callURL(String url, String method, TableItem[] items) { + BufferedReader br = null; + OutputStreamWriter writer = null; + try { + + HttpURLConnection con = null; + if (method.equals("GET")) { + String delimiter = "?"; + if (url.contains("?")) { + delimiter = "&"; + } + con = (HttpURLConnection) new URL(url + delimiter + getParamString(items).toString()).openConnection(); + } else { + con = (HttpURLConnection) new URL(url).openConnection(); + con.setDoOutput(true); + writer = new OutputStreamWriter(con.getOutputStream()); + writer.write(getParamString(items).toString()); + writer.flush(); + } + + for (TableItem item : items) { + if (item.getText(0).equals("header")) { + con.setRequestProperty(item.getText(1), item.getText(2)); + } + } + + con.setRequestMethod(method); + con.setDoInput(true); + + if (con.getResponseCode() != 200) { + return null; + } + + br = new BufferedReader(new InputStreamReader(con.getInputStream())); + + String line = null; + StringBuilder sb = new StringBuilder(); + + while ((line = br.readLine()) != null) { + sb.append(line); + } + + if (writer != null) { + writer.close(); + writer = null; + } + br.close(); + br = null; + + return sb.toString(); + } catch (Exception e) { + e.printStackTrace(); + return null; + } finally { + try { + if (br != null) + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + try { + if (writer != null) + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + public static JsonObject readJsonFromStream(InputStream is) { + BufferedReader br = null; + JsonObject result = null; + try { + br = new BufferedReader(new InputStreamReader(is)); + result = gson.fromJson(br, JsonObject.class); + br.close(); + br = null; + } catch (IOException e) { + e.printStackTrace(); + return null; + } finally { + try { + if (br != null) + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + return result; + } + + public static void makeTreeItem(JsonElement jsonElement, Tree tree, TreeItem item, boolean includeIndex) { + if (jsonElement.isJsonArray()) { + JsonArray array = jsonElement.getAsJsonArray(); + + for (int i = 0; i < array.size(); i++) { + if (includeIndex) { + TreeItem indexItem = new TreeItem(item, 0); + careteTreeItem(indexItem, String.valueOf(i), null, "Index"); + makeTreeItem(array.get(i), tree, indexItem, includeIndex); + indexItem.setExpanded(true); + } else { + makeTreeItem(array.get(i), tree, item, includeIndex); + break; + } + } + } else if (jsonElement.isJsonObject()) { + + JsonObject jb = jsonElement.getAsJsonObject(); + Set> entrys = jb.entrySet(); + for (Entry entry : entrys) { + + TreeItem treeItem = null; + if (item == null) { + treeItem = new TreeItem(tree, 0); + } else { + treeItem = new TreeItem(item, 0); + } + + if (entry.getValue().isJsonPrimitive()) { + JsonPrimitive jp = entry.getValue().getAsJsonPrimitive(); + String type = null; + if (jp.isBoolean()) + type = "Boolean"; + else if (jp.isNumber()) + type = "Number"; + else if (jp.isString()) + type = "String"; + + careteTreeItem(treeItem, entry.getKey(), jp.getAsString(), type); + } else if (entry.getValue().isJsonObject()) { + careteTreeItem(treeItem, entry.getKey(), null, "Object"); + makeTreeItem(entry.getValue(), tree, treeItem, includeIndex); + } else if (entry.getValue().isJsonArray()) { + careteTreeItem(treeItem, entry.getKey(), null, "Array"); + makeTreeItem(entry.getValue(), tree, treeItem, includeIndex); + } else if (entry.getValue().isJsonNull()) { + careteTreeItem(treeItem, entry.getKey(), null, "undefined"); + makeTreeItem(entry.getValue(), tree, treeItem, includeIndex); + } + treeItem.setExpanded(true); + } + return; + } else if (jsonElement.isJsonPrimitive()) { + JsonPrimitive jp = jsonElement.getAsJsonPrimitive(); + String type = null; + if (jp.isBoolean()) { + type = "Boolean"; + } else if (jp.isNumber()) { + type = "Number"; + } else if (jp.isString()) { + type = "String"; + } + + if (item.getParent().getColumnCount() > 0) { + Helper.careteTreeItem(new TreeItem(item, 0), null, jp.getAsString(), type); + } + } + } + + private static TreeItem careteTreeItem(TreeItem treeItem, String key, String value, String type) { + + TreeItemData treeItemData = new TreeItemData(); + + if (treeItem.getParent().getColumnCount() == 1) { + treeItem.setText(key); + } else { + treeItem.setText(new String[] { key, value, type }); + } + + treeItemData.setObjectType(type); + treeItemData.setObjectValue(value); + treeItemData.setSource("original"); + + treeItem.setData("TREEITEMDATA", treeItemData); + + //String imageName = null; + + //if (type.equals("Array")) { + // imageName = "temp.png"; + //} + // TODO:FIXME + // if ( imageName != null ) { + // treeItem.setImage( ResourceManager.getImage( + // BuilderConstants.ICON_DIR, imageName ) ); + // } + + return treeItem; + } + + public static void makeJsonFromTree(TreeItem parentItem, JsonElement parentJsonElement) { + String key = parentItem.getText(0); + String value = parentItem.getText(1); + String type = parentItem.getText(2); + + TreeItem[] items = parentItem.getItems(); + + JsonObject jsonOb = null; + + if (type.equals("Array")) { + JsonArray array = new JsonArray(); + ((JsonObject) parentJsonElement).add(key, array); + jsonOb = null; + for (TreeItem item : items) { + if (item.getText(2).equals("Index")) { + makeJsonFromTree(item, array); + } else { + if (jsonOb == null) { + jsonOb = new JsonObject(); + array.add(jsonOb); + } + makeJsonFromTree(item, jsonOb); + } + } + } else if (type.equals("Object")) { + jsonOb = new JsonObject(); + ((JsonObject) parentJsonElement).add(key, jsonOb); + for (TreeItem item : items) { + makeJsonFromTree(item, jsonOb); + } + } else if (type.equals("Index")) { + jsonOb = new JsonObject(); + for (TreeItem item : items) { + if (item.getText().length() > 0) { + makeJsonFromTree(item, jsonOb); + } else { + ((JsonArray) parentJsonElement).add(new JsonPrimitive(item.getText(1))); + } + } + if (!jsonOb.entrySet().isEmpty()) + ((JsonArray) parentJsonElement).add(jsonOb); + } else if (type.equals("String")) { + ((JsonObject) parentJsonElement).addProperty(key, value); + } else if (type.equals("Boolean")) { + ((JsonObject) parentJsonElement).addProperty(key, Boolean.valueOf(value)); + } else if (type.equals("Number")) { + ((JsonObject) parentJsonElement).addProperty(key, new BigDecimal(value)); + } else { + ((JsonObject) parentJsonElement).add(key, null); + } + } + + public static Composite makeInputText(Composite parentComposite, String title) { + + Composite subComposite = new Composite(parentComposite, SWT.NONE); + FormLayout layout = new FormLayout(); + subComposite.setLayout(layout); + + Label label = new Label(subComposite, SWT.NONE); + label.setText(title); + FormData data = new FormData(); + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(0, 0); + label.setLayoutData(data); + + Text text = new Text(subComposite, SWT.SINGLE | SWT.BORDER); + data = new FormData(); + data.top = new FormAttachment(label, 0); + data.left = new FormAttachment(10, 0); + data.right = new FormAttachment(100, 0); + text.setLayoutData(data); + subComposite.setData(text); + return subComposite; + } + + public static Composite makeInputCombo(Composite parentComposite, String title, String[] items) { + + Composite subComposite = new Composite(parentComposite, SWT.NONE); + FormLayout layout = new FormLayout(); + subComposite.setLayout(layout); + + Label label = new Label(subComposite, SWT.NONE); + label.setText(title); + FormData data = new FormData(); + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(0, 0); + label.setLayoutData(data); + + CCombo combo = new CCombo(subComposite, SWT.SINGLE | SWT.BORDER | SWT.FLAT | SWT.READ_ONLY); + data = new FormData(); + data.top = new FormAttachment(label, 0); + data.left = new FormAttachment(10, 0); + data.right = new FormAttachment(100, 0); + combo.setLayoutData(data); + combo.setItems(items); + combo.select(0); + + subComposite.setData(combo); + + return subComposite; + } + + public static String getParamString(TableItem[] items) { + StringBuilder query = new StringBuilder(); + boolean isFirst = true; + + for (TableItem item : items) { + + if (item.getText(0).equals("query")) { + if (isFirst) { + isFirst = false; + } else { + query.append("&"); + } + + query.append(item.getText(1)).append("=").append(item.getText(2)); + } + } + + return query.toString(); + } + + public static JsonObject getJsonByScript(String xml) { + String jsonString = null; + + return gson.fromJson(jsonString, JsonObject.class); + } + + public static JsonObject getJsonFromXML(String xml) { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db; + Document doc = null; + try { + InputSource inStream = new InputSource(); + inStream.setCharacterStream(new StringReader(xml)); + db = dbf.newDocumentBuilder(); + doc = db.parse(inStream); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + } catch (SAXException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + JsonObject root = new JsonObject(); + + if (doc != null) { + NodeList nodeList = doc.getChildNodes(); + parseNodeList(root, nodeList); + } + + return root; + } + + /** + * @param json + * @param nodeList + */ + private static void parseNodeList(JsonObject parentJson, NodeList nodeList) { + HashMap meta = createMetaData(nodeList); + HashMap arrayParents = new HashMap(); + + for (int i = 0; i < nodeList.getLength(); i++) { + + Node node = nodeList.item(i); + JsonObject jsonOb = null; + + DataType type = meta.get(node.getNodeName()); + + if (type == DataType.ARRAY) { + + Node parentNode = node.getParentNode(); + String nodePath = parentNode.getNodeName() + "/" + node.getNodeName(); + + while ((parentNode = parentNode.getParentNode()) != null) { + nodePath = parentNode.getNodeName() + "/" + nodePath; + } + + JsonArray parentArray = null; + + if ((parentArray = arrayParents.get(nodePath)) == null) { + parentArray = new JsonArray(); + parentJson.add(node.getNodeName(), parentArray); + arrayParents.put(nodePath, parentArray); + } + + if (node.getChildNodes().getLength() == 1 && node.getFirstChild().getNodeType() == Node.TEXT_NODE) { + parentArray.add(new JsonPrimitive(node.getFirstChild().getTextContent())); + } else { + jsonOb = new JsonObject(); + parentArray.add(jsonOb); + + parseNodeList(jsonOb, node.getChildNodes()); + addAttributes(jsonOb, node); + } + + } else if (type == DataType.OBJECT) { + jsonOb = new JsonObject(); + parentJson.add(node.getNodeName(), jsonOb); + + parseNodeList(jsonOb, node.getChildNodes()); + addAttributes(jsonOb, node); + } else if (type == DataType.PRIMITIVE) { + if (node.getFirstChild() != null) + parentJson.addProperty(node.getNodeName(), node.getFirstChild().getTextContent()); + else + parentJson.add(node.getNodeName(), null); + } + } + } + + /** + * @param jsonOb + * @param node + */ + private static void addAttributes(JsonObject jsonOb, Node node) { + boolean isExistAttr = false; + + for (int j = 0; j < node.getAttributes().getLength(); j++) { + Node attNode = node.getAttributes().item(j); + jsonOb.addProperty(xmlConvertAttrPrifix + attNode.getNodeName(), attNode.getNodeValue()); + isExistAttr = true; + } + + String textNodeName = xmlConvertTextName; + if (isExistAttr) + textNodeName = xmlConvertTextPrifix + textNodeName; + + if (node.getFirstChild() != null && node.getFirstChild().getNodeType() == Node.TEXT_NODE + && node.getFirstChild().getTextContent().trim().length() != 0) { + jsonOb.addProperty(textNodeName, node.getFirstChild().getTextContent()); + } + } + + /** + * @param nodeList + * @return + */ + private static HashMap createMetaData(NodeList nodeList) { + HashMap result = new HashMap(); + for (int i = 0; i < nodeList.getLength(); i++) { + Node node = nodeList.item(i); + + if (node.getNodeType() != Node.ELEMENT_NODE) { + continue; + } + + DataType type = result.get(node.getNodeName()); + + if (type != null) { + result.put(node.getNodeName(), DataType.ARRAY); + } else if (node.getChildNodes().getLength() <= 1 && node.getAttributes().getLength() == 0) { + result.put(node.getNodeName(), DataType.PRIMITIVE); + } else { + result.put(node.getNodeName(), DataType.OBJECT); + } + } + return result; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/RemoteCallSubPage.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/RemoteCallSubPage.java new file mode 100644 index 0000000..78ebb30 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/RemoteCallSubPage.java @@ -0,0 +1,829 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.dialog; + +import java.net.MalformedURLException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.core.resources.IProject; +import org.eclipse.jface.layout.TableColumnLayout; +import org.eclipse.jface.viewers.ColumnWeightData; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.custom.TableEditor; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Cursor; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +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.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingData; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; +import org.tizen.efluibuilder.ui.view.databinding.utils.Helper; +import org.tizen.efluibuilder.ui.view.databinding.utils.ResourceManager; +import org.xml.sax.SAXException; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +public class RemoteCallSubPage implements SourceDialogSubPage { + + private static final String INTERNET_PRIVILEGE = "http://tizen.org/privilege/internet"; + private static final String DOWNLOAD_PRIVILEGE = "http://tizen.org/privilege/download"; + private static final String NETWORK_PRIVILEGE = "http://tizen.org/privilege/network.get"; + + private IProject project; + private SetSourcePage parent; + + private Composite settingComposite; + private Composite pollIntervalComposite; + private CCombo methodSettingCombo; + private CCombo proxySettingCombo; + private CCombo sourceTypeCombo; + private Group parentGroup; + private StyledText remoteSourceStyledText; + private Table requestParam; + private Text urlText; + private Text timeoutText; + private Text pollIntervalText; + private Tree parentDataTree; + private Button poll; + private Button push; + private Button staticButton; + + private BindingData temp; + + private static Gson gson; + + private static String[] SoureTypes; + private static List requiredPrivileges; + + static { + SoureTypes = new String[] { "JSON", "XML" }; + gson = new GsonBuilder().serializeNulls().create(); + } + + private SelectionAdapter loadEvent = new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + // enqueue a given Runnable for execution on the UI thread + parentDataTree.getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + + if (parent.isDataModelDirty()) { + MessageBox messageBox = new MessageBox(remoteSourceStyledText.getShell(), SWT.ICON_WARNING | SWT.OK | SWT.CANCEL); + messageBox.setText("Set Source Warning"); + messageBox.setMessage("Warning : Modified Data Model is lost. Do you want to continue?"); + int result = messageBox.open(); + + if (result != SWT.OK) { + loadData(temp); + return; + } + } + + parentDataTree.getShell().setCursor(new Cursor(Display.getCurrent(), SWT.CURSOR_WAIT)); + + for (Control control : parentDataTree.getChildren()) { + control.dispose(); + } + parentDataTree.removeAll(); + try { + createDataSource(); + } catch (Exception e) { + MessageBox messageBox = new MessageBox(remoteSourceStyledText.getShell(), SWT.ICON_ERROR); + messageBox.setText("Set Source Error"); + messageBox.setMessage("Error occured while retrieving the data."); + messageBox.open(); + return; + } + + parentDataTree.getShell().setCursor(new Cursor(Display.getCurrent(), SWT.CURSOR_ARROW)); + } + }); + } + }; + + public RemoteCallSubPage(SetSourcePage setSourcePage, Group dataGroup, Tree dialogTree, IProject project) { + parent = setSourcePage; + parentGroup = dataGroup; + parentDataTree = dialogTree; + this.project = project; + } + + @Override + public BindingData getData() { + + BindingData dataSource = (BindingData) PartUtil.createPart(PartType.DATASOURCE, LayoutSchemaConstants.DATASOURCE); + dataSource.setURL(urlText.getText()); + dataSource.setMethod(methodSettingCombo.getText()); + dataSource.setProxy(proxySettingCombo.getText()); + dataSource.setQuery(Helper.getParamString(requestParam.getItems())); + dataSource.setSourceType(sourceTypeCombo.getText().toLowerCase()); + dataSource.setTimeout(timeoutText.getText()); + dataSource.setPollingInterval(pollIntervalText.getText()); + if (poll.getSelection() == true) { + dataSource.setRemoteCallRequestType("poll"); + } else if (staticButton.getSelection() == true) { + dataSource.setRemoteCallRequestType("static"); + } + HashMap headers = new HashMap(); + + for (TableItem item : requestParam.getItems()) { + if (item.getText(0).equals("header") && (item.getText(1) + item.getText(2)).trim().length() > 0) { + headers.put(item.getText(1), item.getText(2)); + } + } + dataSource.setHeadersString(Helper.getHeadersString(headers)); + dataSource.addAllHeaderInfos(headers); + + JsonObject jsonObject = new JsonObject(); + TreeItem[] items = parentDataTree.getItems(); + + if (items == null || items.length == 0) { + MessageBox messageBox = new MessageBox(remoteSourceStyledText.getShell(), SWT.ICON_ERROR); + messageBox.setText("Set Source Error"); + messageBox.setMessage("Error : Data is invalid."); + messageBox.open(); + return null; + } + + for (TreeItem item : items) { + Helper.makeJsonFromTree(item, jsonObject); + } + + dataSource.setJsonData(jsonObject.toString()); + requiredPrivileges = new ArrayList(Arrays.asList(INTERNET_PRIVILEGE, NETWORK_PRIVILEGE, DOWNLOAD_PRIVILEGE)); + if (Helper.addPrivileges(settingComposite.getShell(), requiredPrivileges, project)) { + return dataSource; + } else { + return null; + } + } + + @Override + public Composite getSettingComposite() { + if (settingComposite == null) { + createSettingComposite(); + } + return settingComposite; + } + + private void createSettingComposite() { + + settingComposite = new Composite(parentGroup, SWT.NONE); + FormLayout layout = new FormLayout(); + layout.marginWidth = 5; + layout.marginHeight = 5; + + settingComposite.setLayout(layout); + + FormData data = new FormData(); + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(0, 0); + settingComposite.setLayoutData(data); + + // Load buttton + Button loadButton = new Button(settingComposite, SWT.PUSH); + loadButton.setImage(ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_RELOAD_ICON)); + loadButton.setToolTipText("Load"); + data = new FormData(29, 29); + data.bottom = new FormAttachment(100, -2); + data.right = new FormAttachment(100, -2); + loadButton.setLayoutData(data); + loadButton.addSelectionListener(loadEvent); + + // URL Composite + Composite urlComposite = makeInputText(settingComposite, "URL"); + data = new FormData(); + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(100, 0); + urlComposite.setLayoutData(data); + + urlText = (Text) urlComposite.getData(); + + Listener listener = new Listener() { + @Override + public void handleEvent(Event event) { + if (!(event.type == SWT.FocusOut || event.type == SWT.KeyDown)) + return; + else if (event.type == SWT.KeyDown && event.keyCode != 13) { + return; + } + + String url = urlText.getText(); + if (url.contains("?")) { + + urlText.setText(url.substring(0, url.indexOf("?"))); + String[] params = url.substring(url.indexOf("?") + 1).split("&"); + + requestParam.removeAll(); + + for (String param : params) { + param = "query=" + param; + String[] data = param.split("="); + TableItem item = new TableItem(requestParam, SWT.BORDER); + item.setText(data); + makeParamCombo(item, data[0]); + } + } + + loadEvent.widgetSelected(null); + } + }; + urlText.addListener(SWT.FocusOut, listener); + urlText.addListener(SWT.KeyDown, listener); + + // HTTP Method Composite + Composite methodComposite = makeInputCombo(settingComposite, "Method", new String[] { "GET", "POST", "PUT", "DELETE" }); + data = new FormData(); + data.top = new FormAttachment(urlComposite, 5); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(100, 0); + methodComposite.setLayoutData(data); + + methodSettingCombo = (CCombo) methodComposite.getData(); + methodSettingCombo.setEnabled(false); + + // HTTP Proxy Composite + Composite proxyComposite = makeInputCombo(settingComposite, "Proxy", new String[] { "jsonp", "ajax" }); + data = new FormData(); + data.top = new FormAttachment(methodComposite, 5); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(100, 0); + proxyComposite.setLayoutData(data); + + proxySettingCombo = (CCombo) proxyComposite.getData(); + proxySettingCombo.setEnabled(false); + + // Source Type Composite + Composite sourceTypeComposite = makeInputCombo(settingComposite, "Source Type", SoureTypes); + data = new FormData(); + data.top = new FormAttachment(proxyComposite, 5); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(100, 0); + sourceTypeComposite.setLayoutData(data); + + sourceTypeCombo = (CCombo) sourceTypeComposite.getData(); + sourceTypeCombo.setEnabled(false); + + // Timeout Composite + Composite timeoutComposite = makeInputText(settingComposite, "Timeout"); + data = new FormData(); + data.top = new FormAttachment(sourceTypeComposite, 5); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(100, 0); + timeoutComposite.setLayoutData(data); + + timeoutText = (Text) timeoutComposite.getData(); + timeoutText.setText("5000"); + + // Radio Button Composite + Composite buttonComposite = new Composite(settingComposite, SWT.NONE); + buttonComposite.setLayout(new FormLayout()); + poll = new Button(buttonComposite, SWT.RADIO); + poll.setText("Poll"); + poll.setSelection(true); + poll.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + pollIntervalComposite.setVisible(true); + pollIntervalText.setText("5000"); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + + } + }); + data = new FormData(); + poll.setLayoutData(data); + push = new Button(buttonComposite, SWT.RADIO); + push.setText("Push"); + push.setEnabled(false); + data = new FormData(); + data.left = new FormAttachment(poll, 50); + push.setLayoutData(data); + staticButton = new Button(buttonComposite, SWT.RADIO); + staticButton.setText("Static"); + staticButton.setEnabled(true); + staticButton.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent arg0) { + pollIntervalComposite.setVisible(false); + pollIntervalText.setText("-1"); + } + + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + }); + data = new FormData(); + data.left = new FormAttachment(push, 50); + staticButton.setLayoutData(data); + data = new FormData(); + data.top = new FormAttachment(timeoutComposite, 5); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(100, 0); + buttonComposite.setLayoutData(data); + + // Poll Interval Composite + pollIntervalComposite = makeInputText(settingComposite, "Poll Interval"); + data = new FormData(); + data.top = new FormAttachment(buttonComposite, 5); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(100, 0); + pollIntervalComposite.setLayoutData(data); + + pollIntervalText = (Text) pollIntervalComposite.getData(); + pollIntervalText.setText("5000"); + + // HTTP Request Parameter Composite + Composite queryComposite = makeQueryTable(settingComposite); + data = new FormData(); + data.top = new FormAttachment(pollIntervalComposite, 5); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(100, 0); + data.bottom = new FormAttachment(loadButton, -3); + queryComposite.setLayoutData(data); + + makeSourceStyledText(parentDataTree.getParent()); + } + + public Composite makeInputCombo(Composite parentComposite, String title, String[] items) { + + Composite subComposite = new Composite(parentComposite, SWT.NONE); + FormLayout layout = new FormLayout(); + subComposite.setLayout(layout); + + Label label = new Label(subComposite, SWT.NONE); + label.setText(title); + FormData data = new FormData(); + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(0, 0); + label.setLayoutData(data); + + CCombo combo = new CCombo(subComposite, SWT.SINGLE | SWT.BORDER | SWT.FLAT | SWT.READ_ONLY); + data = new FormData(); + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(30, 0); + data.right = new FormAttachment(100, 0); + combo.setLayoutData(data); + combo.setItems(items); + combo.select(0); + + subComposite.setData(combo); + + return subComposite; + } + + public Composite makeInputText(Composite parentComposite, String title) { + + Composite subComposite = new Composite(parentComposite, SWT.NONE); + FormLayout layout = new FormLayout(); + subComposite.setLayout(layout); + + Label label = new Label(subComposite, SWT.NONE); + label.setText(title); + FormData data = new FormData(); + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(0, 0); + label.setLayoutData(data); + + Text text = new Text(subComposite, SWT.SINGLE | SWT.BORDER); + + data = new FormData(); + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(30, 0); + data.right = new FormAttachment(100, 0); + text.setLayoutData(data); + subComposite.setData(text); + return subComposite; + } + + private Composite makeQueryTable(Composite parentComposite) { + + Composite subComposite = new Composite(parentComposite, SWT.NONE); + FormLayout layout = new FormLayout(); + subComposite.setLayout(layout); + + Label label = new Label(subComposite, SWT.NONE); + label.setText("Request Parameters"); + + FormData data = new FormData(); + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(0, 0); + label.setLayoutData(data); + + Composite composite = new Composite(subComposite, SWT.NONE); + + data = new FormData(50, 100); + data.top = new FormAttachment(label, 2); + data.right = new FormAttachment(100, 0); + data.left = new FormAttachment(10, 0); + data.bottom = new FormAttachment(100, 0); + composite.setLayoutData(data); + + TableColumnLayout tableLayout = new TableColumnLayout(); + composite.setLayout(tableLayout); + + requestParam = new Table(composite, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); + + requestParam.setLinesVisible(true); + requestParam.setHeaderVisible(true); + + requestParam.addListener(SWT.MeasureItem, new Listener() { + + @Override + public void handleEvent(Event e) { + e.height = 30; + } + }); + + TableColumn tblclmnType = new TableColumn(requestParam, SWT.LEFT); + tableLayout.setColumnData(tblclmnType, new ColumnWeightData(3, ColumnWeightData.MINIMUM_WIDTH, false)); + tblclmnType.setText("Type"); + + TableColumn tblclmnKey = new TableColumn(requestParam, SWT.LEFT); + tableLayout.setColumnData(tblclmnKey, new ColumnWeightData(3, ColumnWeightData.MINIMUM_WIDTH, false)); + tblclmnKey.setText("Key"); + + TableColumn tblclmnValue = new TableColumn(requestParam, SWT.LEFT); + tableLayout.setColumnData(tblclmnValue, new ColumnWeightData(3, ColumnWeightData.MINIMUM_WIDTH, false)); + tblclmnValue.setText("Value"); + + TableColumn tblclmnButton = new TableColumn(requestParam, SWT.LEFT); + tableLayout.setColumnData(tblclmnButton, new ColumnWeightData(1, ColumnWeightData.MINIMUM_WIDTH, false)); + + final TableEditor editor = new TableEditor(requestParam); + editor.horizontalAlignment = SWT.LEFT; + editor.grabHorizontal = true; + editor.grabVertical = true; + + makeParamCombo(new TableItem(requestParam, SWT.BORDER), "query"); + + requestParam.addListener(SWT.MouseDown, new Listener() { + public void handleEvent(Event event) { + Rectangle clientArea = requestParam.getClientArea(); + + Point pt = new Point(event.x, event.y); + int index = requestParam.getTopIndex(); + + TableItem lastItem = requestParam.getItem(requestParam.getItems().length - 1); + if ((lastItem.getText(1) + lastItem.getText(2)).trim().length() != 0) { + makeParamCombo(new TableItem(requestParam, SWT.BORDER), "query"); + } + + while (index < requestParam.getItemCount()) { + boolean visible = false; + final TableItem item = requestParam.getItem(index); + for (int i = 0; i < requestParam.getColumnCount(); i++) { + Rectangle rect = item.getBounds(i); + if (rect.contains(pt)) { + + if (requestParam.getSelection().length == 0 || !requestParam.getSelection()[0].equals(item)) + return; + + final int column = i; + final Text text = new Text(requestParam, SWT.NONE); + Listener textListener = new Listener() { + public void handleEvent(final Event e) { + switch (e.type) { + case SWT.FocusOut: + item.setText(column, text.getText()); + loadEvent.widgetSelected(null); + text.dispose(); + break; + case SWT.Traverse: + switch (e.detail) { + case SWT.TRAVERSE_RETURN: + item.setText(column, text.getText()); + // loadEvent.widgetSelected( null ); + // FALL THROUGH + case SWT.TRAVERSE_ESCAPE: + text.dispose(); + e.doit = false; + } + break; + } + } + }; + text.addListener(SWT.FocusOut, textListener); + text.addListener(SWT.Traverse, textListener); + editor.setEditor(text, item, i); + text.setText(item.getText(i)); + text.selectAll(); + text.setFocus(); + return; + } + if (!visible && rect.intersects(clientArea)) { + visible = true; + } + } + if (!visible) + return; + index++; + } + } + }); + + return subComposite; + } + + private void createDataSource() throws Exception { + + if (urlText.getText().trim().length() == 0) + return; + + MessageBox messageBox = new MessageBox(remoteSourceStyledText.getShell(), SWT.ICON_ERROR); + messageBox.setText("Set Source Error"); + String result; + + try { + result = Helper.callURL(urlText.getText(), methodSettingCombo.getText(), Integer.parseInt(timeoutText.getText()), requestParam.getItems()); + + if (result == null || result.trim().length() == 0) { + messageBox.setMessage("Error : Data is empty."); + messageBox.open(); + return; + } + + } catch (MalformedURLException e) { + for (Control control : parentDataTree.getChildren()) { + control.dispose(); + } + parentDataTree.removeAll(); + + messageBox.setMessage("Error : Invalid URL."); + messageBox.open(); + throw e; + } + + remoteSourceStyledText.setText(result); + + JsonElement json = null; + + int type = -1; + + try { + json = gson.fromJson(result, JsonElement.class); + type = 0; + } catch (Exception e) { + try { + json = Helper.getJsonFromXML(result); + type = 1; + } catch (SAXException e1) { + } + } + + if (type >= 0) + sourceTypeCombo.select(type); + + if (json != null) { + Helper.makeTreeItem(json, parentDataTree, null, true, this); + parent.setDataModelDirty(false); + } else { + messageBox.setMessage("Error : Can not parse the data"); + messageBox.open(); + + for (Control control : parentDataTree.getChildren()) { + control.dispose(); + } + parentDataTree.removeAll(); + } + } + + private void makeParamCombo(TableItem item, String value) { + + TableEditor editor = new TableEditor(requestParam); + Combo combo = new Combo(requestParam, SWT.NONE); + + editor.grabHorizontal = true; + editor.grabVertical = true; + editor.setEditor(combo, item, 0); + editor.layout(); + + combo.add("query"); + combo.add("header"); + + combo.select(Arrays.asList(combo.getItems()).indexOf(value)); + + item.setText(combo.getText()); + item.setData("ITEMCOMBO", editor); + combo.setData("EDITOR", editor); + + combo.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + Combo combo = (Combo) e.getSource(); + TableEditor editor = (TableEditor) combo.getData("EDITOR"); + TableItem item = editor.getItem(); + item.setText(0, combo.getText()); + } + }); + + editor = new TableEditor(requestParam); + editor.grabHorizontal = true; + editor.verticalAlignment = SWT.TOP; + Button button = new Button(requestParam, SWT.PUSH); + item.setData("ITEMBUTTON", editor); + button.setText("-"); + button.pack(); + button.setData("EDITOR", editor); + button.setToolTipText("Delete"); + editor.minimumWidth = button.getSize().x; + editor.horizontalAlignment = SWT.RIGHT; + editor.setEditor(button, item, 3); + editor.layout(); + + button.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + + Button button = (Button) e.getSource(); + Rectangle rect = button.getBounds(); + TableItem targetItem = requestParam.getItem(new Point(rect.x + 1, rect.y + 1)); + + if (targetItem == null || requestParam.indexOf(targetItem) == requestParam.getItemCount() - 1) + return; + + TableEditor buttonEditor = (TableEditor) targetItem.getData("ITEMBUTTON"); + TableEditor comboEditor = (TableEditor) targetItem.getData("ITEMCOMBO"); + + comboEditor.getEditor().setVisible(false); + comboEditor.getEditor().dispose(); + + comboEditor.dispose(); + + buttonEditor.getEditor().setVisible(false); + buttonEditor.getEditor().dispose(); + + buttonEditor.dispose(); + + targetItem.dispose(); + + for (TableItem item : requestParam.getItems()) { + ((TableEditor) item.getData("ITEMBUTTON")).layout(); + ((TableEditor) item.getData("ITEMCOMBO")).layout(); + } + } + }); + + } + + private void makeSourceStyledText(Composite composite) { + remoteSourceStyledText = new StyledText(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); + + FormData data = new FormData(); + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(0, 0); + remoteSourceStyledText.setLayoutData(data); + } + + @Override + public void setButtonsState(Map dataButtonMap) { + + if (dataButtonMap.get("conversionTreeAndText").getSelection()) { + dataButtonMap.get("upTreeItem").setEnabled(false); + dataButtonMap.get("downTreeItem").setEnabled(false); + } else { + dataButtonMap.get("upTreeItem").setEnabled(true); + dataButtonMap.get("downTreeItem").setEnabled(true); + } + dataButtonMap.get("addTreeItem").setEnabled(false); + dataButtonMap.get("removeTreeItem").setEnabled(false); + dataButtonMap.get("removeAllTreeItem").setEnabled(false); + + dataButtonMap.get("conversionTreeAndText").setVisible(true); + } + + @Override + public void loadData(BindingData dataSource) { + if (temp == null) + temp = dataSource; + + JsonElement json = gson.fromJson(dataSource.getJsonData(), JsonElement.class); + urlText.setText(dataSource.getURL()); + methodSettingCombo.select(Arrays.asList(methodSettingCombo.getItems()).indexOf(dataSource.getMethod())); + proxySettingCombo.select(Arrays.asList(proxySettingCombo.getItems()).indexOf(dataSource.getProxy())); + if (dataSource.getRemoteCallRequestType().equals("static")) { + pollIntervalComposite.setVisible(false); + pollIntervalText.setText("-1"); + poll.setSelection(false); + push.setSelection(false); + staticButton.setSelection(true); + } else if (dataSource.getRemoteCallRequestType().equals("poll")) { + pollIntervalComposite.setVisible(true); + pollIntervalText.setText(dataSource.getPollingInterval()); + poll.setSelection(true); + push.setSelection(false); + staticButton.setSelection(false); + } + sourceTypeCombo.select(Arrays.asList(SoureTypes).indexOf(dataSource.getSourceType().toUpperCase())); + timeoutText.setText(dataSource.getTimeout()); + requestParam.removeAll(); + + for (Control control : requestParam.getChildren()) + control.dispose(); + + if (dataSource.getHeaders() != null) { + for (Entry entry : dataSource.getHeaders().entrySet()) { + TableItem item = new TableItem(requestParam, SWT.BORDER); + item.setText(1, "header"); + item.setText(1, entry.getKey()); + item.setText(2, entry.getValue()); + makeParamCombo(item, "header"); + } + } + + String query = dataSource.getQuery(); + if (!query.isEmpty()) { + setParamString(query); + } + + makeParamCombo(new TableItem(requestParam, SWT.BORDER), "query"); + + if (dataSource.getJsonData() != null) { + remoteSourceStyledText.setText(dataSource.getJsonData()); + } + + if (!parent.isDataModelDirty()) { + parentDataTree.removeAll(); + for (Control control : parentDataTree.getChildren()) { + control.dispose(); + } + + Helper.makeTreeItem(json, parentDataTree, null, true, this); + } + } + + private void setParamString(String query) { + String[] params = query.split("&"); + for (int i = 0; i < params.length; i++) { + String[] param = ("query=" + params[i]).split("="); + if (param.length == 0) { + continue; + } else { + TableItem item = new TableItem(requestParam, SWT.BORDER); + item.setText(param); + makeParamCombo(item, param[0]); + } + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/SetModelTargetDialog.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/SetModelTargetDialog.java new file mode 100644 index 0000000..59f37cd --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/SetModelTargetDialog.java @@ -0,0 +1,351 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.dialog; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.ListViewer; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; +import org.tizen.efluibuilder.core.configurator.Configurator; +import org.tizen.efluibuilder.model.descriptors.DescriptorManager; +import org.tizen.efluibuilder.model.descriptors.PropertyDescriptor; +import org.tizen.efluibuilder.model.descriptors.WidgetDescriptor; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; + +public class SetModelTargetDialog extends Dialog { + private Object widgetContents; + private Viewer propertyList; + private Part selectedPart; + private String selectedWidgetPropertyName; + private ListViewer listViewer; + + DescriptorManager descriptorManager; + + private static class WidgetTreeViewerLabelProvider implements ILabelProvider { + + @Override + public void removeListener(ILabelProviderListener arg0) { + // TODO Auto-generated method stub + + } + + @Override + public boolean isLabelProperty(Object arg0, String arg1) { + // TODO Auto-generated method stub + return false; + } + + @Override + public void dispose() { + // TODO Auto-generated method stub + + } + + @Override + public void addListener(ILabelProviderListener arg0) { + // TODO Auto-generated method stub + + } + + @Override + public String getText(Object element) { + return ((Part) element).getPropertyValue("id"); + } + + @Override + public Image getImage(Object arg0) { + // TODO Auto-generated method stub + return null; + } + } + + private class WidgetTreeViewerSelectionChangedListener implements ISelectionChangedListener { + + @Override + public void selectionChanged(SelectionChangedEvent event) { + // if the selection is empty clear the label + if (event.getSelection().isEmpty()) { + return; + } + if (event.getSelection() instanceof IStructuredSelection) { + IStructuredSelection selection = (IStructuredSelection) event.getSelection(); + + selectedPart = (Part) selection.getFirstElement(); + + Configurator configurator = Configurator.of(selectedPart.getOwnerDocumentPart().getPlatform()); + descriptorManager = configurator.getDescriptorManager(); + WidgetDescriptor selectedWidgetDescriptor = descriptorManager + .getWidgetDescriptor(selectedPart.getDescriptorId()); + List propertyDescriptors = selectedWidgetDescriptor.getPropertyDescriptors(); + + if (propertyList != null) { + List inputList = new ArrayList(); + for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { + + if (propertyDescriptor.getPropertyName() + .equalsIgnoreCase(BuilderConstants.ATTRIBUTE_DATA_BIND)) { + inputList.add(propertyDescriptor); + } + } + propertyList.setInput(inputList); + } + Button ok = getButton(IDialogConstants.OK_ID); + if (ok != null) { + ok.setEnabled(false); + } + selectedWidgetPropertyName = null; + if(listViewer.getElementAt(0)!=null) + listViewer.setSelection(new StructuredSelection(listViewer.getElementAt(0)),true); + } + } + } + + private class WidgetTreeViewerContentProvider implements ITreeContentProvider { + + @Override + public void inputChanged(Viewer arg0, Object arg1, Object arg2) { + } + + @Override + public void dispose() { + // TODO Auto-generated method stub + + } + + @Override + public boolean hasChildren(Object element) { + + return (numComponentTypeChildren((Part) element) > 0); + } + + @Override + public Object getParent(Object element) { + Part partElement = (Part) element; + return partElement.getParent(); + } + + @Override + public Object[] getElements(Object inputElement) { + List rootElements = new ArrayList(); + for (Part part : ((Part) inputElement).getChildren()) { + if (hasChildren(part) && part.getType() == PartType.COMPONENT) { + + rootElements.add(part); + } + } + return rootElements.toArray(); + } + + @Override + public Object[] getChildren(Object parentElement) { + List rootElements = new ArrayList(); + for (final Part part : ((Part) parentElement).getChildren()) { + if (part.getType() == PartType.COMPONENT) { + rootElements.add(part); + } + } + return rootElements.toArray(); + } + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets + * .Composite) + */ + @Override + protected Control createDialogArea(Composite parent) { + + Composite area = (Composite) super.createDialogArea(parent); + + Composite container = new Composite(area, SWT.FILL); + container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + GridLayout layout = new GridLayout(2, true); + container.setLayout(layout); + + createWidgetTreeList(container); + + createPropertyListViewer(container); + + return area; + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText("Set Target"); + } + + @Override + protected void createButtonsForButtonBar(Composite parent) { + // TODO Auto-generated method stub + super.createButtonsForButtonBar(parent); + Button ok = getButton(IDialogConstants.OK_ID); + if (ok != null) { + ok.setEnabled(false); + } + } + + private void createPropertyListViewer(Composite parent) { + listViewer = new ListViewer(parent); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + data.minimumWidth = 100; + data.minimumHeight = 350; + listViewer.getList().setLayoutData(data); + // TODO: Create Separate class for IStructuredContentProvider + listViewer.setContentProvider(new IStructuredContentProvider() { + + @Override + public void inputChanged(Viewer arg0, Object arg1, Object arg2) { + + } + + @Override + public void dispose() { + } + + @Override + public Object[] getElements(Object inputElements) { + + List propNameList = new ArrayList(); + + for (PropertyDescriptor prop : ((List) inputElements)) { + + // data binding type is defined as 'text@data-binding' + propNameList.add(prop.getPropertyType().split("@")[0]); + + } + return propNameList.toArray(); + } + }); + + listViewer.addSelectionChangedListener(new ISelectionChangedListener() { + + @Override + public void selectionChanged(SelectionChangedEvent event) { + // if the selection is empty clear the label + if (event.getSelection().isEmpty()) { + return; + } + if (event.getSelection() instanceof IStructuredSelection) { + IStructuredSelection selection = (IStructuredSelection) event.getSelection(); + + selectedWidgetPropertyName = (String) selection.getFirstElement(); + Button ok = getButton(IDialogConstants.OK_ID); + if(ok != null){ + ok.setEnabled(true); + } + } + } + }); + + propertyList = listViewer; + } + + private int numComponentTypeChildren(Part element) { + // TODO: Confirm algorithm to decide it + // For time being, count all component type child + // parts and if it is greater than zero, then it's a + // container type of component + int count = 0; + List children = element.getChildren(); + for (int i = 0; i < children.size(); ++i) { + if (children.get(i).getType() == PartType.COMPONENT) { + ++count; + } + } + return count; + } + + // TODO: Solve widget alignment and placement issue + private void createWidgetTreeList(Composite parent) { + // Consult: This article + // http://www.eclipse.org/articles/Article-TreeViewer/TreeViewerArticle.htm?PHPSESSID=4d48764999a9cb66a7fd58a954ef2131 + + TreeViewer widgetTreeViewer = new TreeViewer(parent, SWT.SINGLE); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + data.minimumWidth = 200; + data.minimumHeight = 350; + widgetTreeViewer.getTree().setLayoutData(data); + widgetTreeViewer.setContentProvider(new WidgetTreeViewerContentProvider()); + + widgetTreeViewer.addSelectionChangedListener(new WidgetTreeViewerSelectionChangedListener()); + + widgetTreeViewer.setLabelProvider(new WidgetTreeViewerLabelProvider()); + + widgetTreeViewer.setInput(widgetContents); + } + + public SetModelTargetDialog(Shell parent) { + super(parent); + + } + + /** + * @param widgetContents + * the widgetContents to set + */ + public void setWidgetContents(Object widgetContents) { + this.widgetContents = widgetContents; + } + + /** + * @return the selectedWidgetProperty + */ + public String getSelectedWidgetPropertyName() { + return selectedWidgetPropertyName; + } + + /** + * @return the selectedPart + */ + public Part getSelectedPart() { + return selectedPart; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/SetSourcePage.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/SetSourcePage.java new file mode 100644 index 0000000..8072571 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/SetSourcePage.java @@ -0,0 +1,1273 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.dialog; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.resources.IProject; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.custom.StackLayout; +import org.eclipse.swt.custom.TreeEditor; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DragSource; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.events.ControlAdapter; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.FocusAdapter; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Dialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeColumn; +import org.eclipse.swt.widgets.TreeItem; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingData; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingObject; +import org.tizen.efluibuilder.ui.view.databinding.model.TreeItemData; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; +import org.tizen.efluibuilder.ui.view.databinding.utils.Helper; +import org.tizen.efluibuilder.ui.view.databinding.utils.Helper.DataSourceType; +import org.tizen.efluibuilder.ui.view.databinding.utils.ResourceManager; + +public class SetSourcePage extends Dialog { + + private Shell shell; + private TreeItem dataSourceTreeItem; + private BindingData dataSource; + private IProject project; + + private StackLayout setttingStackLayout; + private StackLayout dataStackLayout; + + private StaticSubPage staticSubPage; + private CallHistorySubPage callHistorySubPage; + private ContactSubPage contactSubPage; + private SourceDialogSubPage currentSubPage; + + private CCombo dataTypeCombo; + private CLabel typeDesc; + private Tree dialogTree; + private Composite treeComposite; + private Composite dataComposite; + + private Group dataModelGroup; + + private SashForm sashForm; + + private boolean isDataModelDirty = false; + + private Map dataButtonMap = new HashMap(); + + private List types = Arrays + .asList(new String[] { "Boolean", "Number", "String", "Object", "Array", "Index", "Undefined" }); + + private DataSourceType[] dataSourceTypes = DataSourceType.values(); + private RemoteCallSubPage remoteCallSubPage; + + /** + * Constructor. + * + * @param parent + * @param dataSourceTreeItem + * @param project + */ + public SetSourcePage(Shell parent, TreeItem dataSourceTreeItem, IProject project) { + super(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); + setText("Set Source"); + this.dataSourceTreeItem = dataSourceTreeItem; + this.project = project; + } + + /** + * Opens the dialog and returns the input + * + * @return message + */ + public BindingData open() { + // Create the dialog window + shell = new Shell(getParent(), SWT.TITLE | SWT.CLOSE | SWT.BORDER | SWT.RESIZE | SWT.APPLICATION_MODAL); + shell.setText(getText()); + createContents(); + shell.pack(); + + TreeItemData treeItemData = (TreeItemData) dataSourceTreeItem.getData("TREEITEMDATA"); + if (treeItemData != null) + loadParentData(treeItemData); + + shell.open(); + Display display = getParent().getDisplay(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + + return dataSource; + } + + /** + * Creates the dialog's contents + */ + private void createContents() { + + FormLayout layout = new FormLayout(); + shell.setLayout(layout); + layout.marginWidth = 5; + layout.marginHeight = 5; + + Group typeGroup = makeTypeGroup(shell); + Composite baseGroup = makeBaseGroup(shell, typeGroup); + + sashForm = new SashForm(baseGroup, SWT.HORIZONTAL); + + FormData sashData = new FormData(); + sashData.top = new FormAttachment(0, 0); + sashData.bottom = new FormAttachment(100, 0); + sashData.left = new FormAttachment(0, 0); + sashData.right = new FormAttachment(100, 0); + sashForm.setLayoutData(sashData); + + Group settingGroup = new Group(sashForm, SWT.NONE); + dataModelGroup = new Group(sashForm, SWT.NONE); + + sashForm.setWeights(new int[] { 2, 3 }); + + makeDataModelGroup(dataModelGroup); + makeSettingGroup(settingGroup); + + // Create the cancel button and add a handler + // so that pressing it will set input to null + Button cancelButton = new Button(shell, SWT.PUSH); + cancelButton.setText("CANCEL"); + + FormData data = new FormData(100, 30); + data.top = new FormAttachment(baseGroup, 5); + data.right = new FormAttachment(100, -5); + data.bottom = new FormAttachment(100, -5); + + cancelButton.setLayoutData(data); + + cancelButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + dataSource = null; + shell.close(); + } + }); + + // Create the OK button and add a handler + // so that pressing it will set input + // to the entered value + Button okButton = new Button(shell, SWT.PUSH); + okButton.setText("OK"); + + data = new FormData(100, 30); + data.top = new FormAttachment(baseGroup, 5); + data.right = new FormAttachment(cancelButton, -5); + data.bottom = new FormAttachment(100, -5); + + okButton.setLayoutData(data); + + okButton.addSelectionListener(new SelectionAdapter() { + + public void widgetSelected(SelectionEvent event) { + TreeItemData treeItemData = (TreeItemData) dataSourceTreeItem.getData("TREEITEMDATA"); + if (treeItemData == null) { + return; + } + BindingData dataModel = currentSubPage.getData(); + + if (dataModel == null) + return; + + String type = null; + for (DataSourceType dataSourceType : dataSourceTypes) { + if(dataSourceType.getLabel().equals(dataTypeCombo.getText())){ + type = dataSourceType.getValue(); + } + } + dataModel.setModelType(type); + dataModel.setSourceName(dataSourceTreeItem.getText()); + TreeItem[] treeItems = dialogTree.getItems(); + + for (TreeItem item : treeItems) { + BindingObject bindingObject = (BindingObject) PartUtil.createPart(PartType.BINDINGOBJECT, LayoutSchemaConstants.BINDINGOBJECT); + bindingObject.setName(item.getText(0)); + bindingObject.setValue(item.getText(1)); + bindingObject.setValueType(item.getText(2)); + dataModel.insertChildBefore(bindingObject, null); + makeBindingDataFromTree(item, bindingObject); + } + + dataSource = dataModel; + shell.close(); + } + }); + } + + private void makeBindingDataFromTree(TreeItem parentItem, BindingObject parentBindingObject) { + String type = parentItem.getText(2); + + TreeItem[] items = parentItem.getItems(); + + if (type.equals("Array")) { + for (TreeItem item : items) { + if (item.getText(2).equals("Index") && !item.getText(1).isEmpty()) { + BindingObject bo = (BindingObject) PartUtil.createPart(PartType.BINDINGOBJECT, LayoutSchemaConstants.BINDINGOBJECT); + bo.setName(item.getText(0)); + bo.setValue(item.getText(1)); + bo.setValueType(item.getText(2)); + parentBindingObject.insertChildBefore(bo, null); + for (TreeItem subItem : item.getItems()) { + + if (subItem.getText(0).trim().length() == 0) + continue; + + BindingObject bindingData = (BindingObject) PartUtil.createPart(PartType.BINDINGOBJECT, LayoutSchemaConstants.BINDINGOBJECT); + bindingData.setName(item.getText(0)); + bindingData.setValue(item.getText(1)); + bindingData.setValueType(item.getText(2)); + parentBindingObject.insertChildBefore(bindingData, null); + makeBindingDataFromTree(subItem, bindingData); + } + } else { + BindingObject bindingData = (BindingObject) PartUtil.createPart(PartType.BINDINGOBJECT, LayoutSchemaConstants.BINDINGOBJECT); + bindingData.setName(item.getText(0)); + bindingData.setValue(item.getText(1)); + bindingData.setValueType(item.getText(2)); + parentBindingObject.insertChildBefore(bindingData, null); + makeBindingDataFromTree(item, bindingData); + } + } + } else { + for (TreeItem item : items) { + BindingObject bindingData = (BindingObject) PartUtil.createPart(PartType.BINDINGOBJECT, LayoutSchemaConstants.BINDINGOBJECT); + bindingData.setName(item.getText(0)); + bindingData.setValue(item.getText(1)); + bindingData.setValueType(item.getText(2)); + parentBindingObject.insertChildBefore(bindingData, null); + makeBindingDataFromTree(item, bindingData); + } + } + } + + private void loadParentData(TreeItemData treeItemData) { + BindingData dataModel = treeItemData.getModel(); + + if (dataModel != null) { + if (dataModel.getModelType().equals(BuilderConstants.DATABINDING_TYPE_EMPTY)) { + dataTypeCombo.select(0); + } else { + String modelType = dataModel.getModelType(); + for (DataSourceType dataBindingType : dataSourceTypes) { + if (dataBindingType.getValue().equals(modelType)) { + dataTypeCombo.setText(dataBindingType.getLabel()); + } + } + } + initByType(); + try { + currentSubPage.loadData(dataModel); + } catch (Exception e) { + } + currentSubPage.setButtonsState(dataButtonMap); + } + } + + private Group makeTypeGroup(Shell shell) { + Group typeGroup = new Group(shell, SWT.NONE); + typeGroup.setText("Data Type"); + + FormData data = new FormData(); + data.top = new FormAttachment(0, 5); + data.left = new FormAttachment(0, 5); + data.right = new FormAttachment(100, -5); + typeGroup.setLayoutData(data); + typeGroup.setLayout(new FormLayout()); + + dataTypeCombo = new CCombo(typeGroup, SWT.READ_ONLY | SWT.BORDER | SWT.SINGLE); + data = new FormData(); + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(0, 0); + dataTypeCombo.setLayoutData(data); + + int count = 0; + String[] dataTypeItems = new String[dataSourceTypes.length]; + for (DataSourceType dataSourceType : dataSourceTypes) { + dataTypeItems[count++] = dataSourceType.getLabel(); + } + dataTypeCombo.setItems(dataTypeItems); + dataTypeCombo.setVisibleItemCount(dataSourceTypes.length); + dataTypeCombo.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + dataTypeCombo.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + + for (Control control : dialogTree.getChildren()) { + control.dispose(); + } + + dialogTree.removeAll(); + + initByType(); + + currentSubPage.setButtonsState(dataButtonMap); + } + }); + + typeDesc = new CLabel(typeGroup, SWT.NONE); + typeDesc.setText("Call history API Is supported only on real devices."); + + data = new FormData(); + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(dataTypeCombo, 10); + typeDesc.setLayoutData(data); + + return typeGroup; + } + + private void initByType() { + int settingWeight = 3; + int shshWidth = 1; + Composite dataCompositeParent = dataModelGroup; + typeDesc.setVisible(false); + if (dataTypeCombo.getText().equals(DataSourceType.STATIC.getLabel())) { + currentSubPage = staticSubPage; + settingWeight = 0; + shshWidth = 0; + dataCompositeParent = staticSubPage.getDataComposite(); + } else if (dataTypeCombo.getText().equals(DataSourceType.REMOTE.getLabel())) { + currentSubPage = remoteCallSubPage; + } /*else if (dataTypeCombo.getText().equals(DataSourceType.CALL_HISTORY.getLabel())) { + currentSubPage = callHistorySubPage; + } else if (dataTypeCombo.getText().equals(DataSourceType.CONTACT.getLabel())) { + currentSubPage = contactSubPage; + } else { + // TODO: Handle other sources + }*/ + + sashForm.setWeights(new int[] { 2, settingWeight }); + sashForm.setSashWidth(shshWidth); + dataComposite.setParent(dataCompositeParent); + dataComposite.getParent().layout(); + + Composite composite = currentSubPage.getSettingComposite(); + setttingStackLayout.topControl = composite; + composite.getParent().layout(); + isDataModelDirty = false; + } + + private Composite makeBaseGroup(Shell shell, Group typeGroup) { + Composite mainGroup = new Composite(shell, SWT.NONE); + + FormLayout mainLayout = new FormLayout(); + + FormData mainFormData = new FormData(); + mainFormData.top = new FormAttachment(typeGroup, 5); + mainFormData.bottom = new FormAttachment(100, -35); + mainFormData.left = new FormAttachment(0, 5); + mainFormData.right = new FormAttachment(100, -5); + + mainGroup.setLayout(mainLayout); + mainGroup.setLayoutData(mainFormData); + + return mainGroup; + } + + private Group makeDataModelGroup(Group dataGroup) { + + dataGroup.setText("Data Source Schema"); + FormLayout layout = new FormLayout(); + dataGroup.setLayout(layout); + + dataComposite = new Composite(dataGroup, SWT.NONE); + + FormData data = new FormData(); + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(100, 0); + data.bottom = new FormAttachment(100, 0); + dataComposite.setLayoutData(data); + + dataComposite.setLayout(new FormLayout()); + + makeDataButtons(dataComposite); + + treeComposite = new Composite(dataComposite, SWT.NONE); + data = new FormData(); + data.top = new FormAttachment(dataButtonMap.get("expandAll"), 2); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(100, 0); + data.bottom = new FormAttachment(100, 0); + treeComposite.setLayoutData(data); + + dataStackLayout = new StackLayout(); + treeComposite.setLayout(dataStackLayout); + + makeDataTree(treeComposite); + + dataStackLayout.topControl = dialogTree; + + dataGroup.layout(); + return dataGroup; + } + + private void makeDataButtons(Composite dataGroup) { + + Button expandAllButton = new Button(dataGroup, SWT.FLAT); + expandAllButton.setImage( + ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_DATA_EXPAND_ALL_ICON)); + expandAllButton.setToolTipText("Expand All Fields"); + + FormData data = new FormData(29, 29); + data.top = new FormAttachment(2, 0); + data.left = new FormAttachment(0, 0); + + expandAllButton.setLayoutData(data); + dataButtonMap.put("expandAll", expandAllButton); + + SelectionAdapter adapter = new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + boolean isExpand; + Button bt = (Button) e.getSource(); + if (bt.getData("expand") != null && (Boolean) bt.getData("expand")) { + isExpand = true; + } else { + isExpand = false; + } + + for (TreeItem treeItem : dialogTree.getItems()) { + doExpend(treeItem, isExpand); + } + } + + private void doExpend(TreeItem treeItems, boolean expand) { + treeItems.setExpanded(expand); + for (TreeItem treeItem : treeItems.getItems()) { + doExpend(treeItem, expand); + } + } + }; + expandAllButton.setData("expand", true); + expandAllButton.addSelectionListener(adapter); + + Button collapseAllButton = new Button(dataGroup, SWT.FLAT); + collapseAllButton.setImage(ResourceManager.getImage(BuilderConstants.ICON_DIR, + BuilderConstants.DATABINDING_DATA_COLLAPSE_ALL_ICON)); + collapseAllButton.setToolTipText("Collapse All Fields"); + collapseAllButton.setData("expand", false); + collapseAllButton.addSelectionListener(adapter); + + data = new FormData(29, 29); + data.top = new FormAttachment(2, 0); + data.left = new FormAttachment(expandAllButton, 2); + + collapseAllButton.setLayoutData(data); + dataButtonMap.put("collapseAll", collapseAllButton); + + Button conversionButtonBetweenTreeAndText = new Button(dataGroup, SWT.TOGGLE | SWT.FLAT); + conversionButtonBetweenTreeAndText.setImage(ResourceManager.getImage(BuilderConstants.ICON_DIR, + BuilderConstants.DATABINDING_DATA_VIEW_SOURCE_ICON)); + conversionButtonBetweenTreeAndText.setToolTipText("View Source"); + + data = new FormData(29, 29); + data.top = new FormAttachment(2, 0); + data.right = new FormAttachment(100, -2); + conversionButtonBetweenTreeAndText.setLayoutData(data); + + conversionButtonBetweenTreeAndText.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + Button button = (Button) event.getSource(); + + if (button.getSelection()) { + button.setToolTipText("View Tree"); + // TODO: FIXME + // dataStackLayout.topControl = + // remoteCallSubPage.getDataSourceStyledText(); + button.setImage(ResourceManager.getImage(BuilderConstants.ICON_DIR, + BuilderConstants.DATABINDING_DATA_VIEW_TREE_ICON)); + } else { + dataStackLayout.topControl = dialogTree; + button.setToolTipText("View Source"); + button.setImage(ResourceManager.getImage(BuilderConstants.ICON_DIR, + BuilderConstants.DATABINDING_DATA_VIEW_SOURCE_ICON)); + } + currentSubPage.setButtonsState(dataButtonMap); + dialogTree.getParent().layout(); + } + }); + dataButtonMap.put("conversionTreeAndText", conversionButtonBetweenTreeAndText); + + Label verticalSeparator = new Label(dataGroup, SWT.SEPARATOR | SWT.VERTICAL); + data = new FormData(1, 29); + data.top = new FormAttachment(2, 0); + data.right = new FormAttachment(conversionButtonBetweenTreeAndText, -2); + verticalSeparator.setLayoutData(data); + + Button downTreeItemButton = new Button(dataGroup, SWT.PUSH | SWT.FLAT); + downTreeItemButton.setImage( + ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_DATA_DOWN_ICON)); + downTreeItemButton.setToolTipText("Move Down"); + + data = new FormData(29, 29); + data.top = new FormAttachment(2, 0); + data.right = new FormAttachment(verticalSeparator, -2); + + downTreeItemButton.setLayoutData(data); + downTreeItemButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + moveItem(false); + isDataModelDirty = true; + } + }); + dataButtonMap.put("downTreeItem", downTreeItemButton); + + Button upTreeItemButton = new Button(dataGroup, SWT.PUSH | SWT.FLAT); + upTreeItemButton.setImage( + ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_DATA_UP_ICON)); + upTreeItemButton.setToolTipText("Move Up"); + + data = new FormData(29, 29); + data.top = new FormAttachment(2, 0); + data.right = new FormAttachment(downTreeItemButton, -2); + upTreeItemButton.setLayoutData(data); + + upTreeItemButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + moveItem(true); + isDataModelDirty = true; + } + }); + dataButtonMap.put("upTreeItem", upTreeItemButton); + + verticalSeparator = new Label(dataGroup, SWT.SEPARATOR | SWT.VERTICAL); + data = new FormData(1, 29); + data.top = new FormAttachment(2, 0); + data.right = new FormAttachment(upTreeItemButton, -2); + verticalSeparator.setLayoutData(data); + + Button removeAllTreeItemButton = new Button(dataGroup, SWT.PUSH | SWT.FLAT); + removeAllTreeItemButton.setImage( + ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_DATA_REMOVE_ALL_ICON)); + removeAllTreeItemButton.setToolTipText("Remove All"); + + data = new FormData(29, 29); + data.top = new FormAttachment(2, 0); + data.right = new FormAttachment(verticalSeparator, -2); + removeAllTreeItemButton.setLayoutData(data); + + removeAllTreeItemButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + removeAllItems(); + isDataModelDirty = true; + } + }); + dataButtonMap.put("removeAllTreeItem", removeAllTreeItemButton); + + Button removeTreeItemButton = new Button(dataGroup, SWT.PUSH | SWT.FLAT); + removeTreeItemButton.setImage( + ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_DATA_REMOVE_ICON)); + removeTreeItemButton.setToolTipText("Remove"); + + data = new FormData(29, 29); + data.top = new FormAttachment(2, 0); + data.right = new FormAttachment(removeAllTreeItemButton, -2); + + removeTreeItemButton.setLayoutData(data); + removeTreeItemButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + removeItem(); + isDataModelDirty = true; + } + }); + dataButtonMap.put("removeTreeItem", removeTreeItemButton); + + Button addTreeItemButton = new Button(dataGroup, SWT.PUSH | SWT.FLAT); + addTreeItemButton.setImage( + ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_DATA_ADD_ICON)); + addTreeItemButton.setToolTipText("Add New Field"); + + data = new FormData(29, 29); + data.top = new FormAttachment(2, 0); + data.right = new FormAttachment(removeTreeItemButton, -2); + addTreeItemButton.setLayoutData(data); + + addTreeItemButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + addItem(); + isDataModelDirty = true; + } + }); + dataButtonMap.put("addTreeItem", addTreeItemButton); + } + + private void makeDataTree(Composite treeComposite) { + + Button expandAll = new Button(treeComposite, SWT.FLAT); + expandAll.setToolTipText("Exapnd All fields"); + + FormData data = new FormData(33, 33); + data.top = new FormAttachment(2, 0); + data.left = new FormAttachment(2, 0); + + expandAll.setLayoutData(data); + + dialogTree = new Tree(treeComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION); + + dialogTree.addListener(SWT.MeasureItem, new Listener() { + @Override + public void handleEvent(Event event) { + event.height = 19; + } + }); + + dialogTree.addMouseListener(new MouseAdapter() { + @Override + public void mouseDoubleClick(MouseEvent e) { + if (dialogTree.getSelection().length > 0) { + if (dialogTree.getSelection()[0].getExpanded()) + dialogTree.getSelection()[0].setExpanded(false); + else + dialogTree.getSelection()[0].setExpanded(true); + } + } + }); + + dialogTree.setLinesVisible(true); + dialogTree.setHeaderVisible(true); + + data = new FormData(); + data.top = new FormAttachment(expandAll, 2); + data.left = new FormAttachment(0, 0); + dialogTree.setLayoutData(data); + + TreeColumn column1 = new TreeColumn(dialogTree, SWT.LEFT); + column1.setText("Field"); + column1.setWidth(140); + TreeColumn column2 = new TreeColumn(dialogTree, SWT.LEFT); + column2.setText("Data"); + column2.setWidth(100); + TreeColumn column3 = new TreeColumn(dialogTree, SWT.LEFT); + column3.setText("Type"); + column3.setWidth(80); + + dialogTree.addControlListener(new ControlAdapter() { + public void controlResized(ControlEvent e) { + Tree tree = (Tree) e.getSource(); + tree.getColumn(1).setWidth(tree.getClientArea().width - tree.getColumn(0).getWidth() - 95); + } + }); + + final TreeEditor treeEditor = new TreeEditor(dialogTree); + treeEditor.horizontalAlignment = SWT.LEFT; + treeEditor.grabHorizontal = true; + + dialogTree.addMouseListener(new MouseAdapter() { + public void mouseDoubleClick(MouseEvent e) { + Point point = new Point(e.x, e.y); + final TreeItem treeItem = dialogTree.getItem(point); + if (treeItem == null) { + dialogTree.deselectAll(); + return; + } + + for (int i = 0; i < dialogTree.getColumnCount(); i++) {// this + // is + // the + // column + // that + // was + // clicked + final int column = i; + Rectangle rect = treeItem.getBounds(column); + if (rect.contains(point)) { + + TreeItemData data = (TreeItemData) treeItem.getData("TREEITEMDATA"); + String type = treeItem.getText(2); + + if (data.getSource().equals("original") && column != 1) { + return; + } else if (!types.contains(data.getObjectType()) && treeItem.getData("") == null) + return; + else if ((type.equals("Index") || type.equals("IndexObject")) && (column == 0 || column == 2)) + return; + else if ((type.equals("Object") || type.equals("Array")) && column != 0) + return; + + if (column == 1 && !(currentSubPage instanceof StaticSubPage)) + return; + + Control oldEditor = treeEditor.getEditor(); + if (oldEditor != null) { + oldEditor.dispose(); + } + + // Create a text field to do the editing + final Text text = new Text(dialogTree, SWT.NONE); + text.setText(treeItem.getText(column)); + text.selectAll(); + text.setFocus(); + + // If the text field loses focus, set its text into the + // tree and end the editing session + text.addFocusListener(new FocusAdapter() { + public void focusLost(FocusEvent event) { + treeItem.setText(column, text.getText()); + isDataModelDirty = true; + if (currentSubPage instanceof StaticSubPage) { + staticSubPage.updateJsonFromTree(); + } + text.dispose(); + } + }); + + // If they hit Enter, set the text into the tree and end + // the editing session. + // If they hit Escape, ignore the text and end the + // editing session + text.addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent event) { + switch (event.keyCode) { + case SWT.CR: + treeItem.setText(column, text.getText()); + if (currentSubPage instanceof StaticSubPage) { + staticSubPage.updateJsonFromTree(); + } + isDataModelDirty = true; + text.dispose(); + break; + case SWT.KEYPAD_CR: + // Enter hit--set the text into the tree and + // drop through + treeItem.setText(column, text.getText()); + if (currentSubPage instanceof StaticSubPage) { + staticSubPage.updateJsonFromTree(); + } + isDataModelDirty = true; + text.dispose(); + break; + case SWT.ESC: + // End editing session + text.dispose(); + break; + } + } + }); + + treeEditor.setEditor(text, treeItem, column); + } + } + } + }); + + // Add a key listener to the tree that listens for F2. If F2 is pressed, + // we do the editing + dialogTree.addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent event) { + // Make sure one and only one item is selected when F2 is + // pressed + if (event.keyCode == SWT.F2 && dialogTree.getSelectionCount() == 1) { + // Determine the item to edit + final TreeItem item = dialogTree.getSelection()[0]; + TreeItemData data = (TreeItemData) item.getData("TREEITEMDATA"); + + if (data.getSource().equals("original")) { + return; + } else if (!types.contains(data.getObjectType())) + return; + + Control oldEditor = treeEditor.getEditor(); + if (oldEditor != null) { + oldEditor.dispose(); + } + + // Create a text field to do the editing + final Text text = new Text(dialogTree, SWT.NONE); + text.setText(item.getText()); + text.selectAll(); + text.setFocus(); + + // If the text field loses focus, set its text into the tree + // and end the editing session + text.addFocusListener(new FocusAdapter() { + public void focusLost(FocusEvent event) { + item.setText(text.getText()); + isDataModelDirty = true; + text.dispose(); + if (currentSubPage instanceof StaticSubPage) { + staticSubPage.updateJsonFromTree(); + } + } + }); + + // If they hit Enter, set the text into the tree and end the + // editing session. + // If they hit Escape, ignore the text and end the editing + // session + text.addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent event) { + switch (event.keyCode) { + case SWT.CR: + case SWT.KEYPAD_CR: + // Enter hit--set the text into the tree and + // drop through + item.setText(text.getText()); + isDataModelDirty = true; + if (currentSubPage instanceof StaticSubPage) { + staticSubPage.updateJsonFromTree(); + } + text.dispose(); + break; + case SWT.ESC: + // End editing session + text.dispose(); + break; + } + } + }); + + // Set the text field into the editor + treeEditor.setEditor(text, item); + } + } + }); + + Transfer[] types = new Transfer[] { TextTransfer.getInstance() }; + int operations = DND.DROP_MOVE | DND.DROP_LINK; + + DragSource source = new DragSource(dialogTree, operations); + source.setTransfer(types); + //final TreeItem[] dragSourceItem = new TreeItem[1]; + // TODO: FIXME + /* + * source.addDragListener( new DragSourceListener() { public void + * dragStart( DragSourceEvent event ) { + * + * if( !( currentSubPage instanceof StaticSubPage || currentSubPage + * instanceof RemoteCallSubPage ) ){ event.detail = DND.DROP_NONE; + * event.doit = false; return; } + * + * TreeItem[] selection = dialogTree.getSelection(); event.doit = true; + * dragSourceItem[0] = selection[0]; }; + * + * public void dragSetData( DragSourceEvent event ) { event.data = + * dragSourceItem[0].getText(); } + * + * public void dragFinished( DragSourceEvent event ) { if ( event.detail + * == DND.DROP_MOVE ) dragSourceItem[0].dispose(); dragSourceItem[0] = + * null; } } ); + * + * DropTarget target = new DropTarget( dialogTree, operations ); + * target.setTransfer( types ); target.addDropListener( new + * DropTargetAdapter() { public void dragOver( DropTargetEvent event ) { + * event.feedback = DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL; + * + * if( dragSourceItem[0] == event.item ) { event.detail = DND.DROP_NONE; + * } + * + * if ( event.item != null ) { TreeItem item = (TreeItem) event.item; + * Point pt = dialogTree.getDisplay().map( null, dialogTree, event.x, + * event.y ); Rectangle bounds = item.getBounds(); + * + * TreeItem parentItem; + * + * if ( pt.y < bounds.y + bounds.height / 3 ) { event.feedback |= + * DND.FEEDBACK_INSERT_BEFORE; parentItem = item.getParentItem(); } else + * if ( pt.y > bounds.y + 2 * bounds.height / 3 ) { event.feedback |= + * DND.FEEDBACK_INSERT_AFTER; parentItem = item.getParentItem(); } else + * { event.feedback |= DND.FEEDBACK_SELECT; parentItem = item; } + * + * if( !checkValidation( parentItem ) ) event.detail = DND.DROP_NONE; + * else event.detail = DND.DROP_MOVE; } } + * + * public void drop( DropTargetEvent event ) { if ( event.data == null + * || dragSourceItem[0] == event.item ) { event.detail = DND.DROP_NONE; + * return; } TreeEditor editor = (TreeEditor) + * dragSourceItem[0].getData("TREEEDITORFORCOMBO"); + * + * if ( event.item == null ) { TreeItem item = new TreeItem( dialogTree, + * SWT.NONE ); copyAndDisposeItme( dragSourceItem[0], item, editor, true + * ); } else { TreeItem item = (TreeItem) event.item; Point pt = + * dialogTree.getDisplay().map( null, dialogTree, event.x, event.y ); + * Rectangle bounds = item.getBounds(); TreeItem parent = + * item.getParentItem(); if ( parent != null ) { TreeItem[] items = + * parent.getItems(); int index = 0; for ( int i = 0; i < items.length; + * i++ ) { if ( items[i] == item ) { index = i; break; } } if ( pt.y < + * bounds.y + bounds.height / 3 ) { TreeItem newItem = new TreeItem( + * parent, SWT.NONE, index ); copyAndDisposeItme( dragSourceItem[0], + * newItem, editor, true ); } else if ( pt.y > bounds.y + 2 * + * bounds.height / 3 ) { TreeItem newItem = new TreeItem( parent, + * SWT.NONE, index + 1 ); copyAndDisposeItme( dragSourceItem[0], + * newItem, editor, true ); } else { TreeItem newItem = new TreeItem( + * item, SWT.NONE ); copyAndDisposeItme( dragSourceItem[0], newItem, + * editor, true ); } + * + * } else { TreeItem[] items = dialogTree.getItems(); int index = 0; for + * ( int i = 0; i < items.length; i++ ) { if ( items[i] == item ) { + * index = i; break; } } if ( pt.y < bounds.y + bounds.height / 3 ) { + * TreeItem newItem = new TreeItem( dialogTree, SWT.NONE, index ); + * copyAndDisposeItme( dragSourceItem[0], newItem, editor, true ); } + * else if ( pt.y > bounds.y + 2 * bounds.height / 3 ) { TreeItem + * newItem = new TreeItem( dialogTree, SWT.NONE, index + 1 ); + * copyAndDisposeItme( dragSourceItem[0], newItem, editor, true ); } + * else { TreeItem newItem = new TreeItem( item, SWT.NONE ); + * copyAndDisposeItme( dragSourceItem[0], newItem, editor, true ); } } + * + * } + * + * isDataModelDirty = true; if( currentSubPage instanceof StaticSubPage + * ){ staticSubPage.updateJsonFromTree(); } } + * + * private boolean checkValidation( TreeItem parent ) { + * + * boolean result = true; List primitiveTypes = Arrays.asList( + * new String[]{ "String", "Number", "Boolean", "Undefined" } ); String + * sourceType = dragSourceItem[0].getText(2); + * + * if( parent == null && sourceType.equals( "Index" ) ) result = false; + * + * if( parent == null ) return result; + * + * String parentType = parent.getText(2); + * + * if( primitiveTypes.contains( parentType ) ) result = false; + * + * if( parentType.equals( sourceType ) && !sourceType.equals( "Object" ) + * ) result = false; + * + * if( parentType.equals( "Object" ) && sourceType.equals( "Index" ) ) + * result = false; + * + * if( parentType.equals( "Index" ) && ( sourceType.equals( "Index" ) || + * sourceType.equals( "Object" )) ) result = false; + * + * if( parentType.equals( "Array" ) && !sourceType.equals( "Index" ) ) + * result = false; + * + * return result; } } ); + */ + } + + private Group makeSettingGroup(Group settingGroup) { + + settingGroup.setText("Setting"); + + setttingStackLayout = new StackLayout(); + settingGroup.setLayout(setttingStackLayout); + + staticSubPage = new StaticSubPage(this, settingGroup, dialogTree); + remoteCallSubPage = new RemoteCallSubPage(this, settingGroup, dialogTree, project); + + callHistorySubPage = new CallHistorySubPage(this, settingGroup, dialogTree, project); + + contactSubPage = new ContactSubPage(this, settingGroup, dialogTree, project); + + currentSubPage = staticSubPage; + setttingStackLayout.topControl = staticSubPage.getSettingComposite(); + + sashForm.setWeights(new int[] { 2, 0 }); + sashForm.setSashWidth(0); + dataComposite.setParent(staticSubPage.getDataComposite()); + + staticSubPage.setButtonsState(dataButtonMap); + + return settingGroup; + } + + private void addItem() { + TreeItem parentItem = null; + + if (dialogTree.getSelection().length > 0) + parentItem = dialogTree.getSelection()[0]; + + String[] ableTypes = new String[] { "Object", "Array", "IndexObject" }; + + if (parentItem != null && !Arrays.asList(ableTypes).contains(parentItem.getText(2))) { + return; + } + + if (currentSubPage instanceof StaticSubPage && staticSubPage.getCurrentType().equals("XML") + && dialogTree.getItemCount() > 0 && parentItem == null) { + return; + } + + TreeItem item; + int index = 0; + + String type = "String"; + String value = "data"; + + if (parentItem == null) { + item = new TreeItem(dialogTree, SWT.NONE); + index = dialogTree.getItemCount(); + type = "Object"; + value = ""; + } else { + item = new TreeItem(parentItem, SWT.NONE); + index = parentItem.getItemCount(); + value += index; + } + + String key = "key" + index; + + if (parentItem != null && currentSubPage instanceof StaticSubPage && parentItem.getText(2).equals("Array")) { + if (parentItem.getItem(0).getText(2).equals("IndexObject")) { + type = "IndexObject"; + } else { + type = "Index"; + } + value = ""; + key = String.valueOf(parentItem.getItemCount() - 1); + } + + if (!type.equals("Index") && !type.equals("IndexObject")) + Helper.addComboInTreeItem(item, type, currentSubPage); + + item.setText(new String[] { key, value, type }); + + String imageName; + + if (type.equals("Array")) { + imageName = BuilderConstants.DATABINDING_ARRAY_ICON; + } else if (type.equals("Number")) { + imageName = BuilderConstants.DATABINDING_NUMBER_ICON; + } else if (type.equals("String")) { + imageName = BuilderConstants.DATABINDING_STRING_ICON; + } else if (type.equals("Index") || type.equals("IndexObject")) { + imageName = BuilderConstants.DATABINDING_INDEX_ICON; + } else if (type.equals("Object")) { + imageName = BuilderConstants.DATABINDING_OBJECT_ICON; + } else if (type.equals("Boolean")) { + imageName = BuilderConstants.DATABINDING_BOOLEAN_ICON; + } else { + imageName = BuilderConstants.DATABINDING_UNDEFINED_ICON; + } + + if (imageName != null) { + item.setImage(ResourceManager.getImage(BuilderConstants.ICON_DIR, imageName)); + } + + TreeItemData treeItemData = new TreeItemData(); + treeItemData.setSource("custom"); + treeItemData.setObjectType(type); + treeItemData.setObjectValue(value); + + item.setData("TREEITEMDATA", treeItemData); + + dialogTree.showItem(item); + + if (currentSubPage instanceof StaticSubPage) { + staticSubPage.updateJsonFromTree(); + } + } + + private void removeAllItems() { + TreeItem[] treeItems = dialogTree.getItems(); + if (treeItems.length != 0) { + for (TreeItem treeItem : treeItems) { + removeAllChildrenRecursively(treeItem); + } + + if (currentSubPage instanceof StaticSubPage) { + staticSubPage.updateJsonFromTree(); + } + } + } + + private void removeItem() { + TreeItem[] treeItems = dialogTree.getSelection(); + for (TreeItem treeItem : treeItems) { + removeAllChildrenRecursively(treeItem); + } + + if (currentSubPage instanceof StaticSubPage) { + staticSubPage.updateJsonFromTree(); + } + + // for redraw + dialogTree.setSize(dialogTree.getSize().x, dialogTree.getSize().y - 1); + dialogTree.setSize(dialogTree.getSize().x, dialogTree.getSize().y + 1); + } + + private void removeAllChildrenRecursively(TreeItem treeItem) { + TreeItem[] treeItems = treeItem.getItems(); + + if (treeItems.length != 0) { + for (TreeItem item : treeItems) { + removeAllChildrenRecursively(item); + } + } + //TreeItemData data = (TreeItemData) treeItem.getData("TREEITEMDATA"); + // TODO: FIXME + // if( data != null && data.getSource().equals( "original" ) && + // currentSubPage instanceof RemoteCallSubPage ) + // return; + + TreeEditor editor = (TreeEditor) treeItem.getData("TREEEDITORFORCOMBO"); + if (editor != null) { + editor.getEditor().dispose(); + editor.dispose(); + } + + if (treeItem.getText(2).equals("Index")) { + int idx = 0; + + TreeItem parentTreeItem = treeItem.getParentItem(); + if (parentTreeItem != null) { + for (TreeItem item : parentTreeItem.getItems()) { + if (item.equals(treeItem)) + continue; + + item.setText(0, String.valueOf(idx)); + idx++; + } + } + } + treeItem.dispose(); + } + + private void moveItem(boolean option) { + + if (dialogTree.getSelection().length > 0) { + + TreeItem selectedItem = dialogTree.getSelection()[0]; + TreeItem parentItem = selectedItem.getParentItem(); + int index = 0; + int total = 0; + + if (parentItem == null) { + index = dialogTree.indexOf(selectedItem); + total = dialogTree.getItemCount(); + } else { + index = parentItem.indexOf(selectedItem); + total = parentItem.getItemCount(); + } + + if ((option && index == 0) || (!option && index == total - 1)) + return; + + int targetIndex = 0; + + if (option) { + targetIndex = index - 1; + } else { + targetIndex = index + 2; + } + + TreeEditor editor = (TreeEditor) selectedItem.getData("TREEEDITORFORCOMBO"); + TreeItem targetItem; + + if (parentItem == null) { + targetItem = new TreeItem(dialogTree, SWT.NONE, targetIndex); + } else { + targetItem = new TreeItem(parentItem, SWT.NONE, targetIndex); + } + + for (int i = 0; i < dialogTree.getColumnCount(); i++) { + targetItem.setText(i, selectedItem.getText(i)); + } + + targetItem.setData("TREEITEMDATA", selectedItem.getData("TREEITEMDATA")); + + copyAndDisposeItme(selectedItem, targetItem, editor, true); + + if (currentSubPage instanceof StaticSubPage) { + staticSubPage.updateJsonFromTree(); + } + } + } + + private void copyAndDisposeItme(TreeItem sourceItem, TreeItem targetItem, TreeEditor editor, boolean isRedraw) { + + if (sourceItem == targetItem) + return; + + targetItem.setData("TREEITEMDATA", sourceItem.getData("TREEITEMDATA")); + targetItem.setData(sourceItem.getData()); + + for (int i = 0; i < dialogTree.getColumnCount(); i++) { + targetItem.setText(i, sourceItem.getText(i)); + targetItem.setImage(sourceItem.getImage()); + } + + if (editor != null) { + editor.setItem(targetItem); + targetItem.setData("TREEEDITORFORCOMBO", editor); + } + + for (TreeItem item : sourceItem.getItems()) { + TreeEditor subEditor = (TreeEditor) item.getData("TREEEDITORFORCOMBO"); + TreeItem subItem = new TreeItem(targetItem, SWT.NONE); + copyAndDisposeItme(item, subItem, subEditor, false); + } + + targetItem.setExpanded(sourceItem.getExpanded()); + + if (!sourceItem.isDisposed()) + sourceItem.dispose(); + + if (isRedraw) { + dialogTree.select(targetItem); + + for (Control control : dialogTree.getChildren()) { + control.redraw(); + } + } + } + + public boolean isDataModelDirty() { + return isDataModelDirty; + } + + public void setDataModelDirty(boolean isDataModelDirty) { + this.isDataModelDirty = isDataModelDirty; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/SourceDialogSubPage.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/SourceDialogSubPage.java new file mode 100644 index 0000000..7ab6173 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/SourceDialogSubPage.java @@ -0,0 +1,40 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.dialog; + +import java.util.Map; + +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingData; + +public interface SourceDialogSubPage { + + public BindingData getData(); + + public Composite getSettingComposite(); + + public void setButtonsState(Map dataButtonMap); + + public void loadData(BindingData dataModel); +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/StaticSubPage.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/StaticSubPage.java new file mode 100644 index 0000000..5cd1d69 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/dialog/StaticSubPage.java @@ -0,0 +1,667 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.dialog; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.util.Arrays; +import java.util.Map; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingData; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; +import org.tizen.efluibuilder.ui.view.databinding.utils.Helper; +import org.tizen.efluibuilder.ui.view.databinding.utils.ResourceManager; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +public class StaticSubPage implements SourceDialogSubPage { + + private Group parentGroup; + private Tree parentDataTree; + private Composite settingComposite; + private Composite dataComposite; + + private Text staticSourceText; + private Combo typeCombo; + + private String jsonFile; + private String temp; + private static Gson prettyGson; + private static Gson normalGson; + + private static String[] comboItems; + + static { + comboItems = new String[] { "JSON", "XML" }; + prettyGson = new GsonBuilder().setPrettyPrinting().serializeNulls().create(); + normalGson = new GsonBuilder().serializeNulls().create(); + } + + public StaticSubPage(SetSourcePage setSourcePage, Group dataGroup, Tree dialogTree) { + parentGroup = dataGroup; + parentDataTree = dialogTree; + } + + @Override + public BindingData getData() { + BindingData dataSource = (BindingData) PartUtil.createPart(PartType.DATASOURCE, LayoutSchemaConstants.DATASOURCE); + Object obj = null; + String compactData = ""; + String text = staticSourceText.getText(); + try { + if (typeCombo.getSelectionIndex() == 0) { + obj = normalGson.fromJson(text, JsonElement.class); + compactData = normalGson.toJson(obj); + } else { + obj = Helper.parseXML(text); + compactData = text.replaceAll(">\\s*<", "><").replace("\r\n", "").replace("\n", ""); + } + } catch (SAXException e) { + } + + if (obj == null) { + MessageBox messageBox = new MessageBox(staticSourceText.getShell(), SWT.ICON_ERROR); + messageBox.setText("Set Source Error"); + messageBox.setMessage("Error : Data is invalid."); + messageBox.open(); + return null; + } + + /* + * JsonObject root = new JsonObject(); TreeItem[] items = + * parentDataTree.getItems(); for (TreeItem item : items) { + * Helper.makeJsonFromTree(item, root); } + */ + + dataSource.setJsonData(compactData); + dataSource.setStaticFilePath(jsonFile); + dataSource.setSourceType(typeCombo.getText().toLowerCase()); + + return dataSource; + } + + @Override + public Composite getSettingComposite() { + if (settingComposite == null) { + createSettingComposite(); + } + + String inputText = staticSourceText.getText(); + + if (inputText.trim().length() > 0) { + + JsonElement json = null; + try { + + if (typeCombo.getSelectionIndex() == 0) + json = normalGson.fromJson(inputText, JsonElement.class); + else + json = Helper.getJsonFromXML(inputText); + + } catch (SAXException ex) { + } + + if (json != null) { + parentDataTree.removeAll(); + Helper.makeTreeItem(json, parentDataTree, null, true, this); + } + } + + return settingComposite; + } + + private void createSettingComposite() { + + settingComposite = new Composite(parentGroup, SWT.NONE); + settingComposite.setLayout(new FormLayout()); + + FormData data = new FormData(); + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(5, 0); + data.right = new FormAttachment(100, -5); + data.bottom = new FormAttachment(100, 0); + settingComposite.setLayoutData(data); + + SashForm sashForm = new SashForm(settingComposite, SWT.HORIZONTAL); + data = new FormData(); + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(100, 0); + data.bottom = new FormAttachment(100, 0); + sashForm.setLayoutData(data); + + Composite subSettingComposite = new Composite(sashForm, SWT.NONE); + subSettingComposite.setLayout(new FormLayout()); + + dataComposite = new Composite(sashForm, SWT.NONE); + dataComposite.setLayout(new FormLayout()); + + data = new FormData(); + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(5, 0); + data.right = new FormAttachment(100, 0); + data.bottom = new FormAttachment(100, 0); + dataComposite.setLayoutData(data); + + sashForm.setWeights(new int[] { 2, 3 }); + + Button formatButton = new Button(subSettingComposite, SWT.FLAT); + formatButton.setToolTipText("Formatted Data"); + formatButton.setImage(ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_FORMAT_STRING_ICON)); + + data = new FormData(29, 29); + data.top = new FormAttachment(2, 0); + data.left = new FormAttachment(2, 0); + + formatButton.setLayoutData(data); + + formatButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (typeCombo.getSelectionIndex() == 0) { + JsonElement jo = prettyGson.fromJson(staticSourceText.getText(), JsonElement.class); + staticSourceText.setData("editing", true); + staticSourceText.setText(prettyGson.toJson(jo)); + staticSourceText.setData("editing", false); + } else { + Document doc = null; + try { + doc = Helper.parseXML(staticSourceText.getText()); + } catch (SAXException e1) { + e1.printStackTrace(); + } + + if (doc == null) + return; + + staticSourceText.setData("editing", true); + staticSourceText.setText(Helper.getStringFromDocument(doc, true)); + staticSourceText.setData("editing", false); + } + } + }); + + Button compactButton = new Button(subSettingComposite, SWT.FLAT); + compactButton.setImage(ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_COMPACT_STRING_ICON)); + compactButton.setToolTipText("Compacted Data"); + + data = new FormData(29, 29); + data.top = new FormAttachment(2, 0); + data.left = new FormAttachment(formatButton, 2); + + compactButton.setLayoutData(data); + + compactButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (typeCombo.getSelectionIndex() == 0) { + JsonElement jo = normalGson.fromJson(staticSourceText.getText(), JsonElement.class); + staticSourceText.setData("editing", true); + staticSourceText.setText(normalGson.toJson(jo)); + staticSourceText.setData("editing", false); + } else { + staticSourceText.setData("editing", true); + staticSourceText.setText(staticSourceText.getText().replaceAll(">\\s*<", "><")); + staticSourceText.setData("editing", false); + } + } + }); + + Label typelabel = new Label(subSettingComposite, SWT.NONE); + typelabel.setText("Type"); + + data = new FormData(); + data.top = new FormAttachment(2, 0); + data.left = new FormAttachment(compactButton, 10); + + typelabel.setLayoutData(data); + + typeCombo = new Combo(subSettingComposite, SWT.SINGLE | SWT.BORDER | SWT.FLAT | SWT.READ_ONLY); + typeCombo.setItems(comboItems); + typeCombo.select(0); + + data = new FormData(90, 29); + data.top = new FormAttachment(2, 0); + data.left = new FormAttachment(typelabel, 5); + + typeCombo.setLayoutData(data); + + typeCombo.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + String source = staticSourceText.getText(); + + if (source.trim().length() == 0) + return; + + String result = ""; + JsonElement jo; + + try { + if (typeCombo.getSelectionIndex() == 0) { + jo = Helper.getJsonFromXML(source); + } else { + temp = staticSourceText.getText(); + jo = prettyGson.fromJson(source, JsonElement.class); + } + + if (jo == null) + return; + + if (typeCombo.getSelectionIndex() == 0) { + if (temp == null) + result = prettyGson.toJson(jo); + else + result = temp; + } else { + result = Helper.getStringFromDocument(Helper.getXMLFromJson(null, null, jo), true); + } + } catch (Exception e) { + MessageBox box = new MessageBox(typeCombo.getShell(), SWT.ERROR); + box.setText("Error"); + box.setMessage("Invalid data format. Unable to change data type.\n\nReason: " + e.getMessage()); + box.open(); + if (typeCombo.getSelectionIndex() == 0) + typeCombo.select(1); + else + typeCombo.select(0); + + return; + } + + if (result.length() == 0 || parentDataTree.getChildren().length == 0) { + staticSourceText.setText(result); + } else { + staticSourceText.setData("editing", true); + staticSourceText.setText(result); + staticSourceText.setData("editing", false); + } + } + }); + + Button clearButton = new Button(subSettingComposite, SWT.PUSH | SWT.FLAT); + clearButton.setImage(ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_CLEAR_ICON)); + clearButton.setToolTipText("Clear"); + + data = new FormData(29, 29); + data.top = new FormAttachment(2, 0); + data.right = new FormAttachment(100, -5); + + clearButton.setLayoutData(data); + clearButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + staticSourceText.setText(""); + } + }); + + final Button reloadFileButton = new Button(subSettingComposite, SWT.PUSH | SWT.FLAT); + reloadFileButton.setImage(ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_RELOAD_ICON)); + reloadFileButton.setToolTipText("Reload"); + + data = new FormData(29, 29); + data.top = new FormAttachment(2, 0); + data.right = new FormAttachment(clearButton, -2); + + reloadFileButton.setLayoutData(data); + + SelectionAdapter fileOpenSelectionAdapter = new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + + Button sourceButton = (Button) event.getSource(); + + if (sourceButton.getToolTipText().equals("Open")) { + FileDialog fileDialog = new FileDialog(parentGroup.getShell(), SWT.OPEN); + String file = fileDialog.open(); + + if (file == null) + return; + + jsonFile = file; + } + try { + + for (Control control : parentDataTree.getChildren()) { + control.dispose(); + } + parentDataTree.removeAll(); + staticSourceText.setText(Helper.streamToString(new FileInputStream(new File(jsonFile)))); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + }; + + reloadFileButton.addSelectionListener(fileOpenSelectionAdapter); + + Button saveAdButton = new Button(subSettingComposite, SWT.PUSH | SWT.FLAT); + saveAdButton.setImage(ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_SAVE_AS_ICON)); + saveAdButton.setToolTipText("Save AS"); + + data = new FormData(29, 29); + data.top = new FormAttachment(2, 0); + data.right = new FormAttachment(reloadFileButton, -2); + saveAdButton.setLayoutData(data); + + saveAdButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Shell shell = ((Control) e.getSource()).getShell(); + FileDialog fdl = new FileDialog(shell, SWT.SAVE); + String path = fdl.open(); + + if (path == null) + return; + + File file = new File(path); + + if (file.exists()) { + String msg = file.getAbsolutePath() + " File is exist.\nDo you want to overwrite ?"; + MessageBox messageBox = new MessageBox(shell, SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL); + messageBox.setText("Save As"); + messageBox.setMessage(msg); + + if (messageBox.open() != SWT.OK) + return; + } + + if (file.exists()) + file.delete(); + + BufferedWriter bw = null; + + try { + file.createNewFile(); + bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))); + bw.write(staticSourceText.getText()); + + bw.close(); + bw = null; + } catch (IOException e1) { + e1.printStackTrace(); + } finally { + if (bw != null) { + try { + bw.close(); + } catch (IOException e1) { + } + } + } + } + }); + + Button openFileButton = new Button(subSettingComposite, SWT.PUSH | SWT.FLAT); + openFileButton.setImage(ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_OPEN_ICON)); + openFileButton.setToolTipText("Open"); + + data = new FormData(29, 29); + data.top = new FormAttachment(2, 0); + data.right = new FormAttachment(saveAdButton, -2); + + openFileButton.setLayoutData(data); + openFileButton.addSelectionListener(fileOpenSelectionAdapter); + + Composite composite = new Composite(subSettingComposite, SWT.NONE); + + data = new FormData(390, 450); + data.top = new FormAttachment(formatButton, 2); + data.bottom = new FormAttachment(100, -2); + data.left = new FormAttachment(2, 0); + data.right = new FormAttachment(100, 8); + + composite.setLayoutData(data); + composite.setLayout(new FormLayout()); + // composite.setLayout( new FillLayout() ); + // MemoryEditorInput editorInput = + // new MemoryEditorInput( "MemFile", new ByteArrayInputStream( new + // byte[0] ) ); + // + // CompilationUnitEditor editor = new CompilationUnitEditor(); + // + // IEditorSite parentSite = + // PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() + // .getActiveEditor().getEditorSite(); + //// + //// WorkbenchPage workbrenchpage = + //// (WorkbenchPage) + // PlatformUI.getWorkbench().getActiveWorkbenchWindow() + //// .getActivePage(); + //// + //// EditorDescriptor desc = + //// (EditorDescriptor) PlatformUI.getWorkbench().getEditorRegistry() + //// .findEditor( PageDesigner.ID ); + //// + //// EditorReference reference = + //// new EditorReference( workbrenchpage.getEditorManager(), + // editorInput, desc ); + //// + //// EditorSite editorSite = new EditorSite( reference, editor, + // workbrenchpage, desc ); + //// editorSite.setActionBars( new SubActionBars( + // parentSite.getActionBars() ) ); + // + // try { + // editor.init( parentSite, editorInput ); + // } catch ( PartInitException e1 ) { + // e1.printStackTrace(); + // } + // + // editor.createPartControl( composite ); + // + // editor.setActionActivationCode( + // ITextEditorActionConstants.GROUP_UNDO, 'Z', SWT.CONTROL, SWT.DEFAULT + // ); + // staticSourceStyledText = editor.getViewer().getTextWidget(); + staticSourceText = new Text(composite, SWT.V_SCROLL | SWT.H_SCROLL); + + // staticSourceStyledText.addModifyListener(new ModifyListener() { + // public void modifyText(ModifyEvent event) { + // int maxLine = staticSourceStyledText.getLineCount(); + // int lineCountWidth = Math.max(String.valueOf(maxLine).length(), 3); + // + // StyleRange style = new StyleRange(); + // style.metrics = new GlyphMetrics(0, 0, lineCountWidth * 8 + 5); + // Bullet bullet = new Bullet(ST.BULLET_NUMBER, style); + // staticSourceStyledText.setLineBullet(0, + // staticSourceStyledText.getLineCount(), null); + // staticSourceStyledText.setLineBullet(0, + // staticSourceStyledText.getLineCount(), bullet); + // } + // }); + + data = new FormData(); + data.top = new FormAttachment(2, 0); + data.right = new FormAttachment(100, -10); + data.left = new FormAttachment(2, 0); + data.bottom = new FormAttachment(100, -2); + staticSourceText.setLayoutData(data); + + staticSourceText.setData("editing", false); + + final SourceDialogSubPage subPage = this; + staticSourceText.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + + String inputText = staticSourceText.getText(); + + if (staticSourceText.getData("editing") != null && (Boolean) staticSourceText.getData("editing")) + return; + + if (inputText.trim().length() == 0) { + for (Control control : parentDataTree.getChildren()) { + control.dispose(); + } + parentDataTree.removeAll(); + return; + } + + temp = null; + + JsonElement json = null; + try { + + if (typeCombo.getSelectionIndex() == 0) + json = normalGson.fromJson(inputText, JsonElement.class); + else + json = Helper.getJsonFromXML(inputText); + + } catch (SAXException ex) { + } + + if (json != null) { + TreeRefreshTask task = new TreeRefreshTask(subPage, json); + parentDataTree.setData("LAST_TASK", task); + parentDataTree.getDisplay().timerExec(800, task); + + } + } + }); + } + + class TreeRefreshTask implements Runnable { + + private JsonElement taskJson; + private SourceDialogSubPage subPage; + + TreeRefreshTask(SourceDialogSubPage currentSubPage, JsonElement taskJson) { + this.subPage = currentSubPage; + this.taskJson = taskJson; + } + + public void run() { + if (!parentDataTree.getData("LAST_TASK").equals(this)) + return; + + for (Control control : parentDataTree.getChildren()) { + control.dispose(); + } + + parentDataTree.removeAll(); + Helper.makeTreeItem(taskJson, parentDataTree, null, true, subPage); + } + } + + @Override + public void setButtonsState(Map dataButtonMap) { + dataButtonMap.get("addTreeItem").setEnabled(true); + dataButtonMap.get("upTreeItem").setEnabled(true); + dataButtonMap.get("downTreeItem").setEnabled(true); + dataButtonMap.get("removeTreeItem").setEnabled(true); + dataButtonMap.get("removeAllTreeItem").setEnabled(true); + + Button conversionTreeAndText = dataButtonMap.get("conversionTreeAndText"); + + if (conversionTreeAndText.getSelection()) { + conversionTreeAndText.setSelection(false); + Event e = new Event(); + e.item = conversionTreeAndText; + e.widget = conversionTreeAndText; + e.type = SWT.Selection; + conversionTreeAndText.notifyListeners(SWT.Selection, e); + } + + conversionTreeAndText.setVisible(false); + } + + @Override + public void loadData(BindingData dataModel) { + + jsonFile = dataModel.getStaticFilePath(); + + if (dataModel.getSourceType() != null) + typeCombo.select(Arrays.asList(comboItems).indexOf(dataModel.getSourceType().toUpperCase())); + + if (dataModel.getJsonData() != null) + staticSourceText.setText(dataModel.getJsonData()); + } + + public Composite getDataComposite() { + return dataComposite; + } + + public void updateJsonFromTree() { + if (parentDataTree.getItemCount() > 0) { + JsonObject root = new JsonObject(); + TreeItem[] items = parentDataTree.getItems(); + for (TreeItem item : items) { + Helper.makeJsonFromTree(item, root); + } + + staticSourceText.setData("editing", true); + temp = null; + try { + if (typeCombo.getSelectionIndex() == 0) + staticSourceText.setText(prettyGson.toJson(root)); + else + staticSourceText.setText(Helper.getStringFromDocument(Helper.getXMLFromJson(null, null, root), true)); + } catch (Exception e) { + staticSourceText.setText(""); + } + + staticSourceText.setData("editing", false); + + } else { + staticSourceText.setData("editing", true); + staticSourceText.setText(""); + staticSourceText.setData("editing", false); + } + } + + public String getCurrentType() { + return typeCombo.getText(); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/BindingData.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/BindingData.java new file mode 100644 index 0000000..8b5f0f9 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/BindingData.java @@ -0,0 +1,480 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.model; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.tizen.efluibuilder.model.part.DataBindingPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; + +public class BindingData extends Part { + + private String itemName; + private Map headers = new HashMap(); + private String runtimeApiName; + private String runtimeApiAddressBookID; + private String calendarName; + private String calendarType; + private String calendarID; + + public BindingData(String uniqueId, DataBindingPart parentPart, int type) { + super(uniqueId, parentPart, type); + } + + /** + * Sets a name. + * + * @param name + */ + public void setModelName(String name) { + this.setPropertyValue(BuilderConstants.ATTRIBUTE_MODEL_NAME, name); + } + + /** + * Gets a name. + * + * @return name + */ + public String getModelName() { + return getPropertyValue(BuilderConstants.ATTRIBUTE_MODEL_NAME); + } + + public String getItemName() { + return itemName; + } + + public void setItemName(String itemName) { + this.itemName = itemName; + } + + /** + * Sets a source name. + * + * @param sourceName + */ + public void setSourceName(String sourceName) { + this.setPropertyValue(BuilderConstants.ATTRIBUTE_DATASOURCE, sourceName); + } + + /** + * Gets a source name. + * + * @return source name + */ + public String getSourceName() { + return getPropertyValue(BuilderConstants.ATTRIBUTE_DATASOURCE); + } + + /** + * Sets a JSON data. + * + * @param jsonData + */ + public void setJsonData(String jsonData) { + this.setPropertyValue(BuilderConstants.ATTRIBUTE_JSONDATA, jsonData); + } + + /** + * Gets a JSON data. + * + * @return JSON data + */ + public String getJsonData() { + return getPropertyValue(BuilderConstants.ATTRIBUTE_JSONDATA); + } + + /** + * Sets a static file path. + * + * @param staticFilePath + */ + public void setStaticFilePath(String staticFilePath) { + this.setPropertyValue(BuilderConstants.ATTRIBUTE_FILEPATH, staticFilePath); + } + + /** + * @return static file path + */ + public String getStaticFilePath() { + return getPropertyValue(BuilderConstants.ATTRIBUTE_FILEPATH); + } + + /** + * Sets a model type. + * + * @param modelType + */ + public void setModelType(String modelType) { + this.setPropertyValue(BuilderConstants.ATTRIBUTE_MODELTYPE, modelType); + } + + /** + * Gets a model type. + * + * @return model type + */ + public String getModelType() { + return getPropertyValue(BuilderConstants.ATTRIBUTE_MODELTYPE); + } + + /** + * Sets a URL. + * + * @param url + */ + public void setURL(String url) { + this.setPropertyValue(BuilderConstants.ATTRIBUTE_URL, url); + } + + /** + * Gets a URL. + * + * @return URL + */ + public String getURL() { + return getPropertyValue(BuilderConstants.ATTRIBUTE_URL); + } + + /** + * Sets a method. + * + * @param method + */ + public void setMethod(String method) { + this.setPropertyValue(BuilderConstants.ATTRIBUTE_METHOD, method); + } + + /** + * Gets a method. + * + * @return method + */ + public String getMethod() { + return getPropertyValue(BuilderConstants.ATTRIBUTE_METHOD); + } + + /** + * Sets a proxy. + * + * @param proxy + */ + public void setProxy(String proxy) { + this.setPropertyValue(BuilderConstants.ATTRIBUTE_PROXY, proxy); + } + + /** + * Gets a proxy. + * + * @return proxy + */ + public String getProxy() { + return getPropertyValue(BuilderConstants.ATTRIBUTE_PROXY); + } + + /** + * Sets a query. + * + * @param query + */ + public void setQuery(String query) { + this.setPropertyValue(BuilderConstants.ATTRIBUTE_QUERY, query); + } + + /** + * Gets a query. + * + * @return query + */ + public String getQuery() { + return this.getPropertyValue(BuilderConstants.ATTRIBUTE_QUERY); + } + + /** + * Sets a source type. + * + * @param sourceType + */ + public void setSourceType(String sourceType) { + this.setPropertyValue(BuilderConstants.ATTRIBUTE_SOURCE_TYPE, sourceType); + } + + /** + * Gets a source type. + * + * @return source type + */ + public String getSourceType() { + return this.getPropertyValue(BuilderConstants.ATTRIBUTE_SOURCE_TYPE); + } + + /** + * Sets a timeout. + * + * @param timeout + */ + public void setTimeout(String timeout) { + this.setPropertyValue(BuilderConstants.ATTRIBUTE_TIMEOUT, timeout); + } + + /** + * Gets a timeout. + * + * @return timeout + */ + public String getTimeout() { + return this.getPropertyValue(BuilderConstants.ATTRIBUTE_TIMEOUT); + } + + /** + * Sets polling Interval + * + * @param pollingInterval + */ + public void setPollingInterval(String pollingInterval) { + this.setPropertyValue(BuilderConstants.ATTRIBUTE_POLLING_INTERVAL, pollingInterval); + } + + /** + * Gets polling interval + * + * @return pollingInterval + */ + public String getPollingInterval() { + return this.getPropertyValue(BuilderConstants.ATTRIBUTE_POLLING_INTERVAL); + } + + /** + * Sets a runtime API name. + * + * @param runtimeApiName + */ + public void setRuntimeApiName(String runtimeApiName) { + this.runtimeApiName = runtimeApiName; + } + + /** + * Gets a runtime API name. + * + * @return runtime API name + */ + public String getRuntimeApiName() { + return runtimeApiName; + } + + /** + * Remove a view model object. + * + * @param observableObject + */ + public void removeDataModelObject(BindingObject observableObject) { + removeChild(observableObject); + } + + /** + * Clear view model objects. + */ + public void clearDataModelObjects() { + clearChildrenBindingObjects(); + } + + public void clearChildrenBindingObjects() { + for (Part child : getChildren()) { + removeChild(child); + } + } + + public List getBindingObjects() { + List bindingObjects = new ArrayList(); + for (Part child : getChildren()) { + bindingObjects.add((BindingObject) child); + } + return bindingObjects; + } + + /** + * Gets a Runtime API Address Book ID. + * + * @return runtimeApiAddressBookID + */ + public String getRuntimeApiAddressBookID() { + return runtimeApiAddressBookID; + } + + /** + * Sets a Runtime API Address Book ID. + * + * @param runtimeApiAddressBookID + */ + public void setRuntimeApiAddressBookID(String runtimeApiAddressBookID) { + this.runtimeApiAddressBookID = runtimeApiAddressBookID; + } + + /** + * Gets a CallHistory Type. + * + * @return callHistoryType + */ + public String getCallHistoryType() { + return getPropertyValue(BuilderConstants.ATTRIBUTE_CALL_HISTORY_TYPE); + } + + /** + * Sets a CallHistory Type. + * + * @param callHistoryType + */ + public void setCallHistoryType(String callHistoryType) { + this.setPropertyValue(BuilderConstants.ATTRIBUTE_CALL_HISTORY_TYPE, callHistoryType); + } + + /** + * Gets a CallHistory Direction. + * + * @return callHistoryDirection + */ + public String getCallHistoryDirection() { + return getPropertyValue(BuilderConstants.ATTRIBUTE_CALL_HISTORY_DIRECTION); + } + + /** + * Sets a CallHistory Direction. + * + * @param callHistoryDirection + */ + public void setCallHistoryDirection(String callHistoryDirection) { + this.setPropertyValue(BuilderConstants.ATTRIBUTE_CALL_HISTORY_DIRECTION, callHistoryDirection); + } + + /** + * Gets a CallHistory Start Time Order. + * + * @return callHistoryStartTimeOrder + */ + public String getCallHistoryStartTimeOrder() { + return getPropertyValue(BuilderConstants.ATTRIBUTE_CALL_HISTORY_START_TIME_ORDER); + } + + /** + * Sets a CallHistory Start Time Order. + * + * @param callHistoryStartTimeOrder + */ + public void setCallHistoryStartTimeOrder(String callHistoryStartTimeOrder) { + this.setPropertyValue(BuilderConstants.ATTRIBUTE_CALL_HISTORY_START_TIME_ORDER, callHistoryStartTimeOrder); + } + + /** + * Gets a CallHistory Start Time Order. + * + * @return callHistoryStartTimeOrder + */ + public String getCalendarName() { + return calendarName; + } + + /** + * Sets a Calendar Name. + * + * @param calendarName + */ + public void setCalendarName(String calendarName) { + this.calendarName = calendarName; + } + + /** + * Gets a CallHistory Start Time Order. + * + * @return callHistoryStartTimeOrder + */ + public String getCalendarType() { + return calendarType; + } + + /** + * Sets a Calendar Type. + * + * @param calendarType + */ + public void setCalendarType(String calendarType) { + this.calendarType = calendarType; + } + + /** + * Gets a Calendar ID. + * + * @return calendarID + */ + public String getCalendarID() { + return calendarID; + } + + /** + * Sets a Calendar ID. + * + * @param calendarID + */ + public void setCalendarID(String calendarID) { + this.calendarID = calendarID; + } + + public Map getHeaders() { + return headers; + } + + /** + * Clear header informations. + */ + public void clearHeaderInfos() { + if (this.headers != null) { + this.headers.clear(); + } + } + + public void addAllHeaderInfos(Map headers) { + clearHeaderInfos(); + if (this.headers != null) { + this.headers.putAll(headers); + } + } + + public String getHeadersString() { + return this.getPropertyValue(BuilderConstants.ATTRIBUTE_HEADERS); + } + + public void setHeadersString(String headersString) { + this.setPropertyValue(BuilderConstants.ATTRIBUTE_HEADERS, headersString); + } + + public String getRemoteCallRequestType() { + return this.getPropertyValue(BuilderConstants.ATTRIBUTE_REMOTE_CALL_REQUEST_TYPE); + } + + public void setRemoteCallRequestType(String remoteCallRequestType) { + this.setPropertyValue(BuilderConstants.ATTRIBUTE_REMOTE_CALL_REQUEST_TYPE, remoteCallRequestType); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/BindingDataSet.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/BindingDataSet.java new file mode 100644 index 0000000..5978e5d --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/BindingDataSet.java @@ -0,0 +1,503 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.model; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.swt.widgets.Display; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingDataSetEvent.BindingDataSetEventType; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; + +public class BindingDataSet { + + private Part dataBindingPart = null; + + private List listeners = new ArrayList(); + private List removeListeners = new ArrayList(); + private boolean processEventFlag = false; + + public BindingDataSet(Part root) { + dataBindingPart = root; + } + + public void initDataSource(BindingData dataSource) { + dataBindingPart.insertChildBefore(dataSource, null); + } + + public void initDataModel(BindingData dataModel) { + dataBindingPart.insertChildBefore(dataModel, null); + } + + public void addDataSource(BindingData dataSource, Part nextSibling) { + dataBindingPart.insertChildBefore(dataSource, nextSibling); + fireEvent(new BindingDataSetEvent(BindingDataSetEventType.DATASOURCE_ADDED, dataSource, 0, null)); + } + + public void renameDataSource(BindingData dataSource, String newName) { + String oldName = dataSource.getSourceName(); + dataSource.setSourceName(newName); + fireEvent(new BindingDataSetEvent(BindingDataSetEventType.DATASOURCE_RENAMED, dataSource, newName, oldName)); + } + + public void removeDataSource(BindingData dataSource) { + dataBindingPart.removeChild(dataSource); + fireEvent(new BindingDataSetEvent(BindingDataSetEventType.DATASOURCE_REMOVED, dataSource, getNumberOfDataSources() - 1, null)); + } + + // Data Model Handling + public void addDataModel(BindingData dataModel, Part nextSibling) { + dataBindingPart.insertChildBefore(dataModel, nextSibling); + fireEvent(new BindingDataSetEvent(BindingDataSetEventType.DATAMODEL_ADDED, dataModel, getNumberOfDataModels() - 1, null)); + } + + public BindingData getDataModelByItemName(String name) { + List viewModels = getDataModels(); + for (BindingData viewModel : viewModels) { + if (viewModel.getItemName().equals(name)) { + return viewModel; + } + } + return null; + } + + public BindingData getDataModelByModelName(String name) { + List viewModels = getDataModels(); + for (BindingData viewModel : viewModels) { + if (viewModel.getModelName().equals(name)) { + return viewModel; + } + } + return null; + } + + public void addDataModelItem(BindingData dataModelToBeChanged, List bindingObjectItemPath, String bindingObjectItemName, String value) { + List dataModels = getDataModels(); + for (BindingData dataModel : dataModels) { + if (dataModel.equals(dataModelToBeChanged)) { + BindingObject viewModelObject = getDataModelObject(dataModelToBeChanged, bindingObjectItemPath); + if (viewModelObject != null) { + // addChildViewModelObject(viewModelObject, + // bindingObjectItemName, value); + } else if (bindingObjectItemName != null) { + // addChildViewModelObject(dataModelToBeChanged, + // bindingObjectItemName, value); + } + fireEvent(new BindingDataSetEvent(BindingDataSetEventType.DATAMODEL_ITEM_ADDED, dataModel, value, getNumberOfDataModels() - 1, null)); + } + } + } + + public void removeDataModelItems(BindingData dataModelToBeChanged, List bindingObjectItemPath, String bindingObjectItemName, String value) { + List dataModels = getDataModels(); + for (BindingData dataModel : dataModels) { + if (dataModel.equals(dataModelToBeChanged)) { + List itemPath = new ArrayList(); + for (int i = 1; i < bindingObjectItemPath.size(); i++) { + itemPath.add(bindingObjectItemPath.get(i)); + } + List parentDataModelBindingObjects = getBindingObjectsList(dataModelToBeChanged, itemPath); + if (parentDataModelBindingObjects != null && parentDataModelBindingObjects.size() > 0) { + for (BindingObject parentDataModelBindingObject : parentDataModelBindingObjects) { + removeChildDataModelObject(parentDataModelBindingObject, bindingObjectItemName, value); + } + } else if (bindingObjectItemName != null) { + removeChildDataModelObject(dataModelToBeChanged, bindingObjectItemName, value); + } else { + // TODO remove? + removeAllChildDataModelObject(dataModelToBeChanged); + } + fireEvent(new BindingDataSetEvent(BindingDataSetEventType.DATAMODEL_ITEM_REMOVED, dataModel, value, -1, null)); + } + } + } + + public List getBindingObjectsList(BindingData bindingData, List itemPath) { + if (itemPath == null) { + return null; + } + List copyItemPath = new ArrayList<>(); + copyItemPath.addAll(itemPath); + String sourceName = bindingData.getPropertyValue(BuilderConstants.ATTRIBUTE_DATASOURCE); + if (sourceName != null && !sourceName.isEmpty()) { + BindingData dataSource = getDataSource(sourceName); + if (dataSource != null && dataSource.getSourceType().equals(BuilderConstants.JSON)) { + copyItemPath.remove(copyItemPath.size() - 2); + } + } + if (copyItemPath.size() < 2) { + return null; + } + + List objects = new ArrayList<>(); + List viewModelObjects = bindingData.getBindingObjects(); + int i = copyItemPath.size() - 1; + String name = copyItemPath.get(i - 1); + for (BindingObject modelObject : viewModelObjects) { + if (modelObject.getValueType().equals("IndexObject")) { + for (BindingObject obj : modelObject.getBindingObjects()) { + if (obj.getName().equals(name)) { + addObjectToList(obj, copyItemPath, objects, i - 2); + } + } + } else { + if (modelObject.getName().equals(name)) { + addObjectToList(modelObject, copyItemPath, objects, i - 2); + } + } + } + return objects; + } + + private void addObjectToList(BindingObject bindingObj, List itemPath, List listObj, int i){ + String name = null; + if(i < 0) { + name = itemPath.get(i+1); + if(bindingObj.getName().equals(name)) + listObj.add(bindingObj); + return; + } + name = itemPath.get(i); + List viewModelObjects = bindingObj.getBindingObjects(); + for (BindingObject modelObject : viewModelObjects) { + if(modelObject.getValueType().equals("IndexObject")){ + for (BindingObject obj : modelObject.getBindingObjects()) { + if (obj.getName().equals(name)) { + addObjectToList(obj, itemPath, listObj, i-1); + } + } + } else { + if (modelObject.getName().equals(name)) { + addObjectToList(modelObject, itemPath, listObj, i-1); + } + } + } + } + + public void addDataModelItems(BindingData bindingData, List nextSiblings, List itemPath, List dataModelObject, String value) { + List viewModels = getDataModels(); + int index = 0; + for (BindingData viewModel : viewModels) { + if (viewModel.equals(bindingData)) { + List bindingObjectItemPath = new ArrayList(); + for (int i = 1; i < itemPath.size(); i++) { + bindingObjectItemPath.add(itemPath.get(i)); + } + List viewModelParentObjects = getBindingObjectsList(bindingData, bindingObjectItemPath); + if (viewModelParentObjects != null && viewModelParentObjects.size() > 0) { + for (BindingObject viewModelParentObject : viewModelParentObjects) { + if(viewModelParentObject.getValueType().equals("Array")){ + for (BindingObject obj : viewModelParentObject.getBindingObjects()) { + obj.insertChildBefore(dataModelObject.get(index), nextSiblings.get(index)); + index++; + } + } else { + viewModelParentObject.insertChildBefore(dataModelObject.get(index), nextSiblings.get(index)); + index++; + } + } + } else { + bindingData.insertChildBefore(dataModelObject.get(index), nextSiblings.get(index)); + index++; + } + } + fireEvent(new BindingDataSetEvent(BindingDataSetEventType.DATAMODEL_ITEM_ADDED, viewModel, value, getNumberOfDataModels() - 1, null)); + } + } + + public void setDataModel(BindingData dataModel, BindingData newDataModel) { + Part nextSibling = dataModel.getNextSibling(); + dataBindingPart.removeChild(dataModel); + dataBindingPart.insertChildBefore(newDataModel, nextSibling); + fireEvent(new BindingDataSetEvent(BindingDataSetEventType.DATAMODEL_SET_DATASOURCE, newDataModel, null, getNumberOfDataModels() - 1, null)); + } + + public void unlinkDataModel(BindingData dataModel, BindingData newDataModel) { + fireEvent(new BindingDataSetEvent(BindingDataSetEventType.DATAMODEL_CHANGED, newDataModel, null, getNumberOfDataModels() - 1, null)); + } + + public void renameDataModel(BindingData bindingData, String newName) { + String oldName = bindingData.getModelName(); + bindingData.setModelName(newName); + fireEvent(new BindingDataSetEvent(BindingDataSetEventType.DATAMODEL_RENAMED, bindingData, newName, oldName)); + } + + public void renameDataModelItems(BindingData bindingData, String newName, List itemPath) { + BindingObject viewModelObject = getDataModelObject(bindingData, itemPath); + + if (viewModelObject != null) + viewModelObject.setName(newName); + + StringBuffer oldPath = new StringBuffer(); + for (int i = itemPath.size() - 1; i >= 0; i--) { + if (oldPath.length() > 0) { + oldPath.append("."); + } + oldPath.append(itemPath.get(i)); + } + + StringBuffer newPath = new StringBuffer(); + for (int i = itemPath.size() - 1; i >= 1; i--) { + if (newPath.length() > 0) { + newPath.append("."); + } + newPath.append(itemPath.get(i)); + } + newPath.append("." + newName); + fireEvent(new BindingDataSetEvent(BindingDataSetEventType.DATAMODEL_ITEM_RENAMED, bindingData, newPath.toString(), oldPath.toString())); + } + + public BindingObject getDataModelObject(BindingData bindingData, List itemPath) { + List viewModelObjects = bindingData.getBindingObjects(); + BindingObject object = null; + List modelPath = new ArrayList(); + + if ((itemPath == null) || (itemPath.isEmpty())) { + return null; + } + + for (String path : itemPath) { + modelPath.add(path); + } + + if (modelPath.isEmpty()) { + return null; + } + + modelPath.remove(modelPath.size() - 1); + for (int i = 0; i < modelPath.size(); i++) { + String name = modelPath.get(modelPath.size() - 1); + modelPath.remove(modelPath.size() - 1); + for (BindingObject modelObject : viewModelObjects) { + if (modelObject.getName().equals(name)) { + object = getDataModelObject(modelObject, modelPath); + if (object == null) { + object = modelObject; + } + } + } + } + return object; + } + + private BindingObject getDataModelObject(BindingObject viewModelObject, List itemPath) { + List subViewModelObjects = viewModelObject.getBindingObjects(); + BindingObject object = null; + + for (int i = 0; i < itemPath.size(); i++) { + String name = itemPath.get(itemPath.size() - 1); + itemPath.remove(itemPath.size() - 1); + for (BindingObject subViewModelObject : subViewModelObjects) { + if (subViewModelObject.getName().equals(name)) { + object = getDataModelObject(subViewModelObject, itemPath); + if (object == null) { + object = subViewModelObject; + } + } + } + } + return object; + } + + public void removeDataModel(BindingData bindingData) { + dataBindingPart.removeChild(bindingData); + fireEvent(new BindingDataSetEvent(BindingDataSetEventType.DATAMODEL_REMOVED, bindingData, 0, null)); + } + + private void removeChildDataModelObject(BindingObject dataModelObject, String childName, String value) { + for (BindingObject object : dataModelObject.getBindingObjects()) { + if(object.getValueType().equals("IndexObject")){ + for (BindingObject obj : object.getBindingObjects()) { + if (obj.getName().equals(childName)) { + object.removeChild(obj); + break; + } + } + } else { + if (object.getName().equals(childName)) { + dataModelObject.removeChild(object); + break; + } + } + } + } + + private void removeChildDataModelObject(BindingData bindingData, String childName, String value) { + for (BindingObject object : bindingData.getBindingObjects()) { + if (object.getName().equals(childName)) { + bindingData.removeDataModelObject(object); + break; + } + } + } + + private void removeAllChildDataModelObject(BindingData bindingData) { + bindingData.clearDataModelObjects(); + bindingData.setSourceName(null); + } + + private void fireEvent(final BindingDataSetEvent bindingDataEvent) { + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + fireEvent(bindingDataEvent, listeners); + } + }); + } + + private void fireEvent(BindingDataSetEvent bindingEvent, List listeners) { + Iterator itr = listeners.iterator(); + IBindingDataSetListener listener = null; + + processEventFlag = true; + while (itr.hasNext()) { + listener = itr.next(); + switch (bindingEvent.getType()) { + case DATASOURCE_ADDED: + listener.dataSourceAdded(bindingEvent); + break; + case DATASOURCE_RENAMED: + listener.dataSourceRenamed(bindingEvent); + break; + case DATASOURCE_REMOVED: + listener.dataSourceRemoved(bindingEvent); + break; + case DATASOURCE_CHANGED: + listener.dataSourceChanged(bindingEvent); + break; + case ALL_DATAMODEL_RESETED: + listener.allDataModelReseted(bindingEvent); + break; + case DATAMODEL_ADDED: + listener.dataModelAdded(bindingEvent); + break; + case DATAMODEL_REMOVED: + listener.dataModelRemoved(bindingEvent); + break; + case DATAMODEL_RENAMED: + listener.dataModelRenamed(bindingEvent); + break; + case DATAMODEL_MOVED: + listener.dataModelMoved(bindingEvent); + break; + case DATAMODEL_CHANGED: + case DATAMODEL_SET_DATASOURCE: + case DATAMODEL_ITEM_ADDED: + case DATAMODEL_ITEM_REMOVED: + listener.dataModelChanged(bindingEvent); + break; + case DATAMODEL_ITEM_RENAMED: + listener.dataModelItemRenamed(bindingEvent); + break; + + default: + break; + } + } + processEventFlag = false; + + if (!removeListeners.isEmpty()) { + for (IBindingDataSetListener removeListener : removeListeners) { + listeners.remove(removeListener); + } + removeListeners.clear(); + } + } + + public void addBindingDataListener(IBindingDataSetListener listener) { + listeners.add(listener); + } + + public void removeBindingDataListener(IBindingDataSetListener listener) { + if (!processEventFlag) { + listeners.remove(listener); + } else { + removeListeners.add(listener); + } + } + + public List getDataModels() { + List dataModels = new ArrayList<>(); + for (Part child : dataBindingPart.getChildren()) { + if (child.getType() == PartType.DATAMODEL) { + dataModels.add((BindingData) child); + } + } + return dataModels; + } + + public int getNumberOfDataModels() { + int size = 0; + for (Part child : dataBindingPart.getChildren()) { + if (child.getType() == PartType.DATAMODEL) { + size++; + } + } + return size; + } + + public List getDataSources() { + List dataSources = new ArrayList<>(); + for (Part child : dataBindingPart.getChildren()) { + if (child.getType() == PartType.DATASOURCE) { + dataSources.add((BindingData) child); + } + } + return dataSources; + } + + public int getNumberOfDataSources() { + int size = 0; + for (Part child : dataBindingPart.getChildren()) { + if (child.getType() == PartType.DATASOURCE) { + size++; + } + } + return size; + } + + public BindingData getDataSource(String name) { + for (Part child : dataBindingPart.getChildren()) { + if (child instanceof BindingData && child.getType() == PartType.DATASOURCE && ((BindingData) child).getItemName().equals(name)) { + return (BindingData) child; + } + } + return null; + } + + public Part getNextSiblingToAddDataSource() { + Part dataModel = null; + for (Part bindingData : dataBindingPart.getChildren()) { + if (bindingData.getDescriptorId().equals(LayoutSchemaConstants.DATAMODEL)) { + dataModel = bindingData; + break; + } + } + return dataModel; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/BindingDataSetEvent.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/BindingDataSetEvent.java new file mode 100644 index 0000000..a13b23a --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/BindingDataSetEvent.java @@ -0,0 +1,84 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.model; + +public class BindingDataSetEvent { + + public enum BindingDataSetEventType { + ALL_DATASOURCE_RESETED, DATASOURCE_ADDED, DATASOURCE_REMOVED, DATASOURCE_RENAMED, DATASOURCE_MOVED, ALL_DATAMODEL_RESETED, DATAMODEL_ADDED, DATAMODEL_REMOVED, DATAMODEL_RENAMED, DATAMODEL_MOVED, DATAMODEL_ITEM_ADDED, DATAMODEL_ITEM_REMOVED, DATAMODEL_ITEM_RENAMED, DATAMODEL_CHANGED, DATASOURCE_CHANGED, DATAMODEL_SET_DATASOURCE, DATAMODEL_UNLINK + } + + private BindingDataSetEventType type; + private BindingData bindingData; + private int index; + private String value; + private BindingData oldBindingData; + private String oldValue; + + public BindingDataSetEvent(BindingDataSetEventType type, BindingData bindingData, int index, BindingData oldBindingData) { + this.type = type; + this.bindingData = bindingData; + this.index = index; + this.oldBindingData = oldBindingData; + } + + public BindingDataSetEvent(BindingDataSetEventType type, BindingData bindingData, String value, int index, BindingData oldBindingData) { + this.type = type; + this.bindingData = bindingData; + this.value = value; + this.index = index; + this.oldBindingData = oldBindingData; + } + + public BindingDataSetEvent(BindingDataSetEventType type, BindingData bindingData, String value, String oldValue) { + this.type = type; + this.bindingData = bindingData; + this.value = value; + this.oldValue = oldValue; + } + + public BindingDataSetEventType getType() { + return type; + } + + public BindingData getBindingData() { + return bindingData; + } + + public int getIndex() { + return index; + } + + public String getValue() { + return value; + } + + public BindingData getOldBindingData() { + return oldBindingData; + } + + public String getOldValue() { + return oldValue; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/BindingObject.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/BindingObject.java new file mode 100644 index 0000000..93c6e72 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/BindingObject.java @@ -0,0 +1,132 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.model; + +import java.util.ArrayList; +import java.util.List; + +import org.tizen.efluibuilder.model.part.DataBindingPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; + +public class BindingObject extends Part { + + public BindingObject(String uniqueId, DataBindingPart _parentPart) { + super(uniqueId, _parentPart, PartType.BINDINGOBJECT); + } + + /** + * Sets a name. + * + * @param name + */ + public void setName(String name) { + this.setPropertyValue(BuilderConstants.ATTRIBUTE_NAME, name); + } + + /** + * Gets a name. + * + * @return name + */ + public String getName() { + return getPropertyValue(BuilderConstants.ATTRIBUTE_NAME); + } + + /** + * Sets a value. + * + * @param value + */ + public void setValue(String value) { + this.setPropertyValue(BuilderConstants.ATTRIBUTE_VALUE, value); + } + + /** + * Gets a value. + * + * @return value + */ + public String getValue() { + return getPropertyValue(BuilderConstants.ATTRIBUTE_VALUE); + } + + /** + * Sets a type. + * + * @param type + */ + public void setValueType(String type) { + this.setPropertyValue(BuilderConstants.ATTRIBUTE_TYPE, type); + } + + /** + * Gets a type. + * + * @return type + */ + public String getValueType() { + return getPropertyValue(BuilderConstants.ATTRIBUTE_TYPE); + } + + /** + * Get observableObjects. + * + * @return observableObjects + */ + public List getBindingObjects() { + List bindingObjects = new ArrayList(); + for (Part child : getChildren()) { + bindingObjects.add((BindingObject) child); + } + return bindingObjects; + } + + public BindingObject clone() { + BindingObject newObj = null; + try { + newObj = (BindingObject) super.clone(); + for (Part bindingObject : getChildren()) { + newObj.insertChildBefore(((BindingObject) bindingObject).clone(), null); + } + + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + return newObj; + } + + public String getPath() { + String path = getName(); + return path; + } + + public BindingData getOwnerBindingData() { + Part parent = this.getParent(); + while (!(parent instanceof BindingData)) { + parent = parent.getParent(); + } + return (BindingData) parent; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/DataBindingPartProperty.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/DataBindingPartProperty.java new file mode 100644 index 0000000..46d975f --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/DataBindingPartProperty.java @@ -0,0 +1,127 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.model; + +/** + * A property class. + */ +public class DataBindingPartProperty { + + /** + * Model name. + */ + private String modelName; + + /** + * Item Name + */ + private String viewName; + + /** + * Data Type binded + */ + private String dataType; + + /** + * Whether property value is changed. + */ + private boolean isChanged; + + /** + * Allowed binding type + */ + private String allowedBindingType; + + /** + * json OR xml + */ + private String sourceType; + + /** + * Constructor. + * + * @param name + * a property name + * @param value + * a property value + * @param defaultValue + * a default property value + */ + public DataBindingPartProperty(String modelName, String viewName, String dataType, String allowedBindingType, String sourceType) { + this.modelName = modelName; + this.viewName = viewName; + this.dataType = dataType; + this.allowedBindingType = allowedBindingType; + this.sourceType = sourceType; + isChanged = false; + } + + /** + * Gets a property name. + * + * @return property name + */ + public String getModelName() { + return modelName; + } + + /** + * Gets a property value. + * + * @return property value + */ + public String getViewItemName() { + return viewName; + } + + /** + * Gets a property defaultValue. + * + * @return property defaultValue + */ + public String getDataType() { + return dataType; + } + + /** + * Returns true if property value can be reset. + * + * @return true if property value can be reset, and + * false otherwise + */ + public boolean isChanged() { + return isChanged; + } + + public String getAllowedBindingType() { + return allowedBindingType; + } + + public void setAllowedBindingType(String allowedBindingType) { + this.allowedBindingType = allowedBindingType; + } + + public String getSourceType() { + return sourceType; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/IBindingDataSetListener.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/IBindingDataSetListener.java new file mode 100644 index 0000000..bf8c58c --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/IBindingDataSetListener.java @@ -0,0 +1,52 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.model; + +public interface IBindingDataSetListener { + + void allDataSourcesReseted(BindingDataSetEvent e); + + void dataSourceAdded(BindingDataSetEvent e); + + void dataSourceRemoved(BindingDataSetEvent e); + + void dataSourceRenamed(BindingDataSetEvent e); + + void dataSourceMoved(BindingDataSetEvent e); + + void dataSourceChanged(BindingDataSetEvent e); + + void allDataModelReseted(BindingDataSetEvent e); + + void dataModelAdded(BindingDataSetEvent e); + + void dataModelRemoved(BindingDataSetEvent e); + + void dataModelRenamed(BindingDataSetEvent e); + + void dataModelMoved(BindingDataSetEvent e); + + void dataModelChanged(BindingDataSetEvent e); + + void dataModelItemRenamed(BindingDataSetEvent e); +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/TreeItemData.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/TreeItemData.java new file mode 100644 index 0000000..9d655fe --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/TreeItemData.java @@ -0,0 +1,152 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.model; + +import java.util.ArrayList; +import java.util.List; + +public class TreeItemData { + + // For BindingData + private BindingData model; + + //For BindingObject + private String originModelName; + private String objectType; + private String objectValue; + private String source; //original or custom + private boolean isBinded = false; + private List selectionPath = new ArrayList(); + private String allowedBindingType; + + /** + * Gets a model. + * + * @return model + */ + public BindingData getModel() { + return model; + } + + /** + * Sets a model. + * + * @param dataModel + */ + public void setModel(BindingData dataModel) { + this.model = dataModel; + } + + public boolean getBindedValue() { + return isBinded; + } + + public void setBindedValue(boolean isBinded) { + this.isBinded = isBinded; + } + + /** + * Gets a origin model name. + * + * @return origin model name + */ + public String getOriginModelName() { + return originModelName; + } + + /** + * Sets a origin model name. + * + * @param originModelName + */ + public void setOriginModelName(String originModelName) { + this.originModelName = originModelName; + } + + /** + * Gets a object type. + * + * @return object type + */ + public String getObjectType() { + return objectType; + } + + /** + * Sets a object type. + * + * @param objectType + */ + public void setObjectType(String objectType) { + this.objectType = objectType; + } + + /** + * Gets a object value. + * + * @return object value + */ + public String getObjectValue() { + return objectValue; + } + + /** + * Sets a object value. + * + * @param objectValue + */ + public void setObjectValue(String objectValue) { + this.objectValue = objectValue; + } + + /** + * Gets a object source. + * + * @return String source + */ + public String getSource() { + return source; + } + + /** + * Sets a object source. + * + * @param source + */ + public void setSource(String source) { + this.source = source; + } + + public void setSelectionPath(List itemPath) { + selectionPath.clear(); + selectionPath.addAll(itemPath); + } + + public String getAllowedBindingType() { + return allowedBindingType; + } + + public void setAllowedBindingType(String allowedBindingType) { + this.allowedBindingType = allowedBindingType; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/WidgetDataSourceBindingView.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/WidgetDataSourceBindingView.java new file mode 100644 index 0000000..f62e58b --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/WidgetDataSourceBindingView.java @@ -0,0 +1,27 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.model; + +public class WidgetDataSourceBindingView { + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/command/ConfigureDataModelCommand.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/command/ConfigureDataModelCommand.java new file mode 100644 index 0000000..de6d55d --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/command/ConfigureDataModelCommand.java @@ -0,0 +1,177 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.model.command; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.gef.commands.Command; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingManager; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingData; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingDataSetEvent.BindingDataSetEventType; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingObject; + +public class ConfigureDataModelCommand extends Command { + private DataBindingManager dataBindingManager; + private BindingData dataModel; + private Part nextSibling; + private List itemPath; + private String childName; + private String value; + private BindingDataSetEventType type; + private List oldBindingObjects; + private List nextSiblings; + private BindingData newDataModel; + private String oldName; + + // For Data Model addition + // For Data Model deletion + public ConfigureDataModelCommand(BindingDataSetEventType type, DataBindingManager dataBindingManager, BindingData dataModel) { + super("Configure DataModel"); + this.type = type; + this.dataBindingManager = dataBindingManager; + this.dataModel = dataModel; + } + + // For DataModelItem deletion + public ConfigureDataModelCommand(BindingDataSetEventType type, DataBindingManager dataBindingManager, BindingData bindingData, List itemPath, String childName) { + super("Configure DataModelItem"); + this.type = type; + this.dataBindingManager = dataBindingManager; + this.dataModel = bindingData; + this.itemPath = itemPath; + this.childName = childName; + } + + // For DataModel Renaming + public ConfigureDataModelCommand(BindingDataSetEventType type, DataBindingManager dataBindingManager, BindingData dataModel, String newValue) { + super("Configure DataModel"); + this.type = type; + this.dataBindingManager = dataBindingManager; + this.dataModel = dataModel; + this.value = newValue; + } + + public ConfigureDataModelCommand(BindingDataSetEventType type, DataBindingManager dataBindingManager, BindingData bindingData, List itemPath, String childName, String value, int index) { + super("Configure DataModel"); + this.type = type; + this.dataBindingManager = dataBindingManager; + this.dataModel = bindingData; + this.itemPath = itemPath; + this.childName = childName; + this.value = value; + } + + // For Setting DataModel + public ConfigureDataModelCommand(BindingDataSetEventType type, DataBindingManager dataBindingManager, BindingData dataModelTobeReplaced, BindingData newDataModel) { + super("Configure DataModel"); + this.type = type; + this.dataBindingManager = dataBindingManager; + this.dataModel = dataModelTobeReplaced; + this.newDataModel = newDataModel; + } + + @Override + public boolean canExecute() { + if ((dataBindingManager == null)) { + return false; + } else { + return true; + } + } + + @Override + public void execute() { + if (canExecute()) { + switch(type){ + case DATAMODEL_ADDED: + dataBindingManager.addDataModel(dataModel, null); + break; + case DATAMODEL_REMOVED: + nextSibling = dataModel.getNextSibling(); + dataBindingManager.removeDataModel(dataModel); + break; + case DATAMODEL_RENAMED: + oldName = dataModel.getModelName(); + dataBindingManager.renameDataModel(dataModel, value); + break; + case DATAMODEL_SET_DATASOURCE: + dataBindingManager.setDataModel(dataModel, newDataModel); + break; + case DATAMODEL_ITEM_REMOVED: + nextSiblings = new ArrayList(); + oldBindingObjects = dataBindingManager.getDataModelObjects(dataModel, itemPath); + if(oldBindingObjects != null) { + for (BindingObject obj : oldBindingObjects) { + nextSiblings.add(obj.getNextSibling()); + } + } + dataBindingManager.removeDataModelItems(dataModel, itemPath, childName, value); + break; + case DATAMODEL_ITEM_ADDED: + dataBindingManager.addDataModelItem(dataModel, itemPath, childName, value); + itemPath.add(0, childName); + break; + case DATAMODEL_ITEM_RENAMED: + BindingObject bo = dataBindingManager.getDataModelObject(dataModel, itemPath); + if (bo != null) { + oldName = bo.getName(); + dataBindingManager.renameDataModelItems(dataModel, value, itemPath); + itemPath.remove(0); + itemPath.add(0, value); + } + break; + case DATAMODEL_UNLINK: + dataBindingManager.unlinkDataModel(dataModel, newDataModel); + break; + default: + break; + } + } + } + + @Override + public void undo() { + switch (type) { + case DATAMODEL_ADDED: + dataBindingManager.removeDataModel(dataModel); + break; + case DATAMODEL_REMOVED: + dataBindingManager.addDataModel(dataModel, nextSibling); + break; + case DATAMODEL_SET_DATASOURCE: + dataBindingManager.setDataModel(newDataModel, dataModel); + break; + case DATAMODEL_RENAMED: + dataBindingManager.renameDataModel(dataModel, oldName); + break; + case DATAMODEL_ITEM_REMOVED: + dataBindingManager.addDataModelItems(dataModel, nextSiblings, itemPath, oldBindingObjects, value); + break; + default: + break; + } + super.undo(); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/command/ConfigureDataSourceCommand.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/command/ConfigureDataSourceCommand.java new file mode 100644 index 0000000..7ba25f1 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/command/ConfigureDataSourceCommand.java @@ -0,0 +1,138 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.model.command; + +import java.util.List; + +import org.eclipse.gef.commands.Command; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingManager; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingData; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingDataSetEvent.BindingDataSetEventType; + +public class ConfigureDataSourceCommand extends Command { + private BindingData originalDataSource; + private BindingData dataSource; + private DataBindingManager dataBindingManager; + private BindingDataSetEventType type; + private Part nextSibling; + private String value; + private String oldName; + + // For Adding DataSource + // For Removing DataSource + // For Editing DataSource + public ConfigureDataSourceCommand(BindingDataSetEventType type, DataBindingManager dataBindingManager, BindingData dataSource) { + super("Configure DataSource"); + this.dataSource = dataSource; + this.dataBindingManager = dataBindingManager; + this.type = type; + } + + // For Renaming DataSource + public ConfigureDataSourceCommand(BindingDataSetEventType type, DataBindingManager dataBindingManager, BindingData bindingData, String value) { + super("Configure DataSource"); + this.type = type; + this.dataBindingManager = dataBindingManager; + this.dataSource = bindingData; + this.value = value; + } + + @Override + public void execute() { + switch (type) { + case DATASOURCE_ADDED: + nextSibling = dataBindingManager.getNextSiblingToAddDataSource(); + dataBindingManager.addDataSource(dataSource, nextSibling); + break; + case DATASOURCE_RENAMED: + oldName = dataSource.getSourceName(); + dataBindingManager.renameDataSource(dataSource, value); + break; + case DATASOURCE_REMOVED: + nextSibling = dataSource.getNextSibling(); + dataBindingManager.removeDataSource(dataSource); + break; + case DATASOURCE_CHANGED: + List dataSources = dataBindingManager.getDataSources(); + for (BindingData dataSource : dataSources) { + if (dataSource.getSourceName().equals(this.dataSource.getSourceName())) { + nextSibling = dataSource.getNextSibling(); + originalDataSource = dataSource; + dataBindingManager.removeDataSource(dataSource); + dataBindingManager.addDataSource(this.dataSource, nextSibling); + break; + } + } + break; + default: + break; + } + } + + @Override + public boolean canExecute() { + return super.canExecute(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.gef.commands.Command#canUndo() + */ + @Override + public boolean canUndo() { + return super.canUndo(); + } + + @Override + public void undo() { + switch (type) { + case DATASOURCE_ADDED: + dataBindingManager.removeDataSource(dataSource); + break; + case DATASOURCE_RENAMED: + dataBindingManager.renameDataSource(dataSource, oldName); + break; + case DATASOURCE_REMOVED: + dataBindingManager.addDataSource(dataSource, nextSibling); + break; + case DATASOURCE_CHANGED: + List dataSources = dataBindingManager.getDataSources(); + BindingData docPartDataSource = null; + for (BindingData dataSource : dataSources) { + if (dataSource.getSourceName().equals(this.dataSource.getSourceName())) { + docPartDataSource = dataSource; + break; + } + } + dataBindingManager.removeDataSource(docPartDataSource); + dataBindingManager.addDataSource(originalDataSource, nextSibling); + break; + default: + break; + } + + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/command/DataBindingCommandAdapter.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/command/DataBindingCommandAdapter.java new file mode 100644 index 0000000..0ed9a0e --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/command/DataBindingCommandAdapter.java @@ -0,0 +1,69 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.view.databinding.model.command; + +import org.eclipse.emf.common.command.CompoundCommand; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartObserver; +import org.tizen.efluibuilder.ui.editor.designeditor.DesignEditCommandStack; + + +/* + * We now use the EMFCommandStack instead of the GEFCommandStack. + */ +public class DataBindingCommandAdapter extends CompoundCommand { + private Part databindingPart; + DesignEditCommandStack commandStack; + + public DataBindingCommandAdapter(Part databindingPart, DesignEditCommandStack commandStack) { + this.databindingPart = databindingPart; + this.commandStack = commandStack; + } + + @Override + public void execute() { + super.execute(); + processPostExecute(PartObserver.MESSAGE_GEF_EXECUTE); + } + + @Override + public void redo() { + super.redo(); + processPostExecute(PartObserver.MESSAGE_GEF_REDO); + } + + @Override + public void undo() { + super.undo(); + processPostExecute(PartObserver.MESSAGE_GEF_UNDO); + } + + private void processPostExecute(String sender) { + // make dirty for the layout.xml + commandStack.makeDirtyByForce(); + // If user undo/redo in Source tab (not Design), DesignEditCommandStack cannot handle it. + // So databindingPart change must be handled here not DesignEditCommandStack. + databindingPart.notifyObservers(sender); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/command/DataBindingCommandFactory.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/command/DataBindingCommandFactory.java new file mode 100644 index 0000000..adb36b1 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/command/DataBindingCommandFactory.java @@ -0,0 +1,408 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.model.command; + +import java.util.List; +import java.util.Map; + +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CompoundCommand; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.Shell; +import org.tizen.efluibuilder.model.command.SetPropertyPartCommand; +import org.tizen.efluibuilder.model.descriptors.ConstantDescriptor; +import org.tizen.efluibuilder.model.descriptors.PropertyDescriptor; +import org.tizen.efluibuilder.model.descriptors.TypeDescriptor; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.efluibuilder.ui.view.databinding.dialog.DataBindingFilterDialog; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingData; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingDataSetEvent.BindingDataSetEventType; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingObject; +import org.tizen.efluibuilder.ui.view.databinding.model.DataBindingPartProperty; +import org.tizen.efluibuilder.ui.view.databinding.utils.BuilderConstants; +import org.tizen.efluibuilder.ui.view.databinding.utils.DataBindingHelper; +import org.tizen.efluibuilder.ui.view.databinding.utils.DataBindingHelper.PopUpListener; + +public class DataBindingCommandFactory { + + public static Command createAddDataSourceCommand(CombineEditorPart combineEditorPart, BindingData dataSource) { + Command addDataSourceCommand = new ConfigureDataSourceCommand(BindingDataSetEventType.DATASOURCE_ADDED, combineEditorPart.getDataBindManager(), dataSource); + return addDataSourceCommand; + } + + public static Command createRenameDataSourceCommand(CombineEditorPart combineEditorPart, BindingData dataSource, String newName) { + CompoundCommand cc = new CompoundCommand("Rename DataSource"); + Command renameDataSourceCommand = new ConfigureDataSourceCommand(BindingDataSetEventType.DATASOURCE_RENAMED, combineEditorPart.getDataBindManager(), dataSource, newName); + cc.add(renameDataSourceCommand); + return cc; + } + + public static Command createRemoveDataSourceCommand(CombineEditorPart combineEditorPart, BindingData dataSource) { + CompoundCommand cc = new CompoundCommand("Remove DataSource"); + Command removeDataSourceCommand = new ConfigureDataSourceCommand(BindingDataSetEventType.DATASOURCE_REMOVED, combineEditorPart.getDataBindManager(), dataSource); + cc.add(removeDataSourceCommand); + Command removeDataModelCommand = null; + List dataModels = combineEditorPart.getDataBindManager().getDataModels(); + for (BindingData dataModel : dataModels) { + if (dataModel.getSourceName() != null && dataModel.getSourceName().equals(dataSource.getSourceName())) { + removeDataModelCommand = createRemoveDataModelCommand(combineEditorPart, dataModel); + cc.add(removeDataModelCommand); + } + } + return cc; + } + + public static Command createEditDataSourceCommand(CombineEditorPart combineEditorPart, BindingData dataSource) { + CompoundCommand cc = new CompoundCommand("Edit DataSource"); + Command editDataSourceCommand = new ConfigureDataSourceCommand(BindingDataSetEventType.DATASOURCE_CHANGED, combineEditorPart.getDataBindManager(), dataSource); + cc.add(editDataSourceCommand); + List dataModels = combineEditorPart.getDataBindManager().getDataModels(); + for (BindingData dataModel : dataModels) { + if (dataModel.getSourceName() != null && dataModel.getSourceName().equals(dataSource.getSourceName())) { +// Part nextSibling = dataModel.getNextSibling(); + Command removeDataModelCommand = createRemoveDataModelCommand(combineEditorPart, dataModel); + cc.add(removeDataModelCommand); + + BindingData newDataModel = (BindingData) PartUtil.createPart(PartType.DATAMODEL, LayoutSchemaConstants.DATAMODEL); + newDataModel.setSourceName(dataSource.getSourceName()); + newDataModel.setItemName(dataModel.getItemName()); + newDataModel.setModelName(dataModel.getModelName()); + newDataModel.setModelType(dataSource.getModelType()); + for (BindingObject bo : dataSource.getBindingObjects()) { + BindingObject newBo = bo.clone(); + newDataModel.insertChildBefore(newBo, null); + } + + Command addDataModelCommand = createAddDataModelCommand(combineEditorPart, newDataModel); + cc.add(addDataModelCommand); + } + } + return cc; + } + + public static Command createAddDataModelCommand(CombineEditorPart combineEditorPart, BindingData dataModel) { + Command addDataModelCommand = new ConfigureDataModelCommand(BindingDataSetEventType.DATAMODEL_ADDED, combineEditorPart.getDataBindManager(), dataModel); + return addDataModelCommand; + } + + public static Command createSetDataModelCommand(CombineEditorPart combineEditorPart, BindingData dataModelToBeReplaced, BindingData newDataModel) { + CompoundCommand cc = new CompoundCommand("Set DataSource To Model"); + Command setDataModelCommand = new ConfigureDataModelCommand(BindingDataSetEventType.DATAMODEL_SET_DATASOURCE, combineEditorPart.getDataBindManager(), dataModelToBeReplaced, + newDataModel); + cc.add(setDataModelCommand); + Command removeBindingInfoCommand = createRemoveBindingInfoCommand(combineEditorPart, dataModelToBeReplaced.getModelName(), null); + if (removeBindingInfoCommand != null) { + cc.add(removeBindingInfoCommand); + } + return cc; + } + + public static Command createRemoveDataModelCommand(CombineEditorPart combineEditorPart, BindingData dataModel) { + CompoundCommand cc = new CompoundCommand("Remove DataModel"); + Command removeDataModelCommand = new ConfigureDataModelCommand(BindingDataSetEventType.DATAMODEL_REMOVED, combineEditorPart.getDataBindManager(), dataModel); + cc.add(removeDataModelCommand); + Command removeBindingInfoCommand = createRemoveBindingInfoCommand(combineEditorPart, dataModel.getModelName(), null); + // if (removeBindingInfoCommand != null) { + // MessageBox msgBox = new + // MessageBox(Display.getDefault().getActiveShell(), SWT.ICON_QUESTION | + // SWT.YES | SWT.NO); + // msgBox.setText("Data Binding"); + // StringBuilder sb = new StringBuilder().append("Related binding + // Information will be deleted when deleting the data + // model.\n").append("Do you want to delete it ?"); + // msgBox.setMessage(sb.toString()); + // if (msgBox.open() == SWT.NO) { + // return null; + // } else { + // cc.add(removeBindingInfoCommand); + // } + // } + if (removeBindingInfoCommand != null) { + cc.add(removeBindingInfoCommand); + } + return cc; + } + + public static Command createRenameDataModelCommand(CombineEditorPart combineEditorPart, BindingData dataModel, String newName) { + CompoundCommand cc = new CompoundCommand("Rename DataModel"); + Command renameDataModelCommand = new ConfigureDataModelCommand(BindingDataSetEventType.DATAMODEL_RENAMED, combineEditorPart.getDataBindManager(), dataModel, newName); + cc.add(renameDataModelCommand); + Part viewsPart = PartUtil.findViewsPart(combineEditorPart.getDocumentPart()); + CompoundCommand updateBindingInfoscommand = new CompoundCommand("Update BindingInfos"); + addUpdateBindingInfoCommands(viewsPart, updateBindingInfoscommand, dataModel.getModelName(), newName); + if (!updateBindingInfoscommand.isEmpty()) { + cc.add(updateBindingInfoscommand); + } + return cc; + } + + public static Command createRemoveDataModelItemCommand(CombineEditorPart combineEditorPart, BindingData dataModel, List itemPath, String childName) { + CompoundCommand cc = new CompoundCommand("Remove DataModelItem"); + Command removeDataModelItemCommand = new ConfigureDataModelCommand(BindingDataSetEventType.DATAMODEL_ITEM_REMOVED, combineEditorPart.getDataBindManager(), dataModel, itemPath, childName); + cc.add(removeDataModelItemCommand); + Command removeBindingInfoCommand = createRemoveBindingInfoCommand(combineEditorPart, dataModel.getModelName(), itemPath); + // if (removeBindingInfoCommand != null) { + // MessageBox msgBox = new + // MessageBox(Display.getDefault().getActiveShell(), SWT.ICON_QUESTION | + // SWT.YES | SWT.NO); + // msgBox.setText("Data Binding"); + // StringBuilder sb = new StringBuilder().append("Related binding + // Information will be deleted when deleting the data + // model.\n").append("Do you want to delete it ?"); + // msgBox.setMessage(sb.toString()); + // if (msgBox.open() == SWT.NO) { + // return null; + // } else { + // cc.add(removeBindingInfoCommand); + // } + // } + if (removeBindingInfoCommand != null) { + cc.add(removeBindingInfoCommand); + } + + return cc; + } + + public static Command createRemoveBindingInfoCommand(CombineEditorPart combineEditorPart, String name, List itemPath) { + CompoundCommand removeBindingInfoscommand = new CompoundCommand("Remove BindingInfos"); + + String modelFullPath = null; + if (itemPath != null) { + for (int i = itemPath.size() - 1; i >= 0; i--) { + + String path = itemPath.get(i); + + if (i == itemPath.size() - 1 && path.lastIndexOf(" ") > 0) + path = path.substring(0, path.lastIndexOf(" ")); + + if (modelFullPath == null) + modelFullPath = path; + else + modelFullPath = modelFullPath + BuilderConstants.SLASH + path; + } + } else + modelFullPath = name; + Part viewsPart = PartUtil.findViewsPart(combineEditorPart.getDocumentPart()); + addRemoveBindingInfoCommands(viewsPart, removeBindingInfoscommand, modelFullPath); + if (removeBindingInfoscommand.isEmpty()) { + return null; + } + return removeBindingInfoscommand; + } + + private static void addUpdateBindingInfoCommands(Part part, CompoundCommand command, String modelName, String updatedModelName) { + if (part instanceof ComponentPart) { + String dataBindValue = part.getPropertyValue(BuilderConstants.ATTRIBUTE_DATA_BIND); + if ((dataBindValue != null) && (!dataBindValue.isEmpty())) { + Map bindingInfos = DataBindingHelper.parseToMap(dataBindValue); + Object[] bindingTypes = bindingInfos.keySet().toArray(); + for (Object bindingType : bindingTypes) { + String value = bindingInfos.get(bindingType); + if ((value != null) && (value.startsWith(modelName))) { + value = value.replace(modelName, updatedModelName); + bindingInfos.remove(bindingType.toString()); + bindingInfos.put(bindingType.toString(), value); + String bindingInfo = DataBindingHelper.makeStringFromMap(bindingInfos); + Command updateBindingCommand = new SetPropertyPartCommand(part, BuilderConstants.ATTRIBUTE_DATA_BIND, bindingInfo); + command.add(updateBindingCommand); + } + } + } + } + for (Part child : part.getChildren()) { + addUpdateBindingInfoCommands(child, command, modelName, updatedModelName); + } + } + + private static void addRemoveBindingInfoCommands(Part part, CompoundCommand command, String modelFullPath) { + if (part instanceof ComponentPart) { + String dataBindValue = part.getPropertyValue(BuilderConstants.ATTRIBUTE_DATA_BIND); + if (dataBindValue != null) { + String[] array = dataBindValue.split(BuilderConstants.FILTER_REGEX); + String modelPath = null; + for (int i = 0; i < array.length; i++) { + if (modelPath == null) + modelPath = array[i]; + else + modelPath = modelPath + array[i]; + } + if (modelPath != null && modelPath.contains(modelFullPath)) { + Command removeBindingCommand = new SetPropertyPartCommand(part, BuilderConstants.ATTRIBUTE_DATA_BIND, ""); + command.add(removeBindingCommand); + } + } + } + for (Part child : part.getChildren()) { + addRemoveBindingInfoCommands(child, command, modelFullPath); + } + } + + public static Command getAddBindingCommand(Part targetPart, BindingData dataModel, String itemPath, String bindingType) { + Command command = null; + String value = bindingType + ": " + xPathConversion(dataModel.getModelName() + BuilderConstants.SLASH + itemPath); + command = new SetPropertyPartCommand(targetPart, BuilderConstants.ATTRIBUTE_DATA_BIND, value); + return command; + } + + public static Command createDropCommand(Part currentPart, DataBindingPartProperty property, Shell shell, Point popupPoint) { + Command cmd = null; + if (!(currentPart instanceof ComponentPart)) + return null; + ComponentPart part = (ComponentPart) currentPart; + + if (!checkDataBinding(part, property)) { + return null; + } + if (canApplyFilter(part, property)) { + String type = bindingTypeAllowedonPart(part); + DataBindingFilterDialog dialog = new DataBindingFilterDialog(Display.getCurrent().getActiveShell(), property, getLevelDiff(part, property), part.getDescriptorId(), type); + if (dialog.open() == Window.OK) { + String value = type + ": " + xPathConversion(dialog.getFilterPath()); + cmd = new SetPropertyPartCommand(part, BuilderConstants.ATTRIBUTE_DATA_BIND, value); + } + } else { + PopUpListener popUpListener = new PopUpListener(currentPart, property.getModelName(), property.getViewItemName()); + popUpListener.init(); + + Menu contextMenu = new Menu(shell, SWT.POP_UP); + ComponentPart parentPart = null; + if (part.getParent() instanceof ComponentPart) { + parentPart = (ComponentPart) part.getParent(); + } + ComponentDescriptor componentDescriptor = part.getOwnerDocumentPart().getComponentDescriptor(); + PropertyDescriptor propDesc = componentDescriptor.getPropertyDescriptor(parentPart, part, BuilderConstants.ATTRIBUTE_DATA_BIND); + if (propDesc == null) + return null; + List list = propDesc.getTypeDescriptor().getAvailableConstant(); + if ((list != null) && (list.size() > 0)) { + if (popupPoint != null) + contextMenu.setLocation(popupPoint); + + for (ConstantDescriptor cd : list) { + MenuItem item = new MenuItem(contextMenu, SWT.PUSH); + String bindingType = cd.getValue(); + item.setData("bindingType", bindingType); + item.setText(bindingType); + item.addListener(SWT.Selection, popUpListener); + } + contextMenu.setVisible(true); + + while (!contextMenu.isDisposed() && contextMenu.isVisible()) { + if (!shell.getDisplay().readAndDispatch()) + shell.getDisplay().sleep(); + } + contextMenu.dispose(); + } + + cmd = popUpListener.getCommand(); + } + return cmd; + } + + public static boolean isIncludeDataBindProp(ComponentPart part, String propType) { + + String propDescValue = part.getPropertyValue(BuilderConstants.ATTRIBUTE_DATA_BIND); + if (propDescValue == null) + return false; + ComponentPart parentPart = null; + if (part.getParent() instanceof ComponentPart) { + parentPart = (ComponentPart) part.getParent(); + } + ComponentDescriptor componentDescriptor = part.getOwnerDocumentPart().getComponentDescriptor(); + PropertyDescriptor propDesc = componentDescriptor.getPropertyDescriptor(parentPart, part, BuilderConstants.ATTRIBUTE_DATA_BIND); + if (propDesc == null) + return false; + + TypeDescriptor TypeDesc = propDesc.getTypeDescriptor(); + if (TypeDesc == null) + return false; + + List list = TypeDesc.getAvailableConstant(); + + for (ConstantDescriptor cd : list) { + if (cd.getValue().equals(propType)) { + return true; + } + } + return false; + } + + public static String bindingTypeAllowedonPart(ComponentPart targetModel) { + String type = null; + if (isIncludeDataBindProp(targetModel, "foreach")) { + type = "foreach"; + } else { + type = "text"; + } + return type; + } + + public static int getLevelDiff(ComponentPart targetModel, DataBindingPartProperty property) { + String[] array = property.getViewItemName().split(BuilderConstants.ARRAY_REGEX); + int propertyLevel; + if (property.getDataType().equals("Array")) { + propertyLevel = array.length; + } else { + propertyLevel = array.length - 1; + } + int widgetLevel = 0; + if (isIncludeDataBindProp(targetModel, "foreach")) { + widgetLevel = 1; + } + return propertyLevel - widgetLevel; + } + + public static boolean canApplyFilter(ComponentPart targetModel, DataBindingPartProperty property) { + return getLevelDiff(targetModel, property) > 0; + } + + public static boolean checkDataBinding(ComponentPart targetModel, DataBindingPartProperty property) { + boolean flag = true; + if (targetModel.getChildren() != null && targetModel.getChildren().size() != 0) { + for (Part child : targetModel.getChildren()) { + if (child instanceof ComponentPart) { + flag = false; + break; + } + } + } + return flag; + } + + public static String xPathConversion(String path) { + path = path.replaceAll(BuilderConstants.ARRAY_REGEX, BuilderConstants.EMPTY).replaceAll(BuilderConstants.AT, + BuilderConstants.DOT); + return path; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/command/DataBindingPropertyPartCommand.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/command/DataBindingPropertyPartCommand.java new file mode 100644 index 0000000..a579d80 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/model/command/DataBindingPropertyPartCommand.java @@ -0,0 +1,84 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.model.command; + +import java.util.List; + +import org.eclipse.gef.commands.Command; +import org.tizen.efluibuilder.model.descriptors.PropertyDescriptor; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; + +public class DataBindingPropertyPartCommand extends Command { + + private Part part = null; + private String name = null; + private String value = null; + private String oldValue = null; + private List properties = null; + + public DataBindingPropertyPartCommand(Part part, String name, String value) { + this.part = part; + this.name = name; + this.setValue(value); + if (part instanceof ComponentPart) { + ComponentPart parentPart = null; + if (part.getParent() instanceof ComponentPart) { + parentPart = (ComponentPart) part.getParent(); + } + ComponentDescriptor componentDescriptor = part.getOwnerDocumentPart().getComponentDescriptor(); + properties = componentDescriptor.getPropertyDescriptors(parentPart, (ComponentPart) part); + } + + } + + @Override + public boolean canExecute() { + if (!(part instanceof ComponentPart)) { + return true; + } + + if (part.hasProperty(name)) { + return true; + } + return false; + } + + @Override + public void execute() { + super.execute(); + oldValue = this.part.getPropertyValue(name); + this.part.setPropertyValue(name, value); + } + + public void setValue(String value) { + this.value = value; + } + + @Override + public void undo() { + super.undo(); + this.part.setPropertyValue(name, oldValue); + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/utils/BuilderConstants.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/utils/BuilderConstants.java new file mode 100644 index 0000000..0d1200f --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/utils/BuilderConstants.java @@ -0,0 +1,399 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.utils; + +public class BuilderConstants { + + // Special character + public static final String EMPTY = ""; //$NON-NLS-1$ + public static final String SPACE = " "; //$NON-NLS-1$ + public static final String TAB = " "; //$NON-NLS-1$ + public static final String SLASH = "/"; //$NON-NLS-1$ + public static final String BSLASH = "\\"; //$NON-NLS-1$ + public static final String NEW_LINE = "\n"; //$NON-NLS-1$ + public static final String DOT = "."; //$NON-NLS-1$ + public static final String COMMA = ","; //$NON-NLS-1$ + public static final String COLON = ":"; //$NON-NLS-1$ + public static final String SEMICOLON = ";"; //$NON-NLS-1$ + public static final String DASH = "-"; //$NON-NLS-1$ + public static final String UNDERBAR = "_"; //$NON-NLS-1$ + public static final String OPEN_BRACKET = "("; //$NON-NLS-1$ + public static final String CLOSE_BRACKET = ")"; //$NON-NLS-1$ + public static final String OPEN_CURLY_BRACKET = "{"; //$NON-NLS-1$ + public static final String CLOSE_CURLY_BRACKET = "}"; //$NON-NLS-1$ + public static final String OPEN_SQUARE_BRACKET = "["; //$NON-NLS-1$ + public static final String CLOSE_SQUARE_BRACKET = "]"; //$NON-NLS-1$ + public static final String OPEN_TRI_BRACKET = "<"; //$NON-NLS-1$ + public static final String CLOSE_TRI_BRACKET = ">"; //$NON-NLS-1$ + public static final String TILDE = "~"; //$NON-NLS-1$ + public static final String ELLIPSIS = "..."; //$NON-NLS-1$ + public static final String EQUAL = "="; //$NON-NLS-1$ + public static final String ASTERISK = "*"; //$NON-NLS-1$ + public static final String GRAVE_ACCENT = "`"; //$NON-NLS-1$ + public static final String QUOTATION_MARK = "\""; //$NON-NLS-1$ + public static final String APOSTROPHE_MARK = "'"; //$NON-NLS-1$ + public static final String SHARP = "#"; //$NON-NLS-1$ + public static final String AT = "@"; //$NON-NLS-1$ + public final static String ARRAY_REGEX = "\\[\\*\\]"; //$NON-NLS-1$ + public final static String DOT_REGEX = "\\."; //$NON-NLS-1$ + public final static String SLASH_REGEX = "\\/"; //$NON-NLS-1$ + public final static String FILTER_REGEX = "\\[(.*?)\\]"; + + // Path + public static final String RES_DIR = "res" + SLASH; //$NON-NLS-1$ + public static final String ICON_DIR = RES_DIR + "icons" + SLASH; //$NON-NLS-1$ + public static final String PREVIEW_DIR = RES_DIR + "preview" + SLASH; //$NON-NLS-1$ + public static final String TEMPLATE_DIR = RES_DIR + "template" + SLASH; //$NON-NLS-1$ + public static final String IMAGE_DIR = RES_DIR + "images" + SLASH; //$NON-NLS-1$ + public static final String XSLT_DIR = RES_DIR + "xslt" + SLASH; //$NON-NLS-1$ + public static final String DATABINDING_DIR = RES_DIR + "databinding" + SLASH; //$NON-NLS-1$ + public static final String DATABINDING_DIR_JSON = RES_DIR + "json" + SLASH + "databinding" + SLASH; //$NON-NLS-1$ + public static final String ASSIST_DIR = RES_DIR + "assist" + SLASH; //$NON-NLS-1$ + + // Designer and Preview + public static final String PROPERTY_PROJECTMANAGER = "ProjectManager"; //$NON-NLS-1$ + public static final String PROPERTY_APPMANAGER = "AppManager"; //$NON-NLS-1$ + public static final String PROPERTY_DESCRIPTORMANAGER = "DescriptorManager"; //$NON-NLS-1$ + public static final String DESIGNER_BACKGROUND_IMAGE = "workspace_pattern.png"; //$NON-NLS-1$ + public static final String PREVIEW_BACKGROUND_IMAGE = "preview_panel_back.png"; //$NON-NLS-1$ + public static final String SCROLLBAR_IMAGE = "scrollbar_image.png"; //$NON-NLS-1$ + + // UIFW + public static final String TAU = "tau"; //$NON-NLS-1$ + + // preview + public static final String PREVIEW_LEFT_TOP = "preview_left_top.png"; //$NON-NLS-1$ + public static final String PREVIEW_TOP = "preview_top.png"; //$NON-NLS-1$ + public static final String PREVIEW_RIGHT_TOP = "preview_right_top.png"; //$NON-NLS-1$ + public static final String PREVIEW_LEFT = "preview_left.png"; //$NON-NLS-1$ + public static final String PREVIEW_RIGHT = "preview_right.png"; //$NON-NLS-1$ + public static final String PREVIEW_LEFT_BOTTOM = "preview_left_bottom.png"; //$NON-NLS-1$ + public static final String PREVIEW_BOTTOM = "preview_bottom.png"; //$NON-NLS-1$ + public static final String PREVIEW_RIGHT_BOTTOM = "preview_right_bottom.png"; //$NON-NLS-1$ + + // Model + public static final String PART_DOC = "tizen.doc"; //$NON-NLS-1$ + public static final String PART_PAGE = "tizen.page"; //$NON-NLS-1$ + public static final String PART_CONTENT = "tizen.content"; //$NON-NLS-1$ + public static final String PART_HEADER = "tizen.header"; //$NON-NLS-1$ + public static final String PART_FOOTER = "tizen.footer"; //$NON-NLS-1$ + public static final String PART_TEXT = "html.text"; //$NON-NLS-1$ + public static final String PX = "px"; //$NON-NLS-1$ + public static final String SELECTOR_ID = "%id%";//$NON-NLS-1$ + + // Model descriptor + public static final String STYLE_DESCRIPTOR_FILE = "CSSProperties.xml"; //$NON-NLS-1$ + public static final String SCREENFEATURE_DESCRIPTOR_FILE = "ScreenFeatures.xml"; //$NON-NLS-1$ + public static final String DEVICE_DESCRIPTOR_FILE = "SupportedDevices.xml"; //$NON-NLS-1$ + public static final String FEATURE_DESCRIPTOR_FILE = "FeatureDescriptor.xml"; //$NON-NLS-1$ + public static final String FEATURE_DESCRIPTOR_XSLT_FILE = "FeatureDescriptorXslt.xml"; //$NON-NLS-1$ + + // Model IO + public static final String ATTRIBUTE_PID = "part-id"; //$NON-NLS-1$ + public static final String ATTRIBUTE_POSITION_SELECTOR = "position-selector"; //$NON-NLS-1$ + public static final String ATTRIBUTE_STYLE = "style"; //$NON-NLS-1$ + public static final String ATTRIBUTE_VALUE_POSITION = "position"; //$NON-NLS-1$ + public static final String ATTRIBUTE_VALUE_ABSOLUTE = "absolute"; //$NON-NLS-1$ + public static final String ATTRIBUTE_VALUE_RELATIVE = "relative"; //$NON-NLS-1$ + public static final String ATTRIBUTE_VALUE_LEFT = "left"; //$NON-NLS-1$ + public static final String ATTRIBUTE_VALUE_TOP = "top"; //$NON-NLS-1$ + public static final String ATTRIBUTE_VALUE_WIDTH = "width"; //$NON-NLS-1$ + public static final String ATTRIBUTE_VALUE_HEIGHT = "height"; //$NON-NLS-1$ + public static final String ATTRIBUTE_VALUE_PX = PX; + public static final String ATTRIBUTE_TEXT = "text"; //$NON-NLS-1$ + public static final String ATTRIBUTE_EVENT_PREFIX = "on"; //$NON-NLS-1$ + public static final String PROPERTY_GROUP_PREFIX = "group"; //$NON-NLS-1$ + public static final String LOG_READ_PAGE_ERROR = "This file is not valid XML."; //$NON-NLS-1$ + public static final String CANNOT_BE_FOUND_ERROR = " cannot be found."; //$NON-NLS-1$ + public static final String LOG_DESC_CANNOT_BE_FOUND_ERROR = "Descriptor cannot be found."; //$NON-NLS-1$ + + // Project + public static final String PAGE = "page"; //$NON-NLS-1$ + public static final String JAVASCRIPT = "js"; //$NON-NLS-1$ + public static final String CSS = "css"; //$NON-NLS-1$ + public static final String XML = "xml"; //$NON-NLS-1$ + public static final String HTML = "html"; //$NON-NLS-1$ + public static final String JSON = "json"; //$NON-NLS-1$ + public static final String PAGE_DIR = PAGE; + public static final String TIZEN_UI_BUILDER_TOOL_DIR = "tizen-ui-builder-tool"; //$NON-NLS-1$ + public static final String XML_EXTENSION = DOT + XML; + public static final String PAGE_EXTENSION = DOT + PAGE; + public static final String JAVASCRIPT_EXTENSION = DOT + JAVASCRIPT; + private static final String MANAGED = "managed"; //$NON-NLS-1$ + private static final String ASSIST = "assist"; //$NON-NLS-1$ + public static final String MANAGEDJS_EXTENSION = DOT + MANAGED + DOT + JAVASCRIPT; + public static final String ASSISTJS_EXTENSION = DOT + ASSIST + DOT + JAVASCRIPT; + public static final String HTML_EXTENSION = DOT + HTML; + public static final String CSS_EXTENSION = DOT + CSS; + public static final String MANAGED_CSS_EXTENSION = DOT + MANAGED + CSS_EXTENSION; + public static final String DEFAULT_PAGE_NAME = "page1" + PAGE_EXTENSION; //$NON-NLS-1$ + + public static final String TIZEN_UI_BUILDER_TOOL_FILE = DOT + "tizen-ui-builder-tool.xml"; //$NON-NLS-1$ //$NON-NLS-2$ + public static final String TIZEN_UI_BUILDER_TOOL_FILE_OLD = "tizen-ui-builder-tool.xml"; //$NON-NLS-1$ //$NON-NLS-2$ + + public static final String INDEX_HTML_FILE_PREFIX = "index"; //$NON-NLS-1$ + public static final String INDEX_HTML_FILE = INDEX_HTML_FILE_PREFIX + HTML_EXTENSION; + public static final String INDEX_MANAGED_JS_FILE = INDEX_HTML_FILE_PREFIX + MANAGEDJS_EXTENSION; + public static final String PROJECT_FILE_PREFIX = "app"; //$NON-NLS-1$ + public static final String PROJECT_FILE = PROJECT_FILE_PREFIX + XML_EXTENSION; + public static final String PROJECT_HTML_FILE = PROJECT_FILE_PREFIX + HTML_EXTENSION; + public static final String PROJECT_JS_FILE = PROJECT_FILE_PREFIX + JAVASCRIPT_EXTENSION; + public static final String PROJECT_MANAGED_JS_FILE = PROJECT_FILE_PREFIX + MANAGEDJS_EXTENSION; + public static final String PROJECT_CSS_FILE = PROJECT_FILE_PREFIX + CSS_EXTENSION; + public static final String PROJECT_TYPE_SYSTEM = "system"; //$NON-NLS-1$ + public static final String UIBINDING_FILE_PREFIX = "uibinding"; + public static final String UIBINDING_ASSIST_JS_FILE = UIBINDING_FILE_PREFIX + ASSISTJS_EXTENSION; + + // Code generator + public static final String YES = "yes"; //$NON-NLS-1$ + public static final String NO = "no"; //$NON-NLS-1$ + public static final String ENCODING = "UTF-8"; //$NON-NLS-1$ + public static final String CLOSE_ANNOTATION = "-->"; //$NON-NLS-1$ + public static final String ELEMENT_OPEN_HEAD = ""; //$NON-NLS-1$ + public static final String ELEMENT_CLOSE_HEAD = ""; //$NON-NLS-1$ + public static final String ELEMENT_OPEN_STYLE = ""; //$NON-NLS-1$ + public static final String ELEMENT_OPEN_LINK = ""; //$NON-NLS-1$ + + // Project descriptor + public static final String DEFAULT_THEME = "tizen-white"; //$NON-NLS-1$ + public static final String LOG_EXIST_ERROR = " is already exist"; //$NON-NLS-1$ + + // Project file element name + public static final String ELEMENT_TIZENPROJECT = "tizenProject"; //$NON-NLS-1$ + public static final String ELEMENT_PROJECTINFO = "projectInfo"; //$NON-NLS-1$ + public static final String ELEMENT_TITLE = "title"; //$NON-NLS-1$ + public static final String ELEMENT_AUTHOR = "author"; //$NON-NLS-1$ + public static final String ELEMENT_VERSION = "version"; //$NON-NLS-1$ + public static final String ELEMENT_PAGESYSTEM = "pageSystem"; //$NON-NLS-1$ + public static final String ELEMENT_METAS = "metas"; //$NON-NLS-1$ + public static final String ELEMENT_FRAMEWORKS = "frameworks"; //$NON-NLS-1$ + public static final String ELEMENT_LIBRARIES = "libraries"; //$NON-NLS-1$ + public static final String ELEMENT_SCREEN = "screen"; //$NON-NLS-1$ + public static final String ELEMENT_PAGES = "pages"; //$NON-NLS-1$ + public static final String ELEMENT_ENTRIES = "entries"; //$NON-NLS-1$ + public static final String ELEMENT_STYLESHEETS = "stylesheets"; //$NON-NLS-1$ + public static final String ELEMENT_NSCREEN = "nscreen"; //$NON-NLS-1$ + public static final String ELEMENT_META = "meta"; //$NON-NLS-1$ + public static final String ELEMENT_HEAD = "head"; //$NON-NLS-1$ + public static final String ELEMENT_BODY = "body"; //$NON-NLS-1$ + public static final String ELEMENT_LIBRARY = "library"; //$NON-NLS-1$ + public static final String ELEMENT_SCRIPT = "script"; //$NON-NLS-1$ + public static final String ELEMENT_VARIABLES = "variables"; //$NON-NLS-1$ + public static final String ELEMENT_VARIABLE = "variable"; //$NON-NLS-1$ + public static final String ELEMENT_FRAMEWORK = "framework"; //$NON-NLS-1$ + public static final String ELEMENT_PAGE = PAGE; + public static final String ELEMENT_STYLESHEET = "stylesheet"; //$NON-NLS-1$ + public static final String ELEMENT_FRAMEWORK_THEME = "framework-theme"; //$NON-NLS-1$ + public static final String ELEMENT_SCREENDESC = "screenDesc"; //$NON-NLS-1$ + public static final String ELEMENT_SCREENDESCLAYER = "screenDescLayer"; //$NON-NLS-1$ + public static final String ELEMENT_DEVICE = "device"; //$NON-NLS-1$ + public static final String ELEMENT_DATABINDING = "dataBinding"; //$NON-NLS-1$ + public static final String ELEMENT_DATASOURCE = "dataSource"; //$NON-NLS-1$ + public static final String ELEMENT_DATAMODEL = "dataModel"; //$NON-NLS-1$ + public static final String ELEMENT_HANDLERINFO = "handlerInfo"; //$NON-NLS-1$ + public static final String ELEMENT_MODELINFO = "modelInfo"; //$NON-NLS-1$ + public static final String ELEMENT_UPDATEONSTARTUP = "updateOnStartUp"; //$NON-NLS-1$ + public static final String ELEMENT_OBSERVABLEOBJECT = "observableObject"; //$NON-NLS-1$ + + // Project file attribute name + public static final String ATTRIBUTE_TYPE = "type"; //$NON-NLS-1$ + public static final String ATTRIBUTE_PATH = "path"; //$NON-NLS-1$ + public static final String ATTRIBUTE_PARAM = "param"; //$NON-NLS-1$ + public static final String ATTRIBUTE_PARAM2 = "param2"; //$NON-NLS-1$ + public static final String ATTRIBUTE_THEME = "data-framework-theme"; //$NON-NLS-1$ + public static final String ATTRIBUTE_SCALE = "data-framework-viewport-scale"; //$NON-NLS-1$ + public static final String ATTRIBUTE_PAGEPATH = "pagePath"; //$NON-NLS-1$ + public static final String ATTRIBUTE_JSPATH = "jsPath"; //$NON-NLS-1$ + public static final String ATTRIBUTE_MANAGEDJSPATH = "managedJsPath"; //$NON-NLS-1$ + public static final String ATTRIBUTE_HTMLPATH = "htmlPath"; //$NON-NLS-1$ + public static final String ATTRIBUTE_CSSPATH = "cssPath"; //$NON-NLS-1$ + public static final String ATTRIBUTE_MANAGED_CSSPATH = "managedCssPath"; //$NON-NLS-1$ + public static final String ATTRIBUTE_NAME = "name"; //$NON-NLS-1$ + public static final String ATTRIBUTE_VALUE = "value"; //$NON-NLS-1$ + public static final String ATTRIBUTE_STARTUP = "startup"; //$NON-NLS-1$ + public static final String ATTRIBUTE_PAGEID = "pageId"; //$NON-NLS-1$ + public static final String ATTRIBUTE_WIDGETID = "widgetId"; //$NON-NLS-1$ + public static final String ATTRIBUTE_PARTID = "partId"; //$NON-NLS-1$ + public static final String ATTRIBUTE_DATASOURCE = "dataSource"; //$NON-NLS-1$ + public static final String ATTRIBUTE_ISCHECKED = "isChecked"; //$NON-NLS-1$ + public static final String ATTRIBUTE_MODELTYPE = "modelType"; //$NON-NLS-1$ + public static final String ATTRIBUTE_URL = "url"; //$NON-NLS-1$ + public static final String ATTRIBUTE_PROXY = "proxy"; //$NON-NLS-1$ + public static final String ATTRIBUTE_QUERY = "query"; //$NON-NLS-1$ + public static final String ATTRIBUTE_DATATYPE = "dataType"; //$NON-NLS-1$ + public static final String ATTRIBUTE_TIMEOUT = "timeout"; //$NON-NLS-1$ + public static final String ATTRIBUTE_JSONDATA = "jsonData"; //$NON-NLS-1$ + public static final String ATTRIBUTE_FILEPATH = "filePath"; //$NON-NLS-1$ + public static final String ATTRIBUTE_API = "api"; //$NON-NLS-1$ + public static final String ATTRIBUTE_METHOD = "method"; //$NON-NLS-1$ + public static final String ATTRIBUTE_ADDRESS_BOOK_ID = "addressBookId"; //$NON-NLS-1$ + public static final String ATTRIBUTE_CALENDAR_TYPE = "calendarType"; //$NON-NLS-1$ + public static final String ATTRIBUTE_CALENDAR_ID = "calendarId"; //$NON-NLS-1$ + public static final String ATTRIBUTE_DIRECTION = "direction"; //$NON-NLS-1$ + public static final String ATTRIBUTE_START_TIME_ORDER = "starttimeorder"; //$NON-NLS-1$ + public static final String ATTRIBUTE_HEADERS = "headers"; //$NON-NLS-1$ + public static final String ATTRIBUTE_DEVICE_NAME = "deviceName"; //$NON-NLS-1$ + public static final String ATTRIBUTE_SCREEN_DESC_NAME = "screenDescName"; //$NON-NLS-1$ + public static final String ATTRIBUTE_MODEL_NAME = "modelName"; //$NON-NLS-1$ + public static final String ATTRIBUTE_SOURCE_TYPE = "sourceType"; //$NON-NLS-1$ + public static final String ATTRIBUTE_POLLING_INTERVAL = "pollingInterval"; //$NON-NLS-1$ + public static final String ATTRIBUTE_CALL_HISTORY_TYPE = "callHistoryType"; //$NON-NLS-1$ + public static final String ATTRIBUTE_CALL_HISTORY_DIRECTION = "callHistoryDirection"; //$NON-NLS-1$ + public static final String ATTRIBUTE_CALL_HISTORY_START_TIME_ORDER = "callHistoryStartTimeOrder"; //$NON-NLS-1$ + public static final String ATTRIBUTE_REMOTE_CALL_REQUEST_TYPE = "remoteCallRequestType"; //$NON-NLS-1$ + public static final String ATTRIBUTE_DATA_BIND = "data_bind"; //$NON-NLS-1$ + + // Project file attribute value + public static final String TRUE = "true"; //$NON-NLS-1$ + public static final String FALSE = "false"; //$NON-NLS-1$ + + // Property + public static final String ELEMENT_PROPERTY = "property"; //$NON-NLS-1$ + public static final String PROPERTY_ID = "id"; //$NON-NLS-1$ + public static final String REGULAREXPRESSION = "^[a-zA-Z]+[a-zA-Z0-9_]*$"; //$NON-NLS-1$ + public static final String ID_PATTERN = "^[a-zA-Z]+[a-zA-Z0-9]*$"; //$NON-NLS-1$ + public static final String INTEGERVALUE = "^[0-9-]?+[0-9]*$"; //$NON-NLS-1$ + public static final String FLOATVALUE = "^[0-9-]?+[.?0-9]*$"; //$NON-NLS-1$ + public static final String SIZEVALUE = "^[0-9-]+[.?0-9]*(?:px|%|cm|em|deg)$"; //$NON-NLS-1$ + public static final String SIZEPATTERN = "(^[0-9]?+[0-9]*)?(px|%|cm|em|deg)?$"; //$NON-NLS-1$ + public static final String UNITPATTERN = "(px|%|cm|em)?$"; //$NON-NLS-1$ + public static final String PROPERTY_VALUE_AUTO = "auto"; //$NON-NLS-1$ + public static final String PROPERTY_VALUE_INHERIT = "inherit"; //$NON-NLS-1$ + public static final String PROPERTY_VALUE_INITIAL = "initial"; //$NON-NLS-1$ + public static final String PROPERTY_VALUE_NORMAL = "normal"; //$NON-NLS-1$ + + // DataBinding + public static final String DATABINDINGVIEW_DEFAULT_MESSAGE = "Data-Binding view is not available."; //$NON-NLS-1$ + public static final String DATABINDING_ARRAYITEM_VALUE_PREFIX = "$data."; //$NON-NLS-1$ + public static final String DATABINDING_ARRAYITEM_VALUE_SUFFIX = ", attr: { 'data-index': $index }"; //$NON-NLS-1$ + public static final String DATABINDING_TYPE_EMPTY = "Empty"; //$NON-NLS-1$ + public static final String DATABINDING_TYPE_STATIC = "static"; //$NON-NLS-1$ + public static final String DATABINDING_DATAMODEL_ITEM_NAME = "item"; //$NON-NLS-1$ + public static final String DATABINDING_TYPE_REMOTECALL = "Remote Call"; //$NON-NLS-1$ + public static final String DATABINDING_ARRAY_ICON = "databinding/array.png"; //$NON-NLS-1$ + public static final String DATABINDING_NUMBER_ICON = "databinding/number.png"; //$NON-NLS-1$ + public static final String DATABINDING_INDEX_ICON = "databinding/index.png"; //$NON-NLS-1$ + public static final String DATABINDING_STRING_ICON = "databinding/string.png"; //$NON-NLS-1$ + public static final String DATABINDING_BOOLEAN_ICON = "databinding/boolean.png"; //$NON-NLS-1$ + public static final String DATABINDING_ARRAY_BIND_ICON = "databinding/array_link.png"; //$NON-NLS-1$ + public static final String DATABINDING_NUMBER_BIND_ICON = "databinding/number_link.png"; //$NON-NLS-1$ + public static final String DATABINDING_INDEX_BIND_ICON = "databinding/index_link.png"; //$NON-NLS-1$ + public static final String DATABINDING_STRING_BIND_ICON = "databinding/string_link.png"; //$NON-NLS-1$ + public static final String DATABINDING_BOOLEAN_BIND_ICON = "databinding/boolean_link.png"; //$NON-NLS-1$ + public static final String DATABINDING_OBJECT_ICON = "databinding/object.png"; //$NON-NLS-1$ + public static final String DATABINDING_OBJECT_BIND_ICON = "databinding/object_link.png"; //$NON-NLS-1$ + public static final String DATABINDING_UNDEFINED_ICON = "databinding/undefined.png"; //$NON-NLS-1$ + public static final String DATABINDING_FORMAT_STRING_ICON = "databinding/format_string.png"; //$NON-NLS-1$ + public static final String DATABINDING_COMPACT_STRING_ICON = "databinding/compact_string.png"; //$NON-NLS-1$ + public static final String DATABINDING_DATA_COLLAPSE_ALL_ICON = "databinding/collapseallfields.png"; //$NON-NLS-1$ + public static final String DATABINDING_DATA_EXPAND_ALL_ICON = "databinding/expandallfields.png"; //$NON-NLS-1$ + public static final String DATABINDING_DATA_ADD_ICON = "databinding/add.png"; //$NON-NLS-1$ + public static final String DATABINDING_DATA_UP_ICON = "databinding/up.png"; //$NON-NLS-1$ + public static final String DATABINDING_DATA_DOWN_ICON = "databinding/down.png"; //$NON-NLS-1$ + public static final String DATABINDING_DATA_REMOVE_ICON = "databinding/remove.png"; //$NON-NLS-1$ + public static final String DATABINDING_DATA_REMOVE_ALL_ICON = "databinding/removeall.png"; //$NON-NLS-1$ + public static final String DATABINDING_DATA_VIEW_SOURCE_ICON = "databinding/view_source.png"; //$NON-NLS-1$ + public static final String DATABINDING_DATA_VIEW_TREE_ICON = "databinding/view_tree.png"; //$NON-NLS-1$ + public static final String DATABINDING_OPEN_ICON = "databinding/open.png"; //$NON-NLS-1$ + public static final String DATABINDING_RELOAD_ICON = "databinding/reload.png"; //$NON-NLS-1$ + public static final String DATABINDING_CLEAR_ICON = "databinding/clear.png"; //$NON-NLS-1$ + public static final String DATABINDING_SAVE_AS_ICON = "databinding/saveas.png"; //$NON-NLS-1$ + public static final String DATABINDING_IMPORT_ICON = "databinding/import.png"; //$NON-NLS-1$ + public static final String DATABINDING_LOAD_ICON = "databinding/load.png"; //$NON-NLS-1$ + + public static final String DATABINDING_EMPTY_ICON = "databinding/empty.png"; //$NON-NLS-1$ + public static final String DATABINDING_FILE_ICON = "databinding/file.png"; //$NON-NLS-1$ + public static final String DATABINDING_REMOTE_ICON = "databinding/remote.png"; //$NON-NLS-1$ + public static final String DATABINDING_STATIC_ICON = "databinding/static.png"; //$NON-NLS-1$ + public static final String DATABINDING_SYSTEM_API_CALL_ICON = "databinding/system_api_calls.png"; //$NON-NLS-1$ + public static final String DATABINDING_MODEL_EMPTY_ICON = "databinding/datamodel_1.png"; //$NON-NLS-1$ + public static final String DATABINDING_MODEL_NOT_EMPTY_ICON = "databinding/datamodel_2.png"; //$NON-NLS-1$ + + public static final String DATABINDING_BINDING_ICON = "databinding/link.png"; //$NON-NLS-1$ + public static final String DATABINDING_BINDING_IMAGE = "databinding/link_image.png"; //$NON-NLS-1$ + public static final String DATABINDING_BINDING_DELETE = "databinding/binding_delete.png"; //$NON-NLS-1$ + public static final String DATABINDING_HIDE_ICON = "databinding/binding_hide.png"; //$NON-NLS-1$ + public static final String DATABINDING_SHOW_ICON = "databinding/binding_show.png"; //$NON-NLS-1$ + public static final String DATABINDING_RENAME_ICON = "databinding/rename.png"; //$NON-NLS-1$ + public static final String DATABINDING_DATASOURCE_DIALOG_ICON = "databinding/datasource_open.png"; //$NON-NLS-1$ + public static final String DATABINDING_DATASOURCE_ADD_ICON = "databinding/datasource_add.png"; //$NON-NLS-1$ + public static final String DATABINDING_DATASOURCE_DELETE_ICON = "databinding/datasource_delete.png"; //$NON-NLS-1$ + public static final String DATABINDING_DATAMODEL_ADD_ICON = "databinding/datamodel_add.png"; //$NON-NLS-1$ + public static final String DATABINDING_DATAMODEL_DELETE_ICON = "databinding/datamodel_delete.png"; //$NON-NLS-1$ + public static final String DATABINDING_DATAMODELITEM_ADD_ICON = "databinding/modelitem_add.png"; //$NON-NLS-1$ + public static final String DATABINDING_DELETE_ICON = "databinding/delete.png"; //$NON-NLS-1$ + public static final String DATABINDING_SET_TARGET_ICON = "databinding/set_target.png"; //$NON-NLS-1$ + public static final String DATABINDING_COLLAPSEALL = "databinding/collapseallfields.png"; + + public static final String DATABINDING_LAYOUT_META_XML = ".databinding"; //$NON-NLS-1$ + public static final String DATABINDING_ROOT_ELEMENT = "dataBinding"; //$NON-NLS-1$ + + // HandlerCodeWriter + public static final String FILENAME = "%FileName%"; //$NON-NLS-1$ + public static final String PAGENAME = UNDERBAR + FILENAME + "_page"; //$NON-NLS-1$ + public static final String FULLFUNCNAME_PREFIX = UNDERBAR + "page.prototype."; //$NON-NLS-1$ + public static final String FUNCNAME = "%FuncName%"; //$NON-NLS-1$ + public static final String FUNCPARAMS = "%FuncParams%"; //$NON-NLS-1$ + public static final String JSEXTENSION = "js"; //$NON-NLS-1$ + public static final String CEXTENSION = "c"; //$NON-NLS-1$ + public static final String PAGEEXTENSION = "page"; //$NON-NLS-1$ + public static final String UNBINDEDFUNCNAME = "unbinded_function"; //$NON-NLS-1$ + public static final String FUNCTION_ANNOTATION = "/**\n * @param {Object} " + FUNCPARAMS + "\n * @base " + PAGENAME //$NON-NLS-1$ //$NON-NLS-2$ + + "\n * @returns {Boolean}\n*/\n"; //$NON-NLS-1$ + public static final String EVENT_HANDLER_FUNCTION = PAGENAME + ".prototype." + FUNCNAME + " = function(" //$NON-NLS-1$ //$NON-NLS-2$ + + FUNCPARAMS + ") {\n\t\n};\n\n"; //$NON-NLS-1$ + + // Command + + // Bit constant + public static final int INVALID = -1; + public static final int SUCCESS = 0; + public static final int NONE = 0; + public static final int HTML_FILE = 1; + public static final int MANAGED_JS_FILE = 1 << 1; + public static final int JS_FILE = 1 << 2; + public static final int CSS_FILE = 1 << 3; + public static final int MANAGED_CSS_FILE = 1 << 4; + + // Nscreen + public static final String SCREEN_FEATURE_COMMON = "Common"; //$NON-NLS-1$ + public static final String SCREEN_FEATURE_PORTRAIT = "Portrait"; //$NON-NLS-1$ + public static final String SCREEN_FEATURE_LANDSCAPE = "Landscape"; //$NON-NLS-1$ + + // Profile + public static final String PROFILE_MOBILE = "mobile"; //$NON-NLS-1$ + public static final String PROFILE_WEARABLE = "wearable"; //$NON-NLS-1$ + public static final String PROFILE_TV = "tv"; //$NON-NLS-1$ + + // Databinding notations + public static final String ARRAY = "Array"; //$NON-NLS-1$ + public static final String INDEX = "Index"; //$NON-NLS-1$ + public static final String INDEXOBJECT = "IndexObject";//$NON-NLS-1$ + public static final String OBJECT = "Object"; //$NON-NLS-1$ + public static final String NUMBER = "Number";//$NON-NLS-1$ + public static final String STRING = "String";//$NON-NLS-1$ + public static final String BOOLEAN = "Boolean"; //$NON-NLS-1$ + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/utils/DataBindingHelper.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/utils/DataBindingHelper.java new file mode 100644 index 0000000..58b04cb --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/utils/DataBindingHelper.java @@ -0,0 +1,328 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.utils; + +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.gef.commands.Command; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.PlatformUI; +import org.tizen.common.util.Assert; +import org.tizen.efluibuilder.BuilderPlugin; +import org.tizen.efluibuilder.model.descriptors.ConstantDescriptor; +import org.tizen.efluibuilder.model.descriptors.PropertyDescriptor; +import org.tizen.efluibuilder.model.descriptors.TypeDescriptor; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.efluibuilder.ui.view.databinding.DataBindingManager; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingData; +import org.tizen.efluibuilder.ui.view.databinding.model.BindingObject; +import org.tizen.efluibuilder.ui.view.databinding.model.DataBindingPartProperty; +import org.tizen.efluibuilder.ui.view.databinding.model.TreeItemData; +import org.tizen.efluibuilder.ui.view.databinding.model.command.DataBindingCommandFactory; +import org.tizen.efluibuilder.ui.view.databinding.utils.Helper.DataSourceType; + +public class DataBindingHelper { + + public static Map parseToMap(String str) { + Map bindingInfos = new HashMap(); + if (str.contains(", ")) { + String[] infos = str.split(", "); + for (String info : infos) { + put(bindingInfos, info); + } + } else { + put(bindingInfos, str); + } + + return bindingInfos; + } + + private static void put(Map bindingInfos, String string) { + String[] infos = string.split(": "); + if (infos.length == 2) { + if ((infos[0] != null) && (!infos[0].isEmpty())) { + if ((infos[1] != null) && (!infos[1].isEmpty())) { + bindingInfos.put(infos[0], infos[1]); + } + } + } + } + + public static void extendItems(ArrayList extendedItems, TreeItem[] items, String selectedPath) { + for (int i = 0; i < items.length; i++) { + if (items[i].getItemCount() > 0) { + if (extendedItems.contains(items[i].getData("path"))) + items[i].setExpanded(true); + } + + if (selectedPath != null && selectedPath.equals(items[i].getData("path"))) { + items[i].getParent().select(items[i]); + if (!items[i].getExpanded()) + items[i].setExpanded(true); + } + extendItems(extendedItems, items[i].getItems(), selectedPath); + } + } + + public static void getExtendedItems(ArrayList extendedItems, TreeItem[] items) { + for (int i = 0; i < items.length; i++) { + if (items[i].getItemCount() > 0) { + if (items[i].getExpanded()) { + String path = (String) items[i].getData("path"); + extendedItems.add(path); + } + getExtendedItems(extendedItems, items[i].getItems()); + } + } + } + + public static String makeStringFromMap(Map bindingInfos) { + Object[] bindingTypes = bindingInfos.keySet().toArray(); + StringBuffer buffer = new StringBuffer(); + for (Object bindingType : bindingTypes) { + String key = bindingType.toString(); + String modelValue = bindingInfos.get(key); + + if (buffer.length() > 0) { + buffer.append(", "); + } + buffer.append(key + ": " + modelValue); + } + + return buffer.toString(); + } + + public static String makeIconPath(String type) { + if (type == null) { + return BuilderConstants.DATABINDING_EMPTY_ICON; + } + + String imageName = null; + if (type.equals(DataSourceType.STATIC.getValue())) { + imageName = BuilderConstants.DATABINDING_STATIC_ICON; + } else if (type.equals(DataSourceType.REMOTE.getValue())) { + imageName = BuilderConstants.DATABINDING_REMOTE_ICON; + } /*else if (type.equals(DataSourceType.CALL_HISTORY.getValue())) { + imageName = BuilderConstants.DATABINDING_SYSTEM_API_CALL_ICON; + } else if (type.equals(DataSourceType.CONTACT.getValue())) { + imageName = BuilderConstants.DATABINDING_SYSTEM_API_CALL_ICON; + } else if (type.equals(DataSourceType.CALENDAR)) { + imageName = BuilderConstants.DATABINDING_SYSTEM_API_CALL_ICON; + } else if (type.equals(DataSourceType.FILE)) { + imageName = BuilderConstants.DATABINDING_FILE_ICON; + } */else { + imageName = BuilderConstants.DATABINDING_EMPTY_ICON; + } + return imageName; + } + + /** + * Creates a view model information. + * + * @param treeItem + * @return view model information + */ + public static String makeDataModelInfoString(TreeItem treeItem) { + if (treeItem == null) { + return null; + } + + String str = ""; + while (treeItem != null && treeItem.getParentItem() != null) { + + if (str.isEmpty()) { + str = treeItem.getText(); + } else { + str = treeItem.getText() + "." + str; + } + treeItem = treeItem.getParentItem(); + } + + if (treeItem != null && treeItem.getData("TREEITEMDATA") != null) { + TreeItemData treeItemData = (TreeItemData) treeItem.getData("TREEITEMDATA"); + str = treeItemData.getOriginModelName() + "-" + str; + } + + return str; + } + + private static String makeInfoString(String modelName, String bindingPath, String bindingType, String oldDbProp) { + String value = ""; + value = bindingType + ": " + modelName + "." + bindingPath; + return value; + } + + public static String toString(String[] items, int indx) { + StringBuilder builder = new StringBuilder(); + for (int i = indx; i < items.length; ++i) { + builder.append(items[i]); + } + return builder.toString(); + } + + public static BindingObject getModelItem(List dataModelObjects, String[] modelIds, int i) { + + for (BindingObject bo : dataModelObjects) { + if (bo.getName().equals(modelIds[i])) { + if (modelIds.length - 1 == i) + return bo; + else + return getModelItem(bo.getBindingObjects(), modelIds, i + 1); + } + } + + return null; + + } + + public static class PopUpListener implements Listener { + private Command command = null; + private Part targetPart; + private String modelName; + private String modelItem; + + public PopUpListener(Part part, String modelName, String modelItem) { + // TODO: Hanlde multiple models to the same Component part? + this.targetPart = part; + this.modelName = modelName; + this.modelItem = modelItem; + } + + public void init() { + command = null; + } + + @Override + public void handleEvent(Event event) { + CombineEditorPart combineEditorPart = (CombineEditorPart) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); + DataBindingManager dataBindManager = combineEditorPart.getDataBindManager(); + MenuItem item = (MenuItem) event.widget; + String bindingType = (String) item.getData("bindingType"); + BindingData dataModel = dataBindManager.getDataModelByModelName(modelName); + + if (dataModel == null) + return; + command = DataBindingCommandFactory.getAddBindingCommand(targetPart, dataModel, modelItem, bindingType); + } + + public Command getCommand() { + return command; + } + } + + public static boolean isIncludeDataBindProp(ComponentPart part, String propType) { + + String propDescValue = part.getPropertyValue(BuilderConstants.ATTRIBUTE_DATA_BIND); + if (propDescValue == null) + return false; + ComponentPart parentPart = null; + if (part.getParent() instanceof ComponentPart) { + parentPart = (ComponentPart) part.getParent(); + } + ComponentDescriptor componentDescriptor = part.getOwnerDocumentPart().getComponentDescriptor(); + PropertyDescriptor propDesc = componentDescriptor.getPropertyDescriptor(parentPart, part, BuilderConstants.ATTRIBUTE_DATA_BIND); + if (propDesc == null) + return false; + + TypeDescriptor TypeDesc = propDesc.getTypeDescriptor(); + if (TypeDesc == null) + return false; + + List list = TypeDesc.getAvailableConstant(); + + for (ConstantDescriptor cd : list) { + if (cd.getValue().equals(propType)) { + return true; + } + } + return false; + } + + public static boolean checkDataBinding(ComponentPart targetModel, DataBindingPartProperty property) { + String allowedBinding = property.getAllowedBindingType(); + if (allowedBinding == null || allowedBinding.isEmpty()) { + return false; + } + if (allowedBinding.equals("Array") && isIncludeDataBindProp(targetModel, "foreach")) { + if (targetModel.getDescriptorId().equals(LayoutSchemaConstants.LIST) && targetModel.getChildren() != null && targetModel.getChildren().size() != 0) { + return false; + } + String[] array = property.getViewItemName().split("\\[\\*\\]"); + int propertyLevel; + if (property.getDataType().equals("Array")) { + propertyLevel = array.length; + } else { + propertyLevel = array.length - 1; + } + int widgetLevel = 1; + Part parent = targetModel.getParent(); + while (parent instanceof ComponentPart) { + if (isIncludeDataBindProp((ComponentPart) parent, "foreach")) { + widgetLevel++; + } + parent = parent.getParent(); + } + return widgetLevel == propertyLevel; + } else if (allowedBinding.equals("Text") && isIncludeDataBindProp(targetModel, "text")) { + return true; + } + return false; + } + + public static String makeDataModelInfo(TreeItem treeItem) { + String viewModelInfo; + viewModelInfo = DataBindingHelper.makeDataModelInfoString(treeItem); + return viewModelInfo; + } + + + public static String getAbsolutePath(String bundleRelativePath) { + Assert.notNull(bundleRelativePath); + URL url = BuilderPlugin.getDefault().getBundle().getEntry(""); + String bundleAbsPath = getAbsolutePath(url); + + return bundleAbsPath + bundleRelativePath; + } + + private static String getAbsolutePath(URL url) { + URL fileUrl = null; + try { + fileUrl = FileLocator.toFileURL(url); + } catch (Exception e) { + return null; + } + return fileUrl.getPath().toString(); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/utils/Helper.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/utils/Helper.java new file mode 100644 index 0000000..6a4814d --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/utils/Helper.java @@ -0,0 +1,1018 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.utils; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.StringReader; +import java.io.StringWriter; +import java.math.BigDecimal; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; +import java.util.Set; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.TransformerFactoryConfigurationError; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.custom.TreeEditor; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.tizen.efluibuilder.ui.view.databinding.dialog.SourceDialogSubPage; +import org.tizen.efluibuilder.ui.view.databinding.dialog.StaticSubPage; +import org.tizen.efluibuilder.ui.view.databinding.model.TreeItemData; +import org.tizen.nativecore.ext.manifest.Manifest; +import org.tizen.nativecore.ext.xmlstore.CoreXMLStore; +import org.tizen.nativecore.misc.IConstants; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonNull; +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; + +public class Helper { + + private enum DataType { + OBJECT, ARRAY, PRIMITIVE + } + + public enum DataSourceType { + + STATIC("static", "Static"), REMOTE("remote", "Remote Call"), /*CALL_HISTORY("call_history", "Call History"), CONTACT("contacts", "Contact"), CALENDAR("calendar", "Calendar"), FILE("file", "File")*/; + + String value; + String label; + + DataSourceType(String value, String label) { + this.value = value; + this.label = label; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + } + + private static final String xmlAttrPrefix = ""; + private static final String xmlTextPrefix = ""; + private static final String xmlTextName = "text"; + private static String nullFixAttrPrefix = null; + + private static Gson gson; + private static DocumentBuilderFactory dbf; + private static DocumentBuilder db; + private static Transformer transformer; + + static { + + if (xmlAttrPrefix.trim().length() == 0) + nullFixAttrPrefix = "__@@__"; + else + nullFixAttrPrefix = xmlAttrPrefix; + + gson = new GsonBuilder().setPrettyPrinting().serializeNulls().create(); + + dbf = DocumentBuilderFactory.newInstance(); + + try { + db = dbf.newDocumentBuilder(); + transformer = TransformerFactory.newInstance().newTransformer(); + transformer.setOutputProperty(OutputKeys.METHOD, "xml"); + } catch (TransformerConfigurationException e) { + e.printStackTrace(); + } catch (TransformerFactoryConfigurationError e) { + e.printStackTrace(); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + } + } + + public static String callURL(String url, String method, int timeout, TableItem[] items) throws Exception { + BufferedReader br = null; + OutputStreamWriter writer = null; + try { + + HttpURLConnection con = null; + if (method.equals("GET")) { + String delimiter = "?"; + if (url.contains("?")) { + delimiter = "&"; + } + con = (HttpURLConnection) new URL(url + delimiter + getParamString(items).toString()).openConnection(); + con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11"); + con.setConnectTimeout(timeout); + } else { + con = (HttpURLConnection) new URL(url).openConnection(); + con.setConnectTimeout(timeout); + con.setDoOutput(true); + writer = new OutputStreamWriter(con.getOutputStream()); + writer.write(getParamString(items).toString()); + writer.flush(); + } + for (TableItem item : items) { + if (item.getText(0).equals("header")) { + con.setRequestProperty(item.getText(1), item.getText(2)); + } + } + + con.setRequestMethod(method); + con.setDoInput(true); + + if (con.getResponseCode() != 200) { + return null; + } + + br = new BufferedReader(new InputStreamReader(con.getInputStream())); + + String line = null; + StringBuilder sb = new StringBuilder(); + + while ((line = br.readLine()) != null) { + sb.append(line); + } + + if (writer != null) { + writer.close(); + writer = null; + } + br.close(); + br = null; + + return sb.toString(); + } catch (Exception e) { + throw e; + } finally { + try { + if (br != null) + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + try { + if (writer != null) + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + public static JsonObject readJsonFromStream(InputStream is) { + BufferedReader br = null; + JsonObject result = null; + try { + br = new BufferedReader(new InputStreamReader(is)); + result = gson.fromJson(br, JsonObject.class); + br.close(); + br = null; + } catch (IOException e) { + e.printStackTrace(); + return null; + } finally { + try { + if (br != null) + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + return result; + } + + public static void makeTreeItem(JsonElement jsonElement, Tree tree, TreeItem item, boolean includeIndex, + SourceDialogSubPage currentSubPage) { + if (jsonElement.isJsonArray()) { + if (item == null) { + item = new TreeItem(tree, 0); + careteTreeItem(item, "TreeRoot", null, "Array"); + } + JsonArray array = jsonElement.getAsJsonArray(); + + for (int i = 0; i < array.size(); i++) { + if (includeIndex) { + TreeItem indexItem = new TreeItem(item, 0); + if (array.get(i).isJsonObject()) { + careteTreeItem(indexItem, String.valueOf(i), null, "IndexObject"); + } else { + careteTreeItem(indexItem, String.valueOf(i), array.get(i) instanceof JsonNull ? null : array.get(i).getAsString(), "Index"); + } + + makeTreeItem(array.get(i), tree, indexItem, includeIndex, currentSubPage); + item.setExpanded(true); + indexItem.setExpanded(true); + } else { + makeTreeItem(array.get(i), tree, item, includeIndex, currentSubPage); + item.setExpanded(true); + break; + } + } + } else if (jsonElement.isJsonObject()) { + + JsonObject jb = jsonElement.getAsJsonObject(); + Set> entrys = jb.entrySet(); + for (Entry entry : entrys) { + + TreeItem treeItem = null; + if (item == null) { + treeItem = new TreeItem(tree, 0); + } else { + treeItem = new TreeItem(item, 0); + } + + if (entry.getValue().isJsonPrimitive()) { + JsonPrimitive jp = entry.getValue().getAsJsonPrimitive(); + String type = null; + if (jp.isBoolean()) + type = "Boolean"; + else if (jp.isNumber()) + type = "Number"; + else // else if ( jp.isString() ) + type = "String"; + + careteTreeItem(treeItem, entry.getKey(), jp.getAsString(), type); + if (includeIndex) + Helper.addComboInTreeItem(treeItem, type, currentSubPage); + } else if (entry.getValue().isJsonObject()) { + careteTreeItem(treeItem, entry.getKey(), null, "Object"); + + if (includeIndex) + Helper.addComboInTreeItem(treeItem, "Object", currentSubPage); + + makeTreeItem(entry.getValue(), tree, treeItem, includeIndex, currentSubPage); + } else if (entry.getValue().isJsonArray()) { + careteTreeItem(treeItem, entry.getKey(), null, "Array"); + + if (includeIndex) + Helper.addComboInTreeItem(treeItem, "Array", currentSubPage); + + makeTreeItem(entry.getValue(), tree, treeItem, includeIndex, currentSubPage); + } else if (entry.getValue().isJsonNull()) { + careteTreeItem(treeItem, entry.getKey(), null, "String"); + + if (includeIndex) + Helper.addComboInTreeItem(treeItem, "String", currentSubPage); + + makeTreeItem(entry.getValue(), tree, treeItem, includeIndex, currentSubPage); + + } + treeItem.setExpanded(true); + } + return; + } else if (jsonElement.isJsonPrimitive()) { + // JsonPrimitive jp = jsonElement.getAsJsonPrimitive(); + // String type = null; + // if ( jp.isBoolean() ) { + // type = "Boolean"; + // } else if ( jp.isNumber() ) { + // type = "Number"; + // } else if ( jp.isString() ) { + // type = "String"; + // } + // + // if ( item.getParent().getColumnCount() > 0 ) { + // TreeItem primitiveItem = new TreeItem( item, 0 ); + // Helper.careteTreeItem( primitiveItem, null, jp.getAsString(), + // type ); + // + // if ( includeIndex ) + // Helper.addComboInTreeItem( primitiveItem, type, currentSubPage ); + // + // item.setExpanded( true ); + // } + } + } + + private static TreeItem careteTreeItem(TreeItem treeItem, String key, String value, String type) { + + TreeItemData treeItemData = new TreeItemData(); + + if (treeItem.getParent().getColumnCount() == 1) { + treeItem.setText(key); + } else { + treeItem.setText(new String[] { key, value, type }); + } + + treeItemData.setObjectType(type); + treeItemData.setObjectValue(value); + treeItemData.setSource("original"); + + treeItem.setData("TREEITEMDATA", treeItemData); + + String imageName = null; + + if (type.equals("Array")) { + imageName = BuilderConstants.DATABINDING_ARRAY_ICON; + } else if (type.equals("Number")) { + imageName = BuilderConstants.DATABINDING_NUMBER_ICON; + } else if (type.equals("String")) { + imageName = BuilderConstants.DATABINDING_STRING_ICON; + } else if (type.equals("Index") || type.equals("IndexObject")) { + imageName = BuilderConstants.DATABINDING_INDEX_ICON; + } else if (type.equals("Object")) { + imageName = BuilderConstants.DATABINDING_OBJECT_ICON; + } else if (type.equals("Boolean")) { + imageName = BuilderConstants.DATABINDING_BOOLEAN_ICON; + } else { + imageName = BuilderConstants.DATABINDING_UNDEFINED_ICON; + } + + if (imageName != null) { + treeItem.setImage(ResourceManager.getImage(BuilderConstants.ICON_DIR, imageName)); + } + + return treeItem; + } + + public static void makeJsonFromTree(TreeItem parentItem, JsonElement parentJsonElement) { + String key = parentItem.getText(0); + String value = parentItem.getText(1); + String type = parentItem.getText(2); + + TreeItem[] items = parentItem.getItems(); + + JsonObject jsonOb = null; + + if (type.equals("Array")) { + JsonArray array = new JsonArray(); + ((JsonObject) parentJsonElement).add(key, array); + jsonOb = null; + for (TreeItem item : items) { + if (item.getText(2).equals("Index")) { + makeJsonFromTree(item, array); + } else if(item.getText(2).equals("IndexObject")){ + jsonOb = new JsonObject(); + array.add(jsonOb); + makeJsonFromTree(item, jsonOb); + } + } + } else if (type.equals("Object")) { + jsonOb = new JsonObject(); + ((JsonObject) parentJsonElement).add(key, jsonOb); + for (TreeItem item : items) { + makeJsonFromTree(item, jsonOb); + } + } else if (type.equals("Index")) { + ((JsonArray) parentJsonElement).add(new JsonPrimitive(parentItem.getText(1))); + } else if (type.equals("IndexObject")) { + for (TreeItem item : items) { + makeJsonFromTree(item, parentJsonElement); + } + } else if (type.equals("String")) { + ((JsonObject) parentJsonElement).addProperty(key, value); + } else if (type.equals("Boolean")) { + ((JsonObject) parentJsonElement).addProperty(key, Boolean.valueOf(value)); + parentItem.setText(1, Boolean.valueOf(value).toString()); + } else if (type.equals("Number")) { + try { + ((JsonObject) parentJsonElement).addProperty(key, new BigDecimal(value)); + } catch (NumberFormatException e) { + ((JsonObject) parentJsonElement).addProperty(key, new BigDecimal(0)); + parentItem.setText(1, "0"); + } + } else if (type.equals("Undefined") && value != null) { + ((JsonObject) parentJsonElement).addProperty(key, value); + } else { + ((JsonObject) parentJsonElement).add(key, null); + } + } + + public static Composite makeInputText(Composite parentComposite, String title) { + + Composite subComposite = new Composite(parentComposite, SWT.NONE); + FormLayout layout = new FormLayout(); + subComposite.setLayout(layout); + + Label label = new Label(subComposite, SWT.NONE); + label.setText(title); + FormData data = new FormData(); + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(0, 0); + label.setLayoutData(data); + + Text text = new Text(subComposite, SWT.SINGLE | SWT.BORDER); + + data = new FormData(200, 16); + data.top = new FormAttachment(label, 2); + data.left = new FormAttachment(10, 0); + data.right = new FormAttachment(100, 0); + text.setLayoutData(data); + subComposite.setData(text); + return subComposite; + } + + public static Composite makeInputCombo(Composite parentComposite, String title, String[] items) { + + Composite subComposite = new Composite(parentComposite, SWT.NONE); + FormLayout layout = new FormLayout(); + subComposite.setLayout(layout); + + Label label = new Label(subComposite, SWT.NONE); + label.setText(title); + FormData data = new FormData(); + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(0, 0); + label.setLayoutData(data); + + CCombo combo = new CCombo(subComposite, SWT.SINGLE | SWT.BORDER | SWT.FLAT | SWT.READ_ONLY); + data = new FormData(200, 26); + data.top = new FormAttachment(label, 2); + data.left = new FormAttachment(10, 0); + data.right = new FormAttachment(100, 0); + combo.setLayoutData(data); + combo.setItems(items); + combo.select(0); + + subComposite.setData(combo); + + return subComposite; + } + + public static String getParamString(TableItem[] items) { + StringBuilder query = new StringBuilder(); + boolean isFirst = true; + + for (TableItem item : items) { + + if (item.getText(0).equals("query") && (item.getText(1) + item.getText(2)).trim().length() > 0) { + if (isFirst) { + isFirst = false; + } else { + query.append("&"); + } + + query.append(item.getText(1)).append("=").append(item.getText(2)); + } + } + + return query.toString(); + } + + public static String getHeadersString(HashMap headers) { + StringBuilder headerString = new StringBuilder(); + for (HashMap.Entry header : headers.entrySet()) { + headerString.append(header.getKey()).append("=").append(header.getValue()).append(";"); + } + return headerString.toString(); + } + + public static JsonObject getJsonFromXML(String xml) throws SAXException { + + Document doc = parseXML(xml); + + JsonObject root = new JsonObject(); + if (doc != null) { + NodeList nodeList = doc.getChildNodes(); + parseNodeList(root, nodeList); + } + + return root; + } + + public static Document parseXML(String xml) throws SAXException { + DocumentBuilder db; + Document doc = null; + try { + InputSource inStream = new InputSource(); + inStream.setCharacterStream(new StringReader(xml)); + db = dbf.newDocumentBuilder(); + doc = db.parse(inStream); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + } catch (SAXException e) { + throw e; + } catch (IOException e) { + e.printStackTrace(); + } + + return doc; + } + + /** + * @param parentJson + * @param nodeList + */ + private static void parseNodeList(JsonObject parentJson, NodeList nodeList) { + HashMap meta = createMetaData(nodeList); + HashMap arrayParents = new HashMap(); + + for (int i = 0; i < nodeList.getLength(); i++) { + + Node node = nodeList.item(i); + JsonObject jsonOb = null; + + DataType type = meta.get(node.getNodeName()); + + if (type == DataType.ARRAY) { + + Node parentNode = node.getParentNode(); + String nodePath = parentNode.getNodeName() + "/" + node.getNodeName(); + + while ((parentNode = parentNode.getParentNode()) != null) { + nodePath = parentNode.getNodeName() + "/" + nodePath; + } + + JsonArray parentArray = null; + + if ((parentArray = arrayParents.get(nodePath)) == null) { + parentArray = new JsonArray(); + parentJson.add(node.getNodeName(), parentArray); + arrayParents.put(nodePath, parentArray); + } + + if (node.getChildNodes().getLength() == 1 && node.getFirstChild().getNodeType() == Node.TEXT_NODE) { + parentArray.add(new JsonPrimitive(node.getFirstChild().getTextContent())); + } else { + jsonOb = new JsonObject(); + parentArray.add(jsonOb); + + parseNodeList(jsonOb, node.getChildNodes()); + addAttributes(jsonOb, node); + } + + } else if (type == DataType.OBJECT) { + jsonOb = new JsonObject(); + parentJson.add(node.getNodeName(), jsonOb); + + parseNodeList(jsonOb, node.getChildNodes()); + addAttributes(jsonOb, node); + } else if (type == DataType.PRIMITIVE) { + if (node.getFirstChild() != null) { + parentJson.addProperty(node.getNodeName(), node.getFirstChild().getTextContent()); + } else { + parentJson.add(node.getNodeName(), null); + } + } + } + } + + /** + * @param jsonOb + * @param node + */ + private static void addAttributes(JsonObject jsonOb, Node node) { + boolean isExistChild = false; + + for (int j = 0; j < node.getAttributes().getLength(); j++) { + Node attNode = node.getAttributes().item(j); + jsonOb.addProperty(xmlAttrPrefix + attNode.getNodeName(), attNode.getNodeValue()); + isExistChild = true; + } + + if (node.getChildNodes().getLength() > 0) + isExistChild = true; + + String textNodeName = ""; + + if (isExistChild) + textNodeName = xmlTextPrefix + xmlTextName; + + if (node.getFirstChild() != null && node.getFirstChild().getNodeType() == Node.TEXT_NODE + && node.getFirstChild().getTextContent().trim().length() != 0) { + jsonOb.addProperty(textNodeName, node.getFirstChild().getTextContent()); + } + } + + /** + * @param nodeList + * @return + */ + private static HashMap createMetaData(NodeList nodeList) { + HashMap result = new HashMap(); + for (int i = 0; i < nodeList.getLength(); i++) { + Node node = nodeList.item(i); + + if (node.getNodeType() != Node.ELEMENT_NODE) { + continue; + } + + DataType type = result.get(node.getNodeName()); + + if (type != null) { + result.put(node.getNodeName(), DataType.ARRAY); + } else if (node.getAttributes().getLength() == 0 && node.getChildNodes().getLength() == 1 + && node.getFirstChild().getNodeType() == Node.TEXT_NODE) { + result.put(node.getNodeName(), DataType.PRIMITIVE); + } else { + result.put(node.getNodeName(), DataType.OBJECT); + } + } + return result; + } + + public static void removeAllChildren(TreeItem[] treeItems) { + for (TreeItem item : treeItems) { + TreeEditor editor = (TreeEditor) item.getData("TREEEDITORFORCOMBO"); + if (editor != null) { + editor.getEditor().dispose(); + editor.dispose(); + } + item.dispose(); + } + } + + public static Combo addComboInTreeItem(TreeItem item, String data, final SourceDialogSubPage currentSubPage) { + + TreeEditor treeEditor = new TreeEditor(item.getParent()); + treeEditor.grabHorizontal = true; + treeEditor.grabVertical = true; + + Combo combo = new Combo(item.getParent(), SWT.SINGLE | SWT.READ_ONLY); + treeEditor.setEditor(combo, item, 2); + final String[] comboItems = { "String", "Number", "Boolean", "Object", "Array" }; + + combo.setVisibleItemCount(comboItems.length); + combo.setItems(comboItems); + combo.select(Arrays.asList(comboItems).indexOf(data)); + combo.setData("parentItem", item); + + item.setData("TREEEDITORFORCOMBO", treeEditor); + + combo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Combo combo = (Combo) e.getSource(); + TreeItem parentItem = (TreeItem) combo.getData("parentItem"); + String selectedText = ""; + int selectionIndex = combo.getSelectionIndex(); + if (selectionIndex >= 0) + selectedText = comboItems[selectionIndex]; + String parentText = parentItem.getText(2); + + if(selectedText.equals(parentText)) + return; + + if(parentText.equals("Object") && selectedText.equals("Array")){ // Allow changing from Object to Array + TreeItem[] items = parentItem.getItems(); + TreeItem newItem = new TreeItem(parentItem, SWT.NONE); + newItem.setText(new String[] { "0", "", "IndexObject" }); + String imageName = BuilderConstants.DATABINDING_INDEX_ICON; + newItem.setImage(ResourceManager.getImage(BuilderConstants.ICON_DIR, imageName)); + addAllChildrenRecursively(items, newItem, currentSubPage); + removeAllChildren(items); + } else if(selectedText.equals("Array")){ + TreeItem newItem = new TreeItem(parentItem, SWT.NONE); + newItem.setText(new String[]{"0", parentItem.getText(1), "Index"}); + newItem.setImage(ResourceManager.getImage(BuilderConstants.ICON_DIR, BuilderConstants.DATABINDING_INDEX_ICON)); + TreeItemData treeItemData = new TreeItemData(); + treeItemData.setSource("custom"); + treeItemData.setObjectType(newItem.getText(2)); + treeItemData.setObjectValue(newItem.getText(1)); + + newItem.setData("TREEITEMDATA", treeItemData); + parentItem.setText(new String[]{parentItem.getText(0), "", "Array"}); + } else if ((parentText.equals("Object") || parentText.equals("Array")) && parentItem.getItemCount() > 0 + && !selectedText.equals(parentText)) { + + String msg = "Error : Can not change the type of items that have a child."; + MessageBox messageBox = new MessageBox(combo.getShell(), SWT.ICON_WARNING); + messageBox.setText("Set Source Warning"); + messageBox.setMessage(msg); + combo.select(Arrays.asList(comboItems).indexOf(parentText)); + messageBox.open(); + return; + } + + if (selectedText.equals("Object")) { + parentItem.setText(1, ""); + } + + parentItem.setText(2, selectedText); + + String imageName; + + if (selectedText.equals("Array")) { + imageName = BuilderConstants.DATABINDING_ARRAY_ICON; + } else if (selectedText.equals("Number")) { + imageName = BuilderConstants.DATABINDING_NUMBER_ICON; + } else if (selectedText.equals("String")) { + imageName = BuilderConstants.DATABINDING_STRING_ICON; + } else if (selectedText.equals("Index")) { + imageName = BuilderConstants.DATABINDING_INDEX_ICON; + } else if (selectedText.equals("Object")) { + imageName = BuilderConstants.DATABINDING_OBJECT_ICON; + } else if (selectedText.equals("Boolean")) { + imageName = BuilderConstants.DATABINDING_BOOLEAN_ICON; + } else { + imageName = BuilderConstants.DATABINDING_UNDEFINED_ICON; + } + + if (imageName != null) { + parentItem.setImage(ResourceManager.getImage(BuilderConstants.ICON_DIR, imageName)); + } + + if (currentSubPage instanceof StaticSubPage) { + ((StaticSubPage) currentSubPage).updateJsonFromTree(); + } + } + }); + + return combo; + } + + public static void addAllChildrenRecursively(TreeItem[] items, TreeItem parentItem, SourceDialogSubPage currentSubPage) { + // TODO Auto-generated method stub + if(items.length <= 0){ + return; + } + for (TreeItem treeItem : items) { + TreeItem newItem = new TreeItem(parentItem, SWT.NONE); + newItem.setText(new String[] { treeItem.getText(0), treeItem.getText(1), treeItem.getText(2)}); + String type = treeItem.getText(2); + String imageName; + if (!type.equals("Index") && !type.equals("IndexObject")) + Helper.addComboInTreeItem(newItem, type, currentSubPage); + + + if (type.equals("Array")) { + imageName = BuilderConstants.DATABINDING_ARRAY_ICON; + } else if (type.equals("Number")) { + imageName = BuilderConstants.DATABINDING_NUMBER_ICON; + } else if (type.equals("String")) { + imageName = BuilderConstants.DATABINDING_STRING_ICON; + } else if (type.equals("Index") || type.equals("IndexObject")) { + imageName = BuilderConstants.DATABINDING_INDEX_ICON; + } else if (type.equals("Object")) { + imageName = BuilderConstants.DATABINDING_OBJECT_ICON; + } else if (type.equals("Boolean")) { + imageName = BuilderConstants.DATABINDING_BOOLEAN_ICON; + } else { + imageName = BuilderConstants.DATABINDING_UNDEFINED_ICON; + } + + if (imageName != null) { + newItem.setImage(ResourceManager.getImage(BuilderConstants.ICON_DIR, imageName)); + } + TreeItemData treeItemData = new TreeItemData(); + treeItemData.setSource("original"); + treeItemData.setObjectType(treeItem.getText(2)); + treeItemData.setObjectValue(treeItem.getText(1)); + + newItem.setData("TREEITEMDATA", treeItemData); + addAllChildrenRecursively(treeItem.getItems(), newItem, currentSubPage); + } + } + public static String streamToString(InputStream is) { + StringBuilder sb = new StringBuilder(); + + BufferedReader br = null; + String line = null; + + try { + br = new BufferedReader(new InputStreamReader(is)); + + while ((line = br.readLine()) != null) { + sb.append(line); + } + + br.close(); + is.close(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (is != null) { + try { + is.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + return sb.toString(); + } + + public static String getStringFromDocument(Document dom, boolean indented) { + String signedContent = null; + + if (!indented) { + dom.normalize(); + dom.normalizeDocument(); + } + + try { + StringWriter sw = new StringWriter(); + DOMSource domSource = new DOMSource(dom); + transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + transformer.setOutputProperty(OutputKeys.INDENT, indented ? "yes" : "no"); + transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", indented ? "2" : "0"); + transformer.transform(domSource, new StreamResult(sw)); + sw.flush(); + signedContent = sw.toString(); + } catch (TransformerException e) { + e.printStackTrace(); + } + + return signedContent; + } + + public static Document getXMLFromJson(Document doc, Element element, JsonElement jsonElement) { + + if (doc == null) + doc = db.newDocument(); + + if (jsonElement.isJsonArray()) { + JsonArray array = jsonElement.getAsJsonArray(); + for (int i = 0; i < array.size(); i++) { + getXMLFromJson(doc, element, array.get(i)); + } + } else if (jsonElement.isJsonObject()) { + JsonObject jb = jsonElement.getAsJsonObject(); + + JsonElement textElement = jb.get(xmlTextPrefix + xmlTextName); + if (textElement != null) + element.setTextContent(textElement.getAsString()); + + Set> entrys = jb.entrySet(); + for (Entry entry : entrys) { + + String key = entry.getKey(); + Element newChild = null; + + if (entry.getValue().isJsonArray()) { + JsonArray value = entry.getValue().getAsJsonArray(); + Iterator valueIterator = value.iterator(); + while(valueIterator.hasNext()){ + if (!key.startsWith(nullFixAttrPrefix) && !key.equals(xmlTextPrefix + xmlTextName)) { + newChild = doc.createElement(key); + if (element == null) + doc.appendChild(newChild); + else + element.appendChild(newChild); + } + getXMLFromJson(doc, newChild, valueIterator.next()); + } + } else { + if (!key.startsWith(nullFixAttrPrefix) && !key.equals(xmlTextPrefix + xmlTextName)) { + newChild = doc.createElement(key); + if (element == null) + doc.appendChild(newChild); + else + element.appendChild(newChild); + } + } + + if (entry.getValue().isJsonPrimitive()) { + String value = entry.getValue().getAsJsonPrimitive().getAsString(); + if (element != null && key.startsWith(nullFixAttrPrefix)) { + element.setAttribute(key.substring(1, key.length()), value); + } else if (key.equals(xmlTextPrefix + xmlTextName)) { + continue; + } else if(newChild != null){ + newChild.setTextContent(value); + } + } else if (entry.getValue().isJsonObject()) { + getXMLFromJson(doc, newChild, entry.getValue()); + } else if(element != null) { + element.appendChild(newChild); + } + } + return doc; + } else if (jsonElement.isJsonPrimitive()) { + element.setTextContent(jsonElement.getAsJsonPrimitive().getAsString()); + } + return doc; + + } + + /** + * + * @param shell + * @param privilegeKeys + * required for specific datasource + * @param project + * @return false if privileges are already present + */ + public static boolean addPrivileges(Shell shell, List privilegeKeys, IProject project) { + + CoreXMLStore coreXmlManager = new CoreXMLStore(project); + coreXmlManager.loadXml(); + Manifest manifestModel = coreXmlManager.getCoreManifest(); + Collection privileges = coreXmlManager.getPrivileges(); + if (privileges != null) { + for (String privilege : privileges) { + for (Iterator itr = privilegeKeys.iterator(); itr.hasNext();) { + String privilegeKey = itr.next(); + if (privilege.equals(privilegeKey)) { + itr.remove(); + } + } + } + } + + if (!privilegeKeys.isEmpty()) { + StringBuilder privileges_list = new StringBuilder("\n"); + for (String privilege : privilegeKeys) { + privileges_list = privileges_list.append("\"").append(privilege).append("\"\n"); + } + String msg = "Additional privileges required " + privileges_list + " Do you want to add? \n (Privileges addition can not be undone)"; + MessageBox mb = new MessageBox(shell, SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL); + mb.setText("Set Source"); + mb.setMessage(msg); + + if (mb.open() == SWT.OK) { + for (String privilege : privilegeKeys) { + manifestModel.addPrivilege(privilege); + } + // Updating privileges to tizen-manifest.xml file + coreXmlManager.storeXml(); + IFile manifestFile = project.getFile(IConstants.MANIFEST_FILE); + + // Refresh the tizen-manifest.xml file + try { + manifestFile.refreshLocal(IResource.DEPTH_ZERO, null); + } catch (CoreException e) { + e.printStackTrace(); + } + + } else { + return false; + } + } + return true; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/utils/ResourceManager.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/utils/ResourceManager.java new file mode 100644 index 0000000..80e48f3 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/view/databinding/utils/ResourceManager.java @@ -0,0 +1,181 @@ +/* + * UI Builder - Databinding + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + +package org.tizen.efluibuilder.ui.view.databinding.utils; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.common.util.IOUtil; +import org.tizen.efluibuilder.BuilderPlugin; + +public class ResourceManager { + private static final String ID = "org.tizen.efluibuilder"; + private static ImageRegistry imageRegistry = BuilderPlugin.getDefault().getImageRegistry(); + protected static final Logger logger = LoggerFactory.getLogger(ResourceManager.class); + + private ResourceManager() { + } + + /** + * + * @param dir + * image directory + * @param imageName + * resource name + * @return Image object from resource + */ + public static Image getImage(String dir, String imageName) { + String imageFilePath = dir + imageName; + String key = imageFilePath; + if (imageRegistry.get(key) == null || imageRegistry.get(key).isDisposed()) { + ImageDescriptor desc = AbstractUIPlugin.imageDescriptorFromPlugin(ID, imageFilePath); + imageRegistry.put(key, desc); + } + + return imageRegistry.get(key); + } + + public static Image getImage(String name) { + return getImage(BuilderConstants.IMAGE_DIR, name); + } + + public static Image getIcon(String name) { + return getImage(BuilderConstants.ICON_DIR, name); + } + + /** + * @param dir + * image directory + * @param imageName + * resource name + * @return ImageDescriptor object from resource + */ + public static ImageDescriptor getImageDescriptor(String dir, String imageName) { + if (imageName == null || imageName.equals(BuilderConstants.EMPTY)) { + return null; + } + + ImageDescriptor desc = AbstractUIPlugin.imageDescriptorFromPlugin(ID, dir + imageName); + return desc; + } + + public static ImageDescriptor getImageDescriptor(String name) { + return getImageDescriptor(BuilderConstants.IMAGE_DIR, name); + } + + public static ImageDescriptor getIconDescriptor(String name) { + return getImageDescriptor(BuilderConstants.ICON_DIR, name); + } + + /** + * @param resource + * name + * @return URL of resource file + */ + public static URL getResource(String name) { + return BuilderPlugin.getDefault().getBundle().getResource(name); + } + + /** + * @param resource + * name + * @return InputStream of resource file + * @throws IOException + */ + public static InputStream openStream(String name) throws IOException { + InputStream stream = getResource(name).openStream(); + return stream; + } + + /** + * + * @param name + * resource name (bundle relative path) + * @return String of resource file (or null) + */ + public static String getString(String name) { + InputStream stream = null; + try { + stream = openStream(name); + int length = stream.available(); + if (length > 4096) { + logger.warn("Resource file is too large"); + } + byte[] buffer = new byte[length]; + int readLength = stream.read(buffer); + if (readLength == -1) { + logger.warn("End of file"); + } + stream.close(); + return new String(buffer, BuilderConstants.ENCODING); + } catch (IOException e) { + IOUtil.tryClose(stream); + return null; + } + + } + + /** + * Copy Plugin resource -> Project file + * + * @param src + * resource name + * @param dst + * dst file + * @throws IOException + * @throws CoreException + */ + /* + * public static final void copy(String src, IFile dst) throws IOException, + * CoreException { InputStream stream = ResourceManager.openStream(src); + * dst.create(stream, false, null); } + */ + + public static URL getFileURL(String bundle, String fullPath) { + URL url = null; + if (fullPath != null && !fullPath.isEmpty()) { + url = FileLocator.find(org.eclipse.core.runtime.Platform.getBundle(bundle), new Path(fullPath), null); + } else { + url = FileLocator.find(org.eclipse.core.runtime.Platform.getBundle(bundle), new Path(""), null); + } + if (url != null) { + try { + return FileLocator.resolve(url); + } catch (IOException e) { + return null; + } + } + return null; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/Messages.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/Messages.java new file mode 100644 index 0000000..fa180f2 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/Messages.java @@ -0,0 +1,60 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.outline; + +import org.eclipse.osgi.util.NLS; + + +public final class Messages { + private static final String BUNDLE_NAME = Messages.class.getName(); + + // == filters + public static String FILTER_TEXT; + + // == actions + + // rename + public static String RENAME; + + // new view + public static String ACTION_ADD_VIEW_TITLE; + public static String ACTION_ADD_VIEW_TEMPLATE_TITLE; + public static String ACTION_ADD_VIEW_EMPTY_TITLE; + public static String ACTION_ADD_VIEW_EMPTY_ICON_NOR; + public static String ACTION_ADD_VIEW_EMPTY_ICON_MV; + public static String ACTION_ADD_VIEW_EMPTY_ICON_SEL; + public static String ACTION_ADD_VIEW_POPUP_TITLE; + public static String ACTION_ADD_VIEW_CTXPOPUP_TITLE; + public static String ACTION_SET_MAIN_VIEW_TITLE; + + public static String ACTION_CREATE_TEMPLATE_VIEW_TITLE; + + static { + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/Messages.properties b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/Messages.properties new file mode 100644 index 0000000..a4dcfc1 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/Messages.properties @@ -0,0 +1,22 @@ +# Messages + +# Filters +FILTER_TEXT=type filter text + +#== actions +# rename +RENAME=Modify ID + +# new view +ACTION_ADD_VIEW_TITLE=&Add View +ACTION_ADD_VIEW_EMPTY_TITLE=&Empty View +ACTION_ADD_VIEW_TEMPLATE_TITLE=&View From Template List... +ACTION_ADD_VIEW_POPUP_TITLE=&Popup View +ACTION_ADD_VIEW_CTXPOPUP_TITLE=&Ctxpopup View + +ACTION_ADD_VIEW_EMPTY_ICON_NOR=res/icons/outline/t_outline_icon2_nor.png +ACTION_ADD_VIEW_EMPTY_ICON_MV=res/icons/outline/t_outline_icon2_mv.png +ACTION_ADD_VIEW_EMPTY_ICON_SEL=res/icons/outline/t_outline_icon2_sel.png +ACTION_SET_MAIN_VIEW_TITLE=&Set As Startup View + +ACTION_CREATE_TEMPLATE_VIEW_TITLE=&Save As View Template \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineConstants.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineConstants.java new file mode 100644 index 0000000..40d2558 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineConstants.java @@ -0,0 +1,87 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.outline; + +/** + * A OutlinePage constants + */ +public final class OutlineConstants { + + // Action key (popup, ctxpopup) + public static final String KEY_POPUP_VIEW = "Popup"; //$NON-NLS-1$ + public static final String KEY_CTXPOPUP_VIEW = "Ctxpopup"; //$NON-NLS-1$ + + // ActionConstants + public static final String RENAME_GROUP = "outline rename group"; //$NON-NLS-1$ + public static final String RENAME_ACTION = "outline rename"; //$NON-NLS-1$ + + // ==== + // New View Group + public static final String ADD_VIEW_GROUP = "org.tizen.efluibuilder.ui.view.outline.action.addviewgroup"; + + /** + * New popup view action id. + */ + public static final String ADD_VIEW_POPUP = "org.tizen.efluibuilder.ui.view.outline.action.AddViewPopup";//$NON-NLS-1$ + + /** + * New ctxpopup view action id. + */ + public static final String ADD_VIEW_CTXPOPUP = "org.tizen.efluibuilder.ui.view.outline.action.AddViewCtxpopup";//$NON-NLS-1$ + + /** + * New view template action id. + */ + public static final String ADD_VIEW_TEMPLATE = "org.tizen.efluibuilder.ui.view.outline.action.AddViewtemplate";//$NON-NLS-1$ + + /** + * Set main view action id. + */ + public static final String CREATE_TEMPLATE_VIEW = "org.tizen.efluibuilder.ui.view.outline.action.CreateTemplateView";//$NON-NLS-1$ + + /** + * Show view action id. + *

+ * Value : "org.tizen.efluibuilder.ui.view.outline.action.ShowView" + */ + public static final String SHOW_VIEW = "org.tizen.efluibuilder.ui.view.outline.action.ShowView";//$NON-NLS-1$ + + /** + * Show popup view action id. + *

+ * Value : "org.tizen.efluibuilder.ui.view.outline.action.ShowPopup" + */ + public static final String SHOW_POPUP = "org.tizen.efluibuilder.ui.view.outline.action.ShowPopup";//$NON-NLS-1$ + + /** + * Show text filter action id. + *

+ * "org.tizen.efluibuilder.ui.view.outline.action.ShowTextFilter" + */ + public static final String SHOW_TEXT_FILTER = "org.tizen.efluibuilder.ui.view.outline.action.ShowTextFilter";//$NON-NLS-1$ + + // RequestConstnats + public static final String REQ_RENAME = "outlineview treeitem rename"; //$NON-NLS-1$ + public static final String NEW_NAME = "treeitem new name"; //$NON-NLS-1$ +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineContextMenu.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineContextMenu.java new file mode 100644 index 0000000..152938d --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineContextMenu.java @@ -0,0 +1,61 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.outline; + +import org.eclipse.gef.EditPartViewer; +import org.eclipse.gef.ui.actions.ActionRegistry; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.Separator; +import org.tizen.efluibuilder.ui.contextmenu.CommonContextMenu; + + +public final class OutlineContextMenu extends CommonContextMenu { + // Storyboard Start + // private IEventsMenu eventMenu; + + public OutlineContextMenu(EditPartViewer viewer, + ActionRegistry registry/* , IEventsMenu eventMenu */) { + super(viewer, registry); + // this.eventMenu = eventMenu; + } + + @SuppressWarnings("unchecked") + @Override + public void buildContextMenu(IMenuManager menu) { + addUndoContextMenu(menu); + addEditContextMenu(menu); + addViewSpecificContextMenu(menu); + + IAction action = null; + + // ADD RENAME + menu.add(new Separator(OutlineConstants.RENAME_GROUP)); + + action = getAction(OutlineConstants.RENAME_ACTION); + if (action != null) { + menu.appendToGroup(OutlineConstants.RENAME_GROUP, action); + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineEditPartFactory.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineEditPartFactory.java new file mode 100644 index 0000000..7507b0b --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineEditPartFactory.java @@ -0,0 +1,48 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.outline; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPartFactory; +import org.eclipse.gef.ui.actions.ActionRegistry; +import org.eclipse.ui.IActionBars; + + +public final class OutlineEditPartFactory implements EditPartFactory { + private IActionBars actionBars = null; + private ActionRegistry registry = null; + + public OutlineEditPartFactory(IActionBars actionBars, ActionRegistry registry) { + this.actionBars = actionBars; + this.registry = registry; + } + + @Override + public EditPart createEditPart(EditPart context, Object model) { + EditPart editPart = new OutlineViewEditPart(actionBars, registry); + editPart.setModel(model); + + return editPart; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineEditPolicy.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineEditPolicy.java new file mode 100644 index 0000000..df76c95 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineEditPolicy.java @@ -0,0 +1,184 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.outline; + +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.TreeEditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.editpolicies.TreeContainerEditPolicy; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.TreeItem; +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.PartUtil; + + +/** + * An edit policy class for outline page. + */ +public final class OutlineEditPolicy extends TreeContainerEditPolicy { + + @Override + protected Command getAddCommand(ChangeBoundsRequest request) { + return getMoveCommand(request); + } + + @Override + protected Command getCreateCommand(CreateRequest request) { + Part parent = null; + Part child = null; + Part refChild = null; + Part part = (Part) getHost().getModel(); + Part nextSibling = null; + + if ((Part) request.getNewObject() == null) { + return null; + } + + Point point = request.getLocation(); + TreeEditPart treeEditPart = (TreeEditPart) getHost().getViewer().findObjectAt(point); + if (treeEditPart == null) { + return null; + } + if (!(treeEditPart.getWidget() instanceof TreeItem)) { + return null; + } + TreeItem item = (TreeItem) treeEditPart.getWidget(); + refChild = (Part) treeEditPart.getModel(); + Rectangle rect = item.getBounds(); + + ComponentDescriptor componentDescriptor = part.getOwnerDocumentPart().getComponentDescriptor(); + if ((refChild.equals(part)) && componentDescriptor.canHaveChild((ComponentPart) part, (ComponentPart) request.getNewObject())) { + parent = (Part) getHost().getParent().getModel(); + child = (Part) request.getNewObject(); + nextSibling = null; + } else if (refChild.equals(part)) { + return null; + } else if (!part.getChildren().isEmpty()) { + parent = part; + child = (Part) request.getNewObject(); + + if (isNextPosion(rect, point)) { + nextSibling = refChild; + } else { + nextSibling = refChild.getNextSibling(); + } + } + + return PartUtil.createAddPartCommand(parent, child, nextSibling); + } + + private boolean isNextPosion(Rectangle rect, Point point) { + Rectangle temp = rect; + temp.y = rect.y + (rect.height / 2); + temp.height = rect.height / 2; + + if (temp.contains(point.x, point.y)) { + return true; + } else { + return false; + } + } + + @Override + protected Command getMoveChildrenCommand(ChangeBoundsRequest request) { + // TODO implement + return null; + } + + /** + * Gets a rename {@link Command}. + * + * @param request + * a {@link Request} + * @return a rename {@link Command} + */ + protected Command getRenameCommand(Request request) { + Object object = getHost().getModel(); + /* + * if (object instanceof ViewPart) { ViewPart viewPart = (ViewPart) getHost().getModel(); + * return PartUtil.createSetViewPropertyIdCommand(viewPart, (String) + * request.getExtendedData().get(OutlineConstants.NEW_NAME)); } else + */if (object instanceof Part) { + Part part = (Part) object; + return PartUtil.createSetPropertyCommand(part, BuilderConstants.PROPERTY_ID, (String) request.getExtendedData().get(OutlineConstants.NEW_NAME)); + } + return null; + + } + + @Override + public Command getCommand(Request req) { + if (OutlineConstants.REQ_RENAME.equals(req.getType())) { + return getRenameCommand(req); + } else if (REQ_MOVE.equals(req.getType())) { + if (req instanceof ChangeBoundsRequest) { + return getMoveCommand((ChangeBoundsRequest) req); + } + } + return super.getCommand(req); + } + + @Override + public boolean understandsRequest(Request req) { + return true; + } + + private Command getMoveCommand(ChangeBoundsRequest request) { + EditPart srcEditPart = (EditPart) request.getEditParts().get(0); + if (srcEditPart == null) { + return null; + } + + EditPart targetEditPart = (EditPart) request.getExtendedData().get("target"); + if (targetEditPart == null) { + return null; + } + + Part sourcePart = null, parentPart = null, siblingPart = null; + + sourcePart = (Part) srcEditPart.getModel(); + if (!(sourcePart instanceof ComponentPart)) { + return null; + } + + parentPart = (Part) targetEditPart.getModel(); + if (!(parentPart instanceof ComponentPart)) { + return null; + } + ComponentDescriptor componentDescriptor = sourcePart.getOwnerDocumentPart().getComponentDescriptor(); + if (!componentDescriptor.canHaveChild((ComponentPart) parentPart, (ComponentPart) sourcePart)) { + parentPart = (Part) targetEditPart.getParent().getModel(); + siblingPart = (Part) targetEditPart.getModel(); + } + + return PartUtil.createMovePartCommand(sourcePart, sourcePart.getParent(), parentPart, siblingPart); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlinePage.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlinePage.java new file mode 100644 index 0000000..9462962 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlinePage.java @@ -0,0 +1,180 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.outline; + +import org.eclipse.gef.EditDomain; +import org.eclipse.gef.KeyHandler; +import org.eclipse.gef.KeyStroke; +import org.eclipse.gef.ui.actions.ActionRegistry; +import org.eclipse.gef.ui.parts.ContentOutlinePage; +import org.eclipse.gef.ui.parts.SelectionSynchronizer; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.actions.ActionFactory; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.actions.ActionConstants; + + +public final class OutlinePage extends ContentOutlinePage { + private ActionRegistry registry = null; + private EditDomain editDomain = null; + + private Composite composite = null; + private Composite viewerComposite = null; + private Part documentPart; + private SelectionSynchronizer selectionSynchronizer = null; + + // public OutlinePage(Part documentPart, EditDomain editDomain, ActionRegistry registry, + // SelectionSynchronizer selectionSynchronizer, + // ISBTabManager sbTabManager) { + public OutlinePage(Part documentPart, EditDomain editDomain, ActionRegistry registry, SelectionSynchronizer selectionSynchronizer) { + super(new OutlineTreeViewer()); + // this.sbTabManager = sbTabManager; + + this.documentPart = documentPart; + this.editDomain = editDomain; + this.registry = registry; + this.selectionSynchronizer = selectionSynchronizer; + } + + @Override + public Control getControl() { + return composite; + } + + @Override + public void createControl(Composite parent) { + // super.createControl(parent); + createActions(); + configureToolBar(); + composite = new SashForm(parent, SWT.VERTICAL); + viewerComposite = new Composite(composite, SWT.NONE); + viewerComposite.setLayout(new FormLayout()); + getViewer().setEditDomain(editDomain); + getViewer().createControl(viewerComposite); + getViewer().setEditPartFactory(new OutlineEditPartFactory(getSite().getActionBars(), registry)); + KeyHandler keyHandler = new KeyHandler(); + keyHandler.put(KeyStroke.getPressed(SWT.F2, 0), registry.getAction(OutlineConstants.RENAME_ACTION)); + getViewer().setKeyHandler(keyHandler); + getViewer().setContextMenu(new OutlineContextMenu(getViewer(), registry /* , eventMenu */)); + + FormData layoutData = new FormData(); + layoutData.top = new FormAttachment(0); + layoutData.bottom = new FormAttachment(100); + layoutData.left = new FormAttachment(0); + layoutData.right = new FormAttachment(100); + getViewer().getControl().setLayoutData(layoutData); + composite.layout(); + parent.layout(); + addListeners(); + + Part viewsPart = PartUtil.findViewsPart(documentPart); + getViewer().setContents(viewsPart); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.part.Page#dispose() + */ + @Override + public void dispose() { + removeListeners(); + super.dispose(); + } + + private void createActions() { + // set actions to actionbars. + IActionBars actionBars = getSite().getActionBars(); + + String id = ActionFactory.UNDO.getId(); + actionBars.setGlobalActionHandler(id, registry.getAction(id)); + + id = ActionFactory.REDO.getId(); + actionBars.setGlobalActionHandler(id, registry.getAction(id)); + + id = ActionConstants.DELETE_PART; + actionBars.setGlobalActionHandler(id, registry.getAction(id)); + + id = ActionConstants.COPY_PART; + actionBars.setGlobalActionHandler(id, registry.getAction(id)); + + id = ActionConstants.CUT_PART; + actionBars.setGlobalActionHandler(id, registry.getAction(id)); + + id = ActionConstants.PASTE_PART; + actionBars.setGlobalActionHandler(id, registry.getAction(id)); + + // == advux ==// + // New View + + id = ActionConstants.ADD_VIEW_EMPTY; + actionBars.setGlobalActionHandler(id, registry.getAction(id)); + + id = OutlineConstants.ADD_VIEW_TEMPLATE; + actionBars.setGlobalActionHandler(id, registry.getAction(id)); + + id = OutlineConstants.ADD_VIEW_POPUP; + actionBars.setGlobalActionHandler(id, registry.getAction(id)); + + id = OutlineConstants.ADD_VIEW_CTXPOPUP; + actionBars.setGlobalActionHandler(id, registry.getAction(id)); + + id = OutlineConstants.CREATE_TEMPLATE_VIEW; + actionBars.setGlobalActionHandler(id, registry.getAction(id)); + + id = ActionConstants.SET_STARTUP_VIEW; + actionBars.setGlobalActionHandler(id, registry.getAction(id)); + + actionBars.updateActionBars(); + } + + private void configureToolBar() { + // set actions to toollbar. + IActionBars actionBars = getSite().getActionBars(); + IToolBarManager toolBarManager = actionBars.getToolBarManager(); + toolBarManager.add(new Separator(OutlineConstants.ADD_VIEW_GROUP)); + + IAction action = actionBars.getGlobalActionHandler(ActionConstants.ADD_VIEW_EMPTY); + toolBarManager.appendToGroup(OutlineConstants.ADD_VIEW_GROUP, action); + } + + private void addListeners() { + selectionSynchronizer.addViewer(getViewer()); + } + + private void removeListeners() { + selectionSynchronizer.removeViewer(getViewer()); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineTreeTransfer.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineTreeTransfer.java new file mode 100644 index 0000000..4cf043c --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineTreeTransfer.java @@ -0,0 +1,83 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.outline; + +import org.eclipse.gef.EditPartViewer; +import org.eclipse.gef.dnd.SimpleObjectTransfer; + + +/** + * A tree transfer class for drag and drop. + */ +final class OutlineTreeTransfer extends SimpleObjectTransfer { + + private static final OutlineTreeTransfer INSTANCE = new OutlineTreeTransfer(); + private static final String TYPE_NAME = "Local Transfer"//$NON-NLS-1$ + + System.currentTimeMillis() + ":" + INSTANCE.hashCode();//$NON-NLS-1$ + private static final int TYPEID = registerType(TYPE_NAME); + + private EditPartViewer viewer; + + /** + * Gets a {@link OutlineTreeTransfer}. + * + * @return a {@link OutlineTreeTransfer} + */ + public static OutlineTreeTransfer getInstance() { + return INSTANCE; + } + + private OutlineTreeTransfer() { + } + + @Override + protected int[] getTypeIds() { + return new int[] { TYPEID }; + } + + @Override + protected String[] getTypeNames() { + return new String[] { TYPE_NAME }; + } + + /** + * Gets a {@link EditPartViewer}. + * + * @return a {@link EditPartViewer} + */ + public EditPartViewer getViewer() { + return viewer; + } + + /** + * Sets a {@link EditPartViewer}. + * + * @param epv + * a {@link EditPartViewer} + */ + public void setViewer(EditPartViewer viewer) { + this.viewer = viewer; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineTreeTransferDragListener.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineTreeTransferDragListener.java new file mode 100644 index 0000000..1760cd5 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineTreeTransferDragListener.java @@ -0,0 +1,103 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.outline; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPartViewer; +import org.eclipse.gef.dnd.AbstractTransferDragSourceListener; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.dnd.DragSourceEvent; +import org.tizen.efluibuilder.model.part.Part; + + +/** + * A tree transfer class for drag and drop. + * + * @see AbstractTransferDragSourceListener + */ +class OutlineTreeTransferDragListener extends AbstractTransferDragSourceListener { + + private List modelSelection; + + /** + * Constructor. + * + * @param viewer + * a {@link EditPartViewer} + * @see AbstractTransferDragSourceListener + */ + public OutlineTreeTransferDragListener(EditPartViewer viewer) { + super(viewer, OutlineTreeTransfer.getInstance()); + } + + @Override + public void dragSetData(DragSourceEvent event) { + event.data = getViewer().getSelectedEditParts(); + } + + @Override + @SuppressWarnings("unchecked") + public void dragStart(DragSourceEvent event) { + OutlineTreeTransfer.getInstance().setViewer(getViewer()); + List selection = getViewer().getSelectedEditParts(); + OutlineTreeTransfer.getInstance().setObject(selection); + saveModelSelection(selection); + } + + @Override + public void dragFinished(DragSourceEvent event) { + OutlineTreeTransfer.getInstance().setObject(null); + OutlineTreeTransfer.getInstance().setViewer(null); + if (event.doit) { + revertModelSelection(); + } else { + modelSelection = null; + } + } + + protected void revertModelSelection() { + List list = new ArrayList(); + Object editpart; + for (int i = 0; i < modelSelection.size(); i++) { + editpart = getViewer().getEditPartRegistry().get(modelSelection.get(i)); + if (editpart != null) { + list.add((EditPart) editpart); + } + } + getViewer().setSelection(new StructuredSelection(list)); + modelSelection = null; + } + + protected void saveModelSelection(List editPartSelection) { + modelSelection = new ArrayList(); + for (int i = 0; i < editPartSelection.size(); i++) { + // EditPart editpart = (EditPart) editPartSelection.get(i); + // modelSelection.add((Part) editpart.getModel()); + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineTreeTransferDropListener.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineTreeTransferDropListener.java new file mode 100644 index 0000000..d638de8 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineTreeTransferDropListener.java @@ -0,0 +1,327 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.outline; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPartViewer; +import org.eclipse.gef.Request; +import org.eclipse.gef.RequestConstants; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.dnd.AbstractTransferDropTargetListener; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DropTargetEvent; +import org.tizen.efluibuilder.model.command.ChangeOrderPartCommand; +import org.tizen.efluibuilder.model.part.Part; + + +/** + * A tree transfer class for drag and drop. + * + * @see AbstractTransferDropTargetListener + */ +class OutlineTreeTransferDropListener extends AbstractTransferDropTargetListener { + + /** + * Constructor. + * + * @param viewer + * a {@link EditPartViewer} + * @see AbstractTransferDropTargetListener + */ + public OutlineTreeTransferDropListener(EditPartViewer viewer) { + super(viewer, OutlineTreeTransfer.getInstance()); + setEnablementDeterminedByCommand(true); + } + + @Override + @SuppressWarnings({ "unchecked", "rawtypes" }) + protected Request createTargetRequest() { + if (OutlineTreeTransfer.getInstance().isSupportedType(getCurrentEvent().currentDataType)) { + ChangeBoundsRequest request = new ChangeBoundsRequest(RequestConstants.REQ_MOVE); + request.setEditParts((List) OutlineTreeTransfer.getInstance().getObject()); + request.getExtendedData().put("source", getCurrentEvent().data); + return request; + } else { + return null; + } + } + + private Command getMoveCommand(EditPart srcEditPart, EditPart targetEditPart) { + if (srcEditPart != null && targetEditPart != null && + srcEditPart.getModel() instanceof Part && targetEditPart.getModel() instanceof Part) { + Part srcPart = (Part) srcEditPart.getModel(); + Part targetPart = (Part) targetEditPart.getModel(); + if (srcEditPart.getParent() == targetEditPart && srcPart.getNextSibling() != null) { + return new ChangeOrderPartCommand(srcPart, null); + } else if (srcEditPart.getParent() == targetEditPart.getParent() && srcPart.getNextSibling() != targetPart) { + return new ChangeOrderPartCommand(srcPart, targetPart); + } + } + return null; + } + + @Override + @SuppressWarnings({ "rawtypes", "unchecked" }) + protected Command getCommand() { + if (OutlineTreeTransfer.getInstance().isSupportedType(getCurrentEvent().currentDataType)) { + Request request = getTargetRequest(); + if (request instanceof ChangeBoundsRequest && getTargetEditPart() != null) { + ChangeBoundsRequest req = (ChangeBoundsRequest) request; + List editparts = req.getEditParts(); + if (editparts.size() == 1) { + EditPart sourceEditPart = (EditPart) editparts.get(0); + EditPart targetEditPart = getTargetEditPart(); + return getMoveCommand(sourceEditPart, targetEditPart); + } + } + } + return null; + + } + + protected String getCommandName() { + if (OutlineTreeTransfer.getInstance().isSupportedType(getCurrentEvent().currentDataType)) { + if (isMove()) { + return RequestConstants.REQ_MOVE; + } + return RequestConstants.REQ_ADD; + } else { + return null; + } + } + + @Override + @SuppressWarnings({ "rawtypes", "unchecked" }) + protected Collection getExclusionSet() { + if (OutlineTreeTransfer.getInstance().isSupportedType(getCurrentEvent().currentDataType)) { + List selection = getViewer().getSelectedEditParts(); + List exclude = new ArrayList(selection); + exclude.addAll(includeChildren(selection)); + return exclude; + } else { + return null; + } + } + + @Override + @SuppressWarnings("unchecked") + protected void handleDragOver() { + if (getCommand() != null) { + getCurrentEvent().detail = DND.DROP_MOVE; + getCurrentEvent().feedback = DND.FEEDBACK_SELECT; + } else { + getCurrentEvent().detail = DND.DROP_NONE; + getCurrentEvent().feedback = DND.FEEDBACK_NONE; + } + // + // if (OutlineTreeTransfer.getInstance().isSupportedType(getCurrentEvent().currentDataType)) + // { + // if (OutlineTreeTransfer.getInstance().getViewer() != getViewer()) { + // getCurrentEvent().detail = DND.DROP_NONE; + // return; + // } + // + // Part target = null; + // Part part = null; + // TreeItem treeItem = null; + // TreeEditPart treeEditPart = null; + // Rectangle rect = null; + // Point point = null; + // ChangeBoundsRequest request = (ChangeBoundsRequest) getTargetRequest(); + // + // List list = + // OutlineTreeTransfer.getInstance().getViewer().getSelectedEditParts(); + // if (list == null || list.size() == 0) { + // return; + // } + // + // Part source = (Part) (list.get(0)).getModel(); + // if (getTargetEditPart() == null) { + // return; + // } + // point = request.getLocation(); + // treeEditPart = (TreeEditPart) getTargetEditPart().getViewer().findObjectAt(point); + // target = (Part) treeEditPart.getModel(); + // part = (Part) getTargetEditPart().getModel(); + // if (getCommand() == null) { + // getCurrentEvent().detail = DND.DROP_NONE; + // getCurrentEvent().feedback = DND.FEEDBACK_NONE; + // } else { + // getCurrentEvent().detail = DND.DROP_MOVE; + // getCurrentEvent().feedback = DND.FEEDBACK_INSERT_BEFORE; + // } + // + // getCurrentEvent().detail = DND.DROP_MOVE; + // if (target != null) { + // ComponentDescriptor componentDescriptor = + // part.getOwnerDocumentPart().getComponentDescriptor(); + // if (componentDescriptor.canHaveChild((ComponentPart) target, (ComponentPart) source)) { + // getCurrentEvent().feedback = DND.FEEDBACK_SCROLL | DND.FEEDBACK_EXPAND | + // DND.FEEDBACK_SELECT; + // + // } else if ((target.equals(part)) + // || (target.getParent() != null && ((!componentDescriptor.canHaveChild((ComponentPart) + // target.getParent(), (ComponentPart) source)) + // || (target.getParent().equals(((ComponentPart) target).getOwnerViewPart())) + // || (target.equals(((ComponentPart) target).getOwnerViewPart()))))) { + // getCurrentEvent().detail = DND.DROP_NONE; + // getCurrentEvent().feedback = DND.FEEDBACK_NONE; + // } else if (treeEditPart.getWidget() instanceof TreeItem) { + // treeItem = (TreeItem) treeEditPart.getWidget(); + // rect = treeItem.getBounds(); + // if (isNextPosion(rect, point)) { + // getCurrentEvent().feedback = DND.FEEDBACK_SCROLL | DND.FEEDBACK_EXPAND | + // DND.FEEDBACK_INSERT_AFTER; + // } else { + // getCurrentEvent().feedback = DND.FEEDBACK_SCROLL | DND.FEEDBACK_EXPAND | + // DND.FEEDBACK_INSERT_BEFORE; + // } + // } else { + // getCurrentEvent().feedback = DND.FEEDBACK_SCROLL | DND.FEEDBACK_EXPAND | + // DND.FEEDBACK_INSERT_BEFORE; + // } + // } else { + // getCurrentEvent().detail = DND.DROP_NONE; + // getCurrentEvent().feedback = DND.FEEDBACK_NONE; + // } + // super.handleDragOver(); + // } + super.handleDragOver(); + } + + // private boolean isNextPosion(Rectangle rect, Point point) { + // Rectangle temp = rect; + // temp.y = rect.y + (rect.height / 2); + // temp.height = rect.height / 2; + // + // if (temp.contains(point.x, point.y)) { + // return true; + // } else { + // return false; + // } + // } + + @SuppressWarnings("rawtypes") + protected EditPart getSourceEditPart() { + if (OutlineTreeTransfer.getInstance().isSupportedType(getCurrentEvent().currentDataType)) { + List selection = (List) OutlineTreeTransfer.getInstance().getObject(); + if (selection == null || selection.isEmpty() || !(selection.get(0) instanceof EditPart)) { + return null; + } + return (EditPart) selection.get(0); + } else { + return null; + } + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + protected List includeChildren(List list) { + List result = new ArrayList(); + for (int i = 0; i < list.size(); i++) { + List children = ((EditPart) list.get(i)).getChildren(); + result.addAll(children); + result.addAll(includeChildren(children)); + } + return result; + } + + @Override + public boolean isEnabled(DropTargetEvent event) { + if (OutlineTreeTransfer.getInstance().isSupportedType(getCurrentEvent().currentDataType)) { + if (event.detail != DND.DROP_MOVE) { + return false; + } + return super.isEnabled(event); + } else { + return false; + } + } + + @SuppressWarnings("rawtypes") + protected boolean isMove() { + if (OutlineTreeTransfer.getInstance().isSupportedType(getCurrentEvent().currentDataType)) { + EditPart source = getSourceEditPart(); + if (source == null) { + return false; + } + // for moving to child of other parent + // Part sourcePart = (Part) source.getModel(); + // Part targetPart = null; + // if(getTargetEditPart() != null) { + // targetPart = (Part) getTargetEditPart().getModel(); + // } + // + List selection = (List) OutlineTreeTransfer.getInstance().getObject(); + for (int i = 0; i < selection.size(); i++) { + EditPart ep = (EditPart) selection.get(i); + if (ep.getParent() != source.getParent()) { + return false; + } + + } + return source.getParent() == getTargetEditPart(); + + // for moving to child of other parent + // return sourcePart.getParent().getPartDescriptor().equals((targetPart != null) ? + // targetPart + // .getPartDescriptor() : null); + } else { + return false; + } + } + + @Override + protected void updateTargetRequest() { + if (OutlineTreeTransfer.getInstance().isSupportedType(getCurrentEvent().currentDataType)) { + ChangeBoundsRequest request = (ChangeBoundsRequest) getTargetRequest(); + request.setLocation(getDropLocation()); + request.setType(getCommandName()); + } + } + + @Override + protected void handleDrop() { + if (OutlineTreeTransfer.getInstance().isSupportedType(getCurrentEvent().currentDataType)) { + // Object obj = getCurrentEvent().data; + // if (obj != null) { + // List list = (List) obj; + // Part source = (Part) (list.get(0)).getModel(); + // if (source != null) { + // EditPart ep = + // (EditPart) getViewer().getEditPartRegistry().get(source.getPartId()); + // if (ep != null) { + // getViewer().select(ep); + // } + // } + // } + super.handleDrop(); + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineTreeViewer.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineTreeViewer.java new file mode 100644 index 0000000..5ecba42 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineTreeViewer.java @@ -0,0 +1,232 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.outline; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.dnd.TemplateTransfer; +import org.eclipse.gef.ui.parts.TreeViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.TreeEditor; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DragSource; +import org.eclipse.swt.dnd.DropTarget; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.IPartChangedListener; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartMutation; +import org.tizen.efluibuilder.model.part.PartObserver; +import org.tizen.efluibuilder.model.part.ViewPart; +import org.tizen.efluibuilder.model.part.ViewsPart; +import org.tizen.efluibuilder.ui.editor.dnd.listener.OutlineDropTargetListener; +import org.tizen.efluibuilder.ui.resources.ColorResources; + + +/** + * A tree viewer class for outline page. + */ +public final class OutlineTreeViewer extends TreeViewer implements IPartChangedListener { + private TreeEditor editor = null; + private DragSource dragSource = null; + private DropTarget dropTarget = null; + private OutlineTreeTransferDragListener outlineTreeTransferDragListener = null; + private OutlineTreeTransferDropListener outlineTreeTransferDropListener = null; + private OutlineDropTargetListener outlineDropTargetListener = null; + private PartObserver observer = null; + + @Override + public Control createControl(Composite parent) { + super.createControl(parent); + editor = new TreeEditor((Tree) getControl()); + editor.horizontalAlignment = SWT.LEFT; + editor.grabHorizontal = true; + + setDragSource(null); + setDropTarget(null); + + addDragSourceListener(); + addDropTargetListener(); + getControl().setBackground(ColorResources.OUTLINE_BACKGROUND); // for advux + return getControl(); + } + + /** + * Gets tree editor in outline page. + * + * @return a {@link TreeEditor} + */ + public TreeEditor getTreeEditor() { + return editor; + } + + public void refreshSelection() { + super.fireSelectionChanged(); + } + + private void addDragSourceListener() { + dragSource = new DragSource(this.getControl(), DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK | DND.DROP_DEFAULT); + Transfer[] types = { OutlineTreeTransfer.getInstance() }; + dragSource.setTransfer(types); + outlineTreeTransferDragListener = new OutlineTreeTransferDragListener(this); + dragSource.addDragListener(outlineTreeTransferDragListener); + } + + private void addDropTargetListener() { + dropTarget = new DropTarget(this.getControl(), DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK | DND.DROP_DEFAULT); + Transfer[] types = { TemplateTransfer.getInstance(), OutlineTreeTransfer.getInstance() }; + dropTarget.setTransfer(types); + outlineTreeTransferDropListener = new OutlineTreeTransferDropListener(this); + dropTarget.addDropListener(outlineTreeTransferDropListener); + outlineDropTargetListener = new OutlineDropTargetListener(this); + dropTarget.addDropListener(outlineDropTargetListener); + } + + @Override + public void setContents(Object contents) { + + if (contents instanceof ViewsPart) { + super.setContents(contents); + this.observer = new PartObserver(this); + Part viewsPart = (ViewsPart) contents; + observer.observe(viewsPart.getParent()); + + expandAll(); + + if (viewsPart.getOwnerDocumentPart().isValidDocument() == false) { + setEnabled(false); + } + } + } + + private void expandAll() { + Tree tree = (Tree) getControl(); + TreeItem[] items = tree.getItems(); + for (TreeItem item : items) { + expandChild(item); + } + } + + private void expandChild(TreeItem item) { + item.setExpanded(true); + TreeItem[] items = item.getItems(); + for (TreeItem child : items) { + expandChild(child); + } + } + + @Override + public void partsChanged(List mutations, PartObserver observer, String sender) { + if (sender.equals(PartObserver.MESSAGE_VALID_XML)) { + setEnabled(true); + } else if (sender.equals(PartObserver.MESSAGE_INVALID_XML)) { + setEnabled(false); + return; + } + HashMap partMapToRefresh = new HashMap(); + boolean isViewChanged = false; + Map partMapToSelect = new HashMap(); + int addedMutationSize = 0; + int removedMutationSize = 0; + Part addedPartToSelect = null; + + for (PartMutation mutation : mutations) { + String mutationType = mutation.getType(); + if (mutationType.equals(PartMutation.PARTS_ADDED)) { + addedMutationSize++; + for (Part part : mutation.getAddedParts()) { + addedPartToSelect = part; + if (part instanceof ViewPart) { + isViewChanged = true; + } else if (part instanceof ComponentPart) { + partMapToSelect.put(part, ""); + } + } + } else if (mutationType.equals(PartMutation.PARTS_REMOVED)) { + removedMutationSize++; + for (Part part : mutation.getRemovedParts()) { + if (part instanceof ViewPart) { + isViewChanged = true; + } + } + } + + if (mutationType.equals(PartMutation.PARTS_ADDED) || mutationType.equals(PartMutation.PARTS_REMOVED) + || mutationType.equals(PartMutation.PARTS_ORDER_CHANGED) || mutationType.equals(PartMutation.PROPERTY_CHANGED)) { + if (mutation.getTargetPart() instanceof ComponentPart) { + // FIXED: When parts with parent relation are removed, + // cannot get DocumentPart from it. + partMapToRefresh.put(mutation.getTargetPart(), ""); + } else if (mutation.getTargetPart() instanceof ViewsPart) { + isViewChanged = true; + } + } + + } + + if (isViewChanged) { + getContents().refresh(); + // Part viewsPart = (Part) getContents().getModel(); + // String strStrupView = viewsPart.getPropertyValue(LayoutSchemaConstants.STARTUP); + for (Object model : getContents().getChildren()) { + Part childPart = (Part) (((EditPart) model).getModel()); + if (childPart.getParent() != null) { + ((EditPart) model).refresh(); + } + // if (strStrupView != null && + // strStrupView.equals(childPart.getPropertyValue(LayoutSchemaConstants.ID))) { + // ((EditPart) model).refresh(); + // break; + // } + } + } + + for (Part child : partMapToRefresh.keySet()) { + OutlineViewEditPart editPart = (OutlineViewEditPart) getEditPartRegistry().get(child.getUniqueId()); + if (editPart != null && ((Part) (editPart.getModel())).getParent() != null) { + editPart.refresh(); + } + } + + if (addedMutationSize == 1 && removedMutationSize == 0 && addedPartToSelect != null) { + EditPart editPart = (EditPart) getEditPartRegistry().get(addedPartToSelect.getUniqueId()); + if (editPart != null) { + this.select(editPart); + } + } + + } + + public void setEnabled(boolean enabled) { + getControl().setEnabled(enabled); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineViewEditPart.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineViewEditPart.java new file mode 100644 index 0000000..fe79248 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/OutlineViewEditPart.java @@ -0,0 +1,355 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.outline; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang3.StringEscapeUtils; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.gef.editparts.AbstractTreeEditPart; +import org.eclipse.gef.ui.actions.ActionRegistry; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.TreeEditor; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.ToolTip; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.actions.ActionFactory; +import org.tizen.common.util.Assert; +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.part.ViewsPart; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.ComponentValidator; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.ModelConstants; +import org.tizen.efluibuilder.ui.resources.ImageResources; + + +/** + * A tree editpart class for outline page. + * + * @see AbstractTreeEditPart + */ +public class OutlineViewEditPart extends AbstractTreeEditPart { + private Request request; + private ToolTip tooltip; + private IActionBars actionBars; + private ActionRegistry registry; + + public OutlineViewEditPart(IActionBars actionBars, ActionRegistry registry) { + this.actionBars = actionBars; + this.registry = registry; + } + + private boolean isValidPart(Part part) { + if (part != null && part instanceof ComponentPart && part.getOwnerDocumentPart() != null + && part.getOwnerDocumentPart().getComponentDescriptor().getWidgetDescriptor(part.getDescriptorId()) != null) { + return true; + } + return false; + } + + @Override + protected List getModelChildren() { + List children = new ArrayList(); + for (Part part : ((Part) getModel()).getChildren()) { + if (isValidPart(part) == true) { + children.add(part); + } + } + return children; + } + + @Override + public void activate() { + super.activate(); + } + + @Override + public void deactivate() { + super.deactivate(); + } + + @Override + protected void createEditPolicies() { + installEditPolicy(EditPolicy.TREE_CONTAINER_ROLE, new OutlineEditPolicy()); + } + + public String getId() { + Part part = ((Part) getModel()); + return part.getUniqueId(); + } + + @SuppressWarnings("unchecked") + @Override + protected void registerModel() { + getViewer().getEditPartRegistry().put(getId(), this); + } + + @Override + protected void refreshVisuals() { + refreshWidgetText(); + refreshWidgetImage(); + } + + private void refreshWidgetText() { + Part model = (Part) getModel(); + if (!((model.getType() == PartType.COMPONENT) || (model.getType() == PartType.VIEW))) + return; + + String text = model.getPropertyValue(ModelConstants.PROPERTY_ID); + if (model.getOwnerDocumentPart() == null) { //prevent dangling + return; + } + ComponentDescriptor componentDescriptor = model.getOwnerDocumentPart().getComponentDescriptor(); + if (model.getParent() instanceof ViewsPart + && model.getParent().getPropertyValue(LayoutSchemaConstants.STARTUP).equals(model.getPropertyValue(LayoutSchemaConstants.ID))) { + String unicodeCh = "\u27AA "; + // String unicodeCh = "\u27A2 "; + // String unicodeCh = "\u279C "; + // String unicodeCh = "\u00BB "; + StringEscapeUtils.unescapeJava(unicodeCh); + // text += " <" + componentDescriptor.getDisplayName((ComponentPart) model) + "> - " + + // LayoutSchemaConstants.STARTUP; + // text = unicodeCh + text + " <" + componentDescriptor.getDisplayName((ComponentPart) + // model) + ">"; + text += " <" + componentDescriptor.getDisplayName((ComponentPart) model) + "> " + unicodeCh; + } else if ((model.getType() == PartType.VIEW) && model.getPropertyValue(LayoutSchemaConstants.TYPE).equals(LayoutSchemaConstants.POPUP)) { + text += " <" + componentDescriptor.getDisplayName((ComponentPart) model) + "> - " + LayoutSchemaConstants.POPUP; + } else { + text += " <" + componentDescriptor.getDisplayName((ComponentPart) model) + ">"; + } + + setWidgetText(text); + + } + + private void refreshWidgetImage() { + Part model = (Part) getModel(); + if (!((model.getType() == PartType.COMPONENT) || (model.getType() == PartType.VIEW)) || model.getOwnerDocumentPart() == null) + return; + + ComponentDescriptor componentDescriptor = model.getOwnerDocumentPart().getComponentDescriptor(); + String icon = componentDescriptor.getIcon16((ComponentPart) model); + Assert.notNull(icon, model.getDescriptorId()); + Image image = ImageResources.getImage(BuilderConstants.ICON_DIR + icon); + Assert.notNull(image); + setWidgetImage(image); + } + + @Override + public void performRequest(Request request) { + if (request.getType() == OutlineConstants.REQ_RENAME) { + this.request = request; + renameTreeItem(); + } + } + + private void renameTreeItem() { + final Part model = (Part) getModel(); + final Tree tree = (Tree) getViewer().getControl(); + TreeItem item = (TreeItem) this.getWidget(); + TreeEditor treeEditor = ((OutlineTreeViewer) getViewer()).getTreeEditor(); + + Control oldEditor = treeEditor.getEditor(); + if (oldEditor != null) { + oldEditor.dispose(); + } + + final Text newEditor = new Text(tree, SWT.NONE); + String text[] = item.getText().split(" "); + newEditor.setText(text[0]); + newEditor.selectAll(); + newEditor.setFocus(); + actionBars.clearGlobalActionHandlers(); + actionBars.updateActionBars(); + + newEditor.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent event) { + switch (event.keyCode) { + case SWT.CR: + case SWT.KEYPAD_CR: + String message = canCommitID(model, newEditor.getText()); + if (message.equals(ComponentValidator.OK)) { + commitID(newEditor.getText()); + newEditor.dispose(); + hideTooltipText(); + } else { + newEditor.setText(model.getPropertyValue(ModelConstants.PROPERTY_ID)); + newEditor.selectAll(); + showTooltipText(newEditor, message); + } + setGlobalActions(); + actionBars.updateActionBars(); + break; + case SWT.ESC: + newEditor.dispose(); + tree.setFocus(); + setGlobalActions(); + actionBars.updateActionBars(); + break; + default: + // do nothing + break; + } + } + }); + + newEditor.addFocusListener(new FocusListener() { + + @Override + public void focusLost(FocusEvent e) { + String message = canCommitID(model, newEditor.getText()); + if (message.equals(ComponentValidator.OK)) { + commitID(newEditor.getText()); + hideTooltipText(); + } else { + newEditor.setText(model.getPropertyValue(ModelConstants.PROPERTY_ID)); + showTooltipText(newEditor, message); + } + + setGlobalActions(); + actionBars.updateActionBars(); + newEditor.dispose(); + } + + @Override + public void focusGained(FocusEvent e) { + } + }); + + treeEditor.setEditor(newEditor, item); + } + + private void setGlobalActions() { + String id = ActionFactory.UNDO.getId(); + actionBars.setGlobalActionHandler(id, registry.getAction(id)); + + id = ActionFactory.REDO.getId(); + actionBars.setGlobalActionHandler(id, registry.getAction(id)); + + id = ActionFactory.DELETE.getId(); + actionBars.setGlobalActionHandler(id, registry.getAction(id)); + + id = ActionFactory.COPY.getId(); + actionBars.setGlobalActionHandler(id, registry.getAction(id)); + + id = ActionFactory.CUT.getId(); + actionBars.setGlobalActionHandler(id, registry.getAction(id)); + + id = ActionFactory.PASTE.getId(); + actionBars.setGlobalActionHandler(id, registry.getAction(id)); + + actionBars.updateActionBars(); + } + + private void showTooltipText(Text newEditor, String text) { + tooltip = new ToolTip(newEditor.getShell(), SWT.BALLOON); + tooltip.setMessage(text); + + Point location = newEditor.toDisplay(newEditor.getSize().x, newEditor.getSize().y); + + tooltip.setLocation(location.x - newEditor.getSize().x + newEditor.getBorderWidth(), location.y - newEditor.getBorderWidth()); + tooltip.setVisible(true); + + newEditor.addFocusListener(new FocusListener() { + + @Override + public void focusLost(FocusEvent e) { + hideTooltipText(); + } + + @Override + public void focusGained(FocusEvent e) { + // Do nothing + } + }); + } + + private void hideTooltipText() { + if (tooltip != null) { + tooltip.setVisible(false); + } + } + + private String canCommitID(Part model, String newValue) { + return new ComponentValidator().canSetPropertyValue(model, ModelConstants.PROPERTY_ID, newValue); + } + + public void refreshChildren2() { + List children = this.getChildren(); + List modelChildren = this.getModelChildren(); + List removedList = new ArrayList(); + boolean isExist = false; + for (int i = 0; i < children.size(); i++) { + isExist = false; + for (int j = 0; j < modelChildren.size(); j++) { + if (children.get(i).getModel() == modelChildren.get(j)) { + isExist = true; + break; + } + if (isExist == false) { + removedList.add(children.get(i)); + } + } + } + for (EditPart editpart : removedList) { + if (editpart.getParent() != null && (editpart.getParent() instanceof OutlineViewEditPart)) { + ((OutlineViewEditPart) editpart.getParent()).removeChild(editpart); + // this.removeChild(editpart); + } + } + super.refreshChildren(); + } + + @SuppressWarnings("unchecked") + private void commitID(String newName) { + request.getExtendedData().put(OutlineConstants.NEW_NAME, newName); + + CommandStack stack = getViewer().getEditDomain().getCommandStack(); + stack.execute(getCommand(request)); + } + + @Override + public void refresh() { + refreshChildren(); + refreshVisuals(); + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/actions/OutlineAbstractAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/actions/OutlineAbstractAction.java new file mode 100644 index 0000000..bedbbea --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/actions/OutlineAbstractAction.java @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.ui.views.outline.actions; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.ui.actions.SelectionAction; +import org.eclipse.ui.IWorkbenchPart; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.gef.policies.containers.DesignEditorUtil; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.app.AppManager; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.DocumentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.part.ViewPart; +import org.tizen.efluibuilder.model.part.ViewsPart; +import org.tizen.efluibuilder.model.snippet.ISnippet; +import org.tizen.efluibuilder.model.snippet.ISnippetManager; +import org.tizen.efluibuilder.model.snippet.SnippetManager; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUnmarshaller; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.editor.designeditor.DesignEditor; +import org.tizen.efluibuilder.ui.views.outline.OutlineViewEditPart; +import org.w3c.dom.Document; + + +public abstract class OutlineAbstractAction extends SelectionAction { + + protected final Logger logger = LoggerFactory.getLogger(getClass()); + + private EditPart rootEditPart = null; + private DesignViewer viewer = null; + + public OutlineAbstractAction(IWorkbenchPart part) { + super(part); + DesignEditor designEditor = (DesignEditor) part; + rootEditPart = designEditor.getViewer().getRootEditPart(); + viewer = designEditor.getViewer(); + } + + protected ViewPart getLastViewPart() { + List selectedViewParts = getSelectedViewParts(); + if (selectedViewParts.isEmpty()) { + if (rootEditPart.getViewer().getContents() != null) { + Object viewsPartObj = this.rootEditPart.getViewer().getContents().getModel(); + if (viewsPartObj instanceof ViewsPart) { + ViewsPart viewsPart = (ViewsPart) viewsPartObj; + int childrenSize = viewsPart.getChildren().size(); + if (childrenSize > 0) { + return (ViewPart) viewsPart.getChildren().get(childrenSize - 1); + } + } + } + return null; + } + + return selectedViewParts.get(0); + } + + protected List getSelectedViewParts() { + List views = new ArrayList(); + List selections = getSelectedObjects(); + for (Object object : selections) { + if (!(object instanceof OutlineViewEditPart)) { + continue; + } + OutlineViewEditPart editPart = (OutlineViewEditPart) object; + Object model = editPart.getModel(); + if (model instanceof ViewPart) { + views.add((ViewPart) model); + } else if (model instanceof ComponentPart) { + ComponentPart componentPart = (ComponentPart) model; + views.add(componentPart.getOwnerViewPart()); + } + } + return views; + } + + // for ctxpopup, popup + protected Command createAddTemplateViewCommand(String key, ViewPart selectedViewPart) { + try { + String newViewName = null; + String platform = null; + ISnippetManager manager = SnippetManager.getDefault(); + Collection templates = manager.getViewTemplates(); + + Document document = null; + + for (ISnippet template : templates) { + if (!template.getCategory().equals(ISnippet.CATEGORY_SYSTEM)) { + continue; + } + if (template.getName().equals(key)) { + document = template.getModel(); + break; + } + } + + if (document != null) { + DocumentPart docPart = (DocumentPart) PartUtil.createPart(PartType.DOCUMENT, null); + platform = AppManager.getAppManager().getPlatform(); + docPart.setPlatform(platform); + + PartUnmarshaller unmarshaller = new PartUnmarshaller(); + Part part = unmarshaller.unmarshall(docPart, document, false); + + // get ViewPart from part + Part viewPart = (part instanceof ViewsPart) ? part.getChildren().get(0) : part; + Part parent = selectedViewPart.getParent(); + Part nextSibiling = selectedViewPart.getNextSibling(); + + Point screenSize = viewer.getMScreenQualifierManager().getScreenSize(); + Point viewPosition = DesignEditorUtil.getNextViewPosition(parent, screenSize.x, screenSize.y); + viewPart.setPropertyValue("id", newViewName); + viewPart.setPropertyValue(LayoutSchemaConstants.PAGE_LOCATION_X, Integer.toString(viewPosition.x)); + viewPart.setPropertyValue(LayoutSchemaConstants.PAGE_LOCATION_Y, Integer.toString(viewPosition.y)); + + return PartUtil.createAddPartCommand(parent, viewPart, nextSibiling); + } + return null; + } catch (RuntimeException e) { + logger.error(e.getMessage(), e); + throw e; + } catch (Exception e) { + logger.error(e.getMessage(), e); + return null; + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/actions/OutlineCreateTemplateAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/actions/OutlineCreateTemplateAction.java new file mode 100644 index 0000000..c8e3f80 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/actions/OutlineCreateTemplateAction.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.ui.views.outline.actions; + +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PlatformUI; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.efluibuilder.ui.views.outline.Messages; +import org.tizen.efluibuilder.ui.views.outline.OutlineConstants; +import org.tizen.efluibuilder.ui.wizard.snippet.NewViewTemplateWizard; + + +public class OutlineCreateTemplateAction extends OutlineAbstractAction { + + public static final String ID = OutlineConstants.CREATE_TEMPLATE_VIEW; + + public OutlineCreateTemplateAction(IWorkbenchPart part) { + super(part); + } + + private boolean isActivePageDesignTab() { + IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); + if (!(editorPart instanceof CombineEditorPart)) { + return false; + } + + CombineEditorPart combineEditorPart = (CombineEditorPart) editorPart; + if ((combineEditorPart.getGraphiclaDataManager() != null) && (combineEditorPart.getActivePage() == CombineEditorPart.DESIGN_TAB)) { + return true; + } else { + return false; + } + } + + @Override + protected boolean calculateEnabled() { + if ((getLastViewPart() == null) || (!isActivePageDesignTab())) { + return false; + } + return true; + } + + @Override + public void run() { + // create wizard + NewViewTemplateWizard wizard = new NewViewTemplateWizard(); + wizard.setModel(getLastViewPart()); // FIXME + + // dialog open + Shell shell = Display.getDefault().getActiveShell(); + WizardDialog dialog = new WizardDialog(shell, wizard); + dialog.setPageSize(600, 300); + dialog.open(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#init() + */ + @Override + protected void init() { + super.init(); + setText(Messages.ACTION_CREATE_TEMPLATE_VIEW_TITLE); + setId(ID); + // ImageDescriptor descriptor = + // AbstractUIPlugin.imageDescriptorFromPlugin(BuilderPlugin.PLUGIN_ID, + // Messages.ACTION_NEW_EMPTY_VIEW_ICON); + // setImageDescriptor(descriptor); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/actions/OutlineNewViewCtxPopupAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/actions/OutlineNewViewCtxPopupAction.java new file mode 100644 index 0000000..291698c --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/actions/OutlineNewViewCtxPopupAction.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.ui.views.outline.actions; + +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.ui.IWorkbenchPart; +import org.tizen.efluibuilder.ui.views.outline.Messages; +import org.tizen.efluibuilder.ui.views.outline.OutlineConstants; + + +public class OutlineNewViewCtxPopupAction extends OutlineAbstractAction { + + public static final String ID = OutlineConstants.ADD_VIEW_CTXPOPUP; + + public OutlineNewViewCtxPopupAction(IWorkbenchPart part) { + super(part); + } + + @Override + protected boolean calculateEnabled() { + if (getLastViewPart() == null) { + return false; + } + return true; + } + + @Override + public void run() { + Command command = createAddTemplateViewCommand(OutlineConstants.KEY_CTXPOPUP_VIEW, getLastViewPart()); + if (command != null) { + CommandStack commandStack = getCommandStack(); + commandStack.execute(command); + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#init() + */ + @Override + protected void init() { + super.init(); + setText(Messages.ACTION_ADD_VIEW_CTXPOPUP_TITLE); + setId(ID); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/actions/OutlineNewViewPopupAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/actions/OutlineNewViewPopupAction.java new file mode 100644 index 0000000..44748bc --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/actions/OutlineNewViewPopupAction.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.ui.views.outline.actions; + +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.ui.IWorkbenchPart; +import org.tizen.efluibuilder.ui.views.outline.Messages; +import org.tizen.efluibuilder.ui.views.outline.OutlineConstants; + + +public class OutlineNewViewPopupAction extends OutlineAbstractAction { + + public static final String ID = OutlineConstants.ADD_VIEW_POPUP; + + public OutlineNewViewPopupAction(IWorkbenchPart part) { + super(part); + } + + @Override + protected boolean calculateEnabled() { + if (getLastViewPart() == null) { + return false; + } + return true; + } + + @Override + public void run() { + Command command = createAddTemplateViewCommand(OutlineConstants.KEY_POPUP_VIEW, getLastViewPart()); + if (command != null) { + CommandStack commandStack = getCommandStack(); + commandStack.execute(command); + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#init() + */ + @Override + protected void init() { + super.init(); + setText(Messages.ACTION_ADD_VIEW_POPUP_TITLE); + setId(ID); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/actions/OutlineNewViewTemplateAction.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/actions/OutlineNewViewTemplateAction.java new file mode 100644 index 0000000..3ceecc5 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/outline/actions/OutlineNewViewTemplateAction.java @@ -0,0 +1,82 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.outline.actions; + +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbenchPart; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.ui.views.outline.Messages; +import org.tizen.efluibuilder.ui.views.outline.OutlineConstants; +import org.tizen.efluibuilder.ui.wizard.snippet.NewViewWizard; + + +public final class OutlineNewViewTemplateAction extends OutlineAbstractAction { + + DesignViewer viewer = null; + public OutlineNewViewTemplateAction(DesignViewer viewer, IWorkbenchPart part) { + super(part); + this.viewer = viewer; + } + + @Override + protected void init() { + super.init(); + setText(Messages.ACTION_ADD_VIEW_TEMPLATE_TITLE); + setId(OutlineConstants.ADD_VIEW_TEMPLATE); + } + + @Override + public boolean calculateEnabled() { + if (getLastViewPart() == null) { + return false; + } + return true; + } + + @Override + public void run() { + // create wizard + NewViewWizard wizard = new NewViewWizard(viewer); + wizard.setModel(getLastViewPart()); + + // dialog open + Shell shell = Display.getDefault().getActiveShell(); + WizardDialog dialog = new WizardDialog(shell, wizard); + dialog.setPageSize(600, 300); + int result = dialog.open(); + if (result == Dialog.OK) { + Command command = wizard.getCommnad(); + if (command != null) { + CommandStack commandStack = getCommandStack(); + commandStack.execute(command); + } + } + } + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/CategoryComposite.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/CategoryComposite.java new file mode 100644 index 0000000..dd1271d --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/CategoryComposite.java @@ -0,0 +1,291 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.forms.events.ExpansionEvent; +import org.eclipse.ui.forms.events.IExpansionListener; +import org.eclipse.ui.forms.widgets.ExpandableComposite; +import org.tizen.efluibuilder.ui.resources.FontResources; +import org.tizen.efluibuilder.ui.views.properties.method.Editable; + + +/** + * A category composite class. This includes the {@link ExpandableComposite}. + */ +public class CategoryComposite extends Composite { + + private ExpandableComposite expandableComposite; + private FoldingComposite foldingComposite; + private Label briefLabel; + private String brief = null; + private List methods = new ArrayList(); + private List foldings = new ArrayList(); + private IExpansionListener foldingListener = new IExpansionListener() { + + @Override + public void expansionStateChanging(ExpansionEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void expansionStateChanged(ExpansionEvent e) { + if (foldingComposite != null && !foldingComposite.isDisposed()) { + GridData data = (GridData) foldingComposite.getLayoutData(); + if (e.getState()) { + data.exclude = false; + foldingComposite.setVisible(true); + } else { + data.exclude = true; + foldingComposite.setVisible(false); + } + layout(); + } + } + }; + + /** + * Constructs a new instance of this class given its parent and category name. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param name + * category name + * @param brief + * brief message + * @param folding + * folding information + */ + public CategoryComposite(Composite parent, String name, String brief, List foldings) { + super(parent, SWT.NONE); + init(); + createExpandableComposite(name); + this.brief = brief; + briefLabel = createBriefLabel(); + setFoldings(foldings); + } + + protected void init() { + setLayout(new FormLayout()); + } + + @Override + public void dispose() { + expandableComposite.removeExpansionListener(foldingListener); + methods.clear(); + + Control client = expandableComposite.getClient(); + if (client != null) { + client.dispose(); + } + + if (briefLabel != null) { + briefLabel.dispose(); + } + + super.dispose(); + } + + /** + * Gets category name. + * + * @return category name + */ + public String getCategoryName() { + return expandableComposite.getText(); + } + + /** + * Gets {@link ExpandableComposite}. + * + * @return {@link ExpandableComposite} + */ + public ExpandableComposite getExpandableComposite() { + return expandableComposite; + } + + protected void createExpandableComposite(String name) { + expandableComposite = new ExpandableComposite(this, SWT.FILL, ExpandableComposite.TITLE_BAR | ExpandableComposite.FOCUS_TITLE + | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED); + expandableComposite.setText(name); + + FormData data = new FormData(); + data.left = new FormAttachment(0, 20); + data.right = new FormAttachment(100, -28); + expandableComposite.setLayoutData(data); + + expandableComposite.addExpansionListener(foldingListener); + } + + protected Label createBriefLabel() { + Label label = new Label(expandableComposite, SWT.NONE); + label.setForeground(getDisplay().getSystemColor(SWT.COLOR_BLUE)); + label.setFont(FontResources.BOLD); + + expandableComposite.setTextClient(label); + return label; + } + + /** + * Sets the client to expandable composite. The client must not be null and must be a direct + * child of this container. + * + * @param client + */ + public void setClient(Control client) { + expandableComposite.setClient(client); + } + + /** + * Gets a client with property name. + * + * @param childPropertyName + * @return + */ + public Composite getClient(String childPropertyName) { + if (childPropertyName != null + && (foldings == null || !foldings.contains(childPropertyName) || foldingComposite == null || foldingComposite.isDisposed())) { + return (Composite) expandableComposite.getClient(); + } + return foldingComposite.getClient(); + } + + /** + * Adds the listener that will be notified when the expansion state changes. + * + * @param listener + * the listener to add + */ + public void addExpansionListener(IExpansionListener listener) { + expandableComposite.addExpansionListener(listener); + } + + public void setBriefMessage(String key, String value) { + if (brief == null || brief.isEmpty()) { + return; + } + String msg = brief.replaceAll("%" + key + "%", value); + + for (Editable method : methods) { + String methodName = method.getMethodName(); + String methodValue = method.getValue(); + if (methodValue == null || methodValue.isEmpty()) { + methodValue = method.getDefaultValue(); + } + + msg = msg.replaceAll("%" + methodName + "%", methodValue); + } + + if (briefLabel != null && !briefLabel.isDisposed()) { + briefLabel.dispose(); + briefLabel = null; + } + + briefLabel = createBriefLabel(); + if (briefLabel != null) { + briefLabel.setText(msg); + } + expandableComposite.layout(); + + // Logger logger = LoggerFactory.getLogger(CategoryComposite.class); + // logger.info("brief : " + msg); + } + + /** + * Sets a method to list. + * + * @param method + * a {@link Editable} + */ + public void addMethod(Editable method) { + if (method != null) { + methods.add(method); + } + } + + /** + * Returns true if this {@link CategoryComposite} contains a specified {@link Editable}. + * + * @param method + * a specified {@link Editable} + * @return true if this {@link CategoryComposite} contains a specified {@link Editable} + */ + public boolean hasMethod(Editable method) { + return methods.contains(method); + } + + /** + * Refreshes brief message on this {@link CategoryComposite}. + */ + public void refreshBrief() { + String msg = null; + if (brief == null || brief.isEmpty()) { + return; + } + msg = brief; + + for (Editable method : methods) { + String methodName = method.getMethodName(); + String methodValue = method.getValue(); + if (methodValue == null || methodValue.isEmpty()) { + methodValue = method.getDefaultValue(); + } + + msg = msg.replaceAll("%" + methodName + "%", methodValue); + } + + if (briefLabel != null && !briefLabel.isDisposed()) { + briefLabel.dispose(); + briefLabel = null; + } + briefLabel = createBriefLabel(); + if (briefLabel != null && !msg.equals(brief)) { + briefLabel.setText(msg); + } + + expandableComposite.layout(); + } + + private void setFoldings(List foldings) { + if (foldings == null || foldings.isEmpty()) { + return; + } + + this.foldings = foldings; + foldingComposite = new FoldingComposite(this, SWT.NONE, getParent()); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + foldingComposite.setLayoutData(data); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/ConstraintsUtil.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/ConstraintsUtil.java new file mode 100644 index 0000000..2dc8b1a --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/ConstraintsUtil.java @@ -0,0 +1,100 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties; + +import java.util.Collection; +import java.util.List; + +import org.tizen.efluibuilder.model.descriptors.PropertyConditionDescriptor; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.ComponentValidator; +import org.tizen.efluibuilder.ui.views.properties.method.Editable; + + +public class ConstraintsUtil { + + public static void applyConstraintsToEditable(Part model, ComponentDescriptor partDescriptor, Collection collection, Editable editable) { + List conditions = editable.getConditions(); + + boolean enableForTargetCondition = true; + if (conditions != null) { + for (PropertyConditionDescriptor condition : conditions) { + String conditionName = condition.getName(); + + Editable target = null; + for (Editable e : collection) { + if (editable.getMethodName().equals(condition.getTarget())) { + target = e; + } + } + if (target != null) { + String conditionValue = condition.getValue(); + boolean match = conditionValue != null ? conditionValue.equals(editable.getValue()) : false; + if (conditionName.equals(PropertyConditionDescriptor.ENABLE_PROPERTY)) { + target.setEnabled(match); + } else if (conditionName.equals(PropertyConditionDescriptor.DISABLE_PROPERTY)) { + enableForTargetCondition &= !match; + target.setEnabled(enableForTargetCondition); + } else if (conditionName.equals(PropertyConditionDescriptor.NOTIFY_PROPERTY)) { + target.refreshValue(editable.getMethodName(), editable.getValue()); + } + } + } + } + } + + public static String validateProperty(PropertiesUIController uiController, String propName, String newValue, Editable method) { + String message = new ComponentValidator().canSetPropertyValue(uiController.getBasePartModel(), propName, newValue); + + if (!message.equals(ComponentValidator.OK)) { + return message; + } + + List conditions = method.getConditions(); + + if (conditions != null) { + for (PropertyConditionDescriptor condition : conditions) { + String conditionName = condition.getName(); + if (conditionName.equals(PropertyConditionDescriptor.INTEGER_MIN_BY) || + conditionName.equals(PropertyConditionDescriptor.INTEGER_MAX_BY)) { + String comparePropName = condition.getValue(); + Editable editable = uiController.getEditableFromAttributeName(comparePropName); + + if (editable == null) { + return ComponentValidator.ERROR; + } + message = new ComponentValidator().canSetPropertyValue(condition, newValue, + editable.getValue(), editable.getDisplayName()); + if (!message.equals(ComponentValidator.OK)) { + break; + } + } // else if (other condition) + } + } + + return message; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/EdjeControlUtil.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/EdjeControlUtil.java new file mode 100644 index 0000000..3e0ad20 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/EdjeControlUtil.java @@ -0,0 +1,89 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.eclipse.swt.widgets.Display; +import org.tizen.efluibuilder.model.descriptors.ConstantDescriptor; +import org.tizen.efluibuilder.model.descriptors.PropertyDescriptor; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.ui.views.properties.method.ComboEditable; +import org.tizen.efluibuilder.ui.views.properties.style.StyleEditMethod; + + +public class EdjeControlUtil { + public static void updateStyleEditable(Part model, Map>> customStyleMap, ComponentDescriptor partDescriptor, + final StyleEditMethod method) { + PropertyDescriptor property = partDescriptor.getPropertyDescriptor(model.getParent(), (ComponentPart) model, LayoutSchemaConstants.STYLE); + List descriptors = property.getTypeDescriptor().getAvailableConstant(); + String componentName = model.getDescriptorId(); + boolean isItemContainer = false; + if (partDescriptor.getWidgetDescriptor(componentName).getContainerID() != null) { + componentName = partDescriptor.getWidgetDescriptor(componentName).getContainerID(); + isItemContainer = true; + } + method.updateItems(componentName, descriptors, customStyleMap, isItemContainer); + } + + public static void updateEdjGroupEditable(List groupNames, final ComboEditable editable, boolean isAsync) { + if (groupNames != null) { + final List items = new ArrayList(); + for (int i = 0; i < groupNames.size(); i++) { + items.add(new ConstantDescriptor(groupNames.get(i), groupNames.get(i))); + } + + if (isAsync) { + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + editable.resetItems(items); + if (editable.getIndex(editable.getValue()) != -1) { + editable.setValue(editable.getValue()); + } else if (items.size() > 0){ + editable.setValue(items.get(0).getValue()); + } + } + }); + } else { + editable.resetItems(items); + if (editable.getIndex(editable.getValue()) != -1) { + editable.setValue(editable.getValue()); + } else if (items.size() > 0){ + editable.setValue(items.get(0).getValue()); + } + } + } + } + + public static void updateEdjGroupEditable(List groupNames, final ComboEditable editable) { + updateEdjGroupEditable(groupNames, editable, false); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/EventDelegater.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/EventDelegater.java new file mode 100644 index 0000000..bc183bb --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/EventDelegater.java @@ -0,0 +1,414 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.gef.commands.CompoundCommand; +import org.tizen.efluibuilder.model.descriptors.ConstantDescriptor; +import org.tizen.efluibuilder.model.descriptors.ContentDescriptor; +import org.tizen.efluibuilder.model.descriptors.TypeDescriptor; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.ConfigurationPart; +import org.tizen.efluibuilder.model.part.DocumentPart; +import org.tizen.efluibuilder.model.part.EventPart; +import org.tizen.efluibuilder.model.part.IPartChangedListener; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartMutation; +import org.tizen.efluibuilder.model.part.PartObserver; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.part.VariationPart; +import org.tizen.efluibuilder.model.part.ViewPart; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.ComponentValidator; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.mscreen.configurator.IScreenConfigurationSelectionChangedListener; +import org.tizen.efluibuilder.mscreen.configurator.MScreenQualifierManager; +import org.tizen.efluibuilder.ui.views.properties.method.ComboEditable; +import org.tizen.efluibuilder.ui.views.properties.method.Editable; +import org.tizen.efluibuilder.ui.views.properties.method.EditableEvent; +import org.tizen.efluibuilder.ui.views.properties.method.IValueChangeListener; +import org.tizen.efluibuilder.ui.views.properties.style.StyleEDJManager; + +import edjResourceSyncManager.EdjResourceChangedEvent; +import edjResourceSyncManager.EdjResourceSyncManager; +import edjResourceSyncManager.IEdjResourceChangeListener; + + +public class EventDelegater + implements IPartChangedListener, IValueChangeListener, IEdjResourceChangeListener, + IScreenConfigurationSelectionChangedListener { + + private PartControlUtil partControlUtil = null; + private PropertiesUIController uiController = null; + private StyleEDJManager styleEDJManager = null; + private EdjResourceSyncManager edjResourceSyncManager = null; + private ComponentDescriptor partDescriptor = null; + private Part documentPart = null; + private CommandStack commandStack; + private PartObserver partObserver = null; + + public EventDelegater(Part documentPart, PropertiesUIController uiController, StyleEDJManager styleEDJManager, + EdjResourceSyncManager edjResourceSyncManager, PartControlUtil partControlUtil, CommandStack commandStack) { + this.documentPart = documentPart; + this.partDescriptor = ((DocumentPart) documentPart).getComponentDescriptor(); + this.uiController = uiController; + this.styleEDJManager = styleEDJManager; + this.edjResourceSyncManager = edjResourceSyncManager; + this.commandStack = commandStack; + this.partControlUtil = partControlUtil; + + bindListeners(); + } + + private void bindListeners() { + partObserver = new PartObserver(this); + partObserver.observe(documentPart); + edjResourceSyncManager.addListener(this); + partControlUtil.getMScreenQualifierManager().addConfigureSelectionChangedListener(this); + } + + private void executeCommand(Command cmd) { + if (cmd != null && cmd.canExecute()) { + commandStack.execute(cmd); + } + } + + @Override + public void valueChanged(EditableEvent event) { + // if (isStoryboardConnectionSelected()) { + // this.handleStoryboardConnectionChanged(event); + // } else { + this.handleEditableValueChanged(event); + // } + } + + @Override + public void valueModified(EditableEvent event) { + // TODO Auto-generated method stub + + } + + @Override + public void partsChanged(List mutations, PartObserver observer, String sender) { + Part model = uiController.getBasePartModel(); + boolean isChildChanged = false; + Set changedPropertySet = new HashSet(); + for (PartMutation mutation : mutations) { + if (model != null && !model.equals(mutation.getTargetPart())) + continue; + + if (isChildChanged == false) { + if (mutation.getType().equals(PartMutation.PARTS_ADDED) && isChildChanged == false) { + boolean updatedComponent = false; + for (Part child : mutation.getAddedParts()) { + if (child.getType() == PartType.COMPONENT && !updatedComponent) { + isChildChanged = true; + } + } + } else if (mutation.getType().equals(PartMutation.PARTS_REMOVED) && isChildChanged == false) { + for (Part child : mutation.getRemovedParts()) { + if (child.getType() == PartType.COMPONENT) { + isChildChanged = true; + } + } + } + } + if (mutation.getType().equals(PartMutation.PROPERTY_CHANGED)) { + Part targetPart = mutation.getTargetPart(); + if (targetPart.getType() == PartType.COMPONENT) { + changedPropertySet.add(mutation.getPropertyName()); + } + } + } + + for (String key : changedPropertySet) { + uiController.updateEditable(key); + } + + } + + @Override + public void edjResourceChanged(EdjResourceChangedEvent event) { + String filePath; + Part partModel = uiController.getBasePartModel(); + + filePath = event.path; + if (event.type == EdjResourceChangedEvent.TYPE_GROUP_NAMES_CHANGED) { + if (partControlUtil.checkPartType(partModel, LayoutSchemaConstants.LAYOUT) && + filePath.equals(partControlUtil.getRealResourcePath(partModel, LayoutSchemaConstants.SRC))) { + uiController.updateEdjGroupEditable(event.groupNames); + } + } else if (event.type == EdjResourceChangedEvent.TYPE_STYLE_LIST_CHANGED) { + if (filePath.equals(styleEDJManager.getCustomThemePath())) { + uiController.updateStyleListEditable(event.styleNames); + } + } + } + + @Override + public void configurationSelected(MScreenQualifierManager mscreenManager) { + uiController.updateMScreenProperty(); + } + + // private void handleStoryboardConnectionChanged(EditableEvent event) { + // Part model = uiController.getBasePartModel(); + // ISBTabManager sbTabManager = storyboardController.getsbTabManager(); + // ConnectionData connectionData = uiController.getBaseConnectionModel(); + // String key = event.getKey(); + // String value = event.getValue(); + // + // if (key.equals(PropertiesConstant.PROPERTY_TARGET_VIEW)) { + // Part targetView = null; + // Part viewsPart = PartUtil.findViewsPart(documentPart); + // for (Part view : viewsPart.getChildren()) { + // if (view.getPropertyValue(LayoutSchemaConstants.ID).equals(value)) { + // targetView = view; + // break; + // } + // } + // sbTabManager.changeConnectionTarget(connectionData, targetView); + // } else if (key.equals(PropertiesConstant.PROPERTY_LOCATION_X)) { + // Page pageModel = uiController.getBasePageModel(); + // storyboardController.getsbTabManager().movePage(pageModel, Integer.parseInt(value), + // pageModel.getLocation().y); + // } else if (key.equals(PropertiesConstant.PROPERTY_LOCATION_Y)) { + // Page pageModel = uiController.getBasePageModel(); + // storyboardController.getsbTabManager().movePage(pageModel, pageModel.getLocation().x, + // Integer.parseInt(value)); + // } else if (key.equals(PropertiesConstant.NAVI_VIEW_PROP) && + // model.getDescriptorId().equals(Messages.StoryboardViewer_EFL_NAVIFRAME)) { + // List srcConnections = ((ComponentPart) model).getSourceConnections(); + // if (srcConnections != null && !srcConnections.isEmpty()) { + // ConnectionData connData = srcConnections.get(0); + // if (value.isEmpty()) { + // sbTabManager.deleteConnection(connData); + // } else { + // String viewName = value.substring(1); + // Part viewPart = partControlUtil.getViewPartFromName(viewName); + // sbTabManager.changeConnectionTarget(connData, viewPart); + // } + // } else { + // String firstDisplayView = event.getValue(); + // if (!firstDisplayView.isEmpty()) { + // String targetViewName = firstDisplayView.substring(1); + // ConnectionData connData = new + // ConnectionData(model.getPropertyValue(LayoutSchemaConstants.ID), + // model.getParent().getPropertyValue(LayoutSchemaConstants.ID)); + // connData.setConnectionProperty(PropertiesConstant.PROPERTY_TARGET_VIEW, targetViewName, + // false); + // Part targetPart = partControlUtil.getViewPartFromName(targetViewName); + // sbTabManager.createConnection(new Connection(model, targetPart, connData)); + // } + // } + // } else if (key.equals(ModelConstants.PROPERTY_ID) && + // !(value.equals(model.getPropertyValue(key)))) { + // Page pageModel = uiController.getBasePageModel(); + // sbTabManager.updateViewLocationMap(pageModel, + // model.getPropertyValue(model.getPropertyValue(key)), value); + // } + // + // } + + private Command getCommandFromEditableEvent(Part model, EditableEvent event) { + String key = event.getKey(); + String value = event.getValue(); + + CompoundCommand compCmd = new CompoundCommand(); + if (key.equals(TypeDescriptor.ID_OF_ITEM_ADD)) { + // only execute AddPartVariationCommand for item widget + List contentList = partDescriptor.getWidgetDescriptor(model.getDescriptorId()).getRelation().getContents(); + if (contentList.get(0) != null) { + Part item = + PartUtil.createPartWithInitValue((DocumentPart) documentPart, PartType.COMPONENT, model, contentList.get(0).getPartIds().get(0)); + // compCmd.add(new AddPartCommand(model, item, null, partDescriptor)); + // compCmd.add(new AddPartVariationCommand(partDescriptor, msManager, model, + // item, null)); + compCmd.add(PartUtil.createAddPartCommand(model, item, null)); + } + } else { + if (model instanceof ViewPart) { + if (LayoutSchemaConstants.ID.equals(key)) { + compCmd.add(PartUtil.createSetViewPropertyIdCommand((ViewPart) model, value)); + } else { + compCmd.add(PartUtil.createSetPropertyCommand(model, key, value)); + } + } else { + ConfigurationPart currentConfigurationPart = partControlUtil.getMScreenQualifierManager().getCurrentConfigurePart(); + if (currentConfigurationPart == null) { + return null; + } + if (currentConfigurationPart.isCommon()) { + compCmd.add(PartUtil.createSetPropertyCommand(model, key, value)); + } else { + List variationProperties = new ArrayList(Arrays.asList(LayoutSchemaConstants.VARIATION_PROPERTIES)); + if ((model instanceof ComponentPart) && (variationProperties.contains(key))) { + ComponentPart part = (ComponentPart) model; + VariationPart variationPart = part.getVariationPart(currentConfigurationPart.getPropertyValue(LayoutSchemaConstants.ID)); + if (variationPart != null) { + compCmd.add(PartUtil.createSetPropertyCommand(variationPart, key, value)); + } else { + variationPart = (VariationPart) PartUtil.createPartWithInitValue((DocumentPart) documentPart, PartType.VARIATION, part, null); + compCmd.add(PartUtil.createVariationPartCommand(part, variationPart, + currentConfigurationPart.getPropertyValue(LayoutSchemaConstants.ID), + LayoutSchemaConstants.TRUE)); + compCmd.add(PartUtil.createSetPropertiesCommand(model, variationPart, partControlUtil.getPackProperties(part.getParent()))); + if (variationProperties.contains(key)) { + compCmd.add(PartUtil.createSetPropertyCommand(variationPart, key, value)); + } + } + } else { + compCmd.add(PartUtil.createSetPropertyCommand(model, key, value)); + } + } + } + } + + /* + * In case of "layout" component, When "src" attribute is changed, "group" attribute also + * should be changed. + */ + if (model.getDescriptorId().equals(LayoutSchemaConstants.LAYOUT) && + key.equals(LayoutSchemaConstants.SRC)) { + List items = new ArrayList(); + String filePath = value; + if (filePath != null) { + ArrayList groupNames = edjResourceSyncManager.getGroupNames(filePath); + if (groupNames != null) { + for (int i = 0; i < groupNames.size(); i++) { + items.add(new ConstantDescriptor(groupNames.get(i), groupNames.get(i))); + } + } + ComboEditable combo = (ComboEditable) this.uiController.getEditableFromAttributeName(LayoutSchemaConstants.GROUP); + if (combo != null) { + combo.resetItems(items); + String groupName = ""; + if (items.isEmpty() == false) { + groupName = items.get(0).getValue(); + } + compCmd.add(PartUtil.createSetPropertyCommand(model, LayoutSchemaConstants.GROUP, + groupName)); + } + + } + } + // Switch children of Panes. + else if (key.equals(LayoutSchemaConstants.PANES_PACK) && LayoutSchemaConstants.PANES.equals(model.getParent().getDescriptorId())) { + List children = model.getParent().getChildren(); + for (int i = 0; i < children.size(); i++) { + if (model != children.get(i)) { + String oppositeValue = LayoutSchemaConstants.PANES_PACK_LEFT; + if ("left".equals(value)) { + oppositeValue = LayoutSchemaConstants.PANES_PACK_RIGHT; + } + compCmd.add(PartUtil.createSetPropertyCommand(children.get(i), LayoutSchemaConstants.PANES_PACK, oppositeValue)); + break; + } + } + } + if (!compCmd.isEmpty()) { + return compCmd; + } + return null; + } + + private boolean processChangedEvent(EditableEvent event) { + String key = event.getKey(); + String value = event.getValue(); + Editable method = event.getMethod(); + Part model = null; + if (uiController.getCurrentModel() != null) { + model = uiController.getCurrentModel().get(0); + } + if (model == null) { + return false; + } else if (model instanceof EventPart) { + return true; + } + + String oldValue = model.getPropertyValue(key); + method.hideErrorTooltip(); + + String message = ConstraintsUtil.validateProperty(uiController, key, value, method); + boolean isValid = false; + if (ComponentValidator.OK.equals(message)) { + isValid = true; + } + + if (!isValid) { + uiController.refreshEditable(method.getMethodName(), oldValue); + uiController.showErrorToolTip(method.getMethodName(), message); + } + return isValid; + } + + private boolean isStoryboardProperty(String propertyName) { + if (propertyName.equals(PropertiesConstant.PROPERTY_LOCATION_X) || propertyName.equals(PropertiesConstant.PROPERTY_LOCATION_Y)) { + return true; + } + return false; + } + + private void handleEditableValueChanged(EditableEvent event) { + CompoundCommand compCmd = new CompoundCommand(); + Command cmd = null; + Part part; + + boolean isAllValid = true; + List parts = null; + if (uiController.getBaseConnectionModel() != null) { + parts = uiController.getConnectionModel(); + } else { + parts = uiController.getPartModel(); + } + for (int i = 0; i < parts.size(); i++) { + part = parts.get(i); + if (processChangedEvent(event) == false) { + isAllValid = false; + break; + } + } + if (isAllValid) { + for (int i = 0; i < parts.size(); i++) { + part = parts.get(i); + cmd = getCommandFromEditableEvent(part, event); + if (cmd != null) { + compCmd.add(cmd); + } + } + } + + if (compCmd.isEmpty() == false) { + executeCommand(compCmd); + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/FoldingComposite.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/FoldingComposite.java new file mode 100644 index 0000000..c2fd876 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/FoldingComposite.java @@ -0,0 +1,153 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.ui.resources.ImageResources; + + +public class FoldingComposite extends Composite { + private static Logger logger = LoggerFactory.getLogger(FoldingComposite.class); + private Composite ancestor; + private Composite client; + private boolean selection = false; + private Composite toggleComposite; + private Label toggle; + private MouseListener toggleListener = new MouseListener() { + + @Override + public void mouseUp(MouseEvent e) { + if (selection) { + selection = false; + Image image = ImageResources.getImage(ImageResources.PROPERTIES_DOWN_ARROW); + toggle.setImage(image); + setClientVisible(false); + } else { + selection = true; + Image image = ImageResources.getImage(ImageResources.PROPERTIES_UP_ARROW); + toggle.setImage(image); + setClientVisible(true); + } + + if (ancestor != null) { + ancestor.layout(); + } + + } + + @Override + public void mouseDown(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseDoubleClick(MouseEvent e) { + // TODO Auto-generated method stub + + } + }; + + /** + * Constructs a new instance of this class given its parent and a style value describing its + * behavior and appearance. And ancestor needs for layout. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param style + * the style of widget to construct + * @param ancestor + * a widget which the parent of parent + */ + public FoldingComposite(Composite parent, int style, Composite ancestor) { + super(parent, style); + logger.error("second_folding_closed.png is used"); + this.ancestor = ancestor; + setLayout(new GridLayout()); + createToggle(); + createClient(); + } + + private void createToggle() { + logger.error("second_folding_closed.png is used"); + // toggle composite + toggleComposite = new Composite(this, SWT.BORDER); + + toggleComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + GridLayout layout = new GridLayout(); + layout.marginHeight = 0; + toggleComposite.setLayout(layout); + + // toggle + toggle = new Label(toggleComposite, SWT.NONE); + // FIXME : followin image is removed + Image image = ImageResources.getImage(ImageResources.PROPERTIES_SECOND_FOLDING_CLOSED); + toggle.setImage(image); + GridData data = new GridData(SWT.CENTER, SWT.CENTER, true, false); + toggle.setLayoutData(data); + + toggleComposite.addMouseListener(toggleListener); + toggle.addMouseListener(toggleListener); + + } + + private void createClient() { + client = new Composite(this, SWT.NONE); + client.setLayout(new GridLayout(2, true)); + + client.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + // initial visible = false + setClientVisible(false); + } + + /** + * Gets a client {@link Composite}. + * + * @return client {@link Composite} + */ + public Composite getClient() { + return client; + } + + private void setClientVisible(boolean visible) { + if (client == null || client.isDisposed() || !(client.getLayoutData() instanceof GridData)) { + return; + } + GridData data = (GridData) client.getLayoutData(); + data.exclude = !visible; + client.setVisible(visible); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/PartControlUtil.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/PartControlUtil.java new file mode 100644 index 0000000..a4c35d3 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/PartControlUtil.java @@ -0,0 +1,227 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.ui.PlatformUI; +import org.tizen.efluibuilder.model.descriptors.PropertyConditionDescriptor; +import org.tizen.efluibuilder.model.descriptors.PropertyDescriptor; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.mscreen.configurator.MScreenQualifierManager; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; + +import graphicalDataManager.GraphicalDataManager; + + +public class PartControlUtil { + + private MScreenQualifierManager mscreenMgr = null; + private GraphicalDataManager gdataMgr = null; + private ComponentDescriptor partDescriptor = null; + private Map> multipleEditablePropertyMap = new HashMap>(); + + public PartControlUtil(MScreenQualifierManager mscreenMgr, GraphicalDataManager gdataMgr, ComponentDescriptor partDescriptor) { + this.mscreenMgr = mscreenMgr; + this.gdataMgr = gdataMgr; + this.partDescriptor = partDescriptor; + } + + public MScreenQualifierManager getMScreenQualifierManager() { + return mscreenMgr; + } + + public GraphicalDataManager getGraphicalDataManager() { + return gdataMgr; + } + + public Part getCurrentScreenPart() { + return mscreenMgr.getCurrentConfigurePart(); + } + + public String getCurrentScreenID() { + Part currentScreenPart = getCurrentScreenPart(); + if (currentScreenPart != null) { + return currentScreenPart.getPropertyValue(LayoutSchemaConstants.ID); + } + return null; + } + + public String getRealResourcePath(Part model, String propertyName) { + if (mscreenMgr == null || gdataMgr == null || gdataMgr.getRenderDataGenerator() == null) { + return null; + } + return this.gdataMgr.getRenderDataGenerator().getRealPathFromResourceProperty(model, propertyName, mscreenMgr.getCurrentDevice(), + mscreenMgr.getCurrentLocale()); + } + + public boolean checkPartType(Part part, String partType) { + if (part != null && partType.equals(part.getDescriptorId())) { + return true; + } + return false; + } + + public Part getViewPartFromName(String viewName) { + CombineEditorPart editor = (CombineEditorPart) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); + Part viewsPart = PartUtil.findViewsPart(editor.getDocumentPart()); + for (Part view : viewsPart.getChildren()) { + if (viewName.equals(view.getPropertyValue(LayoutSchemaConstants.ID))) { + return view; + } + } + return null; + } + + public List getPackProperties(Part parent) { + List keys = null; + String descriptorId = null; + if (parent != null) { + descriptorId = parent.getDescriptorId(); + } + + if (LayoutSchemaConstants.GRID.equals(descriptorId)) { + keys = new ArrayList(Arrays.asList(LayoutSchemaConstants.GRID_PACK_PROPERTIES)); + } else if (LayoutSchemaConstants.TABLE.equals(descriptorId)) { + keys = new ArrayList(Arrays.asList(LayoutSchemaConstants.TABLE_PACK_PROPERTIES)); + } else if (LayoutSchemaConstants.PANES.equals(descriptorId)) { + keys = new ArrayList(Arrays.asList(LayoutSchemaConstants.PANES_PACK_PROPERTIES)); + } + return keys; + } + + public List getMultiEditableProperties(List parts) { + List properties = new ArrayList(); + if (parts.size() > 0) { + if (PartControlUtil.isAllEqualType(parts) == true) { + Part basePart = parts.get(0); + properties.addAll(this.getMultiEditableProperties(basePart.getDescriptorId())); + } + + Part basePart = parts.get(0); + if (PartControlUtil.isSameParentType(parts) && + (LayoutSchemaConstants.GRID.equals(basePart.getParent().getDescriptorId()) || + LayoutSchemaConstants.TABLE.equals(basePart.getParent().getDescriptorId()))) { + properties.addAll(partDescriptor.getChildUIComponentPropertyDescriptors(basePart.getParent().getDescriptorId())); + } + } + return properties; + } + + private List getMultiEditableProperties(String descriptorId) { + if (this.multipleEditablePropertyMap.get(descriptorId) == null) { + boolean isAccept = true; + List properties = new ArrayList(); + List descriptors = this.partDescriptor.getPropertyDescriptors(null, descriptorId); + for (PropertyDescriptor desc : descriptors) { + isAccept = true; + if (desc.getPropertyName().equals(LayoutSchemaConstants.ID) || desc.getPropertyName().equals(LayoutSchemaConstants.EVENT)) { + continue; + } + for (PropertyConditionDescriptor condition : desc.getConditionDescriptors()) { + if (condition.getName().equals(PropertyConditionDescriptor.DISABLE_PROPERTY) || + condition.getName().equals(PropertyConditionDescriptor.ENABLE_PROPERTY) || + condition.getName().equals(PropertyConditionDescriptor.INTEGER_MIN_BY) || + condition.getName().equals(PropertyConditionDescriptor.INTEGER_MAX_BY)) { + isAccept = false; + break; + } + } + if (isAccept == true) { + properties.add(desc); + } + } + multipleEditablePropertyMap.put(descriptorId, properties); + } + return multipleEditablePropertyMap.get(descriptorId); + } + + public static boolean isAllEqualType(List parts) { + if (parts.isEmpty()) { + return false; + } + + if (parts.size() > 1) { + for (int i = 1; i < parts.size(); i++) { + if (parts.get(i).getDescriptorId() == null || + parts.get(i - 1).getDescriptorId() == null || + (parts.get(i).getDescriptorId().equals(parts.get(i - 1).getDescriptorId()) == false)) { + return false; + } + } + } + return true; + } + + public static boolean isAllComponentPart(List parts) { + for (int i = 0; i < parts.size(); i++) { + if (parts.get(i) instanceof ComponentPart == false) { + return false; + } + } + return true; + } + + public static boolean isSameParentType(List parts) { + if (parts.isEmpty()) { + return false; + } + for (int i = 1; i < parts.size(); i++) { + if (parts.get(i - 1).getParent().getDescriptorId().equals(parts.get(i).getParent().getDescriptorId()) == false) { + return false; + } + } + return true; + } + + public String getMultiPartPropertyValue(List parts, String propertyName) { + String prevValue = null, value = null; + ComponentPart part; + + String configurationID = this.getCurrentScreenID(); + + if (parts.size() == 1) { + return ((ComponentPart) (parts.get(0))).getPropertyValue(configurationID, propertyName); + } + + for (int i = 0; i < parts.size(); i++) { + part = (ComponentPart) (parts.get(i)); + value = part.getPropertyValue(configurationID, propertyName); + if (i > 0) { + if (prevValue != null && value != null && prevValue.equals(value) == false) + return null; + } + prevValue = value; + } + return value; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/PropertiesConstant.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/PropertiesConstant.java new file mode 100644 index 0000000..38ae7ae --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/PropertiesConstant.java @@ -0,0 +1,144 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties; + +/** + * A properties page constants class. + */ +public class PropertiesConstant { + public static final String ATTRIBUTES = "Attributes"; //$NON-NLS-1$ + public static final String EVENT = "Events"; //$NON-NLS-1$ + public static final String STYLE = "Style"; //$NON-NLS-1$ + + public static final String EVENT_ADD = "<>"; //$NON-NLS-1$ + public static final int INDEX_EVENT_ADD = 0; + public static final String EVENT_CUSTOM = "<>"; //$NON-NLS-1$ + public static final int INDEX_EVENT_CUSTOM = 1; + public static final String CATEGORY_WIDGET_SPEC = "General"; //$NON-NLS-1$ + + public static final String GET_TARGET = "%target%"; //$NON-NLS-1$ + public static final String EVENT_REPLACE_PAGE = "%page%"; //$NON-NLS-1$ + public static final String EVENT_REPLACE_OBJECT = "%object%"; //$NON-NLS-1$ + public static final String EVENT_REPLACE_EVENT = "%event%"; //$NON-NLS-1$ + public static final String STYLE_REPLACE_ID = "%id%"; //$NON-NLS-1$ + public static final String STYLE_REPLACE_PAGE_ID = "%pageid%"; //$NON-NLS-1$ + + public static final String NO_CONTENTS = "nocontents"; //$NON-NLS-1$ + public static final String NO_CONTENTS_MSG = "No selected contents"; //$NON-NLS-1$ + + public static final String PROPERTY_RESET = "Reset"; //$NON-NLS-1$ + public static final String PROPERTY_RESET_TOOLTIP = "Reset default value"; //$NON-NLS-1$ + public static final String PROPERTY_DELETE_TOOLTIP = "Delete event handler"; //$NON-NLS-1$ + public static final String STYLE_RESET_TOOLTIP = "Reset value"; //$NON-NLS-1$ + public static final String STYLE_ERROR_INVALID_UNITS = "Invalid use of units. Only use px, %, em and cm."; //$NON-NLS-1$ + public static final String STYLE_FONT_FAMILY_TOOLTIP = "font-family may be expressed differently depending on the target."; //$NON-NLS-1$ + + /* + * Images in Properties view + */ + public static final String DIALOG_TITLE_OPEN = "Open"; //$NON-NLS-1$ + public static final String DIALOG_FILTER_ALL = "*.*"; //$NON-NLS-1$ + public static final String DIALOG_FILTER_PNG = "*.png"; //$NON-NLS-1$ + public static final String DIALOG_FILTER_JPG = "*.jpg"; //$NON-NLS-1$ + public static final String DIALOG_FILTER_JPEG = "*.jpeg"; //$NON-NLS-1$ + public static final String DIALOG_FILTER_GIF = "*.gif"; //$NON-NLS-1$ + public static final String DIALOG_FILTER_ICO = "*.ico"; //$NON-NLS-1$ + public static final String DIALOG_FILTER_MP4 = "*.mp4"; //$NON-NLS-1$ + public static final String DIALOG_FILTER_OGG = "*.ogg"; //$NON-NLS-1$ + public static final String DIALOG_FILTER_WEBM = "*.webm"; //$NON-NLS-1$ + public static final String DIALOG_FILTER_MPEG = "*.mpeg"; //$NON-NLS-1$ + public static final String DIALOG_FILTER_NAME_ALL_IMAGE = "All image files (*.jpg;*.png;*.gif)"; //$NON-NLS-1$ + public static final String DIALOG_FILTER_NAME_JPEG = "JPEG (*.jpg;*.jpeg)"; //$NON-NLS-1$ + public static final String DIALOG_FILTER_NAME_PNG = "PNG (*.png)"; //$NON-NLS-1$ + public static final String DIALOG_FILTER_NAME_GIF = "GIF (*.gif)"; //$NON-NLS-1$ + public static final String DIALOG_FILTER_NAME_ICO = "ICO (*.ico)"; //$NON-NLS-1$ + public static final String DIALOG_FILTER_NAME_ALL = "All files (*.*)"; //$NON-NLS-1$ + + public static final String DIALOG_FILTER_EDC = "*.edc"; //$NON-NLS-1$ + public static final String DIALOG_FILTER_EDJ = "*.edj"; //$NON-NLS-1$ + public static final String DIALOG_FILTER_NAME_ALL_LAYOUT = "All layout files (*.edc;*.edj)"; //$NON-NLS-1$ + public static final String DIALOG_FILTER_NAME_EDC = "EDC (*.edc)"; //$NON-NLS-1$ + public static final String DIALOG_FILTER_NAME_EDJ = "EDJ (*.edj)"; //$NON-NLS-1$ + + public static final String DIALOG_FILTER_TXT = "*.txt"; //$NON-NLS-1$ + public static final String DIALOG_FILTER_NAME_TXT = "TEXT (*.txt)"; //$NON-NLS-1$ + + public static final String DIALOG_FILTER_NAME_ALL_AUDIO = "All audio files (*.mp4;*.ogg;*.mpeg)"; //$NON-NLS-1$ + public static final String DIALOG_FILTER_NAME_MP4 = "MP4 (*.mp4)"; //$NON-NLS-1$ + public static final String DIALOG_FILTER_NAME_OGG = "OGG (*.ogg)"; //$NON-NLS-1$ + public static final String DIALOG_FILTER_NAME_MPEG = "MPEG (*.mpeg)"; //$NON-NLS-1$ + + public static final String DIALOG_FILTER_NAME_ALL_VIDEO = "All video files (*.mp4;*.ogg;*.webm)"; //$NON-NLS-1$ + public static final String DIALOG_FILTER_NAME_WEBM = "WEBM (*.webm)"; //$NON-NLS-1$ + + public static final String DIALOG_COLOR_SELECTOR = "Color selector"; //$NON-NLS-1$ + + public static final String STYLE_PROPERTY_COLUMN_NAME = "Element"; //$NON-NLS-1$ + public static final String STYLE_VALUE_COLUMN_NAME = "Value"; //$NON-NLS-1$ + + public static final int STYLE_PROPERTY_COLUMN_SIZE = 150; + public static final int STYLE_VALUE_COLUMN_SIZE = 150; + + public static final int ATTRIBUTES_MIN_WIDTH_SIZE = 200; + public static final int ACTION_MIN_WIDTH_SIZE = 260; + public static final int STYLE_MIN_WIDTH_SIZE = 350; + + public static final String TEXT_NONE = "None"; //$NON-NLS-1$ + public static final String NONE = "(" + TEXT_NONE + ")"; //$NON-NLS-1$ + + public static final String PROPERTY_DATE_FORMAT = "yyyy/MM/dd"; //$NON-NLS-1$ + public static final String PROPERTY_TIME_FORMAT = "HH:mm:ss"; //$NON-NLS-1$ + + public static final String EVENT_PREFIX = "on"; //$NON-NLS-1$ + public static final String CUSTOM_EVENT_DIALOG_TITLE = "Custom event"; //$NON-NLS-1$ + public static final String CUSTOM_EVENT_DIALOG_CONTENT = "Enter the event name (such as 'click')."; //$NON-NLS-1$ + public static final String EVENT_INVALID_MESSAGE_1 = "Invalid character is used."; //$NON-NLS-1$ + public static final String EVENT_INVALID_MESSAGE_2 = "The first word cannot be 'on'."; //$NON-NLS-1$ + public static final String EVENT_INVALID_MESSAGE_3 = "Must be different from the name of UI Component event"; //$NON-NLS-1$ + public static final String EVENT_INVALID_MESSAGE_4 = "Already exists."; //$NON-NLS-1$ + + // StoryBoard_START + public static final String PROPERTY_SOURCE = "Source"; //$NON-NLS-1$ + public static final String PROPERTY_TARGET = "Target"; //$NON-NLS-1$ + public static final String PROPERTY_COMMON = "Common"; //$NON-NLS-1$ + public static final String PROPERTY_SPECIFICATION = "Specification"; //$NON-NLS-1$ + public static final String PROPERTY_WIDGET_ID = "WidgetID"; //$NON-NLS-1$ + public static final String PROPERTY_WIDGET_ID_DISPLAY_NAME = "Widget ID"; //$NON-NLS-1$ + public static final String PROPERTY_PARENT_VIEW = "ParentView"; //$NON-NLS-1$ + public static final String PROPERTY_PARENT_VIEW_DISPLAY_NAME = "Parent View"; //$NON-NLS-1$ + public static final String PROPERTY_TARGET_VIEW = "target"; //$NON-NLS-1$ + public static final String PROPERTY_TARGET_VIEW_DISPLAY_NAME = "Target View"; //$NON-NLS-1$ + public static final String PROPERTY_PREV_BUTTON = "prev"; //$NON-NLS-1$ + public static final String PROPERTY_PREV_BUTTON_DISPLAY_NAME = "Previous Button"; //$NON-NLS-1$ + public static final String PROPERTY_NEXT_BUTTON = "next"; //$NON-NLS-1$ + public static final String PROPERTY_NEXT_BUTTON_DISPLAY_NAME = "Next Button"; //$NON-NLS-1$ + public static final String PROPERTY_STYLE = "style"; //$NON-NLS-1$ + public static final String PROPERTY_STYLE_DISPLAY_NAME = "Style"; //$NON-NLS-1$ + public static final String PROPERTY_LOCATION_X = "location_x"; //$NON-NLS-1$ + public static final String PROPERTY_LOCATION_Y = "location_y"; //$NON-NLS-1$ + public static final String NAVI_VIEW_PROP = "view"; //$NON-NLS-1$ + public static final String PROPERTY_WRAPPER = "connection_wrapper"; //$NON-NLS-1$ + public static final String PROPERTY_EVENTNAME = "event_name"; //$NON-NLS-1$ + // StoryBoard_END +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/PropertiesModelProvider.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/PropertiesModelProvider.java new file mode 100644 index 0000000..4a24985 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/PropertiesModelProvider.java @@ -0,0 +1,111 @@ +/* +* UI Builder +* +* Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. +* +* 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.efluibuilder.ui.views.properties; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.gef.EditPart; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.views.contentoutline.ContentOutline; +import org.tizen.efluibuilder.model.part.EventPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.ViewsPart; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.efluibuilder.ui.editor.designeditor.DesignEditor; +import org.tizen.efluibuilder.ui.editor.texteditor.TextEditor; + + +public class PropertiesModelProvider { + public static List getModelFromSelection(IWorkbenchPart part, ISelection selection) { + if (!(selection instanceof StructuredSelection) || selection.isEmpty()) { + return null; + } + + if (!(part instanceof ContentOutline || part instanceof CombineEditorPart)) { + return null; + } + + Object selectedPage = ((CombineEditorPart) part).getSelectedPage(); + if (!(((selectedPage instanceof DesignEditor) || (selectedPage instanceof TextEditor)) || selectedPage instanceof Composite)) { + return null; + } + + IStructuredSelection ss = (IStructuredSelection) selection; + List model = ss.toList(); + return model; + } + + public static boolean isAllPartModel(List model) { + boolean ret = false; + for (Object obj : model) { + if (obj instanceof EditPart && ((EditPart) obj).getModel() instanceof Part) { + ret = true; + } else { + ret = false; + break; + } + } + return ret; + } + + public static PropertyViewModelSet getPropertyViewModelSet(List selectionModel) { + List partModel = new ArrayList(); + List connectionModel = new ArrayList(); + List selectedEditPart = new ArrayList(); + + if (isAllPartModel(selectionModel) == true) { + for (Object obj : selectionModel) { + Part part = (Part) (((EditPart) obj).getModel()); + if (part.getParent() == null) { // dangling part + return null; + } + if (part instanceof EventPart) { + connectionModel.add(part); + continue; + } else if (part instanceof ViewsPart) { + continue; + } + partModel.add(part); + } + } else { + return null; + } + + if (PartControlUtil.isAllComponentPart(partModel) == false + // || PartControlUtil.isAllEqualType(partModel) == false + ) { + partModel.clear(); + } + + for (Object obj : selectionModel) { + selectedEditPart.add((EditPart) obj); + } + return new PropertyViewModelSet(selectedEditPart, partModel, connectionModel); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/PropertiesPage.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/PropertiesPage.java new file mode 100644 index 0000000..d6efe75 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/PropertiesPage.java @@ -0,0 +1,166 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties; + +import java.util.List; + +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.gef.ui.actions.ActionRegistry; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.actions.ActionFactory; +import org.eclipse.ui.part.Page; +import org.eclipse.ui.views.contentoutline.ContentOutline; +import org.eclipse.ui.views.properties.IPropertySheetPage; +import org.eclipse.ui.views.properties.PropertySheet; +import org.tizen.efluibuilder.model.part.DocumentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.mscreen.configurator.MScreenQualifierManager; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.efluibuilder.ui.editor.designeditor.DesignEditor; +import org.tizen.efluibuilder.ui.editor.texteditor.TextEditor; +import org.tizen.efluibuilder.ui.views.properties.style.StyleEDJManager; + +import edjResourceSyncManager.EdjResourceSyncManager; +import graphicalDataManager.GraphicalDataManager; + + +/** + * Page-book page for the {@link PropertySheet}. This page is activated in PageDesigner. + */ +public final class PropertiesPage extends Page implements IPropertySheetPage { + private PropertiesPageComposite pageComposite; + private CommandStack commandStack = null; + private ActionRegistry registry = null; + private Part documentPart; + private EdjResourceSyncManager edjResSyncMgr = null; + private GraphicalDataManager graphicalDataMgr = null; + private StyleEDJManager styleEDJManager = null; + private MScreenQualifierManager screenQualifierMgr = null; + private EventDelegater eventDelegater = null; + private PropertiesUIController uiController = null; + + CombineEditorPart editor = (CombineEditorPart) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); + + public PropertiesPage(CommandStack commandStack, ActionRegistry registry, Part documentPart, EdjResourceSyncManager edjResSyncMgr, + GraphicalDataManager graphicalDataMgr, StyleEDJManager styleEDJManager) { + this.commandStack = commandStack; + this.registry = registry; + this.documentPart = documentPart; + this.edjResSyncMgr = edjResSyncMgr; + this.graphicalDataMgr = graphicalDataMgr; + this.styleEDJManager = styleEDJManager; + + } + + @Override + public void createControl(Composite parent) { + Control control = getControl(); + if (control != null && !control.isDisposed()) { + return; + } + CombineEditorPart editor = (CombineEditorPart) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); + screenQualifierMgr = editor.getDesignEditor().getViewer().getMScreenQualifierManager(); + uiController = new PropertiesUIController(); + PartControlUtil partControlUtil = new PartControlUtil(screenQualifierMgr, graphicalDataMgr, ((DocumentPart) documentPart).getComponentDescriptor()); + eventDelegater = + new EventDelegater(documentPart, uiController, styleEDJManager, edjResSyncMgr, partControlUtil, commandStack); + pageComposite = + new PropertiesPageComposite(parent, SWT.NONE, commandStack, documentPart, edjResSyncMgr, graphicalDataMgr, styleEDJManager, screenQualifierMgr, + uiController); + + uiController.initContent(pageComposite, ((DocumentPart) documentPart).getComponentDescriptor(), eventDelegater, partControlUtil, + styleEDJManager.getProjectVersion()); + createActions(); + } + + @Override + public void setFocus() { + getControl().setFocus(); + } + + @Override + public void dispose() { + if (pageComposite != null) { + pageComposite.dispose(); + } + registry = null; + super.dispose(); + } + + private boolean isAcceptableSelection(IWorkbenchPart part, ISelection selection) { + if (!(selection instanceof StructuredSelection) || selection.isEmpty()) + return false; + + if (!(part instanceof ContentOutline)) { + if (!(part instanceof CombineEditorPart)) { + return false; + } + + Object selectedPage = ((CombineEditorPart) part).getSelectedPage(); + if (!(((selectedPage instanceof DesignEditor) || (selectedPage instanceof TextEditor)) || selectedPage instanceof Composite)) { + return false; + } + } + return true; + } + + @Override + public void selectionChanged(IWorkbenchPart part, ISelection selection) { + if (isAcceptableSelection(part, selection)) { + IStructuredSelection ss = (IStructuredSelection) selection; + List selections = ss.toList(); + PropertyViewModelSet modelSet = + PropertiesModelProvider.getPropertyViewModelSet(selections); + if (modelSet != null) { + uiController.setModel(modelSet); + } + } + } + + @Override + public Control getControl() { + return pageComposite; + } + + private void createActions() { + IActionBars actionBars = getSite().getActionBars(); + + String id = ActionFactory.UNDO.getId(); + actionBars.setGlobalActionHandler(id, registry.getAction(id)); + + id = ActionFactory.REDO.getId(); + actionBars.setGlobalActionHandler(id, registry.getAction(id)); + + actionBars.updateActionBars(); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/PropertiesPageComposite.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/PropertiesPageComposite.java new file mode 100644 index 0000000..4dbbda1 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/PropertiesPageComposite.java @@ -0,0 +1,797 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.ui.views.properties; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.events.ControlAdapter; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.forms.events.ExpansionAdapter; +import org.eclipse.ui.forms.events.ExpansionEvent; +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.model.descriptors.EventDescriptor; +import org.tizen.efluibuilder.model.descriptors.PropertyDescriptor; +import org.tizen.efluibuilder.model.descriptors.PropertyDescriptor.UnusedEditors; +import org.tizen.efluibuilder.model.descriptors.TypeDescriptor; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.DocumentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.renderDataGenerator.RenderDataGenerator; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.mscreen.configurator.MScreenQualifierManager; +import org.tizen.efluibuilder.storyboard.codegenerator.CodeGeneratorUtil; +import org.tizen.efluibuilder.storyboard.codegenerator.Messages; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.efluibuilder.ui.resources.ColorResources; +import org.tizen.efluibuilder.ui.resources.FontResources; +import org.tizen.efluibuilder.ui.resources.ImageResources; +import org.tizen.efluibuilder.ui.views.properties.event.AbstractEventComposite; +import org.tizen.efluibuilder.ui.views.properties.event.EventComposite; +import org.tizen.efluibuilder.ui.views.properties.events.HandlerCodeWriter; +import org.tizen.efluibuilder.ui.views.properties.method.ComboEditable; +import org.tizen.efluibuilder.ui.views.properties.method.Editable; +import org.tizen.efluibuilder.ui.views.properties.method.Editable.MethodType; +import org.tizen.efluibuilder.ui.views.properties.method.EditableCreationFactory; +import org.tizen.efluibuilder.ui.views.properties.method.NoContentEditable; +import org.tizen.efluibuilder.ui.views.properties.method.TextEditable; +import org.tizen.efluibuilder.ui.views.properties.method.ViewsComboEditable; +import org.tizen.efluibuilder.ui.views.properties.style.StyleEDJManager; +import org.tizen.efluibuilder.ui.views.properties.style.StyleEditMethod; + +import edjResourceSyncManager.EdjResourceSyncManager; +import graphicalDataManager.GraphicalDataManager; + + +/** + * + * @author jungwook.ryu This class is just merged AttributesTab, EventTab, PropertiesTabItem classes + * and adjust UI layout. TODO After refactoring the Model, this class should be + * refactorizing. + */ +public class PropertiesPageComposite extends Composite { + // If size of content is same CONTENT_MIN_SIZE, horizontal scrollbar will be shown. + private final int CONTENT_MIN_SIZE = 280; + + // PropertiesTabItem + private ScrolledComposite scrolledComposite; + private Composite content; + private Composite attrTitleComposite; + private Composite eventTitleComposite; + private String infoText; + // private CLabel selectedWidgetLabel; + private Canvas selectedWidgetLabel; + + // private Canvas selectedWidgetLabel; + private ComponentDescriptor partDescriptor; + // AttributesTab + private List categories = new ArrayList(); + private EditableCreationFactory factory; + private CommandStack commandStack; + // EventTab + private Composite eventComposite; + private List eventComposites = new ArrayList(); + // StoryBoard_START + private Composite connectionEventDetailsContent; + private HandlerCodeWriter codeWriter = new HandlerCodeWriter(); + // StoryBoard_END + + private EdjResourceSyncManager edjResSyncMgr = null; + private RenderDataGenerator renderDataGenerator = null; + private StyleEDJManager styleEDJManager = null; + private MScreenQualifierManager screenQualifierMgr = null; + + private PropertiesUIController uiController = null; + + private Listener listener = new Listener() { + @Override + public void handleEvent(Event event) { + switch (event.type) { + case SWT.MouseWheel: + Point origin = scrolledComposite.getOrigin(); + origin.y += (event.count * -1) * 10; + scrolledComposite.setOrigin(origin); + break; + default: + break; + } + } + }; + + public PropertiesPageComposite(Composite parent, int style, CommandStack commandStack, Part documentPart, EdjResourceSyncManager edjResSyncMgr, + GraphicalDataManager graphicalDataMgr, StyleEDJManager styleEDJManager, MScreenQualifierManager screenQualifierMgr, + PropertiesUIController uiController) { + super(parent, style); + createContent(this); + this.commandStack = commandStack; + if (documentPart == null) { + return; + } + this.partDescriptor = ((DocumentPart) documentPart).getComponentDescriptor(); + + // new ActionEventDelegater(this); + factory = EditableCreationFactory.getInstance(); + + this.edjResSyncMgr = edjResSyncMgr; + this.styleEDJManager = styleEDJManager; + this.renderDataGenerator = graphicalDataMgr.getRenderDataGenerator(); + this.screenQualifierMgr = screenQualifierMgr; + this.uiController = uiController; + } + + private void layoutStoryboardContent() { + List possibleTargetViews = new ArrayList(); + List editableList = new ArrayList(); + boolean naviframeFlag = false; + if (uiController.getConnectionCount() != 1) { + addNoContentEditable(); + return; + } + + Part eventPart = uiController.getBaseConnectionModel(); + Part sourcePart = eventPart != null ? eventPart.getParent() : null; + if (eventPart == null || sourcePart == null) { + return; + } + Part sourceViewPart = ((ComponentPart) sourcePart).getOwnerViewPart(); + ComponentDescriptor componentDescriptor = sourcePart.getOwnerDocumentPart().getComponentDescriptor(); + String sourceId = eventPart.getParent().getPropertyValue(LayoutSchemaConstants.ID); + String sourceViewId = sourceViewPart.getPropertyValue(LayoutSchemaConstants.ID); + String targetViewId = eventPart.getPropertyValue(LayoutSchemaConstants.EVENT_TARGET); + String signalId = eventPart.getPropertyValue(LayoutSchemaConstants.EVENT_SIGNAL); + String functionName = eventPart.getPropertyValue(LayoutSchemaConstants.EVENT_FUNCTION_NAME); + String functionNamePost = functionName + "_post"; + String eventInfo = componentDescriptor.getEventInfo((ComponentPart) sourcePart, signalId); + + if (sourceId.equals(Messages.StoryboardViewer_EFL_NAVIFRAME)) { + naviframeFlag = true; + } + + attrTitleComposite = createTitleComposite(PropertiesConstant.ATTRIBUTES, 18, 0); + CategoryComposite categorySource = getCategory(PropertiesConstant.PROPERTY_SOURCE, 4); + Composite clientSourceComposite = categorySource.getClient(PropertiesConstant.PROPERTY_SOURCE); + + Editable methodWidgetID = new TextEditable(clientSourceComposite, SWT.NONE, MethodType.ATTRIBUTE, PropertiesConstant.PROPERTY_WIDGET_ID, + sourceId, PropertiesConstant.PROPERTY_WIDGET_ID_DISPLAY_NAME, false); + methodWidgetID.setEnabled(false); + editableList.add(methodWidgetID); + + Editable methodParentView = new TextEditable(clientSourceComposite, SWT.NONE, MethodType.ATTRIBUTE, PropertiesConstant.PROPERTY_PARENT_VIEW, + sourceViewId, PropertiesConstant.PROPERTY_PARENT_VIEW_DISPLAY_NAME, false); + methodParentView.setEnabled(false); + editableList.add(methodParentView); + + CategoryComposite categoryTarget = getCategory(PropertiesConstant.PROPERTY_TARGET, 4); + Composite clientTargetComposite = categoryTarget.getClient(PropertiesConstant.PROPERTY_TARGET); + ViewsComboEditable methodTargetView = + new ViewsComboEditable(clientTargetComposite, SWT.NONE, MethodType.ATTRIBUTE, PropertiesConstant.PROPERTY_TARGET_VIEW, + targetViewId, + PropertiesConstant.PROPERTY_TARGET_VIEW_DISPLAY_NAME, false); + CombineEditorPart editor = (CombineEditorPart) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); + Part viewsPart = PartUtil.findViewsPart(editor.getDocumentPart()); + + for (Part view : viewsPart.getChildren()) { + if (!(view.getPropertyValue(LayoutSchemaConstants.ID).equals(sourceViewId))) { + possibleTargetViews.add(view); + } + } + methodTargetView.setItems(possibleTargetViews); + editableList.add(methodTargetView); + + CategoryComposite categorySpecification = getCategory(PropertiesConstant.PROPERTY_SPECIFICATION, 4); + Composite clientSpecificationComposite = categorySpecification.getClient(PropertiesConstant.PROPERTY_SPECIFICATION); + Editable methodPrevButton = new TextEditable(clientSpecificationComposite, SWT.NONE, MethodType.ATTRIBUTE, PropertiesConstant.PROPERTY_PREV_BUTTON, + "NULL", PropertiesConstant.PROPERTY_PREV_BUTTON_DISPLAY_NAME, false); + methodPrevButton.setEnabled(false); + editableList.add(methodPrevButton); + + Editable methodNextButton = new TextEditable(clientSpecificationComposite, SWT.NONE, MethodType.ATTRIBUTE, PropertiesConstant.PROPERTY_NEXT_BUTTON, + "NULL", PropertiesConstant.PROPERTY_NEXT_BUTTON_DISPLAY_NAME, false); + methodNextButton.setEnabled(false); + editableList.add(methodNextButton); + + Editable methodStyle = new TextEditable(clientSpecificationComposite, SWT.NONE, MethodType.ATTRIBUTE, PropertiesConstant.PROPERTY_STYLE, "NULL", + PropertiesConstant.PROPERTY_STYLE_DISPLAY_NAME, false); + methodStyle.setEnabled(false); + editableList.add(methodStyle); + + for (Editable m : editableList) { + if (naviframeFlag) { + m.setEnabled(false); + } + m.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); + m.setLabelRightData(32, 0); + m.setControlRightData(100, 0); + m.refresh(); + uiController.addEditable(m.getMethodName(), m); + } + + // layout events + content.setEnabled(true); + if (naviframeFlag) { + return; + } + eventTitleComposite = createTitleComposite(PropertiesConstant.EVENT, 10, -10); + final String viewName = sourceViewId; + + connectionEventDetailsContent = new Composite(content, SWT.NONE); + connectionEventDetailsContent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); + connectionEventDetailsContent.setLayout(new FormLayout()); + Composite textComposite = new Composite(connectionEventDetailsContent, SWT.BORDER); + FormData formData = new FormData(); + formData.left = new FormAttachment(0, 40); + formData.right = new FormAttachment(100, -35); + formData.height = 22; + textComposite.setLayoutData(formData); + textComposite.setLayout(new FillLayout()); + + Label eventLabel = new Label(textComposite, SWT.NONE); + eventLabel.setForeground(ColorResources.PROPERTIES_EVENT_LABEL); + eventLabel.setText(signalId); + + // pre handler + + Composite eventNameComposite = new Composite(content, SWT.NONE); + + eventNameComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); + eventNameComposite.setLayout(new FormLayout()); + Text eventName = new Text(eventNameComposite, SWT.BORDER); + eventName.setText(functionName); + eventName.setEnabled(false); + formData = new FormData(); + formData.left = new FormAttachment(0, 40); + formData.right = new FormAttachment(100, -50); + formData.height = 22; + eventName.setLayoutData(formData); + + Label btnGoButton = new Label(eventNameComposite, SWT.NONE); + Image image = ImageResources.getImage(ImageResources.PROPERTIES_EVENT_ARROW_BTN_NOR); + formData = new FormData(); + formData.left = new FormAttachment(eventName, 5); + btnGoButton.setLayoutData(formData); + btnGoButton.setImage(image); + btnGoButton.addMouseListener(new MouseAdapter() { + @Override + public void mouseUp(MouseEvent arg0) { + codeWriter.addConnectionHandlerFunction(functionName, viewName, CodeGeneratorUtil.getEventParams(sourcePart, signalId), eventInfo, false); + } + }); + + // post handler + eventNameComposite = new Composite(content, SWT.NONE); + + eventNameComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); + eventNameComposite.setLayout(new FormLayout()); + eventName = new Text(eventNameComposite, SWT.BORDER); + eventName.setText(functionNamePost); + eventName.setEnabled(false); + formData = new FormData(); + formData.left = new FormAttachment(0, 40); + formData.right = new FormAttachment(100, -50); + formData.height = 22; + eventName.setLayoutData(formData); + + btnGoButton = new Label(eventNameComposite, SWT.NONE); + image = ImageResources.getImage(ImageResources.PROPERTIES_EVENT_ARROW_BTN_NOR); + formData = new FormData(); + formData.left = new FormAttachment(eventName, 5); + btnGoButton.setLayoutData(formData); + btnGoButton.setImage(image); + btnGoButton.addMouseListener(new MouseAdapter() { + @Override + public void mouseUp(MouseEvent arg0) { + codeWriter.addConnectionHandlerFunction(functionName, viewName, CodeGeneratorUtil.getEventParams(sourcePart, signalId), eventInfo, true); + } + }); + } + + private void addNoContentEditable() { + Editable method = new NoContentEditable(content, MethodType.ATTRIBUTE); + method.setLayoutData(new GridData(GridData.CENTER, GridData.FILL, true, true, 2, 1)); + uiController.addEditable(method.getMethodName(), method); + } + + private void layoutContent() { + Part model = uiController.getBasePartModel(); + if (model == null || model.getType() == PartType.VIEWS || model.getParent() == null + || (uiController.getPartModel().size() > 1 && uiController.getMultiEditableProperties().isEmpty())) { + // if (uiController.getSelection().size() > 1) { + // // not surpported + // // TODO + // Editable method = new MultiSelectMethod(content, MethodType.ATTRIBUTE); + // method.setLayoutData(new GridData(GridData.CENTER, GridData.FILL, true, true, 2, 1)); + // uiController.addEditable(method.getMethodName(), method); + // } else { + // Editable method = new NoContentEditable(content, MethodType.ATTRIBUTE); + // method.setLayoutData(new GridData(GridData.CENTER, GridData.FILL, true, true, 2, 1)); + // uiController.addEditable(method.getMethodName(), method); + // } + addNoContentEditable(); + } else { + ComponentPart part = null; + ComponentPart parentPart = null; + if (model instanceof ComponentPart) { + part = (ComponentPart) model; + } else { + throw new IllegalArgumentException("The model must be ComponentPart: " + model); + } + + if (model.getParent() instanceof ComponentPart) { + parentPart = (ComponentPart) model.getParent(); + } + + // Add Attribute title + attrTitleComposite = createTitleComposite(PropertiesConstant.ATTRIBUTES, 18, 0); + + List properties; + if (uiController.getPartModel().size() > 1) { + properties = uiController.getMultiEditableProperties(); + } else { + properties = partDescriptor.getPropertyDescriptors(parentPart, part); + } + + // Get category count + Set categories = new HashSet(); + for (PropertyDescriptor property : properties) { + String categoryName = property.getCategory(); + if (property.checkUnusedEditors(UnusedEditors.PROPERTIES)) { // TODO + continue; + } + + categories.add(categoryName); + } + + // Add properties component + for (PropertyDescriptor property : properties) { + // StoryBoard_START + CombineEditorPart editor = (CombineEditorPart) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); + if ((property.getPropertyName().equals(PropertiesConstant.PROPERTY_LOCATION_X) + || property.getPropertyName().equals(PropertiesConstant.PROPERTY_LOCATION_Y)) + && editor.getActivePage() == CombineEditorPart.DESIGN_TAB) { + continue; + } + // StoryBoard_END + if (property.checkUnusedEditors(UnusedEditors.PROPERTIES)) { + continue; + } + + String groupName = property.getCategory(); + CategoryComposite category = getCategory(groupName, categories.size()); + // String value = + // part.getPropertyValue(currentConfigurationPart.getPropertyValue(LayoutSchemaConstants.ID), + // property.getPropertyName()); + String value = uiController.getPartControlUtil().getMultiPartPropertyValue(uiController.getPartModel(), + property.getPropertyName()); + Editable method = factory.createMethod(category.getClient(property.getPropertyName()), property, value, MethodType.ATTRIBUTE, false); + if (method == null) { + continue; + } else if (property.getPropertyName().equals("type") && (part.getType() == PartType.VIEW)) { + method.setEnabled(false); + } else if (property.getPropertyName().equals("name") && (part.getType() == PartType.VIEW)) { + method.setEnabled(false); + } else if (model.getDescriptorId().equals(LayoutSchemaConstants.LAYOUT) && + property.getPropertyName().equals(LayoutSchemaConstants.GROUP)) { + String filePath = + renderDataGenerator.getRealPathFromResourceProperty(model, + LayoutSchemaConstants.SRC, screenQualifierMgr.getCurrentDevice(), + screenQualifierMgr.getCurrentLocale()); + ArrayList groupNames = edjResSyncMgr.getGroupNames(filePath); + EdjeControlUtil.updateEdjGroupEditable(groupNames, (ComboEditable) method); + } else if ((property.getTypeDescriptor().getType() == TypeDescriptor.Types.EFL_STYLE)) { + String version = styleEDJManager.getProjectVersion(); + if (StyleEDJManager.isLaterVersion3_0(version)) { + EdjeControlUtil.updateStyleEditable(model, styleEDJManager.getCustomStyleNames(), partDescriptor, (StyleEditMethod) method); + ((StyleEditMethod) method).setStyleEDJManager(styleEDJManager); + ((StyleEditMethod) method).setPropertiesPageComposite(this); + } + } + if (property.getInlineValue() != null && property.getInlineValue().equals("true")) { + GridData data = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1); + method.setLayoutData(data); + method.setLabelRightData(65, 1); + method.setControlRightData(100, 0); + } else { + method.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); + method.setLabelRightData(35, 0); + method.setControlRightData(100, 0); + } + + // addListenerToMethod(method); + changeResetState(method); + method.refresh(); + uiController.addEditable(property.getPropertyName(), method); + // methods.add(method); + } + } + + // layout events + if (model == null || (model.getType() == PartType.VIEWS) || model.getParent() == null) { + // Do nothing + } else if (uiController.getPartModel().size() > 1) { + // Do nothing + } else { + /* get event trigger list */ + List events = partDescriptor.getEventDescriptors((ComponentPart) model); + if (events != null && events.isEmpty() == false) { + eventTitleComposite = createTitleComposite(PropertiesConstant.EVENT, 10, -8); + eventComposite = createEventComposite(); + // check already exist event handler in model + EventComposite actionEventComposite; + for (EventDescriptor event : events) { + actionEventComposite = new EventComposite(eventComposite, event, model, this); + if (actionEventComposite != null) { + eventComposites.add(actionEventComposite); + actionEventComposite.updateState(); + } + } + } + } + + } + + private Composite createEventComposite() { + Composite eventComposite = new Composite(content, SWT.NONE); + eventComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + GridLayout layout = new GridLayout(1, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.horizontalSpacing = 0; + layout.verticalSpacing = 5; + eventComposite.setLayout(layout); + + return eventComposite; + } + + // DONE + public void refresh() { + if (content.isDisposed()) { + return; + } + clear(); + + if (uiController.getBaseConnectionModel() != null && uiController.getBasePartModel() != null) { + addNoContentEditable(); + } else if (uiController.getBaseConnectionModel() != null) { + layoutStoryboardContent(); + refreshConnectionInfo(); + } else { + layoutContent(); + if (PartControlUtil.isAllEqualType(uiController.getPartModel()) == true) { + uiController.applyConstraints(); // apply conditions after all methods are created + } + } + content.pack(); + refreshInfoArea(); // TODO : FIXME + resizeScrolledComposite(); + } + + /** + * Changes reset state after compare {@link Editable} and value of property in model. + * + * @param method + * a {@link Editable} + */ + public void changeResetState(Editable method) { + boolean canReset = false; + Part basePart = uiController.getBasePartModel(); + if (basePart == null) { + return; + } + for (String key : basePart.getProperties().keySet()) { + if (key.equals(method.getMethodName())) { + canReset = true; + break; + } + } + + method.enableFuncButton(canReset); + } + + public CommandStack getCommandStack() { + return commandStack; + } + + // //////////////////////////////////////////////////////////////////////////////////////////////////////// + + private void createContent(Composite parent) { + parent.setLayout(new FormLayout()); + + Composite info = makeInfoArea(parent); + + scrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL); + scrolledComposite.setLayout(new FillLayout()); + FormData data = new FormData(); + data.top = new FormAttachment(info, 0); + data.bottom = new FormAttachment(100, 0); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(100, 0); + scrolledComposite.setLayoutData(data); + + scrolledComposite.setExpandHorizontal(true); + scrolledComposite.setExpandVertical(true); + scrolledComposite.setMinSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT)); + + content = new Composite(scrolledComposite, SWT.NONE); + content.setBackground(ColorResources.PROPERTIES_CONTENT_BG); + content.setBackgroundMode(SWT.INHERIT_DEFAULT); + + GridLayout layout = new GridLayout(1, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.horizontalSpacing = 0; + layout.verticalSpacing = 5; + content.setLayout(layout); + + scrolledComposite.setContent(content); + scrolledComposite.addListener(SWT.MouseWheel, listener); + scrolledComposite.addControlListener(new ControlAdapter() { + @Override + public void controlResized(ControlEvent event) { + resizeScrolledComposite(); + } + }); + scrolledComposite.setMinSize(content.computeSize(310, SWT.DEFAULT)); + } + + private void refreshInfoArea() { + Part model = uiController.getBasePartModel(); + if (model == null || (model.getType() == PartType.VIEWS) || model.getParent() == null || (uiController.getPartModel().size() > 1)) { + selectedWidgetLabel.setData("KEY_IMAGE", null); + selectedWidgetLabel.setData("KEY_TEXT", BuilderConstants.EMPTY); + // selectedWidgetLabel.setImage(null); + // selectedWidgetLabel.setText(BuilderConstants.EMPTY); + selectedWidgetLabel.redraw(); + return; + } + String iconPath = partDescriptor.getIcon16((ComponentPart) model); + Image image = ImageResources.getImage(BuilderConstants.ICON_DIR + iconPath); + if (image != null) { + // selectedWidgetLabel.setImage(image); + selectedWidgetLabel.setData("KEY_IMAGE", image); + } + infoText = partDescriptor.getDisplayName((ComponentPart) model); + // selectedWidgetLabel.setText(infoText); + selectedWidgetLabel.setData("KEY_TEXT", infoText); + selectedWidgetLabel.redraw(); + } + + /* + * e.g. "Properties > Button" + */ + private Composite makeInfoArea(Composite parent) { + Composite info = new Composite(parent, SWT.NONE); + FormData formData = new FormData(); + formData.top = new FormAttachment(0, 0); + formData.height = 35; + formData.left = new FormAttachment(0, 0); + formData.right = new FormAttachment(100, 0); + info.setLayoutData(formData); + info.setBackground(ColorResources.PROPERTIES_TITLE_BG); + info.setLayout(new FormLayout()); + + /* + * Title Line + */ + Composite lineComp = new Composite(info, SWT.NONE); + lineComp.setBackground(ColorResources.PROPERTIES_SEPERARTOR); + formData = new FormData(); + formData.left = new FormAttachment(0, 0); + formData.right = new FormAttachment(100, 0); + formData.height = 1; + lineComp.setLayoutData(formData); + + /* + * Component (e.g. Button..) + */ + selectedWidgetLabel = new Canvas(info, SWT.NONE); + formData = new FormData(); + formData.top = new FormAttachment(0, 9); + formData.left = new FormAttachment(0, 15); + formData.right = new FormAttachment(100, 0); + + selectedWidgetLabel.setLayoutData(formData); + selectedWidgetLabel.addPaintListener(new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + e.gc.setBackground(ColorResources.PROPERTIES_TITLE_BG); + e.gc.fillRectangle(0, 0, e.width, e.height); + + Image image = (Image) selectedWidgetLabel.getData("KEY_IMAGE"); + String text = (String) selectedWidgetLabel.getData("KEY_TEXT"); + int x = 0; + if (image != null) { + e.gc.drawImage(image, x, 1); + x += image.getBounds().width + 6; + } + if (text != null) { + e.gc.drawText(text, x, 0); + } + } + }); + return info; + } + + /** + * Resize the {@link ScrolledComposite} on this item. + */ + public void resizeScrolledComposite() { + scrolledComposite.setMinSize(content.computeSize(CONTENT_MIN_SIZE, SWT.DEFAULT)); + } + + private CategoryComposite getCategory(String categoryName, int categoryCount) { + if (categoryName == null || categoryName.isEmpty()) { + categoryName = PropertiesConstant.CATEGORY_WIDGET_SPEC; + } + + for (CategoryComposite category : categories) { + if (category.getCategoryName().equals(categoryName)) { + return category; + } + } + + // create new category + CategoryComposite categoryComposite = createCategory(categoryName); + + if (categories.size() < categoryCount) { // Separator to divide categories in Attributes + drawSeparator(18, ColorResources.PROPERTIES_ATTR_SEPERATOR); + } else { // Separator to divide Attributes and Event + drawSeparator(0, ColorResources.PROPERTIES_SEPERARTOR); + } + + return categoryComposite; + } + + private void drawSeparator(int widthGap, final Color color) { + Composite separatorComposite = new Composite(content, SWT.None); + separatorComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); + separatorComposite.setLayout(new FormLayout()); + + Composite separator = new Composite(separatorComposite, SWT.NONE); + FormData formData = new FormData(); + formData.left = new FormAttachment(0, widthGap); + formData.right = new FormAttachment(100, -widthGap); + formData.height = 1; + separator.setLayoutData(formData); + separator.setBackground(color); + } + + private CategoryComposite createCategory(String categoryName) { + CategoryComposite categoryComposite = new CategoryComposite(content, categoryName, BuilderConstants.EMPTY, null); + categoryComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); + categoryComposite.addExpansionListener(new ExpansionAdapter() { + + @Override + public void expansionStateChanged(ExpansionEvent e) { + content.layout(); + } + }); + + Composite composite = new Composite(categoryComposite.getExpandableComposite(), SWT.NONE); + categoryComposite.setClient(composite); + + GridLayout layout = new GridLayout(2, false); + layout.marginWidth = 0; + layout.verticalSpacing = 5; + layout.marginBottom = 0; + layout.marginTop = 0; + composite.setLayout(layout); + + categories.add(categoryComposite); + + return categoryComposite; + } + + private void clear() { + // Attribute + for (CategoryComposite category : categories) { + category.dispose(); + } + + if (attrTitleComposite != null) { + attrTitleComposite.dispose(); + attrTitleComposite = null; + } + if (eventTitleComposite != null) { + eventTitleComposite.dispose(); + eventTitleComposite = null; + } + for (Control control : content.getChildren()) { + control.dispose(); + } + categories.clear(); + uiController.clearEditables(); + + // Event + // StoryBoard_START + if (connectionEventDetailsContent != null && !connectionEventDetailsContent.isDisposed()) { + connectionEventDetailsContent.dispose(); + connectionEventDetailsContent = null; + } + // StoryBoard_END + + eventComposites.clear(); + } + + private void refreshConnectionInfo() { + if (uiController.getBaseConnectionModel() != null) { + // selectedWidgetLabel.setImage(null); + // selectedWidgetLabel.setText(""); + + selectedWidgetLabel.setData("KEY_IMAGE", null); + selectedWidgetLabel.setData("KEY_TEXT", "Connection"); + selectedWidgetLabel.redraw(); + } + } + + private Composite createTitleComposite(String title, int topMargin, int bottomMargin) { + Composite titleComp = new Composite(content, SWT.NONE); + titleComp.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); + titleComp.setLayout(new FormLayout()); + FormData formData = new FormData(); + formData.left = new FormAttachment(0, 16); + formData.top = new FormAttachment(0, topMargin); + formData.bottom = new FormAttachment(100, bottomMargin); + + Label titleLabel = new Label(titleComp, SWT.NONE); + titleLabel.setFont(FontResources.BOLD); + titleLabel.setText(title); + titleLabel.setLayoutData(formData); + + return titleComp; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/PropertiesUIController.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/PropertiesUIController.java new file mode 100644 index 0000000..f273a4f --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/PropertiesUIController.java @@ -0,0 +1,226 @@ +/* +* UI Builder +* +* Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. +* +* 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.efluibuilder.ui.views.properties; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; + +import org.eclipse.gef.EditPart; +import org.tizen.efluibuilder.model.descriptors.PropertyDescriptor; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.EventPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.ui.views.properties.method.ComboEditable; +import org.tizen.efluibuilder.ui.views.properties.method.Editable; +import org.tizen.efluibuilder.ui.views.properties.method.EditableCreationFactory; +import org.tizen.efluibuilder.ui.views.properties.style.StyleEditMethod; + + +public class PropertiesUIController { + private PropertiesPageComposite pageComposite = null; + private Map editableMap = new HashMap(); + private ComponentDescriptor partDescriptor; + private PropertyViewModelSet model; + private EventDelegater eventDelegater = null; + private PartControlUtil partControlUtil = null; + private String projectVersion = ""; + private List multiEditableProperties = null; + + public void initContent(PropertiesPageComposite pageComposite, ComponentDescriptor partDescriptor, EventDelegater pageChangeListener, + PartControlUtil partControlUtil, String projectVersion) { + this.partDescriptor = partDescriptor; + this.eventDelegater = pageChangeListener; + this.projectVersion = projectVersion; + this.pageComposite = pageComposite; + this.partControlUtil = partControlUtil; + } + + public void refreshUI() { + pageComposite.refresh(); + } + + public void updateMScreenProperty() { + if (getPartModel().size() == 1 && getBasePartModel() instanceof ComponentPart && getBasePartModel().getParent() instanceof ComponentPart) { + ComponentPart part = (ComponentPart) getBasePartModel(); + List descriptors = partDescriptor.getPropertyDescriptors(part.getParent().getDescriptorId(), part.getDescriptorId()); + for (PropertyDescriptor descriptor : descriptors) { + for (String varitionPropertyName : LayoutSchemaConstants.VARIATION_PROPERTIES) { + if (descriptor.getPropertyName().equals(varitionPropertyName)) + this.refreshEditable(descriptor.getPropertyName(), part.getPropertyValue(partControlUtil.getCurrentScreenID(), + descriptor.getPropertyName())); + } + } + } + } + + public void updateEdjGroupEditable(List groupNames) { + final Editable editable = getEditableFromAttributeName(LayoutSchemaConstants.GROUP); + if (editable != null && editable instanceof ComboEditable) { + EdjeControlUtil.updateEdjGroupEditable(groupNames, (ComboEditable) editable, true); + } + } + + public void updateStyleListEditable(Map>> map) { + Part model = this.getBasePartModel(); + Editable editable = this.getEditableFromAttributeName(LayoutSchemaConstants.STYLE); + if (editable instanceof StyleEditMethod) { + StyleEditMethod styleEditable = (StyleEditMethod) editable; + EdjeControlUtil.updateStyleEditable(model, map, partDescriptor, styleEditable); + } + } + + public Editable getEditableFromAttributeName(String name) { + return editableMap.get(name); + } + + public PropertyViewModelSet getModel() { + return model; + } + + public List getPartModel() { + if (model != null) { + return model.partModel; + } + return null; + } + + public List getConnectionModel() { + if (model != null) { + return model.connectionModel; + } + return null; + } + + public int getConnectionCount() { + return model != null ? model.connectionModel.size() : 0; + } + + public Part getBasePartModel() { + if (model != null && model.partModel.size() > 0) { + return model.partModel.get(0); + } + return null; + } + + public Part getBaseConnectionModel() { + if (model != null && model.connectionModel.size() > 0) { + return model.connectionModel.get(0); + } + return null; + } + + public List getCurrentModel() { + if (getBasePartModel() != null && getBaseConnectionModel() != null) { + return null; + } else if (getBaseConnectionModel() != null) { + return getConnectionModel(); + } else if (getBasePartModel() != null) { + return getPartModel(); + } + return null; + } + + public List getSelection() { + return model.selection; + } + + public void setModel(PropertyViewModelSet model) { + this.model = model; + multiEditableProperties = partControlUtil.getMultiEditableProperties(model.partModel); + EditableCreationFactory.getInstance().setModel(getBasePartModel()); + EditableCreationFactory.getInstance().setProjectVersion(projectVersion); + refreshContent(); + } + + public void clearEditables() { + for (Editable editable : editableMap.values()) { + editable.dispose(); + } + this.editableMap.clear(); + } + + public void addEditable(String name, Editable editable) { + this.editableMap.put(name, editable); + bindEditableListener(editable); + } + + private void bindEditableListener(Editable editable) { + editable.setValueChangedListener(this.eventDelegater); + } + + public void updateEditable(String propertyName) { + Editable editable = editableMap.get(propertyName); + if (editable != null) { + editable.refreshValue(propertyName, partControlUtil.getMultiPartPropertyValue(this.getPartModel(), propertyName)); + } + } + + public void refreshContent() { + pageComposite.refresh(); + pageComposite.layout(); + } + + public void refreshEditable(String propertyName, String propertyValue) { + Editable editable = getEditableFromAttributeName(propertyName); + if (editable != null) { + editable.refreshValue(propertyName, propertyValue); + } + } + + public void showErrorToolTip(String propertyName, String message) { + Editable editable = getEditableFromAttributeName(propertyName); + if (editable != null) { + editable.showErrorToolTip(message); + } + } + + public void applyConstraints() { + for (Editable editable : editableMap.values()) { + ConstraintsUtil.applyConstraintsToEditable(getBasePartModel(), partDescriptor, editableMap.values(), editable); + } + } + + public PartControlUtil getPartControlUtil() { + return this.partControlUtil; + } + + public List getMultiEditableProperties() { + return this.multiEditableProperties; + } + + public HashSet getViewTransitionTrigger(Part part) { + HashSet hashSet = new HashSet(); + for (Part child : part.getChildren()) { + if (child instanceof EventPart && child.hasProperty(LayoutSchemaConstants.EVENT_CONNECTION)) { + hashSet.add(child.getPropertyValue(LayoutSchemaConstants.EVENT_SIGNAL)); + } + } + return hashSet; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/PropertyViewModelSet.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/PropertyViewModelSet.java new file mode 100644 index 0000000..1b808b0 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/PropertyViewModelSet.java @@ -0,0 +1,42 @@ +/* +* UI Builder +* +* Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. +* +* 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.efluibuilder.ui.views.properties; + +import java.util.List; + +import org.eclipse.gef.EditPart; +import org.tizen.efluibuilder.model.part.Part; + + +public class PropertyViewModelSet { + public List partModel = null; + public List connectionModel = null; + public List selection = null; + + public PropertyViewModelSet(List selection, List partModel, List connectionModel) { + this.selection = selection; + this.partModel = partModel; + this.connectionModel = connectionModel; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/event/AbstractEventComposite.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/event/AbstractEventComposite.java new file mode 100644 index 0000000..68e82e2 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/event/AbstractEventComposite.java @@ -0,0 +1,49 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.event; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; + + +public abstract class AbstractEventComposite extends Composite { + + private Composite composite; + + public AbstractEventComposite(Composite parent) { + super(parent, SWT.NONE); + setLayout(); + composite = createControl(this); + } + + protected abstract void setLayout(); + + protected abstract Composite createControl(Composite parent); + + protected abstract void initContents(); + + protected Composite getComposite() { + return composite; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/event/EventComposite.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/event/EventComposite.java new file mode 100644 index 0000000..62dd66a --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/event/EventComposite.java @@ -0,0 +1,238 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.event; + +import java.util.List; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseTrackAdapter; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.tizen.efluibuilder.model.descriptors.EventDescriptor; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.EventPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.ui.resources.ColorResources; +import org.tizen.efluibuilder.ui.resources.ImageResources; +import org.tizen.efluibuilder.ui.views.properties.PropertiesPageComposite; + + +public class EventComposite extends AbstractEventComposite { + private Canvas btnNewButton; + private boolean hasEventHandler = false; + private Label event; + private Part part; + private EventDescriptor descriptor; + private PropertiesPageComposite propertiesPage; + + /** + * @param parent + * {@link Composite} + * @param descriptor + * {@link EventDescriptor} + * @param part + * {@link Part} + * @param propertiesPage + * {@link PropertiesPageComposite} + */ + public EventComposite(Composite parent, EventDescriptor descriptor, Part part, PropertiesPageComposite propertiesPage) { + super(parent); + this.descriptor = descriptor; + this.part = part; + this.propertiesPage = propertiesPage; + + initContents(); + } + + @Override + protected void setLayout() { + GridLayout layout = new GridLayout(1, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.horizontalSpacing = 0; + layout.verticalSpacing = 0; + setLayout(layout); + setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + } + + @Override + protected Composite createControl(Composite parent) { + Composite compositeEventName = new Composite(parent, SWT.NONE); + compositeEventName.setLayoutData(new GridData(GridData.FILL_BOTH)); + compositeEventName.setLayout(new FormLayout()); + + Composite textComposite = new Composite(compositeEventName, SWT.BORDER); + FormData formData = new FormData(); + formData.top = new FormAttachment(0, 0); + formData.left = new FormAttachment(0, 42); + formData.right = new FormAttachment(100, -65); + formData.bottom = new FormAttachment(0, 24); + textComposite.setLayoutData(formData); + textComposite.setLayout(new FillLayout()); + + event = new Label(textComposite, SWT.NONE); + event.setForeground(ColorResources.PROPERTIES_EVENT_LABEL); + + btnNewButton = new Canvas(compositeEventName, SWT.NONE); + FormData fd_btnNewButton = new FormData(); + fd_btnNewButton.top = new FormAttachment(0, 0); + fd_btnNewButton.left = new FormAttachment(textComposite, 9); + fd_btnNewButton.bottom = new FormAttachment(0, 24); + fd_btnNewButton.width = 24; + fd_btnNewButton.height = 24; + btnNewButton.setLayoutData(fd_btnNewButton); + + addButtonListener2(btnNewButton); + btnNewButton.setData(ImageResources.getImage(ImageResources.PROPERTIES_EVENT_PLUS_NOR)); + + return compositeEventName; + } + + @Override + protected void initContents() { + event.setText(" " + descriptor.getEventDisplayName()); + } + + /** + * add button listeners and icons + * + * @param btnNewButton + */ + private void addButtonListener2(final Canvas btnNewButton) { + btnNewButton.addMouseListener(new MouseAdapter() { + @Override + public void mouseUp(MouseEvent e) { + if (hasEventHandler) { + return; + } + addEventHandlerComposite(null); + updateLayout(); + propertiesPage.resizeScrolledComposite(); + } + + @Override + public void mouseDown(MouseEvent e) { + if (hasEventHandler) { + return; + } + btnNewButton.setData(ImageResources.getImage(ImageResources.PROPERTIES_EVENT_PLUS_SEL)); + btnNewButton.redraw(); + } + }); + btnNewButton.addMouseTrackListener(new MouseTrackAdapter() { + @Override + public void mouseEnter(MouseEvent arg0) { + if (hasEventHandler) { + return; + } + btnNewButton.setData(ImageResources.getImage(ImageResources.PROPERTIES_EVENT_PLUS_MV)); + btnNewButton.redraw(); + } + + @Override + public void mouseExit(MouseEvent arg0) { + if (!hasEventHandler) { + btnNewButton.setData(ImageResources.getImage(ImageResources.PROPERTIES_EVENT_PLUS_NOR)); + btnNewButton.redraw(); + } + } + }); + btnNewButton.addPaintListener(new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + Image image = (Image) btnNewButton.getData(); + e.gc.drawImage(image, 0, 0); + } + }); + } + + /** + * add EventHandlerComposite + * + * @return + */ + private void addEventHandlerComposite(EventPart part) { + new EventHandlerComposite(this, this, part); + setHasEventHandler(true); + } + + public void setHasEventHandler(boolean hasEventHandler) { + this.hasEventHandler = hasEventHandler; + if (hasEventHandler) { + btnNewButton.setData(ImageResources.getImage(ImageResources.PROPERTIES_EVENT_PLUS_DIM)); + btnNewButton.redraw(); + } else { + btnNewButton.setData(ImageResources.getImage(ImageResources.PROPERTIES_EVENT_PLUS_NOR)); + btnNewButton.redraw(); + } + } + + /** + * call composite.layout() for redraw + */ + public void updateLayout() { + getParent().getParent().layout(); + } + + /** + * update EventComposite state + */ + public void updateState() { + List partActions = ((ComponentPart) part).getEventParts(descriptor.getEventName()); + if ((partActions != null) && (partActions.size() != 0)) { + for (EventPart partAction : partActions) { + if (!partAction.hasProperty(LayoutSchemaConstants.EVENT_CONNECTION)) { + addEventHandlerComposite(partAction); + } else { + setHasEventHandler(true); + } + } + } + } + + public Part getPart() { + return part; + } + + public EventDescriptor getDescriptor() { + return descriptor; + } + + public PropertiesPageComposite getPropertiesPage() { + return propertiesPage; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/event/EventHandlerComposite.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/event/EventHandlerComposite.java new file mode 100644 index 0000000..fc1f19d --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/event/EventHandlerComposite.java @@ -0,0 +1,474 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.event; + +import java.util.List; + +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CommandStack; +import org.eclipse.gef.commands.CompoundCommand; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseTrackAdapter; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Text; +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.model.descriptors.EventParamDescriptor; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.EventPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.ComponentValidator; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.resources.ImageResources; +import org.tizen.efluibuilder.ui.views.properties.events.HandlerCodeManager; + + +public class EventHandlerComposite extends AbstractEventComposite { + + private EventComposite eventComposite; + private EventPart eventPart; + private Text combo; + private String oldComboText; + private HandlerCodeManager codeWriter = new HandlerCodeManager(); + + /** + * @param parent + * {@link Composite} + * @param eventComposite + * {@link EventComposite} + * @param javaScriptFuncIndex + */ + public EventHandlerComposite(Composite parent, EventComposite eventComposite, EventPart eventPart) { + super(parent); + this.eventComposite = eventComposite; + this.eventPart = eventPart; + + initContents(); + } + + @Override + protected void setLayout() { + GridLayout layout = new GridLayout(1, false); + layout.marginHeight = 3; + layout.marginWidth = 0; + layout.horizontalSpacing = 0; + layout.verticalSpacing = 0; + setLayout(layout); + setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.swt.widgets.Widget#dispose() + */ + @Override + public void dispose() { + Composite composite = getComposite(); + if (composite != null) + composite.dispose(); + + super.dispose(); + } + + @Override + protected Composite createControl(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + composite.setLayout(new FormLayout()); + + /* + * Arrow icon + */ + Canvas arrowIcon = new Canvas(composite, SWT.NONE); + FormData formData = new FormData(); + formData.top = new FormAttachment(0, 8); + formData.left = new FormAttachment(0, 29); + formData.width = 7; + formData.height = 7; + arrowIcon.setLayoutData(formData); + arrowIcon.addPaintListener(new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + Image image = ImageResources.getImage(ImageResources.PROPERTIES_EVENT_ARROW); + e.gc.drawImage(image, 0, 0); + } + }); + + /* + * Listener Text + */ + combo = new Text(composite, SWT.BORDER); + formData = new FormData(); + formData.top = new FormAttachment(0, 0); + formData.left = new FormAttachment(arrowIcon, 6); + formData.right = new FormAttachment(100, -87); + combo.setLayoutData(formData); + addListenersToCombo(); + + /* + * Delete listener button + */ + Canvas btnDeleteButton = new Canvas(composite, SWT.NONE); + FormData fd_btnDeleteButton = new FormData(); + fd_btnDeleteButton.top = new FormAttachment(0, 0); + fd_btnDeleteButton.left = new FormAttachment(combo, 4); + fd_btnDeleteButton.bottom = new FormAttachment(0, 24); + fd_btnDeleteButton.width = 24; + fd_btnDeleteButton.height = 24; + btnDeleteButton.setLayoutData(fd_btnDeleteButton); + + addDeleteButtonListener(btnDeleteButton); + btnDeleteButton.setData(ImageResources.getImage(ImageResources.PROPERTIES_EVENT_DELETE_NOR)); + /* + * Go to source code button + */ + Canvas btnGoButton = new Canvas(composite, SWT.NONE); + FormData fd_btnGoButton = new FormData(); + fd_btnGoButton.top = new FormAttachment(0, 0); + fd_btnGoButton.left = new FormAttachment(btnDeleteButton, 4); + fd_btnGoButton.bottom = new FormAttachment(0, 24); + fd_btnGoButton.width = 24; + fd_btnGoButton.height = 24; + btnGoButton.setLayoutData(fd_btnGoButton); + + addGoButtonListener(btnGoButton); + btnGoButton.setData(ImageResources.getImage(ImageResources.PROPERTIES_EVENT_ARROW_BTN_NOR)); + + return composite; + } + + @Override + protected void initContents() { + setValidatedValue(getDefaultCode()); + } + + /** + * go button listeners and icons + * + * @param btnGoButton + */ + private void addGoButtonListener(final Canvas btnGoButton) { + btnGoButton.addMouseListener(new MouseAdapter() { + @Override + public void mouseUp(MouseEvent e) { + btnGoButton.setData(ImageResources.getImage(ImageResources.PROPERTIES_EVENT_ARROW_BTN_NOR)); + btnGoButton.redraw(); + valueChanged(); + } + + @Override + public void mouseDown(MouseEvent e) { + btnGoButton.setData(ImageResources.getImage(ImageResources.PROPERTIES_EVENT_ARROW_BTN_SEL)); + btnGoButton.redraw(); + } + }); + btnGoButton.addMouseTrackListener(new MouseTrackAdapter() { + @Override + public void mouseEnter(MouseEvent e) { + btnGoButton.setData(ImageResources.getImage(ImageResources.PROPERTIES_EVENT_ARROW_BTN_MV)); + btnGoButton.redraw(); + } + + @Override + public void mouseExit(MouseEvent arg0) { + btnGoButton.setData(ImageResources.getImage(ImageResources.PROPERTIES_EVENT_ARROW_BTN_NOR)); + btnGoButton.redraw(); + } + }); + + btnGoButton.addPaintListener(new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + Image image = (Image) btnGoButton.getData(); + e.gc.drawImage(image, 0, 0); + } + }); + } + + /** + * delete button listeners and icons + * + * @param btnDeleteButton + */ + private void addDeleteButtonListener(final Canvas btnDeleteButton) { + btnDeleteButton.addMouseListener(new MouseAdapter() { + @Override + public void mouseUp(MouseEvent e) { + btnDeleteButton.setData(ImageResources.getImage(ImageResources.PROPERTIES_EVENT_DELETE_NOR)); + removeEventHandlerComposite(); + } + + @Override + public void mouseDown(MouseEvent e) { + btnDeleteButton.setData(ImageResources.getImage(ImageResources.PROPERTIES_EVENT_DELETE_SEL)); + btnDeleteButton.redraw(); + } + }); + btnDeleteButton.addMouseTrackListener(new MouseTrackAdapter() { + @Override + public void mouseEnter(MouseEvent e) { + btnDeleteButton.setData(ImageResources.getImage(ImageResources.PROPERTIES_EVENT_DELETE_MV)); + btnDeleteButton.redraw(); + } + + @Override + public void mouseExit(MouseEvent arg0) { + btnDeleteButton.setData(ImageResources.getImage(ImageResources.PROPERTIES_EVENT_DELETE_NOR)); + btnDeleteButton.redraw(); + } + }); + btnDeleteButton.addPaintListener(new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + Image image = (Image) btnDeleteButton.getData(); + e.gc.drawImage(image, 0, 0); + } + }); + } + + /** + * removeEventHandlerComposite + */ + private void removeEventHandlerComposite() { + removeEventPart(); + dispose(); + + eventComposite.setHasEventHandler(false); + eventComposite.updateLayout(); + eventComposite.getPropertiesPage().resizeScrolledComposite(); + } + + private String getDefaultCode() { + String eventName = eventComposite.getDescriptor().getEventName(); + String defaultCode = null; + if (eventPart == null) { + defaultCode = getDefaultCode(eventName); + } else { + if (eventPart.getPropertyValue(LayoutSchemaConstants.EVENT_FUNCTION_NAME) == null) { + defaultCode = getDefaultCode(eventName); + eventPart.setPropertyValue(LayoutSchemaConstants.EVENT_FUNCTION_NAME, defaultCode); + } else { + defaultCode = eventPart.getPropertyValue(LayoutSchemaConstants.EVENT_FUNCTION_NAME); + } + } + return defaultCode; + } + + private String getDefaultCode(String eventName) { + String defaultCode = eventComposite.getDescriptor().getEventTypeDescriptor().getDefaultCode(); + ComponentPart model = (ComponentPart) eventComposite.getPart(); + String widgetID = model.getPropertyValue(BuilderConstants.PROPERTY_ID); + if (widgetID == null) { + widgetID = ""; + } + + String viewID = model.getOwnerViewPart().getPropertyValue(BuilderConstants.PROPERTY_ID); + if (viewID == null) { + viewID = ""; + } + + return EventHandlerUtil.getDefaultEventHandlerName(viewID, widgetID, eventName, defaultCode); + } + + /** + * setValidatedValue + * + * @param value + * @return + */ + private boolean setValidatedValue(String value) { + if (value == null) { + return false; + } + if (value.matches(BuilderConstants.REGULAREXPRESSION)) { + setValue(value); + return true; + } else { + // FIXME "" + if (this.oldComboText == null) { + combo.setText(""); + } else { + combo.setText(this.oldComboText); + } + return false; + } + } + + /** + * setValue + * + * @param value + */ + private void setValue(String value) { + combo.setText(value); + this.oldComboText = value; + } + + /** + * valueChanged + */ + private void valueChanged() { + Part part = eventComposite.getPart(); + if (!(part instanceof ComponentPart)) { + return; + } + CommandStack commandStack = eventComposite.getPropertiesPage().getCommandStack(); + if (commandStack == null) { + return; + } + ComponentPart componentPart = (ComponentPart) part; + // page id + String viewID = componentPart.getOwnerViewPart().getPropertyValue(BuilderConstants.PROPERTY_ID); + if (viewID == null) { + viewID = ""; + } + + String eventName = combo.getText(); + String signal = eventComposite.getDescriptor().getEventName(); + ComponentDescriptor componentDescriptor = componentPart.getOwnerDocumentPart().getComponentDescriptor(); + List params = componentDescriptor.getEventParams(componentPart, signal); + String eventInfo = componentDescriptor.getEventInfo(componentPart, signal); + if (eventPart == null) { + // add handler func + codeWriter.addHandlerFunction(eventName, viewID, params, eventInfo); + eventPart = (EventPart) PartUtil.createPartWithInitValue(componentPart.getOwnerDocumentPart(), PartType.EVENT, componentPart, + LayoutSchemaConstants.EVENT); + Command command = PartUtil.createEventPartCommand(componentPart, eventPart, eventName, signal); + commandStack.execute(command); + } else if (eventPart.getPropertyValue(LayoutSchemaConstants.EVENT_FUNCTION_NAME) == null) { + // add hanlder func and set EVENT_FUNCTION_NAME/EVENT_SIGNAL property + codeWriter.addHandlerFunction(eventName, viewID, params, eventInfo); + CompoundCommand compCmd = new CompoundCommand(); + compCmd.add(PartUtil.createSetPropertyCommand(componentPart, LayoutSchemaConstants.EVENT_FUNCTION_NAME, eventName)); + compCmd.add(PartUtil.createSetPropertyCommand(componentPart, LayoutSchemaConstants.EVENT_SIGNAL, eventName)); + commandStack.execute(compCmd); + } else { + // modify handler func + String oldEventName = eventPart.getPropertyValue(LayoutSchemaConstants.EVENT_FUNCTION_NAME); + if (!eventName.equals(oldEventName)) { + EventPart newEventPart = (EventPart) PartUtil.createPart(PartType.EVENT, null, componentPart); + CompoundCommand compundCmd = new CompoundCommand(); + compundCmd.add(PartUtil.createRemovePartCommand(componentPart, eventPart)); + compundCmd.add(PartUtil.createAddPartCommand(componentPart, newEventPart, null)); + commandStack.execute(compundCmd); + } else { + ComponentValidator ComponentValidator = new ComponentValidator(); + if ((ComponentValidator.getUsedEventNameCount(componentPart, oldEventName) == 1) + && (ComponentValidator.getUsedEventNameCount(componentPart, eventName) == 0)) { + codeWriter.modifyHandlerFunction(oldEventName, eventName, viewID); + Command command = PartUtil.createSetPropertyCommand(componentPart, LayoutSchemaConstants.EVENT_FUNCTION_NAME, eventName); + commandStack.execute(command); + } else { + codeWriter.addHandlerFunction(eventName, viewID, params, eventInfo); + if (eventPart.getIndex() == -1) { + Command command = PartUtil.createAddPartCommand(componentPart, eventPart, null); + commandStack.execute(command); + } + } + } + } + + } + + /** + * addListenersToCombo + */ + private void addListenersToCombo() { + combo.addListener(SWT.Traverse, new Listener() { + + @Override + public void handleEvent(Event event) { + + switch (event.type) { + case SWT.Traverse: + if (event.detail == SWT.TRAVERSE_RETURN) { + if (setValidatedValue(combo.getText())) { + valueChanged(); + } + } else if (event.detail == SWT.TRAVERSE_ESCAPE) { + removeEventHandlerComposite(); + } + break; + + default: + break; + } + } + }); + + combo.addListener(SWT.MouseDoubleClick, new Listener() { + + @Override + public void handleEvent(Event event) { + + switch (event.type) { + case SWT.MouseDoubleClick: + setValidatedValue(combo.getText()); + valueChanged(); + break; + default: + break; + } + } + }); + } + + private void removeEventPart() { + if (eventPart == null) { + return; + } + Part part = eventComposite.getPart(); + if (!(part instanceof ComponentPart)) { + return; + } + CommandStack commandStack = eventComposite.getPropertiesPage().getCommandStack(); + if (commandStack == null) { + return; + } + ComponentPart componentPart = (ComponentPart) part; + String viewID = componentPart.getOwnerViewPart().getPropertyValue(BuilderConstants.PROPERTY_ID); + String oldEventName = eventPart.getPropertyValue(LayoutSchemaConstants.EVENT_FUNCTION_NAME); + if ((oldEventName != null) && (new ComponentValidator().getUsedEventNameCount(componentPart, oldEventName) == 1)) { + codeWriter.deleteHandlerFunction(oldEventName, viewID); + } + + commandStack.execute(PartUtil.createRemovePartCommand(componentPart, eventPart)); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/event/EventHandlerUtil.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/event/EventHandlerUtil.java new file mode 100644 index 0000000..dfddcc5 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/event/EventHandlerUtil.java @@ -0,0 +1,65 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.event; + +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.ui.views.properties.PropertiesConstant; + + +public class EventHandlerUtil { + + /** + * return default event handler function + * + * @param viewId + * ex)view1 + * @param componentId + * ex)button1 + * @param eventName + * ex) clicked + * @param defaultCode + * ex)%page%_%object%_%event% + * @return ex)view1_button1_onclicked + */ + public static String getDefaultEventHandlerName(String viewId, String componentId, String eventName, String defaultCode) { + if (eventName.contains(",")) { + String[] split = eventName.split(","); + String results = split[0]; + StringBuffer buf = new StringBuffer(); + for (int i = 1; i < split.length; i++) { + // results += BuilderConstants.UNDERSCORE + split[i]; + buf.append(BuilderConstants.UNDERSCORE); + buf.append(split[i]); + } + results = results + buf.toString(); + eventName = results; + } + defaultCode = defaultCode.replace(PropertiesConstant.EVENT_REPLACE_PAGE, viewId); + defaultCode = defaultCode.replace(PropertiesConstant.EVENT_REPLACE_OBJECT, componentId); + defaultCode = defaultCode.replace(PropertiesConstant.EVENT_REPLACE_EVENT, PropertiesConstant.EVENT_PREFIX + eventName); + + return defaultCode; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/events/HandlerCodeManager.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/events/HandlerCodeManager.java new file mode 100644 index 0000000..bb103a0 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/events/HandlerCodeManager.java @@ -0,0 +1,78 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.events; + +import java.util.List; + +import org.tizen.efluibuilder.model.descriptors.EventParamDescriptor; + + +public class HandlerCodeManager { + private IHandlerCodeWriter codeWriter = null; + + public HandlerCodeManager() { + codeWriter = new HandlerCodeWriter(); + } + + /** + * Adds a event handler function + * + * @param part + * @param funcName + * @param pageID + * @param params + */ + public void addHandlerFunction(String funcName, String pageID, List params, String eventInfo) { + if (codeWriter == null) { + return; + } + codeWriter.addHandlerFunction(funcName, pageID, params, eventInfo); + } + + /** + * Modify a event handler function + * + * @param part + * @param oldFuncName + * @param newFuncName + * @param pageID + */ + public void modifyHandlerFunction(String oldFuncName, String newFuncName, String pageID) { + if (codeWriter == null) { + return; + } + codeWriter.modifyHandlerFunction(oldFuncName, newFuncName, pageID); + } + + /** + * Delete a event handler function + * + * @param funcName + * @param pageID + */ + public void deleteHandlerFunction(String funcName, String pageID) { + codeWriter.deleteHandlerFunction(funcName, pageID); + } + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/events/HandlerCodeWriter.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/events/HandlerCodeWriter.java new file mode 100644 index 0000000..d36fd8f --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/events/HandlerCodeWriter.java @@ -0,0 +1,617 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.events; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.ASTVisitor; +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; +import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.ui.CDTUITools; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; +import org.eclipse.ui.texteditor.IDocumentProvider; +import org.eclipse.ui.texteditor.ITextEditor; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.codegenerator.CodeGeneratorException; +import org.tizen.efluibuilder.codegenerator.event.EventCodeGenerator; +import org.tizen.efluibuilder.codegenerator.event.EventCodeGeneratorUtil; +import org.tizen.efluibuilder.codegenerator.event.IEventCodeGenerator; +import org.tizen.efluibuilder.model.descriptors.EventParamDescriptor; +import org.tizen.efluibuilder.storyboard.codegenerator.CodeGeneratorConstants; +import org.tizen.efluibuilder.storyboard.codegenerator.CodeGeneratorUtil; +import org.tizen.efluibuilder.storyboard.codegenerator.Messages; + + +class VisitForEFL extends ASTVisitor { + private List _funcOffsetList = new ArrayList(); + private List _funcLengthList = new ArrayList(); + private List _funcNameList = new ArrayList(); + private List _funcNameLengthList = new ArrayList(); + private List _funcBodyOffsetList = new ArrayList(); + private List _funcBodyLengthList = new ArrayList(); + private List _funcSpecifierOffsetList = new ArrayList(); + + VisitForEFL() { + this.shouldVisitDeclarations = true; + // this.includeInactiveNodes = true; + } + + public int visit(IASTDeclaration declaration) { + if (declaration instanceof IASTFunctionDefinition) { + IASTFunctionDefinition func = (IASTFunctionDefinition) declaration; + IASTFunctionDeclarator func_name_expr = func.getDeclarator(); + IASTStatement func_body_expr = func.getBody(); + IASTDeclSpecifier func_specifier_expr = func.getDeclSpecifier(); + + _funcNameList.add(func_name_expr.getName().toString()); + _funcNameLengthList.add(func_name_expr.getName().toString().length()); + _funcOffsetList.add(func_name_expr.getFileLocation().getNodeOffset()); + _funcLengthList.add(func_name_expr.getFileLocation().getNodeLength()); + _funcBodyOffsetList.add(func_body_expr.getFileLocation().getNodeOffset()); + _funcBodyLengthList.add(func_body_expr.getFileLocation().getNodeLength()); + _funcSpecifierOffsetList.add(func_specifier_expr.getFileLocation().getNodeOffset()); + } + return PROCESS_CONTINUE; + } + + public List getFuncBodyOffsetList() { + return _funcBodyOffsetList; + } + + public List getFuncBodyLengthList() { + return _funcBodyLengthList; + } + + public List getFuncOffsetList() { + return _funcOffsetList; + } + + public List getFuncLengthList() { + return _funcLengthList; + } + + public List getFuncNameList() { + return _funcNameList; + } + + public List getFuncNameLengthList() { + return _funcNameLengthList; + } + + public List getFuncSpecifierOffsetList() { + return _funcSpecifierOffsetList; + } +} + + +public class HandlerCodeWriter implements IHandlerCodeWriter { + static final String PAGENAME = "$(page_name)"; + public static final String FUNCNAME = "%FuncName%"; //$NON-NLS-1$ + public static final String FUNCPARAMS = "%FuncParams%"; //$NON-NLS-1$ + public static final String EVENTINFO = "$(eventInfo)"; //$NON-NLS-1$ + static final String EVENT_HANDLER_FUNCTION = "void " + FUNCNAME + "(" + FUNCPARAMS + ") {\n\t\n}\n\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + private ITextEditor _editor; + private IDocument _document; + + private List _funcNameList = new ArrayList(); + private List _funcNameLengthList = new ArrayList(); + private List _funcOffsetList = new ArrayList(); + private List _funcLengthList = new ArrayList(); + private List _funcBodyOffsetList = new ArrayList(); + private List _funcBodyLengthList = new ArrayList(); + + private int findHandlerFunction(String funcName) { + return _funcNameList.indexOf(funcName); + } + + private int getFuncNameLength(int index) { + return _funcNameLengthList.get(index); + } + + private int getFuncOffset(int index) { + return _funcOffsetList.get(index); + } + + private int getFuncBodyLength(int index) { + return _funcBodyLengthList.get(index); + } + + private int getFuncBodyOffset(int index) { + return _funcBodyOffsetList.get(index); + } + + private int getFuncLength(int index) { + return _funcLengthList.get(index); + } + + private IFile getFile(String id) { + IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); + + if (editorPart == null) { + return null; + } + + IFileEditorInput input = (IFileEditorInput) editorPart.getEditorInput(); + IFile file = input.getFile(); + IProject project = file.getProject(); + IFile eventHandlerFile = EventCodeGeneratorUtil.getEventHandlerFile(project, id); + if (eventHandlerFile.exists()) { + return eventHandlerFile; + } + + IEventCodeGenerator generator = new EventCodeGenerator(project); + try { + generator.addView(id); + } catch (CodeGeneratorException e) { + e.printStackTrace(); + } + + return eventHandlerFile; + } + + private IEditorPart openEditor(final IFile ifile) { + // editor open + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + + try { + IDE.openEditor(page, ifile); + } catch (PartInitException e) { + } + + return page.getActiveEditor(); + } + + private boolean initEditor(String pageID) { + IFile ifile = getFile(pageID); + // IFile ifile = getFile(); + if ((ifile == null) || (!ifile.exists())) { + return false; + } + + IEditorPart part = openEditor(ifile); + if (!(part instanceof ITextEditor)) { + return false; + } + + _editor = (ITextEditor) part; + IDocumentProvider provider = _editor.getDocumentProvider(); + _document = provider.getDocument(_editor.getEditorInput()); + + createFuncInfoUsingAST(part); + + return true; + } + + private void createFuncInfoUsingAST(IEditorPart part) { + VisitForEFL visitor = new VisitForEFL(); + ITranslationUnit tu = (ITranslationUnit) CDTUITools.getEditorInputCElement(part.getEditorInput()); + if (tu != null) { + try { + // IASTTranslationUnit ast = tu.getAST(null, ITranslationUnit.AST_SKIP_ALL_HEADERS | + // ITranslationUnit.AST_SKIP_FUNCTION_BODIES | + // ITranslationUnit.AST_PARSE_INACTIVE_CODE); + IASTTranslationUnit ast = tu.getAST(null, ITranslationUnit.AST_SKIP_ALL_HEADERS | ITranslationUnit.AST_SKIP_FUNCTION_BODIES); + + if (null != ast) { + ast.accept(visitor); + _funcNameList = visitor.getFuncNameList(); + _funcNameLengthList = visitor.getFuncNameLengthList(); + _funcOffsetList = visitor.getFuncOffsetList(); + _funcLengthList = visitor.getFuncLengthList(); + _funcBodyOffsetList = visitor.getFuncBodyOffsetList(); + _funcBodyLengthList = visitor.getFuncBodyLengthList(); + // _funcSpecifierOffsetList = visitor.getFuncSpecifierOffsetList(); + } + } catch (CoreException e) { + e.printStackTrace(); + } + } + } + + public void addConnectionHandlerFunction(String funcName, String pageID, List params, String eventInfo, boolean isPost) { + if (!initEditor(pageID)) { + return; + } + + String handlerCode = _document.get(); + String postFuncName = funcName + CodeGeneratorConstants.WRAPPER_POST; + String currentFuncName = funcName; + if (isPost) { + currentFuncName = postFuncName; + } + + int index = findHandlerFunction(currentFuncName); + if (index != -1) { + _editor.setHighlightRange(handlerCode.indexOf('{', (getFuncOffset(index) + getFuncLength(index))) + 3, 0, true);// move + return; + } + +// setFocusStoryBoardEditor(); + String comments = (eventInfo == null || eventInfo.isEmpty()) ? BuilderConstants.EMPTY + : ("/**".concat(BuilderConstants.NEW_LINE).concat(eventInfo).concat(BuilderConstants.NEW_LINE)) + .replace(BuilderConstants.NEW_LINE, System.getProperty("line.separator").concat(" * ")).concat(System.getProperty("line.separator")) + .concat(" */").concat(System.getProperty("line.separator")); + + String funcParam = ""; //$NON-NLS-1$ + + if (params != null) { + StringBuffer funcParamBuffer = new StringBuffer(); + for (EventParamDescriptor param : params) { + funcParamBuffer.append(param.getName()).append(Messages.CodeGenerator_COMMA); + } + funcParam = funcParamBuffer.substring(0, funcParamBuffer.length() - 2); + } + + handlerCode = handlerCode.concat(comments); + + if (isPost) { + funcParam = CodeGeneratorConstants.WRAPPER_PARAM + funcParam; + handlerCode = handlerCode + CodeGeneratorUtil.getFunctionDefinition(pageID, funcName, CodeGeneratorConstants.TYPE_POST); + } else { + handlerCode = handlerCode + CodeGeneratorUtil.getFunctionDefinition(pageID, funcName, CodeGeneratorConstants.TYPE_PRE); + } + + handlerCode = handlerCode.replace(FUNCNAME, currentFuncName); + handlerCode = handlerCode.replace(FUNCPARAMS, funcParam); + handlerCode = handlerCode.replace(PAGENAME, pageID); + + _document.set(handlerCode); + _editor.setHighlightRange(handlerCode.lastIndexOf('{') + 3, 0, true); + } + + /** + * Adds a event handler function in the java script file. + * + * @param funcName + * @param pageID + * @param params + */ + public void addHandlerFunction(String funcName, String pageID, List params, String eventInfo) { + if (!initEditor(pageID)) { + return; + } + + String comments = eventInfo == null || eventInfo.isEmpty() ? BuilderConstants.EMPTY + : ("/**".concat(BuilderConstants.NEW_LINE).concat(eventInfo).concat(BuilderConstants.NEW_LINE)) + .replace(BuilderConstants.NEW_LINE, System.getProperty("line.separator").concat(" * ")).concat(System.getProperty("line.separator")) + .concat(" */").concat(System.getProperty("line.separator")); + + String handlerCode = _document.get(); + int index = findHandlerFunction(funcName); + // int index = findHandlerFullFunction(fullFuncName); + if (index == -1) { + String funcParam = ""; + if (params != null) { + StringBuffer sb = new StringBuffer(); + for (EventParamDescriptor param : params) { + sb.append(param.getName() + ", "); + } + funcParam = sb.toString(); + funcParam = funcParam.substring(0, funcParam.length() - 2); // remove + } + handlerCode = handlerCode.concat(comments); + handlerCode = handlerCode + EVENT_HANDLER_FUNCTION; + handlerCode = handlerCode.replace(FUNCNAME, funcName); + handlerCode = handlerCode.replace(FUNCPARAMS, funcParam); + handlerCode = handlerCode.replace(PAGENAME, pageID); + + _document.set(handlerCode); + _editor.setHighlightRange(_document.getLength() - 5, 0, true); // move + // cursor + } else { + _editor.setHighlightRange(handlerCode.indexOf('{', (getFuncOffset(index) + getFuncLength(index))) + 3, 0, true);// move + // cursor + // //3 + // = + // {\n\t + } + } + + /** + * Modify a event handler function in the java script file. + * + * @param oldFuncName + * @param newFuncName + * @param pageID + */ + public void modifyHandlerFunction(String oldFuncName, String newFuncName, String pageID) { + if (!initEditor(pageID)) { + return; + } + + int index = findHandlerFunction(oldFuncName); + + if (index == -1) { + } else { + try { + _document.replace(getFuncOffset(index), getFuncNameLength(index), newFuncName); + } catch (BadLocationException e) { + } + String handlerCode = _document.get(); + _editor.setHighlightRange(handlerCode.indexOf('{', (getFuncOffset(index) + getFuncLength(index))) + 3, 0, true);// move + // cursor + // //3 + // = + // {\n\t + } + // Storyboard_START + // Modify the post function + createFuncInfoUsingAST(_editor); + index = findHandlerFunction(oldFuncName + CodeGeneratorConstants.WRAPPER_POST); + if (index == -1) { + } else { + try { + _document.replace(getFuncOffset(index), getFuncNameLength(index), newFuncName + CodeGeneratorConstants.WRAPPER_POST); + } catch (BadLocationException e) { + LoggerFactory.getLogger(HandlerCodeWriter.class).error(e.getMessage()); + } + } + // Storyboard_END + } + + /** + * Delete a event handler function in the java script file. + * + * @param funcName + * @param pageID + */ + public void deleteHandlerFunction(String funcName, String pageID) { + if (!initEditor(pageID)) { + return; + } + + int index = findHandlerFunction(funcName); + + if (index == -1) { + } else { + try { + String handlerCode = _document.get(); + _editor.setHighlightRange(handlerCode.indexOf('{', (getFuncOffset(index) + getFuncLength(index))) + 3, 0, true);// move + // cursor + // //3 + // = + // {\n\t + + commentOutFullFunction(index); + // Storyboard_START + createFuncInfoUsingAST(_editor); + int i = findHandlerFunction(funcName + CodeGeneratorConstants.WRAPPER_POST); + if (i != -1) { + commentOutFullFunction(i); + } + // Storyboard_END + } catch (BadLocationException e) { + } + } + } + + // StoryBoard_START + /** + * Add event handler for the storyboard connection. + * + * @param funcName + * @param pageID + * @param params + * @param targetView + */ + public void addConnectionHandler(String funcName, String pageID, List params, String eventInfo) { + if (!initEditor(pageID)) { + return; + } + setFocusStoryBoardEditor(); + String comments = (eventInfo == null || eventInfo.isEmpty()) ? BuilderConstants.EMPTY + : ("/**".concat(BuilderConstants.NEW_LINE).concat(eventInfo).concat(BuilderConstants.NEW_LINE)) + .replace(BuilderConstants.NEW_LINE, System.getProperty("line.separator").concat(" * ")).concat(System.getProperty("line.separator")) + .concat(" */").concat(System.getProperty("line.separator")); + + String handlerCode = _document.get(); + String funcParam = ""; //$NON-NLS-1$ + + int index = findHandlerFunction(funcName); + if (index == -1) { + if (params != null) { + StringBuffer funcParamBuffer = new StringBuffer(); + for (EventParamDescriptor param : params) { + funcParamBuffer.append(param.getName()).append(Messages.CodeGenerator_COMMA); + } + funcParam = funcParamBuffer.substring(0, funcParamBuffer.length() - 2); + } + handlerCode = handlerCode.concat(comments); + handlerCode = handlerCode + CodeGeneratorUtil.getFunctionDefinition(pageID, funcName, CodeGeneratorConstants.TYPE_PRE); + handlerCode = handlerCode.replace(FUNCNAME, funcName); + handlerCode = handlerCode.replace(FUNCPARAMS, funcParam); + handlerCode = handlerCode.replace(PAGENAME, pageID); + + // Add post_method + String postFuncName = funcName + CodeGeneratorConstants.WRAPPER_POST; + funcParam = CodeGeneratorConstants.WRAPPER_PARAM + funcParam; + index = findHandlerFunction(funcName + CodeGeneratorConstants.WRAPPER_POST); + if (index == -1) { + handlerCode = handlerCode + CodeGeneratorUtil.getFunctionDefinition(pageID, funcName, CodeGeneratorConstants.TYPE_POST); + handlerCode = handlerCode.replace(FUNCNAME, postFuncName); + handlerCode = handlerCode.replace(FUNCPARAMS, funcParam); + handlerCode = handlerCode.replace(PAGENAME, pageID); + } + + _document.set(handlerCode); + _editor.setHighlightRange(handlerCode.lastIndexOf('{') + 3, 0, true); + } else { + // Add wrapper comment + index = findHandlerFunction(funcName); + addWrapperComment(index, pageID, funcName, CodeGeneratorConstants.TYPE_PRE); + createFuncInfoUsingAST(_editor); + index = findHandlerFunction(funcName + CodeGeneratorConstants.WRAPPER_POST); + addWrapperComment(index, pageID, funcName, CodeGeneratorConstants.TYPE_POST); + _editor.setHighlightRange(handlerCode.indexOf('{', (getFuncOffset(index) + getFuncLength(index))) + 3, 0, true); + } + } + + /** + * Comment out the event handler for storyboard + * + * @param funcName + * @param pageID + */ + public void deleteConnectionHandler(String funcName, String pageID) { + if (!initEditor(pageID)) { + return; + } + setFocusStoryBoardEditor(); + + int index = findHandlerFunction(funcName); + + if (index != -1) { + try { + deleteWrapperComment(index); + + // Update post method + createFuncInfoUsingAST(_editor); + String postFuncName = funcName + CodeGeneratorConstants.WRAPPER_POST; + int i = findHandlerFunction(postFuncName); + if (i != -1) + deleteWrapperComment(i); + } catch (BadLocationException e) { + } + String handlerCode = _document.get(); + _editor.setHighlightRange(handlerCode.indexOf('{', (getFuncOffset(index) + getFuncLength(index))) + 3, 0, true); + } + } + + /** + * Modify connection properties + * + * @param funcName + * @param pageID + */ + /* + * public void modifyConnectionHandler(String funcName, String pageID, ConnectionData + * connectionData) { if (!initEditor(pageID)) { return; } setFocusStoryBoardEditor(); + * + * int index = findHandlerFunction(funcName); + * + * if (index != -1) { String handlerCode = _document.get(); String functionBody = + * handlerCode.substring(getFuncOffset(index) + getFuncLength(index), getFuncBodyOffset(index) + + * getFuncBodyLength(index)); int changeIndex = + * functionBody.indexOf(Messages.CodeGenerator_CHANGE_PAGE_METHOD); if (changeIndex != -1) { int + * changeEnd = functionBody.indexOf(Messages.CodeGenerator_CHANGE_END, changeIndex); int + * changeStart = functionBody.lastIndexOf(Messages.CodeGenerator_CHANGE_START, changeIndex) - 1; + * int len = changeEnd - changeStart; String modifiedCode = + * CodeGeneratorUtil.getChangePage(connectionData); try { + * _document.replace(getFuncBodyOffset(index) + changeStart, len, modifiedCode); } catch + * (BadLocationException e) { // TODO Auto-generated catch block e.printStackTrace(); } + * _editor.setHighlightRange(handlerCode.indexOf('{', (getFuncOffset(index) + + * getFuncLength(index))) + 3, 0, true); } } } + */ + + /** + * Set Focus to WYSIWYG editor + * + * @param + */ + private void setFocusStoryBoardEditor() { + // Set focus to WYSIWYG editor + IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); + if (editorPart == null) { + return; + } + IFileEditorInput input = (IFileEditorInput) editorPart.getEditorInput(); + IProject project = input.getFile().getProject(); + IFolder iLayoutFolder = project.getFolder(CodeGeneratorConstants.LAYOUT_FOLDER); + IFile ifile = iLayoutFolder.getFile(CodeGeneratorConstants.LAYOUT_XML); + + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + try { + IDE.openEditor(page, ifile); + } catch (PartInitException e) { + LoggerFactory.getLogger(HandlerCodeWriter.class).error(e.getMessage()); + } + } + + /** + * Delete single line wrapper comment from function + * + * @param index + * @throws BadLocationException + */ + private void deleteWrapperComment(int index) throws BadLocationException { + String handlerCode = _document.get(); + String functionBody = handlerCode.substring(getFuncOffset(index), getFuncBodyOffset(index) + getFuncBodyLength(index)); + int commentStart = functionBody.indexOf(CodeGeneratorConstants.WRAPPER_COMMENT) - 1; + int commentEnd = functionBody.indexOf("\n", commentStart) + 1; + if (commentStart >= 0 && commentEnd >= 0) + _document.replace(getFuncOffset(index) + commentStart, commentEnd - commentStart, ""); + } + + /** + * Comment out the whole function + * + * @param index + * @throws BadLocationException + */ + private void commentOutFullFunction(int index) throws BadLocationException { + int pos = getFuncOffset(index); + while (_document.getChar(pos - 1) != '\n') { + pos--; + } + _document.replace(pos, 0, "//"); + + int count = 1; + for (int i = getFuncOffset(index); i <= getFuncBodyOffset(index) + getFuncBodyLength(index) + (count * 2); i++) { + if (_document.getChar(i - 1) == '\n') { + _document.replace(i, 0, "//"); + count++; + } + } + } + + private void addWrapperComment(int index, String pageID, String funcName, String type) { + String handlerCode = _document.get(); + String fulFunctionBody = handlerCode.substring(getFuncOffset(index), getFuncBodyOffset(index) + getFuncBodyLength(index)); + String functionHeader = handlerCode.substring(getFuncOffset(index), getFuncOffset(index) + getFuncLength(index) + 3); + String functionBody = handlerCode.substring(getFuncOffset(index) + getFuncLength(index) + 3, getFuncBodyOffset(index) + getFuncBodyLength(index)); + functionBody = functionHeader + CodeGeneratorUtil.getWrapperComment(pageID, funcName, type) + functionBody; + handlerCode = handlerCode.replace(fulFunctionBody, functionBody); + _document.set(handlerCode); + } + // StoryBoard_END +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/events/HandlerNameValidator.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/events/HandlerNameValidator.java new file mode 100644 index 0000000..a358351 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/events/HandlerNameValidator.java @@ -0,0 +1,71 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.events; + +import java.util.List; + +import org.eclipse.jface.dialogs.IInputValidator; +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.model.descriptors.EventDescriptor; +import org.tizen.efluibuilder.ui.views.properties.PropertiesConstant; + + +public class HandlerNameValidator implements IInputValidator { + + private List descriptors; + private List events; + + public HandlerNameValidator(List descriptors, List events) { + this.descriptors = descriptors; + this.events = events; + } + + @Override + public String isValid(String newText) { + if (newText.isEmpty()) { + return newText; + } else if (!newText.matches(BuilderConstants.REGULAREXPRESSION)) { + return PropertiesConstant.EVENT_INVALID_MESSAGE_1; + } else if (newText.startsWith(PropertiesConstant.EVENT_PREFIX)) { + return PropertiesConstant.EVENT_INVALID_MESSAGE_2; + } else { + String value = newText.toLowerCase(); + for (EventDescriptor desc : descriptors) { + String eventName = desc.getEventDisplayName().toLowerCase(); + if (eventName.equals(value)) { + return PropertiesConstant.EVENT_INVALID_MESSAGE_3; + } + } + + value = PropertiesConstant.EVENT_PREFIX + value; + for (String name : events) { + if (name.equals(value)) { + return PropertiesConstant.EVENT_INVALID_MESSAGE_4; + } + } + } + return null; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/events/IHandlerCodeWriter.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/events/IHandlerCodeWriter.java new file mode 100644 index 0000000..f3978c8 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/events/IHandlerCodeWriter.java @@ -0,0 +1,47 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.events; + +import java.util.List; + +import org.tizen.efluibuilder.model.descriptors.EventParamDescriptor; + + +public interface IHandlerCodeWriter { + + public void addHandlerFunction(String funcName, String pageID, List params, String eventInfo); + + public void modifyHandlerFunction(String oldFuncName, String newFuncName, String pageID); + + public void deleteHandlerFunction(String funcName, String pageID); + + // StoryBoard_START + public void addConnectionHandler(String funcName, String pageID, List params, String eventInfo); + + public void deleteConnectionHandler(String funcName, String pageID); + + // public void modifyConnectionHandler(String Name, String pageID, ConnectionData + // connectionData); + // StoryBoard_END +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/CheckScaleEditable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/CheckScaleEditable.java new file mode 100644 index 0000000..5c5efca --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/CheckScaleEditable.java @@ -0,0 +1,375 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import java.text.DecimalFormat; +import java.util.List; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Scale; +import org.eclipse.swt.widgets.Text; +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.model.descriptors.PropertyConditionDescriptor; +import org.tizen.efluibuilder.model.descriptors.PropertyDescriptor; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.ui.widgets.TizenScale; +import org.tizen.efluibuilder.utility.PlatformUtil; + + +/** + * This class creates a 'Scale component' and then adds it to the parent {@link Composite}. + */ +public class CheckScaleEditable extends Editable { + + private Button check; + private TizenScale scale; + private Text scaleValue; + private PropertyDescriptor parentDescriptor; + private Listener listener; + private Listener textListener; + private Listener checkListener; + private boolean checkEnabled; + + /** + * Constructor. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param style + * the style of widget to construct + * @param type + * a {@link MethodType} + * @param name + * property name + * @param value + * property value + * @param displayName + * display name + * @param hasFunc + * true if the Method has function button, and false + * otherwise + * @param parentDescriptor + * property descriptor + */ + public CheckScaleEditable(Composite parent, int style, MethodType type, String name, String value, String displayName, boolean hasFunc, + PropertyDescriptor parentDescriptor, boolean checkEnabled) { + super(parent, style, type, name, value, displayName, hasFunc); + this.parentDescriptor = parentDescriptor; + this.checkEnabled = checkEnabled; + } + + @Override + public void dispose() { + if (scale != null && !scale.isDisposed()) { + scale.removeListener(SWT.MouseUp, listener); + scale.removeListener(SWT.Selection, listener); + } + + if (scaleValue != null && !scaleValue.isDisposed()) { + scaleValue.removeListener(SWT.Traverse, textListener); + scaleValue.removeListener(SWT.FocusOut, textListener); + } + + if (check != null && !check.isDisposed()) { + check.removeListener(SWT.Selection, checkListener); + } + + super.dispose(); + } + + /* + * (non-Javadoc) + * + * @see org.tizen.webuibuilder.ui.views.properties.method.Method#refreshValue(java.lang.String, + * java.lang.String) + */ + @Override + public void refreshValue(String name, String value) { + Control control = getControl(); + if (control == null || control.isDisposed()) { + return; + } + + if (value == null) { + value = BuilderConstants.EMPTY; + } + + super.refreshValue(name, value); + + if (value != null && !value.isEmpty()) { + if (value.equals(LayoutSchemaConstants.ALIGN_H_FILL)) { + scale.setSelection(0); + scaleValue.setText(value); + setState(false); + } else { + Double defaultValue = Double.parseDouble(value); + scale.setSelection((int) (defaultValue * 100)); + scaleValue.setText(value); + setState(true); + } + } + } + + /* + * (non-Javadoc) + * + * @see org.tizen.webuibuilder.ui.views.properties.method.Method#createControl() + */ + @Override + protected Control createControl() { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new FormLayout()); + + /** check */ + check = new Button(composite, SWT.CHECK); + FormData data = new FormData(); + data = new FormData(20, 15); + data.left = new FormAttachment(0, 0); + data.top = new FormAttachment(0, 5); + check.setLayoutData(data); + checkListener = createCheckListener(); + check.addListener(SWT.Selection, checkListener); + + /** scale */ + scale = new TizenScale(composite, SWT.HORIZONTAL); + data = new FormData(); + data.left = new FormAttachment(check, 5); + data.top = new FormAttachment(0, 0); + data.height = 24; + if (PlatformUtil.getOS().equals(PlatformUtil.OS_LINUX)) { + data.right = new FormAttachment(100, -45); + } else { + data.right = new FormAttachment(100, -40); + } + scale.setLayoutData(data); + listener = createScaleListener(); + scale.addListener(SWT.MouseUp, listener); + + scale.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent arg0) { + String value = String.format("%d", scale.getSelection()); + String convertedValue = convertIntToDouble(value); + scaleValue.setText(convertedValue); + modifyValue(convertedValue); + } + }); + + /** scale value */ + scaleValue = new Text(composite, SWT.CENTER | SWT.BORDER); + scaleValue.setTextLimit(4); + data = new FormData(); + data.left = new FormAttachment(scale, 5); + data.right = new FormAttachment(100, 0); + data.top = new FormAttachment(0); + if (PlatformUtil.getOS().equals(PlatformUtil.OS_LINUX)) { + data.height = 24; + } + + scaleValue.setLayoutData(data); + + textListener = createScaleTextListener(); + scaleValue.addListener(SWT.Traverse, textListener); + scaleValue.addListener(SWT.FocusOut, textListener); + + if (getValue().equals(LayoutSchemaConstants.ALIGN_H_FILL)) { + setState(false); + } else { + setState(true); + } + + return composite; + } + + private Listener createScaleTextListener() { + Listener textListener = new Listener() { + + @Override + public void handleEvent(Event event) { + Text text = (Text) event.widget; + + switch (event.type) { + case SWT.Traverse: + if (event.detail == SWT.TRAVERSE_RETURN) { + setValue(text.getText()); + refreshValue(getMethodName(), getValue()); + } else if (event.detail == SWT.TRAVERSE_ESCAPE) { + modifyValue(BuilderConstants.EMPTY); + refreshValue(getMethodName(), getValue()); + } + break; + case SWT.FocusOut: + setValue(text.getText()); + break; + + default: + break; + } + } + }; + + return textListener; + } + + /* + * (non-Javadoc) + * + * @see org.tizen.webuibuilder.ui.views.properties.method.Method#setConditions(java.util.List) + */ + @Override + public void setConditions(List conditions) { + if (conditions.size() > 0) { + if (conditions.get(0).getValue() != null) { + scale.setMinimum(Integer.parseInt(conditions.get(0).getValue()) * 100); + scale.setMaximum(Integer.parseInt(conditions.get(1).getValue()) * 100); + scale.setIncrement(1); + + String value = getValue(); + if (value == null || value.isEmpty()) { + if (parentDescriptor.getDefaultValue().equals(LayoutSchemaConstants.ALIGN_H_FILL)) { + scale.setSelection(0); + scaleValue.setText(value); + } else { + Double defaultValue = Double.parseDouble(parentDescriptor.getDefaultValue()); + scale.setSelection((int) (defaultValue * 100)); + scaleValue.setText(parentDescriptor.getDefaultValue()); + } + } else if (value.equals(LayoutSchemaConstants.ALIGN_H_FILL)) { + scale.setSelection(0); + scaleValue.setText(value); + } else { + Double defaultValue = Double.parseDouble(value); + scale.setSelection((int) (defaultValue * 100)); + scaleValue.setText(value); + } + } + } + } + + /** + * This method creates a {@link Listener} for the mouse event at the {@link Scale}. + * + * @param target + * own class ({@link Editable}) + * @return a {@link Listener} + */ + private Listener createScaleListener() { + Listener listener = new Listener() { + + @Override + public void handleEvent(Event event) { + String value = String.format("%d", scale.getSelection()); + String convertedValue = null; + + switch (event.type) { + case SWT.MouseUp: + convertedValue = convertIntToDouble(value); + scaleValue.setText(convertedValue); + setValue(convertedValue); + break; + default: + break; + } + + } + }; + + return listener; + } + + private Listener createCheckListener() { + Listener listener = new Listener() { + + @Override + public void handleEvent(Event event) { + if (check == null || check.isDisposed()) { + return; + } + String value = null; + switch (event.type) { + case SWT.Selection: + if (check.getSelection()) { + value = LayoutSchemaConstants.ALIGN_H_FILL; + setValue(value); + refreshValue(getMethodName(), value); + } else { + value = "0.5"; + setValue(value); + refreshValue(getMethodName(), value); + } + break; + default: + break; + } + + } + }; + + return listener; + } + + private void setState(Boolean enabled) { + check.setSelection(!enabled); + scale.setEnabled(enabled); + scaleValue.setEnabled(enabled); + + check.setVisible(checkEnabled); + } + + /* + * (non-Javadoc) + * + * @see org.tizen.webuibuilder.ui.views.properties.method.Method#getControlLayoutData() + */ + @Override + protected FormData getControlLayoutData() { + FormData data = super.getControlLayoutData(); + + data.right = new FormAttachment(80, 0); + return data; + } + + private String convertIntToDouble(String value) { + DecimalFormat format = new DecimalFormat("0.##"); + return format.format(Double.parseDouble(value) / 100); + } + + @Override + public void setValue(String value) { + if (getValue().equals(value)) { + return; + } + super.setValue(value); + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ColorData.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ColorData.java new file mode 100644 index 0000000..576345f --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ColorData.java @@ -0,0 +1,87 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import org.eclipse.swt.graphics.RGB; + + +/** + * This class creates a color data model that contains Alpha value and {@link RGB} value. + */ +public class ColorData { + + private int alphaValue; + private RGB rgbValue; + + /** + * Construct + * + * @param alpha + * alpha value of the {@link ColorData} + * @param rgb + * a {@link RGB} + */ + public ColorData(int alpha, RGB rgb) { + alphaValue = alpha; + rgbValue = rgb; + } + + /** + * This method returns the alpha value of the {@link ColorData}. + * + * @return alpha value of the {@link ColorData} + */ + public int getAlphaValue() { + return alphaValue; + } + + /** + * This method returns the {@link RGB} of the {@link ColorData}. + * + * @return a {@link RGB} + */ + public RGB getRGBValue() { + return rgbValue; + } + + /** + * This method set alpha value of the {@link ColorData}. + * + * @param value + * new alpha value of the {@link ColorData} + */ + public void setAlphaValue(int value) { + alphaValue = value; + } + + /** + * This method set {@link RGB} value of the {@link ColorData}. + * + * @param value + * new {@link RGB} + */ + public void setRGBValue(RGB value) { + rgbValue = value; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ColorListEditable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ColorListEditable.java new file mode 100644 index 0000000..68de02b --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ColorListEditable.java @@ -0,0 +1,341 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.MouseTrackAdapter; +import org.eclipse.swt.events.MouseTrackListener; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.tizen.common.util.SWTUtil; +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.model.descriptors.ConstantDescriptor; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.resources.ColorResources; +import org.tizen.efluibuilder.ui.resources.ImageResources; +import org.tizen.efluibuilder.ui.widgets.UIBLabel; + + +public class ColorListEditable extends ColorPickerEditable { + private static final String KEY_COLOR_NAME = "color"; + private static final String KEY_IMAGE = "image"; + + private final RGB EMPTYCOLOR = getDisplay().getSystemColor(SWT.COLOR_WHITE).getRGB(); + + private List items; + private Map colorCompositeMap = new HashMap(); + private Map colorLabelMap = new HashMap(); + private Map colorButtonMap = new HashMap(); + private Map resetButtonMap = new HashMap(); + private Map currentColorMap = new HashMap(); + + /** + * Constructor. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param style + * the style of widget to construct + * @param type + * a {@link MethodType} + * @param name + * property name + * @param value + * property value + * @param displayName + * display name + * @param hasFunc + * true if the Method has function button, and false + * otherwise + * @see Editable + */ + public ColorListEditable(Composite parent, int style, MethodType type, String name, String value, String displayName, boolean hasFunc, + List items) { + super(parent, style, type, name, value, displayName, hasFunc); + this.items = items; + Composite control = (Composite) getControl(); + for (int i = 0; i < items.size(); i++) { + String colorName = items.get(i).getValue(); + colorCompositeMap.put(colorName, createColorComposite(control, colorName)); + } + addListener(); + } + + @Override + public void refreshValue(String name, String value) { + if (name.equals(LayoutSchemaConstants.COLORS)) { + currentColorMap = PartUtil.getPartColors(value); + if (currentColorMap == null) { + currentColorMap = new HashMap(); + } + for (int i = 0; i < items.size(); i++) { + String colorName = items.get(i).getValue(); + if (currentColorMap.get(colorName) != null) { + resetButtonMap.get(colorName).setVisible(true); + } else { + resetButtonMap.get(colorName).setVisible(false); + } + } + } else if (name.equals(LayoutSchemaConstants.STYLE)) { + for (int i = 0; i < items.size(); i++) { + String styleList = items.get(i).getRequired(); + CLabel colorLabel = colorLabelMap.get(items.get(i).getValue()); + if (styleList != null && !styleList.matches("(.*;|)" + value + "(;.*|)")) { + colorLabel.setForeground(ColorResources.PROPERTIES_ATTR_LABEL_DIM); + } else { + colorLabel.setForeground(ColorResources.PROPERTIES_ATTR_LABEL); + } + } + } + Iterator iterButton = colorButtonMap.values().iterator(); + while (iterButton.hasNext()) { + iterButton.next().redraw(); + } + } + + @Override + protected Control createControl() { + Composite control = new Composite(this, SWT.NONE); + FillLayout layout = new FillLayout(); + layout.spacing = 10; + layout.type = SWT.VERTICAL; + control.setLayout(layout); + return control; + } + + private Composite createColorComposite(Composite control, String colorName) { + Composite colorComposite = new Composite(control, SWT.NONE); + colorComposite.setLayout(new FormLayout()); + CLabel label = new UIBLabel(colorComposite, SWT.NONE); + label.setText(colorName); + FormData formData = new FormData(); + formData.left = new FormAttachment(0, 0); + formData.right = new FormAttachment(55, 0); + formData.top = new FormAttachment(0, 0); + formData.bottom = new FormAttachment(100, 0); + label.setLayoutData(formData); + colorLabelMap.put(colorName, label); + + Canvas btnColor = new Canvas(colorComposite, SWT.NONE); + formData = new FormData(); + formData.left = new FormAttachment(label, 5); + formData.width = 25; + formData.height = 25; + formData.bottom = new FormAttachment(100, 0); + btnColor.setLayoutData(formData); + btnColor.setData(colorName); + colorButtonMap.put(colorName, btnColor); + + Canvas btnResetButton = new Canvas(colorComposite, SWT.NONE); + formData = new FormData(); + formData.left = new FormAttachment(btnColor, 10); + formData.bottom = new FormAttachment(0, 24); + formData.width = 24; + formData.height = 24; + btnResetButton.setLayoutData(formData); + btnResetButton.setData(KEY_COLOR_NAME, colorName); + btnResetButton.setData(KEY_IMAGE, ImageResources.getImage(ImageResources.METHOD_COLOR_RESET_NOR)); + resetButtonMap.put(colorName, btnResetButton); + + return colorComposite; + } + + @Override + protected FormData getControlLayoutData() { + FormData data = new FormData(); + data.left = new FormAttachment(0, 16); + data.right = new FormAttachment(100, 0); + return data; + } + + @Override + public void setEnabled(boolean enabled) { + getControl().setEnabled(enabled); + } + + @Override + public void setValue(String value) { + setValue(value, true); + canSetValue = false; + } + + protected void setCurrentRGB(String hex) { + if (!hex.startsWith(BuilderConstants.SHARP)) { + hex = BuilderConstants.SHARP + hex; + } + currentRGB = SWTUtil.convertHexadecimalToRGB(hex); + currentColorMap.put((String) colorButton.getData(), hex); + isEmptyColor = false; + } + + @Override + protected String getColorValue(String colorName) { + return PartUtil.convertColorMapToPropertyValue(currentColorMap); + } + + private void resetColor(String colorName) { + currentColorMap.remove(colorName); + setValue(getColorValue(null)); + } + + @Override + public void dispose() { + removesListeners(); + closeColorDialog(); + super.dispose(); + } + + @Override + public void setLabelTooltipText(String tooltip) { + // Do nothing + } + + /************************************************ + * Event Listener + **********************************************/ + private void addListener() { + for (int i = 0; i < items.size(); i++) { + String colorName = items.get(i).getValue(); + Canvas btnColor = colorButtonMap.get(colorName); + btnColor.addPaintListener(btnColorPaintListener); + btnColor.addMouseListener(btnColorMouseListener); + Canvas btnReset = resetButtonMap.get(colorName); + btnReset.addPaintListener(btnResetPaintListener); + btnReset.addMouseListener(btnResetMouseListener); + btnReset.addMouseTrackListener(btnResetMouseTrackListener); + } + } + + private void removesListeners() { + for (int i = 0; i < items.size(); i++) { + String colorName = items.get(i).getValue(); + Canvas btnColor = colorButtonMap.get(colorName); + if (btnColor != null && !btnColor.isDisposed()) { + btnColor.removePaintListener(btnColorPaintListener); + btnColor.removeMouseListener(btnColorMouseListener); + } + Canvas btnReset = resetButtonMap.get(colorName); + if (btnReset != null && !btnReset.isDisposed()) { + btnReset.removePaintListener(btnResetPaintListener); + btnReset.removeMouseListener(btnResetMouseListener); + btnReset.removeMouseTrackListener(btnResetMouseTrackListener); + } + } + } + + private MouseListener btnColorMouseListener = new MouseAdapter() { + @Override + public void mouseUp(MouseEvent e) { + if (colorDialog != null && !colorDialog.isDisposed()) { + closeColorDialog(); + } + colorButton = (Canvas) e.widget; + String color = currentColorMap.get(colorButton.getData()); + currentRGB = (color == null) ? EMPTYCOLOR : SWTUtil.convertHexadecimalToRGB(color); + createColorDialog(); + openColorDialog(); + } + }; + + private PaintListener btnColorPaintListener = new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + Canvas colorButton = (Canvas) (e.widget); + String colorName = (String) colorButton.getData(); + RGB currentRGB = (currentColorMap.get(colorName) == null) ? EMPTYCOLOR : SWTUtil.convertHexadecimalToRGB(currentColorMap.get(colorName)); + + Rectangle rect = colorButton.getClientArea(); + e.gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_GRAY)); + e.gc.drawRectangle(rect.x, rect.y, rect.width - 1, rect.height - 1); + Color color = new Color(e.display, currentRGB.red, currentRGB.green, currentRGB.blue); + e.gc.setBackground(color); + e.gc.fillRectangle(rect.x + 1, rect.y + 1, rect.width - 2, rect.height - 2); + color.dispose(); + e.gc.dispose(); + } + }; + + private PaintListener btnResetPaintListener = new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + Image image = (Image) (e.widget).getData(KEY_IMAGE); + e.gc.drawImage(image, 0, 0); + } + }; + + private MouseListener btnResetMouseListener = new MouseAdapter() { + @Override + public void mouseUp(MouseEvent e) { + Canvas btnReset = (Canvas) e.widget; + btnReset.setData(KEY_IMAGE, ImageResources.getImage(ImageResources.METHOD_COLOR_RESET_NOR)); + String colorName = (String) btnReset.getData(KEY_COLOR_NAME); + resetColor(colorName); + } + + @Override + public void mouseDown(MouseEvent e) { + Canvas btnReset = (Canvas) e.widget; + btnReset.setData(KEY_IMAGE, ImageResources.getImage(ImageResources.METHOD_COLOR_RESET_SEL)); + btnReset.redraw(); + } + }; + + private MouseTrackListener btnResetMouseTrackListener = new MouseTrackAdapter() { + @Override + public void mouseEnter(MouseEvent e) { + Canvas btnReset = (Canvas) e.widget; + btnReset.setData(KEY_IMAGE, ImageResources.getImage(ImageResources.METHOD_COLOR_RESET_MV)); + btnReset.redraw(); + } + + @Override + public void mouseExit(MouseEvent e) { + Canvas btnReset = (Canvas) e.widget; + btnReset.setData(KEY_IMAGE, ImageResources.getImage(ImageResources.METHOD_COLOR_RESET_NOR)); + btnReset.redraw(); + } + }; + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ColorPickerEditable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ColorPickerEditable.java new file mode 100644 index 0000000..146cf4f --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ColorPickerEditable.java @@ -0,0 +1,385 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.browser.Browser; +import org.eclipse.swt.browser.BrowserFunction; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Canvas; +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.Listener; +import org.eclipse.swt.widgets.Shell; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.common.ui.dialog.ColorPickerDialog; +import org.tizen.common.util.BrowserWrapper; +import org.tizen.common.util.SWTUtil; +import org.tizen.efluibuilder.BuilderConstants; + + +public class ColorPickerEditable extends Editable { + + private Logger logger = LoggerFactory.getLogger(ColorPickerEditable.class); + + // Control + protected Canvas colorButton; + protected RGB currentRGB; + + // ColorPickerDialog + protected static int COLOR_DIALOG_WIDTH = 360; + protected static int COLOR_DIALOG_HEIGHT = 180; + protected static int COLOR_DIALOG_X_MARGIN = 30; + protected static int COLOR_DIALOG_Y_MARGIN = 30; + protected static String COLOR_PREFIX_FOR_URL = "?color="; //$NON-NLS-1$ + + protected Shell colorDialog; + protected BrowserWrapper browserWrapper; + protected boolean canSetValue = false; + protected boolean isEmptyColor = true; + + // Listeners + private Listener dialogListener = new Listener() { + + @Override + public void handleEvent(Event event) { + if (colorDialog == null || colorDialog.isDisposed()) { + return; + } + switch (event.type) { + case SWT.Activate: + logger.debug("ColorPickerDialog activated"); + break; + case SWT.Deactivate: + logger.debug("ColorPickerDialog deactivated"); + if (canSetValue) { + String color = SWTUtil.convertRGBToHexadecimal(currentRGB); + setValue(getColorValue(color)); + } + closeColorDialog(); + break; + case SWT.MouseUp: + canSetValue = true; + break; + default: + break; + } + + } + }; + private PaintListener paintListener = new PaintListener() { + + @Override + public void paintControl(PaintEvent e) { + if (currentRGB == null) { + resetCurrentRGB(); + } + e.gc.setBackground(new Color(e.display, currentRGB.red, currentRGB.green, currentRGB.blue)); + // e.gc.setAlpha(userAlpha); + Rectangle rect = colorButton.getClientArea(); + + e.gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_GRAY)); + e.gc.drawRectangle(rect.x, rect.y, rect.width - 1, rect.height - 1); + e.gc.setBackground(new Color(e.display, currentRGB.red, currentRGB.green, currentRGB.blue)); + e.gc.fillRectangle(rect.x + 1, rect.y + 1, rect.width - 2, rect.height - 2); + + e.gc.dispose(); + } + }; + + private MouseListener mouseListener = new MouseListener() { + + @Override + public void mouseUp(MouseEvent e) { + if (colorDialog != null && !colorDialog.isDisposed()) { + closeColorDialog(); + } + createColorDialog(); + openColorDialog(); + } + + @Override + public void mouseDown(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseDoubleClick(MouseEvent e) { + // TODO Auto-generated method stub + + } + }; + + private Listener displayListener = new Listener() { + + @Override + public void handleEvent(Event arg0) { + switch (arg0.type) { + case SWT.MouseDown: + if (colorDialog != null && !colorDialog.isDisposed()) { + Rectangle rec = colorDialog.getBounds(); + Point pt = colorDialog.toControl(Display.getDefault().getCursorLocation()); + + if (pt.x < 0 || pt.x > rec.width || pt.y < 0 || pt.y > rec.height) { + if (canSetValue) { + String color = SWTUtil.convertRGBToHexadecimal(currentRGB); + setValue(getColorValue(color)); + } + closeColorDialog(); + } + } + break; + } + } + }; + + private class ColorFunction extends BrowserFunction { + ColorFunction(Browser browser) { + super(browser, ColorPickerDialog.GET_COLOR_FUNCTION); + } + + public Object function(Object[] arguments) { + if (arguments.length > 0 && (arguments[0] instanceof String)) { + String hex = (String) arguments[0]; + StringBuilder builder = new StringBuilder(BuilderConstants.SHARP); + builder.append(hex); + modifyValue(builder.toString()); + setCurrentRGB(hex); + colorButton.redraw(); + } + return null; + } + + } + + /** + * Construct + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param style + * the style of widget to construct + * @param type + * a {@link MethodType} + * @param name + * property name + * @param value + * property value + * @param displayName + * display name + * @param hasFunc + * true if the Method has function button, and false + * otherwise + */ + public ColorPickerEditable(Composite parent, int style, MethodType type, String name, String value, String displayName, boolean hasFunc) { + super(parent, style, type, name, value, displayName, hasFunc); + Color defaultColor = getDisplay().getSystemColor(SWT.COLOR_WHITE); + setCurrentRGB(defaultColor); + isEmptyColor = true; + addListeners(); + } + + @Override + protected Control createControl() { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new FormLayout()); + colorButton = new Canvas(composite, SWT.NONE); + FormData data = new FormData(25, 25); + // data.left = new FormAttachment(0, 0); + // data.top = new FormAttachment(10, 0); + // data.bottom = new FormAttachment(90, 0); + colorButton.setLayoutData(data); + resetCurrentRGB(); + + return composite; + } + + @Override + public void refreshValue(String name, String value) { + super.refreshValue(name, value); + if (colorButton != null) { + if (value == null || value.isEmpty()) { + resetCurrentRGB(); + } else { + setCurrentRGB(value); + } + + colorButton.redraw(); + } + } + + @Override + public void setValue(String value) { + if (value == null || value.isEmpty()) { + resetCurrentRGB(); + super.setValue(BuilderConstants.EMPTY); + } else { + setCurrentRGB(value); + super.setValue(value); + } + canSetValue = false; + } + + private void addListeners() { + if (colorButton != null) { + colorButton.addPaintListener(paintListener); + colorButton.addMouseListener(mouseListener); + } + + } + + private void removesListeners() { + if (colorButton != null && !colorButton.isDisposed()) { + colorButton.removePaintListener(paintListener); + colorButton.removeMouseListener(mouseListener); + } + + } + + @Override + public void dispose() { + removesListeners(); + closeColorDialog(); + super.dispose(); + } + + protected void resetCurrentRGB() { + Color defaultColor = getDisplay().getSystemColor(SWT.COLOR_WHITE); + setCurrentRGB(defaultColor); + isEmptyColor = true; + } + + protected void setCurrentRGB(String hex) { + if (!hex.startsWith(BuilderConstants.SHARP)) { + hex = BuilderConstants.SHARP + hex; + } + currentRGB = SWTUtil.convertHexadecimalToRGB(hex); + isEmptyColor = false; + } + + private void setCurrentRGB(Color color) { + currentRGB = new RGB(color.getRed(), color.getGreen(), color.getBlue()); + isEmptyColor = false; + } + + protected Canvas getColorButton() { + return colorButton; + } + + protected RGB getCurrentRGB() { + return currentRGB; + } + + protected void createColorDialog() { + colorDialog = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP); + colorDialog.setLayout(new FillLayout()); + // shell.setLocation(100, 100); + Point ll = colorButton.getLocation(); + Point ls = colorButton.getSize(); + Rectangle sRect = getShell().getBounds(); + + Point location = colorButton.toDisplay(ll.x, ll.y + ls.y); + if (sRect.x + sRect.width - location.x < COLOR_DIALOG_WIDTH) { + location.x = sRect.x + sRect.width - COLOR_DIALOG_WIDTH - COLOR_DIALOG_X_MARGIN; + } + + if (sRect.y + sRect.height - location.y < COLOR_DIALOG_HEIGHT) { + location.y = location.y - COLOR_DIALOG_HEIGHT - COLOR_DIALOG_Y_MARGIN; + } + + colorDialog.setLocation(location); + colorDialog.setSize(COLOR_DIALOG_WIDTH, COLOR_DIALOG_HEIGHT); + browserWrapper = new BrowserWrapper(ColorPickerDialog.createBrowser(colorDialog)); + + StringBuilder urlBuilder = new StringBuilder(); + urlBuilder.append(ColorPickerDialog.getColorPickerURL()); + String color = SWTUtil.convertRGBToHexadecimal(currentRGB); + + urlBuilder.append(COLOR_PREFIX_FOR_URL + color); + final String url = urlBuilder.toString(); + + // reset browser + browserWrapper.setText(BuilderConstants.EMPTY); + browserWrapper.setUrl(url); + + new ColorFunction(browserWrapper.getBrowser()); + + colorDialog.addListener(SWT.Activate, dialogListener); + colorDialog.addListener(SWT.Deactivate, dialogListener); + browserWrapper.getBrowser().addListener(SWT.MouseUp, dialogListener); + + Display.getDefault().addFilter(SWT.MouseDown, displayListener); + } + + protected void closeColorDialog() { + if (colorDialog == null || colorDialog.isDisposed()) { + return; + } else { + colorDialog.removeListener(SWT.Activate, dialogListener); + colorDialog.removeListener(SWT.Deactivate, dialogListener); + browserWrapper.getBrowser().removeListener(SWT.MouseUp, dialogListener); + + Display.getDefault().removeFilter(SWT.MouseDown, displayListener); + + browserWrapper.dispose(); + colorDialog.close(); + canSetValue = false; + } + } + + protected void openColorDialog() { + if (colorDialog == null || colorDialog.isDisposed()) { + return; + } else { + colorDialog.open(); + } + } + + @Override + public void setLabelTooltipText(String tooltip) { + if (checkControl(getLabel())) { + getLabel().setToolTipText(tooltip); + } else { + colorButton.setToolTipText(tooltip); + } + } + + protected String getColorValue(String color) { + return color; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ComboEditable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ComboEditable.java new file mode 100644 index 0000000..43eaeae --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ComboEditable.java @@ -0,0 +1,207 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.tizen.common.util.Assert; +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.model.descriptors.ConstantDescriptor; +import org.tizen.efluibuilder.model.descriptors.TypeDescriptor; + + +/** + * A ComboMethod for ENUM type in the {@link TypeDescriptor.Types} + */ +public class ComboEditable extends Editable { + + private List items = null; + private SelectionAdapter comboListener = new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Combo combo = (Combo) getControl(); + int index = combo.getSelectionIndex(); + ConstantDescriptor descriptor = items.get(index); + /* + * This comments to solve the problem that if the value is empty string for + * efl.icon@standardicon, display name that is a value. + * + * It means display name should not be a value. + */ + + // if (!descriptor.getValue().isEmpty()) { + setValue(descriptor.getValue()); + // } else { + // setValue(descriptor.getDisplayName()); + // } + + } + }; + + /** + * Constructor. + * + * @see Editable + */ + public ComboEditable(Composite parent, int style, MethodType type, String name, String value, String displayName, boolean hasFunc) { + super(parent, style, type, name, value, displayName, hasFunc); + } + + @Override + protected Control createControl() { + Combo combo = new Combo(this, SWT.READ_ONLY | SWT.DROP_DOWN); + return combo; + } + + @Override + public void dispose() { + Combo combo = (Combo) getControl(); + if (combo != null && !combo.isDisposed()) { + combo.removeSelectionListener(comboListener); + } + + super.dispose(); + } + + /** + * Sets items for combo. + * + * @param items + * list of {@link ConstantDescriptor} + */ + public void setItems(List items) { + if (getControl().isDisposed()) { + logger.error("Control is disposed"); + return; + } + + this.items = items; + List texts = new ArrayList(); + for (ConstantDescriptor item : items) { + texts.add(item.getDisplayName()); + } + String[] names = texts.toArray(new String[0]); + + Combo combo = (Combo) getControl(); + combo.setItems(names); + if (names.length == 0) { + combo.setEnabled(false); + } + // selection + String value = getValue(); + if (value.equals(BuilderConstants.EMPTY)) { + combo.select(0); + } else { + int index = getIndex(value); + combo.select(index); + } + combo.addSelectionListener(comboListener); + } + + /** + * Gets index by value + * + * @param value + * @return index of value. + */ + public int getIndex(String value) { + List items = getComboItems(); + Assert.notNull(items); + for (int i = 0; i < items.size(); i++) { + ConstantDescriptor descriptor = items.get(i); + if (value.equals(descriptor.getValue())) { + return i; + } + } + return -1; + } + + protected List getComboItems() { + return items; + } + + protected FormData getControlLayoutData() { + FormData data = super.getControlLayoutData(); + data.bottom = new FormAttachment(100, 0); + data.height = 25; + return data; + } + + @Override + public void refreshValue(String name, String value) { + Combo combo = (Combo) getControl(); + int index = -1; + for (int i = 0; i < items.size(); i++) { + if (items.get(i).getValue().equals(value)) { + index = i; + break; + } + } + if (index != -1) { + combo.select(index); + } + super.refreshValue(name, value); + } + + public void resetItems(List items) { + if (getControl().isDisposed()) { + logger.error("Control is disposed"); + return; + } + + this.items = items; + List texts = new ArrayList(); + for (ConstantDescriptor item : items) { + texts.add(item.getDisplayName()); + } + String[] names = texts.toArray(new String[0]); + + Combo combo = (Combo) getControl(); + combo.removeAll(); + if (names.length == 0) { + combo.setEnabled(false); + return; + } + combo.setEnabled(true); + combo.setItems(names); + // selection + String value = getValue(); + if (value.equals(BuilderConstants.EMPTY)) { + combo.select(0); + } else { + int index = getIndex(value); + combo.select(index); + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/DoubleEditable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/DoubleEditable.java new file mode 100644 index 0000000..2951113 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/DoubleEditable.java @@ -0,0 +1,58 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import org.eclipse.swt.widgets.Composite; + + +/** + * A IntegerMethod for INTEGER type property. + */ +public class DoubleEditable extends TextEditable { + + /** + * Constructor. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param style + * the style of widget to construct + * @param type + * a {@link MethodType} + * @param name + * property name + * @param value + * property value + * @param displayName + * display name + * @param hasFunc + * true if the Method has function button, and false + * otherwise + * @see Editable + */ + public DoubleEditable(Composite parent, int style, MethodType type, String name, String value, String displayName, boolean hasFunc) { + + super(parent, style, type, name, value, displayName, hasFunc); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/Editable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/Editable.java new file mode 100644 index 0000000..440b5da --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/Editable.java @@ -0,0 +1,737 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import java.util.ArrayList; +import java.util.List; +import java.util.Timer; +import java.util.TimerTask; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.ToolTip; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.model.descriptors.PropertyConditionDescriptor; +import org.tizen.efluibuilder.ui.resources.ImageResources; +import org.tizen.efluibuilder.ui.views.properties.PropertiesConstant; + + +/** + * Method used on {@link PropertiesTabItem}. + */ +public abstract class Editable extends Composite { + protected Logger logger = LoggerFactory.getLogger(Editable.class); + + public enum MethodType { + ATTRIBUTE, EVENT_HANDLER, STYLE, ACTION, ANIMATION + } + + private MethodType type; + private String name; + private String value; + private String displayName; + private String defaultValue; + + private Label funcButton; + private MenuItem menuItem; + private MenuItem menuItemCreateFrame; + private boolean enableReset = false; + private boolean enableControl = true; + private CLabel label; + private Control control; + + private ToolTip tooltip; + private List conditions = new ArrayList(); + + private IValueChangeListener listener; + + private boolean first = true; + + /** + * Constructs a new instance of this class given its parent and style value. And MethodType, + * property name, property value, diplay name, has function button value. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param style + * the style of widget to construct + * @param type + * a {@link MethodType} + * @param name + * property name + * @param value + * property value + * @param displayName + * display name + * @param hasFunc + * true if the Method has function button, and false + * otherwise + */ + public Editable(Composite parent, int style, MethodType type, String name, String value, String displayName, boolean hasFunc) { + super(parent, style); + + setFields(type, name, value, displayName); + init(hasFunc); + } + + private void setFields(MethodType type, String name, String value, String displayName) { + if (value == null) { + value = BuilderConstants.EMPTY; + } + this.type = type; + this.name = name; + this.value = value; + this.displayName = displayName; + } + + @Override + public void dispose() { + if (tooltip != null) { + tooltip.dispose(); + tooltip = null; + } + super.dispose(); + } + + private void init(boolean hasFunc) { + setMethodLayout(); + + if (hasFunc) { + funcButton = createFuncButton(); + } + + label = createLabel(); + control = createControl(); + + if (checkControl(funcButton)) { + funcButton.setLayoutData(getFuncLayoutData()); + } + + if (checkControl(control)) { + control.setLayoutData(getControlLayoutData()); + } + + if (checkControl(label)) { + label.setLayoutData(getLabelLayoutData()); + } + + } + + private Label createFuncButton() { + final Label button = new Label(this, SWT.NONE); + Image image = ImageResources.getImage(ImageResources.METHOD_RESET); + button.setImage(image); + button.setToolTipText(getMenuTooltip()); + + // TODO : read model. + button.setEnabled(false); + + final Menu menu = new Menu(button.getShell()); + + menuItem = createMenuItems(menu); + if (getType() == MethodType.STYLE) { + menuItemCreateFrame = createMenuItem_CreateFrame(menu); + // menuItemCreateFrame.setEnabled(false); + } + + button.addMouseListener(new MouseListener() { + + @Override + public void mouseUp(MouseEvent e) { + Rectangle rect = button.getBounds(); + Point menuLocation = button.toDisplay(rect.x, rect.height); + + menu.setLocation(menuLocation); + menu.setVisible(true); + + } + + @Override + public void mouseDown(MouseEvent e) { + + } + + @Override + public void mouseDoubleClick(MouseEvent e) { + + } + }); + + return button; + } + + /** + * Gets tool tip message of function button. + * + * @return tool tip message. Default "Reset default value" + */ + protected String getMenuTooltip() { + return PropertiesConstant.PROPERTY_RESET_TOOLTIP; + } + + /** + * Creates menu item. + * + * @param menu + * a {@link Menu} which will be the parent of the new instance (cannot be null) + * @return a {@link MenuItem} + */ + protected MenuItem createMenuItems(Menu menu) { + MenuItem menuItem = new MenuItem(menu, SWT.NONE); + menuItem.setText(PropertiesConstant.PROPERTY_RESET); + return menuItem; + } + + /** + * Creates menu item for Animator. + * + * @param menu + * a {@link Menu} which will be the parent of the new instance (cannot be null) + * @return a {@link MenuItem} + */ + protected MenuItem createMenuItem_CreateFrame(Menu menu) { + MenuItem menuItem = new MenuItem(menu, SWT.NONE); + menuItem.setText("Create Frame"); + return menuItem; + } + + /** + * Adds the selection listener to the menu item who will be notified when the menu item is + * selected by the user. + * + * @param listener + * a {@link SelectionAdapter} + */ + public void addMenuListener(SelectionAdapter listener) { + if (menuItem != null) { + menuItem.addSelectionListener(listener); + } + } + + /** + * Adds the selection listener to the animator menu item who will be notified when the menu item + * is selected by the user. + * + * @param listener + * a {@link SelectionAdapter} + */ + public void addCreateFrameMenuListener(SelectionAdapter listener) { + if (menuItemCreateFrame != null) { + menuItemCreateFrame.setEnabled(true); + menuItemCreateFrame.addSelectionListener(listener); + } + } + + private void setMethodLayout() { + FormLayout layout = new FormLayout(); + setLayout(layout); + } + + /** + * Gets the {@link FormData} for function button. + * + * @return the new {@link FormData} + */ + protected FormData getFuncLayoutData() { + FormData data = new FormData(); + + data.top = new FormAttachment(0, 0); + data.bottom = new FormAttachment(100, 0); + data.left = new FormAttachment(0, 10); + data.right = new FormAttachment(0, 20); + return data; + } + + /** + * Gets the {@link FormData} for label + * + * @return the new {@link FormData} + */ + protected FormData getLabelLayoutData() { + FormData data = new FormData(); + data.right = new FormAttachment(25, 0); + data.top = new FormAttachment(0, 0); + data.bottom = new FormAttachment(100, 0); + if (checkControl(funcButton)) { + data.left = new FormAttachment(funcButton, 5); + } else { + data.left = new FormAttachment(0, 15); + } + return data; + } + + /** + * Gets the {@link FormData} for control. + * + * @return the new {@link FormData} + */ + protected FormData getControlLayoutData() { + FormData data = new FormData(); + data.top = new FormAttachment(0, 0); + data.bottom = new FormAttachment(100, 0); + + if (checkControl(label)) { + data.left = new FormAttachment(label, 0); + } else { + data.left = new FormAttachment(0, 0); + } + data.width = 200; + return data; + } + + /** + * Sets label width. + * + * @param numerator + * the percentage of the position + * @param offset + * the offset of the side from the position + */ + public void setLabelRightData(int numerator, int offset) { + if (!checkControl(label)) { + return; + } + FormData data = getLabelLayoutData(); + data.right = new FormAttachment(numerator, offset); + + label.setLayoutData(data); + } + + /** + * Sets control width. + * + * @param numerator + * the percentage of the position + * @param offset + * the offset of the side from the position + */ + public void setControlRightData(int numerator, int offset) { + if (!checkControl(control)) { + return; + } + + FormData data = getControlLayoutData(); + data.right = new FormAttachment(numerator, offset); + + control.setLayoutData(data); + } + + private CLabel createLabel() { + if (displayName == null || displayName.isEmpty()) { + return null; + } + + CLabel label = EditableUtil.createCLabel(this, displayName); + + return label; + } + + /** + * Returns the SWT control for this {@link Editable}. + * + * @return the SWT control for this {@link Editable}, or null if this {@link Editable} + * does not have a control + */ + public Control getControl() { + return control; + } + + /** + * Returns the label for this {@link Editable}. + * + * @return the label for this {@link Editable}, or null if this {@link Editable} does + * not have a label + */ + public CLabel getLabel() { + return label; + } + + /** + * Gets a method name. + * + * @return a method name + */ + public String getMethodName() { + return name; + } + + /** + * Gets a value of this {@link Editable}. + * + * @return a value + */ + public String getValue() { + return value; + } + + /** + * Gets a display name of this {@link Editable}. + * + * @return a display name + */ + public String getDisplayName() { + return displayName; + } + + /** + * Creates the SWT control for this {@link Editable} under the parent control. + * + * @return new SWT control + */ + abstract protected Control createControl(); + + /** + * Refreshes the value. + * + * @param name + * the {@link Editable} name + * @param value + * the new value + */ + public void refreshValue(String name, String value) { + this.value = value; + } + + @Override + public void setEnabled(boolean enabled) { + super.setEnabled(enabled); + + if (funcButton != null && !funcButton.isDisposed()) { + funcButton.setEnabled(enableReset & enabled); + } + + CLabel label = getLabel(); + if (label != null && !label.isDisposed()) { + label.setEnabled(enabled); + } + + setControlable(enabled); + // Control control = getControl(); + // if (control != null && !control.isDisposed()) { + // control.setEnabled(enabled); + // } + } + + /** + * Sets tool tip text to the label of {@link Editable}. + * + * @param tooltip + * the tool tip text + */ + public void setLabelTooltipText(String tooltip) { + if (checkControl(label)) { + label.setToolTipText(tooltip); + } else { + control.setToolTipText(tooltip); + } + + } + + /** + * Shows error message to the control of {@link Editable}. + * + * @param text + * the error message + */ + public void showErrorToolTip(String text) { + tooltip = new ToolTip(getShell(), SWT.ICON_WARNING | SWT.BALLOON); + tooltip.setText(text); + + Point location = control.toDisplay(control.getSize().x, control.getSize().y); + + tooltip.setLocation(location.x - control.getSize().x + control.getBorderWidth(), location.y - control.getBorderWidth()); + tooltip.setVisible(true); + + Timer timer = new Timer(); + TimerTask timerTask = new TimerTask() { + @Override + public void run() { + Display.getDefault().asyncExec(new Runnable() { + + @Override + public void run() { + hideErrorTooltip(); + } + }); + } + }; + + timer.schedule(timerTask, 2000); + // + // control.addFocusListener(new FocusListener() { + // + // @Override + // public void focusLost(FocusEvent e) { + // if (tooltip != null) { + // Timer timer = new Timer(); + // TimerTask timerTask = new TimerTask() { + // @Override + // public void run() { + // Display.getDefault().asyncExec(new Runnable() { + // + // @Override + // public void run() { + // hideErrorTooltip(); + // } + // }); + // } + // }; + // + // timer.schedule(timerTask, 2000); + // } + // } + // + // @Override + // public void focusGained(FocusEvent e) { + // // Do nothing + // } + // }); + } + + /** + * Hides error message on the control of {@link Editable}. + */ + public void hideErrorTooltip() { + if (tooltip != null && !tooltip.isDisposed()) { + tooltip.setVisible(false); + tooltip.dispose(); + tooltip = null; + } + } + + /** + * Sets conditions. + * + * @param conditions + * list of {@link PropertyConditionDescriptor} + */ + public void setConditions(List conditions) { + this.conditions = conditions; + } + + /** + * Gets conditions. + * + * @return list of {@link PropertyConditionDescriptor} + */ + public List getConditions() { + return conditions; + } + + /** + * Enables the function button if the argument is true, and disables it otherwise. + * A disabled function button is typically not selectable from the user interface and draws with + * an inactive or "grayed" look. + * + * @param enable + */ + public void enableFuncButton(boolean enable) { + if (funcButton != null && !funcButton.isDisposed()) { + funcButton.setEnabled(enable); + enableReset = enable; + } + } + + /** + * Gets a function button. + * + * @return a function button. It's SWT {@link Label}. + */ + protected Label getFuncButton() { + return funcButton; + } + + /** + * Returns false if the widget has been disposed or null, and true + * otherwise. + * + * @param control + * @return + */ + protected boolean checkControl(Control control) { + if (control != null && !control.isDisposed()) { + return true; + } else { + return false; + } + } + + /** + * Sets the default value. + * + * @param defaultValue + * the default value + */ + public void setDefaultValue(String defaultValue) { + this.defaultValue = defaultValue; + } + + /** + * Gets the default value. + * + * @return the default value of this {@link Editable} + */ + public String getDefaultValue() { + return defaultValue == null ? BuilderConstants.EMPTY : defaultValue; + } + + /** + * Refreshes the this {@link Editable} + */ + public void refresh() { + refreshValue(name, value); + } + + /** + * Sets a {@link IValueChangeListener} who will be notified when the value is changed by the + * user. + * + * @param listener + * a {@link IValueChangeListener} + */ + public void setValueChangedListener(IValueChangeListener listener) { + this.listener = listener; + } + + /** + * Gets a {@link IValueChangeListener} of this {@link Editable}. + * + * @return a {@link IValueChangeListener} + */ + public IValueChangeListener getValueChangedListener() { + return listener; + } + + /** + * Sets the value to the {@link Editable} by the argument. + * + * @param value + * the new value + */ + public void setValue(String value) { + setValue(value, true); + } + + /** + * Sets the value to the {@link Editable} by the value argument. + * + * @param value + * the new value + * @param undoable + * whether undo is possible + */ + public void setValue(String value, boolean undoable) { + if (getValue().equals(value)) { + return; + } + this.value = value; + if (!first) { + modifyValue(BuilderConstants.EMPTY); + first = false; + } + + hideErrorTooltip(); + + IValueChangeListener listener = getValueChangedListener(); + + if (listener != null) { + listener.valueChanged(new EditableEvent(this, getMethodName(), value, undoable)); + } + } + + public void modifyValue(String value) { + modifyValue(getMethodName(), value); + } + + public void modifyValue(String key, String value) { + IValueChangeListener listener = getValueChangedListener(); + + if (listener != null) { + listener.valueModified(new EditableEvent(this, key, value)); + } + } + + /** + * Gets the {@link MethodType} of this {@link Editable} + * + * @return + */ + public MethodType getType() { + return type; + } + + /** + * Enables the SWT control of this {@link Editable} if the argument is true, and + * disables it otherwise + * + * @param controlable + * the new enable state + */ + public void setControlable(boolean controlable) { + // Because the control fixed with enableControl. + if (!enableControl) { + controlable = enableControl; + } + + Control control = getControl(); + if (control instanceof Composite) { + Composite composite = (Composite) control; + composite.setEnabled(controlable); + Control[] children = composite.getChildren(); + for (Control child : children) { + child.setEnabled(controlable); + } + } else { + control.setEnabled(controlable); + } + } + + public void fixEnableOfControl(boolean enable) { + enableControl = enable; + setControlable(enable); + } + + @Override + public String toString() { + return getClass().getSimpleName() + " " + getMethodName(); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/EditableCreationFactory.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/EditableCreationFactory.java new file mode 100644 index 0000000..86f2416 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/EditableCreationFactory.java @@ -0,0 +1,263 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.PlatformUI; +import org.tizen.common.util.Assert; +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.model.descriptors.ConstantDescriptor; +import org.tizen.efluibuilder.model.descriptors.PropertyDescriptor; +import org.tizen.efluibuilder.model.descriptors.TypeDescriptor; +import org.tizen.efluibuilder.model.descriptors.TypeDescriptor.Types; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.ModelConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.efluibuilder.ui.views.properties.PropertiesConstant; +import org.tizen.efluibuilder.ui.views.properties.method.Editable.MethodType; +import org.tizen.efluibuilder.ui.views.properties.style.StyleEDJManager; +import org.tizen.efluibuilder.ui.views.properties.style.StyleEditMethod; + + +/** + * A factory class for method create. + */ +public final class EditableCreationFactory { + + private Part model = null; + private String projectVersion = null; + private static EditableCreationFactory instance = null; + + private EditableCreationFactory() { + } + + /** + * Gets a {@link EditableCreationFactory}. + * + * @return a {@link EditableCreationFactory} + */ + public static EditableCreationFactory getInstance() { + if (instance == null) { + instance = new EditableCreationFactory(); + } + return instance; + } + + /** + * Sets a {@link Part} + * + * @param model + * a {@link Part} + */ + public void setModel(Part model) { + this.model = model; + } + + public void setProjectVersion(String version) { + this.projectVersion = version; + } + + /** + * Creates a new {@link Editable} given its parent and {@link PropertyDescriptor}, method type, + * has function button. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param property + * a {@link PropertyDescriptor} + * @param value + * property value + * @param methodType + * a {@link MethodType} + * @param hasFunc + * true if the Method has function button, and false + * otherwise + * @return + */ + public Editable createMethod(Composite parent, PropertyDescriptor property, String value, MethodType methodType, boolean hasFunc) { + Editable method = null; + TypeDescriptor descriptor = property.getTypeDescriptor(); + if (descriptor == null) { + return null; + } + + Types type = descriptor.getType(); + + if (value == null) { + value = BuilderConstants.EMPTY; + } + + String name = property.getPropertyName(); + String displayName = property.getPropertyDisplayName(); + + switch (type) { + case LISTITEM_CLASS: + case ENUM: + List enums = property.getTypeDescriptor().getAvailableConstant(); + if (enums.size() == 2) { + RadioEditable radio = new RadioEditable(parent, SWT.NONE, methodType, name, value, displayName, hasFunc); + radio.setItems(enums); + method = radio; + } else { + ComboEditable combo = new ComboEditable(parent, SWT.NONE, methodType, name, value, displayName, hasFunc); + combo.setItems(enums); + method = combo; + } + break; + case DYNAMIC_COMBO: + enums = property.getTypeDescriptor().getAvailableConstant(); + ComboEditable combo = new ComboEditable(parent, SWT.NONE, methodType, name, value, displayName, hasFunc); + combo.setItems(enums); + method = combo; + break; + case EFL_STYLE: + if (StyleEDJManager.isLaterVersion3_0(projectVersion)) { + method = new StyleEditMethod(parent, SWT.NONE, methodType, name, value, displayName, hasFunc); + } else { + enums = property.getTypeDescriptor().getAvailableConstant(); + combo = new ComboEditable(parent, SWT.NONE, methodType, name, value, displayName, hasFunc); + combo.setItems(enums); + method = combo; + } + break; + case COLORS: + enums = property.getTypeDescriptor().getAvailableConstant(); + method = new ColorListEditable(parent, SWT.NONE, methodType, name, value, displayName, hasFunc, enums); + break; + case IMAGE: + method = new ImageEditable(parent, SWT.NONE, methodType, name, value, displayName, hasFunc); + break; + case LAYOUT_RESOURCE: + method = new LayoutResourceEditable(parent, SWT.NONE, methodType, name, value, displayName, hasFunc); + break; + case TEXT_RESOURCE: + method = new TextResourceEditable(parent, SWT.NONE, methodType, name, value, displayName, hasFunc); + break; + case COLOR: + method = new ColorPickerEditable(parent, SWT.NONE, methodType, name, value, displayName, hasFunc); + break; + case SUB_VIEW: + // is naviframe + Assert.isTrue(model.getDescriptorId().equals(ModelConstants.KEY_WIDGET_NAVIFRAME)); + + // current view + Part viewPart = model.getParent(); + Assert.isTrue(viewPart.getDescriptorId().equals(ModelConstants.KEY_PART_VIEW)); + String currentViewId = viewPart.getPropertyValue(LayoutSchemaConstants.ID); + + CombineEditorPart editor = (CombineEditorPart) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); + Part viewsPart = PartUtil.findViewsPart(editor.getDocumentPart()); + + List constants = new ArrayList(); + constants.add(new ConstantDescriptor("", PropertiesConstant.NONE)); + + for (Part view : viewsPart.getChildren()) { + String id = view.getPropertyValue(LayoutSchemaConstants.ID); + // ignore current view + if (id.equals(currentViewId)) { + continue; + } + + boolean hasSubview = false; + for (Part child : view.getChildren()) { + if (child.getType() == PartType.VIEW) { + hasSubview = true; + break; + } + } + + // ignore view which has naviframe + if (hasSubview) { + continue; + } + + // currently value : # + id + // TODO : Remove # + ConstantDescriptor desc = new ConstantDescriptor(BuilderConstants.SHARP + id, id); + constants.add(desc); + } + + ComboEditable comboMethod = new ComboEditable(parent, SWT.NONE, methodType, name, value, displayName, hasFunc); + comboMethod.setItems(constants); + method = comboMethod; + break; + case GROUP: + method = new GroupEditable(parent, SWT.NONE, methodType, name, value, displayName, hasFunc, null, property); + break; + case INTEGER: + method = new IntegerEditable(parent, SWT.NONE, methodType, name, value, displayName, hasFunc); + break; + case DOUBLE: + method = new DoubleEditable(parent, SWT.NONE, methodType, name, value, displayName, hasFunc); + break; + case EMPTY: + method = new EmptyEditable(parent, SWT.NONE, methodType); + break; + case SCALE_INTEGER: + method = new ScaleEditable(parent, SWT.NONE, methodType, name, value, displayName, hasFunc, property); + break; + case SCALE: + method = new CheckScaleEditable(parent, SWT.NONE, methodType, name, value, displayName, hasFunc, property, false); + break; + case CHECK_SCALE: + method = new CheckScaleEditable(parent, SWT.NONE, methodType, name, value, displayName, hasFunc, property, true); + break; + case GROUP_TEXT: + method = new TextStyleEditable(parent, SWT.NONE, methodType, name, value, displayName, hasFunc, null, property); + break; + case ITEM_ADD: + method = new ItemAddEditable(parent, SWT.NONE, methodType, name, value, displayName, hasFunc); + break; + case RM_STRING: // for RM - localization + method = new RMTextEditable(parent, SWT.NONE, methodType, name, value, displayName, hasFunc); + break; + case STRING: + case UNKNOWN: + default: + if (name.equals(BuilderConstants.PROPERTY_ID)) { + method = new TextEditable(parent, SWT.NONE, methodType, name, value, displayName, false); + } else { + method = new TextEditable(parent, SWT.NONE, methodType, name, value, displayName, hasFunc); + } + break; + } + + if (method != null) + + { + method.setDefaultValue(property.getDefaultValue()); + method.setConditions(property.getConditionDescriptors()); + method.setLabelTooltipText(property.getTooltip()); + } + + return method; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/EditableEvent.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/EditableEvent.java new file mode 100644 index 0000000..6258632 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/EditableEvent.java @@ -0,0 +1,136 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +/** + * Method event class for {@link IValueChangeListener}. + */ +public class EditableEvent { + + private Editable method; + private String key; + private String value; + private boolean undoable = true; + + // TODO : Will be removed. + private String selector; + + /** + * Constructor. + * + * @param method + * a source {@link Editable} + * @param key + * property name + * @param value + * property value + */ + public EditableEvent(Editable method, String key, String value) { + this(method, key, value, true); + } + + /** + * Constructor. + * + * @param method + * a source {@link Editable} + * @param key + * property name + * @param value + * property value + * @param undoable + * whether undo is possible + */ + public EditableEvent(Editable method, String key, String value, boolean undoable) { + this.method = method; + this.key = key; + this.value = value; + this.undoable = undoable; + } + + /** + * Constructor. + * + * @param method + * a source {@link Editable} + * @param key + * property name + * @param value + * property value + * @param undoable + * whether undo is possible + * @param selector + * a selector name. + */ + public EditableEvent(Editable method, String key, String value, boolean undoable, String selector) { + this(method, key, value, true); + this.selector = selector; + } + + /** + * Gets property value. + * + * @return value + */ + public String getValue() { + return value; + } + + /** + * Gets property name. + * + * @return property name + */ + public String getKey() { + return key; + } + + /** + * Gets undoable. + * + * @return true if undoable is true, and false otherwise + */ + public boolean getUndoable() { + return undoable; + } + + /** + * Gets a selector name. + * + * @return a selector name. + */ + public String getSelector() { + return selector; + } + + /** + * Gets a {@link Editable}. + * + * @return a {@link Editable} + */ + public Editable getMethod() { + return method; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/EditableUtil.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/EditableUtil.java new file mode 100644 index 0000000..c769fd7 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/EditableUtil.java @@ -0,0 +1,741 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import java.awt.Color; + +import org.eclipse.core.resources.IProject; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.ColorDialog; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Spinner; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; +import org.eclipse.ui.PlatformUI; +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.mscreen.configurator.MscreenConstants; +import org.tizen.efluibuilder.mscreen.rm.AutoCompleteTextUtil; +import org.tizen.efluibuilder.mscreen.rm.ResourceManagerUtil; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.efluibuilder.ui.resources.ImageResources; +import org.tizen.efluibuilder.ui.views.properties.PropertiesConstant; +import org.tizen.efluibuilder.ui.widgets.UIBLabel; + + +/** + * Utilities class for {@link Editable}. + */ +public class EditableUtil { + + /** + * Creates a new {@link Label}. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param text + * the new text + * @return a new {@link Label} + */ + public static Label createLabel(Composite parent, String text) { + Label label = new Label(parent, SWT.NONE); + label.setText(text); + return label; + } + + /** + * Creates a new {@link CLabel}. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param text + * the new text + * @return a new {@link CLabel} + */ + public static CLabel createCLabel(Composite parent, String text) { + CLabel label = new UIBLabel(parent, SWT.NONE); + label.setText(text); + return label; + } + + /** + * Creates a new {@link Spinner}. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param value + * the new value + * @return a new {@link Spinner} + */ + public static Spinner createSpinner(Composite parent, String value) { + Spinner spinner = new Spinner(parent, SWT.BORDER); + spinner.setMinimum(0); + spinner.setMaximum(9999); + spinner.setIncrement(1); + spinner.setTextLimit(4); + spinner.setSelection(0); + return spinner; + } + + /** + * Creates a new {@link CCombo}. This CCombo style is SWT.READ_ONLY. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @return a new {@link CCombo} + */ + public static CCombo createCombo(Composite parent) { + CCombo combo = new CCombo(parent, SWT.READ_ONLY | SWT.BORDER | SWT.NO_FOCUS | SWT.FLAT); + + return combo; + } + + /** + * Creates a new {@link CCombo}. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @return a new {@link CCombo} + */ + public static CCombo createInputCombo(Composite parent) { + CCombo combo = new CCombo(parent, SWT.BORDER | SWT.FLAT); + + return combo; + } + + /** + * Creates a new {@link ToolBar} for font. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @return a new {@link ToolBar} + */ + public static ToolBar createFontToolbar(Composite parent) { + ToolBar toolbar = new ToolBar(parent, SWT.HORIZONTAL | SWT.NO_FOCUS); + + ToolItem item = new ToolItem(toolbar, SWT.FLAT); + ToolItem item1 = new ToolItem(toolbar, SWT.FLAT); + ToolItem item2 = new ToolItem(toolbar, SWT.FLAT); + ToolItem item3 = new ToolItem(toolbar, SWT.FLAT); + + Image image = ImageResources.getImage(ImageResources.METHOD_BOLD); + item.setImage(image); + + image = ImageResources.getImage(ImageResources.METHOD_ITALIC); + item1.setImage(image); + + image = ImageResources.getImage(ImageResources.METHOD_UNDER_LINE); + item2.setImage(image); + + image = ImageResources.getImage(ImageResources.METHOD_CANCEL_LINE); + item3.setImage(image); + + return toolbar; + } + + /** + * Creates a new {@link ToolBar} for align. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @return a new {@link ToolBar} + */ + public static ToolBar createAlignToolbar(Composite parent) { + ToolBar toolbar = new ToolBar(parent, SWT.HORIZONTAL | SWT.NO_FOCUS); + + ToolItem item = new ToolItem(toolbar, SWT.FLAT); + ToolItem item1 = new ToolItem(toolbar, SWT.FLAT); + ToolItem item2 = new ToolItem(toolbar, SWT.FLAT); + + Image image = ImageResources.getImage(ImageResources.METHOD_ALIGN_LEFT); + item.setImage(image); + image = ImageResources.getImage(ImageResources.METHOD_ALIGN_CENTER); + item1.setImage(image); + image = ImageResources.getImage(ImageResources.METHOD_ALIGN_RIGHT); + item2.setImage(image); + + return toolbar; + } + + // public static Listener createNumberingListener(final Method target) { + // Listener textListener = new Listener() { + // + // private Method method = target; + // private boolean hasFocus = false; + // private boolean hadFocusOnMousedown = false; + // + // @Override + // public void handleEvent(Event event) { + // Combo spinner = (Combo) event.widget; + // + // if (spinner != method.getControl()) { + // return; + // } + // + // switch (event.type) { + // case SWT.Traverse: + // if (event.detail == SWT.TRAVERSE_RETURN) { + // method.setValue(spinner.getText()); + // } else if (event.detail == SWT.TRAVERSE_ESCAPE) { + // method.refreshValue(method.getMethodName(), method.getValue()); + // } + // + // break; + // case SWT.FocusIn: + // // text.selectAll(); + // spinner.getDisplay().asyncExec(new Runnable() { + // + // @Override + // public void run() { + // hasFocus = true; + // } + // }); + // break; + // case SWT.FocusOut: + // method.setValue(spinner.getText()); + // hasFocus = false; + // break; + // case SWT.MouseDown: + // hadFocusOnMousedown = hasFocus; + // break; + // case SWT.MouseUp: + // if (!hadFocusOnMousedown) { + // spinner.setFocus(); + // // text.selectAll(); + // } + // break; + // case SWT.MouseDoubleClick: + // method.setValue(spinner.getText()); + // break; + // default: + // break; + // } + // } + // }; + // + // return textListener; + // } + + /** + * Creates a Listener for spinner. + * + * @param target + * a target {@link Editable} + * @return a {@link Listener} + */ + public static Listener createSpinnerListener(final Editable target) { + Listener textListener = new Listener() { + + private Editable method = target; + private boolean hasFocus = false; + private boolean hadFocusOnMousedown = false; + + @Override + public void handleEvent(Event event) { + Spinner spinner = (Spinner) event.widget; + + if (spinner != method.getControl()) { + return; + } + + switch (event.type) { + case SWT.Traverse: + if (event.detail == SWT.TRAVERSE_RETURN) { + method.setValue(spinner.getText()); + } else if (event.detail == SWT.TRAVERSE_ESCAPE) { + method.refreshValue(method.getMethodName(), method.getValue()); + } + + break; + case SWT.FocusIn: + // text.selectAll(); + spinner.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + hasFocus = true; + } + }); + break; + case SWT.FocusOut: + method.setValue(spinner.getText()); + hasFocus = false; + break; + case SWT.MouseDown: + hadFocusOnMousedown = hasFocus; + break; + case SWT.MouseUp: + if (!hadFocusOnMousedown) { + spinner.setFocus(); + // text.selectAll(); + } + break; + case SWT.MouseDoubleClick: + method.setValue(spinner.getText()); + break; + default: + break; + } + } + }; + + return textListener; + } + + /** + * Creates a Listener for combo. + * + * @param target + * a target {@link Editable} + * @return a {@link Listener} + */ + public static Listener createComboListener(final Editable target) { + Listener textListener = new Listener() { + + private Editable method = target; + private boolean hasFocus = false; + private boolean hadFocusOnMousedown = false; + + @Override + public void handleEvent(Event event) { + Combo combo = (Combo) event.widget; + + if (combo != method.getControl()) { + return; + } + + switch (event.type) { + case SWT.Traverse: + if (event.detail == SWT.TRAVERSE_RETURN) { + method.setValue(combo.getText()); + } else if (event.detail == SWT.TRAVERSE_ESCAPE) { + method.refreshValue(method.getMethodName(), method.getValue()); + } + + break; + case SWT.FocusIn: + // text.selectAll(); + combo.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + hasFocus = true; + } + }); + break; + case SWT.FocusOut: + method.setValue(combo.getText()); + hasFocus = false; + break; + case SWT.MouseDown: + + hadFocusOnMousedown = hasFocus; + Point pt = new Point(0, combo.getText().length()); + combo.setSelection(pt); + break; + case SWT.MouseUp: + if (!hadFocusOnMousedown) { + combo.setFocus(); + // text.selectAll(); + } + break; + case SWT.MouseDoubleClick: + method.setValue(combo.getText()); + break; + // case SWT.Selection: + // method.setValue(combo.getText()); + // break; + default: + break; + } + } + }; + + return textListener; + } + + /** + * Creates Listener for size combo. + * + * @param target + * a target {@link Editable} + * @return a {@link Listener} + */ + public static Listener createSizeComboListener(final Editable target, final double increment) { + Listener textListener = new Listener() { + + private Editable method = target; + private boolean hasFocus = false; + private boolean hadFocusOnMousedown = false; + private Point mousePt = null; + private boolean moveFlag = false; + + @Override + public void handleEvent(Event event) { + if (!(event.widget instanceof Combo)) { + return; + } + Combo combo = (Combo) event.widget; + + switch (event.type) { + case SWT.Traverse: + if (event.detail == SWT.TRAVERSE_RETURN) { + method.setValue(combo.getText()); + } else if (event.detail == SWT.TRAVERSE_ESCAPE) { + method.modifyValue(BuilderConstants.EMPTY); + method.refreshValue(method.getMethodName(), method.getValue()); + } { + Point pt = new Point(0, combo.getText().length()); + combo.setSelection(pt); + } + + break; + case SWT.FocusIn: + // text.selectAll(); + combo.getDisplay().syncExec(new Runnable() { + + @Override + public void run() { + hasFocus = true; + } + }); + break; + case SWT.FocusOut: + method.setValue(combo.getText()); + hasFocus = false; + break; + case SWT.MouseDown: + mousePt = new Point(event.x, event.y); + + hadFocusOnMousedown = hasFocus; + Point pt = new Point(0, combo.getText().length()); + combo.setSelection(pt); + break; + case SWT.MouseUp: + if (mousePt != null && moveFlag) { + mousePt = null; + moveFlag = false; + method.setValue(combo.getText()); + } + hadFocusOnMousedown = false; + // if (!hadFocusOnMousedown) { + // combo.setFocus(); + // // text.selectAll(); + // } + break; + case SWT.MouseDoubleClick: + method.setValue(combo.getText()); + break; + case SWT.MouseMove: { + if (hadFocusOnMousedown) { + moveFlag = true; + // long startTime = System.nanoTime(); + if (combo != null && combo.getText() != null && mousePt != null) { + double valueDouble = 0; + String text = combo.getText(); + if (!text.isEmpty() && text.matches(BuilderConstants.FLOATVALUE)) { + valueDouble = Double.parseDouble(combo.getText()); + } + if (mousePt.y - BuilderConstants.countPerPx > event.y) { + double result = valueDouble + increment; + int intValue = (int) result; + String value = BuilderConstants.EMPTY; + if (result - intValue != 0) { + value = String.format("%.2f", result); + } else { + value = String.valueOf(intValue); + } + + combo.setText(value); + method.modifyValue(value); + mousePt.y = mousePt.y - 10; + } else if (mousePt.y + BuilderConstants.countPerPx < event.y) { + double result = valueDouble - increment; + int intValue = (int) result; + String value = BuilderConstants.EMPTY; + if (result - intValue != 0) { + value = String.format("%.2f", result); + } else { + value = String.valueOf(intValue); + } + combo.setText(value); + method.modifyValue(value); + mousePt.y = mousePt.y + 10; + } + } + } + } + break; + + case SWT.Selection: { + method.setValue(combo.getText()); + // because not validate from combo box value + } + break; + default: + break; + } + } + }; + + return textListener; + } + + private static String replaceCharacter(String str) { + str = str.replaceAll("\"", """); + return str; + } + + /* ==[START]== added by SBC for AutoCompleteText(RM) */ + + /** + * This function is used to check the AutoCompleteText feature. ResourceMananger (Resource / + * Locale). reference to widget descriptor xml and MethodCreationFactory + * + * @param text + * a text {@link Text} + * @param target + * a target {@link Editable} + * @return a {@link Listener} + */ + private static boolean canAutoComplete(Editable target) { + if ((target instanceof ResourceEditable) || (target instanceof RMTextEditable)) { + return true; + } else { + return false; + } + // return (target instanceof RMTextMethod) ? true : false; + + } + + /** + * This function is enable "AutoCompleteText"(Key assistance Interlock for M-Screen and + * ResourceMananger (Resource / Locale). reference to widget descriptor xml and + * MethodCreationFactory + * + * @param text + * a text {@link Text} + * @param target + * a target {@link Editable} + * @return a {@link Listener} + */ + private static void enableAutoCompleteText(Text text, Editable target) { + + if (!canAutoComplete(target)) { + return; + } + + CombineEditorPart combineEditorPart = (CombineEditorPart) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); + IProject project = combineEditorPart.getProject(); + String shortcutPrefixString = null; + + String[] keyStrings = null; + ResourceManagerUtil rmWrapper = new ResourceManagerUtil(project); + Image image = ImageResources.getImage(ImageResources.METHOD_ICON_FILE_LABEL_ITEM); + if (target instanceof ResourceEditable) { + /* + * Target UI Component: ImageMethod(BG, Image, Icon, gengriditem, gengridlist), + * LayoutResourceMethod(edc) + */ + shortcutPrefixString = MscreenConstants.RESOURCE_KEY; + keyStrings = rmWrapper.getAllResourceKeys(shortcutPrefixString, ((ResourceEditable) target).getResourceFileExtentions()); + } else { // This is only TextMethod + /* + * Target UI Component: Button, Label, gengriditem, gengridlist,etc.. + */ + shortcutPrefixString = MscreenConstants.LOCALE_KEY; + keyStrings = rmWrapper.getMsgKeys(shortcutPrefixString); + } + if (keyStrings != null) { + AutoCompleteTextUtil.setAutoCompletion(text, keyStrings, shortcutPrefixString, image); + } + } + + /* ==[END]== added by SBC for AutoCompleteText(RM) */ + + /** + * Creates Listener for text. + * + * @param target + * a target {@link Editable} + * @return a {@link Listener} + */ + public static Listener createTextListener(final Editable target) { + Listener textListener = new Listener() { + + private boolean hasFocus = false; + private boolean hadFocusOnMousedown = false; + private String textStr = null; + + @Override + public void handleEvent(Event event) { + Text text = (Text) event.widget; + + if (text != target.getControl()) { + return; + } + + switch (event.type) { + case SWT.Traverse: + if (event.detail == SWT.TRAVERSE_RETURN) { + textStr = replaceCharacter(text.getText()); + target.setValue(textStr); + } else if (event.detail == SWT.TRAVERSE_ESCAPE) { + target.refreshValue(target.getMethodName(), target.getValue()); + } else { + break; + } + // text.selectAll(); + break; + case SWT.FocusIn: + /* added by SBC for AutoCompleteText(RM) */ + enableAutoCompleteText(text, target); + text.selectAll(); + + text.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + hasFocus = true; + } + }); + break; + case SWT.FocusOut: + textStr = replaceCharacter(text.getText()); + target.setValue(textStr); + hasFocus = false; + if (text.isDisposed() == false) { + text.clearSelection(); + } + break; + case SWT.MouseDown: + hadFocusOnMousedown = hasFocus; + break; + case SWT.MouseUp: + if (!hadFocusOnMousedown) { + text.setFocus(); + text.selectAll(); + } + break; + case SWT.MouseDoubleClick: + textStr = replaceCharacter(text.getText()); + target.setValue(textStr); + break; + default: + break; + } + } + }; + + return textListener; + } + + /** + * Creates Listener for color. + * + * @param target + * a target {@link Editable} + * @return a {@link SelectionListener} + */ + public static SelectionListener createColorListener(final Editable target) { + SelectionAdapter listener = new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + ColorDialog dialog = new ColorDialog(target.getShell()); + dialog.setText(PropertiesConstant.DIALOG_COLOR_SELECTOR); + String value = target.getValue(); + if (value == null || value.isEmpty()) { + value = "0"; + } + Color color = Color.decode(value); + dialog.setRGB(new RGB(color.getRed(), color.getGreen(), color.getBlue())); + + RGB newColor = dialog.open(); + if (newColor == null) { + return; + } else { + String hex = String.format("#%02x%02x%02x", newColor.red, newColor.green, newColor.blue); + target.setValue(hex); + } + } + }; + return listener; + } + + /** + * Creates Listener for color2. + * + * @param target + * a target {@link Editable} + * @return a {@link SelectionListener} + */ + public static SelectionListener createColor2Listener(final Editable target) { + SelectionAdapter listener = new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + ColorDialog dialog = new ColorDialog(target.getShell()); + dialog.setText(PropertiesConstant.DIALOG_COLOR_SELECTOR); + String value = target.getValue(); + if (value == null || value.isEmpty()) { + value = "0, 0, 0"; + } + + String[] values = value.split(", "); + if (values.length != 3) { + return; + } + + int[] colors = { 0, 0, 0 }; + for (int i = 0; i < values.length; i++) { + colors[i] = Integer.parseInt(values[i]); + } + + dialog.setRGB(new RGB(colors[0], colors[1], colors[2])); + + RGB newColor = dialog.open(); + if (newColor == null) { + return; + } else { + String ret = newColor.red + ", " + newColor.green + ", " + newColor.blue; + target.setValue(ret); + } + } + }; + return listener; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/EmptyEditable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/EmptyEditable.java new file mode 100644 index 0000000..f5691d3 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/EmptyEditable.java @@ -0,0 +1,81 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.model.descriptors.TypeDescriptor; + + +/** + * A EmptyMethod for EMPTY type in the {@link TypeDescriptor.Types} + */ +public class EmptyEditable extends Editable { + + /** + * Constructor. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param style + * the style of widget to construct + * @param type + * a {@link MethodType} + * @param name + * property name + * @param value + * property value + * @param displayName + * display name + * @param hasFunc + * true if the Method has function button, and false + * otherwise + * @see Editable + */ + public EmptyEditable(Composite parent, int style, MethodType type) { + super(parent, style, type, BuilderConstants.EMPTY, null, null, false); + } + + @Override + protected Control createControl() { + Label label = new Label(this, SWT.NONE); + label.setVisible(false); + return label; + } + + /** + * Gets the {@link FormData} for control. + * + * @return the new {@link FormData} + */ + protected FormData getControlLayoutData() { + FormData data = new FormData(); + data.height = 27; + return data; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/GroupEditable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/GroupEditable.java new file mode 100644 index 0000000..e525219 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/GroupEditable.java @@ -0,0 +1,411 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.model.descriptors.PropertyDescriptor; +import org.tizen.efluibuilder.model.descriptors.TypeDescriptor; +import org.tizen.efluibuilder.model.util.ComponentValidator; + + +/** + * A GroupMethod for GROUP type in the {@link TypeDescriptor.Types} + */ +public class GroupEditable extends Editable implements IGroupEditable, IValueChangeListener { + + private List methods = new ArrayList(); + private PropertyDescriptor parentDescriptor; + private Object model; + protected Editable recentEditedMethod; + private Map childValues = new HashMap(); + + /** + * Constructor. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param style + * the style of widget to construct + * @param type + * a {@link MethodType} + * @param name + * property name + * @param value + * property value + * @param displayName + * display name + * @param hasFunc + * true if the Method has function button, and false + * otherwise + * @param model + * a {@link AnimatorPart} + * @param parentDescriptor + * a {@link PropertyDescriptor} for group type. + */ + public GroupEditable(Composite parent, int style, MethodType type, String name, String value, String displayName, boolean hasFunc, Object model, + PropertyDescriptor parentDescriptor) { + super(parent, style, type, name, value, displayName, hasFunc); + this.model = model; + this.parentDescriptor = parentDescriptor; + createChildMethods(); + refreshValue(name, value); + } + + @Override + public List getChildMethods() { + return methods; + } + + @Override + public Editable getChildMethod(String key) { + for (Editable child : methods) { + if (child.getMethodName().equals(key)) { + return child; + } + } + return null; + } + + @Override + protected Control createControl() { + Composite composite = new Composite(this, SWT.NONE); + FormLayout layout = new FormLayout(); + // GridLayout layout = new GridLayout(2, true); + composite.setLayout(layout); + return composite; + } + + @Override + public Composite getControl() { + return (Composite) super.getControl(); + } + + @Override + protected FormData getFuncLayoutData() { + FormData data = new FormData(); + data.top = new FormAttachment(0, 0); + data.bottom = new FormAttachment(100, 0); + data.left = new FormAttachment(0, 10); + data.right = new FormAttachment(0, 20); + return data; + } + + @Override + protected FormData getControlLayoutData() { + FormData data = new FormData(); + data.top = new FormAttachment(0, 0); + data.bottom = new FormAttachment(100, 0); + data.right = new FormAttachment(100, 0); + + if (checkControl(getLabel())) { + data.left = new FormAttachment(getLabel(), 0); + } else if (checkControl(getFuncButton())) { + data.left = new FormAttachment(getFuncButton(), 0); + } else { + data.left = new FormAttachment(0, 0); + } + + return data; + } + + @Override + protected FormData getLabelLayoutData() { + FormData data = new FormData(); + data.right = new FormAttachment(25, 0); + + // data.bottom = new FormAttachment(100, 0); + if (checkControl(getFuncButton())) { + data.top = new FormAttachment(getFuncButton(), 0, SWT.CENTER); + data.left = new FormAttachment(getFuncButton(), 5); + } else { + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(0, 0); + } + return data; + } + + /** + * Gets a parent descriptor. + * + * @return a {@link PropertyDescriptor} + */ + protected PropertyDescriptor getParentDescriptor() { + return parentDescriptor; + } + + /** + * Creates child method. + */ + protected void createChildMethods() { + if (parentDescriptor == null) { + return; + } + EditableCreationFactory factory = EditableCreationFactory.getInstance(); + for (PropertyDescriptor child : parentDescriptor.getChildPropertyDescriptors()) { + String value = ""; + Editable method = factory.createMethod(getControl(), child, value, getType(), false); + if (method == null) { + continue; + } else { + int methodSize = methods.size(); + FormData data = new FormData(); + + if (methodSize >= 2) { + data.top = new FormAttachment(methods.get(methodSize - 2), 3); + } else { + data.top = new FormAttachment(0, 0); + } + + if (methodSize % 2 == 0) { + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(50, 0); + } else { + data.left = new FormAttachment(50, 5); + data.right = new FormAttachment(100, 0); + } + // data.height = 25; + // GridData data = new GridData(GridData.FILL, GridData.FILL, true, true); + String displayName = method.getDisplayName(); + if (displayName != null && displayName.length() < 4) { + method.setLabelRightData(18, 0); + } else { + method.setLabelRightData(32, 0); + } + + method.setControlRightData(100, 0); + + method.setLayoutData(data); + method.setValueChangedListener(this); + method.setLabelTooltipText(parentDescriptor.getPropertyName()); + methods.add(method); + } + + addChildKeyValue(child.getPropertyName(), value); + + } + } + + // /** + // * Gets child value given its key. + // * + // * @param key + // * child property name. + // * @return value + // */ + // protected String getChildValue(String key) { + // String value = BuilderConstants.EMPTY; + // MethodType type = getType(); + // switch (type) { + // case ATTRIBUTE: + // // TODO : cast part + // // Part part = (Part) model; + // break; + // case STYLE: + // // TODO : get value from selector + // // CssSelector selector = (CssSelector) model; + // // value = selector.getPropertyValue(key); + // break; + // case EVENT_HANDLER: + // break; + // default: + // break; + // } + // return value; + // } + + /** + * Resets default value of children. + */ + protected void resetChilden() { + for (Editable child : methods) { + child.refreshValue(child.getMethodName(), child.getDefaultValue()); + } + } + + @Override + public void refreshValue(String name, String value) { + super.refreshValue(name, value); + + if (value == null || value.isEmpty() || value.equals("none")) { + resetChilden(); + return; + } + MethodType type = getType(); + switch (type) { + case ATTRIBUTE: + // TODO : cast part + // Part part = (Part) model; + break; + case STYLE: + // StyleValue cssValue = + // new CssReader().createStyleValue(value, + // (StylePropertyDescriptor) parentDescriptor); + // if (cssValue == null) { + // break; + // } + // List components = cssValue.getComponents(); + // + // // For GroupValueMethod + // if (components.size() == 1) { + // components = components.get(0).getParameters(); + // } + // + // int compoSize = components.size(); + // int compoIndex = 0; + // for (int i = 0; i < methods.size(); i++) { + // Method child = methods.get(i); + // if (child instanceof EmptyMethod) { + // continue; + // } + // if (compoSize >= i) { + // String childValue = components.get(compoIndex).getValue(); + // child.refreshValue(child.getMethodName(), childValue); + // compoIndex++; + // addChildKeyValue(child.getMethodName(), childValue); + // } + // } + + break; + case EVENT_HANDLER: + break; + default: + break; + } + + } + + @Override + public void valueChanged(EditableEvent event) { + String key = event.getKey(); + String value = event.getValue(); + Editable childMethod = event.getMethod(); + + String message = validateStyle(key, value); + if (!message.equals(ComponentValidator.OK)) { + childMethod.refreshValue(key, childValues.get(key)); + childMethod.showErrorToolTip(message); + return; + } + + addChildKeyValue(key, value); + recentEditedMethod = childMethod; + + String fullValue = getResultValue(event.getKey(), event.getValue()); + if (fullValue != null) { + setValue(fullValue); + } + } + + @Override + public void valueModified(EditableEvent event) { + String value = getResultValue(event.getKey(), event.getValue()); + if (value != null) { + modifyValue(value); + } + } + + protected String getResultValue(String childKey, String childValue) { + if (childKey == null || childValue == null) { + return null; + } + String resultValue = BuilderConstants.EMPTY; + int size = methods.size(); + for (int i = 0; i < size; i++) { + Editable child = methods.get(i); + if (child instanceof EmptyEditable) { + continue; + } else if (child.getMethodName().equals(childKey)) { + resultValue += childValue; + } else { + String val = child.getValue(); + if (val == null || val.isEmpty()) { + val = child.getDefaultValue(); + } + + resultValue += val; + } + if (i + 1 != size) { + resultValue += BuilderConstants.SPACE; + } + } + return resultValue; + } + + protected String validateStyle(String key, String value) { + String message = ComponentValidator.OK; + PropertyDescriptor descriptor = parentDescriptor.getChildPropertyDescriptor(key); + + message = new ComponentValidator().canSetStyleDeclarationValue(descriptor, value); + return message; + } + + /** + * Gets a model. + * + * @return model + */ + protected Object getModel() { + return model; + } + + @Override + public void setEnabled(boolean enabled) { + super.setEnabled(enabled); + + for (Editable method : methods) { + method.setEnabled(enabled); + } + } + + @Override + public void showErrorToolTip(String text) { + if (recentEditedMethod != null) { + recentEditedMethod.showErrorToolTip(text); + } else { + super.showErrorToolTip(text); + } + } + + protected void addChildKeyValue(String key, String value) { + if (value == null) { + value = BuilderConstants.EMPTY; + } + childValues.put(key, value); + } + + protected String getChildValue(String key) { + return childValues.get(key); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/IGroupEditable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/IGroupEditable.java new file mode 100644 index 0000000..c201a6a --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/IGroupEditable.java @@ -0,0 +1,49 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import java.util.List; + + +/** + * Interface for GroupMethod. + */ +public interface IGroupEditable { + + /** + * Gets child Method lists. + * + * @return list of {@link Editable} + */ + public List getChildMethods(); + + /** + * Gets a child Method + * + * @param key + * a method name + * @return a child method or null + */ + public Editable getChildMethod(String key); +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/IValueChangeListener.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/IValueChangeListener.java new file mode 100644 index 0000000..4953035 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/IValueChangeListener.java @@ -0,0 +1,46 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +/** + * A listener for {@link Editable}. + */ +public interface IValueChangeListener { + + /** + * Called when a value is changed. + * + * @param event + * a {@link EditableEvent} + */ + void valueChanged(EditableEvent event); + + /** + * Called when a value is modified. + * + * @param event + * a {@link EditableEvent} + */ + void valueModified(EditableEvent event); +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ImageEditable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ImageEditable.java new file mode 100644 index 0000000..660035c --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ImageEditable.java @@ -0,0 +1,112 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.gef.dnd.model.RMResource; +import org.tizen.efluibuilder.model.descriptors.TypeDescriptor; +import org.tizen.efluibuilder.ui.resources.ImageResources; +import org.tizen.efluibuilder.ui.views.properties.PropertiesConstant; + + +/** + * A ImageMethod for IMAGE type in the {@link TypeDescriptor.Types} + */ +public class ImageEditable extends ResourceEditable { + + /** + * Constructor. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param style + * the style of widget to construct + * @param type + * a {@link MethodType} + * @param name + * property name + * @param value + * property value + * @param displayName + * display name + * @param hasFunc + * true if the Method has function button, and false + * otherwise + * @see ResourceEditable + */ + public ImageEditable(Composite parent, int style, MethodType type, String name, String value, String displayName, boolean hasFunc) { + super(parent, style, type, name, value, displayName, hasFunc, RMResource.IMAGE); + Image image = ImageResources.getImage(ImageResources.METHOD_IMAGE); + setDialogButtonImage(image); + } + + @Override + protected String[] getFilterExtensions() { + String[] s = { PropertiesConstant.DIALOG_FILTER_JPG + BuilderConstants.SEMICOLON + PropertiesConstant.DIALOG_FILTER_JPEG // JPEG + , PropertiesConstant.DIALOG_FILTER_PNG // PNG + , PropertiesConstant.DIALOG_FILTER_GIF // GIF + , PropertiesConstant.DIALOG_FILTER_ICO // ICO + , + PropertiesConstant.DIALOG_FILTER_JPG + BuilderConstants.SEMICOLON + PropertiesConstant.DIALOG_FILTER_PNG + BuilderConstants.SEMICOLON + + PropertiesConstant.DIALOG_FILTER_GIF // All + // Image + // Files + , PropertiesConstant.DIALOG_FILTER_ALL }; // ALL + + return s; + } + + @Override + protected String[] getFilterNames() { + String[] s = { PropertiesConstant.DIALOG_FILTER_NAME_JPEG, PropertiesConstant.DIALOG_FILTER_NAME_PNG, PropertiesConstant.DIALOG_FILTER_NAME_GIF, + PropertiesConstant.DIALOG_FILTER_NAME_ICO, PropertiesConstant.DIALOG_FILTER_NAME_ALL_IMAGE, PropertiesConstant.DIALOG_FILTER_NAME_ALL }; + + return s; + } + + @Override + protected int getDefaultIndex() { + return 4; + } + + @Override + public void setValue(String value) { + switch (getType()) { + case STYLE: + if (!value.isEmpty() && !value.startsWith("url")) { + value = "url(\'" + value + "\')"; + } + + break; + case ATTRIBUTE: + case EVENT_HANDLER: + default: + break; + } + super.setValue(value); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/IntegerEditable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/IntegerEditable.java new file mode 100644 index 0000000..a1346f3 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/IntegerEditable.java @@ -0,0 +1,58 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import org.eclipse.swt.widgets.Composite; + + +/** + * A IntegerMethod for INTEGER type property. + */ +public class IntegerEditable extends TextEditable { + + /** + * Constructor. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param style + * the style of widget to construct + * @param type + * a {@link MethodType} + * @param name + * property name + * @param value + * property value + * @param displayName + * display name + * @param hasFunc + * true if the Method has function button, and false + * otherwise + * @see Editable + */ + public IntegerEditable(Composite parent, int style, MethodType type, String name, String value, String displayName, boolean hasFunc) { + + super(parent, style, type, name, value, displayName, hasFunc); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ItemAddEditable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ItemAddEditable.java new file mode 100644 index 0000000..6e530bb --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ItemAddEditable.java @@ -0,0 +1,184 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.tizen.efluibuilder.model.descriptors.TypeDescriptor; + + +/** + * A UrlMethod for URL type in the {@link TypeDescriptor.Types} + */ +public class ItemAddEditable extends Editable { + + private SelectionListener listener; + private Button button; + + /** + * Constructor. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param style + * the style of widget to construct + * @param type + * a {@link MethodType} + * @param name + * property name + * @param value + * property value + * @param displayName + * display name + * @param hasFunc + * true if the Method has function button, and false + * otherwise + * @see Editable + */ + public ItemAddEditable(Composite parent, int style, MethodType type, String name, String value, String displayName, boolean hasFunc) { + super(parent, style, type, name, value, displayName, hasFunc); + } + + @Override + protected Control createControl() { + // Control combo = super.createControl(); + /* + * spinner = new Spinner(this, SWT.BORDER); spinner.setMinimum(0); + * spinner.setMaximum(99999); spinner.setIncrement(1); spinner.setTextLimit(4); + * spinner.setSelection(0); + * + * Listener spinnerListener = createSpinnerListener(this); spinner.addListener(SWT.Traverse, + * spinnerListener); // spinner.addListener(SWT.FocusIn, spinnerListener); + * spinner.addListener(SWT.FocusOut, spinnerListener); // spinner.addListener(SWT.MouseDown, + * spinnerListener); // spinner.addListener(SWT.MouseUp, spinnerListener); // + * spinner.addListener(SWT.MouseDoubleClick, spinnerListener); + * spinner.addListener(SWT.Verify, spinnerListener); + * + * return spinner; + * + * //spinner.addListener(SWT.Traverse, comboListener); + * + * //return spinner; + */ + + button = new Button(this, SWT.PUSH); + button.setText("Add item"); + listener = createAddButtonListener(this); + button.addSelectionListener(listener); + return button; + } + + @Override + public void dispose() { + // if (spinner != null && !spinner.isDisposed()) { + // spinner.removeListener(SWT.Traverse, listener); + // spinner.removeListener(SWT.FocusOut, listener); + // spinner.removeListener(SWT.Verify, listener); + // } + + if (button != null && !button.isDisposed()) { + button.removeSelectionListener(listener); + } + super.dispose(); + } + + // @Override + // public void setValue(String value) { + // if (value == null) { + // return; + // } + // super.setValue(value); + // } + + // @Override + // public void refreshValue(String name, String value) { + // super.refreshValue(name, value); + // + // // Spinner spinner = (Spinner) getControl(); + // // spinner.setSelection(Integer.parseInt(value)); + // } + + // @Override + // public void setDefaultValue(String defaultValue) { + // super.setDefaultValue(defaultValue); + // + // Spinner spinner = (Spinner) getControl(); + // if (defaultValue != null && !defaultValue.isEmpty()) { + // spinner.setSelection(Integer.parseInt(defaultValue)); + // setValue(defaultValue); + // } else { + // spinner.setSelection(0); + // setValue("0"); + // } + // } + + protected SelectionListener createAddButtonListener(final Editable target) { + SelectionListener listener = new SelectionListener() { + private Editable method = target; + private int index = 0; + + @Override + public void widgetSelected(SelectionEvent e) { + String str = Integer.toString(index++); + method.setValue(str); + method.enableFuncButton(false); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }; + return listener; + } + + /* + * private Listener createSpinnerListener(final Method target) { Listener textListener = new + * Listener() { + * + * private Method method = target; // private boolean hasFocus = false; // private boolean + * hadFocusOnMousedown = false; + * + * @Override public void handleEvent(Event event) { //Spinner spinner = (Spinner) event.widget; + * + * if (spinner != method.getControl()) { return; } + * + * switch (event.type) { case SWT.Traverse: if (event.detail == SWT.TRAVERSE_RETURN) { + * method.setValue(spinner.getText()); } else if (event.detail == SWT.TRAVERSE_ESCAPE) { + * method.refreshValue(method.getMethodName(), method.getValue()); } + * + * break; // case SWT.FocusIn: // // text.selectAll(); // spinner.getDisplay().asyncExec(new + * Runnable() { // // @Override // public void run() { // hasFocus = true; // } // }); // break; + * case SWT.FocusOut: method.setValue(spinner.getText()); //hasFocus = false; break; // case + * SWT.MouseDown: // hadFocusOnMousedown = hasFocus; // break; // case SWT.MouseUp: // if + * (!hadFocusOnMousedown) { // spinner.setFocus(); // // text.selectAll(); // } // break; // + * case SWT.MouseDoubleClick: // method.setValue(spinner.getText()); // break; case SWT.Verify: + * if (event.keyCode == 0) { method.setValue(spinner.getText()); } break; default: break; } } }; + * + * return textListener; } + */ +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/LayoutResourceEditable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/LayoutResourceEditable.java new file mode 100644 index 0000000..76bd72a --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/LayoutResourceEditable.java @@ -0,0 +1,91 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.tizen.efluibuilder.gef.dnd.model.RMResource; +import org.tizen.efluibuilder.model.descriptors.TypeDescriptor; +import org.tizen.efluibuilder.ui.resources.ImageResources; +import org.tizen.efluibuilder.ui.views.properties.PropertiesConstant; + + +/** + * A LayoutResourceMethod for LAYOUT type in the {@link TypeDescriptor.Types} + */ +public class LayoutResourceEditable extends ResourceEditable { + + /** + * Constructor. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param style + * the style of widget to construct + * @param type + * a {@link MethodType} + * @param name + * property name + * @param value + * property value + * @param displayName + * display name + * @param hasFunc + * true if the Method has function button, and false + * otherwise + * @see ResourceEditable + */ + public LayoutResourceEditable(Composite parent, int style, MethodType type, String name, String value, String displayName, boolean hasFunc) { + super(parent, style, type, name, value, displayName, hasFunc, RMResource.LAYOUT); + Image image = ImageResources.getImage(ImageResources.METHOD_IMAGE); + setDialogButtonImage(image); + } + + @Override + protected String[] getFilterExtensions() { + String[] s = { /* PropertiesConstant.DIALOG_FILTER_EDC, */PropertiesConstant.DIALOG_FILTER_EDJ, + /* + * PropertiesConstant.DIALOG_FILTER_EDC + BuilderConstants.SEMICOLON + + * PropertiesConstant.DIALOG_FILTER_EDJ, + */ + PropertiesConstant.DIALOG_FILTER_ALL }; // ALL + + return s; + } + + @Override + protected String[] getFilterNames() { + String[] s = { /* PropertiesConstant.DIALOG_FILTER_NAME_EDC, */PropertiesConstant.DIALOG_FILTER_NAME_EDJ, + /* PropertiesConstant.DIALOG_FILTER_NAME_ALL_LAYOUT, */ + PropertiesConstant.DIALOG_FILTER_NAME_ALL }; + + return s; + } + + @Override + protected int getDefaultIndex() { + return 0; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/NoContentEditable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/NoContentEditable.java new file mode 100644 index 0000000..9d83e0b --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/NoContentEditable.java @@ -0,0 +1,64 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.tizen.efluibuilder.ui.views.properties.PropertiesConstant; + + +/** + * A no content method. It just display the "No selected contents". + */ +public class NoContentEditable extends Editable { + + /** + * Constructor. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param type + * a {@link MethodType} + */ + public NoContentEditable(Composite parent, MethodType type) { + super(parent, SWT.NONE, type, PropertiesConstant.NO_CONTENTS, null, PropertiesConstant.NO_CONTENTS_MSG, false); + } + + @Override + protected FormData getLabelLayoutData() { + FormData data = new FormData(); + data.bottom = new FormAttachment(50, 0); + + return data; + } + + @Override + protected Control createControl() { + return null; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/RMTextEditable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/RMTextEditable.java new file mode 100644 index 0000000..05d8073 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/RMTextEditable.java @@ -0,0 +1,58 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import org.eclipse.swt.widgets.Composite; + + +/** + * A IntegerMethod for INTEGER type property. + */ +public class RMTextEditable extends TextEditable { + + /** + * Constructor. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param style + * the style of widget to construct + * @param type + * a {@link MethodType} + * @param name + * property name + * @param value + * property value + * @param displayName + * display name + * @param hasFunc + * true if the Method has function button, and false + * otherwise + * @see Editable + */ + public RMTextEditable(Composite parent, int style, MethodType type, String name, String value, String displayName, boolean hasFunc) { + + super(parent, style, type, name, value, displayName, hasFunc); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/RadioEditable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/RadioEditable.java new file mode 100644 index 0000000..15736f2 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/RadioEditable.java @@ -0,0 +1,156 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import java.util.List; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.tizen.efluibuilder.model.descriptors.ConstantDescriptor; +import org.tizen.efluibuilder.model.descriptors.TypeDescriptor; + + +/** + * A RadioMethod for ENUM type that item size is 2 in the {@link TypeDescriptor.Types} + */ +public class RadioEditable extends Editable { + + /** + * Constructor. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param style + * the style of widget to construct + * @param type + * a {@link MethodType} + * @param name + * property name + * @param value + * property value + * @param displayName + * display name + * @param hasFunc + * true if the Method has function button, and false + * otherwise + * @see Editable + */ + public RadioEditable(Composite parent, int style, MethodType type, String name, String value, String displayName, boolean hasFunc) { + super(parent, style, type, name, value, displayName, hasFunc); + } + + @Override + protected Control createControl() { + Composite composite = new Composite(this, SWT.NULL); + composite.setLayout(new FormLayout()); + return composite; + } + + @Override + public void refreshValue(String name, String value) { + super.refreshValue(name, value); + + Composite composite = (Composite) getControl(); + + Control[] children = composite.getChildren(); + + for (int i = 0; i < children.length; i++) { + Button child = (Button) children[i]; + if (value.equals(child.getData())) { + child.setSelection(true); + } else { + child.setSelection(false); + } + } + + } + + /** + * Sets items for radio control. + * + * @param items + * list of {@link ConstantDescriptor} + */ + public void setItems(List items) { + Listener listener = createListener(); + + Button cursor = null; + for (ConstantDescriptor item : items) { + Button radio = new Button((Composite) getControl(), SWT.RADIO); + FormData formData = new FormData(); + formData.top = new FormAttachment(0, 4); + formData.left = (cursor == null ? new FormAttachment(0, 0) : new FormAttachment(cursor, 20)); + cursor = radio; + radio.setLayoutData(formData); + radio.setText(item.getDisplayName()); + if (item.getValue().isEmpty()) { + radio.setData(item.getValue()); + } else { + radio.setData(item.getDisplayName()); + } + + if ((getValue().equals(item.getValue()) || (getValue().equals(item.getDisplayName())))) { + radio.setSelection(true); + } + + radio.addListener(SWT.Selection, listener); + } + } + + private Listener createListener() { + Listener listener = new Listener() { + + @Override + public void handleEvent(Event event) { + Button radio = (Button) event.widget; + if (radio.getSelection()) { + setValue((String) radio.getData()); + } + } + }; + + return listener; + } + + @Override + public void setEnabled(boolean enabled) { + super.setEnabled(enabled); + + Composite composite = (Composite) getControl(); + + Control[] children = composite.getChildren(); + + for (int i = 0; i < children.length; i++) { + children[i].setEnabled(enabled); + } + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ResourceEditable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ResourceEditable.java new file mode 100644 index 0000000..536f1a3 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ResourceEditable.java @@ -0,0 +1,159 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.widgets.Composite; +import org.tizen.efluibuilder.gef.dnd.model.RMResource; +import org.tizen.efluibuilder.ui.views.properties.PropertiesConstant; + + +/** + * A ResourceMethod for resource of project. + */ +public class ResourceEditable extends TextEditable { + + /** + * Constructor. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param style + * the style of widget to construct + * @param type + * a {@link MethodType} + * @param name + * property name + * @param value + * property value + * @param displayName + * display name + * @param hasFunc + * true if the Method has function button, and false + * otherwise + * @see TextEditable + */ + public ResourceEditable(Composite parent, int style, MethodType type, String name, String value, String displayName, boolean hasFunc) { + super(parent, style, type, name, value, displayName, hasFunc); + } + + // for RM START + int resourceType; + + /** + * Constructor. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param style + * the style of widget to construct + * @param type + * a {@link MethodType} + * @param name + * property name + * @param value + * property value + * @param displayName + * display name + * @param hasFunc + * true if the Method has function button, and false + * otherwise + * @see TextEditable + */ + public ResourceEditable(Composite parent, int style, MethodType type, String name, String value, String displayName, boolean hasFunc, int resourceType) { + super(parent, style, type, name, value, displayName, hasFunc); + this.resourceType = resourceType; + } + + public String[] getResourceFileExtentions() { + return RMResource.getResourceFileExtentionsByType(resourceType); + } + + // for RM END + + @Override + protected FormData getControlLayoutData() { + return super.getControlLayoutData(); + } + + @Override + public void setControlRightData(int numerator, int offset) { + super.setControlRightData(numerator, offset); + } + + /** + * Gets using extensions for file dialog. + * + * @return string array + * @deprecated This function is deprecated because of unused file selector dialog. (policy of + * resource managing) + */ + @Deprecated + protected String[] getFilterExtensions() { + String[] s = { PropertiesConstant.DIALOG_FILTER_ALL }; + return s; + } + + /** + * Gets using filter name for file dialog. + * + * @return string array + * @deprecated This function is deprecated because of unused file selector dialog. (policy of + * resource managing) * + */ + @Deprecated + protected String[] getFilterNames() { + String[] s = { PropertiesConstant.DIALOG_FILTER_NAME_ALL }; + return s; + } + + /** + * Gets default index. + * + * @return default index + */ + protected int getDefaultIndex() { + return 0; + } + + @Override + public void setEnabled(boolean enabled) { + super.setEnabled(enabled); + // dialogButton.setEnabled(enabled); // commented: for M-Screen > Resource Manager + } + + /** + * Sets dialog button image. + * + * @return string array + * @deprecated This function is deprecated because of unused file selector dialog. (policy of + * resource managing) * + */ + @Deprecated + protected void setDialogButtonImage(Image image) { + // dialogButton.setImage(image); // commented: for M-Screen > Resource Manager + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ScaleEditable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ScaleEditable.java new file mode 100644 index 0000000..9e7fecb --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ScaleEditable.java @@ -0,0 +1,385 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import java.text.DecimalFormat; +import java.util.List; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Scale; +import org.eclipse.swt.widgets.Text; +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.model.descriptors.PropertyConditionDescriptor; +import org.tizen.efluibuilder.model.descriptors.PropertyDescriptor; +import org.tizen.efluibuilder.ui.widgets.TizenScale; +import org.tizen.efluibuilder.utility.PlatformUtil; + + +/** + * This class creates a 'Scale component' and then adds it to the parent {@link Composite}. + */ +public class ScaleEditable extends Editable { + + private TizenScale scale; + private Text scaleValue; + private PropertyDescriptor parentDescriptor; + private Listener listener; + private Listener textListener; + + /** + * Constructor. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param style + * the style of widget to construct + * @param type + * a {@link MethodType} + * @param name + * property name + * @param value + * property value + * @param displayName + * display name + * @param hasFunc + * true if the Method has function button, and false + * otherwise + * @param parentDescriptor + * property descriptor + */ + public ScaleEditable(Composite parent, int style, MethodType type, String name, String value, String displayName, boolean hasFunc, + PropertyDescriptor parentDescriptor) { + super(parent, style, type, name, value, displayName, hasFunc); + this.parentDescriptor = parentDescriptor; + } + + @Override + public void dispose() { + if (scale != null && !scale.isDisposed()) { + scale.removeListener(SWT.MouseUp, listener); + scale.removeListener(SWT.Selection, listener); + } + if (scaleValue != null && !scaleValue.isDisposed()) { + scaleValue.removeListener(SWT.Traverse, textListener); + scaleValue.removeListener(SWT.FocusIn, textListener); + scaleValue.removeListener(SWT.FocusOut, textListener); + scaleValue.removeListener(SWT.MouseDown, textListener); + scaleValue.removeListener(SWT.MouseUp, textListener); + scaleValue.removeListener(SWT.MouseDoubleClick, textListener); + scaleValue.removeListener(SWT.MouseMove, textListener); + scaleValue.removeListener(SWT.Selection, textListener); + } + + super.dispose(); + } + + /* + * (non-Javadoc) + * + * @see org.tizen.webuibuilder.ui.views.properties.method.Method#refreshValue(java.lang.String, + * java.lang.String) + */ + @Override + public void refreshValue(String name, String value) { + Control control = getControl(); + if (control == null || control.isDisposed()) { + return; + } + + if (value == null) { + value = BuilderConstants.EMPTY; + } + + super.refreshValue(name, value); + + if (value != null && !value.isEmpty()) { + scale.setSelection(convertStringToInt(value)); + scaleValue.setText(value); + } + } + + /* + * (non-Javadoc) + * + * @see org.tizen.webuibuilder.ui.views.properties.method.Method#createControl() + */ + @Override + protected Control createControl() { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new FormLayout()); + + /** scale */ + scale = new TizenScale(composite, SWT.HORIZONTAL); + FormData data = new FormData(); + data.left = new FormAttachment(0, 0); + data.top = new FormAttachment(0, 0); + data.height = 24; + if (PlatformUtil.getOS().equals(PlatformUtil.OS_LINUX)) { + data.right = new FormAttachment(100, -45); + } else { + data.right = new FormAttachment(100, -40); + } + scale.setLayoutData(data); + // scale.addListener(SWT.Selection, createScaleListener(this)); + listener = createScaleListener(); + + scale.addListener(SWT.MouseUp, listener); + scale.addListener(SWT.Selection, listener); + + /** scale value */ + scaleValue = new Text(composite, SWT.CENTER | SWT.BORDER); + scaleValue.setTextLimit(4); + data = new FormData(25, 15); + data.left = new FormAttachment(scale, 5); + data.right = new FormAttachment(100, 0); + data.top = new FormAttachment(0); + if (PlatformUtil.getOS().equals(PlatformUtil.OS_LINUX)) { + data.height = 24; + } + scaleValue.setLayoutData(data); + + textListener = createScaleTextListener(); + // scaleValue.addKeyListener(createTextListener(this)); + scaleValue.addListener(SWT.Traverse, textListener); + scaleValue.addListener(SWT.FocusIn, textListener); + scaleValue.addListener(SWT.FocusOut, textListener); + scaleValue.addListener(SWT.MouseDown, textListener); + scaleValue.addListener(SWT.MouseUp, textListener); + scaleValue.addListener(SWT.MouseDoubleClick, textListener); + scaleValue.addListener(SWT.MouseMove, textListener); + scaleValue.addListener(SWT.Selection, textListener); + + return composite; + } + + private Listener createScaleTextListener() { + Listener textListener = new Listener() { + + private boolean hasFocus = false; + private boolean hadFocusOnMousedown = false; + private Point mousePt = null; + + @Override + public void handleEvent(Event event) { + Text text = (Text) event.widget; + + switch (event.type) { + case SWT.Traverse: + if (event.detail == SWT.TRAVERSE_RETURN) { + setValue(convertString(text.getText())); + } else if (event.detail == SWT.TRAVERSE_ESCAPE) { + modifyValue(BuilderConstants.EMPTY); + refreshValue(getMethodName(), getValue()); + } + + break; + case SWT.FocusIn: + // text.selectAll(); + text.getDisplay().syncExec(new Runnable() { + + @Override + public void run() { + hasFocus = true; + } + }); + break; + case SWT.FocusOut: + setValue(convertString(text.getText())); + hasFocus = false; + break; + case SWT.MouseDown: + mousePt = new Point(event.x, event.y); + + hadFocusOnMousedown = hasFocus; + break; + case SWT.MouseUp: + if (mousePt != null) { + mousePt = null; + setValue(convertString(text.getText())); + } + if (!hadFocusOnMousedown) { + text.setFocus(); + // text.selectAll(); + } + break; + case SWT.MouseDoubleClick: + setValue(convertString(text.getText())); + break; + case SWT.MouseMove: { + if (hadFocusOnMousedown) { + // long startTime = System.nanoTime(); + if (text != null && text.getText() != null && mousePt != null) { + int valueInt = 0; + if (!text.getText().equals(BuilderConstants.EMPTY)) { + try { + float valueFloat = Float.parseFloat(text.getText()); + valueInt = Math.round(valueFloat); + // valueInt = Integer.parseInt(combo.getText()); + } catch (Exception e) { + break; + } + } + if (mousePt.y - BuilderConstants.countPerPx > event.y) { + String value = String.valueOf(valueInt + 1); + int max = scale.getMaximum(); + int intValue = convertStringToInt(value); + if (intValue > max) { + value = String.valueOf(max); + intValue = max; + } + + text.setText(value); + modifyValue(convertString(value)); + scale.setSelection(intValue); + mousePt.y = mousePt.y - 10; + } else if (mousePt.y + BuilderConstants.countPerPx < event.y) { + String value = String.valueOf(valueInt - 1); + int min = scale.getMinimum(); + int intValue = convertStringToInt(value); + if (intValue < min) { + value = String.valueOf(min); + intValue = min; + } + + text.setText(value); + modifyValue(convertString(value)); + scale.setSelection(intValue); + mousePt.y = mousePt.y + 10; + } + } + } + } + break; + + case SWT.Selection: { + setValue(convertString(text.getText()), true); + // because not validate from combo box value + } + break; + default: + break; + } + } + }; + + return textListener; + } + + /* + * (non-Javadoc) + * + * @see org.tizen.webuibuilder.ui.views.properties.method.Method#setConditions(java.util.List) + */ + @Override + public void setConditions(List conditions) { + if (conditions.size() > 0) { + if (conditions.get(0).getValue() != null) { + scale.setMinimum(Integer.parseInt(conditions.get(0).getValue())); + scale.setMaximum(Integer.parseInt(conditions.get(1).getValue())); + scale.setIncrement(1); + + String value = getValue(); + if (value == null || value.isEmpty()) { + scale.setSelection(Integer.parseInt(parentDescriptor.getDefaultValue())); + scaleValue.setText(parentDescriptor.getDefaultValue()); + } else { + scale.setSelection(convertStringToInt(value)); + scaleValue.setText(value); + } + } + } + } + + /** + * This method creates a {@link Listener} for the mouse event at the {@link Scale}. + * + * @param target + * own class ({@link Editable}) + * @return a {@link Listener} + */ + private Listener createScaleListener() { + Listener listener = new Listener() { + + @Override + public void handleEvent(Event event) { + String value = String.format("%d", scale.getSelection()); + + switch (event.type) { + case SWT.MouseUp: + scaleValue.setText(value); + setValue(value); + break; + case SWT.Selection: + scaleValue.setText(value); + modifyValue(value); + break; + default: + break; + } + + } + }; + + return listener; + } + + /* + * (non-Javadoc) + * + * @see org.tizen.webuibuilder.ui.views.properties.method.Method#getControlLayoutData() + */ + @Override + protected FormData getControlLayoutData() { + FormData data = super.getControlLayoutData(); + + data.right = new FormAttachment(80, 0); + return data; + } + + private String convertString(String value) { + DecimalFormat format = new DecimalFormat("#"); + return format.format(convertStringToInt(value)); + } + + private int convertStringToInt(String value) { + int realValue = (int) (Float.parseFloat(value)); + return realValue; + } + + @Override + public void setValue(String value) { + if (getValue().equals(value)) { + return; + } + super.setValue(value); + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/StyleEditable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/StyleEditable.java new file mode 100644 index 0000000..c60c9a9 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/StyleEditable.java @@ -0,0 +1,43 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import org.eclipse.swt.widgets.Composite; + + +/** + * Method used on {@link PropertiesTabItem}. + */ +public abstract class StyleEditable extends Editable { + private String selectorName; + + public StyleEditable(Composite parent, int style, MethodType type, String displayName, boolean hasFunc, String selectorName) { + super(parent, style, type, displayName, displayName, displayName, hasFunc); + this.selectorName = selectorName; + } + + public String getSelectorName() { + return selectorName; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/TextEditable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/TextEditable.java new file mode 100644 index 0000000..07642ad --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/TextEditable.java @@ -0,0 +1,120 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Text; +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.model.descriptors.TypeDescriptor; +import org.tizen.efluibuilder.ui.views.properties.PropertiesConstant; +import org.tizen.efluibuilder.utility.PlatformUtil; + + +/** + * A TextMethod for TEXT type in the {@link TypeDescriptor.Types} + */ +public class TextEditable extends Editable { + + /** + * Constructor. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param style + * the style of widget to construct + * @param type + * a {@link MethodType} + * @param name + * property name + * @param value + * property value + * @param displayName + * display name + * @param hasFunc + * true if the Method has function button, and false + * otherwise + * @see Editable + */ + public TextEditable(Composite parent, int style, MethodType type, String name, String value, String displayName, boolean hasFunc) { + super(parent, style, type, name, value, displayName, hasFunc); + } + + @Override + protected Control createControl() { + Text text = new Text(this, SWT.SINGLE | SWT.BORDER); + + Listener textListener = EditableUtil.createTextListener(this); + + text.addListener(SWT.Traverse, textListener); + text.addListener(SWT.FocusIn, textListener); + text.addListener(SWT.FocusOut, textListener); + text.addListener(SWT.MouseDown, textListener); + text.addListener(SWT.MouseUp, textListener); + text.addListener(SWT.MouseDoubleClick, textListener); + + return text; + } + + @Override + public void refreshValue(String name, String value) { + if (value == null) { + // return; //background-image has no default value so it need to null set empty + value = BuilderConstants.EMPTY; + } + super.refreshValue(name, value); + + Text text = (Text) getControl(); + if (!text.isDisposed()) { + text.setText(value); + } + } + + @Override + public void setDefaultValue(String defaultValue) { + super.setDefaultValue(defaultValue); + + Text text = (Text) getControl(); + if (defaultValue != null && !defaultValue.isEmpty()) { + text.setMessage(BuilderConstants.OPEN_BRACKET + PropertiesConstant.TEXT_NONE + BuilderConstants.COLON + defaultValue + + BuilderConstants.CLOSE_BRACKET); + } else { + text.setMessage(PropertiesConstant.NONE); + } + } + + @Override + protected FormData getControlLayoutData() { + FormData data = super.getControlLayoutData(); + if (PlatformUtil.getOS().equals(PlatformUtil.OS_LINUX)) { + data.height = 24; + } + data.width = 215; + return data; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/TextEditor.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/TextEditor.java new file mode 100644 index 0000000..6027461 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/TextEditor.java @@ -0,0 +1,216 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Text; + + +/** + * This class creates a text editor and then adds it to the parent {@link Composite}. + */ +public class TextEditor { + + public static final int VIEW_POINT_X = 80; + public static final int EDITOR_WIDTH = 60; + public static final int EDITOR_HEIGHT = 20; + private static final int LIMITED_LENGTH = 6; + + private Composite parent; + private Label label; + private Text editor; + + private final Color bgColor = new Color(null, 219, 218, 218); + + /** + * Construct + * + * @param parent + * the parent {@link Composite} + * @param input + * initial value + */ + public TextEditor(final Composite parent, String input) { + this.parent = parent; + label = new Label(this.parent, SWT.CENTER | SWT.READ_ONLY | SWT.BORDER); + editor = new Text(this.parent, SWT.CENTER | SWT.BORDER); + + label.setText(input); + /** set default background color */ + label.setBackground(bgColor); + editor.setTextLimit(LIMITED_LENGTH); + } + + /** + * This method shows the {@link Label} and hides the {@link Text}. + */ + public void showLabel() { + label.setVisible(true); + editor.setVisible(false); + } + + /** + * This method shows the {@link Text} and hides the {@link Label}. + */ + public void showEditor() { + label.setVisible(false); + editor.setVisible(true); + + editor.setText(label.getText()); + editor.selectAll(); + editor.setFocus(); + } + + /** + * This method returns the parent {@link Composite} of the {@link TextEditor}. + * + * @return a {@link Composite} + */ + public Composite getParent() { + return parent; + } + + /** + * This method returns the {@link Label} of the {@link TextEditor}. + * + * @return a {@link Label} + */ + public Label getLabel() { + return label; + } + + /** + * This method returns the {@link Text} of the {@link TextEditor}. + * + * @return a {@link Text} + */ + public Text getEditor() { + return editor; + } + + /** + * This method set value of the {@link Label}. + * + * @param value + * new value of the {@link Label} + */ + public void setLabel(String value) { + if (label == null || label.isDisposed()) { + return; + } + label.setText(value); + } + + /** + * This method set {@link MouseListener} for the mouse event at the {@link Label}. + * + * @param listener + * a {@link MouseListener} + */ + public void setLabelListener(MouseListener listener) { + label.addMouseListener(listener); + } + + /** + * This method set {@link Listener} for the keyboard and mouse event at the {@link Text}. + * + * @param listener + * a {@link Listener} + */ + public void setEditorListener(Listener listener) { + editor.addListener(SWT.FocusOut, listener); + editor.addListener(SWT.Traverse, listener); + editor.addListener(SWT.Deactivate, listener); + } + + /** + * This method set top position of the {@link TextEditor} included in the 'Clip component'. + * + * @param left + * a {@link Label}, which is located on the left side + */ + public void setTopPosition(final Label left) { + FormData topEditorData = new FormData(); + topEditorData.left = new FormAttachment(left, 0); + // topEditorData.top = new FormAttachment(0, VIEW_POINT_Y); + topEditorData.top = new FormAttachment(0, 0); + topEditorData.right = new FormAttachment(left, EDITOR_WIDTH * 2); + // topEditorData.bottom = new FormAttachment(0, VIEW_POINT_Y + EDITOR_HEIGHT); + topEditorData.bottom = new FormAttachment(0, EDITOR_HEIGHT); + label.setLayoutData(topEditorData); + editor.setLayoutData(topEditorData); + } + + /** + * This method set right position of the {@link TextEditor} included in the 'Clip component'. + * + * @param left + * a {@link Label}, which is located on the left side + */ + public void setRightPosition(final Label left) { + FormData rightEditorData = new FormData(); + rightEditorData.left = new FormAttachment(left, 0); + rightEditorData.top = new FormAttachment(0, EDITOR_HEIGHT); + rightEditorData.right = new FormAttachment(left, EDITOR_WIDTH * 2); + rightEditorData.bottom = new FormAttachment(0, EDITOR_HEIGHT * 2); + label.setLayoutData(rightEditorData); + editor.setLayoutData(rightEditorData); + } + + /** + * This method set left position of the {@link TextEditor} included in the 'Clip component'. + */ + public void setLeftPosition() { + FormData rightEditorData = new FormData(); + rightEditorData.left = new FormAttachment(0, VIEW_POINT_X); + rightEditorData.top = new FormAttachment(0, EDITOR_HEIGHT); + rightEditorData.right = new FormAttachment(0, VIEW_POINT_X + EDITOR_WIDTH); + rightEditorData.bottom = new FormAttachment(0, EDITOR_HEIGHT * 2); + label.setLayoutData(rightEditorData); + editor.setLayoutData(rightEditorData); + } + + /** + * This method set bottom position of the {@link TextEditor} included in the 'Clip component'. + * + * @param left + * a {@link Label}, which is located on the left side + */ + public void setBottomPosition(final Label left) { + FormData bottomEditorData = new FormData(); + bottomEditorData.left = new FormAttachment(left, 0); + bottomEditorData.top = new FormAttachment(0, EDITOR_HEIGHT * 2); + bottomEditorData.right = new FormAttachment(left, EDITOR_WIDTH * 2); + bottomEditorData.bottom = new FormAttachment(0, EDITOR_HEIGHT * 3); + label.setLayoutData(bottomEditorData); + editor.setLayoutData(bottomEditorData); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/TextResourceEditable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/TextResourceEditable.java new file mode 100644 index 0000000..f5505d6 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/TextResourceEditable.java @@ -0,0 +1,84 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.tizen.efluibuilder.gef.dnd.model.RMResource; +import org.tizen.efluibuilder.model.descriptors.TypeDescriptor; +import org.tizen.efluibuilder.ui.resources.ImageResources; +import org.tizen.efluibuilder.ui.views.properties.PropertiesConstant; + + +/** + * A TextResourceMethod for TEXTRESOURCE type in the {@link TypeDescriptor.Types} + */ +public class TextResourceEditable extends ResourceEditable { + + /** + * Constructor. + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param style + * the style of widget to construct + * @param type + * a {@link MethodType} + * @param name + * property name + * @param value + * property value + * @param displayName + * display name + * @param hasFunc + * true if the Method has function button, and false + * otherwise + * @see ResourceEditable + */ + public TextResourceEditable(Composite parent, int style, MethodType type, String name, String value, String displayName, boolean hasFunc) { + super(parent, style, type, name, value, displayName, hasFunc, RMResource.TXT); + Image image = ImageResources.getImage(ImageResources.METHOD_IMAGE); + setDialogButtonImage(image); + } + + @Override + protected String[] getFilterExtensions() { + String[] s = { PropertiesConstant.DIALOG_FILTER_TXT, PropertiesConstant.DIALOG_FILTER_ALL }; // ALL + + return s; + } + + @Override + protected String[] getFilterNames() { + String[] s = { PropertiesConstant.DIALOG_FILTER_NAME_TXT, PropertiesConstant.DIALOG_FILTER_NAME_ALL }; + + return s; + } + + @Override + protected int getDefaultIndex() { + return 0; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/TextStyleEditable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/TextStyleEditable.java new file mode 100644 index 0000000..f345685 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/TextStyleEditable.java @@ -0,0 +1,320 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import java.util.List; + +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.widgets.Composite; +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.model.descriptors.PropertyDescriptor; + + +/** + * This class creates a 'Text group component' and then adds it to the parent {@link Composite}. + */ +public class TextStyleEditable extends GroupEditable { + + /** + * Construct + * + * @param parent + * a widget which will be the parent of the new instance (cannot be null) + * @param style + * the style of widget to construct + * @param type + * a {@link MethodType} + * @param name + * property name + * @param value + * property value + * @param displayName + * display name + * @param hasFunc + * true if the Method has function button, and false + * otherwise + * @param model + * a {@link Object} + * @param parentDescriptor + * property descriptor + */ + public TextStyleEditable(Composite parent, int style, MethodType type, String name, String value, String displayName, boolean hasFunc, Object model, + PropertyDescriptor parentDescriptor) { + super(parent, style, type, name, value, displayName, hasFunc, model, parentDescriptor); + } + + /* + * (non-Javadoc) + * + * @see org.tizen.webuibuilder.ui.views.properties.method.GroupMethod#createChildMethods() + */ + protected void createChildMethods() { + PropertyDescriptor parentDescriptor = getParentDescriptor(); + if (parentDescriptor == null) { + return; + } + + EditableCreationFactory factory = EditableCreationFactory.getInstance(); + List methods = getChildMethods(); + List children = parentDescriptor.getChildPropertyDescriptors(); + + // int methodSize = methods.size(); + // int widthMargin = 4; + int heightMargin = 4; + + for (int index = 0; index < children.size(); index++) { + PropertyDescriptor child = children.get(index); + String value = getChildValue(child.getPropertyName()); + + Editable method = factory.createMethod(getControl(), child, value, MethodType.STYLE, false); + if (method == null) { + continue; + } else { + FormData data = new FormData(); + + switch (index) { + case 0: + /** font-family */ + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(49, 0); + break; + case 1: + /** font-size */ + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(methods.get(0), 5); + data.right = new FormAttachment(100, 0); + break; + case 2: + /** group-icon (font-weight / font-style / font-decoration) */ + data.top = new FormAttachment(methods.get(0), heightMargin); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(40, 0); + break; + case 3: + /** text-transform */ + data.top = new FormAttachment(methods.get(0), heightMargin); + data.left = new FormAttachment(methods.get(index - 1), 0); + data.right = new FormAttachment(70, 0); + break; + case 4: + /** color */ + data.top = new FormAttachment(methods.get(0), heightMargin); + data.left = new FormAttachment(methods.get(index - 1), 0); + data.right = new FormAttachment(100, 0); + break; + case 5: + /** text-align */ + data.top = new FormAttachment(methods.get(2), heightMargin); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(40, 0); + break; + case 6: + /** vertical-align */ + data.top = new FormAttachment(methods.get(2), heightMargin); + data.left = new FormAttachment(methods.get(index - 1), 0); + data.right = new FormAttachment(70, 0); + break; + case 7: + /** letter-spacing */ + data.top = new FormAttachment(methods.get(5), heightMargin); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(49, 0); + break; + case 8: + /** line-height */ + data.top = new FormAttachment(methods.get(5), heightMargin); + data.left = new FormAttachment(51, 0); + data.right = new FormAttachment(100, 0); + break; + case 9: + /** stroke-color */ + data.top = new FormAttachment(methods.get(7), heightMargin); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(49, 0); + break; + case 10: + /** stroke-width */ + data.top = new FormAttachment(methods.get(7), heightMargin); + data.left = new FormAttachment(51, 0); + data.right = new FormAttachment(100, 0); + break; + case 11: + /** text-shadow */ + data.top = new FormAttachment(methods.get(9), heightMargin); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(100, 0); + // labelPosition = 17; + break; + default: + break; + } + + method.setControlRightData(100, 0); + method.setValueChangedListener(this); + method.setLayoutData(data); + method.setLabelRightData(0, 65); + method.setLabelTooltipText(child.getPropertyName()); + methods.add(method); + } + + addChildKeyValue(child.getPropertyName(), value); + } + } + + /* + * (non-Javadoc) + * + * @see org.tizen.webuibuilder.ui.views.properties.method.GroupMethod#valueChanged(org.tizen. + * webuibuilder .ui.views.properties.method.MethodEvent) + */ + // @Override + // public void valueChanged(MethodEvent event) { + // String childKey = event.getKey(); + // String childValue = event.getValue(); + // Method childMethod = event.getMethod(); + // + // if (childKey == null || childValue == null) { + // return; + // } + // + // String message = validateStyle(childKey, childValue, childMethod); + // if (!message.equals(ComponentValidator.OK)) { + // refresh(); + // childMethod.showErrorToolTip(message); + // return; + // } + // + // StringBuilder builder = new StringBuilder(childKey); + // builder.append(BuilderConstants.COLON); + // builder.append(childValue); + // recentEditedMethod = event.getMethod(); + // setValue(builder.toString(), true); + // } + + @Override + public void valueModified(EditableEvent event) { + String childKey = event.getKey(); + String childValue = event.getValue(); + + if (childKey == null || childValue == null) { + return; + } + + modifyValue(childKey, childValue); + } + + /* + * (non-Javadoc) + * + * @see org.tizen.webuibuilder.ui.views.properties.method.Method#setValue(java.lang.String, + * boolean) + */ + @Override + public void setValue(String value, boolean undoable) { + if (value != null && !value.isEmpty()) { + String[] values = value.split(":"); + + String realKey = values[0]; + String realValue = BuilderConstants.EMPTY; + if (values.length > 1) { + realValue = values[1]; + } + // refreshValue(realKey, realValue); + hideErrorTooltip(); + + IValueChangeListener listener = getValueChangedListener(); + + if (listener != null) { + listener.valueChanged(new EditableEvent(this, realKey, realValue, undoable)); + } + } else { + /** value is null !! */ + } + } + + /* + * (non-Javadoc) + * + * @see + * org.tizen.webuibuilder.ui.views.properties.method.GroupMethod#refreshValue(java.lang.String, + * java.lang.String) + */ + @Override + public void refreshValue(String name, String value) { + + if (name != null && name.equals(getMethodName()) && (value == null || value.isEmpty() || value.equals("none"))) { + resetChilden(); + return; + } + if (name == null) { + name = BuilderConstants.EMPTY; + } + + addChildKeyValue(name, value); + + Editable child = getChildMethod(name); + if (child != null) { + child.refreshValue(name, value); + } + } + + /* + * (non-Javadoc) + * + * @see + * org.tizen.webuibuilder.ui.views.properties.method.GroupMethod#getChildMethod(java.lang.String + * ) + */ + @Override + public Editable getChildMethod(String key) { + for (Editable child : getChildMethods()) { + if (child.getMethodName().equals(key)) { + return child; + } else if (child instanceof GroupEditable) { + GroupEditable groupChild = (GroupEditable) child; + Editable descendant = groupChild.getChildMethod(key); + if (descendant != null) { + return descendant; + } + } + } + return null; + } + + @Override + public void refresh() { + // / Do nothing + return; + } + + @Override + protected String getResultValue(String childKey, String childValue) { + StringBuilder builder = new StringBuilder(childKey); + builder.append(BuilderConstants.COLON); + builder.append(childValue); + return builder.toString(); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/UserColorData.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/UserColorData.java new file mode 100644 index 0000000..7b1d889 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/UserColorData.java @@ -0,0 +1,110 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.method; + +import org.eclipse.swt.graphics.RGB; + + +/** + * This class creates a color data model that contains Alpha value and {@link RGB} value. + */ +public class UserColorData { + + private ColorData color; + private int labelWidth; + private int labelHeight; + + /** + * Construct + * + * @param color + * custom {@link ColorData} + * @param width + * width of the area to represent the custom color + * @param height + * height of the area to represent the custom color + */ + public UserColorData(ColorData color, int width, int height) { + this.color = color; + labelWidth = width; + labelHeight = height; + } + + /** + * This method returns color data. + * + * @return a {@link ColorData} + */ + public ColorData getColorData() { + return color; + } + + /** + * This method returns width of the area to represent the custom color. + * + * @return width of the area to represent the custom color + */ + public int getLabelWidth() { + return labelWidth; + } + + /** + * Thid method returns height of the area to represent the custom color. + * + * @return height of the area to represent the custom color + */ + public int getLabelHeight() { + return labelHeight; + } + + /** + * This method set color data. + * + * @param color + * new {@link ColorData} + */ + public void setColorData(ColorData color) { + this.color = color; + } + + /** + * This method set width of the area to represent the custom color. + * + * @param width + * width of the area to represent the custom color + */ + public void setLabelWidth(int width) { + labelWidth = width; + } + + /** + * This method set height of the area to represent the custom color. + * + * @param height + * height of the area to represent the custom color + */ + public void setLabelHeight(int height) { + labelHeight = height; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ViewsComboEditable.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ViewsComboEditable.java new file mode 100755 index 0000000..4b90bf0 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/method/ViewsComboEditable.java @@ -0,0 +1,114 @@ +/* + * UI Builder - StoryBoard + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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: + * - Samsung R&D Institute India, Bangalore + * + */ + + +package org.tizen.efluibuilder.ui.views.properties.method; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.ui.views.properties.method.Editable; + + +/** + * A combo method to show the views for selecting target view of connection. + */ +public class ViewsComboEditable extends Editable { + + private List views; + private SelectionAdapter comboListener = new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + selectedCombo(); + } + }; + + public ViewsComboEditable(Composite parent, int style, MethodType type, String name, String value, String displayName, boolean hasFunc) { + super(parent, style, type, name, value, displayName, hasFunc); + } + + @Override + protected Control createControl() { + Combo combo = new Combo(this, SWT.READ_ONLY | SWT.DROP_DOWN); + return combo; + } + + public void setItems(List views) { + if (getControl().isDisposed()) { + return; + } + this.views = views; + Combo combo = (Combo) getControl(); + + List temp = new ArrayList(); + for (Part view : views) { + temp.add(view.getPropertyValue(LayoutSchemaConstants.ID)); + } + String[] names = temp.toArray(new String[0]); + + combo.setItems(names); + combo.select(0); + + combo.addSelectionListener(comboListener); + refreshValue(getMethodName(), getValue()); + } + + @Override + public void dispose() { + Combo combo = (Combo) getControl(); + if (combo != null && !combo.isDisposed()) { + combo.removeSelectionListener(comboListener); + } + + super.dispose(); + } + + protected void selectedCombo() { + Part selectedView = views.get(((Combo) getControl()).getSelectionIndex()); + setValue(selectedView.getPropertyValue(LayoutSchemaConstants.ID)); + } + + @Override + public void refreshValue(String name, String value) { + if (value == null) { + value = BuilderConstants.EMPTY; + } + super.refreshValue(name, value); + if (views != null) { + for (int i = 0, cnt = views.size(); i < cnt; i++) { + if (value != null && value.equals(views.get(i).getPropertyValue(LayoutSchemaConstants.ID))) { + ((Combo) getControl()).select(i); + } + } + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/style/ComponentDesignerExecuter.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/style/ComponentDesignerExecuter.java new file mode 100644 index 0000000..50771f5 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/style/ComponentDesignerExecuter.java @@ -0,0 +1,169 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.style; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.common.core.application.InstallPathConfig; +import org.tizen.common.util.FileUtil; +import org.tizen.common.util.HostUtil; +import org.tizen.common.util.OSChecker; + + +public class ComponentDesignerExecuter { + private static final String OPTION_W = "-w"; //$NON-NLS-1$ + private static final String OPTION_O = "-o"; //$NON-NLS-1$ + private static final String OPTION_EXPORT_EDJ = "--export-edj"; //$NON-NLS-1$ + private static final String OPTION_EXPORT_EDC = "--export-edc"; //$NON-NLS-1$ + private static final String ENV_FORMAT_WINDOWS = "set path=%s;%s;%s &&"; //$NON-NLS-1$ + private static final String ENV_FORMAT_MAC = "PATH=%s:$PATH DYLD_LIBRARY_PATH=%s FONTCONFIG_PATH=%s"; //$NON-NLS-1$ + private static final String ENV_FORMAT_LINUX = "PATH=%s:$PATH LD_LIBRARY_PATH=%s:%s:$LD_LIBRARY_PATH PKG_CONFIG_PATH=%s"; //$NON-NLS-1$ + private static final String EXECUTE_FILE_NAME = "eflete"; //$NON-NLS-1$ + + private static Logger logger = LoggerFactory.getLogger(ComponentDesignerExecuter.class); + + /** + * To run the Component designer, call this method with some arguments. some arguments is + * required, and others is optional. + * + * @param widgetName + * required (not null) + * @param srcStyleName + * required (not null) + * @param srcItemStyleName + * optional (this is needed when you edit an itemStyle.) + * @param exportStyleName + * optional (If this is null, style will be overwritten as same name,). + * @param sourceEDJPath + * required (not null) + * @param exportEDJpath + * optional (If this is null, style will be overwritten to srcEDJPath.) + * @param exportEDCpath + * edc will be exported several files. so this param must be a directory. optional + * (If this is null, edc files will not be exported.) + */ + public static void executeTool(String widgetName, String srcStyleName, String srcItemStyleName, + String exportStyleName, String srcEDJPath, String exportEDJpath, String exportEDCpath) { + final String command = getCommand(widgetName, srcStyleName, srcItemStyleName, exportStyleName, + srcEDJPath, exportEDJpath, exportEDCpath); + logger.debug(command); + new Thread(new Runnable() { + @Override + public void run() { + HostUtil.returnExecute(command, null, false); + } + }).start(); + } + + /* + * In Ubuntu, execute command is like following as : {env} {tool execute binary} --export-edj + * {exportEDJ} --export-edc {exportEDC} -w {widget}:{srcStyle}:{srcItemStyle}[{exportEDJpath}] + * {srcEDJ} + */ + private static String getCommand(String widgetName, String srcStyleName, String srcItemStyleName, + String exportStyleName, String srcEDJPath, String exportEDJPath, String exportEDCPath) { + String env = getEnv(); + String ExecuteToolBinaryPath = getPathOfExecuteBinaryofTool(); + String exportFileOption = getExportFileOption(exportEDJPath, exportEDCPath); + String styleOption = getStyleOption(widgetName, srcStyleName, srcItemStyleName, exportStyleName); + String redirectStream = ""; + if (OSChecker.isWindows()) { + redirectStream = "1> NUL 2> NUL"; //$NON-NLS-1$ + } else { + redirectStream = "1> /dev/null 2> /dev/null"; //$NON-NLS-1$ + } + return env + " " + ExecuteToolBinaryPath + " " + exportFileOption + " " + styleOption + " " + srcEDJPath + " " + redirectStream; + } + + private static String getEnv() { + String fullpathOfEflTool = getFullPathOfEflTool(); + String fullpathOfComponentDesigner = getFullPathOfComponentDesigner(); + String eflToolBin = FileUtil.appendPath(fullpathOfEflTool, "bin"); //$NON-NLS-1$ + String eflToolLib = FileUtil.appendPath(fullpathOfEflTool, "lib"); //$NON-NLS-1$ + + if (OSChecker.isWindows()) { + String componentDesignerBin = FileUtil.appendPath(fullpathOfComponentDesigner, "bin"); //$NON-NLS-1$ + return String.format(ENV_FORMAT_WINDOWS, eflToolBin, componentDesignerBin, "%path%"); //$NON-NLS-1$ + } else if (OSChecker.isMAC()) { + String fontConfig = FileUtil.appendPath(fullpathOfEflTool, "etc"); //$NON-NLS-1$ + fontConfig = FileUtil.appendPath(fontConfig, "font"); //$NON-NLS-1$ + return String.format(ENV_FORMAT_MAC, eflToolBin, eflToolLib, fontConfig); + } else { + // export + // LD_LIBRARY_PATH=~/tizen-studio/tools/efl-tools/lib/:~/tizen-studio/tools/component-designer/lib + // export PKG_CONFIG_PATH=~/tizen-studio/tools/efl-tools/lib/pkgconfig + // export PATH=~/tizen-studio/tools/efl-tools/bin:$PATH + String componentDesignerLib = FileUtil.appendPath(fullpathOfComponentDesigner, "lib"); //$NON-NLS-1$ + String eflToolPkgConfig = FileUtil.appendPath(eflToolLib, "pkgconfig"); //$NON-NLS-1$ + return String.format(ENV_FORMAT_LINUX, eflToolBin, eflToolLib, componentDesignerLib, eflToolPkgConfig); + } + } + + private static String getFullPathOfEflTool() { + IPath path = new Path(InstallPathConfig.getToolsPath()).append("efl-tools"); //$NON-NLS-1$ + return path.toOSString(); + } + + private static String getFullPathOfComponentDesigner() { + IPath path = new Path(InstallPathConfig.getToolsPath()).append("component-designer"); //$NON-NLS-1$ + return path.toOSString(); + } + + private static String getPathOfExecuteBinaryofTool() { + String pathOfComponentDesigner = getFullPathOfComponentDesigner(); + String binPath = FileUtil.appendPath(pathOfComponentDesigner, "bin"); //$NON-NLS-1$ + return FileUtil.appendPath(binPath, EXECUTE_FILE_NAME); // All of OS(Windows, Mac, Linux) + // are same. + } + + private static String getExportFileOption(String exportEDJPath, String exportEDCPath) { + String option = ""; + if (exportEDJPath != null) { + option += OPTION_EXPORT_EDJ + " " + exportEDJPath + " "; + } + // if (exportEDCPath != null) { + // option += OPTION_EXPORT_EDC + " " + exportEDCPath; + // } + return option; + } + + // -w widget:srcStyle{srcItemStyle[exportItemStyleName]}[exportStyleName] + private static String getStyleOption(String widgetName, String srcStyleName, String srcItemStyleName, + String exportStyleName) { + String option = OPTION_O + " " + OPTION_W + " " + widgetName + ":" + srcStyleName; + if (srcItemStyleName != null) { + option += "{" + srcItemStyleName; + } + if (exportStyleName != null) { + option += "[" + exportStyleName + "]"; + } + if (srcItemStyleName != null) { + option += "}"; + } + option = option.replaceAll("&", "\"&\""); + return option; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/style/StyleEDJManager.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/style/StyleEDJManager.java new file mode 100644 index 0000000..cd2798e --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/style/StyleEDJManager.java @@ -0,0 +1,287 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.style; + +import java.io.File; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.core.resources.IProject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.common.core.application.InstallPathConfig; +import org.tizen.common.core.application.ProfileInfo; +import org.tizen.common.core.application.ProfileVersionInfo; +import org.tizen.efluibuilder.core.configurator.ConfiguratorConstants; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.renderer.IArguments; +import org.tizen.efluibuilder.renderer.IRenderer; +import org.tizen.efluibuilder.renderer.IRendererListener; +import org.tizen.efluibuilder.renderer.RendererConstants; +import org.tizen.efluibuilder.renderer.RendererFactory; +import org.tizen.efluibuilder.renderer.event.RenderEvent; +import org.tizen.efluibuilder.utility.PlatformUtil; + +import edjResourceSyncManager.EdjResourceChangedEvent; +import edjResourceSyncManager.EdjResourceSyncManager; +import edjResourceSyncManager.IEdjResourceChangeListener; +import edjResourceSyncManager.ResourceFileDuplicator; + + +public class StyleEDJManager implements IRendererListener, IEdjResourceChangeListener { + private static Logger logger = LoggerFactory.getLogger(StyleEDJManager.class); + // To efl-renderer + private final static String DES_RES_ELM_THEME_PATH = "./res/theme/"; //$NON-NLS-1$ + private final static String PATH_RESOURCE = "res"; //$NON-NLS-1$ + private final static String PATH_CUSTOM_THEME = "theme"; //$NON-NLS-1$ + private final static String CUSTOM_STYLE_EDJ = "custom_theme.edj"; //$NON-NLS-1$ + private final static String DEFAULT_THEME_PATH = "efl-tool" + File.separator + "efl-renderer" + File.separator + "res" + File.separator + "theme"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + private Part documentPart; + private IProject project; + private String version; + private String profile; + private List defaultEDJs; + // Key : Widget, Value : Map> + private Map>> customStyleInfo = new HashMap>>(); + // Key : "full path of defaultEDJ", Value : "Map>>" + private Map>>> defaultStyleInfo = new HashMap>>>(); + private IRenderer renderer; + private ResourceFileDuplicator resFileDuplicator = null; + private boolean isRendererInitialized; + + public StyleEDJManager(Part documentPart, IProject project, String version, String profile, List defaultEDJs, + ResourceFileDuplicator resFileDuplicator) { + this.documentPart = documentPart; + this.project = project; + this.version = version; + this.profile = profile; + this.defaultEDJs = defaultEDJs; + this.resFileDuplicator = resFileDuplicator; + } + + public void init() { + int width = 100; + int height = 100; + RendererFactory factory = RendererFactory.getDefault(); + renderer = factory.create(version, profile, project.getLocation().toString()); + if (renderer != null) { + renderer.setName(""); + renderer.addRendererListener(this); + renderer.create(width, height, getDefaultThemePathForEflRenderer(), getCustomThemePathForEflRenderer()); + } + } + + private String getDefaultStyleEDJPath(String edjFile) { + String eflRendererPath = ""; + if (profile.contains(ConfiguratorConstants.PROFILE_WEARABLE)) { + ProfileInfo profileInfo = InstallPathConfig.getProfileInfo(ConfiguratorConstants.PROFILE_WEARABLE); + if (profileInfo != null) { + ProfileVersionInfo versionInfo = profileInfo.getVersionInfo(version); + eflRendererPath = (versionInfo != null) ? versionInfo.getVersionPath() : ""; + } + } else { + eflRendererPath = InstallPathConfig.getPlatformToolsPath(profile, version); + } + return eflRendererPath + File.separator + DEFAULT_THEME_PATH + File.separator + edjFile; + } + + public void setCustomStyleInfo(Map>> customStyleInfo) { + this.customStyleInfo = customStyleInfo; + } + + public Map>> getCustomStyleNames() { + return customStyleInfo; + } + + public Map>>> getDefaultStyleInfoMap() { + return defaultStyleInfo; + } + + public String getProjectVersion() { + return version; + } + + public Part getDocumentPart() { + return documentPart; + } + + public String findDefaultThemePath(String widgetName, String styleName) { + for (int i = 0; i < defaultEDJs.size(); i++) { + // Key : Widget, Value : Map> + Map>> widgets = defaultStyleInfo.get(getDefaultStyleEDJPath(defaultEDJs.get(i))); + Map> styles = widgets.get(widgetName); + if (styles != null && styles.keySet().contains(styleName)) { + return getDefaultStyleEDJPath(defaultEDJs.get(i)); + } + } + logger.error("Not exist in default theme files (" + widgetName + ", " + styleName + ")"); //$NON-NLS-1$ + return null; + } + + public String findParentStyle(Map> styles, String itemStyleName) { + if (styles != null) { + for (Entry> entry : styles.entrySet()) { + String parentStyle = entry.getKey(); + List itemStyles = entry.getValue(); + if (itemStyles != null) { + for (int i = 0; i < itemStyles.size(); i++) { + if (itemStyles.get(i).equals(itemStyleName)) { + return parentStyle; + } + } + } + } + } + logger.error("Item style(" + itemStyleName + ") has no parent style"); //$NON-NLS-1$ //$NON-NLS-2$ + return null; + } + + public String getDefaultThemePathForEflRenderer() { + StringBuffer themePath = new StringBuffer(); + for (int i = 0; i < defaultEDJs.size(); i++) { + if (i > 0) { + themePath.append(":"); + } + themePath.append(DES_RES_ELM_THEME_PATH + defaultEDJs.get(i)); + } + return themePath.toString(); + } + + public String getCustomThemePathForEflRenderer() { + if (isExistCustomTheme()) { + String customThemePath = getCustomThemePath(); + if (PlatformUtil.getOS().equals(PlatformUtil.OS_WIN32)) { + return resFileDuplicator.copyFileToTempFolder(customThemePath); + } else { + return customThemePath; + } + } + return null; + } + + public void removeStyleFromCustomStyleEDJ(String widgetName, String styleName, String itemStyleName) { + if (renderer != null && isRendererInitialized) { + String path = getCustomThemePath(); + if (path != null) { + if (itemStyleName == null) { + customStyleInfo.get(widgetName).remove(styleName); + } else { + customStyleInfo.get(widgetName).get(styleName).remove(itemStyleName); + } + renderer.requestRemoveStyleName(path, widgetName, styleName, itemStyleName); + } + } + } + + public void overlayTheme() { + if (renderer != null && isRendererInitialized) { + renderer.requestOverlayTheme(getCustomThemePathForEflRenderer()); + } + } + + public boolean createCustomThemeDirectory() { + File themeDirectory = new File(project.getLocation().toString() + File.separator + PATH_RESOURCE + File.separator + PATH_CUSTOM_THEME); + if (!themeDirectory.mkdir()) { + logger.warn("It's failed to make the custom style directory."); //$NON-NLS-1$ + return false; + } + return true; + } + + public String getCustomThemeDirectoryPath() { + if (project != null && project.getLocation() != null) { + return project.getLocation().toString() + File.separator + PATH_RESOURCE + File.separator + PATH_CUSTOM_THEME; + } + return ""; + } + + public String getCustomThemePath() { + return getCustomThemeDirectoryPath() + File.separator + CUSTOM_STYLE_EDJ; + } + + public boolean isExistCustomThemeDirectory() { + return new File(getCustomThemeDirectoryPath()).exists(); + } + + public boolean isExistCustomTheme() { + return new File(getCustomThemePath()).exists(); + } + + @Override + public void replyRender(RenderEvent event) { + // Do nothing + } + + @Override + public void reply(final IArguments message) { + if (message.getId().equals(RendererConstants.EVENT_GET_STYLE_NAMES)) { + String path = (String) message.getArg(0); + @SuppressWarnings("unchecked") + Map>> styleMap = (Map>>) message.getArg(1); + if (path.equals(getCustomThemePath()) == false) { + defaultStyleInfo.put(path, styleMap); + } + } else if (message.getId().equals(RendererConstants.EVENT_CREATE)) { + this.isRendererInitialized = true; + for (int i = 0; i < defaultEDJs.size(); i++) { + renderer.requestGetStyleNames(getDefaultStyleEDJPath(defaultEDJs.get(i))); + } + } else if (message.getId().equals(RendererConstants.EVENT_REMOVE_STYLE_NAME)) { + logger.debug("Received EVENT_REMOVE_STYLE_NAME!!!"); //$NON-NLS-1$ + } else if (message.getId().equals(RendererConstants.EVENT_OVERLAY_THEME)) { + logger.debug("Recevied EVENT_OVERLAY_STYLE!!!"); //$NON-NLS-1$ + } + } + + @Override + public void edjResourceChanged(EdjResourceChangedEvent event) { + if (event.type == EdjResourceChangedEvent.TYPE_CHANGED) { + String filePath = event.path; + if (event.styleNames != null && getCustomThemePath().equals(filePath)) { + logger.debug("custom theme file is changed."); //$NON-NLS-1$ + overlayTheme(); + } + } else if (event.type == EdjResourceChangedEvent.TYPE_REMOVED) { + String filePath = event.path; + if (EdjResourceSyncManager.CUSTOM_STYLE_EDJ.equals(filePath)) { + customStyleInfo = null; + logger.debug("custom theme file is removed."); //$NON-NLS-1$ + overlayTheme(); + } + } + } + + public static boolean isLaterVersion3_0(String version) { + String[] beforeVersions = { + "2.3", + "2.3.1", + "2.3.2", + "2.4" + }; + return (Arrays.asList(beforeVersions).contains(version)) == false; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/style/StyleEditDialog.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/style/StyleEditDialog.java new file mode 100644 index 0000000..40c0747 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/style/StyleEditDialog.java @@ -0,0 +1,420 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.style; + +import java.util.Iterator; + +import org.eclipse.gef.commands.CompoundCommand; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Dialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Widget; +import org.tizen.efluibuilder.model.command.DisableUndoCommand; +import org.tizen.efluibuilder.model.part.ComponentPart; +import org.tizen.efluibuilder.model.part.DocumentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.PartType; +import org.tizen.efluibuilder.model.util.ComponentDescriptor; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.nl.BuilderMessages; +import org.tizen.efluibuilder.ui.resources.ColorResources; +import org.tizen.efluibuilder.ui.resources.ImageResources; +import org.tizen.efluibuilder.ui.views.properties.style.StyleInfo.StyleType; + + +public class StyleEditDialog extends Dialog { + public static final int DIALOG_WIDTH = 510; + public static final int DIALOG_HEIGHT = 260; + private static final int LIST_HEIGHT = 100; + private static final int BUTTON_WIDTH = 86; + private static final int BUTTON_HEIGHT = 24; + + private StyleEditMethod parent; + private StyleEDJManager styleEDJManager = null; + private java.util.List styles; + private Shell shell; + private List listStyle; + private Label lblDescript; + private Button btnExtend; + private Button btnModify; + private Button btnDelete; + private Button btnReset; + + private SelectionListener listStyleSelectionListener = new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + updateButtonState(); + } + }; + + private KeyListener listStyleKeyListener = new KeyAdapter() { + @Override + public void keyReleased(KeyEvent e) { + updateButtonState(); + } + }; + + private SelectionListener btnSelectionListener = new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + StyleInfo styleInfo = getSelectedStyleInfo(); + if (styleInfo == null) { + return; + } + Widget widget = e.widget; + if (widget == btnDelete) { + deleteStyle(true); + listStyle.remove(listStyle.getSelectionIndex()); + updateButtonState(); + } else if (widget == btnReset) { + deleteStyle(false); + int index = listStyle.getSelectionIndex(); + styleInfo.setType(StyleType.DEFAULT); + listStyle.setItem(index, styleInfo.getStyleName()); + updateButtonState(); + } else if (widget == btnModify) { + editStyle(null); + shell.close(); + } else if (widget == btnExtend) { + String exportStyleName = new StyleInputDialog(shell, styleInfo.getStyleName()).open(); + if (exportStyleName != null) { + editStyle(exportStyleName); + shell.close(); + } + } + } + }; + + private DisposeListener shellDisposeListener = new DisposeListener() { + @Override + public void widgetDisposed(DisposeEvent arg0) { + if (listStyle != null && !listStyle.isDisposed()) { + listStyle.removeSelectionListener(listStyleSelectionListener); + listStyle.removeKeyListener(listStyleKeyListener); + } + if (btnDelete != null && !btnDelete.isDisposed()) { + btnDelete.removeSelectionListener(btnSelectionListener); + } + if (btnModify != null && !btnModify.isDisposed()) { + btnModify.removeSelectionListener(btnSelectionListener); + } + if (btnExtend != null && !btnExtend.isDisposed()) { + btnExtend.removeSelectionListener(btnSelectionListener); + } + if (btnReset != null && !btnReset.isDisposed()) { + btnReset.removeSelectionListener(btnSelectionListener); + } + shell.removeDisposeListener(shellDisposeListener); + } + }; + + public StyleEditDialog(Shell parent, java.util.List items, StyleEDJManager styleEDJManager) { + super(parent); + setText(BuilderMessages.COMPONENT_DESIGNER_DIALOG_TITLE); + this.styles = items; + this.styleEDJManager = styleEDJManager; + } + + public StyleEditDialog(StyleEditMethod parent) { + super(parent.getShell()); + setText(BuilderMessages.COMPONENT_DESIGNER_DIALOG_TITLE); + this.styles = parent.getItems(); + this.styleEDJManager = parent.getStyleEDJManager(); + this.parent = parent; + } + + private void createContents(final Shell shell) { + shell.setLayout(new FormLayout()); + + /* + * Label of description + */ + lblDescript = new Label(shell, SWT.WRAP); + FormData formData = new FormData(); + formData.left = new FormAttachment(0, 15); + formData.right = new FormAttachment(100, -15); + formData.top = new FormAttachment(0, 15); + lblDescript.setLayoutData(formData); + lblDescript.setText(BuilderMessages.COMPONENT_DESIGNER_DIALOG_LABEL); + lblDescript.setForeground(ColorResources.PROPERTIES_CD_DESCRIPTOR); + + /* + * List of Styles + */ + listStyle = new List(shell, SWT.BORDER | SWT.V_SCROLL | SWT.SINGLE); + formData = new FormData(); + formData.left = new FormAttachment(0, 10); + formData.right = new FormAttachment(100, -10); + formData.top = new FormAttachment(lblDescript, 10); + formData.height = LIST_HEIGHT; + // if (PlatformUtil.getOS().equals(PlatformUtil.OS_LINUX)) { + // formData.height = 75; + // } else { + // formData.height = LIST_HEIGHT; + // } + listStyle.setLayoutData(formData); + listStyle.addSelectionListener(listStyleSelectionListener); + listStyle.addKeyListener(listStyleKeyListener); + + /* + * Line + */ + Composite lineComp = new Composite(shell, SWT.NONE); + lineComp.setBackground(ColorResources.PROPERTIES_SEPERARTOR); + formData = new FormData(); + formData.top = new FormAttachment(listStyle, 10); + formData.left = new FormAttachment(0, 0); + formData.right = new FormAttachment(100, 0); + formData.height = 1; + lineComp.setLayoutData(formData); + + /* + * Buttons (Delete, Modify, Extend, Reset) + */ + btnDelete = new Button(shell, SWT.PUSH); + btnDelete.setText(BuilderMessages.COMPONENT_DESIGNER_BUTTON_DELETE); + formData = new FormData(); + formData.top = new FormAttachment(lineComp, 18); + formData.left = new FormAttachment(0, 122); + formData.width = BUTTON_WIDTH; + formData.height = BUTTON_HEIGHT; + btnDelete.setLayoutData(formData); + btnDelete.addSelectionListener(btnSelectionListener); + + btnModify = new Button(shell, SWT.PUSH); + btnModify.setText(BuilderMessages.COMPONENT_DESIGNER_BUTTON_MODIFY); + formData = new FormData(); + formData.top = new FormAttachment(lineComp, 18); + formData.left = new FormAttachment(btnDelete, 8); + formData.width = BUTTON_WIDTH; + formData.height = BUTTON_HEIGHT; + btnModify.setLayoutData(formData); + btnModify.addSelectionListener(btnSelectionListener); + + btnExtend = new Button(shell, SWT.PUSH); + btnExtend.setText(BuilderMessages.COMPONENT_DESIGNER_BUTTON_EXTEND); + formData = new FormData(); + formData.top = new FormAttachment(lineComp, 18); + formData.left = new FormAttachment(btnModify, 8); + formData.width = BUTTON_WIDTH; + formData.height = BUTTON_HEIGHT; + btnExtend.setLayoutData(formData); + btnExtend.addSelectionListener(btnSelectionListener); + + btnReset = new Button(shell, SWT.PUSH); + btnReset.setText(BuilderMessages.COMPONENT_DESIGNER_BUTTON_RESET); + formData = new FormData(); + formData.top = new FormAttachment(lineComp, 18); + formData.left = new FormAttachment(btnExtend, 8); + formData.width = BUTTON_WIDTH; + formData.height = BUTTON_HEIGHT; + btnReset.setLayoutData(formData); + btnReset.addSelectionListener(btnSelectionListener); + + updateStylesList(styles); + updateButtonState(); + } + + private void updateButtonState() { + StyleInfo style = getSelectedStyleInfo(); + if (style == null) { + btnDelete.setEnabled(false); + btnModify.setEnabled(false); + btnExtend.setEnabled(false); + btnReset.setEnabled(false); + } else if (style.getType() == StyleType.CUSTOM) { + btnDelete.setEnabled(true); + btnModify.setEnabled(true); + btnExtend.setEnabled(true); + btnReset.setEnabled(false); + } else if (style.getType() == StyleType.MODIFIED) { + btnDelete.setEnabled(false); + btnModify.setEnabled(true); + btnExtend.setEnabled(true); + btnReset.setEnabled(true); + } else { + btnDelete.setEnabled(false); + btnModify.setEnabled(true); + btnExtend.setEnabled(true); + btnReset.setEnabled(false); + } + } + + public void updateStylesList(java.util.List styles) { + this.styles = styles; + listStyle.removeAll(); + for (int i = 0; i < styles.size(); i++) { + listStyle.add(styles.get(i).getDisplayName()); + } + if (listStyle.getItemCount() > 0) { + listStyle.setSelection(0); + } + } + + private void deleteStyle(boolean isCustomStyle) { + StyleInfo style = getSelectedStyleInfo(); + if (style == null) { + return; + } + if (style.isItemStyle()) { + String itemStyle = style.getStyleName(); + String parentStyle = styleEDJManager.findParentStyle(styleEDJManager.getCustomStyleNames().get(style.getWidgetName()), itemStyle); + styleEDJManager.removeStyleFromCustomStyleEDJ(style.getWidgetName(), parentStyle, itemStyle); + } else { + styleEDJManager.removeStyleFromCustomStyleEDJ(style.getWidgetName(), + style.getStyleName(), null); + } + // if custom style is deleted, update models. + if (isCustomStyle) { + Part documentPart = styleEDJManager.getDocumentPart(); + ComponentDescriptor componentDescriptor = ((DocumentPart) documentPart).getComponentDescriptor(); + CompoundCommand compCmd = new DisableUndoCommand(); + updateStyleOfModel(documentPart, componentDescriptor, style, compCmd); + parent.updateStyleAttributes(compCmd); + } + } + + private void updateStyleOfModel(Part part, ComponentDescriptor componentDescriptor, StyleInfo style, CompoundCommand compCmd) { + if (part.getType() == PartType.COMPONENT) { + if ((style.isItemStyle() && style.getWidgetName().equals(componentDescriptor.getWidgetDescriptor(part.getDescriptorId()).getContainerID())) + || (style.isItemStyle() == false && part.getDescriptorId().equals(style.getWidgetName()))) { + String value = part.getPropertyValue(LayoutSchemaConstants.STYLE); + if (value.equals(style.getStyleName())) { + String defaultStyle = + componentDescriptor.getPropertyDescriptor(part.getParent(), (ComponentPart) part, LayoutSchemaConstants.STYLE) + .getDefaultValue(); + compCmd.add(PartUtil.createSetPropertyCommand(part, LayoutSchemaConstants.STYLE, + defaultStyle)); + } + } else { + // Do nothing + } + } + java.util.List children = part.getChildren(); + for (int i = 0; i < children.size(); i++) { + updateStyleOfModel(children.get(i), componentDescriptor, style, compCmd); + } + } + + private void editStyle(String exportStyleName) { + StyleInfo style = getSelectedStyleInfo(); + if (style == null) { + return; + } + String widgetName = style.getWidgetName(); + String srcStyleName = style.getStyleName(); + String srcItemStyleName = null; + if (style.isItemStyle()) { + srcItemStyleName = style.getStyleName(); + } + String srcEDJPath = null; + String exportEDJPath = styleEDJManager.getCustomThemePath(); + String exportEDCPath = styleEDJManager.getCustomThemeDirectoryPath(); + switch (style.getType()) { + case CUSTOM: + case MODIFIED: + srcEDJPath = styleEDJManager.getCustomThemePath(); + if (style.isItemStyle()) { + srcStyleName = styleEDJManager.findParentStyle(styleEDJManager.getCustomStyleNames().get(widgetName), srcItemStyleName); + } + break; + default: + if (style.isItemStyle()) { + Iterator iter = styleEDJManager.getDefaultStyleInfoMap().keySet().iterator(); + while (iter.hasNext()) { + String defaultThemePath = iter.next(); + srcStyleName = + styleEDJManager.findParentStyle(styleEDJManager.getDefaultStyleInfoMap().get(defaultThemePath).get(widgetName), + srcItemStyleName); + if (srcStyleName != null) { + srcEDJPath = defaultThemePath; + break; + } + } + } else { + srcEDJPath = styleEDJManager.findDefaultThemePath(widgetName, srcStyleName); + } + if (styleEDJManager.isExistCustomThemeDirectory() == false) { + styleEDJManager.createCustomThemeDirectory(); + } + break; + } + ComponentDesignerExecuter.executeTool(widgetName, srcStyleName, srcItemStyleName, exportStyleName, srcEDJPath, exportEDJPath, exportEDCPath); + } + + private StyleInfo getSelectedStyleInfo() { + int index = listStyle.getSelectionIndex(); + if (index < 0) { + return null; + } + return styles.get(index); + } + + public void open(int x, int y) { + shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); + shell.addDisposeListener(shellDisposeListener); + shell.setText(getText()); + shell.setImage(ImageResources.getImage(ImageResources.PROPERTIES_CD_ICON)); + shell.setSize(DIALOG_WIDTH, DIALOG_HEIGHT); + // Adjust location as Monitor environment. + Rectangle monitor = shell.getMonitor().getClientArea(); + if (x < 0) { + x = monitor.x; + } else if (x + DIALOG_WIDTH > monitor.x + monitor.width) { + x = monitor.width - DIALOG_WIDTH; + } + if (y < 0) { + y = monitor.y; + } else if (y + DIALOG_HEIGHT > monitor.y + monitor.height) { + y = monitor.height - DIALOG_HEIGHT; + } + shell.setLocation(x, y); + createContents(shell); + shell.open(); + Display display = getParent().getDisplay(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/style/StyleEditMethod.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/style/StyleEditMethod.java new file mode 100644 index 0000000..66ded16 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/style/StyleEditMethod.java @@ -0,0 +1,331 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.style; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.eclipse.gef.commands.Command; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.MouseTrackAdapter; +import org.eclipse.swt.events.MouseTrackListener; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.tizen.common.util.Assert; +import org.tizen.efluibuilder.BuilderConstants; +import org.tizen.efluibuilder.model.descriptors.ConstantDescriptor; +import org.tizen.efluibuilder.ui.resources.ImageResources; +import org.tizen.efluibuilder.ui.views.properties.PropertiesPageComposite; +import org.tizen.efluibuilder.ui.views.properties.method.Editable; +import org.tizen.efluibuilder.ui.views.properties.style.StyleInfo.StyleType; + + +public class StyleEditMethod extends Editable { + private static final int BUTTON_IMAGE_WIDTH = 24; + private static final int METHOD_HEIGHT = 25; + private Combo combo; + private Canvas button; + private PropertiesPageComposite propertiesPage; + private StyleEDJManager styleEDJManager = null; + private List items = null; + + private SelectionListener comboListener; + private PaintListener btnPaintListener; + private MouseListener btnMouseListener; + private MouseTrackListener btnMouseTrackListener; + + /** + * Constructor. + * + * @see Editable + */ + public StyleEditMethod(Composite parent, int style, MethodType type, String name, String value, String displayName, boolean hasFunc) { + super(parent, style, type, name, value, displayName, hasFunc); + } + + @Override + protected Control createControl() { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new FormLayout()); + + FormData layoutData = new FormData(); + + /* + * Combo + */ + layoutData.left = new FormAttachment(0, 0); + layoutData.top = new FormAttachment(0, 0); + layoutData.right = new FormAttachment(100, -28); + layoutData.height = METHOD_HEIGHT; + combo = new Combo(composite, SWT.READ_ONLY | SWT.DROP_DOWN); + combo.setLayoutData(layoutData); + comboListener = new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + int index = combo.getSelectionIndex(); + StyleInfo style = items.get(index); + setValue(style.getStyleName()); + } + }; + combo.addSelectionListener(comboListener); + + /* + * Button + */ + layoutData = new FormData(); + layoutData.top = new FormAttachment(0, 1); + layoutData.left = new FormAttachment(combo, 3); + layoutData.right = new FormAttachment(100, 0); + layoutData.width = BUTTON_IMAGE_WIDTH; + layoutData.height = METHOD_HEIGHT; + + button = new Canvas(composite, SWT.NONE); + button.setLayoutData(layoutData); + button.setData(ImageResources.getImage(ImageResources.PROPERTIES_BTN_IC_LOCATION_NOR)); + btnPaintListener = new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + e.gc.drawImage((Image) button.getData(), 0, 0); + } + }; + button.addPaintListener(btnPaintListener); + btnMouseListener = new MouseAdapter() { + @Override + public void mouseUp(MouseEvent e) { + if (styleEDJManager != null) { + StyleEditDialog editDialog = new StyleEditDialog(StyleEditMethod.this); + Point location = button.toDisplay(button.getSize().x, button.getSize().y); + editDialog.open(location.x - button.getSize().x - StyleEditDialog.DIALOG_WIDTH - 10, location.y); + } else { + logger.error("StyleEditMethod does not have styleEDJManager!!"); //$NON-NLS-1$ + } + button.setData(ImageResources.getImage(ImageResources.PROPERTIES_BTN_IC_LOCATION_NOR)); + button.redraw(); + } + + @Override + public void mouseDown(MouseEvent e) { + button.setData(ImageResources.getImage(ImageResources.PROPERTIES_BTN_IC_LOCATION_SEL)); + button.redraw(); + } + }; + button.addMouseListener(btnMouseListener); + btnMouseTrackListener = new MouseTrackAdapter() { + @Override + public void mouseEnter(MouseEvent arg0) { + button.setData(ImageResources.getImage(ImageResources.PROPERTIES_BTN_IC_LOCATION_OVER)); + button.redraw(); + } + + @Override + public void mouseExit(MouseEvent arg0) { + button.setData(ImageResources.getImage(ImageResources.PROPERTIES_BTN_IC_LOCATION_NOR)); + button.redraw(); + } + }; + button.addMouseTrackListener(btnMouseTrackListener); + return composite; + } + + @Override + public void dispose() { + if (combo != null && !combo.isDisposed()) { + combo.removeSelectionListener(comboListener); + } + if (button != null && !button.isDisposed()) { + button.removePaintListener(btnPaintListener); + button.removeMouseListener(btnMouseListener); + button.removeMouseTrackListener(btnMouseTrackListener); + } + super.dispose(); + } + + public List getItems() { + return items; + } + + public void setStyleEDJManager(StyleEDJManager styleEDJManager) { + this.styleEDJManager = styleEDJManager; + } + + public StyleEDJManager getStyleEDJManager() { + return styleEDJManager; + } + + public void setPropertiesPageComposite(PropertiesPageComposite propertiesPage) { + this.propertiesPage = propertiesPage; + } + + public void updateStyleAttributes(Command command) { + propertiesPage.getCommandStack().execute(command); + } + + /** + * Gets index by value + * + * @param value + * @return index of value. + */ + public int getIndex(String value) { + Assert.notNull(items); + for (int i = 0; i < items.size(); i++) { + StyleInfo style = items.get(i); + if (value.equals(style.getStyleName())) { + return i; + } + } + return -1; + } + + protected FormData getControlLayoutData() { + FormData data = super.getControlLayoutData(); + data.bottom = new FormAttachment(100, -1); + + return data; + } + + @Override + public void refreshValue(String name, String value) { + int index = -1; + for (int i = 0; i < items.size(); i++) { + if (items.get(i).getStyleName().equals(value)) { + index = i; + break; + } + } + if (index != -1) { + combo.select(index); + } + super.refreshValue(name, value); + } + + public void resetItems(List items) { + if (getControl().isDisposed()) { + logger.error("Control is disposed"); + return; + } + + this.items = items; + List texts = new ArrayList(); + for (StyleInfo item : items) { + texts.add(item.getDisplayName()); + } + String[] names = texts.toArray(new String[0]); + + combo.removeAll(); + if (names.length == 0) { + combo.setEnabled(false); + return; + } + combo.setEnabled(true); + combo.setItems(names); + // selection + String value = getValue(); + if (value.equals(BuilderConstants.EMPTY)) { + combo.select(0); + } else { + int index = getIndex(value); + combo.select(index); + } + } + + private void mergeStyleInfo(List items, String widgetName, String styleName, String displayName, boolean isItemStyle) { + StyleInfo styleInfo = null; + // Check if already exist style + for (int i = 0; i < items.size(); i++) { + if (styleName.equals(items.get(i).getStyleName())) { + styleInfo = items.get(i); + } + } + if (styleInfo != null) { + styleInfo.setType(StyleType.MODIFIED); + } else { + items.add(new StyleInfo(widgetName, styleName, styleName, isItemStyle, StyleType.CUSTOM)); + } + } + + public void updateItems(String componentName, List descriptors, Map>> customStyleMap, + boolean isItemContainer) { + final List items = new ArrayList(); + for (int i = 0; i < descriptors.size(); i++) { + String styleName = descriptors.get(i).getValue(); + String displayName = descriptors.get(i).getDisplayName(); + items.add(new StyleInfo(componentName, styleName, displayName, isItemContainer, StyleType.DEFAULT)); + } + + if (customStyleMap != null) { + Map> customStyles = customStyleMap.get(componentName); + if (customStyles != null) { + // Case : Style of Widget (e.g. button, gengrid) + if (isItemContainer == false) { + Set styles = customStyles.keySet(); + Iterator iter = styles.iterator(); + while (iter.hasNext()) { + String style = iter.next(); + mergeStyleInfo(items, componentName, style, style, isItemContainer); + } + } else { // Case : Style of Item (e.g. gengriditem, genlistitem) + Collection> customItemStyles = customStyles.values(); + Iterator> iterCustomItemStyle = customItemStyles.iterator(); + while (iterCustomItemStyle.hasNext()) { + List itemStyles = iterCustomItemStyle.next(); + if (itemStyles != null) { + for (int i = 0; i < itemStyles.size(); i++) { + String style = itemStyles.get(i); + mergeStyleInfo(items, componentName, style, style, isItemContainer); + } + } + } + } + } + } + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + resetItems(items); + } + }); + + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/style/StyleInfo.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/style/StyleInfo.java new file mode 100644 index 0000000..ac55b81 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/style/StyleInfo.java @@ -0,0 +1,73 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.style; + +public class StyleInfo { + public enum StyleType { + DEFAULT, CUSTOM, MODIFIED + } + + private String widgetName; + private String styleName; + private boolean isItemStyle; + private String displayName; + private StyleType type; + + public StyleInfo(String widgetName, String styleName, String displayName, boolean isItemStyle, StyleType type) { + this.widgetName = widgetName; + this.styleName = styleName; + this.isItemStyle = isItemStyle; + this.displayName = displayName; + this.type = type; + } + + public String getWidgetName() { + return widgetName; + } + + public String getStyleName() { + return styleName; + } + + public String getDisplayName() { + if (type == StyleType.CUSTOM) { + return "[ " + displayName + " ]"; // TODO find more appropriate mark than [ ]. + } else if (type == StyleType.MODIFIED) { + return displayName + " (*)"; + } + return displayName; + } + + public StyleType getType() { + return type; + } + + public void setType(StyleType type) { + this.type = type; + } + + public boolean isItemStyle() { + return isItemStyle; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/style/StyleInputDialog.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/style/StyleInputDialog.java new file mode 100644 index 0000000..f561370 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/views/properties/style/StyleInputDialog.java @@ -0,0 +1,183 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.views.properties.style; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Dialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Widget; +import org.tizen.efluibuilder.nl.BuilderMessages; +import org.tizen.efluibuilder.utility.PlatformUtil; + + +public class StyleInputDialog extends Dialog { + private static final int DIALOG_WIDTH = 412; + private static final int DIALOG_HEIGHT = 98; + private static final int BUTTON_WIDTH = 86; + private static final int BUTTON_HEIGHT = 24; + private static final String StyleNameValidationRule = "[a-zA-Z0-9_]+$"; // TODO check again + // restriction of file + // name. + + private String sourceStyle; + private String styleName; + private Shell shell; + private Text txtInput; + private Button btnOK; + private Button btnCancel; + + private KeyListener textKeyListener = new KeyAdapter() { + @Override + public void keyReleased(KeyEvent arg0) { + String text = txtInput.getText(); + if (!text.equals(sourceStyle) && text.matches(StyleNameValidationRule)) { + btnOK.setEnabled(true); + } else { + btnOK.setEnabled(false); + } + } + }; + + private SelectionListener btnSelectionListener = new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Widget widget = e.widget; + if (widget == btnOK) { + styleName = txtInput.getText(); + } else { + styleName = null; + } + shell.close(); + } + }; + + private DisposeListener shellDisposeListener = new DisposeListener() { + @Override + public void widgetDisposed(DisposeEvent arg0) { + if (txtInput != null && !txtInput.isDisposed()) { + txtInput.removeKeyListener(textKeyListener); + } + if (btnOK != null && !btnOK.isDisposed()) { + btnOK.removeSelectionListener(btnSelectionListener); + } + if (btnCancel != null && !btnCancel.isDisposed()) { + btnCancel.removeSelectionListener(btnSelectionListener); + } + shell.removeDisposeListener(shellDisposeListener); + } + }; + + public StyleInputDialog(Shell parent, String sourceStyle) { + super(parent); + this.sourceStyle = sourceStyle; + } + + private void createContents(final Shell shell) { + shell.setLayout(new FormLayout()); + + Label label = new Label(shell, SWT.NONE); + label.setAlignment(SWT.CENTER); + label.setText(BuilderMessages.COMPONENT_DESIGNER_LABEL_INPUT); + FormData formData = new FormData(); + formData.top = new FormAttachment(0, 24); + formData.left = new FormAttachment(0, 20); + formData.height = 22; + label.setLayoutData(formData); + + txtInput = new Text(shell, SWT.BORDER); + formData = new FormData(); + formData.top = new FormAttachment(0, 20); + formData.left = new FormAttachment(label, 15); + formData.right = new FormAttachment(100, -20); + formData.height = 22; + txtInput.setLayoutData(formData); + txtInput.addKeyListener(textKeyListener); + + /* + * Buttons (Ok, Cancel) + */ + Button btnLeft = new Button(shell, SWT.PUSH); + formData = new FormData(); + formData.top = new FormAttachment(txtInput, 12); + formData.left = new FormAttachment(0, 210); + formData.width = BUTTON_WIDTH; + formData.height = BUTTON_HEIGHT; + btnLeft.setLayoutData(formData); + + Button btnRight = new Button(shell, SWT.PUSH); + formData = new FormData(); + formData.top = new FormAttachment(txtInput, 12); + formData.left = new FormAttachment(btnLeft, 8); + formData.width = BUTTON_WIDTH; + formData.height = BUTTON_HEIGHT; + btnRight.setLayoutData(formData); + + btnCancel = btnLeft; + btnOK = btnRight; + if (PlatformUtil.getOS().equals(PlatformUtil.OS_WIN32)) { + btnCancel = btnRight; + btnOK = btnLeft; + } + btnCancel.setText(BuilderMessages.COMPONENT_DESIGNER_BUTTON_CANCEL); + btnCancel.addSelectionListener(btnSelectionListener); + btnOK.setText(BuilderMessages.COMPONENT_DESIGNER_BUTTON_OK); + btnOK.setEnabled(false); + btnOK.addSelectionListener(btnSelectionListener); + } + + public String open() { + shell = new Shell(getParent(), SWT.APPLICATION_MODAL); + shell.setText(getText()); + shell.setSize(DIALOG_WIDTH, DIALOG_HEIGHT); + shell.addDisposeListener(shellDisposeListener); + Rectangle parentBounds = getParent().getBounds(); + shell.setLocation(parentBounds.x + (parentBounds.width - DIALOG_WIDTH) / 2, + parentBounds.y + (parentBounds.height - DIALOG_HEIGHT) / 2); + createContents(shell); + shell.open(); + Display display = getParent().getDisplay(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + return styleName; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/widgets/TizenScale.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/widgets/TizenScale.java new file mode 100644 index 0000000..4d3dd4d --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/widgets/TizenScale.java @@ -0,0 +1,284 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.ui.widgets; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ControlAdapter; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.ControlListener; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; + + +public class TizenScale extends Canvas { + + private static final int LEFT_AREA_WIDTH = 2; + private static final int RIGHT_AREA_WIDTH = 2; + private static final int AREA_HEIGHT = 2; + private static final int THUMB_HEIGHT = 13; + private static final int THUMB_WIDTH = 4; + + private TizenScaleData attr = new TizenScaleData(); + private TizenScaleRenderer renderer = new TizenScaleDefaultRenderer(); + private SelectionListener selectionListener = null; + private List selectPositions = new ArrayList(); + private int selection = 0; + private int maximum = 0; + private int minimum = 0; + + private boolean mouseDown = false; + + private Rectangle thumbRect = null; + private Rectangle areaRect = null; + private Rectangle leftRect = null; + private Rectangle rightRect = null; + + /** + * TODO Apply Increment + */ + private int increment = 1; + private int pageIncrement = 1; + + public TizenScale(Composite parent, int style) { + super(parent, SWT.NONE); + addListener(SWT.MouseDown, mouseListener); + addListener(SWT.MouseUp, mouseListener); + addListener(SWT.MouseMove, mouseListener); + addPaintListener(paintListener); + addControlListener(controlListener); + } + + public void setTizenScaleDefaultRenderer(TizenScaleDefaultRenderer renderer) { + this.renderer = renderer; + } + + public void setIncrement(int increment) { + this.increment = increment; + } + + public int getIncrement() { + return increment; + } + + public void setPageIncrement(int increment) { + this.pageIncrement = increment; + } + + public int getPageIncrement() { + return pageIncrement; + } + + public void setMaximum(int max) { + maximum = max; + } + + public int getMaximum() { + return maximum; + } + + public void setMinimum(int min) { + minimum = min; + } + + public int getMinimum() { + return minimum; + } + + public int getSelection() { + double tick = getTickSize(); + int thumbX = thumbRect.x + THUMB_WIDTH / 2; + double width = thumbX - areaRect.x; + return (int) ((width / tick) + minimum); + } + + public void setSelection(int selection) { + if (selection > maximum) { + selection = maximum; + } else if (selection < minimum) { + selection = minimum; + } + this.selection = selection - minimum; + if (selectPositions.isEmpty() == false) { + int thumbPos = selectPositions.get(this.selection); + thumbRect = getThumbRect(thumbPos); + redraw(); + } + } + + public void setRenderer(TizenScaleRenderer renderer) { + this.renderer = renderer; + } + + public void addSelectionListener(SelectionListener listener) { + if (null == listener) { + return; + } + selectionListener = listener; + } + + private boolean pointInRect(Rectangle rect, Point p) { + if ((p.x > rect.x) && (p.x > rect.y) && (p.x < rect.x + rect.width) && (p.y < rect.y + rect.height)) { + return true; + } + return false; + } + + private Rectangle getThumbRect(int pointX) { + int thumbHeight = THUMB_HEIGHT; + int thumbWidth = THUMB_WIDTH; + + if (pointX < areaRect.x) { + pointX = areaRect.x; + } else if (pointX > areaRect.x + areaRect.width) { + pointX = areaRect.x + areaRect.width; + } + int y = areaRect.y - (thumbHeight - areaRect.height) / 2; + int x = pointX - thumbWidth / 2; + return new Rectangle(x, y, thumbWidth, thumbHeight); + } + + private void setSelectionInternal(int pointX) { + if (pointX <= areaRect.x) { + selection = 0; + } else if (pointX >= areaRect.x + areaRect.width) { + selection = maximum - minimum; + } else { + double tick = getTickSize(); + int width = pointX - areaRect.x; + selection = (int) (width / tick); + } + } + + private double getTickSize() { + return (double) areaRect.width / (double) (maximum - minimum); + } + + private void initSelectPosition() { + selectPositions.clear(); + int size = maximum - minimum + 1; + double tickSize = getTickSize(); + + for (int i = 0; i < size; i++) { + if (i == 0) { + selectPositions.add(areaRect.x); + } else if (i == (size - 1)) { + selectPositions.add(areaRect.x + areaRect.width); + } else { + int pos = (int) (tickSize * i + areaRect.x); + selectPositions.add(pos); + } + } + } + + /* + * Event Listener + */ + private Listener mouseListener = new Listener() { + @Override + public void handleEvent(Event event) { + if (event.type == SWT.MouseDown) { + mouseDown = true; + if (pointInRect(thumbRect, new Point(event.x, event.y))) { + mouseDown = true; + } else if ((event.x >= areaRect.x) && (event.x <= areaRect.x + areaRect.width)) { + setSelectionInternal(event.x); + thumbRect = getThumbRect(event.x); + redraw(); + } + if (null != selectionListener) { + SelectionEvent e = new SelectionEvent(event); + selectionListener.widgetSelected(e); + } + } + if (event.type == SWT.MouseUp) { + mouseDown = false; + } + if (event.type == SWT.MouseMove) { + if (mouseDown) { + setSelectionInternal(event.x); + thumbRect = getThumbRect(event.x); + redraw(); + if (null != selectionListener) { + SelectionEvent e = new SelectionEvent(event); + selectionListener.widgetSelected(e); + } + } + } + } + }; + + private PaintListener paintListener = new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + attr.setAreaRect(areaRect); + attr.setLeftRect(leftRect); + attr.setRightRect(rightRect); + attr.setThumbRect(thumbRect); + attr.setEnabled(TizenScale.this.isEnabled()); + renderer.draw(e.gc, (Canvas) e.widget, attr); + } + }; + + private ControlListener controlListener = new ControlAdapter() { + @Override + public void controlResized(ControlEvent e) { + Canvas canvas = (Canvas) e.widget; + Rectangle rect = canvas.getClientArea(); + + leftRect = new Rectangle(rect.x, rect.y, LEFT_AREA_WIDTH, rect.height); + rightRect = new Rectangle(rect.x + rect.width - RIGHT_AREA_WIDTH, rect.y, RIGHT_AREA_WIDTH, rect.height); + + int areaWidth = rect.width - (leftRect.width + rightRect.width); + int areaY = rect.y + (rect.height - AREA_HEIGHT) / 2; + areaRect = new Rectangle(rect.x + LEFT_AREA_WIDTH, areaY, areaWidth, AREA_HEIGHT); + + initSelectPosition(); + + int thumbPos = selectPositions.get(selection); + thumbRect = getThumbRect(thumbPos); + } + }; + + @Override + public void setEnabled(boolean enabled) { + super.setEnabled(enabled); + this.redraw(); + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/widgets/TizenScaleData.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/widgets/TizenScaleData.java new file mode 100644 index 0000000..c64db22 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/widgets/TizenScaleData.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.ui.widgets; + +import org.eclipse.swt.graphics.Rectangle; + + +public class TizenScaleData { + private Rectangle thumbRect = null; + private Rectangle areaRect = null; + private Rectangle leftRect = null; + private Rectangle rightRect = null; + + private boolean isEnabled = false; + + public boolean isEnabled() { + return isEnabled; + } + + public void setEnabled(boolean isEnabled) { + this.isEnabled = isEnabled; + } + + public Rectangle getThumbRect() { + return thumbRect; + } + + public void setThumbRect(Rectangle thumbRect) { + this.thumbRect = thumbRect; + } + + public Rectangle getAreaRect() { + return areaRect; + } + + public void setAreaRect(Rectangle areaRect) { + this.areaRect = areaRect; + } + + public Rectangle getLeftRect() { + return leftRect; + } + + public void setLeftRect(Rectangle leftRect) { + this.leftRect = leftRect; + } + + public Rectangle getRightRect() { + return rightRect; + } + + public void setRightRect(Rectangle rightRect) { + this.rightRect = rightRect; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/widgets/TizenScaleDefaultRenderer.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/widgets/TizenScaleDefaultRenderer.java new file mode 100644 index 0000000..ceb5963 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/widgets/TizenScaleDefaultRenderer.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.ui.widgets; + +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.widgets.Canvas; +import org.tizen.efluibuilder.ui.resources.ColorResources; + + +public class TizenScaleDefaultRenderer implements TizenScaleRenderer { + + @Override + public void draw(GC gc, Canvas canvas, TizenScaleData attr) { + if (attr.isEnabled()) { + gc.setBackground(ColorResources.TIZEN_SCALE_AREA_NOR); + } else { + gc.setBackground(ColorResources.TIZEN_SCALE_AREA_DIM); + } + gc.fillRectangle(attr.getAreaRect()); + + if (attr.isEnabled()) { + gc.setBackground(ColorResources.TIZEN_SCALE_THUMB_NOR); + } else { + gc.setBackground(ColorResources.TIZEN_SCALE_THUMB_DIM); + } + gc.fillRectangle(attr.getThumbRect().x, attr.getThumbRect().y, attr.getThumbRect().width, attr.getThumbRect().height); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/widgets/TizenScaleRenderer.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/widgets/TizenScaleRenderer.java new file mode 100644 index 0000000..d455b00 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/widgets/TizenScaleRenderer.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.ui.widgets; + +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.widgets.Canvas; + + +public interface TizenScaleRenderer { + public void draw(GC gc, Canvas canvas, TizenScaleData attr); +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/widgets/UIBLabel.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/widgets/UIBLabel.java new file mode 100644 index 0000000..09d031d --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/widgets/UIBLabel.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JungWook Ryu + * ChulKi Kim + * Yongseok Lee + * Dongjo Hwang + * + * 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.efluibuilder.ui.widgets; + +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.widgets.Composite; + + +public class UIBLabel extends CLabel { + private final static String ELLIPSIS = Character.toString((char) (0x2026)); // Unicode of "..." + + public UIBLabel(Composite parent, int style) { + super(parent, style); + } + + /* + * Return shorten text (e.g. abcdefgh -> abcd...) + */ + @Override + protected String shortenText(GC gc, String t, int width) { + if (t == null) { + return null; + } + + // Make shortenText only if length is longer than 3 characters. + int tL = t.length(); + if (tL <= 3) { + return t; + } + + // Find appropriate shorten text. + int start = 0; + int end = tL; + int mid = tL / 2 > 3 ? tL / 2 : 3; + String result = t; + while (start < mid && mid < end) { + result = t.substring(0, mid) + ELLIPSIS; + int rW = gc.textExtent(result).x + 2; + if (rW < width) { + start = mid; + mid = (end + mid) / 2; + } else if (rW > width) { + end = mid; + mid = (start + mid) / 2; + } else { + break; + } + } + + // Shorten text should be longer than 3 characters. (e.g.) ab...(x), abc...(O) + return (mid >= 3) ? result : t.substring(0, 3) + ELLIPSIS; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/newfile/EdcFileWizard.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/newfile/EdcFileWizard.java new file mode 100644 index 0000000..325a980 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/newfile/EdcFileWizard.java @@ -0,0 +1,70 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.wizard.newfile; + +import org.eclipse.core.resources.IFile; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.ui.INewWizard; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.dialogs.WizardNewFileCreationPage; + + +public class EdcFileWizard extends Wizard implements INewWizard { + private static final String WIZARD_TITLE = "New EDC File"; + protected IStructuredSelection selection; + private WizardNewFileCreationPage newXMLFilePage; + IFile createdFile = null; + + @Override + public void init(IWorkbench arg0, IStructuredSelection arg1) { + } + + @Override + public boolean performFinish() { + createdFile = newXMLFilePage.createNewFile(); + if (createdFile != null && createdFile.exists()) { + return true; + } + return false; + } + + public void setSelection(IStructuredSelection arg1) { + this.selection = arg1; + } + + @Override + public void addPages() { + newXMLFilePage = new WizardNewFileCreationPage(WIZARD_TITLE, this.selection); + newXMLFilePage.setTitle(WIZARD_TITLE); + newXMLFilePage.setDescription(WIZARD_TITLE); + newXMLFilePage.setFileExtension("edc"); + super.addPage(newXMLFilePage); + } + + public IFile getCreatedFile() { + return this.createdFile; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/AbstractWizard.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/AbstractWizard.java new file mode 100644 index 0000000..748a7e7 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/AbstractWizard.java @@ -0,0 +1,56 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.wizard.snippet; + +import org.eclipse.jface.wizard.Wizard; +import org.tizen.common.util.Assert; +import org.tizen.efluibuilder.model.app.AppManager; + + +public abstract class AbstractWizard extends Wizard { + private Object model = null; + protected String platform; + + public AbstractWizard() { + super(); + + loadAppManager(); + } + + @Deprecated + private void loadAppManager() { + AppManager appManager = AppManager.getAppManager(); + Assert.notNull(appManager); + + platform = appManager.getPlatform(); + } + + public void setModel(Object model) { + this.model = model; + } + + public Object getModel() { + return model; + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/AbstractWizardPage.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/AbstractWizardPage.java new file mode 100644 index 0000000..b980035 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/AbstractWizardPage.java @@ -0,0 +1,57 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.wizard.snippet; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.wizard.WizardPage; +import org.tizen.common.util.Assert; +import org.tizen.efluibuilder.core.configuration.device.DeviceManager; +import org.tizen.efluibuilder.model.app.AppManager; + + +public abstract class AbstractWizardPage extends WizardPage { + + protected DeviceManager deviceManager; + protected String profile; + + public AbstractWizardPage(String pageName, String title, ImageDescriptor titleImage) { + super(pageName, title, titleImage); + + loadAppManager(); + } + + protected void setMessage(String message, String errorMessage) { + setMessage(message); + setErrorMessage(errorMessage); + } + + @Deprecated + private void loadAppManager() { + AppManager appManager = AppManager.getAppManager(); + Assert.notNull(appManager); + + deviceManager = appManager.getDeviceManager(); + profile = appManager.getProfile(); + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewSnippetDialogPage.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewSnippetDialogPage.java new file mode 100644 index 0000000..7d4f2b1 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewSnippetDialogPage.java @@ -0,0 +1,224 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.wizard.snippet; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.graphics.Point; +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; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.tizen.efluibuilder.BuilderPlugin; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.snippet.ISnippet; +import org.tizen.efluibuilder.model.snippet.ISnippetManager; +import org.tizen.efluibuilder.model.snippet.Snippet; +import org.tizen.efluibuilder.model.snippet.SnippetManager; +import org.tizen.efluibuilder.model.util.PartMarshaller; +import org.tizen.efluibuilder.ui.resources.ImageResources; +import org.tizen.efluibuilder.utility.PlatformUtil; +import org.tizen.efluibuilder.utility.ResourceUtil; +import org.w3c.dom.Document; + + +public class NewSnippetDialogPage extends Dialog { + public static final String NAME = NewSnippetDialogPage.class.getName(); + + private Object model = null; + private Text nameText; + private Text descriptionText; + private String name = ""; + private String description = ""; + private Button okButton; + private Button cancelButton; + + public void setModel(Object model) { + this.model = model; + } + + public Object getModel() { + return model; + } + + public NewSnippetDialogPage(Shell parentShell) { + super(parentShell); + } + + @Override + protected void configureShell(Shell shell) { + super.configureShell(shell); + shell.setText(NewSnippetWizardMessages.WIZARD_TITLE); + } + + public Text getNameText() { + return nameText; + } + + public void setNameText(Text nameText) { + this.nameText = nameText; + } + + public Text getDescriptionText() { + return descriptionText; + } + + public void setDescriptionText(Text descriptionText) { + this.descriptionText = descriptionText; + } + + @Override + protected Control createDialogArea(Composite parent) { + + Composite container = (Composite) super.createDialogArea(parent); + GridLayout layout = new GridLayout(2, false); + layout.marginRight = 20; + layout.marginLeft = 20; + layout.marginTop = 20; + layout.marginBottom = 20; + layout.horizontalSpacing = 8; + layout.verticalSpacing = 10; + container.setLayout(layout); + + Label lblName = new Label(container, SWT.NONE); + lblName.setText(NewSnippetWizardMessages.FIRST_PAGE_NAME_LABEL); + + nameText = new Text(container, SWT.BORDER); + nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, + 1, 1)); + nameText.setText(name); + nameText.addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + Text textWidget = (Text) e.getSource(); + name = textWidget.getText(); + if (!name.isEmpty()) { + okButton.setEnabled(true); + } else { + okButton.setEnabled(false); + + } + } + }); + + Label lblDescription = new Label(container, SWT.NONE); + GridData gd_lblNewLabel = new GridData(SWT.LEFT, SWT.CENTER, false, + false, 1, 1); + lblDescription.setLayoutData(gd_lblNewLabel); + lblDescription.setText(NewSnippetWizardMessages.FIRST_PAGE_DESCRIPTION_LABEL); + + descriptionText = new Text(container, SWT.BORDER); + descriptionText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, + false, 1, 1)); + descriptionText.setText(description); + descriptionText.addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + Text textWidget = (Text) e.getSource(); + description = textWidget.getText(); + if (!name.isEmpty()) { + okButton.setEnabled(true); + } else { + okButton.setEnabled(false); + + } + } + }); + + Label sepLabel = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL); + sepLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, + false, 1, 1)); + return container; + } + + @Override + protected void createButtonsForButtonBar(Composite parent) { + if (PlatformUtil.getOS().equals(PlatformUtil.OS_WIN32)) { + okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); + cancelButton = createButton(parent, IDialogConstants.CANCEL_ID, + IDialogConstants.CANCEL_LABEL, false); + } else { + cancelButton = createButton(parent, IDialogConstants.CANCEL_ID, + IDialogConstants.CANCEL_LABEL, false); + okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); + } + okButton.setSize(86, 24); + cancelButton.setSize(86, 24); + okButton.setEnabled(false); + } + + @Override + protected Point getInitialSize() { + return new Point(510, 188); + } + + @Override + protected void okPressed() { + // set default icon + ImageDescriptor imageDescriptor = ResourceUtil.getImageDescriptor(BuilderPlugin.PLUGIN_ID, ImageResources.SNIPPET_DEFAULT_SNIPPET_IMAGE); + + Part part = (Part) getModel(); + + PartMarshaller marshaller = new PartMarshaller(); + Document document = marshaller.marshall(part); + + // create snippet + ISnippet snippet = new Snippet(); + snippet.setName(name); + snippet.setDescription(description); + snippet.setType(Snippet.TYPE_WIDGET); + snippet.setModel(document); + snippet.setImage(imageDescriptor); + ISnippetManager manager = SnippetManager.getDefault(); + manager.create(snippet); + super.okPressed(); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewSnippetWizardMessages.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewSnippetWizardMessages.java new file mode 100644 index 0000000..6b54465 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewSnippetWizardMessages.java @@ -0,0 +1,51 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.wizard.snippet; + +import org.eclipse.osgi.util.NLS; + + +public class NewSnippetWizardMessages { + private static final String BUNDLE_NAME = NewSnippetWizardMessages.class.getName(); + + // Wizard + public static String WIZARD_TITLE; + + // First Page + public static String FIRST_PAGE_TITLE; + public static String FIRST_PAGE_DESCRIPTION; + public static String FIRST_PAGE_NAME_LABEL; + public static String FIRST_PAGE_DESCRIPTION_LABEL; + + // Error Messages + public static String ERROR_INVALID_NAME; + + static { + NLS.initializeMessages(BUNDLE_NAME, NewSnippetWizardMessages.class); + } + + private NewSnippetWizardMessages() { + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewSnippetWizardMessages.properties b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewSnippetWizardMessages.properties new file mode 100644 index 0000000..c46a9c5 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewSnippetWizardMessages.properties @@ -0,0 +1,11 @@ +# Wizard +WIZARD_TITLE=New Snippet + +# First Page +FIRST_PAGE_TITLE=Snippet +FIRST_PAGE_DESCRIPTION=Create a new Snippet. +FIRST_PAGE_NAME_LABEL=Name +FIRST_PAGE_DESCRIPTION_LABEL=Description + +# Error Message +ERROR_INVALID_NAME=Invalid name. diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewComposite.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewComposite.java new file mode 100644 index 0000000..9895c99 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewComposite.java @@ -0,0 +1,281 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.wizard.snippet; + +import java.util.Collection; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.nebula.widgets.gallery.DefaultGalleryItemRenderer; +import org.eclipse.nebula.widgets.gallery.Gallery; +import org.eclipse.nebula.widgets.gallery.GalleryItem; +import org.eclipse.nebula.widgets.gallery.NoGroupRenderer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Image; +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.MessageBox; +import org.tizen.efluibuilder.core.configurator.ConfiguratorConstants; +import org.tizen.efluibuilder.model.app.AppManager; +import org.tizen.efluibuilder.model.snippet.ISnippet; +import org.tizen.efluibuilder.model.snippet.ISnippetManager; +import org.tizen.efluibuilder.model.snippet.SnippetManager; +import org.tizen.efluibuilder.ui.SelectionProviderAdapter; +import org.tizen.efluibuilder.ui.resources.ColorResources; +import org.tizen.efluibuilder.ui.resources.FontResources; +import org.tizen.efluibuilder.ui.views.outline.OutlineConstants; +import org.tizen.efluibuilder.utility.ImageUtil; + + +public final class NewViewComposite extends Composite implements ISelectionProvider, KeyListener, SelectionListener { + public static final String NAME = NewViewComposite.class.getName(); + private static final int WIDTH = 620; + private static final int HEIGHT = 240; + + private static final int TEMPLATE_IMAGE_WIDTH = 80; + private static final int TEMPLATE_IMAGE_HEIGHT = 140; + + // Selection + private SelectionProviderAdapter selectionProvider = null; + + // controlls + private Gallery gallery = null; + + private SelectionProviderAdapter getSelectionProvider() { + return selectionProvider; + } + + public NewViewComposite(Composite parent, int style) { + super(parent, style); + selectionProvider = new SelectionProviderAdapter(); + setLayout(new GridLayout(1, false)); + GridData gridData = new GridData(GridData.FILL_BOTH); + gridData.widthHint = WIDTH; + gridData.heightHint = HEIGHT; + setLayoutData(gridData); + + gallery = new Gallery(this, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); + gallery.setBackground(ColorResources.DIALOG_TABLE_BG); + + NoGroupRenderer groupRenderer = new NoGroupRenderer(); + groupRenderer.setItemHeight(TEMPLATE_IMAGE_HEIGHT); + groupRenderer.setItemWidth(TEMPLATE_IMAGE_WIDTH); + groupRenderer.setMinMargin(16); + groupRenderer.setAutoMargin(true); + gallery.setGroupRenderer(groupRenderer); + DefaultGalleryItemRenderer itemRenderer = new DefaultGalleryItemRenderer(); + gallery.setItemRenderer(itemRenderer); + gallery.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3)); + + addListeners(); + refresh(); + this.getShell().setMinimumSize(660, 461); + this.getShell().setLocation(SWT.CENTER, SWT.CENTER); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.swt.widgets.Widget#dispose() + */ + @Override + public void dispose() { + removeListeners(); + gallery.dispose(); + gallery = null; + selectionProvider = null; + super.dispose(); + } + + private void addListeners() { + gallery.addSelectionListener(this); + gallery.addKeyListener(this); + } + + private void removeListeners() { + gallery.removeSelectionListener(this); + gallery.removeKeyListener(this); + } + + private void refresh() { + gallery.removeAll(); + + ISnippetManager manager = SnippetManager.getDefault(); + Collection snippets = manager.getViewTemplates(); + GalleryItem group = new GalleryItem(gallery, SWT.BORDER); + group.setText("group"); + for (ISnippet snippet : snippets) { + if (!AppManager.getAppManager().getProfile().equals(ConfiguratorConstants.PROFILE_MOBILE)) { + // This template is not supported in wearable profile + if ((snippet.getName().equals(OutlineConstants.KEY_POPUP_VIEW)) || (snippet.getName().equals(OutlineConstants.KEY_CTXPOPUP_VIEW))) { + continue; + } + } + + final GalleryItem item = new GalleryItem(group, SWT.NONE); + item.addDisposeListener(new DisposeListener() { + @Override + public void widgetDisposed(DisposeEvent arg0) { + Image image = item.getImage(); + if (image != null && image.isDisposed() == false) { + image.dispose(); + } + } + }); + + item.setFont(FontResources.BOLD); + item.setText(snippet.getName()); + Image lineImage = snippet.getImage().createImage(); + item.setImage(ImageUtil.addBorderImage(lineImage, TEMPLATE_IMAGE_WIDTH, TEMPLATE_IMAGE_HEIGHT, + ColorResources.DIALOG_IMAGE_BORDER_COLOR)); + lineImage.dispose(); + item.setData(snippet); + } + + gallery.redraw(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection() + */ + @Override + public ISelection getSelection() { + return getSelectionProvider().getSelection(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers. + * ISelection ) + */ + @Override + public void setSelection(ISelection selection) { + getSelectionProvider().setSelection(selection); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener(org.eclipse.jface + * .viewers.ISelectionChangedListener) + */ + @Override + public void addSelectionChangedListener(ISelectionChangedListener listener) { + getSelectionProvider().addSelectionChangedListener(listener); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jface.viewers.ISelectionProvider#removeSelectionChangedListener(org.eclipse.jface + * .viewers.ISelectionChangedListener) + */ + @Override + public void removeSelectionChangedListener(ISelectionChangedListener listener) { + getSelectionProvider().removeSelectionChangedListener(listener); + } + + @Override + public void widgetSelected(SelectionEvent event) { + if (!event.widget.equals(gallery)) { + return; + } + + GalleryItem[] selections = gallery.getSelection(); + if (selections.length == 0) { + setSelection(StructuredSelection.EMPTY); + return; + } + + Object object = selections[0].getData(); + IStructuredSelection selection = new StructuredSelection(object); + setSelection(selection); + + } + + @Override + public void widgetDefaultSelected(SelectionEvent event) { + widgetSelected(event); + } + + @Override + public void keyPressed(KeyEvent event) { + } + + @Override + public void keyReleased(KeyEvent event) { + if (event.character == SWT.DEL) { + delete(); + } + } + + private void delete() { + ISelection selection = getSelection(); + + Assert.isTrue(selection instanceof StructuredSelection); + if (selection.equals(StructuredSelection.EMPTY)) { + return; + } + + StructuredSelection ss = (StructuredSelection) selection; + Object object = ss.getFirstElement(); + if (object instanceof ISnippet) { + ISnippet snippet = (ISnippet) object; + String category = snippet.getCategory(); + + if (category.equals(ISnippet.CATEGORY_SYSTEM)) { + MessageBox msgBox = new MessageBox(Display.getDefault().getActiveShell(), SWT.ICON_INFORMATION); + msgBox.setMessage("Default template can not be deleted."); + msgBox.open(); + return; + } + + MessageBox msgBox = new MessageBox(Display.getDefault().getActiveShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION); + msgBox.setMessage("Do you really want to delete this template? \nDeleted template can not be restored."); + int result = msgBox.open(); + if (result == SWT.YES) { + ISnippetManager manager = SnippetManager.getDefault(); + manager.remove(snippet); + refresh(); + } + } + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewTemplateWizard.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewTemplateWizard.java new file mode 100644 index 0000000..75cac07 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewTemplateWizard.java @@ -0,0 +1,81 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.wizard.snippet; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.snippet.ISnippet; +import org.tizen.efluibuilder.model.snippet.ISnippetManager; +import org.tizen.efluibuilder.model.snippet.Snippet; +import org.tizen.efluibuilder.model.snippet.SnippetManager; +import org.tizen.efluibuilder.model.util.PartMarshaller; +import org.w3c.dom.Document; + + +public final class NewViewTemplateWizard extends AbstractWizard { + private NewViewTemplateWizardFirstPage firstPage = null; + + public NewViewTemplateWizard() { + super(); + setWindowTitle(NewViewTemplateWizardMessages.WIZARD_TITLE); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.wizard.Wizard#addPages() + */ + @Override + public void addPages() { + super.addPages(); + firstPage = new NewViewTemplateWizardFirstPage(NewViewTemplateWizardFirstPage.NAME, NewViewTemplateWizardMessages.FIRST_PAGE_TITLE, null); + addPage(firstPage); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.wizard.Wizard#performFinish() + */ + @Override + public boolean performFinish() { + String name = firstPage.getViewName(); + ImageDescriptor imageDescriptor = firstPage.getImageDescriptor(); + + Part part = (Part) getModel(); + PartMarshaller marshaller = new PartMarshaller(); + Document document = marshaller.marshall(part); + + ISnippet snippet = new Snippet(); + snippet.setName(name); + snippet.setType(ISnippet.TYPE_VIEW); + snippet.setImage(imageDescriptor); + snippet.setModel(document); + ISnippetManager manager = SnippetManager.getDefault(); + manager.create(snippet); + + return true; + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewTemplateWizardFirstPage.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewTemplateWizardFirstPage.java new file mode 100644 index 0000000..aee93ea --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewTemplateWizardFirstPage.java @@ -0,0 +1,250 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.wizard.snippet; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.wizard.IWizard; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.PlatformUI; +import org.tizen.common.util.Assert; +import org.tizen.efluibuilder.model.part.ViewPart; +import org.tizen.efluibuilder.mscreen.configurator.MScreenQualifierManager; +import org.tizen.efluibuilder.ui.editor.CombineEditorPart; +import org.tizen.efluibuilder.ui.resources.ColorResources; + +import graphicalDataManager.ComponentGraphicalData; + + +public final class NewViewTemplateWizardFirstPage extends AbstractWizardPage implements ModifyListener { + public static final String NAME = NewViewTemplateWizardFirstPage.class.getName(); + + // controls + private Composite rootComposite = null; + private Composite imageComposite = null; + private Composite nameComposite = null; + + private Canvas imageCanvas = null; + + private Label nameLabel = null; + private Text nameText = null; + private ImageDescriptor imageDescriptor = null; + + public String getViewName() { + return nameText.getText(); + } + + public ImageDescriptor getImageDescriptor() { + return imageDescriptor; + } + + public NewViewTemplateWizardFirstPage(String pageName, String title, ImageDescriptor titleImage) { + super(pageName, title, titleImage); + setTitle(NewViewTemplateWizardMessages.FIRST_PAGE_TITLE); + setDescription(NewViewTemplateWizardMessages.FIRST_PAGE_DESCRIPTION); + } + + private ImageDescriptor getImageDescriptorFromViewPart(ViewPart selectedViewPart) { + CombineEditorPart combineEditorPart = (CombineEditorPart) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); + MScreenQualifierManager screenQualifierMgr = combineEditorPart.getDesignEditor().getViewer().getMScreenQualifierManager(); + + ComponentGraphicalData graphicalData = + combineEditorPart.getGraphiclaDataManager().getGraphicalData(selectedViewPart.getUniqueId(), screenQualifierMgr.getCurrentDevice(), + screenQualifierMgr.getCurrentOrientation(), screenQualifierMgr.getCurrentLocale()); + if (graphicalData != null) { + return graphicalData.imageDescriptor; + } + return null; + + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) + */ + @Override + public void createControl(Composite parent) { + // Root Composite + rootComposite = new Composite(parent, SWT.NONE); + rootComposite.setLayout(new GridLayout(1, true)); + rootComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); + setControl(rootComposite); + + imageComposite = new Composite(rootComposite, SWT.BORDER); + imageComposite.setLayout(new GridLayout(1, false)); + imageComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); + IWizard wizard = getWizard(); + AbstractWizard abstractWizard = (AbstractWizard) wizard; + + imageDescriptor = getImageDescriptorFromViewPart((ViewPart) abstractWizard.getModel()); + + imageCanvas = new Canvas(imageComposite, SWT.NONE); + imageCanvas.addPaintListener(new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + if (imageDescriptor != null) { + Image image = imageDescriptor.createImage(); + try { + /* + * Calculate image size to fit in Canvas. + */ + int originalWidth = image.getBounds().width; + int originalHeight = image.getBounds().height; + int diffWidth = (e.width - originalWidth); + int diffHeight = (e.height - originalHeight); + int resizedWidth = originalWidth; + int resizedHeight = originalHeight; + if (diffWidth < 0 || diffHeight < 0) { // If image size is larger than + // Canvas + // size, + if (diffWidth - diffHeight > 0) { + resizedHeight = e.height; + resizedWidth *= ((double) e.height / (double) originalHeight); + } else { + resizedWidth = e.width; + resizedHeight *= ((double) e.width / (double) originalWidth); + } + } + int drawX = (e.width - resizedWidth) / 2; + int drawY = (e.height - resizedHeight) / 2; + e.gc.drawImage(image, 0, 0, image.getBounds().width, image.getBounds().height, + drawX, drawY, resizedWidth, resizedHeight); + + e.gc.setBackground(ColorResources.DIALOG_IMAGECOMPOSITE_BG_COLOR); + + } finally { + + image.dispose(); + + } + } + } + }); + + imageCanvas.setLayoutData(new GridData(GridData.FILL_BOTH)); + + // Name Composite + nameComposite = new Composite(rootComposite, SWT.NONE); + nameComposite.setLayout(new GridLayout(2, false)); + nameComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + nameLabel = new Label(nameComposite, SWT.NONE); + nameLabel.setLayoutData(new GridData(GridData.BEGINNING)); + nameLabel.setText(NewViewTemplateWizardMessages.FIRST_PAGE_NAME_LABEL); + nameText = new Text(nameComposite, SWT.SINGLE | SWT.BORDER); + nameText.setBackground(ColorResources.DIALOG_NEW_VIEW_NAME_TEXT_BG); + nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + nameText.setFocus(); + + setPageComplete(false); + addListeners(); + this.getShell().setMinimumSize(500, 461); + this.getShell().setLocation(SWT.CENTER, SWT.CENTER); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.dialogs.DialogPage#dispose() + */ + @Override + public void dispose() { + removeListeners(); + super.dispose(); + rootComposite = null; + imageComposite = null; + nameComposite = null; + nameLabel = null; + nameText = null; + } + + private void addListeners() { + nameText.addModifyListener(this); + } + + private void removeListeners() { + nameText.removeModifyListener(this); + } + + private void validate() { + if (!isValidPage()) { + setPageComplete(false); + } else { + setMessage(NewViewTemplateWizardMessages.FIRST_PAGE_DESCRIPTION, null); + setPageComplete(true); + } + } + + private boolean isValidPage() { + if (!isValidName(getViewName())) { + setMessage(null, NewViewTemplateWizardMessages.ERROR_INVALID_NAME); + return false; + } + + if (!isValidImage()) { + // condition can not be here + Assert.isTrue(false); + return false; + } + return true; + } + + private boolean isValidName(String name) { + if (name.length() == 0) { + return false; + } + + return true; + } + + private boolean isValidImage() { + if (imageDescriptor == null) { + return false; + } + return true; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent) + */ + @Override + public void modifyText(ModifyEvent e) { + if (e.widget.equals(nameText)) { + validate(); + } + } + +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewTemplateWizardMessages.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewTemplateWizardMessages.java new file mode 100644 index 0000000..7e3fa75 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewTemplateWizardMessages.java @@ -0,0 +1,58 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.wizard.snippet; + +import org.eclipse.osgi.util.NLS; + + +public class NewViewTemplateWizardMessages { + private static final String BUNDLE_NAME = NewViewTemplateWizardMessages.class.getName(); + + // Wizard + public static String WIZARD_TITLE; + + // First Page + public static String FIRST_PAGE_TITLE; + public static String FIRST_PAGE_DESCRIPTION; + public static String FIRST_PAGE_NAME_LABEL; + + // Error Dialog + public static String ERROR_DIALOG_TITLE; + + // Error Messages + public static String ERROR_INVALID_GROUP; + public static String ERROR_INVALID_NAME; + public static String ERROR_EXIST_NAME; + public static String ERROR_EMPTY_FILENAME; + public static String ERROR_EXIST_FILENAME; + public static String ERROR_CREATE_FOLDER; + + static { + NLS.initializeMessages(BUNDLE_NAME, NewViewTemplateWizardMessages.class); + } + + private NewViewTemplateWizardMessages() { + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewTemplateWizardMessages.properties b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewTemplateWizardMessages.properties new file mode 100644 index 0000000..a6c03b6 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewTemplateWizardMessages.properties @@ -0,0 +1,18 @@ +# Wizard +WIZARD_TITLE=Save As Vew Template + +# First Page +FIRST_PAGE_TITLE=View Template +FIRST_PAGE_DESCRIPTION=Save the view as a template for futher use. +FIRST_PAGE_NAME_LABEL=Name: + +# Error Dialog Title +ERROR_DIALOG_TITLE=Problem Occurred. + +# Error Message +ERROR_INVALID_GROUP=No template group specified. +ERROR_INVALID_NAME=Enter a valid name. +ERROR_EXIST_NAME=Name already exists. +ERROR_EMPTY_FILENAME=Filename is emptied. +ERROR_EXIST_FILENAME=Filename already exists. +ERROR_CREATE_FOLDER=Template folder creation failed. \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewWizard.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewWizard.java new file mode 100644 index 0000000..cc556b2 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewWizard.java @@ -0,0 +1,70 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.wizard.snippet; + +import org.eclipse.gef.commands.Command; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.part.ViewPart; + + +public final class NewViewWizard extends AbstractWizard { + + private NewViewWizardFirstPage firstPage = null; +private DesignViewer viewer = null; + public NewViewWizard(DesignViewer viewer) { + this.viewer = viewer; + setWindowTitle(NewViewWizardMessages.WIZARD_TITLE); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.wizard.Wizard#addPages() + */ + @Override + public void addPages() { + super.addPages(); + firstPage = new NewViewWizardFirstPage(getModel(), NewViewWizardFirstPage.NAME, NewViewWizardMessages.FIRST_PAGE_TITLE, null, viewer); + addPage(firstPage); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.wizard.Wizard#performFinish() + */ + @Override + public boolean performFinish() { + Object model = getModel(); + if (model instanceof ViewPart) { + return firstPage.createCommand(platform, (ViewPart) model); + } + + return false; + } + + public Command getCommnad() { + return firstPage.getCommand(); + } +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewWizardFirstPage.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewWizardFirstPage.java new file mode 100644 index 0000000..4e05be4 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewWizardFirstPage.java @@ -0,0 +1,237 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.wizard.snippet; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.gef.commands.Command; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.wizard.IWizard; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.tizen.efluibuilder.gef.policies.containers.DesignEditorUtil; +import org.tizen.efluibuilder.gef.viewer.DesignViewer; +import org.tizen.efluibuilder.model.part.DocumentPart; +import org.tizen.efluibuilder.model.part.Part; +import org.tizen.efluibuilder.model.part.ViewPart; +import org.tizen.efluibuilder.model.part.ViewsPart; +import org.tizen.efluibuilder.model.snippet.ISnippet; +import org.tizen.efluibuilder.model.util.LayoutSchemaConstants; +import org.tizen.efluibuilder.model.util.PartUnmarshaller; +import org.tizen.efluibuilder.model.util.PartUtil; +import org.tizen.efluibuilder.ui.resources.ColorResources; +import org.w3c.dom.Document; + + +public final class NewViewWizardFirstPage extends AbstractWizardPage implements ModifyListener, ISelectionChangedListener { + public static final String NAME = NewViewWizardFirstPage.class.getName(); + private ISnippet snippet = null; + // controls + private NewViewComposite templateComposite = null; + private Composite rootComposite = null; + private Text nameText = null; + private Command command = null; + private Part viewsPart = null; + private DesignViewer viewer = null; + + protected NewViewWizardFirstPage(Object model, String pageName, String title, ImageDescriptor titleImage, DesignViewer viewer) { + super(pageName, title, titleImage); + if (model instanceof ViewPart) { + this.viewsPart = ((Part) model).getParent(); + } + setTitle(NewViewWizardMessages.FIRST_PAGE_TITLE); + this.viewer = viewer; + } + + public String getViewName() { + return nameText.getText(); + } + + private void setSnippet(ISnippet snippet) { + this.snippet = snippet; + } + + public ISnippet getSnippet() { + return snippet; + } + + @Override + public void createControl(Composite parent) { + rootComposite = new Composite(parent, SWT.NONE); + rootComposite.setLayout(new GridLayout(1, false)); + rootComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); + setControl(rootComposite); + + templateComposite = new NewViewComposite(rootComposite, SWT.NONE); + Composite composite = new Composite(rootComposite, SWT.NONE); + composite.setLayout(new GridLayout(2, false)); + composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + Label label = new Label(composite, SWT.NONE); + + label.setText(NewViewWizardMessages.FIRST_PAGE_LABEL_ID); + label.setForeground(ColorResources.DIALOG_NEW_VIEW_ID_LABEL); + + nameText = new Text(composite, SWT.BORDER | SWT.SINGLE); + nameText.setBackground(ColorResources.DIALOG_NEW_VIEW_NAME_TEXT_BG); + + nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + setPageComplete(false); + addListeners(); + } + + @Override + public void dispose() { + removeListeners(); + super.dispose(); + } + + private void addListeners() { + nameText.addModifyListener(this); + templateComposite.addSelectionChangedListener(this); + } + + private void removeListeners() { + nameText.removeModifyListener(this); + templateComposite.removeSelectionChangedListener(this); + } + + private void validate() { + if (!isValid()) { + setPageComplete(false); + } else { + setMessage(null, null); + setPageComplete(true); + } + } + + private boolean isValid() { + if (!isValidName(getViewName())) { + return false; + } + + if (!isValidTemplate(getSnippet())) { + return false; + } + return true; + } + + private boolean isValidName(String name) { + if (name.length() == 0) { + setMessage(null, NewViewWizardMessages.ERROR_EMPTY_ID); + return false; + } + + IWizard wizard = getWizard(); + Assert.isTrue(wizard instanceof AbstractWizard); + if (viewsPart != null) { + int result = PartUtil.isValidViewName(viewsPart, name); + if (result == PartUtil.ERROR_ID_EXISTS) { + setMessage(null, NewViewWizardMessages.ERROR_EXIST_ID); + return false; + } else if (result == PartUtil.ERROR_INVALID_ID) { + setMessage(null, NewViewWizardMessages.ERROR_INVALID_ID); + return false; + } + } + + return true; + } + + private boolean isValidTemplate(ISnippet template) { + if (template == null) { + setMessage(null, NewViewWizardMessages.ERROR_EMPTY_TEMPLATE); + return false; + } + + return true; + } + + @Override + public void modifyText(ModifyEvent e) { + if (e.widget.equals(nameText)) { + validate(); + } + } + + @Override + public void selectionChanged(SelectionChangedEvent event) { + if (event.getSelection().equals(StructuredSelection.EMPTY)) { + setSnippet(null); + validate(); + return; + } + ISelection selection = event.getSelection(); + Assert.isTrue(selection instanceof StructuredSelection); + StructuredSelection ss = (StructuredSelection) selection; + Object object = ss.getFirstElement(); + Assert.isTrue(object instanceof ISnippet); + ISnippet snippet = (ISnippet) object; + setSnippet(snippet); + validate(); + } + + public boolean createCommand(String platform, ViewPart selectedPart) { + String name = getViewName(); + ISnippet snippet = getSnippet(); + + Document document = snippet.getModel(); + DocumentPart docPart = selectedPart.getOwnerDocumentPart(); + + PartUnmarshaller unmarshaller = new PartUnmarshaller(); + Part part = unmarshaller.unmarshall(docPart, document, false); + + // get ViewPart from part + Part viewPart = null; + viewPart = (part instanceof ViewsPart) ? part.getChildren().get(0) : part; + + // update id for part that unmarshall from snippet + docPart.setPartPropertyIdRecursive(part); + viewPart.setPropertyValue("id", name); + + Part parent = selectedPart.getParent(); + Part nextSibiling = selectedPart.getNextSibling(); + + Point screenSize = viewer.getMScreenQualifierManager().getScreenSize(); + Point viewPosition = DesignEditorUtil.getNextViewPosition(parent, screenSize.x, screenSize.y); + viewPart.setPropertyValue(LayoutSchemaConstants.PAGE_LOCATION_X, Integer.toString(viewPosition.x)); + viewPart.setPropertyValue(LayoutSchemaConstants.PAGE_LOCATION_Y, Integer.toString(viewPosition.y)); + + command = PartUtil.createAddPartCommand(parent, viewPart, nextSibiling); + return true; + } + + public Command getCommand() { + return command; + } +} \ No newline at end of file diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewWizardMessages.java b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewWizardMessages.java new file mode 100644 index 0000000..f9a6793 --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewWizardMessages.java @@ -0,0 +1,54 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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.efluibuilder.ui.wizard.snippet; + +import org.eclipse.osgi.util.NLS; + + +public class NewViewWizardMessages { + private static final String BUNDLE_NAME = NewViewWizardMessages.class.getName(); + + // Wizard + public static String WIZARD_TITLE; + + // First Page + public static String FIRST_PAGE_TITLE; + public static String FIRST_PAGE_LABEL_ID; + + // Error messages + public static String ERROR_PROJECT_EMPTY; + public static String ERROR_EMPTY_ID; + public static String ERROR_EXIST_ID; + public static String ERROR_INVALID_ID; + public static String ERROR_EMPTY_TEMPLATE; + public static String ERROR_INVALID_TEMPLATE; + + static { + NLS.initializeMessages(BUNDLE_NAME, NewViewWizardMessages.class); + } + + private NewViewWizardMessages() { + } + +} diff --git a/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewWizardMessages.properties b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewWizardMessages.properties new file mode 100644 index 0000000..64cdb5e --- /dev/null +++ b/org.tizen.efluibuilder/src/org/tizen/efluibuilder/ui/wizard/snippet/NewViewWizardMessages.properties @@ -0,0 +1,15 @@ +# NewPageWizard +WIZARD_TITLE=New View + +# FirstPage +FIRST_PAGE_TITLE=Select a view to add +FIRST_PAGE_LABEL_ID=ID: + +#Error Message +ERROR_PROJECT_EMPTY=No project specified. +ERROR_EMPTY_ID=Enter an ID for the view. +ERROR_EXIST_ID=The ID already exists. +ERROR_INVALID_ID =The ID is invalid. +ERROR_EMPTY_TEMPLATE=No template is selected. +ERROR_INVALID_TEMPLATE=A deleted view cannot be restored. Are you sure that you want to delete the selected view? + diff --git a/package/build.linux b/package/build.linux new file mode 100755 index 0000000..249d44a --- /dev/null +++ b/package/build.linux @@ -0,0 +1,79 @@ +#!/bin/bash -xe + +__copy_necessary_binaries() +{ + echo "add necessary files." + ## ex) + ## ide_root_path_name=IDE + ## cp -rf ~~~~/file.file ${INSTALL_DIR}/${ide_root_path_name}/ + ## cp -rf ${SRCDIR}/package/addingFiles/* ${INSTALL_DIR}/ +} + +__set_parameter() +{ + #echo "TARGET_OS : ${TARGET_OS}" + build_script_path=${ROOTDIR}/pde-build +} + +# clean +clean() +{ + echo "=========================================CLEAN============================================" + __set_parameter + ${build_script_path}/clean.sh ${package_name} +} + +# build +build() +{ + echo "=========================================BUILD============================================" + pkgname_and_platform_list=`awk 'BEGIN{RS="\n\n"; FS="\n"} /Package:/{for(i=1;i 2017-10-26 +* 0.6.129 +- fix runtime issue when binding remote data source. +== Karthik Bhat 2017-10-26 +* 0.6.128 +- update user string & image in the UIB Project Converter +- update color of home icon in the view title +- addWhen the view is deleted, the efl-renderer system resource resource is destroyed. +- fix failuer during remote data source parsing +== ByoungChang Son 2017-10-26 +* 0.6.127 +- Bug fix for release resource issue in NUIBBuilder(Open with previously layout.xml) +== Seongwon Shim 2017-10-23 +* 0.6.126 +- Bug fix for properties view +== Seongwon Shim 2017-10-23 +* 0.6.125 +- Bug fix +- Add contextmenu in the Design Editor for the Storyboard +- Improvement performance the Properties View (eg: Entry UI Component) +== ByoungChang Son 2017-10-23 +* 0.6.124 +- Remove tab ui and add editor switch button +== Seongwon Shim 2017-10-13 +* 0.6.123 +- Stabilize & bug fix +== ByoungChang Son 2017-10-10 +* 0.6.122 +- Stabilize XML Editor +- Unified Design tab, Storyboard tab in the WYSIWYG Editor +== ByoungChang Son 2017-09-29 +* 0.6.121 +- Removes the Connection Explorer View. +== Sujin Kim 2017-09-20 +* 0.6.120 +- Support tizen 4.0 wearable +== Dongjo Hwang 2017-09-04 +* 0.6.119 +- PROFILE: Add mobile3.0 project in uitool(SPTSDKUX=4256) +== YongSeok Lee 2017-07-17 +* 0.6.118 +- Initial packaging after migration to github +- Revise validation of XML editor +== DongJo Hwang 2017-06-21 +* 0.6.117 +- bugfix - #3947 Failed to initialize layout editor due to eception +- [Databinding] Fix for databinding filter windows compatibility issue +- Binding info icon should turn up, on drop of model item if show binding info is enabled +== DongJo Hwang 2017-05-23 +* 0.6.116 +- 'Widget' string replaced with 'UI Component' in UI +- [Databinding][SPTSDKUX-3926] After renaming data source it doesn't update in attached data model +== Aditya Aswani 2017-04-27 +* 0.6.115 +- [Databinding][SPTSDKUX-3826] Unable to bind datamodel to a supported +- [Databinding][SPTSDKUX-3825] Data source/ Data model can't remove +== Aditya Aswani 2017-04-10 +* 0.6.114 +- Bug fixed radio variation in mobile 2.3(SPTSDKUX-3789) +- Bug fixed gengriditem in mobile 2.3(SPTSDKUX-3790) +== DongJo Hwang 2017-04-07 +* 0.6.113 +- Bug Fix: [Databinding] Disable drag of non primitive array tree item +- Remove databinding for unsupported Tizen platform and profiles +- Resolve generated code warnings +- Enable databinding for wearable 3.0 +== Mukul Yadav 2017-04-06 +* 0.6.112 +- Property name changed from 'data-bind' to 'data_bind' +- [Databinding] Path for binding items changed from Json format to xPath format +- [Databinding]Collapse all functionality added for source and model panel +- [Databinding] Bug: Binding not happening when a event is added to a widget +== Aditya Aswani 2017-03-28 +* 0.6.111 +- Bug fix: ListItem drop +- Bug fix: Improper index generation on selection of Array in Combo box +== DongJo Hwang 2017-03-17 +* 0.6.110 +- Enabled XML support for data sources(IDE side) +- Add xml support(Code generation) +- Change databinding icons to grayscale color scheme +== Aditya Aswani 2017-03-21 +* 0.6.109 +- Fixed a build error for MANIFEST.MF of databinding commit +== DongJo Hwang 2017-03-17 +* 0.6.108 +- Change project java runtime version from 1.7 to 1.8 +-Merge branch 'databinding_develop' into develop +== DongJo Hwang 2017-03-17 +* 0.6.107 +- update image files(PROJECT MIGRATOR) +- apply new UX/UI*PROJECT MIGRATOR) +== DongJo Hwang 2017-03-10 +* 0.6.106 +- Bug fixed layout.xml variation in mobile 3.0(SPTSDKUX-3540) +- Bug fixed layout.xml variation in wearable_circle3.0(SPTSDKUX-3540) +- Bug fixed layout.xml variation in wearable_circle2.3.1(SPTSDKUX-3540) +- Bug fixed layout.xml variation in mobile 2.3(SPTSDKUX-3540) +- Bug fixed layout.xml variation in mobile 2.4(SPTSDKUX-3540) +- Bug fixed layout.xml variation in wearable2.3.1(SPTSDKUX-3540) +- Bug fix for copy & paste in m-screen(SPTSDKUX-3540) +- bug fixed - #3426 - add multiple widgets into box container by DND +== DongJo Hwang 2017-03-09 +* 0.6.105 +Modify to support Multi-byte character +== DongJo Hwang 2017-02-21 +* 0.6.104 +Change label's ellipsis property default true(SPTDKUX-3348) +== DongJo Hwang 2017-02-14 +* 0.6.103 +- remove useless layout +- Storyboard not allowing to delete startup view +- Undo after delete of startup view is not working properly +== DongJo Hwang 2017-02-13 +* 0.6.102 +- Apply GUI guide for edit dialog +== DongJo Hwang 2016-12-26 +* 0.6.101 +- Fixed genlistitem image bug in wearable(SPTSDKUX-2693) +== DongJo Hwang 2016-12-20 +* 0.6.100 +- bug-fix, Resolve issue of Finish button malfunction in user view page. +-[StoryBoard] Device view change width issue resolved +== DongJo Hwang 2016-12-20 +* 0.6.99 +- Generate elm_datetime_format_set when style is default(SPTSDKUX-3052) +- Remove getVisitor interface from IProjectMigrator and rename some classes +== DongJo Hwang 2016-12-16 +* 0.6.98 +- changes component create rule on canvas - #3051 +- Rename UIBEnabler -> ProjectMigrator +- Block event that framework not supporting +- fixed a layout bug -#3028 +- Bug fixed panel in mscreen(TSCP-750) +- Bug fixed scroller in mscreen(TSCP-751) +- revise execution option - handle specific character '&' +- Fixed issue where numbers were removed from the clone project if the source project name contained a number +- Disable cancle in add user view mode +- Bug fixed panes in mscreen(TSCP-746) +- Bug fixed box in mscreen(TSCP-749) +- Bug fixed grid in mscreen when wearable(TSCP-748) +- Bug fixed table in mscreen(TSCP-747) +- [StoryBoard] fixed Landscape/Portrait view change bug +== DongJo Hwang 2016-12-16 +* 0.6.97 +- fixed a selection bug in propertiesView - #2979 +- Change color api codegen flexible(TSCP-744) +== DongJo Hwang 2016-12-13 +* 0.6.96 +- fixed a bug in pasteAction - #2829 +== DongJo Hwang 2016-12-12 +* 0.6.95 +- revise command line execution option [SPTSDKUX-2965] +- Bug fixed in mscreen(TSCP-446) +- Add color_class_api +- Change col and rows in table(SPTSDKUX-2821) +- support copy&paste for toolbarItem & hoverselItem - #2980 +- Add color_class_api +- fix the logic to get efl-renderer path for wearable (SPTSDKUX-2978) +- Add color_class_api +- update user strings and related images +- Unable to delete view from storyboard. +- Refactoring uibconberter +- update user string +== DongJo Hwang 2016-12-12 +* 0.6.94 +- Add execution option -o to open the style directly +== DongJo Hwang 2016-12-05 +* 0.6.93 +- reduce unnecessary redrawing in canvas +== DongJo Hwang 2016-12-05 +* 0.6.92 +- Rename method and move some job +- fixed a memory leak in Storyboard +- Delete button colors in wearable +- Stabilize in the user_view page +- Fixed an issue where an error tooltip could not be displayed (check tooltip disposed) +- Fixed an issue where the Finish button was disabled when the user view was added. +- Fixed index error when clearing +- update comment of template/user_view +== DongJo Hwang 2016-12-05 +* 0.6.91 +- Add descriptor for wearable-circle-3.0 +- Added the 'colors' attribute for wearable circle 3.0 +- Fixed and add hoversel in mobile3.0 +== DongJo Hwang 2016-12-02 +* 0.6.90 +-Revise Component designer dialog description +- Add res folder in build.properties +- bugfix in pastePartColorAction +- Add a restriction for style of wearable circle 3.0 +- Add a restriction for style of mobile 3.0 +- Delete horizontal in index descriptor(SPTDKUX-2876) +== DongJo Hwang 2016-12-02 +* 0.6.89 +- support item copy&paste - #2892 +- Color_api bug fixed +-Merge branch 'color_api' into develop +- Seperate app main visitor to handle exception +- add protect code for empty document +- Bug fix for view template(SPTSDKUX-2917) +- update delete policy of user view manager +== DongJo Hwang 2016-12-01 +* 0.6.88 +- Add delete user view file logic +- Change codegen in toolbar(SPTSDKUX-2868) +- Merge from support_legacy branch +- Support java 1.8 environment. +== DongJo Hwang 2016-12-01 +* 0.6.87 +- Add file path adapted OS to EDJResourceSyncManager +- Add description to guide refresh project +- Add Hoversel +== DongJo Hwang 2016-11-29 +* 0.6.86 +- Remove unnecessary context menu (GUI Fetch) +- Fix screen configuration sync +== DongJo Hwang 2016-11-28 +* 0.6.85 +- Fix a bug of Component designer in Windows +- Fixed a bug of tableComponent in canvas - #2855 +- Change toolbar property for bug fixed(SPTSDKUX-2742) +- Fixed some java 7 code to java 6. +== DongJo Hwang 2016-11-26 +* 0.6.84 +- Add non-schema based validator +- Support Windows OS +- add workaround code for flickering in canvas - #2772 +- fixed a exception in edjResourceManager - TSCP#717 +- Fixed a bug in ResourceFileDuplicator +== DongJo Hwang 2016-11-25 +* 0.6.83 +- modify feedback size of placeholder +- modify D&D mechanism in outline view - #2829 +- fixed a bug in connector - TSCP#709 +- Fixed restrictions of screen configuration +- Change a policy of XML fault. +- apply open edc editor icon +== DongJo Hwang 2016-11-24 +* 0.6.82 +- Fixed drawing bugs in canvas - TSCP#705 +- Add execution option for Windows, Mac OS. +- Custom style set currently can be deleted. +- change parameter name for _post function in connection +- Bug fix for popup +-[StoryBoard]- Popup and CtxPopup code generation(SPTSDKUX-2613) +-Remove unused file. +- Refactored some codes. +- Fixed class cast exception in canvas - TSCP#704 +- Add create api for popup and ctxpopup uib_create_popup, uib_create_ctxpopup +== DongJo Hwang 2016-11-22 +* 0.6.81 +- Stabilize the feature for Component designer +- Fixed some NPEs. +- draw outlines to item & item container +- fixed default value of color in background widget(TSCP-688) +- Fixed warning bug in layout.xml(TSCP-669) +== DongJo Hwang 2016-11-14 +* 0.6.80 +- fixed a D&D bug in canvas - TSCP#683 +- fixed a drawing bugs in canvas +== DongJo Hwang 2016-11-10 +* 0.6.79 +- WYSIWYG : modify feedbacks in canvas +- PALETTE: When the user drag the same icon, the issue of the invalid selected ... +- UI : apply design guide for Component designer +== DongJo Hwang 2016-11-08 +* 0.6.78 +- Fixed wrong lowest position of scale widget. (SPTSDKUX-1363) +- Change minmax property issue in spinner(SPTSDKUX-2468) +-Connection with Component designer. +- Upgrade drag-and-drop for the direct manipulation. +- apply none scalable feedback +- Remove removed attribute from view template +- modify boilerplate +== DongJo Hwang 2016-11-02 +* 0.6.77 +-Bug fix - invalid regex for double (SPTSDKUX-2401) +-[StoryBoard] - Resolved New page view name change Properties not displaying in properties tab +== DongJo Hwang 2016-10-25 +* 0.6.76 +-[StoryBoard] - Panning functionality implementation +-[StoryBoard] Flicker issue fix +- Add disable codegen in wearable-square progressbar(SPTSDKUX-2387) +- Delete naviframe/title_icon style in button(SPTDKUX-2386) +- Disable Entry's ediatable property when password property is true, in wearable(SPTSDKUX-2359) +- Fixed order bug in ComponentValidator(SPTSDKUX-2336, TSCP-628) +- Fixed bug in WeightHint(SPTSDKUX-2336, TSCP-628) +- Fixed schema based validation problem. (SPTSDKUX-2271, 2338) +== DongJo Hwang 2016-10-24 +* 0.6.75 +- Add max constraint value for padding in table and box(SPTSDKUX-2334) +== DongJo Hwang 2016-10-19 +* 0.6.74 +- Fix wrong spelling for editfield style(SPTSDKUX-2321) +== DongJo Hwang 2016-10-18 +* 0.6.73 +- Change disable set in circle_progressbar(SPTSDKUX-2226) +== DongJo Hwang 2016-10-13 +* 0.6.72 +- Single line property disable when password is true(SPTSDKUX-2276) +== DongJo Hwang 2016-10-13 +* 0.6.71 +- Single line property disable when password is true(SPTSDKUX-2276) +== DongJo Hwang 2016-10-13 +* 0.6.70 +- Add integer range check logic for Integer type(SPTSDKUX-2269) +- Fixed some problems that cursor is moved suddenly. +- Fixed the line remaining problem about removed elements +- Change properties spelled and tooltip add(SPTSDKUX-2274) +== DongJo Hwang 2016-10-12 +* 0.6.69 +- Remove circle surface create code(SPTSDKUX-2229) +- Added error reason dialog for initialization failure. +- Change user string +- Modify constants for end_image_path and add image_path for resource management +- Change disable set in circle_progressbar(SPTSDKUX-2226) +- Add elm_datetime_format_set for wearable square style(datepicker_layout, timepicker_layout)(SPTSDKUX-2236) +- Remove map component from wearable(SPTSDKUX-2224) +- Fixed some bugs +== DongJo Hwang 2016-10-12 +* 0.6.68 +- Switch child components of Panes +- Add max value for cols and rows(SPTSDKUX-2201) +- radio button text is cropped. +- Fixed added middle elements sync problem. +== DongJo Hwang 2016-09-30 +* 0.6.67 +- WYSIWYG : When image is set, Redraw renderer in Windows OS. +== DongJo Hwang 2016-09-28 +* 0.6.66 +- Fix Storyboard UI Issues (SPTSDKUX-2160 and SPTSDKUX-2161) +== Karthik Bhat 2016-09-27 +* 0.6.65 +- Fixed fatal error state problem when delete modified project without saving (TSCP-435) +== DongJo Hwang 2016-09-27 +* 0.6.64 +- use copied resource files for rendering in windows OS +- Update current max id when id is changed(TSCP-533) +-Add package dependency to enventor-eplugin +== DongJo Hwang 2016-09-26 +* 0.6.63 +- Fixed synchronization of .uproject file +- Improved child element synchronization accuracy +- set proxy info to environment for map component(TSAM-5775) +-[StoryBoard] Button delete connection not deleting issue resolved +-[StoryBoard] Resolved Button delete conflicting with view delete issue +== DongJo Hwang 2016-09-22 +* 0.6.62 +- Fixed NPE with varient part in model. +== DongJo Hwang 2016-09-21 +* 0.6.61 +- Add icon callback logic for genlist item(SPTSDKUX-2086) +- Add scroller & panel component paste action(SPTSDKUX-2121) +- Bug fixed in macos-x change the last column width of mscreen table +- Fixed the crashed layout editor openning case +- Fixed project deletion failure sometimes (SPTSDKUX-1954) +- Change the last column width because all OS's mscreen table show similar +== DongJo Hwang 2016-09-20 +* 0.6.60 +- Add tooltip about mode property in list widget(SPTSDKUX-2005) +- Fixed bug when add button click in mscreen dialog(SPTSDKUX-2039) +== DongJo Hwang 2016-09-19 +* 0.6.59 +- change bundle information +- Fixed synchronization from TextEditor to DesignEditor +-[StoryBoard] Resolved Button delete conflicting with view delete issue +- Change of view id in properties view should reflect in storyboard view +- SPTSDKUX-1994) +-[TSCP-456/TSCP-444] Fix UI issues when deleting a view from Storyboard Tab. +- Refactored some codes +- Replace ctxpopup/popup parent id(tizen.view -> view) +== DongJo Hwang 2016-09-19 +* 0.6.58 +- Fixed some bugs & refactored codes. +- apply design guide (SPTSDKUX-1864) +- disable menu items (List and Icons Only) of in the context menu +== DongJo Hwang 2016-09-07 +* 0.6.57 +- Fixed that some added child elements are not synchronized. (SPTSDKUX-1964) +== DongJo Hwang 2016-09-06 +* 0.6.56 +- Add style property codegen in Scroller Container(SPTSDKUX-1995) +- Adjust textbox width of CheckScaleMethod in Ubuntu OS +- Bug fix for calendar component +- Bug fix for ctxpopup direction property(SPTSDKUX-1964) +- set short cuts to Zorder actions +== DongJo Hwang 2016-09-02 +* 0.6.55 +- Delete disable block code when check widget style changed(SPTSDKUX-1912) +== DongJo Hwang 2016-08-26 +* 0.6.54 +- Remove item_type property from genlist item(SPTSDKUX-1917) +== DongJo Hwang 2016-08-26 +* 0.6.53 +- fix, screen_orientation of views(SPTSDKUX-1913) +- Table pack in mscreen configurator for Linux os(TSCP-522) +== DongJo Hwang 2016-08-26 +* 0.6.52 +- Removed duplicated actions +- remove watch service +== DongJo Hwang 2016-08-23 +* 0.6.51 +- Delete diable property in progressbar(SPTSDKUX-1854) +- Add cursor into screen configurator dialog when user add screen(SPTSDKUX-1754) +== DongJo Hwang 2016-08-23 +* 0.6.50 +- [SPTSDKUX-1880] Fix Orientation issue in storyboard. +== Karthik Bhat 2016-08-22 +* 0.6.49 +-Apply user strings in Properties view +== DongJo Hwang 2016-08-22 +* 0.6.48 +- Revision category (Common, UI Component specification => General) +- to prevent create a new view from template with same view id +- update user strings (UI Component, UI Container -> UI components, UI containers) +- modify info-feedback's font size in design editor - TSCP #501 +- Apply user string to New View Template dialog +- Apply user string to Snippets- +== DongJo Hwang 2016-08-22 +* 0.6.47 +- Apply popup and ctxpopup template in mobile profile +- remove popup&ctxpopup from storyboard's context menu in wearable project +== DongJo Hwang 2016-08-22 +* 0.6.46 +- auto update edj files when file changed - #1690 +- apply user strings in outline view +- Screen Config changed when Screen deleted(SPTSDKUX-1762) +- Bug fixed when every name field does not filled(TSCP-449) +== DongJo Hwang 2016-08-19 +* 0.6.45 +- Update package version +== Seongwon Shim 2016-08-17 +* 0.6.44 +- Bug fix genlistitem image for wearable circle +- Refactored ResourceChangedEvent for editor +- Added lines of exact position for number of ruler +== DongJo Hwang 2016-08-16 +* 0.6.43 +- Fixed Finish button(SPTSDKUX-1755) +- Delete disable option of index(SPTSDKUX-1811) +- Delete disable option of label(SPTSDKUX-1810) +- Tuned spaces for UX guide +- Fixed to can't open editor with exceptions (SPTSDKUX-1808) +- modify selection UX - #1709 +- Removed unnecessary codes. +- remove unnecessary casting +- improve UX in design view -#1799, #1756, #420, #413 - modify margin when Fit To Screen - apply Fit To Screen when screen configuration changed - maintain Fit To Screen while 2s when editor open +- improve delete action - #457 +== DongJo Hwang 2016-08-16 +* 0.6.42 +- Add view (Ctx)popup of the Context menus are available only on mobile +- Change UserString +- Change mscreen Orientation Image +== DongJo Hwang 2016-08-11 +* 0.6.41 +- Fix a bug that property changes doesnot set for viewpart +== DongJo Hwang 2016-08-11 +* 0.6.40 +- Applied user strings for new UX +- removed Pinned action +- apply user string in Palette +- Delete context menu option(SPTSDKUX-1765) +- Change wizard GUI(SPTSDKUX-1732) +- apply user strings in design view +== DongJo Hwang 2016-08-11 +* 0.6.39 +- Remove dependency condition between style and disable property in button +- Fixed bug in preview toolbar(SPTSDKUX-1494) +== DongJo Hwang 2016-08-04 +* 0.6.38 +- Hide some attributes of Index component in wearable +- Remove logic that display name replace value when value is empty string +- Codegenerator : Change set order image and icon to list item +- Change sourcetab toolbar layout +- Add include uib_views_inc.h to event handler +== Jungwook Ryu 2016-08-03 +* 0.6.37 +- Fixed that locale changes are not applied. +- layout component +- StoryBoard - Bug fix for startup page icon change +- Disable combo when combo is empty +== DongJo Hwang 2016-08-01 +* 0.6.36 +- Make Snippet dialog +- Remove invalid code +- Change textbox to combobox (group attribute of Layout) +- Changed xsl indentation to whitespaces +- Applied backslash escaping for file path (SPTSDKUX-1640) +- Fixed validation problem. +- bugfix in EdjResourceSyncManager +- Fixed xml synchronization (SPTSDKUX-1632) +- Change Dialog GUI & BUG FIXED +== DongJo Hwang 2016-07-28 +* 0.6.35 +- update groupnames when edj changed - #1264 +- Revert Auto perspective change +== DongJo Hwang 2016-07-26 +* 0.6.34 +-Auto perspective change +== DongJo Hwang 2016-07-26 +* 0.6.33 +- Fixed NPE when disposing sometimes. +- Revise ellipsis of Label +- Add Dialog Resource Icon File +- show available components in paletteView - #112 +- supported, showing dynamically categories +== DongJo Hwang 2016-07-25 +* 0.6.32 +- [StoryBoard] Maximize-Minimize feature for Landscape mode +- invalid font dispose +- Change efl-renderer path to support platform 3.0-wearable +- Refactoring for maintaining font resources. +== DongJo Hwang 2016-07-22 +* 0.6.31 +- Fixed bugs (SPTSDKUX-1479) +== DongJo Hwang 2016-07-21 +* 0.6.30 +- [SPTSDKUX-1472] Fix Rotation being applied on Storyboard from preview pane. +== DongJo Hwang 2016-07-19 +* 0.6.29 +- Refactoring for maintaining color resources. +- fixed a redraw bug in design view - #1493 +- Set Anit-alias preview Background Image +== DongJo Hwang 2016-07-18 +* 0.6.28 +- Refactoring for maintaining image resources. +- Rempve annotation (SDKRM-1075) +== DongJo Hwang 2016-07-15 +* 0.6.27 +- refresh design viewer when edj file changed - #1477 +== DongJo Hwang 2016-07-13 +* 0.6.26 +- Update gengrid style +- update font_util, apply font cache into palette +== DongJo Hwang 2016-07-13 +* 0.6.25 +- Remove disable property from map +- Update genlist style +- set a part's first id num to 1 - #1365 +- Bug fix in sourcetab toolbar orientation tooltip-text +== DongJo Hwang 2016-07-12 +* 0.6.24 +- fixed a casting error in textEditor +== DongJo Hwang 2016-07-11 +* 0.6.23 +- Change SourceTab Preview Background Image +== DongJo Hwang 2016-07-08 +* 0.6.22 +- Apply wearable widget code +- Change asset preview image +- Delete Progressbar style, invert option in wearable-circle(TWC-56) +- Remove constraints to set disable within specific style for check component(TWC-58) +- Change default value for autohide enable property in index(TWC-62) +-[StoryBoard] - Bug fix for switching between layout.xml of different projects Bug fixed for wrong code generation in StoryBoard. +-[StoryBoard] - Removed White line decorator from Connection +== DongJo Hwang 2016-07-08 +* 0.6.21 +- Remove wearable-2.3.2 descriptor/xsd +-[StoryBoard] Maximize-Minimize feature for each pages +-Fix Screen Configuration not getting synced between Design and Storyboard view. +- Delete Horizontal Direction in list widget(TWC-67) +- Apply new widget code without 2.3.1 +- Fixed the attribute missing of plugin.xml for org.eclipse.wst.sse.ui.sourcevalidation +- New Asset about Preview_lines +- fix the image paht of view extension +- Apply new widget code without 2.3.1 +- Add wearable-circle 2.3.2 descriptor & xsd +== DongJo Hwang 2016-07-05 +* 0.6.20 +- The scrollbar's triangle widgets changed into the images. +- Change the layout.xml icon +== DongJo Hwang 2016-07-04 +* 0.6.19 +- Get the Code When Toolbar Style Changes navigationbar +== DongJo Hwang 2016-07-01 +* 0.6.18 +- change disable api elm_object_disabled_set -> eext_circle_object_disabled_set +== DongJo Hwang 2016-07-01 +* 0.6.17 +- add 'default' style for genlist in mobile profile +== DongJo Hwang 2016-07-01 +* 0.6.16 +- Enable wearable 2.3.2 +bugfix in PasteAction - #1357 +== DongJo Hwang 2016-07-01 +* 0.6.15 +- Enable wearable 2.3.2 +== Seongwon Shim 2016-07-01 +* 0.6.14 +- delete a custom UI Component snippet +== DongJo Hwang 2016-06-30 +* 0.6.13 +- Remove gengrid/multibuttonentry related code from wearable profile in genereated code +- Change sourceTab toolbar left control height +== Seongwon Shim 2016-06-28 +* 0.6.12 +- Change Sourcetab Toolbar Using ComboBox +- Change preview background image +== DongJo Hwang 2016-06-27 +* 0.6.11 +-Adjust align of Textbox by CheckScale (Left -> Center) +- Preview Toolbar and canvas change +- Reverted changes for Combo to ToolItem +- update UI category's scrolling button (color, dimension) +-Don't show Context Menu Option for Views which do not have event assosiated with them. +-[StoryBoard] Page header color change in StoryBoard tab +-[TNEF-7091] Fix Context Menu events not received in MAC when establishing a Page Connection. +- Custom font didn't apply in the beginning time +== DongJo Hwang 2016-06-23 +* 0.6.10 +- apply gui guide (PALETTE & OUTLINE) +- Revision color of Scale +- Fixed the percent image clipping problem in toolbar +- Sourcetab toolbar v-align mac linux +- add protect code for rendering - #1238 +- Apply Properties view GUI guide +- Apply ascending sort in Palette items +- Delete warning messages when no UI component +== DongJo Hwang 2016-06-22 +* 0.6.9 +- The too many generated problem is solved (SPTSDKUX-1027) +- Updated new icons for the UI guide of toolbar +- Applied UX guide for editor ruler & canvas +- add graphicalDataInitializeFailedException +- Sourcetab toolbar seperator and valign +== DongJo Hwang 2016-06-17 +* 0.6.8 +- Enable Scrollbar in the Tizen palette +- Add protect code - #1201 +== DongJo Hwang 2016-06-16 +* 0.6.7 +- Fix for schema loading issue +- Bug fix for m-screen +- support mscreen in copy&paste action - #1088 +- bugfix - layout component into designer view in landscape mode (TSCP #254) +== DongJo Hwang 2016-06-16 +* 0.6.6 +- Tuned details for toolbar +== DongJo Hwang 2016-06-15 +* 0.6.5 +- Fixed a rendering bug in previewer +- Add protect code for errors in renderer +- internalization of gef.palette +== DongJo Hwang 2016-06-15 +* 0.6.4 +- BUILD PROJECT BUG CHANGED +- Apply formatter to xsl, xml, xsd +- Applied the UX guide for toolbar +- Fixed a potential bug. +- Added project specific code analysis options +- Modify create_window_obj function in tv profile +== DongJo Hwang 2016-06-15 +* 0.6.3 +- WYSIWYG: Changed combos in editor toolbar to dropdown toolitem by UX guide. +== DongJo Hwang 2016-06-13 +* 0.6.2 +- Bug fix for exception when loading descriptor +== Seongwon Shim 2016-06-10 +* 0.6.1 +- [UX] Apply advanced UX +- [Model] Apply re-implementation model +== Seongwon Shim 2016-06-10 +* 0.5.53 +- bugfix in source tab - #749 +- Fixed clipped combos in toolbar for Windows +== DongJo Hwang 2016-06-01 +* 0.5.52 +- Bug fix for msconfigurator +- modify position of ToolItem +- fix, X positon of ToolItem in PreviewToolbar +- Fix a bug that Title is not changed in properties view +== DongJo Hwang 2016-06-01 +* 0.5.51 +- apply gui guide +- Fixed a bug (Undo on TextEditor) +-Adjust location of Text in CheckScaleMethod +-Fix width of perspective layout +== DongJo Hwang 2016-05-31 +* 0.5.50 +-Adjust minimum scroll size of Properties view +-Adjust size of Text in CheckScaleMethod +-[StoryBoard] Synching of Configuration Toolbar between StoryBoard and Design tab +- Merge tv profile related code from develop +- Fixed hover problems for align actions +- Bug fix for gengrid direction property +- Change configuration for tizen_3.0 +== DongJo Hwang 2016-05-31 +* 0.5.49 +- fix ClassCastException in OutlineCreateTemplateAction +- Added a horizontal line seperator between toolbar and editor area +-Adjust view ratio (Project Explorer and Outline view) +== DongJo Hwang 2016-05-30 +* 0.5.48 +- Fixed the toolbar crash problem when editor tabs are changed. +== DongJo Hwang 2016-05-27 +* 0.5.47 +- Fixed a bug (codegen on storyboard) +- Fixed a bug (Sync. Selection on SourceTab) +== DongJo Hwang 2016-05-27 +* 0.5.46 +-[StoryBoard] Fix of the Connection Creation not creating Event Part and Connection Deletion deleting all the connections of Component +- Added scale sides like plus, minus +- tunning UI for gui guide +== DongJo Hwang 2016-05-27 +* 0.5.45 +- Bug fix for set startup view +- Apply new icon (OUTLINE, PROPERTIES, PALETTE) +- Apply UI - Connection in Properties view +- Bug fix for progressbar +- Applied icons of the action tool item +- Add reset properties for component which parent is box container +== DongJo Hwang 2016-05-26 +* 0.5.44 +- Fixed a bug about connection codegen (storyboard, header) +== DongJo Hwang 2016-05-26 +* 0.5.43 +- Fixed a bug about conection codegen (storyboard) +- Apply add view (template, ctxpopup, popup) when not focusing +- Adjust Perspective ratio +- Changed information toolitems to combo +- fix perspective layout +== DongJo Hwang 2016-05-26 +* 0.5.42 +- Add title line in Properties view +== DongJo Hwang 2016-05-26 +* 0.5.41 +- Revision GUI of Event in Properties view +- Add initvalue for view +== DongJo Hwang 2016-05-26 +* 0.5.40 +- Add reset properties in policy +- Add null check before access propertydescriptor +== DongJo Hwang 2016-05-26 +* 0.5.39 +- Bug fix for toolbar +- Fixed a bug (NPE) +== DongJo Hwang 2016-05-26 +* 0.5.38 +- apply gui guide in texteditorComposite +- update icon file(listiem, toolbar icon), update widget descriptor file (all platforms) +== DongJo Hwang 2016-05-25 +* 0.5.37 +-[StoryBoard] Connection delete fix for StoryBoard +- Toolitem sequence is changed. +- update perspective icon +- Modify not to marshal location_x, location_y, to xml +-[StoryBoard] Removing selection handle on selection of the page +-Apply GUI Guide for Properties view +-[StoryBoard] Location info getting refreshed in properties page on moving page +- Set initValue for view type +- Remove & Change property name/value +== DongJo Hwang 2016-05-25 +* 0.5.36 +-Adjust location of View in Native UI Builder perspective +-Fix bug in Properties view +- fix, change locale in ScreenDesignToolbar +-Stabilizing Properpties view +- Bug fix for layout group +- Remove col_count from panes +- fix, resource annotation in properties view +-[StoryBoard] Fix of Add View option from StoryBoard view +== DongJo Hwang 2016-05-25 +* 0.5.35 +- Apply Design Guide for Scale +- A shared toolbar in editor is divided. +- [StoryBoard] Setting up Startup view from StoryBoard +- Modify style value for spinner in xsd(default -> horizontal) +== DongJo Hwang 2016-05-25 +* 0.5.34 +- bugfix in outline view - update root editpart when views property changed +- View id change on change of loaction info +- [StoryBoard] Header text alignment to Left-Center +- Add default value for span_size in progressbar +== DongJo Hwang 2016-05-24 +* 0.5.33 +- remove org.tizen.efluibuilder.gef.fragment plugin in feature.xml +== DongJo Hwang 2016-05-24 +* 0.5.32 +- fix palette NotFoundClass Exception +- [StoryBoard] Unselected Page header color change in StoryBoard tab +- apply gui guide (OUTLINE, PALETTE) +== DongJo Hwang 2016-05-24 +* 0.5.31 +-[StoryBoard] - Location info added in Properties tab for view +== DongJo Hwang 2016-05-24 +* 0.5.30 +- Apply GUI Guide for Properties view +- [StoryBoard] Connection Arrow UI change +- [StoryBoard] Goto Designer Tab on double click of the view +- Apply UI Guide for Properties view +- apply startup unichodeCh (\ u 2 7 A A) +- Fixed a bug about NPE +== ${SINGLE_NAME} 2016-05-23 +* 0.5.29 +initial version up using automatic package version-up tool +== ${SINGLE_NAME} 2016-05-23 +* 0.5.28 +- update version +== Hyeonsu Seo 2016-05-23 +* 0.5.27 +- merge from new model to advux +== Hyeonsu Seo 2016-05-17 +* 0.5.26 +- Fixed a build problem that depends with JDT & JUnit +== Jihoon Song 2016-05-14 +* 0.5.25 +- PALETTE: apply GUI Guide (Palette title area) +- Add style descriptor for toolbar, index, popup, scroller +== Jungwook Ryu 2016-05-13 +* 0.5.24 +- View managing function from Navigation View in outline view +- Revision Properties view +- Change location of Preview (right -> left) +- PALETTE: applied GUI Guide of Palette +== Seongwon Shim 2016-05-04 +* 0.5.23 +- Add New Empty View in Outline view +- Remove a view in Outline view +- Fixed remove a view in Outline view +== ByoungChang Son 2016-04-18 +* 0.5.21 +- Navigation view is removed +- Outline view is changed to views +== Seongwon Shim 2016-04-14 +* 0.5.20 +- Moved location property from layout.xml to .uproject +- Show messagebox of drag and drop for resource of invalid project path +== Seongwon Shim 2016-03-31 +* 0.5.19 +- Update texteditor +== Hyeonsu Seo 2016-03-28 +* 0.5.18 +- Update texteditor +== Hyeonsu Seo 2016-03-28 +* 0.5.17 +- Update texteditor +== Hyeonsu Seo 2016-03-28 +* 0.5.16 +- Update texteditor +== Hyeonsu Seo 2016-03-28 +* 0.5.15 +- Update texteditor +== Hyeonsu Seo 2016-03-28 +* 0.5.14 +- Update texteditor about mscreen's configurations +== Hyeonsu Seo 2016-03-25 +* 0.5.13 +- update texteditor logic +== Seongwon Shim 2016-03-25 +* 0.5.12 +- Fixed incorrect code in preview +== Seongwon Shim 2016-03-21 +* 0.5.11 +- Fixed a Undo Error +- Fixed a bug that when generator reads resources-path +- Modify converter for error handling +- Fixed a bug about connections of storyboard +== Seongwon Shim 2016-03-20 +* 0.5.10 +- XML SCHEMA : Change app.xml -> .uproject +- M-Screen : Apply new device +== Seongwon Shim 2016-03-18 +* 0.5.9 +- Fixed a bug (If you open config.xml, emitted NPE) +to "Entry"' +== Hyeonsu Seo 2016-03-14 +* 0.5.8 +- Rollback 'Fixed a issue (sometimes entry widget's text is changed +to "Entry"' +== Hyeonsu Seo 2016-03-11 +* 0.5.7 +- XML SCHEMA : remove col_count attribute from panes widget +- Update logics about LayoutSchemaProvider +- extend checking unused editor logic +- Modify radio's value property default value +- Seperate convert plugin +- Fixed a bug that you can't see a feedback when you create a obj into Box +- Fixed Bug: View Count not getting cleared on dispose +- [StoryBoard] Fixed Issues due to synching with develop. +- fix Get projectPath about drag-and-drop from Project explorer in ... +- rollback event for item widget +- XML SCHEMA : correct element name of toolbaritem add postponed widgets that ... +- Change event signal for view +== Hyeonsu Seo 2016-03-11 +* 0.5.6 +- [BugFix] Bug fix for external schema location provider +- [BugFix] Bug fix for code gernerator(container widget) += Seongwon Shim 2016-03-09 +* 0.5.5 +- [BugFix] Validate xml by xsd properly +- [BugFix] Change selection policy between editor and properties view +- [BugFix] Update event handler list for each widget += Seongwon Shim 2016-03-08 +* 0.5.4 +- [BugFix] Modify Mscreen configurator += Seongwon Shim 2016-03-08 +* 0.5.3 +- [BugFix] Modify convert logic +- [BugFix] Update texteditor(view sync etc) += Seongwon Shim 2016-03-07 +* 0.5.2 +- Merage revisions from develop to tizen_sdk += Hyeonsu Seo 2016-03-04 +* 0.5.1 +- [Feature] MScreen +- [Feature] XML Editor(two-way) += JeongHwan Kim 2016-03-03 +* 0.4.15 +- [BugFix] Connection not being loaded for widget inside internal container += JeongHwan Kim 2015-10-15 +* 0.4.14 +- Set property condition (toolbar) += JeongHwan Kim 2015-10-13 +* 0.4.13 +- Modify refresh (whole --> partial) in Navigation +- [BugFix] Operation error in Storyboard +== JeongHwan Kim 2015-10-12 +* 0.4.12 +- [BugFix] Resolve resource issue +== JeongHwan Kim 2015-10-08 +* 0.4.11 +- [BugFix] Resolve storyboard merge issue +== JeongHwan Kim 2015-10-08 +* 0.4.10 +- [BugFix] Increase in CPU consumption on switching to storyboard +- [BugFix] View shadows remain in storyboard +- Sort widget categories in Palette +== JeongHwan Kim 2015-09-30 +* 0.4.9 +- [BugFix] Modify conditions of Properties +== JeongHwan Kim 2015-09-24 +* 0.4.8 +- Remove message box in Renderer +- Update pixel to grid logic +== JeongHwan Kim 2015-09-24 +* 0.4.7 +- Add environment variables for EFL +== JeongHwan Kim 2015-09-24 +* 0.4.6 +- [BugFix] Remove exception in storyboard +== JeongHwan Kim 2015-09-22 +* 0.4.5 +- [BugFix] Remove DnD exception in Editor. +- [BugFix] Parent widget selection UX in Editor. +- [BugFix] Destroy renderers when Editor is disposed. +== JeongHwan Kim 2015-09-15 +* 0.4.4 +- [BugFix] verify selection condition for navigation +== JeongHwan Kim 2015-09-09 +* 0.4.3 +- [Usability] Add previous selecton management of Navigation +== JeongHwan Kim 2015-09-09 +* 0.4.2 +- [Performance] Modify thread sleep time +== JeongHwan Kim 2015-09-05 +* 0.4.1 +- [BugFix] Renderer does not work +== JeongHwan Kim 2015-09-05 +* 0.4.0 +- Multi platform support (in Renderer) +- Add event handler comments +== JeongHwan Kim 2015-09-01 +* 0.3.15 +- Revert 0.3.12 +== JeongHwan Kim 2015-08-04 +* 0.3.14 +- Revert 0.3.12 +== JeongHwan Kim 2015-08-04 +* 0.3.13 +- Remove memory leak in Navigation +== JeongHwan Kim 2015-08-03 +* 0.3.12 +- Fixed storyboard bug +== JeongHwan Kim 2015-07-24 +* 0.3.11 +- Merge develop +== JeongHwan Kim 2015-07-22 +* 0.3.10 +- Fixed storyboard bug +== JeongHwan Kim 2015-07-22 +* 0.3.9 +- merge get_uib_view_data function in common.c +== JeongHwan Kim 2015-07-22 +* 0.3.8 +- Add descriptor for tizen-2.4 +== JeongHwan Kim 2015-07-21 +* 0.3.7 +- Modify renderer path +- Fixed a bug (auto fit) +== JeongHwan Kim 2015-07-20 +* 0.3.6 +- Fixed a bug that Selection feedback +- Initial commit of storyboard into develop +- DESC : hide UI components +== Seongwon Shim 2015-07-17 +* 0.3.5 +- New Feature , Direct Editing for Text,Label,Sub-Lable +== Seongwon Shim 2015-07-08 +* 0.3.4 +- Replace "widget" to "UI Component" +- Modify the codgen for wearable circle +== Seongwon Shim 2015-07-08 +* 0.3.3 +- Add code fore avoiding NPE when save action on MAC +- Update WYSIWYG UX(Resting Creation) +== Seongwon Shim 2015-07-07 +* 0.3.2 +- Remove Exception in Descriptor +== JeongHwan Kim 2015-07-03 +* 0.3.1 +- View template(Can not delete default view template) +- WYSIWYG UX enhanced(Can select a Widget behind its child) +- Add cropping for circle profile +== Seongwon Shim 2015-07-03 +* 0.3.0 +- Add Feature +-- Snippet +-- Z-order +-- Nesting creation widget +== JeongHwan Kim 2015-06-24 +* 0.2.54 +- Implement that a widget is positioning at out side of a view +- Implement a new feature about wearable-circle +== Seongwon Shim 2015-06-24 +* 0.2.53 +- Implemented about nesting creation widgets on WYSIWYG Editor +== JeongHwan Kim 2015-06-15 +* 0.2.52 +- modify base scale of 360x480 resolution +== Seongwon Shim 2015-06-04 +* 0.2.51 +- Fixed a Bug(Can not build the project in windows) +== Seongwon Shim 2015-05-27 +* 0.2.50 +- Remove Subtitle Property +== Seongwon Shim 2015-05-20 +* 0.2.49 +- Arrange resolution information for wearable profile +== Seongwon Shim 2015-05-19 +* 0.2.48 +- Add Indent for xml files, Modify interfaces +== Seongwon Shim 2015-05-15 +* 0.2.47 +- Add Scrollbar in navigation, Modify preferences +== Seongwon Shim 2015-05-12 +* 0.2.46 +- Add mobile-2.3, wearable-2.4 to mapping table for descriptor & device info +== Seongwon Shim 2015-05-06 +* 0.2.45 +- Add windows version +== JeongHwan Kim 2015-04-29 +* 0.2.44 +- Add view template +== JeongHwan Kim 2015-04-28 +* 0.2.43 +- Modify Navigation UX of move views +== JeongHwan Kim 2015-04-24 +* 0.2.42 +- Modify Navigation UI Design +== JeongHwan Kim 2015-04-23 +* 0.2.41 +- Modify Renderer execution path +== JeongHwan Kim 2015-04-23 +* 0.2.40 +- Support wearable-2.3.1 +== JeongHwan Kim 2015-04-16 +* 0.2.39 +- Support mobile-2.3.1 +== JeongHwan Kim 2015-04-14 +* 0.2.38 +- Modify Nature name +== JeongHwan Kim 2015-04-14 +* 0.2.37 +- Impelement navigaion +== JeongHwan Kim 2015-04-10 +* 0.2.36 +- Fixed a bug : about selection action +== Seongwon Shim 2015-02-10 +* 0.2.35 +- Modify the datetime property +== Seongwon Shim 2015-02-10 +* 0.2.34 +- Remove horizontal style in index +== JeongHwan Kim 2015-02-09 +* 0.2.33 +- enable change resolution +== Hyeonsu Seo 2015-02-06 +* 0.2.32 +- Modify codegen logic +== Seongwon Shim 2015-02-06 +* 0.2.31 +- Enable change resolution +== Hyeonsu Seo 2015-02-05 +* 0.2.30 +- Remove Warnings +== JeongHwan Kim 2015-02-05 +* 0.2.29 +- Apply multi resolution +== JeongHwan Kim 2015-02-04 +* 0.2.28 +- Bugfix modify selection logic in Editor +== JeongHwan Kim 2015-01-28 +* 0.2.27 +- Modify widget properties +== JeongHwan Kim 2015-01-27 +* 0.2.26 +- Modify view template +== JeongHwan Kim 2015-01-27 +* 0.2.25 +- Modify create template UX +== JeongHwan Kim 2015-01-23 +* 0.2.24 +- Modify icons +== JeongHwan Kim 2015-01-22 +* 0.2.23 +- Modify naviframe properties +== JeongHwan Kim 2015-01-21 +* 0.2.22 +- Add datatime +== JeongHwan Kim 2015-01-19 +* 0.2.21 +- Modify selection logic +== JeongHwan Kim 2015-01-17 +* 0.2.20 +- Modify index properties +== JeongHwan Kim 2015-01-16 +* 0.2.19 +- Add tooltips +== JeongHwan Kim 2015-01-15 +* 0.2.18 +- Modify widget icons +== JeongHwan Kim 2015-01-13 +* 0.2.17 +- Add comment to the generated source +== JeongHwan Kim 2015-01-07 +* 0.2.16 +- Register codegenerator to build / clean +== JeongHwan Kim 2015-01-06 +* 0.2.15 +- Rename tizen.page to tizen.view in CodeGenerator +== JeongHwan Kim 2014-12-30 +* 0.2.14 +- Rename tizen.page to tizen.view +== JeongHwan Kim 2014-12-30 +* 0.2.13 +- Modify widget descriptor +== JeongHwan Kim 2014-12-29 +* 0.2.12 +- Add widgets +== JeongHwan Kim 2014-12-26 +* 0.2.11 +- Modify Renderer interfaces +== JeongHwan Kim 2014-12-23 +* 0.2.10 +- Modify CodeGenerator for using url +== JeongHwan Kim 2014-12-23 +* 0.2.9 +- Modify CodeGenerator for using url +== JeongHwan Kim 2014-12-22 +* 0.2.8 +- Modify descriptor +== JeongHwan Kim 2014-12-19 +* 0.2.7 +- Refactoring renderer +== JeongHwan Kim 2014-12-19 +* 0.2.6 +- BugFix null pointer dereference in Designer +== JeongHwan Kim 2014-12-16 +* 0.2.5 +- Update context menu in Designer +== JeongHwan Kim 2014-12-16 +* 0.2.4 +- Add Perspective +== JeongHwan Kim 2014-12-12 +* 0.2.3 +- Add Resources View +== JeongHwan Kim 2014-12-12 +* 0.2.2 +- Modify configuration +== JeongHwan Kim 2014-12-01 +* 0.2.1 +- Create +== JeongHwan Kim 2014-12-01 +* 0.1.522 +- Test +== JeongHwan Kim 2014-12-01 diff --git a/package/pkginfo.manifest b/package/pkginfo.manifest new file mode 100644 index 0000000..b251110 --- /dev/null +++ b/package/pkginfo.manifest @@ -0,0 +1,28 @@ +Version:0.6.130 +Source:efl-ui-builder-eplugin +Maintainer:ByoungChang Son + +Package:efl-ui-builder-eplugin +OS:ubuntu-32 +Build-host-os:ubuntu-32 +Build-dependency:common-eplugin [ubuntu-32], nativecore-ext-eplugin [ubuntu-32], pde-build [ubuntu-32], enventor-eplugin [ubuntu-32] + +Package:efl-ui-builder-eplugin +OS:ubuntu-64 +Build-host-os:ubuntu-64 +Build-dependency:common-eplugin [ubuntu-64], nativecore-ext-eplugin [ubuntu-64], pde-build [ubuntu-64], enventor-eplugin [ubuntu-64] + +Package:efl-ui-builder-eplugin +OS:windows-32 +Build-host-os:ubuntu-32 +Build-dependency:common-eplugin [windows-32], nativecore-ext-eplugin [windows-32], pde-build [windows-32], enventor-eplugin [windows-32] + +Package:efl-ui-builder-eplugin +OS:windows-64 +Build-host-os:ubuntu-64 +Build-dependency:common-eplugin [windows-64], nativecore-ext-eplugin [windows-64], pde-build [windows-64], enventor-eplugin [windows-64] + +Package:efl-ui-builder-eplugin +OS:macos-64 +Build-host-os:ubuntu-64 +Build-dependency:common-eplugin [macos-64], nativecore-ext-eplugin [macos-64], pde-build [macos-64], enventor-eplugin [macos-64] diff --git a/script/boilerplate.txt b/script/boilerplate.txt new file mode 100644 index 0000000..f744b4d --- /dev/null +++ b/script/boilerplate.txt @@ -0,0 +1,21 @@ +/* + * UI Builder + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 + * + */ diff --git a/script/check-boilerplate.sh b/script/check-boilerplate.sh new file mode 100755 index 0000000..e70a330 --- /dev/null +++ b/script/check-boilerplate.sh @@ -0,0 +1,13 @@ +SOURCES=`find . -name *.java` + +for source in ${SOURCES} +do + boilerplate=`cat boilerplate.txt` + `cat ${source} | head -n 21 1> temp.txt` + file_head=`cat temp.txt` + if [ "${boilerplate}" != "${file_head}" ] + then + echo ${source} >> result.txt + fi + +done