diff --git a/eu.scasefp7.eclipse.core.dependencies.feature/feature.xml b/eu.scasefp7.eclipse.core.dependencies.feature/feature.xml index fe7c6d0..fd55902 100644 --- a/eu.scasefp7.eclipse.core.dependencies.feature/feature.xml +++ b/eu.scasefp7.eclipse.core.dependencies.feature/feature.xml @@ -3,7 +3,8 @@ id="eu.scasefp7.eclipse.core.dependencies.feature" label="S-CASE Core third-party dependencies" version="1.1.1.qualifier" - provider-name="S-CASE Consortium"> + provider-name="S-CASE Consortium" + plugin="eu.scasefp7.eclipse.core.ui"> The dependencies of the S-CASE Core module. diff --git a/eu.scasefp7.eclipse.core.ui/META-INF/LICENSE b/eu.scasefp7.eclipse.core.ui/META-INF/LICENSE index 8f71f43..113e843 100644 --- a/eu.scasefp7.eclipse.core.ui/META-INF/LICENSE +++ b/eu.scasefp7.eclipse.core.ui/META-INF/LICENSE @@ -1,202 +1,202 @@ - 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. - + 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/eu.scasefp7.eclipse.core.ui/META-INF/MANIFEST.MF b/eu.scasefp7.eclipse.core.ui/META-INF/MANIFEST.MF index fe52c07..fc866ec 100644 --- a/eu.scasefp7.eclipse.core.ui/META-INF/MANIFEST.MF +++ b/eu.scasefp7.eclipse.core.ui/META-INF/MANIFEST.MF @@ -13,7 +13,17 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.mylyn.commons.notifications.ui, org.eclipse.mylyn.commons.workbench, org.eclipse.ui.forms, + org.eclipse.debug.core, org.eclipse.ui.trace, + org.eclipse.core.variables, + org.eclipse.equinox.security, + org.eclipse.m2e.core, + org.eclipse.m2e.maven.runtime, + org.eclipse.ui.navigator, + org.eclipse.ui.intro, + org.eclipse.core.expressions, + org.eclipse.ui.views.properties.tabbed, + org.eclipse.ui.navigator.resources, org.eclipse.equinox.security;bundle-version="[1.2.0,2.0.0)" Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: eu.scasefp7.eclipse.core.ui @@ -22,4 +32,5 @@ Bundle-ClassPath: . Bundle-Activator: eu.scasefp7.eclipse.core.ui.Activator Bundle-ActivationPolicy: lazy Import-Package: eu.scasefp7.eclipse.core.builder, - eu.scasefp7.eclipse.core.ontology + eu.scasefp7.eclipse.core.ontology, + org.eclipse.debug.internal.ui diff --git a/eu.scasefp7.eclipse.core.ui/about.ini b/eu.scasefp7.eclipse.core.ui/about.ini new file mode 100644 index 0000000..099d212 --- /dev/null +++ b/eu.scasefp7.eclipse.core.ui/about.ini @@ -0,0 +1,15 @@ +featureImage=icons/s-case-feature.png +aboutText=S-CASE UML recognizer image import wizard\n\ +\n\ +Frontend to UML recognizer module presented as an Eclipse import wizard. Image files of type JPG, JPEG2000, PNG and BMP are supported. Activity and use case diagrams can be detected. Result is stored in an XMI file and can be automatically opened in an associated editor.\n\ +\n\ +Please visit http://www.scasefp7.eu for more information on the S-CASE project.\n\ +\n\ +Please visit https://github.com/s-case/ for development information on the S-CASE project.\n\ +Please visit https://github.com/s-case/uml-extraction development information on this feature.\n\ +\n\ +(c) Copyright 2015 S-CASE Consortium\n\ +Licensed under the Apache License, Version 2.0\n\ +\n\ +This feature includes imgscalr software developed by the\n\ +The Buzz Media, LLC (https://github.com/thebuzzmedia/imgscalr)\n\ \ No newline at end of file diff --git a/eu.scasefp7.eclipse.core.ui/build.properties b/eu.scasefp7.eclipse.core.ui/build.properties index a3b76fe..c17a123 100644 --- a/eu.scasefp7.eclipse.core.ui/build.properties +++ b/eu.scasefp7.eclipse.core.ui/build.properties @@ -1,10 +1,12 @@ -source.. = src/ -output.. = target/classes/ -bin.includes = plugin.xml,\ - META-INF/,\ - .,\ - OSGI-INF/,\ - contexts.xml,\ - icons/,\ - .options -src.includes = .options +source.. = src/ +output.. = target/classes/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + OSGI-INF/,\ + contexts.xml,\ + icons/,\ + about.ini,\ + .options +src.includes = about.ini,\ + .options diff --git a/eu.scasefp7.eclipse.core.ui/icons/artefact-text.png b/eu.scasefp7.eclipse.core.ui/icons/artefact-text.png new file mode 100644 index 0000000..ef7822f Binary files /dev/null and b/eu.scasefp7.eclipse.core.ui/icons/artefact-text.png differ diff --git a/eu.scasefp7.eclipse.core.ui/icons/artefact.png b/eu.scasefp7.eclipse.core.ui/icons/artefact.png new file mode 100644 index 0000000..bcd8ccf Binary files /dev/null and b/eu.scasefp7.eclipse.core.ui/icons/artefact.png differ diff --git a/eu.scasefp7.eclipse.core.ui/icons/dashboardButton.png b/eu.scasefp7.eclipse.core.ui/icons/dashboardButton.png new file mode 100644 index 0000000..fc35a99 Binary files /dev/null and b/eu.scasefp7.eclipse.core.ui/icons/dashboardButton.png differ diff --git a/eu.scasefp7.eclipse.core.ui/icons/dashboardButton2.png b/eu.scasefp7.eclipse.core.ui/icons/dashboardButton2.png new file mode 100644 index 0000000..053256b Binary files /dev/null and b/eu.scasefp7.eclipse.core.ui/icons/dashboardButton2.png differ diff --git a/eu.scasefp7.eclipse.core.ui/icons/dashboardCode.png b/eu.scasefp7.eclipse.core.ui/icons/dashboardCode.png new file mode 100644 index 0000000..5e63a0f Binary files /dev/null and b/eu.scasefp7.eclipse.core.ui/icons/dashboardCode.png differ diff --git a/eu.scasefp7.eclipse.core.ui/icons/dashboardCodeBackground.png b/eu.scasefp7.eclipse.core.ui/icons/dashboardCodeBackground.png new file mode 100644 index 0000000..07c6011 Binary files /dev/null and b/eu.scasefp7.eclipse.core.ui/icons/dashboardCodeBackground.png differ diff --git a/eu.scasefp7.eclipse.core.ui/icons/dashboardDesign.png b/eu.scasefp7.eclipse.core.ui/icons/dashboardDesign.png new file mode 100644 index 0000000..c99841f Binary files /dev/null and b/eu.scasefp7.eclipse.core.ui/icons/dashboardDesign.png differ diff --git a/eu.scasefp7.eclipse.core.ui/icons/dashboardDesignBackground.png b/eu.scasefp7.eclipse.core.ui/icons/dashboardDesignBackground.png new file mode 100644 index 0000000..69fb4e2 Binary files /dev/null and b/eu.scasefp7.eclipse.core.ui/icons/dashboardDesignBackground.png differ diff --git a/eu.scasefp7.eclipse.core.ui/icons/dashboardMashup.png b/eu.scasefp7.eclipse.core.ui/icons/dashboardMashup.png new file mode 100644 index 0000000..5d193c6 Binary files /dev/null and b/eu.scasefp7.eclipse.core.ui/icons/dashboardMashup.png differ diff --git a/eu.scasefp7.eclipse.core.ui/icons/dashboardMashupBackground.png b/eu.scasefp7.eclipse.core.ui/icons/dashboardMashupBackground.png new file mode 100644 index 0000000..1088dc3 Binary files /dev/null and b/eu.scasefp7.eclipse.core.ui/icons/dashboardMashupBackground.png differ diff --git a/eu.scasefp7.eclipse.core.ui/icons/dashboardRun.png b/eu.scasefp7.eclipse.core.ui/icons/dashboardRun.png new file mode 100644 index 0000000..e83fd04 Binary files /dev/null and b/eu.scasefp7.eclipse.core.ui/icons/dashboardRun.png differ diff --git a/eu.scasefp7.eclipse.core.ui/icons/dashboardRunBackground.png b/eu.scasefp7.eclipse.core.ui/icons/dashboardRunBackground.png new file mode 100644 index 0000000..c558bfd Binary files /dev/null and b/eu.scasefp7.eclipse.core.ui/icons/dashboardRunBackground.png differ diff --git a/eu.scasefp7.eclipse.core.ui/icons/navigatorAction.png b/eu.scasefp7.eclipse.core.ui/icons/navigatorAction.png new file mode 100644 index 0000000..6368505 Binary files /dev/null and b/eu.scasefp7.eclipse.core.ui/icons/navigatorAction.png differ diff --git a/eu.scasefp7.eclipse.core.ui/icons/navigatorObject.png b/eu.scasefp7.eclipse.core.ui/icons/navigatorObject.png new file mode 100644 index 0000000..a1e1c80 Binary files /dev/null and b/eu.scasefp7.eclipse.core.ui/icons/navigatorObject.png differ diff --git a/eu.scasefp7.eclipse.core.ui/icons/navigatorRequirement.png b/eu.scasefp7.eclipse.core.ui/icons/navigatorRequirement.png new file mode 100644 index 0000000..aa22ee8 Binary files /dev/null and b/eu.scasefp7.eclipse.core.ui/icons/navigatorRequirement.png differ diff --git a/eu.scasefp7.eclipse.core.ui/icons/navigatorRoot.png b/eu.scasefp7.eclipse.core.ui/icons/navigatorRoot.png new file mode 100644 index 0000000..e007a34 Binary files /dev/null and b/eu.scasefp7.eclipse.core.ui/icons/navigatorRoot.png differ diff --git a/eu.scasefp7.eclipse.core.ui/icons/navigatorTransition.png b/eu.scasefp7.eclipse.core.ui/icons/navigatorTransition.png new file mode 100644 index 0000000..0d13951 Binary files /dev/null and b/eu.scasefp7.eclipse.core.ui/icons/navigatorTransition.png differ diff --git a/eu.scasefp7.eclipse.core.ui/icons/s-case-feature.png b/eu.scasefp7.eclipse.core.ui/icons/s-case-feature.png new file mode 100644 index 0000000..d252fc2 Binary files /dev/null and b/eu.scasefp7.eclipse.core.ui/icons/s-case-feature.png differ diff --git a/eu.scasefp7.eclipse.core.ui/icons/s-case_8x8.png b/eu.scasefp7.eclipse.core.ui/icons/s-case_8x8.png new file mode 100644 index 0000000..db43d49 Binary files /dev/null and b/eu.scasefp7.eclipse.core.ui/icons/s-case_8x8.png differ diff --git a/eu.scasefp7.eclipse.core.ui/icons/scaseFolder.png b/eu.scasefp7.eclipse.core.ui/icons/scaseFolder.png new file mode 100644 index 0000000..723f6f1 Binary files /dev/null and b/eu.scasefp7.eclipse.core.ui/icons/scaseFolder.png differ diff --git a/eu.scasefp7.eclipse.core.ui/intropagecontent/introContent.xml b/eu.scasefp7.eclipse.core.ui/intropagecontent/introContent.xml new file mode 100644 index 0000000..e150912 --- /dev/null +++ b/eu.scasefp7.eclipse.core.ui/intropagecontent/introContent.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/eu.scasefp7.eclipse.core.ui/intropagecontent/root.xhtml b/eu.scasefp7.eclipse.core.ui/intropagecontent/root.xhtml new file mode 100644 index 0000000..0ddca58 --- /dev/null +++ b/eu.scasefp7.eclipse.core.ui/intropagecontent/root.xhtml @@ -0,0 +1,23 @@ + + + + + root.xhtml + + + + +

Title

+ + First link + First item + + + + Second + Second item + + + + diff --git a/eu.scasefp7.eclipse.core.ui/plugin.xml b/eu.scasefp7.eclipse.core.ui/plugin.xml index 8f46850..f0fb567 100644 --- a/eu.scasefp7.eclipse.core.ui/plugin.xml +++ b/eu.scasefp7.eclipse.core.ui/plugin.xml @@ -1,7 +1,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -816,4 +725,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/eu.scasefp7.eclipse.core.ui/schema/eu.scasefp7.eclipse.core.ui.projectWizardPages.exsd b/eu.scasefp7.eclipse.core.ui/schema/eu.scasefp7.eclipse.core.ui.projectWizardPages.exsd index ce2f4ea..864e353 100644 --- a/eu.scasefp7.eclipse.core.ui/schema/eu.scasefp7.eclipse.core.ui.projectWizardPages.exsd +++ b/eu.scasefp7.eclipse.core.ui/schema/eu.scasefp7.eclipse.core.ui.projectWizardPages.exsd @@ -10,7 +10,7 @@ - + @@ -72,7 +72,7 @@ - + diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/BuildDeltaVisitor.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/BuildDeltaVisitor.java index 190982c..1c5d3c6 100644 --- a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/BuildDeltaVisitor.java +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/BuildDeltaVisitor.java @@ -1,160 +1,160 @@ -package eu.scasefp7.eclipse.core.ui; - -import java.util.HashSet; - -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IResourceDeltaVisitor; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.QualifiedName; - -/** - * Visitor class used for checking whether a folder has been renamed or removed. - * - * @author themis - */ -public class BuildDeltaVisitor implements IResourceDeltaVisitor { - - /** - * Receives an {@code IResourceDelta} as a parameter and returns its kind as a string. This function is only used - * for debugging purposes. - * - * @param delta the {@code IResourceDelta} of a specific resource. - * @return the kind of delta. - */ - @SuppressWarnings("unused") - private String deltaToString(IResourceDelta delta) { - switch (delta.getKind()) { - case IResourceDelta.REMOVED: - return "REMOVED"; - case IResourceDelta.NO_CHANGE: - return "NO_CHANGE"; - case IResourceDelta.ADDED: - return "ADDED"; - case IResourceDelta.CHANGED: - return "CHANGED"; - case IResourceDelta.ADDED_PHANTOM: - return "ADDED_PHANTOM"; - case IResourceDelta.REMOVED_PHANTOM: - return "REMOVED_PHANTOM"; - case IResourceDelta.ALL_WITH_PHANTOMS: - return "ALL_WITH_PHANTOMS"; - case IResourceDelta.CONTENT: - return "CONTENT"; - case IResourceDelta.MOVED_FROM: - return "MOVED_FROM"; - case IResourceDelta.MOVED_TO: - return "MOVED_TO"; - case IResourceDelta.COPIED_FROM: - return "COPIED_FROM"; - case IResourceDelta.OPEN: - return "OPEN"; - case IResourceDelta.TYPE: - return "TYPE"; - case IResourceDelta.SYNC: - return "SYNC"; - case IResourceDelta.MARKERS: - return "MARKERS"; - case IResourceDelta.REPLACED: - return "REPLACED"; - case IResourceDelta.DESCRIPTION: - return "DESCRIPTION"; - case IResourceDelta.ENCODING: - return "ENCODING"; - case IResourceDelta.LOCAL_CHANGED: - return "LOCAL_CHANGED"; - case IResourceDelta.DERIVED_CHANGED: - return "DERIVED_CHANGED"; - default: - return "ERROR"; - } - } - - @Override - public boolean visit(IResourceDelta delta) throws CoreException { - IResource resource = delta.getResource(); - if (resource instanceof IProject) { - IProject project = (IProject) resource; - if (project.isOpen() && project.hasNature("eu.scasefp7.eclipse.core.scaseNature")) { - - // Set some variables - QualifiedName modelsFolder = new QualifiedName("", ScaseUiConstants.MODELS_FOLDER); - QualifiedName outputFolder = new QualifiedName("", ScaseUiConstants.OUTPUT_FOLDER); - QualifiedName requirementsFolder = new QualifiedName("", ScaseUiConstants.REQUIREMENTS_FOLDER); - QualifiedName compositionsFolder = new QualifiedName("", ScaseUiConstants.COMPOSITIONS_FOLDER); - String modelsPath = project.getPersistentProperty(modelsFolder); - String outputPath = project.getPersistentProperty(outputFolder); - String reqPath = project.getPersistentProperty(requirementsFolder); - String comPath = project.getPersistentProperty(compositionsFolder); - - // Check all possible cases - if (delta.getKind() == IResourceDelta.ADDED) { - // A new project was added - // Do nothing - } else if (delta.getKind() == IResourceDelta.REMOVED) { - // A project was removed - // Do nothing - } else if (delta.getKind() == IResourceDelta.CHANGED) { - // A child of a project has been added, removed, or renamed - IResourceDelta[] childrenDeltas = delta.getAffectedChildren(); - if (childrenDeltas != null && childrenDeltas.length > 0) { - // Get the folder(s) that have been changed and split them according to the typoe of change - HashSet addedFolders = new HashSet(); - HashSet removedFolders = new HashSet(); - HashSet changedFolders = new HashSet(); - for (IResourceDelta childDelta : childrenDeltas) { - IResource childResource = childDelta.getResource(); - if (childResource instanceof IFolder) { - if (childDelta.getKind() == IResourceDelta.ADDED) - addedFolders.add(childResource); - else if (childDelta.getKind() == IResourceDelta.REMOVED) - removedFolders.add(childResource); - else if (childDelta.getKind() == IResourceDelta.CHANGED) - changedFolders.add(childResource); - } - } - // If there are one removed folders and no added folders, then some folders have been deleted - if (removedFolders.size() > 0 && addedFolders.isEmpty()) { - for (IResource removedFolder : removedFolders) { - String removedFolderPath = removedFolder.getProjectRelativePath().toString(); - if (removedFolderPath.equals(modelsPath)) - project.setPersistentProperty(modelsFolder, ""); - else if (removedFolderPath.equals(outputPath)) - project.setPersistentProperty(outputFolder, ""); - else if (removedFolderPath.equals(reqPath)) - project.setPersistentProperty(requirementsFolder, ""); - else if (removedFolderPath.equals(comPath)) - project.setPersistentProperty(compositionsFolder, ""); - } - } - // If there is exactly one removed folder and one added folder, then a folder has been renamed - if (removedFolders.size() == 1 && addedFolders.size() == 1) { - IResource addedFolder = addedFolders.iterator().next(); - IResource removedFolder = removedFolders.iterator().next(); - String removedFolderPath = removedFolder.getProjectRelativePath().toString(); - String addedFolderPath = addedFolder.getProjectRelativePath().toString(); - if (removedFolderPath.equals(modelsPath)) - project.setPersistentProperty(modelsFolder, addedFolderPath); - else if (removedFolderPath.equals(outputPath)) - project.setPersistentProperty(outputFolder, addedFolderPath); - else if (removedFolderPath.equals(reqPath)) - project.setPersistentProperty(requirementsFolder, addedFolderPath); - else if (removedFolderPath.equals(comPath)) - project.setPersistentProperty(compositionsFolder, addedFolderPath); - } - - // For changed folders it means that a resource inside a folder has been added/deleted/changed - // So we do nothing - - // Return false to avoid visiting deeper deltas - return false; - } - } - } - } - return true; - } - -} +package eu.scasefp7.eclipse.core.ui; + +import java.util.HashSet; + +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceDelta; +import org.eclipse.core.resources.IResourceDeltaVisitor; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.QualifiedName; + +/** + * Visitor class used for checking whether a folder has been renamed or removed. + * + * @author themis + */ +public class BuildDeltaVisitor implements IResourceDeltaVisitor { + + /** + * Receives an {@code IResourceDelta} as a parameter and returns its kind as a string. This function is only used + * for debugging purposes. + * + * @param delta the {@code IResourceDelta} of a specific resource. + * @return the kind of delta. + */ + @SuppressWarnings("unused") + private String deltaToString(IResourceDelta delta) { + switch (delta.getKind()) { + case IResourceDelta.REMOVED: + return "REMOVED"; + case IResourceDelta.NO_CHANGE: + return "NO_CHANGE"; + case IResourceDelta.ADDED: + return "ADDED"; + case IResourceDelta.CHANGED: + return "CHANGED"; + case IResourceDelta.ADDED_PHANTOM: + return "ADDED_PHANTOM"; + case IResourceDelta.REMOVED_PHANTOM: + return "REMOVED_PHANTOM"; + case IResourceDelta.ALL_WITH_PHANTOMS: + return "ALL_WITH_PHANTOMS"; + case IResourceDelta.CONTENT: + return "CONTENT"; + case IResourceDelta.MOVED_FROM: + return "MOVED_FROM"; + case IResourceDelta.MOVED_TO: + return "MOVED_TO"; + case IResourceDelta.COPIED_FROM: + return "COPIED_FROM"; + case IResourceDelta.OPEN: + return "OPEN"; + case IResourceDelta.TYPE: + return "TYPE"; + case IResourceDelta.SYNC: + return "SYNC"; + case IResourceDelta.MARKERS: + return "MARKERS"; + case IResourceDelta.REPLACED: + return "REPLACED"; + case IResourceDelta.DESCRIPTION: + return "DESCRIPTION"; + case IResourceDelta.ENCODING: + return "ENCODING"; + case IResourceDelta.LOCAL_CHANGED: + return "LOCAL_CHANGED"; + case IResourceDelta.DERIVED_CHANGED: + return "DERIVED_CHANGED"; + default: + return "ERROR"; + } + } + + @Override + public boolean visit(IResourceDelta delta) throws CoreException { + IResource resource = delta.getResource(); + if (resource instanceof IProject) { + IProject project = (IProject) resource; + if (project.isOpen() && project.hasNature("eu.scasefp7.eclipse.core.scaseNature")) { + + // Set some variables + QualifiedName modelsFolder = new QualifiedName("", ScaseUiConstants.MODELS_FOLDER); + QualifiedName outputFolder = new QualifiedName("", ScaseUiConstants.OUTPUT_FOLDER); + QualifiedName requirementsFolder = new QualifiedName("", ScaseUiConstants.REQUIREMENTS_FOLDER); + QualifiedName compositionsFolder = new QualifiedName("", ScaseUiConstants.COMPOSITIONS_FOLDER); + String modelsPath = project.getPersistentProperty(modelsFolder); + String outputPath = project.getPersistentProperty(outputFolder); + String reqPath = project.getPersistentProperty(requirementsFolder); + String comPath = project.getPersistentProperty(compositionsFolder); + + // Check all possible cases + if (delta.getKind() == IResourceDelta.ADDED) { + // A new project was added + // Do nothing + } else if (delta.getKind() == IResourceDelta.REMOVED) { + // A project was removed + // Do nothing + } else if (delta.getKind() == IResourceDelta.CHANGED) { + // A child of a project has been added, removed, or renamed + IResourceDelta[] childrenDeltas = delta.getAffectedChildren(); + if (childrenDeltas != null && childrenDeltas.length > 0) { + // Get the folder(s) that have been changed and split them according to the typoe of change + HashSet addedFolders = new HashSet(); + HashSet removedFolders = new HashSet(); + HashSet changedFolders = new HashSet(); + for (IResourceDelta childDelta : childrenDeltas) { + IResource childResource = childDelta.getResource(); + if (childResource instanceof IFolder) { + if (childDelta.getKind() == IResourceDelta.ADDED) + addedFolders.add(childResource); + else if (childDelta.getKind() == IResourceDelta.REMOVED) + removedFolders.add(childResource); + else if (childDelta.getKind() == IResourceDelta.CHANGED) + changedFolders.add(childResource); + } + } + // If there are one removed folders and no added folders, then some folders have been deleted + if (removedFolders.size() > 0 && addedFolders.isEmpty()) { + for (IResource removedFolder : removedFolders) { + String removedFolderPath = removedFolder.getProjectRelativePath().toString(); + if (removedFolderPath.equals(modelsPath)) + project.setPersistentProperty(modelsFolder, ""); + else if (removedFolderPath.equals(outputPath)) + project.setPersistentProperty(outputFolder, ""); + else if (removedFolderPath.equals(reqPath)) + project.setPersistentProperty(requirementsFolder, ""); + else if (removedFolderPath.equals(comPath)) + project.setPersistentProperty(compositionsFolder, ""); + } + } + // If there is exactly one removed folder and one added folder, then a folder has been renamed + if (removedFolders.size() == 1 && addedFolders.size() == 1) { + IResource addedFolder = addedFolders.iterator().next(); + IResource removedFolder = removedFolders.iterator().next(); + String removedFolderPath = removedFolder.getProjectRelativePath().toString(); + String addedFolderPath = addedFolder.getProjectRelativePath().toString(); + if (removedFolderPath.equals(modelsPath)) + project.setPersistentProperty(modelsFolder, addedFolderPath); + else if (removedFolderPath.equals(outputPath)) + project.setPersistentProperty(outputFolder, addedFolderPath); + else if (removedFolderPath.equals(reqPath)) + project.setPersistentProperty(requirementsFolder, addedFolderPath); + else if (removedFolderPath.equals(comPath)) + project.setPersistentProperty(compositionsFolder, addedFolderPath); + } + + // For changed folders it means that a resource inside a folder has been added/deleted/changed + // So we do nothing + + // Return false to avoid visiting deeper deltas + return false; + } + } + } + } + return true; + } + +} diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/DynamicVariableResolver.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/DynamicVariableResolver.java new file mode 100644 index 0000000..00599f8 --- /dev/null +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/DynamicVariableResolver.java @@ -0,0 +1,41 @@ +package eu.scasefp7.eclipse.core.ui; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.variables.IDynamicVariable; +import org.eclipse.core.variables.IDynamicVariableResolver; +import org.eclipse.equinox.security.storage.ISecurePreferences; +import org.eclipse.equinox.security.storage.SecurePreferencesFactory; +import org.eclipse.equinox.security.storage.StorageException; +import org.eclipse.jface.preference.IPreferenceStore; + +public class DynamicVariableResolver implements IDynamicVariableResolver { + + @Override + public String resolveValue(IDynamicVariable variable, String argument) + throws CoreException { + + String value = null; + + if(argument == "scase_fco_server_uuid"){ + Activator plugin = Activator.getDefault(); + IPreferenceStore prefStore = plugin.getPreferenceStore(); + value = prefStore.getString(argument); + + return value; + } + + ISecurePreferences prefStore = SecurePreferencesFactory.getDefault(); + + try { + value = prefStore.get(argument, ""); + } catch (StorageException e) { + e.printStackTrace(); + } + + if (value != null && value.length() > 0) + return value; + + return null; + } + +} diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/ScaseUiConstants.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/ScaseUiConstants.java index d79c84c..8a43cb7 100644 --- a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/ScaseUiConstants.java +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/ScaseUiConstants.java @@ -1,133 +1,133 @@ -/** - * Copyright 2015 S-CASE Consortium - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eu.scasefp7.eclipse.core.ui; - -/** - * Convenience collection of constants to reference various IDs. - * - * @author Marin Orlic - * - */ -public final class ScaseUiConstants { - - /** Used to store constants, cannot be instantiated. */ - private ScaseUiConstants() { - - }; - - /** Category for views. */ - public static final String VIEW_CATEGORY = "eu.scasefp7.eclipse.category"; //$NON-NLS-1$ - - /** S-CASE Perspective ID. */ - public static final String PERSPECTIVE = "eu.scasefp7.eclipse.core.ui.ScasePerspective"; //$NON-NLS-1$ - - /** New S-CASE project wizard ID. */ - public static final String NEW_PROJECT_WIZARD = "eu.scasefp7.eclipse.core.ui.newProjectWizard"; //$NON-NLS-1$ - - /** New S-CASE project wizard ID2. */ - public static final String NEW_PROJECT_WIZARD2 = "eu.scasefp7.eclipse.core.ui.newProjectWizard2"; //$NON-NLS-1$ - - /** S-CASE Dashboard view ID. */ - public static final String DASHBOARD_VIEW = "eu.scasefp7.eclipse.core.ui.views.Dashboard"; //$NON-NLS-1$ - - /** Extension point used to contribute dashboard items. */ - public static final String DASHBOARD_EXTENSION = "eu.scasefp7.eclipse.core.ui.dashboardItem"; //$NON-NLS-1$ - - /** Extension point for new project wizard pages */ - public static final String NEWPROJECTPAGES_EXTENSION = "eu.scasefp7.eclipse.core.ui.projectWizardPages"; //$NON-NLS-1$ - - /** Link ontologies command ID. */ - public static final String COMMAND_EXPORTONTOLOGY = "eu.scasefp7.eclipse.core.commands.linkOntologies"; //$NON-NLS-1$ - - - /* These are external, included here for convenience */ - - /** UML recognizer wizard ID. */ - public static final String UML_RECOGNIZER_NEWWIZARDID = "eu.scasefp7.eclipse.umlrec.importWizard"; //$NON-NLS-1$ - - /** Requirements editor wizard ID.*/ - public static final String REQUIREMENTS_EDITOR_NEWWIZARDID = "eu.scasefp7.eclipse.reqeditor.wizards.CreateRqsWizard"; //$NON-NLS-1$ - - /** Requirements editor ontology export command. */ - public static final String REQUIREMENTS_EDITOR_COMMAND_EXPORTONTOLOGY = "eu.scasefp7.eclipse.reqeditor.commands.exportToOntology"; //$NON-NLS-1$ - - /** Storyboards editor wizard ID. */ - public static final String STORYBOARD_EDITOR_NEWWIZARDID = "eu.scasefp7.eclipse.storyboards.diagram.part.StoryboardsCreationWizardID"; //$NON-NLS-1$ - - /** Composition storyboards editor wizard ID. */ - public static final String SC_STORYBOARD_EDITOR_NEWWIZARDID = "eu.scasefp7.eclipse.storyboards.diagram.part.ServiceCompositionStoryboardsCreationWizardID"; //$NON-NLS-1$ - - /** Storyboard editor ontology export command. */ - public static final String STORYBOARD_EDITOR_COMMAND_EXPORTONTOLOGY = "eu.scasefp7.eclipse.storyboards.commands.exportAllToOntology"; //$NON-NLS-1$ - - /** Property for project domain. */ //TODO-move to prefs - public static final String PROP_PROJECT_DOMAIN = "eu.scasefp7.eclipse.core.projectDomain"; //$NON-NLS-1$ - - /** Default project domain (unset). */ - public static final int PROP_PROJECT_DOMAIN_DEFAULT = -1; - - /** Project nature */ - public static final String PROJECT_NATURE = "eu.scasefp7.eclipse.core.scaseNature"; //$NON-NLS-1$ - - /* Links */ - /** URL for the project homepage (http://www.scasefp7.eu/). */ - public static final String PROJECT_HOMEPAGE = "http://www.scasefp7.eu/"; - - /** URL for the tools homepage (http://s-case.github.io//). */ - public static final String TOOLS_HOMEPAGE = "http://s-case.github.io//"; - - /** URL for the project github (https://github.com/s-case). */ - public static final String PROJECT_GITHUB = "https://github.com/s-case"; - - /** URL for the project Facebook page. */ - public static final String PROJECT_FACEBOOK = "http://bit.ly/SCasefb"; - - /** URL for the project LinkedIn page. */ - public static final String PROJECT_LINKEDIN = "http://bit.ly/SCasegrp"; - - /** URL for the project Twitter. */ - public static final String PROJECT_TWITTER = "http://www.twitter.com/scasefp7"; - - /** Hashtag #devtherightway. */ - public static final String PROJECT_HASHTAG = "https://twitter.com/hashtag/devtherightway"; - - /** Path to project folders for requirements. */ - public static final String REQUIREMENTS_FOLDER = "eu.scasefp7.eclipse.core.ui.rqsFolder"; //NON-NLS-1$ - - /** Path to project folders for requirements. */ - public static final String COMPOSITIONS_FOLDER = "eu.scasefp7.eclipse.core.ui.compFolder"; //$NON-NLS-1$ - - /** Path to project folders for requirements. */ - public static final String MODELS_FOLDER = "eu.scasefp7.eclipse.core.ui.modelsFolder"; //$NON-NLS-1$ - - /** Path to project folders for requirements. */ - public static final String OUTPUT_FOLDER = "eu.scasefp7.eclipse.core.ui.outputFolder"; //$NON-NLS-1$ - - // Source providers - - /** Source provider for the models folder. */ - public static final String MODELS_FOLDER_SOURCE = "eu.scasefp7.eclipse.core.ui.sourceprovider.modelsFolderActive"; //$NON-NLS-1$ - - /** Source provider for the compositions folder. */ - public static final String COMPOSITIONS_FOLDER_SOURCE = "eu.scasefp7.eclipse.core.ui.sourceprovider.compositionsFolderActive"; //$NON-NLS-1$ - - /** Source provider for the output folder. */ - public static final String OUTPUT_FOLDER_SOURCE = "eu.scasefp7.eclipse.core.ui.sourceprovider.outputFolderActive"; //$NON-NLS-1$ - - /** Source provider for the requirements folder. */ - public static final String REQUIREMENTS_FOLDER_SOURCE = "eu.scasefp7.eclipse.core.ui.sourceprovider.requirementsFolderActive"; //$NON-NLS-1$ -} - +/** + * Copyright 2015 S-CASE Consortium + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package eu.scasefp7.eclipse.core.ui; + +/** + * Convenience collection of constants to reference various IDs. + * + * @author Marin Orlic + * + */ +public final class ScaseUiConstants { + + /** Used to store constants, cannot be instantiated. */ + private ScaseUiConstants() { + + }; + + /** Category for views. */ + public static final String VIEW_CATEGORY = "eu.scasefp7.eclipse.category"; //$NON-NLS-1$ + + /** S-CASE Perspective ID. */ + public static final String PERSPECTIVE = "eu.scasefp7.eclipse.core.ui.ScasePerspective"; //$NON-NLS-1$ + + /** New S-CASE project wizard ID. */ + public static final String NEW_PROJECT_WIZARD = "eu.scasefp7.eclipse.core.ui.newProjectWizard"; //$NON-NLS-1$ + + /** New S-CASE project wizard ID2. */ + public static final String NEW_PROJECT_WIZARD2 = "eu.scasefp7.eclipse.core.ui.newProjectWizard2"; //$NON-NLS-1$ + + /** S-CASE Dashboard view ID. */ + public static final String DASHBOARD_VIEW = "eu.scasefp7.eclipse.core.ui.views.Dashboard"; //$NON-NLS-1$ + + /** Extension point used to contribute dashboard items. */ + public static final String DASHBOARD_EXTENSION = "eu.scasefp7.eclipse.core.ui.dashboardItem"; //$NON-NLS-1$ + + /** Extension point for new project wizard pages */ + public static final String NEWPROJECTPAGES_EXTENSION = "eu.scasefp7.eclipse.core.ui.projectWizardPages"; //$NON-NLS-1$ + + /** Link ontologies command ID. */ + public static final String COMMAND_EXPORTONTOLOGY = "eu.scasefp7.eclipse.core.commands.linkOntologies"; //$NON-NLS-1$ + + + /* These are external, included here for convenience */ + + /** UML recognizer wizard ID. */ + public static final String UML_RECOGNIZER_NEWWIZARDID = "eu.scasefp7.eclipse.umlrec.importWizard"; //$NON-NLS-1$ + + /** Requirements editor wizard ID.*/ + public static final String REQUIREMENTS_EDITOR_NEWWIZARDID = "eu.scasefp7.eclipse.reqeditor.wizards.CreateRqsWizard"; //$NON-NLS-1$ + + /** Requirements editor ontology export command. */ + public static final String REQUIREMENTS_EDITOR_COMMAND_EXPORTONTOLOGY = "eu.scasefp7.eclipse.reqeditor.commands.exportToOntology"; //$NON-NLS-1$ + + /** Storyboards editor wizard ID. */ + public static final String STORYBOARD_EDITOR_NEWWIZARDID = "eu.scasefp7.eclipse.storyboards.diagram.part.StoryboardsCreationWizardID"; //$NON-NLS-1$ + + /** Composition storyboards editor wizard ID. */ + public static final String SC_STORYBOARD_EDITOR_NEWWIZARDID = "eu.scasefp7.eclipse.storyboards.diagram.part.ServiceCompositionStoryboardsCreationWizardID"; //$NON-NLS-1$ + + /** Storyboard editor ontology export command. */ + public static final String STORYBOARD_EDITOR_COMMAND_EXPORTONTOLOGY = "eu.scasefp7.eclipse.storyboards.commands.exportAllToOntology"; //$NON-NLS-1$ + + /** Property for project domain. */ //TODO-move to prefs + public static final String PROP_PROJECT_DOMAIN = "eu.scasefp7.eclipse.core.projectDomain"; //$NON-NLS-1$ + + /** Default project domain (unset). */ + public static final int PROP_PROJECT_DOMAIN_DEFAULT = -1; + + /** Project nature */ + public static final String PROJECT_NATURE = "eu.scasefp7.eclipse.core.scaseNature"; //$NON-NLS-1$ + + /* Links */ + /** URL for the project homepage (http://www.scasefp7.eu/). */ + public static final String PROJECT_HOMEPAGE = "http://www.scasefp7.eu/"; + + /** URL for the tools homepage (http://s-case.github.io//). */ + public static final String TOOLS_HOMEPAGE = "http://s-case.github.io//"; + + /** URL for the project github (https://github.com/s-case). */ + public static final String PROJECT_GITHUB = "https://github.com/s-case"; + + /** URL for the project Facebook page. */ + public static final String PROJECT_FACEBOOK = "http://bit.ly/SCasefb"; + + /** URL for the project LinkedIn page. */ + public static final String PROJECT_LINKEDIN = "http://bit.ly/SCasegrp"; + + /** URL for the project Twitter. */ + public static final String PROJECT_TWITTER = "http://www.twitter.com/scasefp7"; + + /** Hashtag #devtherightway. */ + public static final String PROJECT_HASHTAG = "https://twitter.com/hashtag/devtherightway"; + + /** Path to project folders for requirements. */ + public static final String REQUIREMENTS_FOLDER = "eu.scasefp7.eclipse.core.ui.rqsFolder"; //NON-NLS-1$ + + /** Path to project folders for requirements. */ + public static final String COMPOSITIONS_FOLDER = "eu.scasefp7.eclipse.core.ui.compFolder"; //$NON-NLS-1$ + + /** Path to project folders for requirements. */ + public static final String MODELS_FOLDER = "eu.scasefp7.eclipse.core.ui.modelsFolder"; //$NON-NLS-1$ + + /** Path to project folders for requirements. */ + public static final String OUTPUT_FOLDER = "eu.scasefp7.eclipse.core.ui.outputFolder"; //$NON-NLS-1$ + + // Source providers + + /** Source provider for the models folder. */ + public static final String MODELS_FOLDER_SOURCE = "eu.scasefp7.eclipse.core.ui.sourceprovider.modelsFolderActive"; //$NON-NLS-1$ + + /** Source provider for the compositions folder. */ + public static final String COMPOSITIONS_FOLDER_SOURCE = "eu.scasefp7.eclipse.core.ui.sourceprovider.compositionsFolderActive"; //$NON-NLS-1$ + + /** Source provider for the output folder. */ + public static final String OUTPUT_FOLDER_SOURCE = "eu.scasefp7.eclipse.core.ui.sourceprovider.outputFolderActive"; //$NON-NLS-1$ + + /** Source provider for the requirements folder. */ + public static final String REQUIREMENTS_FOLDER_SOURCE = "eu.scasefp7.eclipse.core.ui.sourceprovider.requirementsFolderActive"; //$NON-NLS-1$ +} + diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/builder/AddRemoveSCaseNatureHandler.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/builder/AddRemoveSCaseNatureHandler.java new file mode 100644 index 0000000..2510957 --- /dev/null +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/builder/AddRemoveSCaseNatureHandler.java @@ -0,0 +1,77 @@ +package eu.scasefp7.eclipse.core.ui.builder; + +import java.util.Iterator; + +import org.eclipse.core.commands.*; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.handlers.HandlerUtil; + + +public class AddRemoveSCaseNatureHandler extends AbstractHandler { + +public Object execute(ExecutionEvent event) throws ExecutionException { + + ISelection selection = HandlerUtil.getCurrentSelection(event); + // + if (selection instanceof IStructuredSelection) { + for (Iterator it = ((IStructuredSelection) selection).iterator(); it + .hasNext();) { + Object element = it.next(); + IProject project = null; + if (element instanceof IProject) { + project = (IProject) element; + } else if (element instanceof IAdaptable) { + project = (IProject) ((IAdaptable) element) + .getAdapter(IProject.class); + } + if (project != null) { + try { + toggleNature(project); + } catch (CoreException e) { + //TODO log something + throw new ExecutionException("Failed to toggle nature", + e); + } + } + } + } + + return null; + } + +/** + * Toggles sample nature on a project + * + * @param project + * to have sample nature added or removed + */ +private void toggleNature(IProject project) throws CoreException { + IProjectDescription description = project.getDescription(); + String[] natures = description.getNatureIds(); + + for (int i = 0; i < natures.length; ++i) { + if (SCaseNature.NATURE_ID.equals(natures[i])) { + // Remove the nature + String[] newNatures = new String[natures.length - 1]; + System.arraycopy(natures, 0, newNatures, 0, i); + System.arraycopy(natures, i + 1, newNatures, i, natures.length - i - 1); + description.setNatureIds(newNatures); + project.setDescription(description, null); + return; + } + } + + // Add the nature + String[] newNatures = new String[natures.length + 1]; + System.arraycopy(natures, 0, newNatures, 0, natures.length); + newNatures[natures.length] = SCaseNature.NATURE_ID; + description.setNatureIds(newNatures); + project.setDescription(description, null); +} + +} \ No newline at end of file diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/builder/SCaseNature.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/builder/SCaseNature.java new file mode 100644 index 0000000..6bbd5a4 --- /dev/null +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/builder/SCaseNature.java @@ -0,0 +1,74 @@ +package eu.scasefp7.eclipse.core.ui.builder; + +import org.eclipse.core.resources.ICommand; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IProjectNature; +import org.eclipse.core.runtime.CoreException; + + +public class SCaseNature implements IProjectNature { + + public static final String NATURE_ID = "eu.scasefp7.eclipse.core.ui.scaseNature"; + + private IProject project; + + @Override + public void configure() throws CoreException { +// IProjectDescription desc = project.getDescription(); +// ICommand[] commands = desc.getBuildSpec(); +// +// for (int i = 0; i < commands.length; ++i) { +// if (commands[i].getBuilderName().equals(SCaseBuilder.BUILDER_ID)) { +// return; +// } +// } +// +// ICommand[] newCommands = new ICommand[commands.length + 1]; +// System.arraycopy(commands, 0, newCommands, 0, commands.length); +// ICommand command = desc.newCommand(); +// command.setBuilderName(SCaseBuilder.BUILDER_ID); +// newCommands[newCommands.length - 1] = command; +// desc.setBuildSpec(newCommands); +// project.setDescription(desc, null); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.core.resources.IProjectNature#deconfigure() + */ + public void deconfigure() throws CoreException { +// IProjectDescription description = getProject().getDescription(); +// ICommand[] commands = description.getBuildSpec(); +// for (int i = 0; i < commands.length; ++i) { +// if (commands[i].getBuilderName().equals(SCaseBuilder.BUILDER_ID)) { +// ICommand[] newCommands = new ICommand[commands.length - 1]; +// System.arraycopy(commands, 0, newCommands, 0, i); +// System.arraycopy(commands, i + 1, newCommands, i, +// commands.length - i - 1); +// description.setBuildSpec(newCommands); +// project.setDescription(description, null); +// return; +// } +// } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.core.resources.IProjectNature#getProject() + */ + public IProject getProject() { + return project; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.core.resources.IProjectNature#setProject(org.eclipse.core.resources.IProject) + */ + public void setProject(IProject project) { + this.project = project; + } +} diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/ConvertToProjectFolderHandler.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/ConvertToProjectFolderHandler.java index 114a910..0939ee6 100644 --- a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/ConvertToProjectFolderHandler.java +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/ConvertToProjectFolderHandler.java @@ -1,57 +1,57 @@ -package eu.scasefp7.eclipse.core.ui.handlers; - -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.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.handlers.HandlerUtil; - -import eu.scasefp7.eclipse.core.ui.Activator; -import eu.scasefp7.eclipse.core.ui.ScaseUiConstants; - -public class ConvertToProjectFolderHandler extends AbstractHandler { - - String PARAM_TYPE = "eu.scasefp7.eclipse.core.ui.commands.convertToFolder.type"; - - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - String type = event.getParameter(PARAM_TYPE); - ISelection selection = HandlerUtil.getCurrentSelection(event); - - if (selection instanceof IStructuredSelection) { - IStructuredSelection structuredSelection = (IStructuredSelection) selection; - @SuppressWarnings("unchecked") - List selectionList = structuredSelection.toList(); - - for (Object object : selectionList) { - IFolder folder = (IFolder) Platform.getAdapterManager().getAdapter(object, IFolder.class); - String path = folder.getFullPath().toPortableString(); - IProject project = folder.getProject(); - try { - if(type.equals("output")) - project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.OUTPUT_FOLDER), path); - else if(type.equals("requirements")) - project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.REQUIREMENTS_FOLDER), path); - else if(type.equals("compositions")) - project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.COMPOSITIONS_FOLDER), path); - else if(type.equals("models")) - project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.MODELS_FOLDER), path); - } catch (CoreException e) { - Activator.log("Unable to set project folder.", e); - } - } - } - return null; - } - - - -} +package eu.scasefp7.eclipse.core.ui.handlers; + +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.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.handlers.HandlerUtil; + +import eu.scasefp7.eclipse.core.ui.Activator; +import eu.scasefp7.eclipse.core.ui.ScaseUiConstants; + +public class ConvertToProjectFolderHandler extends AbstractHandler { + + String PARAM_TYPE = "eu.scasefp7.eclipse.core.ui.commands.convertToFolder.type"; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + String type = event.getParameter(PARAM_TYPE); + ISelection selection = HandlerUtil.getCurrentSelection(event); + + if (selection instanceof IStructuredSelection) { + IStructuredSelection structuredSelection = (IStructuredSelection) selection; + @SuppressWarnings("unchecked") + List selectionList = structuredSelection.toList(); + + for (Object object : selectionList) { + IFolder folder = (IFolder) Platform.getAdapterManager().getAdapter(object, IFolder.class); + String path = folder.getFullPath().toPortableString(); + IProject project = folder.getProject(); + try { + if(type.equals("output")) + project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.OUTPUT_FOLDER), path); + else if(type.equals("requirements")) + project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.REQUIREMENTS_FOLDER), path); + else if(type.equals("compositions")) + project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.COMPOSITIONS_FOLDER), path); + else if(type.equals("models")) + project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.MODELS_FOLDER), path); + } catch (CoreException e) { + Activator.log("Unable to set project folder.", e); + } + } + } + return null; + } + + + +} diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/CreateServerHandler.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/CreateServerHandler.java new file mode 100644 index 0000000..405bf1b --- /dev/null +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/CreateServerHandler.java @@ -0,0 +1,167 @@ +package eu.scasefp7.eclipse.core.ui.handlers; + +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.variables.IDynamicVariable; +import org.eclipse.core.variables.IStringVariable; +import org.eclipse.core.variables.VariablesPlugin; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.debug.core.ILaunchesListener2; +import org.eclipse.debug.core.IStreamListener; +import org.eclipse.debug.core.model.IProcess; +import org.eclipse.debug.core.model.IStreamMonitor; +import org.eclipse.debug.core.model.IStreamsProxy; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.swt.widgets.Display; + +import eu.scasefp7.eclipse.core.ui.Activator; +import eu.scasefp7.eclipse.core.ui.DynamicVariableResolver; + +public class CreateServerHandler extends AbstractHandler implements ILaunchesListener2, IStreamListener { + + private Set allLaunches = new HashSet(); + ILaunchManager manager; + String consoleOutput = ""; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + try { + manager = DebugPlugin.getDefault().getLaunchManager(); + manager.addLaunchListener(this); + + ILaunchConfigurationType type = manager + .getLaunchConfigurationType("org.eclipse.ui.externaltools.ProgramLaunchConfigurationType"); + + ILaunchConfiguration[] configurations = manager + .getLaunchConfigurations(type); + + for (int i = 0; i < configurations.length; i++) { + ILaunchConfiguration configuration = configurations[i]; + if (configuration.getName().equals("Gen doc")) { + configuration.delete(); + break; + } + } + + String cust_uuid = null, username = null, password = null, ssh_key = null; + IStringVariable[] variables = VariablesPlugin.getDefault().getStringVariableManager().getVariables(); + + for (int i = 0; i < variables.length; i++) { + IDynamicVariable currVar = ((IDynamicVariable)variables[i]); + DynamicVariableResolver resolver = new DynamicVariableResolver(); + String name = currVar.getName(); + + if(name.equals("scase_fco_cust_uuid" ) ) + cust_uuid = resolver.resolveValue(currVar, name); + + if(name.equals( "scase_fco_cust_name")) + username = resolver.resolveValue(currVar, name); + + if(name.equals("scase_fco_cust_pwd" )) + password = resolver.resolveValue(currVar, name); + + if(name.equals("scase_fco_ssh_key" )) + ssh_key = resolver.resolveValue(currVar, name); + + } + + ILaunchConfigurationWorkingCopy workingCopy = type.newInstance( null, "Gen doc"); + + //replace with location of python.exe + String location ="C:\\Python27\\python.exe"; + + //replace with location of script + String arguments ="C:\\Users\\sc2015\\Desktop\\SCase\\YouREST-backend\\SCase-FCO\\createServer.py "; + + arguments += cust_uuid + " " + username + " " + password + " " + ssh_key; + String workingDir = ""; + + workingCopy.setAttribute("org.eclipse.ui.externaltools.ATTR_LOCATION", location); + workingCopy.setAttribute("org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS", arguments); + workingCopy.setAttribute("org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY", workingDir); + + ILaunch launch = workingCopy.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor()); + + allLaunches.add(launch); + + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return null; + } + + @Override + public void launchesRemoved(ILaunch[] launches) { + // TODO Auto-generated method stub + + } + + @Override + public void launchesAdded(ILaunch[] launches) { + // TODO Auto-generated method stub + + } + + + @Override + public void launchesTerminated(ILaunch[] launches) { + + //Fetching serverUUID from scripts' output + String serverUUID = ""; + int i = consoleOutput.indexOf("serverUUID"); + + while(consoleOutput.charAt(i) != '"') ++i; + ++i; + + while(consoleOutput.charAt(i) != '"') ++i; + ++i; + + while(consoleOutput.charAt(i) != '"') + { + serverUUID+=consoleOutput.charAt(i); + ++i; + } + + Activator plugin = Activator.getDefault(); + IPreferenceStore prefStore = plugin.getPreferenceStore(); + prefStore.setValue("scase_fco_server_uuid", serverUUID); + + for (ILaunch launch : launches) { + allLaunches.remove(launch); + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { } + }); + + } + } + + @Override + public void launchesChanged(ILaunch[] launches) { + + IProcess[] processes = launches[0].getProcesses(); + IStreamsProxy streams = processes[0].getStreamsProxy(); + + IStreamMonitor streamsOut = streams.getOutputStreamMonitor(); + streamsOut.addListener(this); + } + + @Override + public void streamAppended(String text, IStreamMonitor monitor) { + consoleOutput += text; + } +} diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/ImportMavenProjectHandler.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/ImportMavenProjectHandler.java new file mode 100644 index 0000000..d3b9b92 --- /dev/null +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/ImportMavenProjectHandler.java @@ -0,0 +1,57 @@ +package eu.scasefp7.eclipse.core.ui.handlers; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.project.MavenProjectInfo; +import org.eclipse.m2e.core.project.ProjectImportConfiguration; +import org.eclipse.m2e.core.project.IProjectConfigurationManager; +import org.apache.maven.model.Model; + + +public class ImportMavenProjectHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) { +// Get pom file location from parameter +// String directory = event.getParameter("eu.scasefp7.eclipse.core.ui.projectDirectory"); +// if (directory.equals(null) || directory.equals(" ")) +// directory = "C:\\Users\\sc2015\\Desktop\\SCase\\mde\\pom.xml"; + + File pomFile = new File("C:\\Users\\sc2015\\Desktop\\SCase\\mde\\eu.scasefp7.eclipse.mde.ui\\pom.xml"); + Model model = new Model(); + + IProgressMonitor monitor = new NullProgressMonitor(); + ProjectImportConfiguration config = new ProjectImportConfiguration(); + Collection infos = new ArrayList(); + IProjectConfigurationManager manager = MavenPlugin.getProjectConfigurationManager(); + + String version = "1.0.0"; + String groupId = "groupID"; + String artifactId = "eu.scasefp7.eclipse.mde.ui"; + String projectName = "eu.scasefp7.eclipse.mde.ui"; + + model.setGroupId(groupId); + model.setArtifactId(artifactId); + model.setVersion(version); + model.setPomFile(pomFile); + + MavenProjectInfo info = new MavenProjectInfo(projectName, pomFile, model, null); + infos.add(info); + + try { + manager.importProjects(infos, config , monitor); + } catch (CoreException e) { + e.printStackTrace(); + } + + return null; + } + +} diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/LaunchExternalProgramHandler.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/LaunchExternalProgramHandler.java new file mode 100644 index 0000000..b224733 --- /dev/null +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/LaunchExternalProgramHandler.java @@ -0,0 +1,104 @@ +package eu.scasefp7.eclipse.core.ui.handlers; + + +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.debug.core.ILaunchesListener2; +import org.eclipse.swt.widgets.Display; + + + +public class LaunchExternalProgramHandler extends AbstractHandler implements ILaunchesListener2 { + + private Set allLaunches = new HashSet(); + ILaunchManager manager; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + try { + manager = DebugPlugin.getDefault().getLaunchManager(); + manager.addLaunchListener(this); + + ILaunchConfigurationType type = manager + .getLaunchConfigurationType("org.eclipse.ui.externaltools.ProgramLaunchConfigurationType"); + + ILaunchConfiguration[] configurations = manager + .getLaunchConfigurations(type); + + for (int i = 0; i < configurations.length; i++) { + ILaunchConfiguration configuration = configurations[i]; + if (configuration.getName().equals("Gen doc")) { + configuration.delete(); + break; + } + } + + ILaunchConfigurationWorkingCopy workingCopy = type.newInstance( null, "Gen doc"); + String location = event.getParameter("eu.scasefp7.eclipse.core.ui.location"); + String arguments = event.getParameter("eu.scasefp7.eclipse.core.ui.arguments"); + String workingDir = event.getParameter("eu.scasefp7.eclipse.core.ui.workingDirectory"); + + + workingCopy.setAttribute("org.eclipse.ui.externaltools.ATTR_LOCATION", location); + workingCopy.setAttribute("org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS", arguments); + workingCopy.setAttribute("org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY", workingDir); + + ILaunch launch = workingCopy.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor()); + + allLaunches.add(launch); + + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return null; + } + + @Override + public void launchesRemoved(ILaunch[] launches) { + // TODO Auto-generated method stub + + } + + @Override + public void launchesAdded(ILaunch[] launches) { + // TODO Auto-generated method stub + + } + + + + @Override + public void launchesTerminated(ILaunch[] launches) { + for (ILaunch launch : launches) { + allLaunches.remove(launch); + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { } + }); + + } + } + + @Override + public void launchesChanged(ILaunch[] launches) { + // TODO Auto-generated method stub + + } + + +} diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/OpenBrowserHandler.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/OpenBrowserHandler.java index cef1836..ff4f26e 100644 --- a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/OpenBrowserHandler.java +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/OpenBrowserHandler.java @@ -1,64 +1,64 @@ -package eu.scasefp7.eclipse.core.ui.handlers; - -import java.net.MalformedURLException; -import java.net.URL; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.browser.IWebBrowser; -//import org.eclipse.ui.browser.IWorkbenchBrowserSupport; -//import org.eclipse.ui.internal.browser.WorkbenchBrowserSupport; - - -import eu.scasefp7.eclipse.core.ui.Activator; -import eu.scasefp7.eclipse.core.ui.ScaseUiConstants; - - -/** - * Opens a URL given as a command parameter in an internal browser. - * - * @author Leonora Gašpar - * - */ -public class OpenBrowserHandler extends AbstractHandler { - - /** - * Command parameter - URL to open - */ - public static final String PARAM_URL = "eu.scasefp7.eclipse.core.ui.commands.openBrowser.url"; - - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - String url = ""; - try { - url = event.getParameter(PARAM_URL); - if(url == null) { - url = ScaseUiConstants.PROJECT_HOMEPAGE; - } - - final IWebBrowser browser = PlatformUI.getWorkbench().getBrowserSupport().createBrowser("browser"); - browser.openURL(new URL(url)); - } catch (PartInitException | MalformedURLException e) { - Activator.log("Unable to open browser on " + url, e); - } - -// ALTERNATIVE: - -// try { -// int style = IWorkbenchBrowserSupport.AS_EDITOR | IWorkbenchBrowserSupport.LOCATION_BAR | IWorkbenchBrowserSupport.STATUS; -// IWebBrowser browser = WorkbenchBrowserSupport.getInstance().createBrowser(style, "MyBrowserID", "MyBrowserName", "MyBrowser Tooltip"); -// browser.openURL(new URL("http://www.google.de")); -// } catch (PartInitException | MalformedURLException e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// } - - return null; - } - - - +package eu.scasefp7.eclipse.core.ui.handlers; + +import java.net.MalformedURLException; +import java.net.URL; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.browser.IWebBrowser; +//import org.eclipse.ui.browser.IWorkbenchBrowserSupport; +//import org.eclipse.ui.internal.browser.WorkbenchBrowserSupport; + + +import eu.scasefp7.eclipse.core.ui.Activator; +import eu.scasefp7.eclipse.core.ui.ScaseUiConstants; + + +/** + * Opens a URL given as a command parameter in an internal browser. + * + * @author Leonora Gašpar + * + */ +public class OpenBrowserHandler extends AbstractHandler { + + /** + * Command parameter - URL to open + */ + public static final String PARAM_URL = "eu.scasefp7.eclipse.core.ui.commands.openBrowser.url"; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + String url = ""; + try { + url = event.getParameter(PARAM_URL); + if(url == null) { + url = ScaseUiConstants.PROJECT_HOMEPAGE; + } + + final IWebBrowser browser = PlatformUI.getWorkbench().getBrowserSupport().createBrowser("browser"); + browser.openURL(new URL(url)); + } catch (PartInitException | MalformedURLException e) { + Activator.log("Unable to open browser on " + url, e); + } + +// ALTERNATIVE: + +// try { +// int style = IWorkbenchBrowserSupport.AS_EDITOR | IWorkbenchBrowserSupport.LOCATION_BAR | IWorkbenchBrowserSupport.STATUS; +// IWebBrowser browser = WorkbenchBrowserSupport.getInstance().createBrowser(style, "MyBrowserID", "MyBrowserName", "MyBrowser Tooltip"); +// browser.openURL(new URL("http://www.google.de")); +// } catch (PartInitException | MalformedURLException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } + + return null; + } + + + } \ No newline at end of file diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/OpenDeployWizardHander.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/OpenDeployWizardHander.java index 82bf41d..ddf605c 100644 --- a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/OpenDeployWizardHander.java +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/OpenDeployWizardHander.java @@ -1,57 +1,57 @@ -package eu.scasefp7.eclipse.core.ui.handlers; - -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.commands.IHandler; -import org.eclipse.core.commands.IHandlerListener; -import org.eclipse.jface.wizard.WizardDialog; -import eu.scasefp7.eclipse.core.ui.wizards.DeployWizard; - -/** - * Opens the deployment wizard. - * - * @author Leonora Gašpar - * - */ -public class OpenDeployWizardHander implements IHandler { - - @Override - public void addHandlerListener(IHandlerListener handlerListener) { - // TODO Auto-generated method stub - - } - - @Override - public void dispose() { - // TODO Auto-generated method stub - - } - - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - DeployWizard dw = new DeployWizard(); - WizardDialog dialog = new WizardDialog(null,dw ); - - dialog.open(); - return null; - } - - @Override - public boolean isEnabled() { - // TODO Auto-generated method stub - return true; - } - - @Override - public boolean isHandled() { - // TODO Auto-generated method stub - return true; - } - - @Override - public void removeHandlerListener(IHandlerListener handlerListener) { - // TODO Auto-generated method stub - - } - -} +package eu.scasefp7.eclipse.core.ui.handlers; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.commands.IHandlerListener; +import org.eclipse.jface.wizard.WizardDialog; +import eu.scasefp7.eclipse.core.ui.wizards.DeployWizard; + +/** + * Opens the deployment wizard. + * + * @author Leonora Gašpar + * + */ +public class OpenDeployWizardHander implements IHandler { + + @Override + public void addHandlerListener(IHandlerListener handlerListener) { + // TODO Auto-generated method stub + + } + + @Override + public void dispose() { + // TODO Auto-generated method stub + + } + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + DeployWizard dw = new DeployWizard(); + WizardDialog dialog = new WizardDialog(null,dw ); + + dialog.open(); + return null; + } + + @Override + public boolean isEnabled() { + // TODO Auto-generated method stub + return true; + } + + @Override + public boolean isHandled() { + // TODO Auto-generated method stub + return true; + } + + @Override + public void removeHandlerListener(IHandlerListener handlerListener) { + // TODO Auto-generated method stub + + } + +} diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/SecureIPreferenceStore.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/SecureIPreferenceStore.java new file mode 100644 index 0000000..2efc8ba --- /dev/null +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/SecureIPreferenceStore.java @@ -0,0 +1,137 @@ +package eu.scasefp7.eclipse.core.ui.handlers; + +import org.eclipse.core.runtime.preferences.IScopeContext; +import org.eclipse.equinox.security.storage.ISecurePreferences; +import org.eclipse.equinox.security.storage.SecurePreferencesFactory; +import org.eclipse.equinox.security.storage.StorageException; +import org.eclipse.ui.preferences.ScopedPreferenceStore; + +public class SecureIPreferenceStore extends ScopedPreferenceStore { + + private static final ISecurePreferences SECURE_PREFERENCES = SecurePreferencesFactory + .getDefault(); + + public SecureIPreferenceStore(IScopeContext context, String qualifier) { + super(context, qualifier); + } + + @Override + public void setValue(String name, boolean value) { + try { + SECURE_PREFERENCES.putBoolean(name, value, true); + } catch (StorageException e) { + e.printStackTrace(); + } + } + + @Override + public void setValue(String name, double value) { + try { + SECURE_PREFERENCES.putDouble(name, value, true); + } catch (StorageException e) { + e.printStackTrace(); + } + } + + @Override + public void setValue(String name, float value) { + try { + SECURE_PREFERENCES.putFloat(name, value, true); + } catch (StorageException e) { + e.printStackTrace(); + } + } + + @Override + public void setValue(String name, int value) { + try { + SECURE_PREFERENCES.putInt(name, value, true); + } catch (StorageException e) { + e.printStackTrace(); + } + } + + @Override + public void setValue(String name, long value) { + try { + SECURE_PREFERENCES.putLong(name, value, true); + } catch (StorageException e) { + e.printStackTrace(); + } + } + + @Override + public void setValue(String name, String value) { + try { + SECURE_PREFERENCES.put(name, value, true); + } catch (StorageException e) { + e.printStackTrace(); + } + } + + @Override + public boolean getBoolean(String name) { + Boolean result = false; + try { + result = SECURE_PREFERENCES.getBoolean(name, result); + } catch (StorageException e) { + e.printStackTrace(); + } + return result; + } + + @Override + public double getDouble(String name) { + Double result = 0.0; + try { + result = SECURE_PREFERENCES.getDouble(name, result); + } catch (StorageException e) { + e.printStackTrace(); + } + return result; + } + + @Override + public float getFloat(String name) { + Float result = 0.0f; + try { + result = SECURE_PREFERENCES.getFloat(name, result); + } catch (StorageException e) { + e.printStackTrace(); + } + return result; + } + + @Override + public int getInt(String name) { + int result = 0; + try { + result = SECURE_PREFERENCES.getInt(name, result); + } catch (StorageException e) { + e.printStackTrace(); + } + return result; + } + + @Override + public long getLong(String name) { + Long result = 0L; + try { + result = SECURE_PREFERENCES.getLong(name, result); + } catch (StorageException e) { + e.printStackTrace(); + } + return result; + } + + @Override + public String getString(String name) { + String result = ""; + try { + result = SECURE_PREFERENCES.get(name, ""); + } catch (StorageException e) { + e.printStackTrace(); + } + return result; + } +} \ No newline at end of file diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/StopServerHandler.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/StopServerHandler.java new file mode 100644 index 0000000..4723a77 --- /dev/null +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/handlers/StopServerHandler.java @@ -0,0 +1,135 @@ +package eu.scasefp7.eclipse.core.ui.handlers; + +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.variables.IDynamicVariable; +import org.eclipse.core.variables.IStringVariable; +import org.eclipse.core.variables.VariablesPlugin; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.debug.core.ILaunchesListener2; +import org.eclipse.debug.core.model.IStreamMonitor; +import org.eclipse.swt.widgets.Display; + +import eu.scasefp7.eclipse.core.ui.DynamicVariableResolver; + +public class StopServerHandler extends AbstractHandler implements ILaunchesListener2 { + + private Set allLaunches = new HashSet(); + ILaunchManager manager; + IStreamMonitor streamsOut; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + try { + manager = DebugPlugin.getDefault().getLaunchManager(); + manager.addLaunchListener(this); + + ILaunchConfigurationType type = manager + .getLaunchConfigurationType("org.eclipse.ui.externaltools.ProgramLaunchConfigurationType"); + + ILaunchConfiguration[] configurations = manager + .getLaunchConfigurations(type); + + for (int i = 0; i < configurations.length; i++) { + ILaunchConfiguration configuration = configurations[i]; + if (configuration.getName().equals("Gen doc")) { + configuration.delete(); + break; + } + } + + + String cust_uuid = null, username = null, password = null, server_uuid = null; + + IStringVariable[] variables = VariablesPlugin.getDefault().getStringVariableManager().getVariables(); + + for (int i = 0; i < variables.length; i++) { + IDynamicVariable currVar = ((IDynamicVariable)variables[i]); + DynamicVariableResolver resolver = new DynamicVariableResolver(); + String name = currVar.getName(); + + if(name.equals("scase_fco_cust_uuid" ) ) + cust_uuid = resolver.resolveValue(currVar, name); + + if(name.equals( "scase_fco_cust_name")) + username = resolver.resolveValue(currVar, name); + + if(name.equals("scase_fco_cust_pwd" )) + password = resolver.resolveValue(currVar, name); + + if(name.equals("scase_fco_server_uuid" )) + server_uuid = resolver.resolveValue(currVar, name); + + } + + + ILaunchConfigurationWorkingCopy workingCopy = type.newInstance( null, "Gen doc"); + + //replace with location of python.exe + String location ="C:\\Python27\\python.exe"; + + //replace with location of script + String arguments ="C:\\Users\\sc2015\\Desktop\\SCase\\YouREST-backend\\SCase-FCO\\stopServer.py "; + + arguments += cust_uuid + " " + username + " " + password + " " + server_uuid; + String workingDir = ""; + + workingCopy.setAttribute("org.eclipse.ui.externaltools.ATTR_LOCATION", location); + workingCopy.setAttribute("org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS", arguments); + workingCopy.setAttribute("org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY", workingDir); + + ILaunch launch = workingCopy.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor()); + allLaunches.add(launch); + + + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return null; + } + + @Override + public void launchesRemoved(ILaunch[] launches) { + // TODO Auto-generated method stub + + } + + @Override + public void launchesAdded(ILaunch[] launches) { + // TODO Auto-generated method stub + } + + + + @Override + public void launchesTerminated(ILaunch[] launches) { + for (ILaunch launch : launches) { + allLaunches.remove(launch); + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { } + }); + + } + } + + @Override + public void launchesChanged(ILaunch[] launches) { + // TODO Auto-generated method stub + + } +} diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/navigator/ScaseLabel.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/navigator/ScaseLabel.java new file mode 100644 index 0000000..3b6d9ba --- /dev/null +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/navigator/ScaseLabel.java @@ -0,0 +1,52 @@ +package eu.scasefp7.eclipse.core.ui.navigator; + +import java.net.URL; + +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.IDecoration; +import org.eclipse.jface.viewers.ILightweightLabelDecorator; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.ui.internal.util.BundleUtility; +import org.osgi.framework.Bundle; + +import eu.scasefp7.eclipse.core.ui.ScaseUiConstants; + +public class ScaseLabel extends LabelProvider implements ILightweightLabelDecorator { + + @Override + public void decorate(Object resource, IDecoration decoration) { + if(resource instanceof IFolder){ + IProject project = ((IFolder)resource).getProject(); + String modelsPath = ""; + String outputPath = ""; + String reqPath = ""; + String comPath = ""; + String resourcePath = ((IFolder) resource).getFullPath().toString(); + + Bundle bundle = Platform.getBundle("eu.scasefp7.eclipse.core.ui"); + URL fullPathString = BundleUtility.find(bundle, "icons/s-case_8x8.png"); + + try { + comPath = project.getPersistentProperty(new QualifiedName("", ScaseUiConstants.COMPOSITIONS_FOLDER)); + reqPath = project.getPersistentProperty(new QualifiedName("", ScaseUiConstants.REQUIREMENTS_FOLDER)); + modelsPath = project.getPersistentProperty(new QualifiedName("", ScaseUiConstants.MODELS_FOLDER)); + outputPath = project.getPersistentProperty(new QualifiedName("", ScaseUiConstants.OUTPUT_FOLDER)); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if(resourcePath.equals(comPath) || resourcePath.equals(reqPath) || resourcePath.equals(modelsPath) || resourcePath.equals(outputPath) ){ + decoration.addOverlay(ImageDescriptor.createFromURL(fullPathString), IDecoration.TOP_RIGHT); + + } + } + + } + + +} diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/DomainBoldLabelProvider.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/DomainBoldLabelProvider.java index 719aace..1742e98 100644 --- a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/DomainBoldLabelProvider.java +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/DomainBoldLabelProvider.java @@ -12,7 +12,7 @@ public class DomainBoldLabelProvider extends DomainLabelProvider implements IFon private FilteredTree filterTree; private PatternFilter filterForBoldElements; - DomainBoldLabelProvider(FilteredTree filterTree) { + public DomainBoldLabelProvider(FilteredTree filterTree) { this.filterTree = filterTree; filterForBoldElements = filterTree.getPatternFilter(); } diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/GlobalPreferencePage.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/GlobalPreferencePage.java index b69cc1f..1316539 100644 --- a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/GlobalPreferencePage.java +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/GlobalPreferencePage.java @@ -190,4 +190,4 @@ public IAdaptable getElement() { public void setElement(IAdaptable element) { this.element = element; } -} +} diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/MultiLineTextFieldEditor.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/MultiLineTextFieldEditor.java new file mode 100644 index 0000000..4ef5211 --- /dev/null +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/MultiLineTextFieldEditor.java @@ -0,0 +1,567 @@ +package eu.scasefp7.eclipse.core.ui.preferences; + +import org.eclipse.jface.preference.FieldEditor; +import org.eclipse.jface.util.Assert; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +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.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Text; + +/** + * MultiLineTextFieldEditor. Field editor that is same as string field editor + * but will have the multi line text field for user input. + */ + +public class MultiLineTextFieldEditor extends FieldEditor { + + private static final String ERROR_MESSAGE = "Multiline.error.message"; //$NON-NLS-1$ + + /** + * Validation strategy constant (value 0) indicating that the + * editor should perform validation after every key stroke. + * + * @see #setValidateStrategy + */ + public static final int VALIDATE_ON_KEY_STROKE = 0; + + /** + * Validation strategy constant (value 1) indicating that the + * editor should perform validation only when the text widget loses focus. + * + * @see #setValidateStrategy + */ + public static final int VALIDATE_ON_FOCUS_LOST = 1; + + /** + * Text limit constant (value -1) indicating unlimited text + * limit and width. + */ + public static int UNLIMITED = -1; + + /** + * Cached valid state. + */ + private boolean isValid; + + /** + * Old text value. + */ + private String oldValue; + + /** + * The text field, or null if none. + */ + private Text textField; + + /** + * Width of text field in characters; initially unlimited. + */ + private int widthInChars = UNLIMITED; + + /** + * Text limit of text field in characters; initially unlimited. + */ + private int textLimit = UNLIMITED; + + /** + * The error message, or null if none. + */ + private String errorMessage; + + /** + * Indicates whether the empty string is legal; true by + * default. + */ + private boolean emptyStringAllowed = true; + + /** + * The validation strategy; VALIDATE_ON_KEY_STROKE by default. + */ + private int validateStrategy = VALIDATE_ON_KEY_STROKE; + + /** + * Creates a new string field editor + */ + protected MultiLineTextFieldEditor() { + } + + /** + * Creates a string field editor. Use the method setTextLimit + * to limit the text. + * + * @param name + * the name of the preference this field editor works on + * @param labelText + * the label text of the field editor + * @param width + * the width of the text input field in characters, or + * UNLIMITED for no limit + * @param strategy + * either VALIDATE_ON_KEY_STROKE to perform on the + * fly checking (the default), or + * VALIDATE_ON_FOCUS_LOST to perform validation only + * after the text has been typed in + * @param parent + * the parent of the field editor's control + * @since 2.0 + */ + public MultiLineTextFieldEditor(String name, String labelText, int width, + int strategy, Composite parent) { + init(name, labelText); + widthInChars = width; + setValidateStrategy(strategy); + isValid = false; + errorMessage = "Field contains an invalid value"; + createControl(parent); + } + + /** + * Creates a string field editor. Use the method setTextLimit + * to limit the text. + * + * @param name + * the name of the preference this field editor works on + * @param labelText + * the label text of the field editor + * @param width + * the width of the text input field in characters, or + * UNLIMITED for no limit + * @param parent + * the parent of the field editor's control + */ + public MultiLineTextFieldEditor(String name, String labelText, int width, + Composite parent) { + this(name, labelText, width, VALIDATE_ON_KEY_STROKE, parent); + // this.compTitle = labelText; + } + + /** + * Creates a string field editor of unlimited width. Use the method + * setTextLimit to limit the text. + * + * @param name + * the name of the preference this field editor works on + * @param labelText + * the label text of the field editor + * @param parent + * the parent of the field editor's control + */ + public MultiLineTextFieldEditor(String name, String labelText, + Composite parent) { + this(name, labelText, UNLIMITED, parent); + } + + /** + * Adjusts the horizontal span of this field editor's basic controls + *

+ * Subclasses must implement this method to adjust the horizontal span of + * controls so they appear correct in the given number of columns. + *

+ *

+ * The number of columns will always be equal to or greater than the value + * returned by this editor's getNumberOfControls method. + * + * @param numColumns + * the number of columns + */ + protected void adjustForNumColumns(int numColumns) { + GridData gd = (GridData) textField.getLayoutData(); + gd.horizontalSpan = numColumns - 1; + // We only grab excess space if we have to + // If another field editor has more columns then + // we assume it is setting the width. + gd.grabExcessHorizontalSpace = gd.horizontalSpan == 1; + } + + /** + * Checks whether the text input field contains a valid value or not. + * + * @return true if the field value is valid, and + * false if invalid + */ + protected boolean checkState() { + boolean result = false; + if (emptyStringAllowed) + result = true; + + if (textField == null) + result = false; + + String txt = textField.getText(); + + if (txt == null) + result = false; + + result = (txt.trim().length() > 0) || emptyStringAllowed; + + // call hook for subclasses + result = result && doCheckState(); + + if (result) + clearErrorMessage(); + else + showErrorMessage(errorMessage); + + return result; + } + + /** + * Hook for subclasses to do specific state checks. + *

+ * The default implementation of this framework method does nothing and + * returns true. Subclasses should override this method to + * specific state checks. + *

+ * + * @return true if the field value is valid, and + * false if invalid + */ + protected boolean doCheckState() { + return true; + } + + /** + * Fills this field editor's basic controls into the given parent. + *

+ * The string field implementation of this FieldEditor + * framework method contributes the text field. Subclasses may override but + * must call super.doFillIntoGrid. + *

+ */ + protected void doFillIntoGrid(Composite parent, int numColumns) { + + getLabelControl(parent); + textField = getTextControl(parent); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.widthHint = 100; + gd.heightHint = 70; + textField.setLayoutData(gd); + + } + + /** + * Initializes this field editor with the preference value from the + * preference store. + *

+ * Subclasses must implement this method to properly initialize the field + * editor. + *

+ */ + protected void doLoad() { + if (textField != null) { + String value = getPreferenceStore().getString(getPreferenceName()); + textField.setText(value); + oldValue = value; + } + } + + /** + * Initializes this field editor with the default preference value from the + * preference store. + *

+ * Subclasses must implement this method to properly initialize the field + * editor. + *

+ */ + protected void doLoadDefault() { + if (textField != null) { + String value = getPreferenceStore().getDefaultString( + getPreferenceName()); + textField.setText(value); + } + valueChanged(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.preference.FieldEditor#doStore() + */ + protected void doStore() { + getPreferenceStore().setValue(getPreferenceName(), textField.getText()); + } + + /** + * Returns the error message that will be displayed when and if an error + * occurs. + * + * @return the error message, or null if none + */ + public String getErrorMessage() { + return errorMessage; + } + + /** + * Returns the number of basic controls this field editor consists of. + * + * @return the number of controls + */ + public int getNumberOfControls() { + return 2; + } + + /** + * Returns the field editor's value. + * + * @return the current value + */ + public String getStringValue() { + if (textField != null) + return textField.getText(); + else + return getPreferenceStore().getString(getPreferenceName()); + } + + /** + * Returns this field editor's text control. + * + * @param parent + * the parent + * @return the text control, or null if no text field is + * created yet + */ + protected Text getTextControl() { + return textField; + } + + /** + * Returns this field editor's text control. + *

+ * The control is created if it does not yet exist + *

+ * + * @param parent + * the parent + * @return the text control + */ + public Text getTextControl(Composite parent) { + if (textField == null) { + textField = new Text(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER + | SWT.WRAP); + textField.setFont(parent.getFont()); + switch (validateStrategy) { + case VALIDATE_ON_KEY_STROKE: + textField.addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent e) { + valueChanged(); + } + }); + + textField.addFocusListener(new FocusAdapter() { + public void focusGained(FocusEvent e) { + refreshValidState(); + } + + public void focusLost(FocusEvent e) { + clearErrorMessage(); + } + }); + break; + case VALIDATE_ON_FOCUS_LOST: + textField.addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent e) { + clearErrorMessage(); + } + }); + textField.addFocusListener(new FocusAdapter() { + public void focusGained(FocusEvent e) { + refreshValidState(); + } + + public void focusLost(FocusEvent e) { + valueChanged(); + clearErrorMessage(); + } + }); + break; + default: + Assert.isTrue(false, "Unknown validate strategy"); //$NON-NLS-1$ + } + textField.addDisposeListener(new DisposeListener() { + public void widgetDisposed(DisposeEvent event) { + textField = null; + } + }); + if (textLimit > 0) { // Only set limits above 0 - see SWT spec + textField.setTextLimit(textLimit); + } + } else { + checkParent(textField, parent); + } + return textField; + } + + /** + * Returns whether an empty string is a valid value. + * + * @return true if an empty string is a valid value, and + * false if an empty string is invalid + * @see #setEmptyStringAllowed + */ + public boolean isEmptyStringAllowed() { + return emptyStringAllowed; + } + + /** + * Returns whether this field editor contains a valid value. + *

+ * The default implementation of this framework method returns + * true. Subclasses wishing to perform validation should + * override both this method and refreshValidState. + *

+ * + * @return true if the field value is valid, and + * false if invalid + * @see #refreshValidState + */ + public boolean isValid() { + return isValid; + } + + /** + * Refreshes this field editor's valid state after a value change and fires + * an IS_VALID property change event if warranted. + *

+ * The default implementation of this framework method does nothing. + * Subclasses wishing to perform validation should override both this method + * and isValid. + *

+ * + * @see #isValid + */ + protected void refreshValidState() { + isValid = checkState(); + } + + @Override + public void setEnabled(boolean enabled, Composite parent) { + super.setEnabled(enabled, parent); + getTextControl(parent).setEnabled(enabled); + } + + /** + * Sets whether the empty string is a valid value or not. + * + * @param b + * true if the empty string is allowed, and + * false if it is considered invalid + */ + public void setEmptyStringAllowed(boolean b) { + emptyStringAllowed = b; + } + + /** + * Sets the error message that will be displayed when and if an error + * occurs. + * + * @param message + * the error message + */ + public void setErrorMessage(String message) { + errorMessage = message; + } + + /** + * Sets the focus to this field editor. + *

+ * The default implementation of this framework method does nothing. + * Subclasses may reimplement. + *

+ */ + public void setFocus() { + if (textField != null) { + textField.setFocus(); + } + } + + /** + * Sets this field editor's value. + * + * @param value + * the new value, or null meaning the empty string + */ + public void setStringValue(String value) { + if (textField != null) { + if (value == null) + value = ""; //$NON-NLS-1$ + oldValue = textField.getText(); + if (!oldValue.equals(value)) { + textField.setText(value); + valueChanged(); + } + } + } + + /** + * Sets this text field's text limit. + * + * @param limit + * the limit on the number of character in the text input field, + * or UNLIMITED for no limit + */ + public void setTextLimit(int limit) { + textLimit = limit; + if (textField != null) + textField.setTextLimit(limit); + } + + /** + * Sets the strategy for validating the text. + *

+ * Calling this method has no effect after createPartControl is + * called. Thus this method is really only useful for subclasses to call in + * their constructor. However, it has public visibility for backward + * compatibility. + *

+ * + * @param value + * either VALIDATE_ON_KEY_STROKE to perform on the + * fly checking (the default), or + * VALIDATE_ON_FOCUS_LOST to perform validation only + * after the text has been typed in + */ + + public void setValidateStrategy(int value) { + Assert.isTrue(value == VALIDATE_ON_FOCUS_LOST + || value == VALIDATE_ON_KEY_STROKE); + validateStrategy = value; + } + + /** + * Shows the error message set via setErrorMessage. + */ + public void showErrorMessage() { + showErrorMessage(errorMessage); + } + + /** + * Informs this field editor's listener, if it has one, about a change to + * the value (VALUE property) provided that the old and new + * values are different. + *

+ * This hook is not called when the text is initialized (or reset + * to the default value) from the preference store. + *

+ */ + protected void valueChanged() { + setPresentsDefaultValue(false); + boolean oldState = isValid; + refreshValidState(); + + if (isValid != oldState) + fireStateChanged(IS_VALID, oldState, isValid); + + String newValue = textField.getText(); + if (!newValue.equals(oldValue)) { + fireValueChanged(VALUE, oldValue, newValue); + oldValue = newValue; + } + } + +} diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/PreferenceConstantsPage.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/PreferenceConstantsPage.java new file mode 100644 index 0000000..994971f --- /dev/null +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/PreferenceConstantsPage.java @@ -0,0 +1,55 @@ +package eu.scasefp7.eclipse.core.ui.preferences; + +import org.eclipse.core.runtime.preferences.ConfigurationScope; +import org.eclipse.jface.preference.StringFieldEditor; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; +import eu.scasefp7.eclipse.core.ui.handlers.SecureIPreferenceStore; + +public class PreferenceConstantsPage extends FieldEditorOverlayPage implements + IWorkbenchPreferencePage { + + private static final String PAGE_ID = "eu.scasefp7.eclipse.core.ui.preferencePages.PreferenceConstantsPage"; + + public PreferenceConstantsPage() { + super(GRID); + setPreferenceStore(new SecureIPreferenceStore(ConfigurationScope.INSTANCE,"eu.scasefp7.eclipse.core.ui.preferences.secure")); + } + + @Override + public void createFieldEditors() { + addField(new StringFieldEditor("scase_fco_cust_uuid", "Customer UUID:", + getFieldEditorParent())); + + addField(new StringFieldEditor("scase_fco_cust_name", "Username:", + getFieldEditorParent())); + + addField(new StringFieldEditor("scase_fco_cust_pwd", "Password", + getFieldEditorParent()) { + @Override + protected void doFillIntoGrid(Composite parent, int numColumns) { + super.doFillIntoGrid(parent, numColumns); + Text text = getTextControl(); + String value = text.toString(); + getTextControl().setEchoChar('*'); + setStringValue(value); + } + }); + + addField(new MultiLineTextFieldEditor("scase_fco_ssh_key", "SSH key:", + getFieldEditorParent())); + + } + + @Override + public void init(IWorkbench workbench) { + setDescription("Preferences for arguments"); + } + + @Override + protected String getPageId() { + return PAGE_ID; + } +} \ No newline at end of file diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/PreferenceInitializer.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/PreferenceInitializer.java index 0577dd3..381cc3c 100644 --- a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/PreferenceInitializer.java +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/PreferenceInitializer.java @@ -23,4 +23,4 @@ public void initializeDefaultPreferences() { store.setDefault(PreferenceConstants.P_WSC_ENDPOINT, "sftp://109.231.127.61:22"); //$NON-NLS-1$ store.setDefault(PreferenceConstants.P_CONTROLTOWER_ENDPOINT, "http://app.scasefp7.com:3000/"); //$NON-NLS-1$ } -} +} diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/ProjectDomainPropertyAndWizardPage.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/ProjectDomainPropertyAndWizardPage.java index f035766..66632c9 100644 --- a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/ProjectDomainPropertyAndWizardPage.java +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/ProjectDomainPropertyAndWizardPage.java @@ -1,434 +1,434 @@ -package eu.scasefp7.eclipse.core.ui.preferences; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.jface.preference.PreferencePage; -import org.eclipse.jface.resource.ImageDescriptor; -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.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.jface.viewers.ViewerFilter; -import org.eclipse.jface.wizard.IWizard; -import org.eclipse.jface.wizard.IWizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.dialogs.FilteredTree; -import org.eclipse.ui.dialogs.PatternFilter; -import org.eclipse.ui.dialogs.PropertyPage; - -import eu.scasefp7.eclipse.core.ui.preferences.internal.DomainEntry; -import eu.scasefp7.eclipse.core.ui.preferences.internal.IProjectDomains; - -/** - * @author Marin Orlic - * - */ -public class ProjectDomainPropertyAndWizardPage extends PropertyPage implements IWizardPage { - - private static final String DOMAIN_PROPERTY = "eu.scasefp7.eclipse.core.projectDomain"; - private static final int DOMAIN_DEFAULT = -1; - - private Label domainLabel; - - private boolean locked; - - private Composite composite; - private Composite cmpLabels; - - protected DomainFilteredTree filteredTree; - protected TreeViewer treeViewer; - - /** - * This page's name. - */ - private String name; - - /** - * The wizard to which this page belongs; null - * if this page has yet to be added to a wizard. - */ - private IWizard wizard = null; - - /** - * Indicates whether this page is complete. - */ - private boolean isPageComplete = true; - - /** - * The page that was shown right before this page became visible; - * null if none. - */ - private IWizardPage previousPage = null; - - - protected class DomainFilteredTree extends FilteredTree { - private ViewerFilter viewerFilter; - - DomainFilteredTree(Composite parent, int treeStyle, PatternFilter filter) { - super(parent, treeStyle, filter, true); - } - - protected void addFilter(ViewerFilter filter) { - viewerFilter = filter; - getViewer().addFilter(filter); - - if (filterText != null) { - setFilterText("type filter text"); - textChanged(); - } - } - - protected void updateToolbar(boolean visible) { - super.updateToolbar((viewerFilter != null) || (visible)); - } - - protected void clearText() { - setFilterText(""); - - if ((!locked) && (viewerFilter != null)) { - getViewer().removeFilter(viewerFilter); - viewerFilter = null; - } - textChanged(); - } - } - - /** - * Constructor for ProjectDomainPropertyPage. - * Sets the message and description. - */ - public ProjectDomainPropertyAndWizardPage() { - super(); - setMessage("Project domain"); - setDescription("Configures project semantical domain"); - } - - /** - * Creates a new wizard page with the given name, and - * with no title or image. - * - * @param pageName the name of the page - */ - protected ProjectDomainPropertyAndWizardPage(String pageName) { - this(pageName, null, (ImageDescriptor) null); - } - - /** - * Creates a new wizard page with the given name, title, and image. - * - * @param pageName the name of the page - * @param title the title for this wizard page, - * or null if none - * @param titleImage the image descriptor for the title of this wizard page, - * or null if none - */ - protected ProjectDomainPropertyAndWizardPage(String pageName, String title, - ImageDescriptor titleImage) { - super(); - this.setTitle(title); - this.setImageDescriptor(titleImage); - Assert.isNotNull(pageName); // page name must not be null - name = pageName; - } - - protected void setContentAndLabelProviders(TreeViewer treeViewer) - { - treeViewer.setLabelProvider(new DomainBoldLabelProvider(filteredTree)); - treeViewer.setContentProvider(new DomainContentProvider()); - } - - - /** - * Read the configured properties and set the label - * @return domain code - */ - private int loadProperties() { - // Populate domain label - if (getElement() == null) - return DOMAIN_DEFAULT; - - try { - IResource project = ((IProject) getElement().getAdapter(IResource.class)); - String domain = project.getPersistentProperty(new QualifiedName("", DOMAIN_PROPERTY)); - if(domain != null) { - return Integer.parseInt(domain); - } - } catch (CoreException | NumberFormatException e) { - return DOMAIN_DEFAULT; - } - - return DOMAIN_DEFAULT; - } - - protected void selectSavedItem() - { - DomainEntry[] domains = IProjectDomains.PROJECT_DOMAINS; - treeViewer.setInput(domains); - - int domainId = loadProperties(); - - DomainEntry domain = findDomainById(domains, domainId); - if (domain != null) { - treeViewer.setSelection(new StructuredSelection(domain), true); - } - - // Set focus to tree or the filter control - if (treeViewer.getTree().getItemCount() > 1) { - Text filterText = filteredTree.getFilterControl(); - if (filterText != null) { - filterText.setFocus(); - } - } else { - treeViewer.getControl().setFocus(); - } - } - - - private DomainEntry findDomainById(DomainEntry[] domains, int domainId) { - for (DomainEntry de : domains) { - if (de.getId() == domainId) { - return de; - } - if(de.hasChildren()) { - for (DomainEntry child : de.getChildren()) { - if(child.getId() == domainId) { - return child; - } - } - } - } - return null; - } - - - private void createDomainLabel(Composite parent, Object data) { - cmpLabels = new Composite(parent, SWT.NONE); - GridLayout gl_cmpLabels = new GridLayout(2, false); - gl_cmpLabels.marginWidth = 0; - cmpLabels.setLayout(gl_cmpLabels); - cmpLabels.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); - - // Add label - Label noteLabel = new Label(cmpLabels, SWT.NONE); - noteLabel.setText("Project do&main:"); - - domainLabel = new Label(cmpLabels, SWT.NONE); - domainLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - domainLabel.setText("(select a domain)"); - domainLabel.setData(data); - } - - /** - * @see PreferencePage#createContents(Composite) - */ - protected Control createContents(Composite parent) { - composite = new Composite(parent, SWT.NONE); - GridLayout gl_composite = new GridLayout(); - gl_composite.marginWidth = 0; - gl_composite.marginHeight = 0; - composite.setLayout(gl_composite); - GridData data = new GridData(GridData.FILL); - data.grabExcessHorizontalSpace = true; - composite.setLayoutData(data); - - int domainId = loadProperties(); - - // Add the domain label - createDomainLabel(composite, (domainId != DOMAIN_DEFAULT) ? domainId : null); - - // Add tree - treeViewer = createTreeViewer(composite); - - // Load the saved property - selectSavedItem(); - - return composite; - } - - protected TreeViewer createTreeViewer(Composite parent) { - TreeViewer tree; - - filteredTree = new DomainFilteredTree(parent, SWT.FILL, new PatternFilter()); - filteredTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); -// horizontalIndent = 7; - filteredTree.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); - - tree = filteredTree.getViewer(); - - setContentAndLabelProviders(tree); - tree.setInput(IProjectDomains.PROJECT_DOMAINS); - - tree.addSelectionChangedListener(new ISelectionChangedListener() { - - public void selectionChanged(SelectionChangedEvent event) { - handleTreeSelectionChanged(event); - } - - }); - - //super.addListeners(tree); - return tree; - } - - protected DomainEntry getSingleSelection(ISelection selection) - { - if (!selection.isEmpty()) { - IStructuredSelection structured = (IStructuredSelection)selection; - if ((structured.getFirstElement() instanceof DomainEntry)) { - return (DomainEntry)structured.getFirstElement(); - } - } - return null; - } - - protected void handleTreeSelectionChanged(SelectionChangedEvent event) { - DomainEntry de = getSingleSelection(event.getSelection()); - updateDomainLabel(de); - } - - protected void performDefaults() { - super.performDefaults(); - // Populate the owner text field with the default value -// ownerText.setText(DEFAULT_OWNER); - } - - public boolean performOk() { - // Store the value in properties - try { - DomainEntry de = (DomainEntry) domainLabel.getData(); - if(de != null) { - ((IResource) getElement()).setPersistentProperty(new QualifiedName("", DOMAIN_PROPERTY), Integer.toString(de.getId())); - } - } catch (CoreException e) { - return false; - } - return true; - } - - /** - * @param selection - */ - private void updateDomainLabel(DomainEntry domain) { - if(domain == null) - return; - - DomainEntry parent = domain.getParent(); - - if(parent != null) { - String text = parent.getName() + "/" + domain.getName(); - - // Escape text for SWT - domainLabel.setText(text.replaceAll("&", "&&")); //$NON-NLS-1$ //$NON-NLS-2$ - domainLabel.setData(domain); - } - } - - @Override - public void createControl(Composite parent) { - super.createControl(parent); -// createContents(parent); - setControl(parent); - } - - @Override - public boolean canFlipToNextPage() { - return isPageComplete() && getNextPage() != null; - } - - @Override - public String getName() { - return name; - } - - @Override - public IWizardPage getNextPage() { - if (wizard == null) { - return null; - } - return wizard.getNextPage(this); - } - - @Override - public IWizardPage getPreviousPage() { - if (previousPage != null) { - return previousPage; - } - - if (wizard == null) { - return null; - } - - return wizard.getPreviousPage(this); - } - - @Override - public IWizard getWizard() { - return wizard; - } - - @Override - public boolean isPageComplete() { - return isPageComplete; - } - - @Override - public void setPreviousPage(IWizardPage page) { - previousPage = page; - } - - /** - * Returns whether this page is the current one in the wizard's container. - * - * @return true if the page is active, - * and false otherwise - */ - protected boolean isCurrentPage() { - return (getContainer() != null - && getContainer() == wizard.getContainer() - && this == wizard.getContainer().getCurrentPage()); - } - - - /** - * The WizardPage implementation of this method - * declared on DialogPage updates the container - * if this is the current page. - */ - @Override - public void setMessage(String newMessage, int newType) { - super.setMessage(newMessage, newType); - if (isCurrentPage()) { // TODO - getContainer().updateMessage(); - } - } - - /** - * The WizardPage implementation of this IDialogPage - * method extends the DialogPage implementation to update - * the wizard container title bar. Subclasses may extend. - */ - @Override - public void setDescription(String description) { - super.setDescription(description); - if (wizard != null) { - wizard.getContainer().updateTitleBar(); - } - } - - @Override - public void setWizard(IWizard newWizard) { - wizard = newWizard; - } - +package eu.scasefp7.eclipse.core.ui.preferences; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.jface.resource.ImageDescriptor; +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.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.jface.wizard.IWizard; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.FilteredTree; +import org.eclipse.ui.dialogs.PatternFilter; +import org.eclipse.ui.dialogs.PropertyPage; + +import eu.scasefp7.eclipse.core.ui.preferences.internal.DomainEntry; +import eu.scasefp7.eclipse.core.ui.preferences.internal.IProjectDomains; + +/** + * @author Marin Orlic + * + */ +public class ProjectDomainPropertyAndWizardPage extends PropertyPage implements IWizardPage { + + private static final String DOMAIN_PROPERTY = "eu.scasefp7.eclipse.core.projectDomain"; + private static final int DOMAIN_DEFAULT = -1; + + private Label domainLabel; + + private boolean locked; + + private Composite composite; + private Composite cmpLabels; + + protected DomainFilteredTree filteredTree; + protected TreeViewer treeViewer; + + /** + * This page's name. + */ + private String name; + + /** + * The wizard to which this page belongs; null + * if this page has yet to be added to a wizard. + */ + private IWizard wizard = null; + + /** + * Indicates whether this page is complete. + */ + private boolean isPageComplete = true; + + /** + * The page that was shown right before this page became visible; + * null if none. + */ + private IWizardPage previousPage = null; + + + protected class DomainFilteredTree extends FilteredTree { + private ViewerFilter viewerFilter; + + DomainFilteredTree(Composite parent, int treeStyle, PatternFilter filter) { + super(parent, treeStyle, filter, true); + } + + protected void addFilter(ViewerFilter filter) { + viewerFilter = filter; + getViewer().addFilter(filter); + + if (filterText != null) { + setFilterText("type filter text"); + textChanged(); + } + } + + protected void updateToolbar(boolean visible) { + super.updateToolbar((viewerFilter != null) || (visible)); + } + + protected void clearText() { + setFilterText(""); + + if ((!locked) && (viewerFilter != null)) { + getViewer().removeFilter(viewerFilter); + viewerFilter = null; + } + textChanged(); + } + } + + /** + * Constructor for ProjectDomainPropertyPage. + * Sets the message and description. + */ + public ProjectDomainPropertyAndWizardPage() { + super(); + setMessage("Project domain"); + setDescription("Configures project semantical domain"); + } + + /** + * Creates a new wizard page with the given name, and + * with no title or image. + * + * @param pageName the name of the page + */ + protected ProjectDomainPropertyAndWizardPage(String pageName) { + this(pageName, null, (ImageDescriptor) null); + } + + /** + * Creates a new wizard page with the given name, title, and image. + * + * @param pageName the name of the page + * @param title the title for this wizard page, + * or null if none + * @param titleImage the image descriptor for the title of this wizard page, + * or null if none + */ + protected ProjectDomainPropertyAndWizardPage(String pageName, String title, + ImageDescriptor titleImage) { + super(); + this.setTitle(title); + this.setImageDescriptor(titleImage); + Assert.isNotNull(pageName); // page name must not be null + name = pageName; + } + + protected void setContentAndLabelProviders(TreeViewer treeViewer) + { + treeViewer.setLabelProvider(new DomainBoldLabelProvider(filteredTree)); + treeViewer.setContentProvider(new DomainContentProvider()); + } + + + /** + * Read the configured properties and set the label + * @return domain code + */ + private int loadProperties() { + // Populate domain label + if (getElement() == null) + return DOMAIN_DEFAULT; + + try { + IResource project = ((IProject) getElement().getAdapter(IResource.class)); + String domain = project.getPersistentProperty(new QualifiedName("", DOMAIN_PROPERTY)); + if(domain != null) { + return Integer.parseInt(domain); + } + } catch (CoreException | NumberFormatException e) { + return DOMAIN_DEFAULT; + } + + return DOMAIN_DEFAULT; + } + + protected void selectSavedItem() + { + DomainEntry[] domains = IProjectDomains.PROJECT_DOMAINS; + treeViewer.setInput(domains); + + int domainId = loadProperties(); + + DomainEntry domain = findDomainById(domains, domainId); + if (domain != null) { + treeViewer.setSelection(new StructuredSelection(domain), true); + } + + // Set focus to tree or the filter control + if (treeViewer.getTree().getItemCount() > 1) { + Text filterText = filteredTree.getFilterControl(); + if (filterText != null) { + filterText.setFocus(); + } + } else { + treeViewer.getControl().setFocus(); + } + } + + + private DomainEntry findDomainById(DomainEntry[] domains, int domainId) { + for (DomainEntry de : domains) { + if (de.getId() == domainId) { + return de; + } + if(de.hasChildren()) { + for (DomainEntry child : de.getChildren()) { + if(child.getId() == domainId) { + return child; + } + } + } + } + return null; + } + + + private void createDomainLabel(Composite parent, Object data) { + cmpLabels = new Composite(parent, SWT.NONE); + GridLayout gl_cmpLabels = new GridLayout(2, false); + gl_cmpLabels.marginWidth = 0; + cmpLabels.setLayout(gl_cmpLabels); + cmpLabels.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); + + // Add label + Label noteLabel = new Label(cmpLabels, SWT.NONE); + noteLabel.setText("Project do&main:"); + + domainLabel = new Label(cmpLabels, SWT.NONE); + domainLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + domainLabel.setText("(select a domain)"); + domainLabel.setData(data); + } + + /** + * @see PreferencePage#createContents(Composite) + */ + protected Control createContents(Composite parent) { + composite = new Composite(parent, SWT.NONE); + GridLayout gl_composite = new GridLayout(); + gl_composite.marginWidth = 0; + gl_composite.marginHeight = 0; + composite.setLayout(gl_composite); + GridData data = new GridData(GridData.FILL); + data.grabExcessHorizontalSpace = true; + composite.setLayoutData(data); + + int domainId = loadProperties(); + + // Add the domain label + createDomainLabel(composite, (domainId != DOMAIN_DEFAULT) ? domainId : null); + + // Add tree + treeViewer = createTreeViewer(composite); + + // Load the saved property + selectSavedItem(); + + return composite; + } + + protected TreeViewer createTreeViewer(Composite parent) { + TreeViewer tree; + + filteredTree = new DomainFilteredTree(parent, SWT.FILL, new PatternFilter()); + filteredTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); +// horizontalIndent = 7; + filteredTree.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + + tree = filteredTree.getViewer(); + + setContentAndLabelProviders(tree); + tree.setInput(IProjectDomains.PROJECT_DOMAINS); + + tree.addSelectionChangedListener(new ISelectionChangedListener() { + + public void selectionChanged(SelectionChangedEvent event) { + handleTreeSelectionChanged(event); + } + + }); + + //super.addListeners(tree); + return tree; + } + + protected DomainEntry getSingleSelection(ISelection selection) + { + if (!selection.isEmpty()) { + IStructuredSelection structured = (IStructuredSelection)selection; + if ((structured.getFirstElement() instanceof DomainEntry)) { + return (DomainEntry)structured.getFirstElement(); + } + } + return null; + } + + protected void handleTreeSelectionChanged(SelectionChangedEvent event) { + DomainEntry de = getSingleSelection(event.getSelection()); + updateDomainLabel(de); + } + + protected void performDefaults() { + super.performDefaults(); + // Populate the owner text field with the default value +// ownerText.setText(DEFAULT_OWNER); + } + + public boolean performOk() { + // Store the value in properties + try { + DomainEntry de = (DomainEntry) domainLabel.getData(); + if(de != null) { + ((IResource) getElement()).setPersistentProperty(new QualifiedName("", DOMAIN_PROPERTY), Integer.toString(de.getId())); + } + } catch (CoreException e) { + return false; + } + return true; + } + + /** + * @param selection + */ + private void updateDomainLabel(DomainEntry domain) { + if(domain == null) + return; + + DomainEntry parent = domain.getParent(); + + if(parent != null) { + String text = parent.getName() + "/" + domain.getName(); + + // Escape text for SWT + domainLabel.setText(text.replaceAll("&", "&&")); //$NON-NLS-1$ //$NON-NLS-2$ + domainLabel.setData(domain); + } + } + + @Override + public void createControl(Composite parent) { + super.createControl(parent); +// createContents(parent); + setControl(parent); + } + + @Override + public boolean canFlipToNextPage() { + return isPageComplete() && getNextPage() != null; + } + + @Override + public String getName() { + return name; + } + + @Override + public IWizardPage getNextPage() { + if (wizard == null) { + return null; + } + return wizard.getNextPage(this); + } + + @Override + public IWizardPage getPreviousPage() { + if (previousPage != null) { + return previousPage; + } + + if (wizard == null) { + return null; + } + + return wizard.getPreviousPage(this); + } + + @Override + public IWizard getWizard() { + return wizard; + } + + @Override + public boolean isPageComplete() { + return isPageComplete; + } + + @Override + public void setPreviousPage(IWizardPage page) { + previousPage = page; + } + + /** + * Returns whether this page is the current one in the wizard's container. + * + * @return true if the page is active, + * and false otherwise + */ + protected boolean isCurrentPage() { + return (getContainer() != null + && getContainer() == wizard.getContainer() + && this == wizard.getContainer().getCurrentPage()); + } + + + /** + * The WizardPage implementation of this method + * declared on DialogPage updates the container + * if this is the current page. + */ + @Override + public void setMessage(String newMessage, int newType) { + super.setMessage(newMessage, newType); + if (isCurrentPage()) { // TODO + getContainer().updateMessage(); + } + } + + /** + * The WizardPage implementation of this IDialogPage + * method extends the DialogPage implementation to update + * the wizard container title bar. Subclasses may extend. + */ + @Override + public void setDescription(String description) { + super.setDescription(description); + if (wizard != null) { + wizard.getContainer().updateTitleBar(); + } + } + + @Override + public void setWizard(IWizard newWizard) { + wizard = newWizard; + } + } \ No newline at end of file diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/ProjectFoldersPreferencePage.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/ProjectFoldersPreferencePage.java index 858abe2..782020d 100644 --- a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/ProjectFoldersPreferencePage.java +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/ProjectFoldersPreferencePage.java @@ -1,421 +1,421 @@ -package eu.scasefp7.eclipse.core.ui.preferences; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.swt.SWT; -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.Text; -import org.eclipse.ui.dialogs.ContainerSelectionDialog; -import org.eclipse.ui.dialogs.ISelectionValidator; -import org.eclipse.ui.dialogs.PropertyPage; - -import eu.scasefp7.eclipse.core.ui.Activator; -import eu.scasefp7.eclipse.core.ui.ScaseUiConstants; - -/** - * Property page to configure project folders (output, models, requirements, compositions). - * - * @author Leonora Gaspar - * - */ -public class ProjectFoldersPreferencePage extends PropertyPage { - String modelsPath = ""; - String outputPath = ""; - String reqPath = ""; - String comPath = ""; - - Text models; - Text output; - Text requirements; - Text compositions; - - @Override - protected Control createContents(Composite parent) { - IProject project = null; - IAdaptable element = getElement(); - if (element instanceof IProject) { - project = (IProject) element; - } else { - Object resource = element.getAdapter(IResource.class); - if (resource instanceof IProject) { - project = (IProject) resource; - } else { - Activator.log("Unable to read project properties.", null); //$NON-NLS-1$ - } - } - try { - modelsPath = project.getPersistentProperty(new QualifiedName("", ScaseUiConstants.MODELS_FOLDER)); //$NON-NLS-1$ - outputPath = project.getPersistentProperty(new QualifiedName("", ScaseUiConstants.OUTPUT_FOLDER)); //$NON-NLS-1$ - reqPath = project.getPersistentProperty(new QualifiedName("", ScaseUiConstants.REQUIREMENTS_FOLDER)); //$NON-NLS-1$ - comPath = project.getPersistentProperty(new QualifiedName("", ScaseUiConstants.COMPOSITIONS_FOLDER)); //$NON-NLS-1$ - } catch (CoreException exc) { - Activator.log("Unable to read project properties.", exc); //$NON-NLS-1$ - } - try { - if (modelsPath == null) { - modelsPath = project.getFolder("models").exists() ? "models" : ""; - project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.MODELS_FOLDER), modelsPath); - } - if (outputPath == null) { - outputPath = project.getFolder("output").exists() ? "output" : ""; - project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.OUTPUT_FOLDER), outputPath); - } - if (reqPath == null) { - reqPath = project.getFolder("requirements").exists() ? "requirements" : ""; - project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.REQUIREMENTS_FOLDER), reqPath); - } - if (comPath == null) { - comPath = project.getFolder("compositions").exists() ? "compositions" : ""; - project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.COMPOSITIONS_FOLDER), comPath); - } - } catch (CoreException e4) { - e4.printStackTrace(); - } - - initializeDialogUnits(parent); - - final Composite composite = new Composite(parent, SWT.NULL); - composite.setFont(parent.getFont()); - GridLayout layout = new GridLayout(); - layout.numColumns = 3; - composite.setLayout(layout); - composite.setLayoutData(new GridData(SWT.BEGINNING)); - - Label a = new Label(composite, SWT.NULL); - a.setText("The models are stored in folder:"); - GridData gridData1 = new GridData(); - gridData1.horizontalAlignment = GridData.FILL; - gridData1.horizontalSpan = 3; - a.setLayoutData(gridData1); - - Label label = new Label(composite, SWT.NULL); - models = new Text(composite, SWT.BORDER); - GridData gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.grabExcessHorizontalSpace = true; - - final Button button = new Button(composite, SWT.PUSH); - - label.setText("Models folder path: "); - models.setText(modelsPath); - models.setEnabled(false); - button.setText("Browse..."); - models.setLayoutData(gridData); - - IContainer root = ResourcesPlugin.getWorkspace().getRoot(); - final IProject currentProject = project; - ISelectionValidator validator = new ISelectionValidator() { - @Override - public String isValid(Object selection) { - try { - IFolder folder = root.getFolder((IPath) selection); - if (!folder.getProject().equals(currentProject)) - return "You must select a folder inside your project"; - } catch (IllegalArgumentException e) { - if (!currentProject.getFullPath().equals(selection)) - return "You must select a folder inside your project"; - } - return null; - } - }; - button.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event e) { - Path resPath; - switch (e.type) { - case SWT.Selection: - - ContainerSelectionDialog dlg; - if (modelsPath.equals("")) - dlg = new ContainerSelectionDialog(parent.getShell(), currentProject, false, null); - else - dlg = new ContainerSelectionDialog(parent.getShell(), currentProject.getFolder(new Path( - modelsPath)), false, null); - dlg.setValidator(validator); - dlg.setMessage("Select a folder"); - dlg.open(); - Object[] res = dlg.getResult(); - if (res != null) { - resPath = (Path) res[0]; - String resPathString = ""; - for (int i = 1; i < resPath.segmentCount(); i++) { - resPathString += resPath.segment(i) + "/"; - } - if (resPathString.length() > 0) - resPathString = resPathString.substring(0, resPathString.length() - 1); - models.setText(resPathString); - modelsPath = resPathString; - } - - break; - } - } - - }); - - // Empty row - Label e1 = new Label(composite, SWT.NULL); - GridData gridData11 = new GridData(); - gridData11.horizontalAlignment = GridData.FILL; - gridData11.horizontalSpan = 3; - e1.setLayoutData(gridData11); - - Label a2 = new Label(composite, SWT.NULL); - a2.setText("The generated code is stored in folder:"); - GridData gridData2 = new GridData(); - gridData2.horizontalAlignment = GridData.FILL; - gridData2.horizontalSpan = 3; - a2.setLayoutData(gridData2); - - GridData gridData3 = new GridData(); - gridData3.horizontalAlignment = SWT.FILL; - gridData3.grabExcessHorizontalSpace = true; - Label label2 = new Label(composite, SWT.NULL); - output = new Text(composite, SWT.BORDER); - final Button button2 = new Button(composite, SWT.PUSH); - - label2.setText("Output folder path: "); - output.setText(outputPath); - output.setEnabled(false); - button2.setText("Browse..."); - output.setLayoutData(gridData3); - - button2.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event e) { - Path resPath; - switch (e.type) { - case SWT.Selection: - - ContainerSelectionDialog dlg; - if (outputPath.equals("")) - dlg = new ContainerSelectionDialog(parent.getShell(), currentProject, false, null); - else - dlg = new ContainerSelectionDialog(parent.getShell(), currentProject.getFolder(new Path( - outputPath)), false, null); - dlg.setValidator(validator); - dlg.setMessage("Select a folder"); - dlg.open(); - Object[] res = dlg.getResult(); - if (res != null) { - resPath = (Path) res[0]; - String resPathString = ""; - for (int i = 1; i < resPath.segmentCount(); i++) { - resPathString += resPath.segment(i) + "/"; - } - if (resPathString.length() > 0) - resPathString = resPathString.substring(0, resPathString.length() - 1); - output.setText(resPathString); - outputPath = resPathString; - } - break; - } - } - - }); - - // Empty row - Label e2 = new Label(composite, SWT.NULL); - GridData gridData21 = new GridData(); - gridData21.horizontalAlignment = GridData.FILL; - gridData21.horizontalSpan = 3; - e2.setLayoutData(gridData21); - - Label a3 = new Label(composite, SWT.NULL); - a3.setText("The requirements are stored in folder:"); - - GridData gridData31 = new GridData(); - gridData31.horizontalAlignment = GridData.FILL; - gridData31.horizontalSpan = 3; - a3.setLayoutData(gridData31); - - GridData gridData4 = new GridData(); - gridData4.horizontalAlignment = SWT.FILL; - gridData4.grabExcessHorizontalSpace = true; - Label label3 = new Label(composite, SWT.NULL); - requirements = new Text(composite, SWT.BORDER); - final Button button3 = new Button(composite, SWT.PUSH); - - label3.setText("Requirements folder path: "); - requirements.setText(reqPath); - requirements.setEnabled(false); - button3.setText("Browse..."); - requirements.setLayoutData(gridData4); - - button3.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event e) { - Path resPath; - switch (e.type) { - case SWT.Selection: - - ContainerSelectionDialog dlg; - if (reqPath.equals("")) - dlg = new ContainerSelectionDialog(parent.getShell(), currentProject, false, null); - else - dlg = new ContainerSelectionDialog(parent.getShell(), currentProject - .getFolder(new Path(reqPath)), false, null); - dlg.setValidator(validator); - dlg.setMessage("Select a folder"); - dlg.open(); - Object[] res = dlg.getResult(); - if (res != null) { - resPath = (Path) res[0]; - String resPathString = ""; - for (int i = 1; i < resPath.segmentCount(); i++) { - resPathString += resPath.segment(i) + "/"; - } - if (resPathString.length() > 0) - resPathString = resPathString.substring(0, resPathString.length() - 1); - requirements.setText(resPathString); - reqPath = resPathString; - } - - break; - } - } - - }); - - // Empty row - Label e3 = new Label(composite, SWT.NULL); - GridData gridData32 = new GridData(); - gridData32.horizontalAlignment = GridData.FILL; - gridData32.horizontalSpan = 3; - e3.setLayoutData(gridData32); - - Label a4 = new Label(composite, SWT.NULL); - a4.setText("The storyboards used for composition are in folder:"); - GridData gridData41 = new GridData(); - gridData41.horizontalAlignment = GridData.FILL; - gridData41.horizontalSpan = 3; - a4.setLayoutData(gridData41); - - Label label4 = new Label(composite, SWT.NULL); - compositions = new Text(composite, SWT.BORDER); - final Button button4 = new Button(composite, SWT.PUSH); - - GridData gridData6 = new GridData(); - gridData6.horizontalAlignment = SWT.FILL; - gridData6.grabExcessHorizontalSpace = true; - - label4.setText("Compositions folder path: "); - compositions.setText(comPath); - compositions.setEnabled(false); - button4.setText("Browse..."); - compositions.setLayoutData(gridData6); - - button4.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event e) { - Path resPath; - switch (e.type) { - case SWT.Selection: - - ContainerSelectionDialog dlg; - if (comPath.equals("")) - dlg = new ContainerSelectionDialog(parent.getShell(), currentProject, false, null); - else - dlg = new ContainerSelectionDialog(parent.getShell(), currentProject - .getFolder(new Path(comPath)), false, null); - dlg.setValidator(validator); - dlg.setMessage("Select a folder"); - dlg.open(); - Object[] res = dlg.getResult(); - if (res != null) { - resPath = (Path) res[0]; - String resPathString = ""; - for (int i = 1; i < resPath.segmentCount(); i++) { - resPathString += resPath.segment(i) + "/"; - } - if (resPathString.length() > 0) - resPathString = resPathString.substring(0, resPathString.length() - 1); - compositions.setText(resPathString); - comPath = resPathString; - } - - break; - } - } - - }); - - // setControl(composite); - return composite; - } - - @Override - public boolean performOk() { - IProject project = null; - IAdaptable element = getElement(); - if (element instanceof IProject) { - project = (IProject) element; - } else { - Object resource = element.getAdapter(IResource.class); - if (resource instanceof IProject) { - project = (IProject) resource; - } else { - Activator.log("Unable to set project properties.", null); //$NON-NLS-1$ - } - } - try { - project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.MODELS_FOLDER), modelsPath); - project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.OUTPUT_FOLDER), outputPath); - project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.REQUIREMENTS_FOLDER), reqPath); - project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.COMPOSITIONS_FOLDER), comPath); - - } catch (CoreException e) { - Activator.log("Unable to set project properties.", e); - } - - return super.performOk(); - } - - @Override - protected void performDefaults() { - IProject project = null; - IAdaptable element = getElement(); - if (element instanceof IProject) { - project = (IProject) element; - } else { - Object resource = element.getAdapter(IResource.class); - if (resource instanceof IProject) { - project = (IProject) resource; - } else { - Activator.log("Unable to set project properties.", null); //$NON-NLS-1$ - } - } - try { - modelsPath = project.getFolder("models").exists() ? "models" : ""; - outputPath = project.getFolder("output").exists() ? "output" : ""; - reqPath = project.getFolder("requirements").exists() ? "requirements" : ""; - comPath = project.getFolder("compositions").exists() ? "compositions" : ""; - project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.MODELS_FOLDER), modelsPath); - project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.OUTPUT_FOLDER), outputPath); - project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.REQUIREMENTS_FOLDER), reqPath); - project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.COMPOSITIONS_FOLDER), comPath); - models.setText(modelsPath); - output.setText(outputPath); - requirements.setText(reqPath); - compositions.setText(comPath); - } catch (CoreException e) { - Activator.log("Unable to set project properties.", null); //$NON-NLS-1$ - } - super.performDefaults(); - } -} +package eu.scasefp7.eclipse.core.ui.preferences; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.swt.SWT; +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.Text; +import org.eclipse.ui.dialogs.ContainerSelectionDialog; +import org.eclipse.ui.dialogs.ISelectionValidator; +import org.eclipse.ui.dialogs.PropertyPage; + +import eu.scasefp7.eclipse.core.ui.Activator; +import eu.scasefp7.eclipse.core.ui.ScaseUiConstants; + +/** + * Property page to configure project folders (output, models, requirements, compositions). + * + * @author Leonora Gaspar + * + */ +public class ProjectFoldersPreferencePage extends PropertyPage { + String modelsPath = ""; + String outputPath = ""; + String reqPath = ""; + String comPath = ""; + + Text models; + Text output; + Text requirements; + Text compositions; + + @Override + protected Control createContents(Composite parent) { + IProject project = null; + IAdaptable element = getElement(); + if (element instanceof IProject) { + project = (IProject) element; + } else { + Object resource = element.getAdapter(IResource.class); + if (resource instanceof IProject) { + project = (IProject) resource; + } else { + Activator.log("Unable to read project properties.", null); //$NON-NLS-1$ + } + } + try { + modelsPath = project.getPersistentProperty(new QualifiedName("", ScaseUiConstants.MODELS_FOLDER)); //$NON-NLS-1$ + outputPath = project.getPersistentProperty(new QualifiedName("", ScaseUiConstants.OUTPUT_FOLDER)); //$NON-NLS-1$ + reqPath = project.getPersistentProperty(new QualifiedName("", ScaseUiConstants.REQUIREMENTS_FOLDER)); //$NON-NLS-1$ + comPath = project.getPersistentProperty(new QualifiedName("", ScaseUiConstants.COMPOSITIONS_FOLDER)); //$NON-NLS-1$ + } catch (CoreException exc) { + Activator.log("Unable to read project properties.", exc); //$NON-NLS-1$ + } + try { + if (modelsPath == null) { + modelsPath = project.getFolder("models").exists() ? "models" : ""; + project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.MODELS_FOLDER), modelsPath); + } + if (outputPath == null) { + outputPath = project.getFolder("output").exists() ? "output" : ""; + project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.OUTPUT_FOLDER), outputPath); + } + if (reqPath == null) { + reqPath = project.getFolder("requirements").exists() ? "requirements" : ""; + project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.REQUIREMENTS_FOLDER), reqPath); + } + if (comPath == null) { + comPath = project.getFolder("compositions").exists() ? "compositions" : ""; + project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.COMPOSITIONS_FOLDER), comPath); + } + } catch (CoreException e4) { + e4.printStackTrace(); + } + + initializeDialogUnits(parent); + + final Composite composite = new Composite(parent, SWT.NULL); + composite.setFont(parent.getFont()); + GridLayout layout = new GridLayout(); + layout.numColumns = 3; + composite.setLayout(layout); + composite.setLayoutData(new GridData(SWT.BEGINNING)); + + Label a = new Label(composite, SWT.NULL); + a.setText("The models are stored in folder:"); + GridData gridData1 = new GridData(); + gridData1.horizontalAlignment = GridData.FILL; + gridData1.horizontalSpan = 3; + a.setLayoutData(gridData1); + + Label label = new Label(composite, SWT.NULL); + models = new Text(composite, SWT.BORDER); + GridData gridData = new GridData(); + gridData.horizontalAlignment = SWT.FILL; + gridData.grabExcessHorizontalSpace = true; + + final Button button = new Button(composite, SWT.PUSH); + + label.setText("Models folder path: "); + models.setText(modelsPath); + models.setEnabled(false); + button.setText("Browse..."); + models.setLayoutData(gridData); + + IContainer root = ResourcesPlugin.getWorkspace().getRoot(); + final IProject currentProject = project; + ISelectionValidator validator = new ISelectionValidator() { + @Override + public String isValid(Object selection) { + try { + IFolder folder = root.getFolder((IPath) selection); + if (!folder.getProject().equals(currentProject)) + return "You must select a folder inside your project"; + } catch (IllegalArgumentException e) { + if (!currentProject.getFullPath().equals(selection)) + return "You must select a folder inside your project"; + } + return null; + } + }; + button.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event e) { + Path resPath; + switch (e.type) { + case SWT.Selection: + + ContainerSelectionDialog dlg; + if (modelsPath.equals("")) + dlg = new ContainerSelectionDialog(parent.getShell(), currentProject, false, null); + else + dlg = new ContainerSelectionDialog(parent.getShell(), currentProject.getFolder(new Path( + modelsPath)), false, null); + dlg.setValidator(validator); + dlg.setMessage("Select a folder"); + dlg.open(); + Object[] res = dlg.getResult(); + if (res != null) { + resPath = (Path) res[0]; + String resPathString = ""; + for (int i = 1; i < resPath.segmentCount(); i++) { + resPathString += resPath.segment(i) + "/"; + } + if (resPathString.length() > 0) + resPathString = resPathString.substring(0, resPathString.length() - 1); + models.setText(resPathString); + modelsPath = resPathString; + } + + break; + } + } + + }); + + // Empty row + Label e1 = new Label(composite, SWT.NULL); + GridData gridData11 = new GridData(); + gridData11.horizontalAlignment = GridData.FILL; + gridData11.horizontalSpan = 3; + e1.setLayoutData(gridData11); + + Label a2 = new Label(composite, SWT.NULL); + a2.setText("The generated code is stored in folder:"); + GridData gridData2 = new GridData(); + gridData2.horizontalAlignment = GridData.FILL; + gridData2.horizontalSpan = 3; + a2.setLayoutData(gridData2); + + GridData gridData3 = new GridData(); + gridData3.horizontalAlignment = SWT.FILL; + gridData3.grabExcessHorizontalSpace = true; + Label label2 = new Label(composite, SWT.NULL); + output = new Text(composite, SWT.BORDER); + final Button button2 = new Button(composite, SWT.PUSH); + + label2.setText("Output folder path: "); + output.setText(outputPath); + output.setEnabled(false); + button2.setText("Browse..."); + output.setLayoutData(gridData3); + + button2.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event e) { + Path resPath; + switch (e.type) { + case SWT.Selection: + + ContainerSelectionDialog dlg; + if (outputPath.equals("")) + dlg = new ContainerSelectionDialog(parent.getShell(), currentProject, false, null); + else + dlg = new ContainerSelectionDialog(parent.getShell(), currentProject.getFolder(new Path( + outputPath)), false, null); + dlg.setValidator(validator); + dlg.setMessage("Select a folder"); + dlg.open(); + Object[] res = dlg.getResult(); + if (res != null) { + resPath = (Path) res[0]; + String resPathString = ""; + for (int i = 1; i < resPath.segmentCount(); i++) { + resPathString += resPath.segment(i) + "/"; + } + if (resPathString.length() > 0) + resPathString = resPathString.substring(0, resPathString.length() - 1); + output.setText(resPathString); + outputPath = resPathString; + } + break; + } + } + + }); + + // Empty row + Label e2 = new Label(composite, SWT.NULL); + GridData gridData21 = new GridData(); + gridData21.horizontalAlignment = GridData.FILL; + gridData21.horizontalSpan = 3; + e2.setLayoutData(gridData21); + + Label a3 = new Label(composite, SWT.NULL); + a3.setText("The requirements are stored in folder:"); + + GridData gridData31 = new GridData(); + gridData31.horizontalAlignment = GridData.FILL; + gridData31.horizontalSpan = 3; + a3.setLayoutData(gridData31); + + GridData gridData4 = new GridData(); + gridData4.horizontalAlignment = SWT.FILL; + gridData4.grabExcessHorizontalSpace = true; + Label label3 = new Label(composite, SWT.NULL); + requirements = new Text(composite, SWT.BORDER); + final Button button3 = new Button(composite, SWT.PUSH); + + label3.setText("Requirements folder path: "); + requirements.setText(reqPath); + requirements.setEnabled(false); + button3.setText("Browse..."); + requirements.setLayoutData(gridData4); + + button3.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event e) { + Path resPath; + switch (e.type) { + case SWT.Selection: + + ContainerSelectionDialog dlg; + if (reqPath.equals("")) + dlg = new ContainerSelectionDialog(parent.getShell(), currentProject, false, null); + else + dlg = new ContainerSelectionDialog(parent.getShell(), currentProject + .getFolder(new Path(reqPath)), false, null); + dlg.setValidator(validator); + dlg.setMessage("Select a folder"); + dlg.open(); + Object[] res = dlg.getResult(); + if (res != null) { + resPath = (Path) res[0]; + String resPathString = ""; + for (int i = 1; i < resPath.segmentCount(); i++) { + resPathString += resPath.segment(i) + "/"; + } + if (resPathString.length() > 0) + resPathString = resPathString.substring(0, resPathString.length() - 1); + requirements.setText(resPathString); + reqPath = resPathString; + } + + break; + } + } + + }); + + // Empty row + Label e3 = new Label(composite, SWT.NULL); + GridData gridData32 = new GridData(); + gridData32.horizontalAlignment = GridData.FILL; + gridData32.horizontalSpan = 3; + e3.setLayoutData(gridData32); + + Label a4 = new Label(composite, SWT.NULL); + a4.setText("The storyboards used for composition are in folder:"); + GridData gridData41 = new GridData(); + gridData41.horizontalAlignment = GridData.FILL; + gridData41.horizontalSpan = 3; + a4.setLayoutData(gridData41); + + Label label4 = new Label(composite, SWT.NULL); + compositions = new Text(composite, SWT.BORDER); + final Button button4 = new Button(composite, SWT.PUSH); + + GridData gridData6 = new GridData(); + gridData6.horizontalAlignment = SWT.FILL; + gridData6.grabExcessHorizontalSpace = true; + + label4.setText("Compositions folder path: "); + compositions.setText(comPath); + compositions.setEnabled(false); + button4.setText("Browse..."); + compositions.setLayoutData(gridData6); + + button4.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event e) { + Path resPath; + switch (e.type) { + case SWT.Selection: + + ContainerSelectionDialog dlg; + if (comPath.equals("")) + dlg = new ContainerSelectionDialog(parent.getShell(), currentProject, false, null); + else + dlg = new ContainerSelectionDialog(parent.getShell(), currentProject + .getFolder(new Path(comPath)), false, null); + dlg.setValidator(validator); + dlg.setMessage("Select a folder"); + dlg.open(); + Object[] res = dlg.getResult(); + if (res != null) { + resPath = (Path) res[0]; + String resPathString = ""; + for (int i = 1; i < resPath.segmentCount(); i++) { + resPathString += resPath.segment(i) + "/"; + } + if (resPathString.length() > 0) + resPathString = resPathString.substring(0, resPathString.length() - 1); + compositions.setText(resPathString); + comPath = resPathString; + } + + break; + } + } + + }); + + // setControl(composite); + return composite; + } + + @Override + public boolean performOk() { + IProject project = null; + IAdaptable element = getElement(); + if (element instanceof IProject) { + project = (IProject) element; + } else { + Object resource = element.getAdapter(IResource.class); + if (resource instanceof IProject) { + project = (IProject) resource; + } else { + Activator.log("Unable to set project properties.", null); //$NON-NLS-1$ + } + } + try { + project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.MODELS_FOLDER), modelsPath); + project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.OUTPUT_FOLDER), outputPath); + project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.REQUIREMENTS_FOLDER), reqPath); + project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.COMPOSITIONS_FOLDER), comPath); + + } catch (CoreException e) { + Activator.log("Unable to set project properties.", e); + } + + return super.performOk(); + } + + @Override + protected void performDefaults() { + IProject project = null; + IAdaptable element = getElement(); + if (element instanceof IProject) { + project = (IProject) element; + } else { + Object resource = element.getAdapter(IResource.class); + if (resource instanceof IProject) { + project = (IProject) resource; + } else { + Activator.log("Unable to set project properties.", null); //$NON-NLS-1$ + } + } + try { + modelsPath = project.getFolder("models").exists() ? "models" : ""; + outputPath = project.getFolder("output").exists() ? "output" : ""; + reqPath = project.getFolder("requirements").exists() ? "requirements" : ""; + comPath = project.getFolder("compositions").exists() ? "compositions" : ""; + project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.MODELS_FOLDER), modelsPath); + project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.OUTPUT_FOLDER), outputPath); + project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.REQUIREMENTS_FOLDER), reqPath); + project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.COMPOSITIONS_FOLDER), comPath); + models.setText(modelsPath); + output.setText(outputPath); + requirements.setText(reqPath); + compositions.setText(comPath); + } catch (CoreException e) { + Activator.log("Unable to set project properties.", null); //$NON-NLS-1$ + } + super.performDefaults(); + } +} diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/PropertyWizardPage.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/PropertyWizardPage.java index 23a1cbf..8cef9f9 100644 --- a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/PropertyWizardPage.java +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/PropertyWizardPage.java @@ -1,62 +1,88 @@ -package eu.scasefp7.eclipse.core.ui.preferences; - - -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; - - -/** - * @author emaorli - * - */ -public class PropertyWizardPage extends WizardPage { - ProjectDomainPropertyPage propPage; - Composite composite; - private static final int DOMAIN_DEFAULT = -1; - - - /** - * @param pageName - */ - public PropertyWizardPage(String pageName) { - super(pageName); - propPage = new ProjectDomainPropertyPage(); - } - - -@Override - public void createControl(Composite parent) { - composite = new Composite(parent, SWT.NONE); - GridLayout gl_composite = new GridLayout(); - gl_composite.marginWidth = 0; - gl_composite.marginHeight = 0; - composite.setLayout(gl_composite); - GridData data = new GridData(GridData.FILL); - data.grabExcessHorizontalSpace = true; - composite.setLayoutData(data); - - int domainId = DOMAIN_DEFAULT; - - // Add the domain label - propPage.createDomainLabel(composite, (domainId != DOMAIN_DEFAULT) ? domainId : null); - - // Add tree - propPage.createTreeViewer(composite); - - setControl(composite); - } - - - /** - * @return - */ - public Label getDomainLabel(){ - return propPage.getDomainLabel(); - } - - -} \ No newline at end of file +package eu.scasefp7.eclipse.core.ui.preferences; + + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +import eu.scasefp7.eclipse.core.ui.ScaseUiConstants; +import eu.scasefp7.eclipse.core.ui.preferences.internal.DomainEntry; +import eu.scasefp7.eclipse.core.ui.wizards.IScaseWizardPage; + + +/** + * @author emaorli + * + */ +public class PropertyWizardPage extends WizardPage implements IScaseWizardPage { + ProjectDomainPropertyPage propPage; + Composite composite; + private static final int DOMAIN_DEFAULT = -1; + + + /** + * @param pageName + */ + public PropertyWizardPage(String pageName) { + super(pageName); + propPage = new ProjectDomainPropertyPage(); + } + + +@Override + public void createControl(Composite parent) { + composite = new Composite(parent, SWT.NONE); + GridLayout gl_composite = new GridLayout(); + gl_composite.marginWidth = 0; + gl_composite.marginHeight = 0; + composite.setLayout(gl_composite); + GridData data = new GridData(GridData.FILL); + data.grabExcessHorizontalSpace = true; + composite.setLayoutData(data); + + int domainId = DOMAIN_DEFAULT; + + // Add the domain label + propPage.createDomainLabel(composite, (domainId != DOMAIN_DEFAULT) ? domainId : null); + + // Add tree + propPage.createTreeViewer(composite); + + setControl(composite); + } + + + /** + * @return + */ + public Label getDomainLabel(){ + return propPage.getDomainLabel(); + } + + + @Override + public boolean performFinish(IResource resource) { + int k; + Label domainLabel = propPage.getDomainLabel(); + DomainEntry de = (DomainEntry) domainLabel.getData(); + if (de == null) + k = -1; + else + k = de.getId(); + try { + resource.setPersistentProperty(new QualifiedName("", ScaseUiConstants.PROP_PROJECT_DOMAIN), Integer.toString(k)); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return true; + } + + +} diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/ScaseProjectPropertySection.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/ScaseProjectPropertySection.java index 6361d25..117d2f5 100644 --- a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/ScaseProjectPropertySection.java +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/preferences/ScaseProjectPropertySection.java @@ -1,36 +1,36 @@ -package eu.scasefp7.eclipse.core.ui.preferences; - -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.views.properties.tabbed.AdvancedPropertySection; - -import eu.scasefp7.eclipse.core.builder.ProjectUtils; - -/** - * Provides the project property section in tabbed properties view. - * - * @author Leonora Gaspar - */ -public class ScaseProjectPropertySection extends AdvancedPropertySection { - @Override - public void setInput(IWorkbenchPart part, ISelection selection) { - - if (selection instanceof IStructuredSelection) { - @SuppressWarnings("unchecked") - List list = ((StructuredSelection)selection).toList(); - IProject project = ProjectUtils.getProjectOfSelectionList(list); - - if(project != null) { - ISelection newSelection = new StructuredSelection(new ProjectResourcePropertySource(project)); - super.setInput(part, newSelection); - } else { - super.setInput(part, selection); - } - } - } +package eu.scasefp7.eclipse.core.ui.preferences; + +import java.util.List; + +import org.eclipse.core.resources.IProject; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.views.properties.tabbed.AdvancedPropertySection; + +import eu.scasefp7.eclipse.core.builder.ProjectUtils; + +/** + * Provides the project property section in tabbed properties view. + * + * @author Leonora Gaspar + */ +public class ScaseProjectPropertySection extends AdvancedPropertySection { + @Override + public void setInput(IWorkbenchPart part, ISelection selection) { + + if (selection instanceof IStructuredSelection) { + @SuppressWarnings("unchecked") + List list = ((StructuredSelection)selection).toList(); + IProject project = ProjectUtils.getProjectOfSelectionList(list); + + if(project != null) { + ISelection newSelection = new StructuredSelection(new ProjectResourcePropertySource(project)); + super.setInput(part, newSelection); + } else { + super.setInput(part, selection); + } + } + } } \ No newline at end of file diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/sourceprovider/CompositionsFolderActive.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/sourceprovider/CompositionsFolderActive.java index 246ff92..4a04b26 100644 --- a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/sourceprovider/CompositionsFolderActive.java +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/sourceprovider/CompositionsFolderActive.java @@ -1,112 +1,112 @@ -package eu.scasefp7.eclipse.core.ui.sourceprovider; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.TreeSelection; -import org.eclipse.ui.AbstractSourceProvider; -import org.eclipse.ui.ISelectionListener; -import org.eclipse.ui.ISources; -import org.eclipse.ui.IWindowListener; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.services.IServiceLocator; - -import eu.scasefp7.eclipse.core.ui.Activator; -import eu.scasefp7.eclipse.core.ui.ScaseUiConstants; - -/** - * Resolves the compositions folder for the currently selected project. - * - * @author Leonora Gaspar - */ -public class CompositionsFolderActive extends AbstractSourceProvider implements ISelectionListener, IWindowListener { - - private final static String MY_STATE = ScaseUiConstants.COMPOSITIONS_FOLDER_SOURCE; - private boolean enabled = true; - - /** - * Constructs the source provider. - */ - public CompositionsFolderActive() { - } - - @Override - public void initialize(IServiceLocator locator) { - super.initialize(locator); - PlatformUI.getWorkbench().addWindowListener(this); - } - - @Override - public void dispose() { - PlatformUI.getWorkbench().removeWindowListener(this); - - } - - @Override - public Map getCurrentState() { - Map map = new HashMap(1); - map.put(MY_STATE, enabled); - return map; - } - - @Override - public String[] getProvidedSourceNames() { - return new String[] { MY_STATE }; - } - - - @Override - public void selectionChanged(IWorkbenchPart part, ISelection selection) { - if(!(selection instanceof TreeSelection)) - return; - TreeSelection treeSelection = (TreeSelection)selection; - Object element = treeSelection.getFirstElement(); - if(element != null && element instanceof IFolder) { - IFolder folder = (IFolder)element; - IProject project = folder.getProject(); - String compositionsPath = ""; - try { - compositionsPath = project.getPersistentProperty(new QualifiedName("",ScaseUiConstants.COMPOSITIONS_FOLDER)); - } catch (CoreException e) { - Activator.log("Unable to read compositions folder path", e); - } - - if(folder.getFullPath().toPortableString().equals(compositionsPath)) - enabled = Boolean.FALSE; - else - enabled = Boolean.TRUE; - } - else - enabled = Boolean.TRUE; - - fireSourceChanged(ISources.WORKBENCH, MY_STATE, enabled); - - } - - @Override - public void windowActivated(IWorkbenchWindow window) { - window.getSelectionService().addSelectionListener(this); - } - - @Override - public void windowDeactivated(IWorkbenchWindow window) { - window.getSelectionService().removeSelectionListener(this); - } - - @Override - public void windowClosed(IWorkbenchWindow window) { - // Nothing to do - } - - @Override - public void windowOpened(IWorkbenchWindow window) { - // Nothing to do - } +package eu.scasefp7.eclipse.core.ui.sourceprovider; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.TreeSelection; +import org.eclipse.ui.AbstractSourceProvider; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.ISources; +import org.eclipse.ui.IWindowListener; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.services.IServiceLocator; + +import eu.scasefp7.eclipse.core.ui.Activator; +import eu.scasefp7.eclipse.core.ui.ScaseUiConstants; + +/** + * Resolves the compositions folder for the currently selected project. + * + * @author Leonora Gaspar + */ +public class CompositionsFolderActive extends AbstractSourceProvider implements ISelectionListener, IWindowListener { + + private final static String MY_STATE = ScaseUiConstants.COMPOSITIONS_FOLDER_SOURCE; + private boolean enabled = true; + + /** + * Constructs the source provider. + */ + public CompositionsFolderActive() { + } + + @Override + public void initialize(IServiceLocator locator) { + super.initialize(locator); + PlatformUI.getWorkbench().addWindowListener(this); + } + + @Override + public void dispose() { + PlatformUI.getWorkbench().removeWindowListener(this); + + } + + @Override + public Map getCurrentState() { + Map map = new HashMap(1); + map.put(MY_STATE, enabled); + return map; + } + + @Override + public String[] getProvidedSourceNames() { + return new String[] { MY_STATE }; + } + + + @Override + public void selectionChanged(IWorkbenchPart part, ISelection selection) { + if(!(selection instanceof TreeSelection)) + return; + TreeSelection treeSelection = (TreeSelection)selection; + Object element = treeSelection.getFirstElement(); + if(element != null && element instanceof IFolder) { + IFolder folder = (IFolder)element; + IProject project = folder.getProject(); + String compositionsPath = ""; + try { + compositionsPath = project.getPersistentProperty(new QualifiedName("",ScaseUiConstants.COMPOSITIONS_FOLDER)); + } catch (CoreException e) { + Activator.log("Unable to read compositions folder path", e); + } + + if(folder.getFullPath().toPortableString().equals(compositionsPath)) + enabled = Boolean.FALSE; + else + enabled = Boolean.TRUE; + } + else + enabled = Boolean.TRUE; + + fireSourceChanged(ISources.WORKBENCH, MY_STATE, enabled); + + } + + @Override + public void windowActivated(IWorkbenchWindow window) { + window.getSelectionService().addSelectionListener(this); + } + + @Override + public void windowDeactivated(IWorkbenchWindow window) { + window.getSelectionService().removeSelectionListener(this); + } + + @Override + public void windowClosed(IWorkbenchWindow window) { + // Nothing to do + } + + @Override + public void windowOpened(IWorkbenchWindow window) { + // Nothing to do + } } \ No newline at end of file diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/sourceprovider/ModelsFolderActive.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/sourceprovider/ModelsFolderActive.java index 0395652..f828dbc 100644 --- a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/sourceprovider/ModelsFolderActive.java +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/sourceprovider/ModelsFolderActive.java @@ -1,112 +1,112 @@ -package eu.scasefp7.eclipse.core.ui.sourceprovider; - -import java.util.HashMap; -import java.util.Map; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.TreeSelection; -import org.eclipse.ui.AbstractSourceProvider; -import org.eclipse.ui.ISelectionListener; -import org.eclipse.ui.ISources; -import org.eclipse.ui.IWindowListener; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.services.IServiceLocator; - -import eu.scasefp7.eclipse.core.ui.Activator; -import eu.scasefp7.eclipse.core.ui.ScaseUiConstants; - -/** - * Resolves the models folder for the currently selected project. - * - * @author Leonora Gaspar - */ -public class ModelsFolderActive extends AbstractSourceProvider implements ISelectionListener, IWindowListener { - - private final static String MY_STATE = ScaseUiConstants.MODELS_FOLDER_SOURCE; - private boolean enabled = true; - - /** - * Constructs the source provider. - */ - public ModelsFolderActive() { - } - - @Override - public void initialize(IServiceLocator locator) { - super.initialize(locator); - PlatformUI.getWorkbench().addWindowListener(this); - } - - @Override - public void dispose() { - PlatformUI.getWorkbench().removeWindowListener(this); - - } - - @Override - public Map getCurrentState() { - Map map = new HashMap(1); - map.put(MY_STATE, enabled); - return map; - } - - @Override - public String[] getProvidedSourceNames() { - return new String[] { MY_STATE }; - } - - - @Override - public void selectionChanged(IWorkbenchPart part, ISelection selection) { - if(!(selection instanceof TreeSelection)) - return; - TreeSelection treeSelection = (TreeSelection)selection; - Object element = treeSelection.getFirstElement(); - if(element != null && element instanceof IFolder) { - IFolder folder = (IFolder)element; - IProject project = folder.getProject(); - String modelsPath = ""; - try { - modelsPath = project.getPersistentProperty(new QualifiedName("",ScaseUiConstants.MODELS_FOLDER)); - } catch (CoreException e) { - Activator.log("Unable to read models folder path", e); - } - - if(folder.getFullPath().toPortableString().equals(modelsPath)) - enabled = Boolean.FALSE; - else - enabled = Boolean.TRUE; - } - else - enabled = Boolean.TRUE; - - fireSourceChanged(ISources.WORKBENCH, MY_STATE, enabled); - - } - - @Override - public void windowActivated(IWorkbenchWindow window) { - window.getSelectionService().addSelectionListener(this); - } - - @Override - public void windowDeactivated(IWorkbenchWindow window) { - window.getSelectionService().removeSelectionListener(this); - } - - @Override - public void windowClosed(IWorkbenchWindow window) { - // Nothing to do - } - - @Override - public void windowOpened(IWorkbenchWindow window) { - // Nothing to do - } - -} +package eu.scasefp7.eclipse.core.ui.sourceprovider; + +import java.util.HashMap; +import java.util.Map; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.TreeSelection; +import org.eclipse.ui.AbstractSourceProvider; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.ISources; +import org.eclipse.ui.IWindowListener; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.services.IServiceLocator; + +import eu.scasefp7.eclipse.core.ui.Activator; +import eu.scasefp7.eclipse.core.ui.ScaseUiConstants; + +/** + * Resolves the models folder for the currently selected project. + * + * @author Leonora Gaspar + */ +public class ModelsFolderActive extends AbstractSourceProvider implements ISelectionListener, IWindowListener { + + private final static String MY_STATE = ScaseUiConstants.MODELS_FOLDER_SOURCE; + private boolean enabled = true; + + /** + * Constructs the source provider. + */ + public ModelsFolderActive() { + } + + @Override + public void initialize(IServiceLocator locator) { + super.initialize(locator); + PlatformUI.getWorkbench().addWindowListener(this); + } + + @Override + public void dispose() { + PlatformUI.getWorkbench().removeWindowListener(this); + + } + + @Override + public Map getCurrentState() { + Map map = new HashMap(1); + map.put(MY_STATE, enabled); + return map; + } + + @Override + public String[] getProvidedSourceNames() { + return new String[] { MY_STATE }; + } + + + @Override + public void selectionChanged(IWorkbenchPart part, ISelection selection) { + if(!(selection instanceof TreeSelection)) + return; + TreeSelection treeSelection = (TreeSelection)selection; + Object element = treeSelection.getFirstElement(); + if(element != null && element instanceof IFolder) { + IFolder folder = (IFolder)element; + IProject project = folder.getProject(); + String modelsPath = ""; + try { + modelsPath = project.getPersistentProperty(new QualifiedName("",ScaseUiConstants.MODELS_FOLDER)); + } catch (CoreException e) { + Activator.log("Unable to read models folder path", e); + } + + if(folder.getFullPath().toPortableString().equals(modelsPath)) + enabled = Boolean.FALSE; + else + enabled = Boolean.TRUE; + } + else + enabled = Boolean.TRUE; + + fireSourceChanged(ISources.WORKBENCH, MY_STATE, enabled); + + } + + @Override + public void windowActivated(IWorkbenchWindow window) { + window.getSelectionService().addSelectionListener(this); + } + + @Override + public void windowDeactivated(IWorkbenchWindow window) { + window.getSelectionService().removeSelectionListener(this); + } + + @Override + public void windowClosed(IWorkbenchWindow window) { + // Nothing to do + } + + @Override + public void windowOpened(IWorkbenchWindow window) { + // Nothing to do + } + +} diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/sourceprovider/OutputFolderActive.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/sourceprovider/OutputFolderActive.java index 88fde09..655581d 100644 --- a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/sourceprovider/OutputFolderActive.java +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/sourceprovider/OutputFolderActive.java @@ -1,112 +1,112 @@ -package eu.scasefp7.eclipse.core.ui.sourceprovider; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.TreeSelection; -import org.eclipse.ui.AbstractSourceProvider; -import org.eclipse.ui.ISelectionListener; -import org.eclipse.ui.ISources; -import org.eclipse.ui.IWindowListener; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.services.IServiceLocator; - -import eu.scasefp7.eclipse.core.ui.Activator; -import eu.scasefp7.eclipse.core.ui.ScaseUiConstants; - -/** - * Resolves the output folder for the currently selected project. - * - * @author Leonora Gaspar - */ -public class OutputFolderActive extends AbstractSourceProvider implements ISelectionListener, IWindowListener { - - private final static String MY_STATE = ScaseUiConstants.OUTPUT_FOLDER_SOURCE; - private boolean enabled = true; - - /** - * Constructs the source provider. - */ - public OutputFolderActive() { - } - - @Override - public void initialize(IServiceLocator locator) { - super.initialize(locator); - PlatformUI.getWorkbench().addWindowListener(this); - } - - @Override - public void dispose() { - PlatformUI.getWorkbench().removeWindowListener(this); - - } - - @Override - public Map getCurrentState() { - Map map = new HashMap(1); - map.put(MY_STATE, enabled); - return map; - } - - @Override - public String[] getProvidedSourceNames() { - return new String[] { MY_STATE }; - } - - - @Override - public void selectionChanged(IWorkbenchPart part, ISelection selection) { - if(!(selection instanceof TreeSelection)) - return; - TreeSelection treeSelection = (TreeSelection)selection; - Object element = treeSelection.getFirstElement(); - if(element != null && element instanceof IFolder) { - IFolder folder = (IFolder)element; - IProject project = folder.getProject(); - String outputPath = ""; - try { - outputPath = project.getPersistentProperty(new QualifiedName("",ScaseUiConstants.OUTPUT_FOLDER)); - } catch (CoreException e) { - Activator.log("Unable to read output folder path", e); - } - - if(folder.getFullPath().toPortableString().equals(outputPath)) - enabled = Boolean.FALSE; - else - enabled = Boolean.TRUE; - } - else - enabled = Boolean.TRUE; - - fireSourceChanged(ISources.WORKBENCH, MY_STATE, enabled); - - } - - @Override - public void windowActivated(IWorkbenchWindow window) { - window.getSelectionService().addSelectionListener(this); - } - - @Override - public void windowDeactivated(IWorkbenchWindow window) { - window.getSelectionService().removeSelectionListener(this); - } - - @Override - public void windowClosed(IWorkbenchWindow window) { - // Nothing to do - } - - @Override - public void windowOpened(IWorkbenchWindow window) { - // Nothing to do - } -} +package eu.scasefp7.eclipse.core.ui.sourceprovider; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.TreeSelection; +import org.eclipse.ui.AbstractSourceProvider; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.ISources; +import org.eclipse.ui.IWindowListener; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.services.IServiceLocator; + +import eu.scasefp7.eclipse.core.ui.Activator; +import eu.scasefp7.eclipse.core.ui.ScaseUiConstants; + +/** + * Resolves the output folder for the currently selected project. + * + * @author Leonora Gaspar + */ +public class OutputFolderActive extends AbstractSourceProvider implements ISelectionListener, IWindowListener { + + private final static String MY_STATE = ScaseUiConstants.OUTPUT_FOLDER_SOURCE; + private boolean enabled = true; + + /** + * Constructs the source provider. + */ + public OutputFolderActive() { + } + + @Override + public void initialize(IServiceLocator locator) { + super.initialize(locator); + PlatformUI.getWorkbench().addWindowListener(this); + } + + @Override + public void dispose() { + PlatformUI.getWorkbench().removeWindowListener(this); + + } + + @Override + public Map getCurrentState() { + Map map = new HashMap(1); + map.put(MY_STATE, enabled); + return map; + } + + @Override + public String[] getProvidedSourceNames() { + return new String[] { MY_STATE }; + } + + + @Override + public void selectionChanged(IWorkbenchPart part, ISelection selection) { + if(!(selection instanceof TreeSelection)) + return; + TreeSelection treeSelection = (TreeSelection)selection; + Object element = treeSelection.getFirstElement(); + if(element != null && element instanceof IFolder) { + IFolder folder = (IFolder)element; + IProject project = folder.getProject(); + String outputPath = ""; + try { + outputPath = project.getPersistentProperty(new QualifiedName("",ScaseUiConstants.OUTPUT_FOLDER)); + } catch (CoreException e) { + Activator.log("Unable to read output folder path", e); + } + + if(folder.getFullPath().toPortableString().equals(outputPath)) + enabled = Boolean.FALSE; + else + enabled = Boolean.TRUE; + } + else + enabled = Boolean.TRUE; + + fireSourceChanged(ISources.WORKBENCH, MY_STATE, enabled); + + } + + @Override + public void windowActivated(IWorkbenchWindow window) { + window.getSelectionService().addSelectionListener(this); + } + + @Override + public void windowDeactivated(IWorkbenchWindow window) { + window.getSelectionService().removeSelectionListener(this); + } + + @Override + public void windowClosed(IWorkbenchWindow window) { + // Nothing to do + } + + @Override + public void windowOpened(IWorkbenchWindow window) { + // Nothing to do + } +} diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/sourceprovider/RequirementsFolderActive.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/sourceprovider/RequirementsFolderActive.java index c09a671..23fa45a 100644 --- a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/sourceprovider/RequirementsFolderActive.java +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/sourceprovider/RequirementsFolderActive.java @@ -1,112 +1,112 @@ -package eu.scasefp7.eclipse.core.ui.sourceprovider; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.TreeSelection; -import org.eclipse.ui.AbstractSourceProvider; -import org.eclipse.ui.ISelectionListener; -import org.eclipse.ui.ISources; -import org.eclipse.ui.IWindowListener; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.services.IServiceLocator; - -import eu.scasefp7.eclipse.core.ui.Activator; -import eu.scasefp7.eclipse.core.ui.ScaseUiConstants; - -/** - * Resolves the requirements folder for the currently selected project. - * - * @author Leonora Gaspar - */ -public class RequirementsFolderActive extends AbstractSourceProvider implements ISelectionListener, IWindowListener { - - private final static String MY_STATE = ScaseUiConstants.REQUIREMENTS_FOLDER_SOURCE; - private boolean enabled = true; - - /** - * Constructs the source provider. - */ - public RequirementsFolderActive() { - } - - @Override - public void initialize(IServiceLocator locator) { - super.initialize(locator); - PlatformUI.getWorkbench().addWindowListener(this); - } - - @Override - public void dispose() { - PlatformUI.getWorkbench().removeWindowListener(this); - - } - - @Override - public Map getCurrentState() { - Map map = new HashMap(1); - map.put(MY_STATE, enabled); - return map; - } - - @Override - public String[] getProvidedSourceNames() { - return new String[] { MY_STATE }; - } - - - @Override - public void selectionChanged(IWorkbenchPart part, ISelection selection) { - if(!(selection instanceof TreeSelection)) - return; - TreeSelection treeSelection = (TreeSelection)selection; - Object element = treeSelection.getFirstElement(); - if(element != null && element instanceof IFolder) { - IFolder folder = (IFolder)element; - IProject project = folder.getProject(); - String rqsPath = ""; - try { - rqsPath = project.getPersistentProperty(new QualifiedName("",ScaseUiConstants.REQUIREMENTS_FOLDER)); - } catch (CoreException e) { - Activator.log("Unable to read requirements folder path", e); - } - - if(folder.getFullPath().toPortableString().equals(rqsPath)) - enabled = Boolean.FALSE; - else - enabled = Boolean.TRUE; - } - else - enabled = Boolean.TRUE; - - fireSourceChanged(ISources.WORKBENCH, MY_STATE, enabled); - - } - - @Override - public void windowActivated(IWorkbenchWindow window) { - window.getSelectionService().addSelectionListener(this); - } - - @Override - public void windowDeactivated(IWorkbenchWindow window) { - window.getSelectionService().removeSelectionListener(this); - } - - @Override - public void windowClosed(IWorkbenchWindow window) { - // Nothing to do - } - - @Override - public void windowOpened(IWorkbenchWindow window) { - // Nothing to do - } +package eu.scasefp7.eclipse.core.ui.sourceprovider; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.TreeSelection; +import org.eclipse.ui.AbstractSourceProvider; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.ISources; +import org.eclipse.ui.IWindowListener; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.services.IServiceLocator; + +import eu.scasefp7.eclipse.core.ui.Activator; +import eu.scasefp7.eclipse.core.ui.ScaseUiConstants; + +/** + * Resolves the requirements folder for the currently selected project. + * + * @author Leonora Gaspar + */ +public class RequirementsFolderActive extends AbstractSourceProvider implements ISelectionListener, IWindowListener { + + private final static String MY_STATE = ScaseUiConstants.REQUIREMENTS_FOLDER_SOURCE; + private boolean enabled = true; + + /** + * Constructs the source provider. + */ + public RequirementsFolderActive() { + } + + @Override + public void initialize(IServiceLocator locator) { + super.initialize(locator); + PlatformUI.getWorkbench().addWindowListener(this); + } + + @Override + public void dispose() { + PlatformUI.getWorkbench().removeWindowListener(this); + + } + + @Override + public Map getCurrentState() { + Map map = new HashMap(1); + map.put(MY_STATE, enabled); + return map; + } + + @Override + public String[] getProvidedSourceNames() { + return new String[] { MY_STATE }; + } + + + @Override + public void selectionChanged(IWorkbenchPart part, ISelection selection) { + if(!(selection instanceof TreeSelection)) + return; + TreeSelection treeSelection = (TreeSelection)selection; + Object element = treeSelection.getFirstElement(); + if(element != null && element instanceof IFolder) { + IFolder folder = (IFolder)element; + IProject project = folder.getProject(); + String rqsPath = ""; + try { + rqsPath = project.getPersistentProperty(new QualifiedName("",ScaseUiConstants.REQUIREMENTS_FOLDER)); + } catch (CoreException e) { + Activator.log("Unable to read requirements folder path", e); + } + + if(folder.getFullPath().toPortableString().equals(rqsPath)) + enabled = Boolean.FALSE; + else + enabled = Boolean.TRUE; + } + else + enabled = Boolean.TRUE; + + fireSourceChanged(ISources.WORKBENCH, MY_STATE, enabled); + + } + + @Override + public void windowActivated(IWorkbenchWindow window) { + window.getSelectionService().addSelectionListener(this); + } + + @Override + public void windowDeactivated(IWorkbenchWindow window) { + window.getSelectionService().removeSelectionListener(this); + } + + @Override + public void windowClosed(IWorkbenchWindow window) { + // Nothing to do + } + + @Override + public void windowOpened(IWorkbenchWindow window) { + // Nothing to do + } } \ No newline at end of file diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/views/Dashboard.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/views/Dashboard.java index bb06deb..5c9c65e 100644 --- a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/views/Dashboard.java +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/views/Dashboard.java @@ -1,668 +1,720 @@ -/** - * Copyright 2015 S-CASE Consortium - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eu.scasefp7.eclipse.core.ui.views; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.commands.Command; -import org.eclipse.core.commands.CommandEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.commands.ICommandListener; -import org.eclipse.core.commands.IParameter; -import org.eclipse.core.commands.NotEnabledException; -import org.eclipse.core.commands.NotHandledException; -import org.eclipse.core.commands.Parameterization; -import org.eclipse.core.commands.ParameterizedCommand; -import org.eclipse.core.commands.common.CommandException; -import org.eclipse.core.commands.common.NotDefinedException; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.IRegistryEventListener; -import org.eclipse.core.runtime.InvalidRegistryObjectException; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.core.runtime.RegistryFactory; -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.SWT; -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.layout.FillLayout; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.RowLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Group; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.ISelectionListener; -import org.eclipse.ui.ISharedImages; -import org.eclipse.ui.IViewSite; -import org.eclipse.ui.IWorkbenchActionConstants; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.commands.ICommandService; -import org.eclipse.ui.handlers.IHandlerService; -import org.eclipse.ui.part.ViewPart; -import org.eclipse.ui.services.IServiceLocator; - -import eu.scasefp7.eclipse.core.ui.Activator; -import eu.scasefp7.eclipse.core.ui.ScaseUiConstants; -import eu.scasefp7.eclipse.core.ui.preferences.internal.DomainEntry; -import eu.scasefp7.eclipse.core.ui.preferences.internal.IProjectDomains; - -/** - * Creates a dashboard viewpart composed of multiple groups and buttons with commands attached. - * Configuration data is read from contributions to an extension point. - * - * @see ScaseUiConstants#DASHBOARD_EXTENSION - * @author Marin Orlic - */ - -public class Dashboard extends ViewPart implements ISelectionListener, IRegistryEventListener { - - /** - * The ID of the view as specified by the extension. - */ - public static final String ID = "eu.scasefp7.eclipse.core.ui.views.Dashboard"; - - /** - * The element names defining the contribution. - */ - private static final String CONTRIBUTION_GROUP = "group"; - private static final String CONTRIBUTION_GROUP_NAME = "name"; - private static final String CONTRIBUTION_COMMAND = "command"; - private static final String CONTRIBUTION_COMMAND_ID = "commandId"; - private static final String CONTRIBUTION_COMMAND_LABEL = "label"; - private static final String CONTRIBUTION_COMMAND_TOOLTIP = "tooltip"; - private static final String CONTRIBUTION_COMMAND_PARAM = "parameter"; - private static final String CONTRIBUTION_COMMAND_PARAM_NAME = "name"; - private static final String CONTRIBUTION_COMMAND_PARAM_VALUE = "value"; - private static final String CONTRIBUTION_COMMAND_NOTIFICATION_SUCCESS = "notification"; - private static final String CONTRIBUTION_COMMAND_NOTIFICATION_FAIL = "error"; - - protected HashMap registeredCommandListeners = new HashMap(); - - /** - * The currently selected project - */ - private IProject currentProject; - - /** - * The current selection - */ - private ISelection currentSelection; - - /** - * The constructor. - */ - public Dashboard() { - RegistryFactory.getRegistry().addListener(this, ScaseUiConstants.DASHBOARD_EXTENSION); - } - - @Override - public void init(IViewSite site) throws PartInitException { - IWorkbenchPage page = site.getPage(); - if (page != null) { - updateSelection(page.getSelection()); - updateContentDescription(); - } - site.getPage().addPostSelectionListener(this); - super.init(site); - } - - /** - * This is a callback that will allow us - * to create the viewer and initialize it. - */ - public void createPartControl(Composite parent) { - // Set the main layout - RowLayout layout = new RowLayout(SWT.HORIZONTAL); - layout.pack = false; - layout.fill = true; - layout.marginWidth = 10; - layout.marginHeight = 10; - layout.spacing = 10; - parent.setLayout(layout); - parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - - // Add menu and toolbar - hookContextMenu(); - contributeToActionBars(); - - // Read the configuration of the dashboard - IExtensionRegistry registry = Platform.getExtensionRegistry(); - IConfigurationElement[] contributions = registry.getConfigurationElementsFor(ScaseUiConstants.DASHBOARD_EXTENSION); - - // Create the configured items - for (IConfigurationElement elem : contributions) { - if(elem.getName().equals(CONTRIBUTION_GROUP)) { - handleGroup(parent, elem); - } - if(elem.getName().equals(CONTRIBUTION_COMMAND)) { - handleButton(parent, elem); - } - } - - parent.addControlListener(new ControlAdapter() { - @Override - public void controlResized(ControlEvent e) { - parent.getShell().layout(); - } - }); - - - // Project setup - /*int startR = 95, - stopR = 0, - startG = 197, - stopG = 61, - startB = 186, - stopB = 92; - int steps = 4; - int step = 0; - */ - //groupProject.setBackground(SWTResourceManager.getColor(startR-(step*(startR-stopR)/steps), startG-(step*(startG-stopG)/steps), startB-(step*(startB-stopB)/steps))); - // Increment gradient step - //step++; - } - - /** - * Disposes the view. Takes care to registered remove command listeners (on buttons). - * - * @see org.eclipse.ui.part.WorkbenchPart#dispose() - */ - @Override - public void dispose() { - super.dispose(); - - if(this.registeredCommandListeners.isEmpty()) { - return; - } - - // Get the command service - ICommandService commandService = (ICommandService)getSite().getService(ICommandService.class); - - // Clear out the listeners - for(Map.Entry entry : this.registeredCommandListeners.entrySet()) { - Command command = commandService.getCommand(entry.getValue()); - command.removeCommandListener(entry.getKey()); - } - - // Remove selection and registry listener registrations - getSite().getPage().removePostSelectionListener(this); - RegistryFactory.getRegistry().removeListener(this); - - currentProject = null; - currentSelection = null; - } - - /** - * Sets the focus. - * - * @see org.eclipse.ui.part.WorkbenchPart#setFocus() - */ - @Override - public void setFocus() { - - } - - private void hookContextMenu() { - MenuManager menuMgr = new MenuManager("#PopupMenu"); - menuMgr.setRemoveAllWhenShown(true); - menuMgr.addMenuListener(new IMenuListener() { - public void menuAboutToShow(IMenuManager manager) { - Dashboard.this.fillContextMenu(manager); - } - }); - } - - private void contributeToActionBars() { - IActionBars bars = getViewSite().getActionBars(); - fillLocalPullDown(bars.getMenuManager()); - fillLocalToolBar(bars.getToolBarManager()); - } - - private void fillLocalPullDown(IMenuManager manager) { -// manager.add(action1); - manager.add(new Separator()); -// manager.add(action2); - } - - private void fillContextMenu(IMenuManager manager) { -// manager.add(action1); -// manager.add(action2); - // Other plug-ins can contribute there actions here - manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); - } - - private void fillLocalToolBar(IToolBarManager manager) { -// manager.add(action1); -// manager.add(action2); -// CommandContributionItemParameter param = new CommandContributionItemParameter(getSite(), "eu.scasefp7.eclipse.core.ui.dashboard.menu1", -// "eu", new HashMap(), null, null, null, "MENUUU", "C", -// "Shows the project properties pages", -// CommandContributionItem.STYLE_PUSH, getContentDescription(), false); -// manager.add(new CommandContributionItem(param)); - } - - - /** - * Create a group and it's children based on the configuration element. - * - * @param parent control - * @param elem configuration element describing the button - * @throws InvalidRegistryObjectException - */ - private void handleGroup(Composite parent, IConfigurationElement elem) throws InvalidRegistryObjectException { - Group group = createGroup(parent, elem.getAttribute(CONTRIBUTION_GROUP_NAME)); - - for (IConfigurationElement child : elem.getChildren()) { - if(child.getName().equals(CONTRIBUTION_GROUP)) { - handleGroup(group, child); - } - if(child.getName().equals(CONTRIBUTION_COMMAND)) { - handleButton(group, child); - } - } - } - - /** - * Create a button and attach the command to it based on the configuration element. - * - * @param parent control - * @param elem configuration element describing the button - * @throws InvalidRegistryObjectException - */ - private void handleButton(Composite parent, IConfigurationElement elem) throws InvalidRegistryObjectException { - - String name = elem.getAttribute(CONTRIBUTION_COMMAND_LABEL); - String tooltip = elem.getAttribute(CONTRIBUTION_COMMAND_TOOLTIP); - final String commandId = elem.getAttribute(CONTRIBUTION_COMMAND_ID); - final String notificationSuccess = elem.getAttribute(CONTRIBUTION_COMMAND_NOTIFICATION_SUCCESS); - final String notificationFail = elem.getAttribute(CONTRIBUTION_COMMAND_NOTIFICATION_FAIL); - - Button btn = new Button(parent, SWT.NONE); - - if(name != null) { - btn.setText(name); - } - if(tooltip != null) { - btn.setToolTipText(tooltip); - } - - if(commandId != null) { - // Add command listener - setupCommandListener(btn, commandId); - - // Setup execution - final Map params = getParameters(elem); - - if(params.isEmpty()) { - // No parameters - btn.addMouseListener(new MouseAdapter() { - @Override - public void mouseDown(MouseEvent e) { - try { - // Trace user action - Activator.TRACE.trace("/dashboard/userActions", "Button pressed: " + name); - - executeCommand(commandId); - notifyUser(commandId, notificationSuccess); - } catch (CommandException ex) { - Activator.log("Unable to execute command " + commandId, ex); - notifyUser(commandId, notificationFail, ex); - } - } - }); - } else { - // Copy parameters - btn.addMouseListener(new MouseAdapter() { - @Override - public void mouseDown(MouseEvent e) { - try { - // Trace user action - Activator.TRACE.trace("/dashboard/userActions", "Button pressed: " + name); - - executeCommand(commandId, params); - notifyUser(commandId, notificationSuccess); - } catch (CommandException ex) { - Activator.log("Unable to execute command " + commandId, ex); - notifyUser(commandId, notificationFail, ex); - } - } - }); - } - } - } - - /** - * Creates a group with fill layout and configured margins. - * - * @param parent control - * @param name for the group, displayed as label - * @return created group control - */ - private static Group createGroup(Composite parent, String name) { - Group group; - group = new Group(parent, SWT.NONE); - //group.setBackground(SWTResourceManager.getColor(startR-(step*(startR-stopR)/steps), startG-(step*(startG-stopG)/steps), startB-(step*(startB-stopB)/steps))); - group.setText(name); - - // Configure layout - FillLayout fl_group = new FillLayout(SWT.VERTICAL); - fl_group.spacing = 10; - fl_group.marginWidth = 10; - fl_group.marginHeight = 10; - group.setLayout(fl_group); - - return group; - } - - /** - * Convenience method to register a command listener and enable/disable control based on command configuration. - * - * @param control - * @param commandId ID of the command to execute - */ - private void setupCommandListener(final Control control, String commandId) { - - // Obtain IServiceLocator implementer, e.g. from PlatformUI.getWorkbench(): - IServiceLocator serviceLocator = getSite(); - // or a site from within a editor or view: - // IServiceLocator serviceLocator = getSite(); - - // Get CommandService - ICommandService commandService = (ICommandService)serviceLocator.getService(ICommandService.class); - - // Lookup commmand with its ID - final Command command = commandService.getCommand(commandId); - - // Update UI initially - control.setEnabled(command.isDefined() && command.isEnabled()); - - // Register state listener - ICommandListener listener = new ICommandListener() { - @Override - public void commandChanged(CommandEvent cmdEvent) { - if(cmdEvent.isDefinedChanged() || cmdEvent.isEnabledChanged() || cmdEvent.isHandledChanged()) { - control.setEnabled(command.isDefined() && command.isEnabled() && command.isHandled()); - } - } - }; - - command.addCommandListener(listener); - registeredCommandListeners.put(listener, commandId); - } - - /** - * Convenience method to call a command with parameters. - * - * @param commandId ID of the command to execute - * @param parameters map of command parameters in form (parameterId, value) - * @throws CommandException if the command execution fails - */ - protected void executeCommand(String commandId, Map parameters) throws CommandException { - // Obtain IServiceLocator implementer, e.g. from PlatformUI.getWorkbench(): - IServiceLocator serviceLocator = getSite(); - // or a site from within a editor or view: - // IServiceLocator serviceLocator = getSite(); - - ICommandService commandService = (ICommandService)serviceLocator.getService(ICommandService.class); - IHandlerService handlerService = (IHandlerService)serviceLocator.getService(IHandlerService.class); - - try { - // Lookup command with its ID - Command command = commandService.getCommand(commandId); - - ArrayList params = new ArrayList(); - for(Map.Entry entry : parameters.entrySet()) { - IParameter p = command.getParameter(entry.getKey()); - if(p != null) { - Parameterization param = new Parameterization(p, entry.getValue()); - params.add(param); - } else { - Activator.TRACE.trace("/dashboard/executeCommand", "Cannot find parameter: " + entry.getKey() + " of command " + commandId); - } - } - - Activator.TRACE.trace("/dashboard/userActions", "Command called: " + commandId + ", parameters: " + params); - - ParameterizedCommand parametrizedCommand = new ParameterizedCommand(command, params.toArray(new Parameterization[params.size()])); - handlerService.executeCommand(parametrizedCommand, null); - - } catch (ExecutionException | NotDefinedException | - NotEnabledException | NotHandledException ex) { - - throw ex; - } - } - - - /** - * Convenience method to call a command with no parameters. - * - * @param commandId ID of the command to execute - * @throws CommandException if the command execution fails - */ - protected void executeCommand(String commandId) throws CommandException { - // Obtain IServiceLocator implementer, e.g. from PlatformUI.getWorkbench(): - IServiceLocator serviceLocator = getSite(); - // or a site from within a editor or view: - // IServiceLocator serviceLocator = getSite(); - - Activator.TRACE.trace("/dashboard/executeCommand", "Executing: " + commandId); - - IHandlerService handlerService = (IHandlerService)serviceLocator.getService(IHandlerService.class); - try { - // Execute command via its ID - handlerService.executeCommand(commandId, null); - - } catch (ExecutionException | NotDefinedException | - NotEnabledException | NotHandledException ex) { - - throw ex; - } - } - - /** - * Reads command parameters as children of configuration element for the command. - * Borrowed from org.eclipse.ui.internal.menus.MenuHelper. - * - * @param element - * @return map with parameter names and values - * @see org.eclipse.ui.internal.menus.MenuHelper#getParameters(IConfigurationElement) - */ - @SuppressWarnings("restriction") - private static Map getParameters(IConfigurationElement element) { - HashMap map = new HashMap(); - IConfigurationElement[] parameters = element.getChildren(CONTRIBUTION_COMMAND_PARAM); - for (int i = 0; i < parameters.length; i++) { - String name = parameters[i].getAttribute(CONTRIBUTION_COMMAND_PARAM_NAME); - String value = parameters[i].getAttribute(CONTRIBUTION_COMMAND_PARAM_VALUE); - if (name != null && value != null) { - map.put(name, value); - } - } - return map; - } - - protected void notifyUser(String commandId, String message) { - if(message != null) { - List notifications = new ArrayList(); - - NotificationPopup popup = new NotificationPopup(this.getViewSite().getShell()); - - notifications.add(new DashboardNotification(commandId, getPartName(), message, PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_INFO_TSK))); - - popup.setContents(notifications); - popup.open(); - } - } - - protected void notifyUser(String commandId, String message, CommandException ex) { - List notifications = new ArrayList(); - - NotificationPopup popup = new NotificationPopup(this.getViewSite().getShell()); - - notifications.add(new DashboardNotification(commandId, getPartName(), ((message != null) ? message + ": " : "") + ex.getLocalizedMessage(), PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK))); - - popup.setContents(notifications); - popup.open(); - } - - @Override - public void selectionChanged(IWorkbenchPart part, ISelection sel) { - // we ignore null selection, or if we are pinned, or our own selection or same selection or if selection is empty - if (sel == null || sel.equals(currentSelection) || sel.isEmpty()) { - if (this.currentProject == null || !this.currentProject.exists()) { - this.currentProject = null; - setContentDescription("Please select a project"); - } - return; - } - - // we ignore selection if we are hidden OR selection is coming from another source as the last one -// if(part == null || !part.equals(currentPart)){ -// return; -// } - updateSelection(sel); - updateContentDescription(); - } - - protected IProject getProjectOfSelectionList(List selectionList) { - IProject project = null; - for (Object object : selectionList) { - IResource resource = (IResource) Platform.getAdapterManager().getAdapter(object, IResource.class); - IProject theproject = null; - if (resource != null) { - theproject = resource.getProject(); - } else { - theproject = (IProject) Platform.getAdapterManager().getAdapter(object, IProject.class); - } - if (theproject != null) { - if (project == null) { - project = theproject; - } else { - if (!project.equals(theproject)) { - return null; - } - } - } - } - return project; - } - - private void updateSelection(ISelection selection) { - if(selection instanceof IStructuredSelection) { - IStructuredSelection sel = (IStructuredSelection) selection; - - if (sel.getFirstElement() instanceof IResource){ - @SuppressWarnings("unchecked") - IProject project = getProjectOfSelectionList(sel.toList()); - if (project != null) { - Activator.TRACE.trace("/dashboard/selectedProjectChanged", "Selected project: " + project.getName()); - this.currentProject = project; - } - } - } - } - - private void updateContentDescription() { - if (this.currentProject != null && this.currentProject.exists()) { - int projectDomain = getProjectDomainId(this.currentProject); - DomainEntry de = findDomainById(IProjectDomains.PROJECT_DOMAINS, projectDomain); - - if(de != null) { - setContentDescription("Active project: " + this.currentProject.getName() + " (" + de.getName() + ")"); - } else { - setContentDescription("Active project: " + this.currentProject.getName() + " (domain unset)"); - } - } else { - setContentDescription("Please select a project"); - } - } - - private DomainEntry findDomainById(DomainEntry[] domains, int domainId) { - for (DomainEntry de : domains) { - if (de.getId() == domainId) { - return de; - } - if(de.hasChildren()) { - for (DomainEntry child : de.getChildren()) { - if(child.getId() == domainId) { - return child; - } - } - } - } - return null; - } - - private static int getProjectDomainId(IProject project) { - try { - String domain = project.getPersistentProperty(new QualifiedName("", ScaseUiConstants.PROP_PROJECT_DOMAIN)); - if(domain != null) { - return Integer.parseInt(domain); - } - } catch (CoreException | NumberFormatException e) { - Activator.log("Unable to load project domain", e); - } - return ScaseUiConstants.PROP_PROJECT_DOMAIN_DEFAULT; - } - - @Override - public void added(IExtension[] extensions) { - // TODO Auto-generated method stub - - } - - @Override - public void removed(IExtension[] extensions) { - // TODO Auto-generated method stub - - } - - @Override - public void added(IExtensionPoint[] extensionPoints) { - // TODO Auto-generated method stub - - } - - @Override - public void removed(IExtensionPoint[] extensionPoints) { - // TODO Auto-generated method stub - - } - -} +/** + * Copyright 2015 S-CASE Consortium + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package eu.scasefp7.eclipse.core.ui.views; + +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.CommandEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.ICommandListener; +import org.eclipse.core.commands.IParameter; +import org.eclipse.core.commands.NotEnabledException; +import org.eclipse.core.commands.NotHandledException; +import org.eclipse.core.commands.Parameterization; +import org.eclipse.core.commands.ParameterizedCommand; +import org.eclipse.core.commands.common.CommandException; +import org.eclipse.core.commands.common.NotDefinedException; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.IRegistryEventListener; +import org.eclipse.core.runtime.InvalidRegistryObjectException; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.core.runtime.RegistryFactory; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.SWT; +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.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.IViewSite; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.commands.ICommandService; +import org.eclipse.ui.handlers.IHandlerService; +import org.eclipse.ui.part.ViewPart; +import org.eclipse.ui.services.IServiceLocator; + +import eu.scasefp7.eclipse.core.ui.Activator; +import eu.scasefp7.eclipse.core.ui.ScaseUiConstants; +import eu.scasefp7.eclipse.core.ui.preferences.internal.DomainEntry; +import eu.scasefp7.eclipse.core.ui.preferences.internal.IProjectDomains; + +/** + * Creates a dashboard viewpart composed of multiple groups and buttons with commands attached. + * Configuration data is read from contributions to an extension point. + * + * @see ScaseUiConstants#DASHBOARD_EXTENSION + * @author Marin Orlic + */ + +public class Dashboard extends ViewPart implements ISelectionListener, IRegistryEventListener { + + /** + * The ID of the view as specified by the extension. + */ + public static final String ID = "eu.scasefp7.eclipse.core.ui.views.Dashboard"; + + /** + * The element names defining the contribution. + */ + private static final String CONTRIBUTION_GROUP = "group"; + private static final String CONTRIBUTION_GROUP_NAME = "name"; + private static final String CONTRIBUTION_COMMAND = "command"; + private static final String CONTRIBUTION_COMMAND_ID = "commandId"; + private static final String CONTRIBUTION_COMMAND_LABEL = "label"; + private static final String CONTRIBUTION_COMMAND_TOOLTIP = "tooltip"; + private static final String CONTRIBUTION_COMMAND_PARAM = "parameter"; + private static final String CONTRIBUTION_COMMAND_PARAM_NAME = "name"; + private static final String CONTRIBUTION_COMMAND_PARAM_VALUE = "value"; + private static final String CONTRIBUTION_COMMAND_NOTIFICATION_SUCCESS = "notification"; + private static final String CONTRIBUTION_COMMAND_NOTIFICATION_FAIL = "error"; + + protected HashMap registeredCommandListeners = new HashMap(); + + /** + * The currently selected project + */ + private IProject currentProject; + + /** + * The current selection + */ + private ISelection currentSelection; + + /** + * Name of the group and group of buttons + */ + private HashMap groups = new HashMap(); + + /** + * Button ID and buttons + */ + private HashMap buttons = new HashMap(); + + /** + * First button is above the button with given string ID + */ + private List> ordering = new ArrayList>(); + + /** + * New extension for dashboard + * TODO: change the current one in ScaseUiConstants.DASHBOARD_EXTENSION to this one + */ + private final String DASHBOARD_EXTENSION = "eu.scasefp7.eclipse.core.dashboardItem2"; + + private Composite _parent; + + /** + * The constructor. + */ + public Dashboard() { + //RegistryFactory.getRegistry().addListener(this, ScaseUiConstants.DASHBOARD_EXTENSION); + RegistryFactory.getRegistry().addListener(this, DASHBOARD_EXTENSION); + } + + @Override + public void init(IViewSite site) throws PartInitException { + IWorkbenchPage page = site.getPage(); + if (page != null) { + updateSelection(page.getSelection()); + updateContentDescription(); + } + site.getPage().addPostSelectionListener(this); + super.init(site); + } + + /** + * This is a callback that will allow us + * to create the viewer and initialize it. + */ + public void createPartControl(Composite parent) { + // Set the main layout + RowLayout layout = new RowLayout(SWT.HORIZONTAL); + layout.pack = false; + layout.fill = true; + layout.marginWidth = 10; + layout.marginHeight = 10; + layout.spacing = 10; + parent.setLayout(layout); + parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + // Add menu and toolbar + hookContextMenu(); + contributeToActionBars(); + + // Read the configuration of the dashboard + IExtensionRegistry registry = Platform.getExtensionRegistry(); + //IConfigurationElement[] contributions = registry.getConfigurationElementsFor(ScaseUiConstants.DASHBOARD_EXTENSION); + IConfigurationElement[] contributions = registry.getConfigurationElementsFor(DASHBOARD_EXTENSION); + // Create the configured items + for (IConfigurationElement elem : contributions) { + if(elem.getName().equals(CONTRIBUTION_GROUP)) { + handleGroup(parent, elem); + } + if(elem.getName().equals(CONTRIBUTION_COMMAND)) { + handleButton(parent, elem); + } + } + if(!ordering.isEmpty()){ + for(Entry e : ordering){ + String id = e.getValue(); + Button first = e.getKey(); + Button second = buttons.get(id);; + first.moveAbove(second); + } + } + + parent.addControlListener(new ControlAdapter() { + @Override + public void controlResized(ControlEvent e) { + parent.getShell().layout(); + } + }); + + _parent = parent; + + // Project setup + /*int startR = 95, + stopR = 0, + startG = 197, + stopG = 61, + startB = 186, + stopB = 92; + int steps = 4; + int step = 0; + */ + //groupProject.setBackground(SWTResourceManager.getColor(startR-(step*(startR-stopR)/steps), startG-(step*(startG-stopG)/steps), startB-(step*(startB-stopB)/steps))); + // Increment gradient step + //step++; + } + + /** + * Disposes the view. Takes care to registered remove command listeners (on buttons). + * + * @see org.eclipse.ui.part.WorkbenchPart#dispose() + */ + @Override + public void dispose() { + super.dispose(); + + if(this.registeredCommandListeners.isEmpty()) { + return; + } + + // Get the command service + ICommandService commandService = (ICommandService)getSite().getService(ICommandService.class); + + // Clear out the listeners + for(Map.Entry entry : this.registeredCommandListeners.entrySet()) { + Command command = commandService.getCommand(entry.getValue()); + command.removeCommandListener(entry.getKey()); + } + + // Remove selection and registry listener registrations + getSite().getPage().removePostSelectionListener(this); + RegistryFactory.getRegistry().removeListener(this); + + currentProject = null; + currentSelection = null; + } + + /** + * Sets the focus. + * + * @see org.eclipse.ui.part.WorkbenchPart#setFocus() + */ + @Override + public void setFocus() { + + } + + private void hookContextMenu() { + MenuManager menuMgr = new MenuManager("#PopupMenu"); + menuMgr.setRemoveAllWhenShown(true); + menuMgr.addMenuListener(new IMenuListener() { + public void menuAboutToShow(IMenuManager manager) { + Dashboard.this.fillContextMenu(manager); + } + }); + } + + private void contributeToActionBars() { + IActionBars bars = getViewSite().getActionBars(); + fillLocalPullDown(bars.getMenuManager()); + fillLocalToolBar(bars.getToolBarManager()); + } + + private void fillLocalPullDown(IMenuManager manager) { +// manager.add(action1); + manager.add(new Separator()); +// manager.add(action2); + } + + private void fillContextMenu(IMenuManager manager) { +// manager.add(action1); +// manager.add(action2); + // Other plug-ins can contribute there actions here + manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); + } + + private void fillLocalToolBar(IToolBarManager manager) { +// manager.add(action1); +// manager.add(action2); +// CommandContributionItemParameter param = new CommandContributionItemParameter(getSite(), "eu.scasefp7.eclipse.core.ui.dashboard.menu1", +// "eu", new HashMap(), null, null, null, "MENUUU", "C", +// "Shows the project properties pages", +// CommandContributionItem.STYLE_PUSH, getContentDescription(), false); +// manager.add(new CommandContributionItem(param)); + } + + + /** + * Create a group and it's children based on the configuration element. + * + * @param parent control + * @param elem configuration element describing the button + * @throws InvalidRegistryObjectException + */ + private void handleGroup(Composite parent, IConfigurationElement elem) throws InvalidRegistryObjectException { + Group group = createGroup(parent, elem.getAttribute(CONTRIBUTION_GROUP_NAME)); + groups.put(elem.getAttribute(CONTRIBUTION_GROUP_NAME), group); + for (IConfigurationElement child : elem.getChildren()) { + if(child.getName().equals(CONTRIBUTION_GROUP)) { + handleGroup(group, child); + } + if(child.getName().equals(CONTRIBUTION_COMMAND)) { + handleButton(group, child); + } + } + } + + /** + * Create a button and attach the command to it based on the configuration element. + * + * @param parent control + * @param elem configuration element describing the button + * @throws InvalidRegistryObjectException + */ + private void handleButton(Composite parent, IConfigurationElement elem) throws InvalidRegistryObjectException { + + String name = elem.getAttribute(CONTRIBUTION_COMMAND_LABEL); + String tooltip = elem.getAttribute(CONTRIBUTION_COMMAND_TOOLTIP); + String groupName = elem.getAttribute("groupName"); + + if(groupName!=null && groupName!="") + parent = groups.get(groupName); + + String appearsBefore = elem.getAttribute("appearsBefore"); + String buttonId = elem.getAttribute("buttonId"); + + final String commandId = elem.getAttribute(CONTRIBUTION_COMMAND_ID); + final String notificationSuccess = elem.getAttribute(CONTRIBUTION_COMMAND_NOTIFICATION_SUCCESS); + final String notificationFail = elem.getAttribute(CONTRIBUTION_COMMAND_NOTIFICATION_FAIL); + + Button btn = new Button(parent, SWT.NONE); + + + if(name != null) { + btn.setText(name); + } + if(tooltip != null) { + btn.setToolTipText(tooltip); + } + + if(commandId != null) { + // Add command listener + setupCommandListener(btn, commandId); + + // Setup execution + final Map params = getParameters(elem); + + if(params.isEmpty()) { + // No parameters + btn.addMouseListener(new MouseAdapter() { + @Override + public void mouseDown(MouseEvent e) { + try { + // Trace user action + Activator.TRACE.trace("/dashboard/userActions", "Button pressed: " + name); + + executeCommand(commandId); + notifyUser(commandId, notificationSuccess); + } catch (CommandException ex) { + Activator.log("Unable to execute command " + commandId, ex); + notifyUser(commandId, notificationFail, ex); + } + } + }); + } else { + // Copy parameters + btn.addMouseListener(new MouseAdapter() { + @Override + public void mouseDown(MouseEvent e) { + try { + // Trace user action + Activator.TRACE.trace("/dashboard/userActions", "Button pressed: " + name); + + executeCommand(commandId, params); + notifyUser(commandId, notificationSuccess); + } catch (CommandException ex) { + Activator.log("Unable to execute command " + commandId, ex); + notifyUser(commandId, notificationFail, ex); + } + } + }); + } + } + + buttons.put(buttonId, btn); + + if(appearsBefore!= null && appearsBefore != ""){ + Entry entry = + new AbstractMap.SimpleEntry(btn, appearsBefore); + ordering.add(entry); + } + } + + /** + * Creates a group with fill layout and configured margins. + * + * @param parent control + * @param name for the group, displayed as label + * @return created group control + */ + private static Group createGroup(Composite parent, String name) { + Group group; + group = new Group(parent, SWT.NONE); + //group.setBackground(SWTResourceManager.getColor(startR-(step*(startR-stopR)/steps), startG-(step*(startG-stopG)/steps), startB-(step*(startB-stopB)/steps))); + group.setText(name); + + // Configure layout + FillLayout fl_group = new FillLayout(SWT.VERTICAL); + fl_group.spacing = 10; + fl_group.marginWidth = 10; + fl_group.marginHeight = 10; + group.setLayout(fl_group); + + return group; + } + + /** + * Convenience method to register a command listener and enable/disable control based on command configuration. + * + * @param control + * @param commandId ID of the command to execute + */ + private void setupCommandListener(final Control control, String commandId) { + + // Obtain IServiceLocator implementer, e.g. from PlatformUI.getWorkbench(): + IServiceLocator serviceLocator = getSite(); + // or a site from within a editor or view: + // IServiceLocator serviceLocator = getSite(); + + // Get CommandService + ICommandService commandService = (ICommandService)serviceLocator.getService(ICommandService.class); + + // Lookup commmand with its ID + final Command command = commandService.getCommand(commandId); + + // Update UI initially + control.setEnabled(command.isDefined() && command.isEnabled()); + + // Register state listener + ICommandListener listener = new ICommandListener() { + @Override + public void commandChanged(CommandEvent cmdEvent) { + if(cmdEvent.isDefinedChanged() || cmdEvent.isEnabledChanged() || cmdEvent.isHandledChanged()) { + control.setEnabled(command.isDefined() && command.isEnabled() && command.isHandled()); + } + } + }; + + command.addCommandListener(listener); + registeredCommandListeners.put(listener, commandId); + } + + /** + * Convenience method to call a command with parameters. + * + * @param commandId ID of the command to execute + * @param parameters map of command parameters in form (parameterId, value) + * @throws CommandException if the command execution fails + */ + protected void executeCommand(String commandId, Map parameters) throws CommandException { + // Obtain IServiceLocator implementer, e.g. from PlatformUI.getWorkbench(): + IServiceLocator serviceLocator = getSite(); + // or a site from within a editor or view: + // IServiceLocator serviceLocator = getSite(); + + ICommandService commandService = (ICommandService)serviceLocator.getService(ICommandService.class); + IHandlerService handlerService = (IHandlerService)serviceLocator.getService(IHandlerService.class); + + try { + // Lookup command with its ID + Command command = commandService.getCommand(commandId); + + ArrayList params = new ArrayList(); + for(Map.Entry entry : parameters.entrySet()) { + IParameter p = command.getParameter(entry.getKey()); + if(p != null) { + Parameterization param = new Parameterization(p, entry.getValue()); + params.add(param); + } else { + Activator.TRACE.trace("/dashboard/executeCommand", "Cannot find parameter: " + entry.getKey() + " of command " + commandId); + } + } + + Activator.TRACE.trace("/dashboard/userActions", "Command called: " + commandId + ", parameters: " + params); + + ParameterizedCommand parametrizedCommand = new ParameterizedCommand(command, params.toArray(new Parameterization[params.size()])); + handlerService.executeCommand(parametrizedCommand, null); + + } catch (ExecutionException | NotDefinedException | + NotEnabledException | NotHandledException ex) { + + throw ex; + } + } + + + /** + * Convenience method to call a command with no parameters. + * + * @param commandId ID of the command to execute + * @throws CommandException if the command execution fails + */ + protected void executeCommand(String commandId) throws CommandException { + // Obtain IServiceLocator implementer, e.g. from PlatformUI.getWorkbench(): + IServiceLocator serviceLocator = getSite(); + // or a site from within a editor or view: + // IServiceLocator serviceLocator = getSite(); + + Activator.TRACE.trace("/dashboard/executeCommand", "Executing: " + commandId); + + IHandlerService handlerService = (IHandlerService)serviceLocator.getService(IHandlerService.class); + try { + // Execute command via its ID + handlerService.executeCommand(commandId, null); + + } catch (ExecutionException | NotDefinedException | + NotEnabledException | NotHandledException ex) { + + throw ex; + } + } + + /** + * Reads command parameters as children of configuration element for the command. + * Borrowed from org.eclipse.ui.internal.menus.MenuHelper. + * + * @param element + * @return map with parameter names and values + * @see org.eclipse.ui.internal.menus.MenuHelper#getParameters(IConfigurationElement) + */ + @SuppressWarnings("restriction") + private static Map getParameters(IConfigurationElement element) { + HashMap map = new HashMap(); + IConfigurationElement[] parameters = element.getChildren(CONTRIBUTION_COMMAND_PARAM); + for (int i = 0; i < parameters.length; i++) { + String name = parameters[i].getAttribute(CONTRIBUTION_COMMAND_PARAM_NAME); + String value = parameters[i].getAttribute(CONTRIBUTION_COMMAND_PARAM_VALUE); + if (name != null && value != null) { + map.put(name, value); + } + } + return map; + } + + protected void notifyUser(String commandId, String message) { + if(message != null) { + List notifications = new ArrayList(); + + NotificationPopup popup = new NotificationPopup(this.getViewSite().getShell()); + + notifications.add(new DashboardNotification(commandId, getPartName(), message, PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_INFO_TSK))); + + popup.setContents(notifications); + popup.open(); + } + } + + protected void notifyUser(String commandId, String message, CommandException ex) { + List notifications = new ArrayList(); + + NotificationPopup popup = new NotificationPopup(this.getViewSite().getShell()); + + notifications.add(new DashboardNotification(commandId, getPartName(), ((message != null) ? message + ": " : "") + ex.getLocalizedMessage(), PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK))); + + popup.setContents(notifications); + popup.open(); + } + + @Override + public void selectionChanged(IWorkbenchPart part, ISelection sel) { + // we ignore null selection, or if we are pinned, or our own selection or same selection or if selection is empty + if (sel == null || sel.equals(currentSelection) || sel.isEmpty()) { + if (this.currentProject == null || !this.currentProject.exists()) { + this.currentProject = null; + setContentDescription("Please select a project"); + } + return; + } + + // we ignore selection if we are hidden OR selection is coming from another source as the last one +// if(part == null || !part.equals(currentPart)){ +// return; +// } + updateSelection(sel); + updateContentDescription(); + } + + protected IProject getProjectOfSelectionList(List selectionList) { + IProject project = null; + for (Object object : selectionList) { + IResource resource = (IResource) Platform.getAdapterManager().getAdapter(object, IResource.class); + IProject theproject = null; + if (resource != null) { + theproject = resource.getProject(); + } else { + theproject = (IProject) Platform.getAdapterManager().getAdapter(object, IProject.class); + } + if (theproject != null) { + if (project == null) { + project = theproject; + } else { + if (!project.equals(theproject)) { + return null; + } + } + } + } + return project; + } + + private void updateSelection(ISelection selection) { + if(selection instanceof IStructuredSelection) { + IStructuredSelection sel = (IStructuredSelection) selection; + + if (sel.getFirstElement() instanceof IResource){ + @SuppressWarnings("unchecked") + IProject project = getProjectOfSelectionList(sel.toList()); + if (project != null) { + Activator.TRACE.trace("/dashboard/selectedProjectChanged", "Selected project: " + project.getName()); + this.currentProject = project; + } + } + } + } + + private void updateContentDescription() { + if (this.currentProject != null && this.currentProject.exists()) { + int projectDomain = getProjectDomainId(this.currentProject); + DomainEntry de = findDomainById(IProjectDomains.PROJECT_DOMAINS, projectDomain); + + if(de != null) { + setContentDescription("Active project: " + this.currentProject.getName() + " (" + de.getName() + ")"); + } else { + setContentDescription("Active project: " + this.currentProject.getName() + " (domain unset)"); + } + } else { + setContentDescription("Please select a project"); + } + } + + private DomainEntry findDomainById(DomainEntry[] domains, int domainId) { + for (DomainEntry de : domains) { + if (de.getId() == domainId) { + return de; + } + if(de.hasChildren()) { + for (DomainEntry child : de.getChildren()) { + if(child.getId() == domainId) { + return child; + } + } + } + } + return null; + } + + private static int getProjectDomainId(IProject project) { + try { + String domain = project.getPersistentProperty(new QualifiedName("", ScaseUiConstants.PROP_PROJECT_DOMAIN)); + if(domain != null) { + return Integer.parseInt(domain); + } + } catch (CoreException | NumberFormatException e) { + Activator.log("Unable to load project domain", e); + } + return ScaseUiConstants.PROP_PROJECT_DOMAIN_DEFAULT; + } + + @Override + public void added(IExtension[] extensions) { + _parent.update(); + + } + + @Override + public void removed(IExtension[] extensions) { + _parent.update(); + + } + + @Override + public void added(IExtensionPoint[] extensionPoints) { + _parent.update(); + + } + + @Override + public void removed(IExtensionPoint[] extensionPoints) { + _parent.update(); + + } + +} diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/views/ImageButton.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/views/ImageButton.java new file mode 100644 index 0000000..c1f0a8f --- /dev/null +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/views/ImageButton.java @@ -0,0 +1,118 @@ +package eu.scasefp7.eclipse.core.ui.views; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; + +public class ImageButton extends Composite +{ + private Color textColor; + private Image image; + private String text; + private int width = 0; + private int height = 0; + private int imgWidth; + private int imgHeight; + + public ImageButton(Composite parent, int style) + { + super(parent, style); + + textColor = Display.getDefault().getSystemColor(SWT.COLOR_BLACK); + + addListener(SWT.Dispose, new Listener() + { + @Override + public void handleEvent(Event arg0) + { + if (image != null) + image.dispose(); + } + }); + + + addListener(SWT.Paint, new Listener() + { + @Override + public void handleEvent(Event e) + { + paintControl(e); + } + }); + + addListener(SWT.MouseDown, new Listener() + { + @Override + public void handleEvent(Event arg0) + { + System.out.println("Click"); + } + }); + } + + private void paintControl(Event event) + { + GC gc = event.gc; + + if (image != null) { + //draw image + gc.drawImage(image, 1, 1, imgWidth-1, imgHeight-1, 1, 1, width, height); + + //draw border + gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY)); + gc.drawRoundRectangle(1, 1, width, height, 5, 5); + + //draw text + gc.setForeground(textColor); + Point textSize = gc.textExtent(text); + gc.drawText(text, (width - textSize.x) / 2 + 1, (height - textSize.y) / 2 + 1, true); + } + } + + public void setImage(Image image) + { + this.image = new Image(Display.getDefault(), image, SWT.IMAGE_COPY); + width = image.getBounds().width; + height = image.getBounds().height; + imgWidth = width; + imgHeight = height; + redraw(); + } + + public void setText(String text) + { + this.text = text; + redraw(); + } + + @Override + public Point computeSize(int wHint, int hHint, boolean changed) + { + int overallWidth = width; + int overallHeight = height; + + if (wHint != SWT.DEFAULT && wHint < overallWidth) + overallWidth = wHint; + + if (hHint != SWT.DEFAULT && hHint < overallHeight) + overallHeight = hHint; + + return new Point(overallWidth + 2, overallHeight + 2); + } + @Override + public void setSize(int w, int h) { + width = w; + height = h; + redraw(); + } + @Override + public void setSize(Point size) { + setSize(size.x,size.y); + } +} \ No newline at end of file diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/DeployWizard.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/DeployWizard.java index 5c11242..0e3f184 100644 --- a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/DeployWizard.java +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/DeployWizard.java @@ -1,55 +1,55 @@ -package eu.scasefp7.eclipse.core.ui.wizards; - -import org.eclipse.jface.wizard.IWizardPage; -import org.eclipse.jface.wizard.Wizard; - -public class DeployWizard extends Wizard { - protected DeployWizardPageOne one; - protected DeployWizardPageTwo two; - protected DeployWizardPageThree three; - - private static final String PAGE_ONE_NAME = "First page"; - private static final String PAGE_TWO_NAME = "Deploy generated service"; - private static final String PAGE_THREE_NAME = "Third page"; - private static final String WIZARD_NAME = "Service deployment"; - - - public DeployWizard() { - super(); - setNeedsProgressMonitor(true); - } - - @Override - public String getWindowTitle() { - return WIZARD_NAME; - } - - - @Override - public void addPages() { - one = new DeployWizardPageOne(PAGE_ONE_NAME); - two = new DeployWizardPageTwo(PAGE_TWO_NAME); - three = new DeployWizardPageThree(PAGE_THREE_NAME); -// addPage(one); - addPage(two); -// addPage(three); - } - - - @Override - public boolean performFinish() { - // TODO Auto-generated method stub - return true; - } - @Override - public IWizardPage getNextPage(IWizardPage page) { - - if(one.getNextPageName() == "two") - return two; - if(one.getNextPageName() == "three") - return three; - - return super.getNextPage(page); - } - -} +package eu.scasefp7.eclipse.core.ui.wizards; + +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.Wizard; + +public class DeployWizard extends Wizard { + protected DeployWizardPageOne one; + protected DeployWizardPageTwo two; + protected DeployWizardPageThree three; + + private static final String PAGE_ONE_NAME = "First page"; + private static final String PAGE_TWO_NAME = "Deploy generated service"; + private static final String PAGE_THREE_NAME = "Third page"; + private static final String WIZARD_NAME = "Service deployment"; + + + public DeployWizard() { + super(); + setNeedsProgressMonitor(true); + } + + @Override + public String getWindowTitle() { + return WIZARD_NAME; + } + + + @Override + public void addPages() { + one = new DeployWizardPageOne(PAGE_ONE_NAME); + two = new DeployWizardPageTwo(PAGE_TWO_NAME); + three = new DeployWizardPageThree(PAGE_THREE_NAME); +// addPage(one); + addPage(two); +// addPage(three); + } + + + @Override + public boolean performFinish() { + // TODO Auto-generated method stub + return true; + } + @Override + public IWizardPage getNextPage(IWizardPage page) { + + if(one.getNextPageName() == "two") + return two; + if(one.getNextPageName() == "three") + return three; + + return super.getNextPage(page); + } + +} diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/DeployWizardPageOne.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/DeployWizardPageOne.java index 2f822c3..2c79f26 100644 --- a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/DeployWizardPageOne.java +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/DeployWizardPageOne.java @@ -1,102 +1,102 @@ -package eu.scasefp7.eclipse.core.ui.wizards; - -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; - -/** - * @author Marin Orlic - */ -public class DeployWizardPageOne extends WizardPage { - private String nextPage = "two"; - protected DeployWizardPageOne(String pageName) { - super(pageName); - setTitle(pageName); - } - - @Override - public void createControl(Composite parent) { - final Composite composite = new Composite(parent, SWT.NONE); - composite.setFont(parent.getFont()); - GridLayout layout = new GridLayout(2, false); - composite.setLayout(layout); - composite.setLayoutData(new GridData(SWT.BEGINNING)); - - - new Label(composite, SWT.NONE); - new Label(composite, SWT.NONE); - new Label(composite, SWT.NONE); - - Label lblLabel = new Label(composite, SWT.NONE); - lblLabel.setText("Label1"); - new Label(composite, SWT.NONE); - - Button btnCompile = new Button(composite, SWT.NONE); - btnCompile.setText("Compile"); - btnCompile.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event e) { - switch (e.type) { - case SWT.Selection: - //TODO define what happens here - System.out.println("Compile button pressed"); - break; - } - } - - }); - new Label(composite, SWT.NONE); - - Button btnRadioButton = new Button(composite, SWT.RADIO); - btnRadioButton.setText("Radio Button1"); - btnRadioButton.addSelectionListener(new SelectionListener() { - @Override - public void widgetSelected(SelectionEvent e) { - boolean isSelected = ((Button)e.getSource()).getSelection(); - if(isSelected) - nextPage = "two"; - } - @Override - public void widgetDefaultSelected(SelectionEvent e) { - // TODO Auto-generated method stub - } - }); - new Label(composite, SWT.NONE); - - Button btnRadioButton_1 = new Button(composite, SWT.RADIO); - btnRadioButton_1.setText("Radio Button2"); - btnRadioButton_1.addSelectionListener(new SelectionListener() { - @Override - public void widgetSelected(SelectionEvent e) { - boolean isSelected = ((Button)e.getSource()).getSelection(); - if(isSelected) - nextPage = "three"; - - } - @Override - public void widgetDefaultSelected(SelectionEvent e) { - // TODO Auto-generated method stub - } - }); - - this.setControl(composite); - setPageComplete(false); - - } - public String getNextPageName() { - return nextPage; - } - @Override - public boolean canFlipToNextPage() { - return true; - } - -} +package eu.scasefp7.eclipse.core.ui.wizards; + +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; + +/** + * @author Marin Orlic + */ +public class DeployWizardPageOne extends WizardPage { + private String nextPage = "two"; + protected DeployWizardPageOne(String pageName) { + super(pageName); + setTitle(pageName); + } + + @Override + public void createControl(Composite parent) { + final Composite composite = new Composite(parent, SWT.NONE); + composite.setFont(parent.getFont()); + GridLayout layout = new GridLayout(2, false); + composite.setLayout(layout); + composite.setLayoutData(new GridData(SWT.BEGINNING)); + + + new Label(composite, SWT.NONE); + new Label(composite, SWT.NONE); + new Label(composite, SWT.NONE); + + Label lblLabel = new Label(composite, SWT.NONE); + lblLabel.setText("Label1"); + new Label(composite, SWT.NONE); + + Button btnCompile = new Button(composite, SWT.NONE); + btnCompile.setText("Compile"); + btnCompile.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event e) { + switch (e.type) { + case SWT.Selection: + //TODO define what happens here + System.out.println("Compile button pressed"); + break; + } + } + + }); + new Label(composite, SWT.NONE); + + Button btnRadioButton = new Button(composite, SWT.RADIO); + btnRadioButton.setText("Radio Button1"); + btnRadioButton.addSelectionListener(new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent e) { + boolean isSelected = ((Button)e.getSource()).getSelection(); + if(isSelected) + nextPage = "two"; + } + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // TODO Auto-generated method stub + } + }); + new Label(composite, SWT.NONE); + + Button btnRadioButton_1 = new Button(composite, SWT.RADIO); + btnRadioButton_1.setText("Radio Button2"); + btnRadioButton_1.addSelectionListener(new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent e) { + boolean isSelected = ((Button)e.getSource()).getSelection(); + if(isSelected) + nextPage = "three"; + + } + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // TODO Auto-generated method stub + } + }); + + this.setControl(composite); + setPageComplete(false); + + } + public String getNextPageName() { + return nextPage; + } + @Override + public boolean canFlipToNextPage() { + return true; + } + +} diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/DeployWizardPageTwo.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/DeployWizardPageTwo.java index 2b6df0c..6a2005e 100644 --- a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/DeployWizardPageTwo.java +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/DeployWizardPageTwo.java @@ -1,81 +1,81 @@ -package eu.scasefp7.eclipse.core.ui.wizards; - -import java.net.MalformedURLException; -import java.net.URL; - -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyledText; -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.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Link; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.browser.IWebBrowser; - -import eu.scasefp7.eclipse.core.ui.Activator; -import org.eclipse.swt.widgets.Text; - -/** - * Wizard intended to help users deploy generated services. - * - * @author Leonora Gaspar - * @author Marin Orlic - */ -public class DeployWizardPageTwo extends WizardPage { - - protected DeployWizardPageTwo(String pageName) { - super(pageName); - setTitle(pageName); - } - - @Override - public void createControl(Composite parent) { - final Composite composite = new Composite(parent, SWT.NONE); - initializeDialogUnits(parent); - composite.setFont(parent.getFont()); - - GridLayout layout = new GridLayout(); - layout.marginWidth = 0; - layout.marginHeight = 0; - composite.setLayout(layout); - composite.setLayoutData(new GridData(GridData.FILL_BOTH)); - - new Label(composite, SWT.NONE); - - StyledText styledText = new StyledText (composite, SWT.MULTI); - styledText.setEditable(false); - //styledText.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_BACKGROUND)); - styledText.setText("To start the generated web service, create a WAR file using Maven with the goal 'package'.\n " - + "The created WAR file is ready to be deployed on a web server that supports Java JAX-RS web service.\n" - + "Your web service will connect to the database using credentials configured in the project.\n"); - - String url = "http://s-case.github.io/webbook.html"; - this.setControl(composite); - new Label(composite, SWT.NONE); - - Label lblMoreInformation = new Label(composite, SWT.NONE); - lblMoreInformation.setText("More information:"); - Link link = new Link(composite, SWT.NONE); - link.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1)); - link.setText("" + url + ""); //$NON-NLS-1$ //$NON-NLS-2$ - link.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - IWebBrowser browser; - try { - browser = PlatformUI.getWorkbench().getBrowserSupport().createBrowser("browser"); - browser.openURL(new URL(url)); - } catch (PartInitException | MalformedURLException e1) { - Activator.log("Unable to open browser.", e1); - } - - } - }); - setPageComplete(true); - - } -} +package eu.scasefp7.eclipse.core.ui.wizards; + +import java.net.MalformedURLException; +import java.net.URL; + +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyledText; +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.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Link; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.browser.IWebBrowser; + +import eu.scasefp7.eclipse.core.ui.Activator; +import org.eclipse.swt.widgets.Text; + +/** + * Wizard intended to help users deploy generated services. + * + * @author Leonora Gaspar + * @author Marin Orlic + */ +public class DeployWizardPageTwo extends WizardPage { + + protected DeployWizardPageTwo(String pageName) { + super(pageName); + setTitle(pageName); + } + + @Override + public void createControl(Composite parent) { + final Composite composite = new Composite(parent, SWT.NONE); + initializeDialogUnits(parent); + composite.setFont(parent.getFont()); + + GridLayout layout = new GridLayout(); + layout.marginWidth = 0; + layout.marginHeight = 0; + composite.setLayout(layout); + composite.setLayoutData(new GridData(GridData.FILL_BOTH)); + + new Label(composite, SWT.NONE); + + StyledText styledText = new StyledText (composite, SWT.MULTI); + styledText.setEditable(false); + //styledText.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_BACKGROUND)); + styledText.setText("To start the generated web service, create a WAR file using Maven with the goal 'package'.\n " + + "The created WAR file is ready to be deployed on a web server that supports Java JAX-RS web service.\n" + + "Your web service will connect to the database using credentials configured in the project.\n"); + + String url = "http://s-case.github.io/webbook.html"; + this.setControl(composite); + new Label(composite, SWT.NONE); + + Label lblMoreInformation = new Label(composite, SWT.NONE); + lblMoreInformation.setText("More information:"); + Link link = new Link(composite, SWT.NONE); + link.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1)); + link.setText("" + url + ""); //$NON-NLS-1$ //$NON-NLS-2$ + link.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + IWebBrowser browser; + try { + browser = PlatformUI.getWorkbench().getBrowserSupport().createBrowser("browser"); + browser.openURL(new URL(url)); + } catch (PartInitException | MalformedURLException e1) { + Activator.log("Unable to open browser.", e1); + } + + } + }); + setPageComplete(true); + + } +} diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/IScaseWizardPage.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/IScaseWizardPage.java new file mode 100644 index 0000000..9121746 --- /dev/null +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/IScaseWizardPage.java @@ -0,0 +1,10 @@ +package eu.scasefp7.eclipse.core.ui.wizards; + +import org.eclipse.core.resources.IResource; +import org.eclipse.jface.wizard.IWizardPage; + +public interface IScaseWizardPage extends IWizardPage { + + public boolean performFinish(IResource resource); + +} diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/NewScaseProjectWizard2.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/NewScaseProjectWizard2.java index a6a1056..8b92092 100644 --- a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/NewScaseProjectWizard2.java +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/NewScaseProjectWizard2.java @@ -1,109 +1,156 @@ -package eu.scasefp7.eclipse.core.ui.wizards; - - -import java.lang.reflect.InvocationTargetException; -import java.net.URI; -import java.util.ArrayList; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.Platform; -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.WizardNewProjectCreationPage; - -import eu.scasefp7.eclipse.core.ui.ScaseUiConstants; - -/** - * @author Leonora Gaspar - * @author Marin Orlic - */ -public class NewScaseProjectWizard2 extends Wizard implements INewWizard { - - private static final String CONTRIBUTION_CLASS = "class"; - private static final String CONTRIBUTION_TITLE = "title"; - private static final String CONTRIBUTION_DESCRIPTION = "description"; - private static final String CONTRIBUTION_PAGE = "page"; - - private static final String PAGE_NAME = "Project name"; - private static final String WIZARD_NAME = "New S-CASE Project"; - - private WizardNewProjectCreationPage _pageOne; - //private PropertyWizardPage _pageTwo; - private ArrayList _pages = new ArrayList(); - - - /** - * - */ - public NewScaseProjectWizard2() { - setWindowTitle(WIZARD_NAME); - } - - - @Override - public void init(IWorkbench workbench, IStructuredSelection selection) { - - } - - @Override - public void addPages() { - super.addPages(); - IExtensionRegistry registry = Platform.getExtensionRegistry(); - IConfigurationElement[] contributions = registry.getConfigurationElementsFor(ScaseUiConstants.NEWPROJECTPAGES_EXTENSION); - - // Add first page to be able to create a project - _pageOne = new WizardNewProjectCreationPage(PAGE_NAME); - _pageOne.setTitle("Create a new S-CASE Project"); - _pageOne.setDescription("Enter project name."); - addPage(_pageOne); - - // Add contributions - if(contributions.length > 0) { - // Create the configured items - for (IConfigurationElement elem : contributions) { - if(elem.getName().equals(CONTRIBUTION_PAGE)) { - try { - String className = elem.getAttribute(CONTRIBUTION_CLASS); - String description = elem.getAttribute(CONTRIBUTION_DESCRIPTION); - String title = elem.getAttribute(CONTRIBUTION_TITLE); - - Class clazz = Class.forName(className).asSubclass(IProjectWizardPage.class); - IProjectWizardPage page = (IProjectWizardPage) clazz.getDeclaredConstructor(String.class).newInstance(title); - - page.setTitle(title); - page.setDescription(description); - _pages.add(page); - addPage(page); - } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - } - } - - @Override - public boolean performFinish() { - - String name = _pageOne.getProjectName(); - URI location = null; - if (!_pageOne.useDefaults()) { - location = _pageOne.getLocationURI(); - } - - IResource res = ScaseProjectSupport.createProject(name, location); - - for(IProjectWizardPage page : _pages) { - if(!page.performFinish(res)) { - return false; - } - } - - return true; - } +package eu.scasefp7.eclipse.core.ui.wizards; + + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExecutableExtension; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.IRegistryEventListener; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.RegistryFactory; +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.WizardNewProjectCreationPage; + +import eu.scasefp7.eclipse.core.ui.ScaseUiConstants; + +/** + * @author Leonora Gaspar + * @author Marin Orlic + */ +public class NewScaseProjectWizard2 extends Wizard implements INewWizard, IExecutableExtension, IRegistryEventListener { + + private static final String CONTRIBUTION_CLASS = "class"; + private static final String CONTRIBUTION_TITLE = "title"; + private static final String CONTRIBUTION_DESCRIPTION = "description"; + private static final String CONTRIBUTION_PAGE = "page"; + + private static final String PAGE_NAME = "Project name"; + private static final String WIZARD_NAME = "New S-CASE Project"; + + private WizardNewProjectCreationPage _pageOne; + + + private List _pages = new ArrayList(); + + + public NewScaseProjectWizard2() { + setWindowTitle(WIZARD_NAME); + //RegistryFactory.getRegistry().addListener(this, ScaseUiConstants.NEWPROJECT_EXTENSION); + } + + + @Override + public void init(IWorkbench workbench, IStructuredSelection selection) { + + } + + @Override + public void addPages() { + super.addPages(); + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IConfigurationElement[] contributions = registry.getConfigurationElementsFor(ScaseUiConstants.NEWPROJECTPAGES_EXTENSION); + + // Add first page to be able to create a project + _pageOne = new WizardNewProjectCreationPage(PAGE_NAME); + _pageOne.setTitle("Create a new S-CASE Project"); + _pageOne.setDescription("Enter project name."); + addPage(_pageOne); + + // Add contributions + if (contributions.length > 0) { + // Create the configured items + for (IConfigurationElement elem : contributions) { + if (elem.getName().equals(CONTRIBUTION_PAGE)) { + + String className = elem.getAttribute(CONTRIBUTION_CLASS); + String description = elem.getAttribute(CONTRIBUTION_DESCRIPTION); + String title = elem.getAttribute(CONTRIBUTION_TITLE); + + try { + Class c = Class.forName(className).asSubclass(IScaseWizardPage.class); + IScaseWizardPage p = (IScaseWizardPage) c.getDeclaredConstructor(String.class).newInstance(title); + + p.setTitle(title); + p.setDescription(description); + + _pages.add(p); + addPage(p); + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + } + } + + + + } + + @Override + public boolean performFinish() { + + String name = _pageOne.getProjectName(); + URI location = null; + if (!_pageOne.useDefaults()) { + location = _pageOne.getLocationURI(); + } + + IResource res = ScaseProjectSupport.createProject(name, location); + + for (IScaseWizardPage page : _pages) + page.performFinish(res); + + return true; + } + + + @Override + public void setInitializationData(IConfigurationElement config, + String propertyName, Object data) throws CoreException { + // TODO Auto-generated method stub + + } + + + @Override + public void added(IExtension[] extensions) { + // TODO Auto-generated method stub + + } + + + @Override + public void removed(IExtension[] extensions) { + // TODO Auto-generated method stub + + } + + + @Override + public void added(IExtensionPoint[] extensionPoints) { + // TODO Auto-generated method stub + + } + + + @Override + public void removed(IExtensionPoint[] extensionPoints) { + // TODO Auto-generated method stub + + } + } \ No newline at end of file diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/ProjectDomainWizardPage.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/ProjectDomainWizardPage.java new file mode 100644 index 0000000..9c2f443 --- /dev/null +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/ProjectDomainWizardPage.java @@ -0,0 +1,240 @@ +package eu.scasefp7.eclipse.core.ui.wizards; + + + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.QualifiedName; +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.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.FilteredTree; +import org.eclipse.ui.dialogs.PatternFilter; + +import eu.scasefp7.eclipse.core.ui.preferences.DomainBoldLabelProvider; +import eu.scasefp7.eclipse.core.ui.preferences.DomainContentProvider; +import eu.scasefp7.eclipse.core.ui.preferences.internal.DomainEntry; +import eu.scasefp7.eclipse.core.ui.preferences.internal.IProjectDomains; +import eu.scasefp7.eclipse.core.ui.preferences.DomainBoldLabelProvider; + +public class ProjectDomainWizardPage extends WizardPage { + + private static final String DOMAIN_PROPERTY = "eu.scasefp7.eclipse.core.projectDomain"; + private static final int DOMAIN_DEFAULT = -1; + + private Label domainLabel; + + private boolean locked; + + private Composite composite; + private Composite cmpLabels; + + protected DomainFilteredTree filteredTree; + protected TreeViewer treeViewer; + + protected ProjectDomainWizardPage(String pageName) { + super(pageName); + + } + public Label getDomainLabel(){ + + return domainLabel; + + } + @Override + public void createControl(Composite parent) { + initializeDialogUnits(parent); + + composite = new Composite(parent, SWT.NONE); + GridLayout gl_composite = new GridLayout(); + gl_composite.marginWidth = 0; + gl_composite.marginHeight = 0; + composite.setLayout(gl_composite); + GridData data = new GridData(GridData.FILL); + data.grabExcessHorizontalSpace = true; + composite.setLayoutData(data); + + int domainId = DOMAIN_DEFAULT; + + // Add the domain label + createDomainLabel(composite, (domainId != DOMAIN_DEFAULT) ? domainId : null); + + // Add tree + treeViewer = createTreeViewer(composite); + + // Load the saved property + selectSavedItem(); + + setControl(composite); + + } + + private void createDomainLabel(Composite parent, Object data) { + cmpLabels = new Composite(parent, SWT.NONE); + GridLayout gl_cmpLabels = new GridLayout(2, false); + gl_cmpLabels.marginWidth = 0; + cmpLabels.setLayout(gl_cmpLabels); + cmpLabels.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); + + // Add label + Label noteLabel = new Label(cmpLabels, SWT.NONE); + noteLabel.setText("Project do&main:"); + + domainLabel = new Label(cmpLabels, SWT.NONE); + domainLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + domainLabel.setText("(select a domain)"); + domainLabel.setData(data); + } + + + + protected class DomainFilteredTree extends FilteredTree { + private ViewerFilter viewerFilter; + + DomainFilteredTree(Composite parent, int treeStyle, PatternFilter filter) { + super(parent, treeStyle, filter, true); + } + + protected void addFilter(ViewerFilter filter) { + viewerFilter = filter; + getViewer().addFilter(filter); + + if (filterText != null) { + setFilterText("type filter text"); + textChanged(); + } + } + + protected void updateToolbar(boolean visible) { + super.updateToolbar((viewerFilter != null) || (visible)); + } + + protected void clearText() { + setFilterText(""); + + if ((!locked) && (viewerFilter != null)) { + getViewer().removeFilter(viewerFilter); + viewerFilter = null; + } + textChanged(); + } + } + + protected TreeViewer createTreeViewer(Composite parent) { + TreeViewer tree; + + filteredTree = new DomainFilteredTree(parent, SWT.FILL, new PatternFilter()); + filteredTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); +// horizontalIndent = 7; + filteredTree.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + + tree = filteredTree.getViewer(); + + setContentAndLabelProviders(tree); + tree.setInput(IProjectDomains.PROJECT_DOMAINS); + + tree.addSelectionChangedListener(new ISelectionChangedListener() { + + public void selectionChanged(SelectionChangedEvent event) { + handleTreeSelectionChanged(event); + } + + }); + + //super.addListeners(tree); + return tree; + } + + private DomainEntry findDomainById(DomainEntry[] domains, int domainId) { + for (DomainEntry de : domains) { + if (de.getId() == domainId) { + return de; + } + if(de.hasChildren()) { + for (DomainEntry child : de.getChildren()) { + if(child.getId() == domainId) { + return child; + } + } + } + } + return null; + } + + protected DomainEntry getSingleSelection(ISelection selection) + { + if (!selection.isEmpty()) { + IStructuredSelection structured = (IStructuredSelection)selection; + if ((structured.getFirstElement() instanceof DomainEntry)) { + return (DomainEntry)structured.getFirstElement(); + } + } + return null; + } + + protected void handleTreeSelectionChanged(SelectionChangedEvent event) { + DomainEntry de = getSingleSelection(event.getSelection()); + updateDomainLabel(de); + } + + + + + protected void selectSavedItem() + { + DomainEntry[] domains = IProjectDomains.PROJECT_DOMAINS; + treeViewer.setInput(domains); + + int domainId = DOMAIN_DEFAULT; + + DomainEntry domain = findDomainById(domains, domainId); + if (domain != null) { + treeViewer.setSelection(new StructuredSelection(domain), true); + } + + // Set focus to tree or the filter control + if (treeViewer.getTree().getItemCount() > 1) { + Text filterText = filteredTree.getFilterControl(); + if (filterText != null) { + filterText.setFocus(); + } + } else { + treeViewer.getControl().setFocus(); + } + } + + protected void setContentAndLabelProviders(TreeViewer treeViewer) + { + treeViewer.setLabelProvider(new DomainBoldLabelProvider(filteredTree )); + treeViewer.setContentProvider(new DomainContentProvider()); + } + + private void updateDomainLabel(DomainEntry domain) { + if(domain == null) + return; + + DomainEntry parent = domain.getParent(); + + if(parent != null) { + String text = parent.getName() + "/" + domain.getName(); + + // Escape text for SWT + domainLabel.setText(text.replaceAll("&", "&&")); //$NON-NLS-1$ //$NON-NLS-2$ + domainLabel.setData(domain); + } + } + +} diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/ProjectFoldersWizardPage.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/ProjectFoldersWizardPage.java index 8231cc6..5ba209c 100644 --- a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/ProjectFoldersWizardPage.java +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/ProjectFoldersWizardPage.java @@ -1,307 +1,307 @@ -package eu.scasefp7.eclipse.core.ui.wizards; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.jface.wizard.IWizardPage; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.dialogs.ContainerSelectionDialog; - -import eu.scasefp7.eclipse.core.ui.Activator; -import eu.scasefp7.eclipse.core.ui.ScaseUiConstants; - - -/** - * Create project folders during project creation. - * - * @author Leonora Gaspar - * @author Marin Orlic - */ -public class ProjectFoldersWizardPage extends WizardPage implements IWizardPage{ - String modelsPath = ""; - String outputPath = ""; - String reqPath = ""; - String comPath = ""; - - protected ProjectFoldersWizardPage(String pageName) { - super(pageName); - // TODO Auto-generated constructor stub - } - - @Override - public void createControl(Composite parent) { - initializeDialogUnits(parent); - - final Composite composite= new Composite(parent, SWT.NULL); - composite.setFont(parent.getFont()); - GridLayout layout = new GridLayout(); - layout.numColumns = 3; - composite.setLayout(layout); - composite.setLayoutData(new GridData(SWT.BEGINNING)); - - Label a = new Label(composite, SWT.NULL); - a.setText ("The models will be stored in folder:"); - GridData gridData1 = new GridData(); - gridData1.horizontalAlignment = GridData.FILL; - gridData1.horizontalSpan = 3; - a.setLayoutData(gridData1); - - Label label = new Label(composite, SWT.NULL); - Text models = new Text(composite, SWT.BORDER); - GridData gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.grabExcessHorizontalSpace = true; - - final Button button = new Button(composite, SWT.PUSH); - - label.setText("Models folder path: "); - models.setText("models"); - models.setEnabled(false); - button.setText("Browse..."); - models.setLayoutData(gridData); - - - IContainer root = ResourcesPlugin.getWorkspace().getRoot(); - button.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event e) { - Path resPath; - switch (e.type) { - case SWT.Selection: - - ContainerSelectionDialog dlg = new ContainerSelectionDialog (parent.getShell(), root, true, null); - dlg.setMessage("Select a folder"); - dlg.open(); - Object[] res = dlg.getResult(); - if(res != null) - { - resPath = (Path) res[0]; - models.setText(resPath.toString()); - modelsPath = resPath.toString(); - } - - break; - } - } - - }); - - //Empty row - Label e1 = new Label(composite, SWT.NULL); - GridData gridData11 = new GridData(); - gridData11.horizontalAlignment = GridData.FILL; - gridData11.horizontalSpan = 3; - e1.setLayoutData(gridData11); - - Label a2 = new Label(composite, SWT.NULL); - a2.setText ("The generated code will be stored in folder:"); - GridData gridData2 = new GridData(); - gridData2.horizontalAlignment = GridData.FILL; - gridData2.horizontalSpan = 3; - a2.setLayoutData(gridData2); - - GridData gridData3 = new GridData(); - gridData3.horizontalAlignment = SWT.FILL; - gridData3.grabExcessHorizontalSpace = true; - Label label2 = new Label(composite, SWT.NULL); - Text output = new Text(composite, SWT.BORDER); - final Button button2 = new Button(composite, SWT.PUSH); - - label2.setText("Output folder path: "); - output.setText("output"); - output.setEnabled(false); - button2.setText("Browse..."); - output.setLayoutData(gridData3); - - button2.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event e) { - Path resPath; - switch (e.type) { - case SWT.Selection: - - ContainerSelectionDialog dlg = new ContainerSelectionDialog (parent.getShell(), root, true, null); - dlg.setMessage("Select a folder"); - dlg.open(); - Object[] res = dlg.getResult(); - if(res != null) - { - resPath = (Path ) res[0]; - output.setText(resPath.toString()); - outputPath = resPath.toString(); - } - - break; - } - } - - }); - - //Empty row - Label e2 = new Label(composite, SWT.NULL); - GridData gridData21 = new GridData(); - gridData21.horizontalAlignment = GridData.FILL; - gridData21.horizontalSpan = 3; - e2.setLayoutData(gridData21); - - Label a3 = new Label(composite, SWT.NULL); - a3.setText ("The requirements will be stored in folder:"); - - GridData gridData31 = new GridData(); - gridData31.horizontalAlignment = GridData.FILL; - gridData31.horizontalSpan = 3; - a3.setLayoutData(gridData31); - - GridData gridData4 = new GridData(); - gridData4.horizontalAlignment = SWT.FILL; - gridData4.grabExcessHorizontalSpace = true; - Label label3 = new Label(composite, SWT.NULL); - Text requirements = new Text(composite, SWT.BORDER); - final Button button3 = new Button(composite, SWT.PUSH); - - label3.setText("Requirements folder path: "); - requirements.setText("requirements"); - requirements.setEnabled(false); - button3.setText("Browse..."); - requirements.setLayoutData(gridData4); - - button3.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event e) { - Path resPath; - switch (e.type) { - case SWT.Selection: - - ContainerSelectionDialog dlg = new ContainerSelectionDialog (parent.getShell(), root, true, null); - dlg.setMessage("Select a folder"); - dlg.open(); - Object[] res = dlg.getResult(); - if(res != null) - { - resPath = (Path ) res[0]; - requirements.setText(resPath.toString()); - reqPath = resPath.toString(); - } - - break; - } - } - - }); - - //Empty row - Label e3 = new Label(composite, SWT.NULL); - GridData gridData32 = new GridData(); - gridData32.horizontalAlignment = GridData.FILL; - gridData32.horizontalSpan = 3; - e3.setLayoutData(gridData32); - - Label a4 = new Label(composite, SWT.NULL); - a4.setText ("The storyboards used for composition will be in folder:"); - GridData gridData41 = new GridData(); - gridData41.horizontalAlignment = GridData.FILL; - gridData41.horizontalSpan = 3; - a4.setLayoutData(gridData41); - - Label label4 = new Label(composite, SWT.NULL); - Text compositions = new Text(composite, SWT.BORDER); - final Button button4 = new Button(composite, SWT.PUSH); - - GridData gridData6 = new GridData(); - gridData6.horizontalAlignment = SWT.FILL; - gridData6.grabExcessHorizontalSpace = true; - - label4.setText("Compositions folder path: "); - compositions.setText("compositions"); - compositions.setEnabled(false); - button4.setText("Browse..."); - compositions.setLayoutData(gridData6); - - button4.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event e) { - Path resPath; - switch (e.type) { - case SWT.Selection: - - ContainerSelectionDialog dlg = new ContainerSelectionDialog (parent.getShell(), root, true, null); - dlg.setMessage("Select a folder"); - dlg.open(); - Object[] res = dlg.getResult(); - if(res != null) - { - resPath = (Path ) res[0]; - compositions.setText(resPath.toString()); - comPath = resPath.toString(); - } - - break; - } - } - - }); - - - - setControl(composite); - } - - /** - * Creates the project folders. - * @param resource - * @return true if the folders were created successfully. - */ - public boolean performFinish(IResource resource) { - IProject project = (IProject) resource; - IFolder models = project.getFolder("models"); - IFolder output = project.getFolder("output"); - IFolder requirements = project.getFolder("requirements"); - IFolder compositions = project.getFolder("compositions"); - - IProgressMonitor monitor = new NullProgressMonitor(); - try { - models.create(true, true, monitor); - output.create(true, true, monitor); - requirements.create(true, true, monitor); - compositions.create(true, true, monitor); - } catch (CoreException e) { - Activator.log("Unable to create project folders.", e); - } - - if(modelsPath.equals("")) - modelsPath = models.getProjectRelativePath().toPortableString(); - if(outputPath.equals("")) - outputPath = output.getProjectRelativePath().toPortableString(); - if(reqPath.equals("")) - reqPath = requirements.getProjectRelativePath().toPortableString(); - if(comPath.equals("")) - comPath = compositions.getProjectRelativePath().toPortableString(); - - try { - project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.MODELS_FOLDER), modelsPath); - project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.OUTPUT_FOLDER), outputPath); - project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.REQUIREMENTS_FOLDER), reqPath); - project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.COMPOSITIONS_FOLDER), comPath); - } catch (CoreException e) { - Activator.log("Unable to set project properties.", e); - } - return false; - } - +package eu.scasefp7.eclipse.core.ui.wizards; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.ContainerSelectionDialog; + +import eu.scasefp7.eclipse.core.ui.Activator; +import eu.scasefp7.eclipse.core.ui.ScaseUiConstants; + + +/** + * Create project folders during project creation. + * + * @author Leonora Gaspar + * @author Marin Orlic + */ +public class ProjectFoldersWizardPage extends WizardPage implements IWizardPage{ + String modelsPath = ""; + String outputPath = ""; + String reqPath = ""; + String comPath = ""; + + protected ProjectFoldersWizardPage(String pageName) { + super(pageName); + // TODO Auto-generated constructor stub + } + + @Override + public void createControl(Composite parent) { + initializeDialogUnits(parent); + + final Composite composite= new Composite(parent, SWT.NULL); + composite.setFont(parent.getFont()); + GridLayout layout = new GridLayout(); + layout.numColumns = 3; + composite.setLayout(layout); + composite.setLayoutData(new GridData(SWT.BEGINNING)); + + Label a = new Label(composite, SWT.NULL); + a.setText ("The models will be stored in folder:"); + GridData gridData1 = new GridData(); + gridData1.horizontalAlignment = GridData.FILL; + gridData1.horizontalSpan = 3; + a.setLayoutData(gridData1); + + Label label = new Label(composite, SWT.NULL); + Text models = new Text(composite, SWT.BORDER); + GridData gridData = new GridData(); + gridData.horizontalAlignment = SWT.FILL; + gridData.grabExcessHorizontalSpace = true; + + final Button button = new Button(composite, SWT.PUSH); + + label.setText("Models folder path: "); + models.setText("models"); + models.setEnabled(false); + button.setText("Browse..."); + models.setLayoutData(gridData); + + + IContainer root = ResourcesPlugin.getWorkspace().getRoot(); + button.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event e) { + Path resPath; + switch (e.type) { + case SWT.Selection: + + ContainerSelectionDialog dlg = new ContainerSelectionDialog (parent.getShell(), root, true, null); + dlg.setMessage("Select a folder"); + dlg.open(); + Object[] res = dlg.getResult(); + if(res != null) + { + resPath = (Path) res[0]; + models.setText(resPath.toString()); + modelsPath = resPath.toString(); + } + + break; + } + } + + }); + + //Empty row + Label e1 = new Label(composite, SWT.NULL); + GridData gridData11 = new GridData(); + gridData11.horizontalAlignment = GridData.FILL; + gridData11.horizontalSpan = 3; + e1.setLayoutData(gridData11); + + Label a2 = new Label(composite, SWT.NULL); + a2.setText ("The generated code will be stored in folder:"); + GridData gridData2 = new GridData(); + gridData2.horizontalAlignment = GridData.FILL; + gridData2.horizontalSpan = 3; + a2.setLayoutData(gridData2); + + GridData gridData3 = new GridData(); + gridData3.horizontalAlignment = SWT.FILL; + gridData3.grabExcessHorizontalSpace = true; + Label label2 = new Label(composite, SWT.NULL); + Text output = new Text(composite, SWT.BORDER); + final Button button2 = new Button(composite, SWT.PUSH); + + label2.setText("Output folder path: "); + output.setText("output"); + output.setEnabled(false); + button2.setText("Browse..."); + output.setLayoutData(gridData3); + + button2.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event e) { + Path resPath; + switch (e.type) { + case SWT.Selection: + + ContainerSelectionDialog dlg = new ContainerSelectionDialog (parent.getShell(), root, true, null); + dlg.setMessage("Select a folder"); + dlg.open(); + Object[] res = dlg.getResult(); + if(res != null) + { + resPath = (Path ) res[0]; + output.setText(resPath.toString()); + outputPath = resPath.toString(); + } + + break; + } + } + + }); + + //Empty row + Label e2 = new Label(composite, SWT.NULL); + GridData gridData21 = new GridData(); + gridData21.horizontalAlignment = GridData.FILL; + gridData21.horizontalSpan = 3; + e2.setLayoutData(gridData21); + + Label a3 = new Label(composite, SWT.NULL); + a3.setText ("The requirements will be stored in folder:"); + + GridData gridData31 = new GridData(); + gridData31.horizontalAlignment = GridData.FILL; + gridData31.horizontalSpan = 3; + a3.setLayoutData(gridData31); + + GridData gridData4 = new GridData(); + gridData4.horizontalAlignment = SWT.FILL; + gridData4.grabExcessHorizontalSpace = true; + Label label3 = new Label(composite, SWT.NULL); + Text requirements = new Text(composite, SWT.BORDER); + final Button button3 = new Button(composite, SWT.PUSH); + + label3.setText("Requirements folder path: "); + requirements.setText("requirements"); + requirements.setEnabled(false); + button3.setText("Browse..."); + requirements.setLayoutData(gridData4); + + button3.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event e) { + Path resPath; + switch (e.type) { + case SWT.Selection: + + ContainerSelectionDialog dlg = new ContainerSelectionDialog (parent.getShell(), root, true, null); + dlg.setMessage("Select a folder"); + dlg.open(); + Object[] res = dlg.getResult(); + if(res != null) + { + resPath = (Path ) res[0]; + requirements.setText(resPath.toString()); + reqPath = resPath.toString(); + } + + break; + } + } + + }); + + //Empty row + Label e3 = new Label(composite, SWT.NULL); + GridData gridData32 = new GridData(); + gridData32.horizontalAlignment = GridData.FILL; + gridData32.horizontalSpan = 3; + e3.setLayoutData(gridData32); + + Label a4 = new Label(composite, SWT.NULL); + a4.setText ("The storyboards used for composition will be in folder:"); + GridData gridData41 = new GridData(); + gridData41.horizontalAlignment = GridData.FILL; + gridData41.horizontalSpan = 3; + a4.setLayoutData(gridData41); + + Label label4 = new Label(composite, SWT.NULL); + Text compositions = new Text(composite, SWT.BORDER); + final Button button4 = new Button(composite, SWT.PUSH); + + GridData gridData6 = new GridData(); + gridData6.horizontalAlignment = SWT.FILL; + gridData6.grabExcessHorizontalSpace = true; + + label4.setText("Compositions folder path: "); + compositions.setText("compositions"); + compositions.setEnabled(false); + button4.setText("Browse..."); + compositions.setLayoutData(gridData6); + + button4.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event e) { + Path resPath; + switch (e.type) { + case SWT.Selection: + + ContainerSelectionDialog dlg = new ContainerSelectionDialog (parent.getShell(), root, true, null); + dlg.setMessage("Select a folder"); + dlg.open(); + Object[] res = dlg.getResult(); + if(res != null) + { + resPath = (Path ) res[0]; + compositions.setText(resPath.toString()); + comPath = resPath.toString(); + } + + break; + } + } + + }); + + + + setControl(composite); + } + + /** + * Creates the project folders. + * @param resource + * @return true if the folders were created successfully. + */ + public boolean performFinish(IResource resource) { + IProject project = (IProject) resource; + IFolder models = project.getFolder("models"); + IFolder output = project.getFolder("output"); + IFolder requirements = project.getFolder("requirements"); + IFolder compositions = project.getFolder("compositions"); + + IProgressMonitor monitor = new NullProgressMonitor(); + try { + models.create(true, true, monitor); + output.create(true, true, monitor); + requirements.create(true, true, monitor); + compositions.create(true, true, monitor); + } catch (CoreException e) { + Activator.log("Unable to create project folders.", e); + } + + if(modelsPath.equals("")) + modelsPath = models.getProjectRelativePath().toPortableString(); + if(outputPath.equals("")) + outputPath = output.getProjectRelativePath().toPortableString(); + if(reqPath.equals("")) + reqPath = requirements.getProjectRelativePath().toPortableString(); + if(comPath.equals("")) + comPath = compositions.getProjectRelativePath().toPortableString(); + + try { + project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.MODELS_FOLDER), modelsPath); + project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.OUTPUT_FOLDER), outputPath); + project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.REQUIREMENTS_FOLDER), reqPath); + project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.COMPOSITIONS_FOLDER), comPath); + } catch (CoreException e) { + Activator.log("Unable to set project properties.", e); + } + return false; + } + } \ No newline at end of file diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/ScaseProjectNewWizard.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/ScaseProjectNewWizard.java new file mode 100644 index 0000000..920675e --- /dev/null +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/ScaseProjectNewWizard.java @@ -0,0 +1,88 @@ +package eu.scasefp7.eclipse.core.ui.wizards; + + +import java.net.URI; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExecutableExtension; +import org.eclipse.core.runtime.QualifiedName; +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.WizardNewProjectCreationPage; + +import eu.scasefp7.eclipse.core.ui.preferences.PropertyWizardPage; +import eu.scasefp7.eclipse.core.ui.preferences.internal.DomainEntry; + + + +public class ScaseProjectNewWizard extends Wizard implements INewWizard, IExecutableExtension { + + private WizardNewProjectCreationPage _pageOne; + private PropertyWizardPage _pageTwo; + private static final String PAGE_NAME = "Custom Plug-in Project Wizard"; + private static final String WIZARD_NAME = "New S-Case Project"; + + public ScaseProjectNewWizard() { + setWindowTitle(WIZARD_NAME); + } + + + @Override + public void init(IWorkbench workbench, IStructuredSelection selection) { + // TODO Auto-generated method stub + + } + @Override + public void addPages() { + super.addPages(); + + _pageOne = new WizardNewProjectCreationPage(PAGE_NAME); + _pageOne.setTitle("Create a S-Case Project"); + _pageOne.setDescription("Enter project name."); + + _pageTwo = new PropertyWizardPage("S-Case project domain"); + _pageTwo.setTitle("Select project domain"); + + addPage(_pageOne); + addPage(_pageTwo); + } + + @Override + public boolean performFinish() { + + String name = _pageOne.getProjectName(); + URI location = null; + if (!_pageOne.useDefaults()) { + location = _pageOne.getLocationURI(); + } // else location == null + + IResource res = ScaseProjectSupport.createProject(name, location); + int k; + org.eclipse.swt.widgets.Label domainLabel = _pageTwo.getDomainLabel(); + DomainEntry de = (DomainEntry) domainLabel.getData(); + if (de == null) + k = -1; + else + k = de.getId(); + try { + res.setPersistentProperty(new QualifiedName("", "eu.scasefp7.eclipse.core.projectDomain"), Integer.toString(k)); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return true; + } + + + @Override + public void setInitializationData(IConfigurationElement config, + String propertyName, Object data) throws CoreException { + // TODO Auto-generated method stub + + } + +} diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/ScaseProjectSupport.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/ScaseProjectSupport.java index 4509eca..3dfb659 100644 --- a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/ScaseProjectSupport.java +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/ScaseProjectSupport.java @@ -1,121 +1,121 @@ -package eu.scasefp7.eclipse.core.ui.wizards; - -import java.net.URI; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; - -import eu.scasefp7.eclipse.core.builder.ScaseNature; -import eu.scasefp7.eclipse.core.ui.Activator; - -/** - * @author Leonora Gašpar - * @author Marin Orlić - */ -public class ScaseProjectSupport { - - /** - * Creates a project in the workspace. - * - * @param projectName name for the new project - * @param location URI - * @return created project - */ - public static IProject createProject(String projectName, URI location) { - Assert.isNotNull(projectName); - Assert.isTrue(projectName.trim().length() > 0); - - IProject project = createBaseProject(projectName, location); - try { - addNature(project); - // Addition of new folders to project - /* - * String[] paths = { "parent/child1-1/child2", "parent/child1-2/child2/child3" }; //$NON-NLS-1$ - * //$NON-NLS-2$ - * addToProjectStructure(project, paths); - */ - } catch (CoreException e) { - Activator.log("Unable to add project nature.", e); - project = null; - } - - return project; - } - - /** - * Create a basic project. - * - * @param location - * @param projectName - */ - private static IProject createBaseProject(String projectName, URI location) { - // it is acceptable to use the ResourcesPlugin class - IProject newProject = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); - - if (!newProject.exists()) { - URI projectLocation = location; - IProjectDescription desc = newProject.getWorkspace().newProjectDescription(newProject.getName()); - if (location != null && ResourcesPlugin.getWorkspace().getRoot().getLocationURI().equals(location)) { - projectLocation = null; - } - - desc.setLocationURI(projectLocation); - try { - newProject.create(desc, null); - if (!newProject.isOpen()) { - newProject.open(null); - } - } catch (CoreException e) { - Activator.log("Unable to create project.", e); - } - } - - return newProject; - } - - private static void createFolder(IFolder folder) throws CoreException { - IContainer parent = folder.getParent(); - if (parent instanceof IFolder) { - createFolder((IFolder) parent); - } - if (!folder.exists()) { - folder.create(false, true, null); - } - } - - /** - * Create a folder structure with a parent root, overlay, and a few child - * folders. - * - * @param newProject - * @param paths - * @throws CoreException - */ - private static void addToProjectStructure(IProject newProject, String[] paths) throws CoreException { - for (String path : paths) { - IFolder etcFolders = newProject.getFolder(path); - createFolder(etcFolders); - } - } - - private static void addNature(IProject project) throws CoreException { - if (!project.hasNature(ScaseNature.NATURE_ID)) { - IProjectDescription description = project.getDescription(); - String[] prevNatures = description.getNatureIds(); - String[] newNatures = new String[prevNatures.length + 1]; - System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length); - newNatures[prevNatures.length] = ScaseNature.NATURE_ID; - description.setNatureIds(newNatures); - - IProgressMonitor monitor = null; - project.setDescription(description, monitor); - } - } - +package eu.scasefp7.eclipse.core.ui.wizards; + +import java.net.URI; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; + +import eu.scasefp7.eclipse.core.builder.ScaseNature; +import eu.scasefp7.eclipse.core.ui.Activator; + +/** + * @author Leonora Gašpar + * @author Marin Orlić + */ +public class ScaseProjectSupport { + + /** + * Creates a project in the workspace. + * + * @param projectName name for the new project + * @param location URI + * @return created project + */ + public static IProject createProject(String projectName, URI location) { + Assert.isNotNull(projectName); + Assert.isTrue(projectName.trim().length() > 0); + + IProject project = createBaseProject(projectName, location); + try { + addNature(project); + // Addition of new folders to project + /* + * String[] paths = { "parent/child1-1/child2", "parent/child1-2/child2/child3" }; //$NON-NLS-1$ + * //$NON-NLS-2$ + * addToProjectStructure(project, paths); + */ + } catch (CoreException e) { + Activator.log("Unable to add project nature.", e); + project = null; + } + + return project; + } + + /** + * Create a basic project. + * + * @param location + * @param projectName + */ + private static IProject createBaseProject(String projectName, URI location) { + // it is acceptable to use the ResourcesPlugin class + IProject newProject = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); + + if (!newProject.exists()) { + URI projectLocation = location; + IProjectDescription desc = newProject.getWorkspace().newProjectDescription(newProject.getName()); + if (location != null && ResourcesPlugin.getWorkspace().getRoot().getLocationURI().equals(location)) { + projectLocation = null; + } + + desc.setLocationURI(projectLocation); + try { + newProject.create(desc, null); + if (!newProject.isOpen()) { + newProject.open(null); + } + } catch (CoreException e) { + Activator.log("Unable to create project.", e); + } + } + + return newProject; + } + + private static void createFolder(IFolder folder) throws CoreException { + IContainer parent = folder.getParent(); + if (parent instanceof IFolder) { + createFolder((IFolder) parent); + } + if (!folder.exists()) { + folder.create(false, true, null); + } + } + + /** + * Create a folder structure with a parent root, overlay, and a few child + * folders. + * + * @param newProject + * @param paths + * @throws CoreException + */ + private static void addToProjectStructure(IProject newProject, String[] paths) throws CoreException { + for (String path : paths) { + IFolder etcFolders = newProject.getFolder(path); + createFolder(etcFolders); + } + } + + private static void addNature(IProject project) throws CoreException { + if (!project.hasNature(ScaseNature.NATURE_ID)) { + IProjectDescription description = project.getDescription(); + String[] prevNatures = description.getNatureIds(); + String[] newNatures = new String[prevNatures.length + 1]; + System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length); + newNatures[prevNatures.length] = ScaseNature.NATURE_ID; + description.setNatureIds(newNatures); + + IProgressMonitor monitor = null; + project.setDescription(description, monitor); + } + } + } \ No newline at end of file diff --git a/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/ScaseProjectWizardPageTwo.java b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/ScaseProjectWizardPageTwo.java new file mode 100644 index 0000000..3e5ba40 --- /dev/null +++ b/eu.scasefp7.eclipse.core.ui/src/eu/scasefp7/eclipse/core/ui/wizards/ScaseProjectWizardPageTwo.java @@ -0,0 +1,291 @@ +package eu.scasefp7.eclipse.core.ui.wizards; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; + +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; + +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.ContainerSelectionDialog; + +import eu.scasefp7.eclipse.core.ui.ScaseUiConstants; + +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.QualifiedName; + + +public class ScaseProjectWizardPageTwo extends WizardPage implements IScaseWizardPage{ + String modelsPath = ""; + String outputPath = ""; + String reqPath = ""; + String comPath = ""; + + protected ScaseProjectWizardPageTwo(String pageName) { + super(pageName); + setTitle(pageName); + } + + + @Override + public void createControl(Composite parent) { + final Composite composite= new Composite(parent, SWT.NULL); + initializeDialogUnits(parent); + composite.setFont(parent.getFont()); + GridLayout layout = new GridLayout(); + layout.numColumns = 3; + composite.setLayout(layout); + composite.setLayoutData(new GridData(SWT.BEGINNING)); + + Label a = new Label(composite, SWT.NULL); + a.setText ("The models will be stored in folder:"); + GridData gridData1 = new GridData(); + gridData1.horizontalAlignment = GridData.FILL; + gridData1.horizontalSpan = 3; + a.setLayoutData(gridData1); + + Label label = new Label(composite, SWT.NULL); + Text models = new Text(composite, SWT.BORDER); + GridData gridData = new GridData(); + gridData.horizontalAlignment = SWT.FILL; + gridData.grabExcessHorizontalSpace = true; + + final Button button = new Button(composite, SWT.PUSH); + + label.setText("Models folder path: "); + models.setText("/models"); + button.setText("Browse..."); + models.setLayoutData(gridData); + + + IContainer root = ResourcesPlugin.getWorkspace().getRoot(); + button.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event e) { + Path resPath; + switch (e.type) { + case SWT.Selection: + + ContainerSelectionDialog dlg = new ContainerSelectionDialog (parent.getShell(), root, true, null); + dlg.setMessage("Select a directory"); + dlg.open(); + Object[] res = dlg.getResult(); + if(res != null) + { + resPath = (Path ) res[0]; + models.setText(resPath.toString()); + modelsPath = resPath.toString(); + } + + break; + } + } + + }); + + //Empty row + Label e1 = new Label(composite, SWT.NULL); + GridData gridData11 = new GridData(); + gridData11.horizontalAlignment = GridData.FILL; + gridData11.horizontalSpan = 3; + e1.setLayoutData(gridData11); + + Label a2 = new Label(composite, SWT.NULL); + a2.setText ("The generated code will be stored in folder:"); + GridData gridData2 = new GridData(); + gridData2.horizontalAlignment = GridData.FILL; + gridData2.horizontalSpan = 3; + a2.setLayoutData(gridData2); + + Label label2 = new Label(composite, SWT.NULL); + Text output = new Text(composite, SWT.BORDER); + final Button button2 = new Button(composite, SWT.PUSH); + + label2.setText("Output folder path: "); + output.setText("/output"); + button2.setText("Browse..."); + output.setLayoutData(gridData); + + button2.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event e) { + Path resPath; + switch (e.type) { + case SWT.Selection: + + ContainerSelectionDialog dlg = new ContainerSelectionDialog (parent.getShell(), root, true, null); + dlg.setMessage("Select a directory"); + dlg.open(); + Object[] res = dlg.getResult(); + if(res != null) + { + resPath = (Path ) res[0]; + output.setText(resPath.toString()); + outputPath = resPath.toString(); + } + + break; + } + } + + }); + + //Empty row + Label e2 = new Label(composite, SWT.NULL); + GridData gridData21 = new GridData(); + gridData21.horizontalAlignment = GridData.FILL; + gridData21.horizontalSpan = 3; + e2.setLayoutData(gridData21); + + Label a3 = new Label(composite, SWT.NULL); + a3.setText ("The requirements will be stored in folder:"); + GridData gridData3 = new GridData(); + gridData3.horizontalAlignment = GridData.FILL; + gridData3.horizontalSpan = 3; + a3.setLayoutData(gridData3); + + Label label3 = new Label(composite, SWT.NULL); + Text requirements = new Text(composite, SWT.BORDER); + final Button button3 = new Button(composite, SWT.PUSH); + + label3.setText("Requirements folder path: "); + requirements.setText("/requirements"); + button3.setText("Browse..."); + requirements.setLayoutData(gridData); + + button3.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event e) { + Path resPath; + switch (e.type) { + case SWT.Selection: + + ContainerSelectionDialog dlg = new ContainerSelectionDialog (parent.getShell(), root, true, null); + dlg.setMessage("Select a directory"); + dlg.open(); + Object[] res = dlg.getResult(); + if(res != null) + { + resPath = (Path ) res[0]; + requirements.setText(resPath.toString()); + reqPath = resPath.toString(); + } + + break; + } + } + + }); + + //Empty row + Label e3 = new Label(composite, SWT.NULL); + GridData gridData31 = new GridData(); + gridData31.horizontalAlignment = GridData.FILL; + gridData31.horizontalSpan = 3; + e3.setLayoutData(gridData31); + + Label a4 = new Label(composite, SWT.NULL); + a4.setText ("The storyboards used for composition will be in folder:"); + GridData gridData4 = new GridData(); + gridData4.horizontalAlignment = GridData.FILL; + gridData4.horizontalSpan = 3; + a4.setLayoutData(gridData4); + + Label label4 = new Label(composite, SWT.NULL); + Text compositions = new Text(composite, SWT.BORDER); + final Button button4 = new Button(composite, SWT.PUSH); + + label4.setText("Compositions folder path: "); + compositions.setText("/compositions"); + button4.setText("Browse..."); + compositions.setLayoutData(gridData); + + button4.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event e) { + Path resPath; + switch (e.type) { + case SWT.Selection: + + ContainerSelectionDialog dlg = new ContainerSelectionDialog (parent.getShell(), root, true, null); + dlg.setMessage("Select a directory"); + dlg.open(); + Object[] res = dlg.getResult(); + if(res != null) + { + resPath = (Path ) res[0]; + compositions.setText(resPath.toString()); + comPath = resPath.toString(); + } + + break; + } + } + + }); + + + + setControl(composite); + } + + + @Override + public boolean performFinish(IResource resource) { + IProject project = (IProject) resource; + IFolder models = project.getFolder("models"); + IFolder output = project.getFolder("output"); + IFolder requirements = project.getFolder("requirements"); + IFolder compositions = project.getFolder("compositions"); + + IProgressMonitor monitor = new NullProgressMonitor(); + try { + models.create(true, true, monitor); + output.create(true, true, monitor); + requirements.create(true, true, monitor); + compositions.create(true, true, monitor); + + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + String projectName = project.getName(); + if(modelsPath.equals("")) + modelsPath = "/" + projectName + "/models"; + if(outputPath.equals("")) + outputPath = "/" + projectName + "/output"; + if(reqPath.equals("")) + reqPath = "/" + projectName + "/requirements"; + if(comPath.equals("")) + comPath = "/" + projectName + "/compositions"; + + try { + project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.MODELS_FOLDER), modelsPath); + project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.OUTPUT_FOLDER), outputPath); + project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.REQUIREMENTS_FOLDER), reqPath); + project.setPersistentProperty(new QualifiedName("", ScaseUiConstants.COMPOSITIONS_FOLDER), comPath); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return false; + } + + @Override + public boolean canFlipToNextPage() { + return false; + } +} diff --git a/eu.scasefp7.eclipse.core.ui/src/org/eclipse/wb/swt/ResourceManager.java b/eu.scasefp7.eclipse.core.ui/src/org/eclipse/wb/swt/ResourceManager.java new file mode 100644 index 0000000..8776b7e --- /dev/null +++ b/eu.scasefp7.eclipse.core.ui/src/org/eclipse/wb/swt/ResourceManager.java @@ -0,0 +1,316 @@ +package org.eclipse.wb.swt; + + import java.io.File; + import java.io.InputStream; + import java.lang.reflect.Constructor; + import java.lang.reflect.Method; + import java.net.MalformedURLException; + import java.net.URL; + import java.util.HashMap; + import java.util.Iterator; + import java.util.Map; + + import org.eclipse.core.runtime.Platform; + import org.eclipse.jface.resource.CompositeImageDescriptor; + import org.eclipse.jface.resource.ImageDescriptor; + import org.eclipse.swt.graphics.Image; + import org.eclipse.swt.graphics.Point; + import org.eclipse.swt.graphics.Rectangle; + import org.osgi.framework.Bundle; + + public class ResourceManager extends SWTResourceManager + { + private static Map m_descriptorImageMap = new HashMap(); + + public static ImageDescriptor getImageDescriptor(Class clazz, String path) + { + return ImageDescriptor.createFromFile(clazz, path); + } + + public static ImageDescriptor getImageDescriptor(String path) + { + try + { + return ImageDescriptor.createFromURL(new File(path).toURI().toURL()); + } catch (MalformedURLException localMalformedURLException) {} + return null; + } + + public static Image getImage(ImageDescriptor descriptor) + { + if (descriptor == null) { + return null; + } + Image image = (Image)m_descriptorImageMap.get(descriptor); + if (image == null) { + image = descriptor.createImage(); + m_descriptorImageMap.put(descriptor, image); + } + return image; + } + + + private static Map>[] m_decoratedImageMap = new Map[5]; + + + public static Image decorateImage(Image baseImage, Image decorator) + { + return decorateImage(baseImage, decorator, 4); + } + + + + + public static Image decorateImage(Image baseImage, final Image decorator, final int corner) + { + if ((corner <= 0) || (corner >= 5)) { + throw new IllegalArgumentException("Wrong decorate corner"); + } + Map> cornerDecoratedImageMap = m_decoratedImageMap[corner]; + if (cornerDecoratedImageMap == null) { + cornerDecoratedImageMap = new HashMap>(); + m_decoratedImageMap[corner] = cornerDecoratedImageMap; + } + Map decoratedMap = (Map)cornerDecoratedImageMap.get(baseImage); + if (decoratedMap == null) { + decoratedMap = new HashMap(); + cornerDecoratedImageMap.put(baseImage, decoratedMap); + } + + Image result = (Image)decoratedMap.get(decorator); + + if (result == null) { + final Rectangle bib = baseImage.getBounds(); + final Rectangle dib = decorator.getBounds(); + + final Point baseImageSize = new Point(bib.width, bib.height); + CompositeImageDescriptor compositImageDesc = new CompositeImageDescriptor() + { + protected void drawCompositeImage(int width, int height) { + drawImage(getImageData(), 0, 0); + int bibwidth = bib.width; + int bibheight = bib.height; + int dibwidth = dib.width; + int dibheight = dib.height; + + if (corner == 1) { + drawImage(decorator.getImageData(), 0, 0); + } else if (corner == 2) { + drawImage(decorator.getImageData(), bibwidth - dibwidth, 0); + } else if (corner == 3) { + drawImage(decorator.getImageData(), 0, bibheight - dibheight); + } else if (corner == 4) { + drawImage(decorator.getImageData(), bibwidth - dibwidth, bibheight - dibheight); + } + } + + protected Point getSize() { + return baseImageSize; + } + + }; + result = compositImageDesc.createImage(); + decoratedMap.put(decorator, result); + } + return result; + } + + + + public static void disposeImages() + { + + + for (Iterator I = m_descriptorImageMap.values().iterator(); I.hasNext();) { + ((Image)I.next()).dispose(); + } + m_descriptorImageMap.clear(); + + + for (int i = 0; i < m_decoratedImageMap.length; i++) { + Map> cornerDecoratedImageMap = m_decoratedImageMap[i]; + if (cornerDecoratedImageMap != null) { + for (Map decoratedMap : cornerDecoratedImageMap.values()) { + for (Image image : decoratedMap.values()) { + image.dispose(); + } + decoratedMap.clear(); + } + cornerDecoratedImageMap.clear(); + } + } + + for (Iterator I = m_URLImageMap.values().iterator(); I.hasNext();) { + ((Image)I.next()).dispose(); + } + m_URLImageMap.clear(); + } + + private static Map m_URLImageMap = new HashMap(); + + + private static PluginResourceProvider m_designTimePluginResourceProvider = null; + + + @Deprecated + public static Image getPluginImage(Object plugin, String name) + { + try + { + URL url = getPluginImageURL(plugin, name); + if (url != null) { + return getPluginImageFromUrl(url); + } + } + catch (Throwable localThrowable) {} + + return null; + } + + + public static Image getPluginImage(String symbolicName, String path) + { + try + { + URL url = getPluginImageURL(symbolicName, path); + if (url != null) { + return getPluginImageFromUrl(url); + } + } + catch (Throwable localThrowable) {} + + return null; + } + + + private static Image getPluginImageFromUrl(URL url) + { + try { + try { + String key = url.toExternalForm(); + Image image = m_URLImageMap.get(key); + if (image == null) { + InputStream stream = url.openStream(); + try { + image = getImage(stream); + m_URLImageMap.put(key, image); + } finally { + stream.close(); + } + } + return image; + } catch (Throwable e) { + // Ignore any exceptions + } + } catch (Throwable e) { + // Ignore any exceptions + } + return null; + + } + + @Deprecated + public static ImageDescriptor getPluginImageDescriptor(Object plugin, String name) + { + try + { + URL url = getPluginImageURL(plugin, name); + return ImageDescriptor.createFromURL(url); + } + catch (Throwable localThrowable1) {} + + + + + return null; + } + + + + + public static ImageDescriptor getPluginImageDescriptor(String symbolicName, String path) + { + try + { + URL url = getPluginImageURL(symbolicName, path); + if (url != null) { + return ImageDescriptor.createFromURL(url); + } + } + catch (Throwable localThrowable) {} + + return null; + } + + + + + private static URL getPluginImageURL(String symbolicName, String path) + { + Bundle bundle = Platform.getBundle(symbolicName); + if (bundle != null) { + return bundle.getEntry(path); + } + + + if (m_designTimePluginResourceProvider != null) { + return m_designTimePluginResourceProvider.getEntry(symbolicName, path); + } + + return null; + } + + + private static URL getPluginImageURL(Object plugin, String name) + throws Exception + { + try + { + Class BundleClass = Class.forName("org.osgi.framework.Bundle"); + Class BundleContextClass = Class.forName("org.osgi.framework.BundleContext"); + if (BundleContextClass.isAssignableFrom(plugin.getClass())) { + Method getBundleMethod = BundleContextClass.getMethod("getBundle", new Class[0]); + Object bundle = getBundleMethod.invoke(plugin, new Object[0]); + + Class PathClass = Class.forName("org.eclipse.core.runtime.Path"); + Constructor pathConstructor = PathClass.getConstructor(new Class[] { String.class }); + Object path = pathConstructor.newInstance(new Object[] { name }); + + Class IPathClass = Class.forName("org.eclipse.core.runtime.IPath"); + Class PlatformClass = Class.forName("org.eclipse.core.runtime.Platform"); + Method findMethod = PlatformClass.getMethod("find", new Class[] { BundleClass, IPathClass }); + return (URL)findMethod.invoke(null, new Object[] { bundle, path }); + } + + + } + catch (Throwable localThrowable) + { + Class PluginClass = Class.forName("org.eclipse.core.runtime.Plugin"); + if (PluginClass.isAssignableFrom(plugin.getClass())) { + Class PathClass = Class.forName("org.eclipse.core.runtime.Path"); + Constructor pathConstructor = PathClass.getConstructor(new Class[] { String.class }); + Object path = pathConstructor.newInstance(new Object[] { name }); + + Class IPathClass = Class.forName("org.eclipse.core.runtime.IPath"); + Method findMethod = PluginClass.getMethod("find", new Class[] { IPathClass }); + return (URL)findMethod.invoke(plugin, new Object[] { path }); + } + } + return null; + } + + + + public static void dispose() + { + disposeColors(); + disposeFonts(); + disposeImages(); + } + + public static abstract interface PluginResourceProvider + { + public abstract URL getEntry(String paramString1, String paramString2); + } + } diff --git a/eu.scasefp7.eclipse.core.ui/src/org/eclipse/wb/swt/SWTResourceManager.java b/eu.scasefp7.eclipse.core.ui/src/org/eclipse/wb/swt/SWTResourceManager.java new file mode 100644 index 0000000..b3fb8b8 --- /dev/null +++ b/eu.scasefp7.eclipse.core.ui/src/org/eclipse/wb/swt/SWTResourceManager.java @@ -0,0 +1,304 @@ +package org.eclipse.wb.swt; + +import java.io.FileInputStream; + import java.io.IOException; + import java.io.InputStream; + import java.util.HashMap; + import java.util.Map; + import org.eclipse.swt.graphics.Color; + import org.eclipse.swt.graphics.Cursor; + import org.eclipse.swt.graphics.Font; + import org.eclipse.swt.graphics.FontData; + import org.eclipse.swt.graphics.GC; + import org.eclipse.swt.graphics.Image; + import org.eclipse.swt.graphics.ImageData; + import org.eclipse.swt.graphics.RGB; + import org.eclipse.swt.graphics.Rectangle; + import org.eclipse.swt.widgets.Display; + + + public class SWTResourceManager { + private static Map m_colorMap = new HashMap(); + + public static Color getColor(int systemColorID) { + Display display = Display.getCurrent(); + return display.getSystemColor(systemColorID); + } + + public static Color getColor(int r, int g, int b) { + return getColor(new RGB(r, g, b)); + } + + + public static Color getColor(RGB rgb) { + Color color = (Color)m_colorMap.get(rgb); + if (color == null) { + Display display = Display.getCurrent(); + color = new Color(display, rgb); + m_colorMap.put(rgb, color); + } + return color; + } + + + public static void disposeColors() { + for (Color color : m_colorMap.values()) + color.dispose(); + + m_colorMap.clear(); + } + + + private static Map m_imageMap = new HashMap(); + public static final int TOP_LEFT = 1; + public static final int TOP_RIGHT = 2; + public static final int BOTTOM_LEFT = 3; + public static final int BOTTOM_RIGHT = 4; + protected static final int LAST_CORNER_KEY = 5; + + protected static Image getImage(InputStream stream) throws IOException { + try { + Display display = Display.getCurrent(); + ImageData data = new ImageData(stream); + //Image localImage; + if (data.transparentPixel > 0) { + return new Image(display, data, data.getTransparencyMask()); + } + return new Image(display, data); + } finally { + stream.close(); + } + } + + + + public static Image getImage(String path) { + Image image = (Image)m_imageMap.get(path); + if (image == null) { + try { + image = getImage(new FileInputStream(path)); + m_imageMap.put(path, image); + } catch (Exception localException) { + image = getMissingImage(); + m_imageMap.put(path, image); + } + } + return image; + } + + + + + + public static Image getImage(Class clazz, String path) { + String key = clazz.getName() + '|' + path; + Image image = (Image)m_imageMap.get(key); + if (image == null) { + try { + image = getImage(clazz.getResourceAsStream(path)); + m_imageMap.put(key, image); + } catch (Exception localException) { + image = getMissingImage(); + m_imageMap.put(key, image); + } + } + return image; + } + + + + private static Image getMissingImage() { + Image image = new Image(Display.getCurrent(), 10, 10); + + GC gc = new GC(image); + gc.setBackground(getColor(3)); + gc.fillRectangle(0, 0, 10, 10); + gc.dispose(); + + return image; + } + + + + private static Map>[] m_decoratedImageMap = new Map[5]; + + + public static Image decorateImage(Image baseImage, Image decorator) { + return decorateImage(baseImage, decorator, 4); + } + + + + public static Image decorateImage(Image baseImage, Image decorator, int corner) { + if ((corner <= 0) || (corner >= 5)) { + throw new IllegalArgumentException("Wrong decorate corner"); + } + Map> cornerDecoratedImageMap = m_decoratedImageMap[corner]; + if (cornerDecoratedImageMap == null) { + cornerDecoratedImageMap = new HashMap>(); + m_decoratedImageMap[corner] = cornerDecoratedImageMap; + } + Map decoratedMap = (Map)cornerDecoratedImageMap.get(baseImage); + if (decoratedMap == null) { + decoratedMap = new HashMap(); + cornerDecoratedImageMap.put(baseImage, decoratedMap); + } + + Image result = (Image)decoratedMap.get(decorator); + if (result == null) { + Rectangle bib = baseImage.getBounds(); + + int width = bib.width; + int height = bib.height; + + result = new Image(Display.getCurrent(), width, height); + + GC gc = new GC(result); + gc.drawImage(baseImage, 0, 0); + if (corner == 1) { + gc.drawImage(decorator, 0, 0); + } else if (corner == 2) { + gc.drawImage(decorator, width - width, 0); + } else if (corner == 3) { + gc.drawImage(decorator, 0, height - height); + } else if (corner == 4) { + gc.drawImage(decorator, width - width, height - height); + } + gc.dispose(); + + decoratedMap.put(decorator, result); + } + return result; + } + + + + + public static void disposeImages() + { + for (Image image : m_imageMap.values()) { + image.dispose(); + } + m_imageMap.clear(); + + + for (int i = 0; i < m_decoratedImageMap.length; i++) { + Map> cornerDecoratedImageMap = m_decoratedImageMap[i]; + if (cornerDecoratedImageMap != null) { + + + for (Map decoratedMap : cornerDecoratedImageMap.values()) { + for (Image image : decoratedMap.values()) { + image.dispose(); + } + decoratedMap.clear(); + } + cornerDecoratedImageMap.clear(); + } + } + } + + + private static Map m_fontMap = new HashMap(); + + + + private static Map m_fontToBoldFontMap = new HashMap(); + + + public static Font getFont(String name, int height, int style) + { + return getFont(name, height, style, false, false); + } + + + public static Font getFont(String name, int size, int style, boolean strikeout, boolean underline) + { + String fontName = name + '|' + size + '|' + style + '|' + strikeout + '|' + underline; + Font font = (Font)m_fontMap.get(fontName); + if (font == null) { + FontData fontData = new FontData(name, size, style); + if ((strikeout) || (underline)) { + try { + Class logFontClass = Class.forName("org.eclipse.swt.internal.win32.LOGFONT"); + Object logFont = FontData.class.getField("data").get(fontData); + if ((logFont != null) && (logFontClass != null)) { + if (strikeout) { + logFontClass.getField("lfStrikeOut").set(logFont, Byte.valueOf((byte)1)); + } + if (underline) { + logFontClass.getField("lfUnderline").set(logFont, Byte.valueOf((byte)1)); + } + } + } catch (Throwable e) { + System.err.println("Unable to set underline or strikeout (probably on a non-Windows platform). " + e); + } + } + font = new Font(Display.getCurrent(), fontData); + m_fontMap.put(fontName, font); + } + return font; + } + + + public static Font getBoldFont(Font baseFont) + { + Font font = (Font)m_fontToBoldFontMap.get(baseFont); + if (font == null) { + FontData[] fontDatas = baseFont.getFontData(); + FontData data = fontDatas[0]; + font = new Font(Display.getCurrent(), data.getName(), data.getHeight(), 1); + m_fontToBoldFontMap.put(baseFont, font); + } + return font; + } + + + + public static void disposeFonts() + { + for (Font font : m_fontMap.values()) { + font.dispose(); + } + m_fontMap.clear(); + + for (Font font : m_fontToBoldFontMap.values()) { + font.dispose(); + } + m_fontToBoldFontMap.clear(); + } + + + private static Map m_idToCursorMap = new HashMap(); + + + public static Cursor getCursor(int id) + { + Integer key = Integer.valueOf(id); + Cursor cursor = (Cursor)m_idToCursorMap.get(key); + if (cursor == null) { + cursor = new Cursor(Display.getDefault(), id); + m_idToCursorMap.put(key, cursor); + } + return cursor; + } + + + public static void disposeCursors() + { + for (Cursor cursor : m_idToCursorMap.values()) { + cursor.dispose(); + } + m_idToCursorMap.clear(); + } + + + public static void dispose() + { + disposeColors(); + disposeImages(); + disposeFonts(); + disposeCursors(); + } + } + diff --git a/eu.scasefp7.eclipse.core/LinkedOntology.owl b/eu.scasefp7.eclipse.core/LinkedOntology.owl new file mode 100644 index 0000000..9f4d0e3 --- /dev/null +++ b/eu.scasefp7.eclipse.core/LinkedOntology.owl @@ -0,0 +1,510 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +XML + + +JSON + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Array + +Object + + +Primitive + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +RESTful + +SOAP + + + + + + + + + + + + +PUT + + + + +DELETE + +UPDATE + +POST + + +GET + + + + + + + + + + +true + + +false + + + + + + + +String + +Float + + +Integer + +Char + + +Double + + + +Boolean + + + + + + + + + + + diff --git a/eu.scasefp7.eclipse.core/META-INF/MANIFEST.MF b/eu.scasefp7.eclipse.core/META-INF/MANIFEST.MF index 093f61a..6f6ada2 100644 --- a/eu.scasefp7.eclipse.core/META-INF/MANIFEST.MF +++ b/eu.scasefp7.eclipse.core/META-INF/MANIFEST.MF @@ -1,24 +1,28 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: S-CASE Core -Bundle-SymbolicName: eu.scasefp7.eclipse.core;singleton:=true -Bundle-Version: 1.1.1.qualifier -Require-Bundle: org.eclipse.ui.workbench, - org.eclipse.osgi, - org.eclipse.core.runtime, - org.eclipse.core.commands, - org.eclipse.core.resources, - org.eclipse.jface -Bundle-ClassPath: . -Export-Package: eu.scasefp7.eclipse.core, - eu.scasefp7.eclipse.core.builder, - eu.scasefp7.eclipse.core.ontology -Bundle-RequiredExecutionEnvironment: JavaSE-1.8 -Import-Package: com.hp.hpl.jena.ontology;version="[2.13.0,3.0.0)", - com.hp.hpl.jena.query;version="[2.13.0,3.0.0)", - com.hp.hpl.jena.rdf.model;version="[2.13.0,3.0.0)", - com.hp.hpl.jena.util;version="[2.13.0,3.0.0)", - com.hp.hpl.jena.util.iterator;version="[2.13.0,3.0.0)", - org.apache.log4j, - org.slf4j, - org.yaml.snakeyaml;version="1.16.0" +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: S-CASE Core +Bundle-SymbolicName: eu.scasefp7.eclipse.core;singleton:=true +Bundle-Version: 1.1.1.qualifier +Require-Bundle: org.eclipse.ui.workbench, + org.eclipse.osgi, + org.eclipse.core.runtime, + org.eclipse.core.commands, + org.eclipse.jface, + org.eclipse.core.resources, + org.eclipse.ui, + org.eclipse.core.variables, + org.eclipse.swt +Bundle-ClassPath: . +Export-Package: eu.scasefp7.eclipse.core, + eu.scasefp7.eclipse.core.builder, + eu.scasefp7.eclipse.core.ontology +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Import-Package: com.hp.hpl.jena.ontology;version="[2.13.0,3.0.0)", + com.hp.hpl.jena.query;version="[2.13.0,3.0.0)", + com.hp.hpl.jena.rdf.model;version="[2.13.0,3.0.0)", + com.hp.hpl.jena.util;version="[2.13.0,3.0.0)", + com.hp.hpl.jena.util.iterator;version="[2.13.0,3.0.0)", + org.apache.log4j, + org.eclipse.emf.ecore, + org.slf4j, + org.yaml.snakeyaml;version="1.16.0" diff --git a/eu.scasefp7.eclipse.core/Restmarks.yaml b/eu.scasefp7.eclipse.core/Restmarks.yaml new file mode 100644 index 0000000..e69de29 diff --git a/eu.scasefp7.eclipse.core/build.properties b/eu.scasefp7.eclipse.core/build.properties index 289e5c4..0a16292 100644 --- a/eu.scasefp7.eclipse.core/build.properties +++ b/eu.scasefp7.eclipse.core/build.properties @@ -1,5 +1,5 @@ source.. = src/ output.. = target/classes/ bin.includes = META-INF/,\ - plugin.xml,\ - . + plugin.xml,\ + .,\ diff --git a/eu.scasefp7.eclipse.core/plugin.xml b/eu.scasefp7.eclipse.core/plugin.xml index 26816c2..e090f82 100644 --- a/eu.scasefp7.eclipse.core/plugin.xml +++ b/eu.scasefp7.eclipse.core/plugin.xml @@ -1,7 +1,8 @@ - + + @@ -19,11 +20,21 @@ categoryId="eu.scasefp7.eclipse.core.commands.category" id="eu.scasefp7.eclipse.core.commands.linkOntologies" name="Link Ontologies"> + + + + - + + + @@ -89,4 +113,36 @@ type="org.eclipse.core.resources.problemmarker"> + + + + + + + + + + + + + + diff --git a/eu.scasefp7.eclipse.core/schema/eu.scasefp7.eclipse.core.builder.exsd b/eu.scasefp7.eclipse.core/schema/eu.scasefp7.eclipse.core.builder.exsd new file mode 100644 index 0000000..87e9eed --- /dev/null +++ b/eu.scasefp7.eclipse.core/schema/eu.scasefp7.eclipse.core.builder.exsd @@ -0,0 +1,297 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/eu.scasefp7.eclipse.core.ui/schema/eu.scasefp7.eclipse.core.ui.dashboardItem.exsd b/eu.scasefp7.eclipse.core/schema/eu.scasefp7.eclipse.core.dashboardItem2.exsd similarity index 75% rename from eu.scasefp7.eclipse.core.ui/schema/eu.scasefp7.eclipse.core.ui.dashboardItem.exsd rename to eu.scasefp7.eclipse.core/schema/eu.scasefp7.eclipse.core.dashboardItem2.exsd index 8b75ac2..4c81b11 100644 --- a/eu.scasefp7.eclipse.core.ui/schema/eu.scasefp7.eclipse.core.ui.dashboardItem.exsd +++ b/eu.scasefp7.eclipse.core/schema/eu.scasefp7.eclipse.core.dashboardItem2.exsd @@ -1,193 +1,246 @@ - - - - - - - - - [Enter description of this extension point.] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The label to be displayed for this element. This value should be translatable. - - - - - - - - - - This is the id of the Command that is to be bound to this element. This is the hook into the Commands/Handlers/Key binding services that actually do the work should this item be selected. In many cases this command will have been defined in a previous extension declaration. - - - - - - - - - - The tooltip to be displayed for this element when it is placed in a toolbar. This value should be translatable. - - - - - - - - - - Notification text to display to user in a popup if the command succeeds. - - - - - - - - - - Notification text to display to user in a popup if the command fails. - - - - - - - - - - - - - A parameter to either an executable extension or a command -- depending on where it appears in the extension. - - - - - - - The name is either the name of the parameter to pass to the executable extension, or the identifier of the parameter for the command. - - - - - - - - - - The value to pass for this parameter. - - - - - - - - - - - - [Enter the first release in which this extension point appears.] - - - - - - - - - [Enter extension point usage example here.] - - - - - - - - - [Enter API information here.] - - - - - - - - - [Enter information about supplied implementation of this extension point.] - - - - - + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + The label to be displayed for this element. This value should be translatable. + + + + + + + + + + This is the id of the Command that is to be bound to this element. This is the hook into the Commands/Handlers/Key binding services that actually do the work should this item be selected. In many cases this command will have been defined in a previous extension declaration. + + + + + + + + + + + + + + + + + + + + The tooltip to be displayed for this element when it is placed in a toolbar. This value should be translatable. + + + + + + + + + + Notification text to display to user in a popup if the command succeeds. + + + + + + + + + + Notification text to display to user in a popup if the command fails. + + + + + + + + + + Id of the group the button belongs to + + + + + + + + + + The button will be before the button with specified id + + + + + + + + + + + + + A parameter to either an executable extension or a command -- depending on where it appears in the extension. + + + + + + + The name is either the name of the parameter to pass to the executable extension, or the identifier of the parameter for the command. + + + + + + + + + + The value to pass for this parameter. + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/builder/ScaseProjectBuilder.java b/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/builder/ScaseProjectBuilder.java index 05492b0..a4ea254 100644 --- a/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/builder/ScaseProjectBuilder.java +++ b/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/builder/ScaseProjectBuilder.java @@ -1,218 +1,437 @@ -package eu.scasefp7.eclipse.core.builder; - -import java.util.Map; - -import org.eclipse.core.commands.Command; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.commands.NotEnabledException; -import org.eclipse.core.commands.NotHandledException; -import org.eclipse.core.commands.Parameterization; -import org.eclipse.core.commands.ParameterizedCommand; -import org.eclipse.core.commands.common.NotDefinedException; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IResourceDeltaVisitor; -import org.eclipse.core.resources.IResourceVisitor; -import org.eclipse.core.resources.IncrementalProjectBuilder; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.commands.ICommandService; -import org.eclipse.ui.handlers.IHandlerService; -import org.eclipse.ui.services.IServiceLocator; - -import eu.scasefp7.eclipse.core.Activator; - -/** - * Builder for S-CASE projects. - * - * @author Leonora Gašpar - * @author Marin Orlić - * - */ -public class ScaseProjectBuilder extends IncrementalProjectBuilder { - - /** - * Builder ID - */ - public static final String BUILDER_ID = "eu.scasefp7.eclipse.core.scaseBuilder"; - - /** - * Marker ID - */ - private static final String MARKER_TYPE = "eu.scasefp7.eclipse.core.problemMarker"; - - class SampleDeltaVisitor implements IResourceDeltaVisitor { - - public boolean visit(IResourceDelta delta) throws CoreException { - // IResource resource = delta.getResource(); - switch (delta.getKind()) { - case IResourceDelta.ADDED: - break; - case IResourceDelta.REMOVED: - break; - case IResourceDelta.CHANGED: - break; - } - - return true; - } - } - - class SampleResourceVisitor implements IResourceVisitor { - boolean fileExsists = false; - int fileCount = 0; - IFile firstXmlFile; - - public boolean visit(IResource resource) { -// boolean other = checkXML(resource); - -// if (resource instanceof IFile && resource.getName().endsWith(".rqs")) -// executeCommand("eu.scasefp7.eclipse.reqeditor.commands.exportToOntology", resource.getFullPath() -// .toString()); -// -// if (resource instanceof IFile && resource.getName().endsWith(".sbd")) -// executeCommand("eu.scasefp7.eclipse.storyboards.commands.exportToOntology", resource.getFullPath() -// .toString()); - - -// if (resource instanceof IFile && ( -// resource.getName().equals("StaticOntology.owl") -// || resource.getName().equals("DynamicOntology.owl"))) { -// executeCommand("eu.scasefp7.eclipse.core.commands.linkOntologies"); -// } - - - -// -// if (fileExsists && other) { -// if (fileCount < 2) -// addMarker(firstXmlFile, "The project must contain only one .xml file", 1, IMarker.SEVERITY_ERROR); -// addMarker((IFile) resource, "The project must contain only one .xml file", 1, IMarker.SEVERITY_ERROR); -// fileCount++; -// } -// -// if (!fileExsists && other) { -// fileCount++; -// fileExsists = true; -// firstXmlFile = (IFile) resource; -// } - - // return true to continue visiting children. - return true; - } - } - - boolean checkXML(IResource resource) { - if (resource instanceof IFile && resource.getName().endsWith(".xml")) { - return true; - } - return false; - } - - protected void executeCommand(String commandId) { - // Obtain IServiceLocator implementer, e.g. from PlatformUI.getWorkbench(): - IServiceLocator serviceLocator = PlatformUI.getWorkbench(); - // or a site from within a editor or view: - // IServiceLocator serviceLocator = getSite(); - - IHandlerService handlerService = (IHandlerService) serviceLocator.getService(IHandlerService.class); - try { - // Execute commmand via its ID - - handlerService.executeCommand(commandId, null); - } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException ex) { - Activator.log("Unable to execute command " + commandId, ex); - } - } - - protected void executeCommand(String commandId, String fileName) { - IServiceLocator serviceLocator = PlatformUI.getWorkbench(); - - ICommandService commandService = (ICommandService) serviceLocator.getService(ICommandService.class); - IHandlerService handlerService = (IHandlerService) serviceLocator.getService(IHandlerService.class); - - try { - Command command = commandService.getCommand(commandId); - - Parameterization[] params = new Parameterization[] { new Parameterization(command.getParameter("fileName"), - (String) fileName) }; - - ParameterizedCommand parametrizedCommand = new ParameterizedCommand(command, params); - - handlerService.executeCommand(parametrizedCommand, null); - - } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException ex) { - Activator.log("Unable to execute command " + commandId + " with filename " + fileName, ex); - } - - } - - -// private void addMarker(IFile file, String message, int lineNumber, int severity) { -// try { -// IMarker marker = file.createMarker(MARKER_TYPE); -// marker.setAttribute(IMarker.MESSAGE, message); -// marker.setAttribute(IMarker.SEVERITY, severity); -// if (lineNumber == -1) { -// lineNumber = 1; -// } -// marker.setAttribute(IMarker.LINE_NUMBER, lineNumber); -// } catch (CoreException e) { -// } -// } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.internal.events.InternalBuilder#build(int, - * java.util.Map, org.eclipse.core.runtime.IProgressMonitor) - */ - protected IProject[] build(int kind, @SuppressWarnings("rawtypes") Map args, IProgressMonitor monitor) throws CoreException { - if (kind == FULL_BUILD) { - fullBuild(monitor); - } else { - IResourceDelta delta = getDelta(getProject()); - if (delta == null) { - fullBuild(monitor); - } else { - incrementalBuild(delta, monitor); - } - } - return null; - } - - protected void clean(IProgressMonitor monitor) throws CoreException { - // delete markers set and files created - getProject().deleteMarkers(MARKER_TYPE, true, IResource.DEPTH_INFINITE); - } - - protected void deleteMarkers(IFile file) { - try { - file.deleteMarkers(MARKER_TYPE, false, IResource.DEPTH_ZERO); - } catch (CoreException ce) { - } - } - - protected void fullBuild(final IProgressMonitor monitor) throws CoreException { - try { - clean(monitor); - getProject().accept(new SampleResourceVisitor()); - } catch (CoreException e) { - } - } - - protected void incrementalBuild(IResourceDelta delta, IProgressMonitor monitor) throws CoreException { - try { - clean(monitor); - // delta.accept(new SampleDeltaVisitor()); - getProject().accept(new SampleResourceVisitor()); - } catch (CoreException e) { - System.out.println(e); - } - } - -} - +package eu.scasefp7.eclipse.core.builder; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.NotEnabledException; +import org.eclipse.core.commands.NotHandledException; +import org.eclipse.core.commands.Parameterization; +import org.eclipse.core.commands.ParameterizedCommand; +import org.eclipse.core.commands.common.NotDefinedException; +import java.io.File; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceDelta; +import org.eclipse.core.resources.IResourceDeltaVisitor; +import org.eclipse.core.resources.IResourceVisitor; +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.resources.ProjectScope; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IRegistryEventListener; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.core.variables.IDynamicVariable; +import org.eclipse.core.variables.IDynamicVariableResolver; +import org.eclipse.core.variables.IStringVariable; +import org.eclipse.core.variables.VariablesPlugin; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.commands.ICommandService; +import org.eclipse.ui.handlers.IHandlerService; +import org.eclipse.ui.preferences.ScopedPreferenceStore; +import org.eclipse.ui.services.IServiceLocator; + +/** + * Builder for S-CASE projects. + * + * @author Leonora Gašpar + * @author Marin Orlić + * + */ +public class ScaseProjectBuilder extends IncrementalProjectBuilder implements ISelectionListener, IRegistryEventListener { + + /** + * Builder ID + */ + public static final String BUILDER_ID = "eu.scasefp7.eclipse.core.scaseBuilder"; + + /** + * Marker ID + */ + private static final String MARKER_TYPE = "eu.scasefp7.eclipse.core.problemMarker"; + + private static final String CONTRIBUTION_STRING = "string"; + private static final String CONTRIBUTION_VARIABLE = "variable"; + private static final String CONTRIBUTION_PREFERENCE = "preference"; + + private Map projectFolders = new HashMap(); + + + class BuildDeltaVisitor implements IResourceDeltaVisitor { + + public boolean visit(IResourceDelta delta) throws CoreException { + switch (delta.getKind()) { + case IResourceDelta.ADDED: + case IResourceDelta.CHANGED: + IResource resource = delta.getResource(); + if (resource instanceof IFile) { + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IConfigurationElement[] contributions = registry.getConfigurationElementsFor("eu.scasefp7.eclipse.core.builder"); + if (contributions.length > 0) + for (IConfigurationElement elem : contributions) + if (elem.getName().equals("buildStep")) { + String commandId = elem.getAttribute("commandId"); + String regex = elem.getAttribute("condition"); + String inFolder = elem.getAttribute("inFolder"); + String folderCondition = ""; + + if(inFolder != null && inFolder != "") { + String property = projectFolders.get(inFolder); + IProject project = ((IFile)resource).getProject(); + folderCondition = project.getPersistentProperty(new QualifiedName("", property)); + } + + IConfigurationElement[] elements = elem.getChildren("commandParameters"); + boolean hasParameters = elements.length > 0; + HashMap parameters = new HashMap(); + + if(hasParameters) + getParameters(resource, parameters, elements[0]); + + if ((folderCondition == "" || resource.getFullPath().toString().contains(folderCondition)) + && resource.getName().matches(regex)) { + if (!hasParameters) + executeCommand(commandId, resource.getFullPath().toString()); + else + executeCommand(commandId, resource.getFullPath().toString(), parameters); + System.out.println("Command: " + commandId + " on file: " + + resource.getFullPath().toString() + " (d)"); + } + } + } + + break; + case IResourceDelta.REMOVED: + case IResourceDelta.NO_CHANGE: + break; + } + + return true; + } + } + + class BuildResourceVisitor implements IResourceVisitor { + public boolean visit(IResource resource) { + + if (resource instanceof IFile) { + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IConfigurationElement[] contributions = registry.getConfigurationElementsFor("eu.scasefp7.eclipse.core.builder"); + if (contributions.length > 0) + for (IConfigurationElement elem : contributions) + if (elem.getName().equals("buildStep")) { + String commandId = elem.getAttribute("commandId"); + String regex = elem.getAttribute("condition"); + String inFolder = elem.getAttribute("inFolder"); + String folderCondition = ""; + + if(inFolder != null && inFolder != "") { + String property = projectFolders.get(inFolder); + IProject project = ((IFile)resource).getProject(); + try { + folderCondition = project.getPersistentProperty(new QualifiedName("", property)); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + IConfigurationElement[] elements = elem.getChildren("commandParameters"); + boolean hasParameters = elements.length > 0; + HashMap parameters = new HashMap(); + + if(hasParameters) + getParameters(resource, parameters, elements[0]); + + if((folderCondition == "" || resource.getFullPath().toString().contains(folderCondition)) + && resource.getName().matches(regex)) { + if(!hasParameters) + executeCommand(commandId, resource.getFullPath().toString()); + else + executeCommand(commandId, resource.getFullPath().toString(), parameters); + System.out.println("Command: " + commandId+" on file: "+resource.getFullPath().toString()); + } + } + } + // return true to continue visiting children. + return true; + } + } + class CleanResourceVisitor implements IResourceVisitor { + public boolean visit(IResource resource) throws CoreException { + + if (resource instanceof IFile) { + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IConfigurationElement[] contributions = registry.getConfigurationElementsFor("eu.scasefp7.eclipse.core.builder"); + if (contributions.length > 0) + for (IConfigurationElement elem : contributions) + if (elem.getName().equals("cleanStep")) { + + IConfigurationElement[] removals = elem.getChildren("removal"); + if(removals.length>0) + for (IConfigurationElement removal : removals) { + String regex = removal.getAttribute("condition"); + if(resource.getName().matches(regex)) { + IPath path = resource.getRawLocation(); + File file = path.toFile(); + file.delete(); + String name = resource.getName(); + resource.delete(false, null); + System.out.println("Removal: "+name + " removed!"); + + } + + } + IConfigurationElement[] commands = elem.getChildren("command"); + + if(commands.length>0) + for (IConfigurationElement command : commands) { + String regex = command.getAttribute("condition"); + String commandId = command.getAttribute("commandId"); + if(resource.getName().matches(regex)) { + IConfigurationElement[] params = command.getChildren("commandParameters"); + boolean hasParameters = params.length > 0; + HashMap parameters = new HashMap(); + if(hasParameters) + getParameters(resource, parameters, params[0]); + + if(!hasParameters) + executeCommand(commandId, resource.getFullPath().toString()); + else + executeCommand(commandId, resource.getFullPath().toString(), parameters); + System.out.println("Cleaning command...: " + commandId); + } + + } + } + } + // return true to continue visiting children. + return true; + } + } + + private void getParameters(IResource resource, HashMap parameters, IConfigurationElement elements) { + for (IConfigurationElement element : elements.getChildren()) { + if (element.getName().equals(CONTRIBUTION_STRING)) { + String paramName = element.getAttribute("name"); + String value = element.getAttribute("value"); + parameters.put(paramName, value); + } + if (element.getName().equals(CONTRIBUTION_VARIABLE)) { + String className = element.getAttribute("variableResolver"); + String variableId = element.getAttribute("variableId"); + String paramName = element.getAttribute("name"); + IStringVariable[] variables = VariablesPlugin.getDefault().getStringVariableManager().getVariables(); + + Class clazz; + try { + clazz = Class.forName(className).asSubclass(IDynamicVariableResolver.class); + IDynamicVariableResolver resolver = (IDynamicVariableResolver) clazz.newInstance(); + for (int i = 0; i < variables.length; i++) { + IDynamicVariable currVar = ((IDynamicVariable)variables[i]); + String name = currVar.getName(); + String value = ""; + if(name.equals(variableId ) ){ + value = resolver.resolveValue(currVar, null); + parameters.put(paramName, value ); + } + } + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | SecurityException | CoreException e) { + e.printStackTrace(); + } + + } + if (element.getName().equals(CONTRIBUTION_PREFERENCE)) { + String preferenceId = element.getAttribute("preferenceId"); + String pluginId = element.getAttribute("pluginId"); + String paramName = element.getAttribute("name"); + + ProjectScope ps = new ProjectScope(resource.getProject()); + ScopedPreferenceStore scoped = new ScopedPreferenceStore(ps, pluginId); + String value = scoped.getString(preferenceId); + parameters.put(paramName, value ); + } + } + } + + + protected void executeCommand(String commandId) { + IServiceLocator serviceLocator = PlatformUI.getWorkbench(); + IHandlerService handlerService = (IHandlerService) serviceLocator.getService(IHandlerService.class); + try { + handlerService.executeCommand(commandId, null); + } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException ex) { + ex.printStackTrace(); + } + } + + /** + * Execution of command without parameters on resource with given name. + * @param commandId + * @param name + */ + + protected void executeCommand(String commandId, String name) { + IServiceLocator serviceLocator = PlatformUI.getWorkbench(); + + ICommandService commandService = (ICommandService) serviceLocator.getService(ICommandService.class); + IHandlerService handlerService = (IHandlerService) serviceLocator.getService(IHandlerService.class); + Command command = commandService.getCommand(commandId); + + Parameterization[] params; + try { + params = new Parameterization[] { new Parameterization(command.getParameter("fileName"), (String) name) }; + ParameterizedCommand parametrizedCommand = new ParameterizedCommand(command, params); + + handlerService.executeCommand(parametrizedCommand, null); + } catch (NotDefinedException | ExecutionException | NotEnabledException | NotHandledException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + /** + * Execution of command with parameters on file with given name. + * @param commandId + * @param name + * @param parameters + */ + protected void executeCommand(String commandId, String name, HashMap parameters) { + IServiceLocator serviceLocator = PlatformUI.getWorkbench(); + + ICommandService commandService = (ICommandService) serviceLocator.getService(ICommandService.class); + IHandlerService handlerService = (IHandlerService) serviceLocator.getService(IHandlerService.class); + Command command = commandService.getCommand(commandId); + try { + List par = new ArrayList(); + par.add(new Parameterization(command.getParameter("fileName"), (String) name)); + + for(Entry e : parameters.entrySet()) + par.add(new Parameterization(command.getParameter(e.getKey()), e.getValue() )); + + Parameterization[] params = (Parameterization[]) par.toArray(new Parameterization[par.size()]); + ParameterizedCommand parametrizedCommand = new ParameterizedCommand(command, params); + handlerService.executeCommand(parametrizedCommand, null); + } catch (NotDefinedException | ExecutionException | NotEnabledException | NotHandledException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + + /* + * (non-Javadoc) + * + * @see org.eclipse.core.internal.events.InternalBuilder#build(int, + * java.util.Map, org.eclipse.core.runtime.IProgressMonitor) + */ + protected IProject[] build(int kind, @SuppressWarnings("rawtypes") Map args, IProgressMonitor monitor) throws CoreException { + + projectFolders.put("requirements folder", "eu.scasefp7.eclipse.core.ui.rqsFolder"); + projectFolders.put("compositions folder", "eu.scasefp7.eclipse.core.ui.compFolder"); + projectFolders.put("models folder", "eu.scasefp7.eclipse.core.ui.modelsFolder"); + projectFolders.put("output folder", "eu.scasefp7.eclipse.core.ui.outputFolder"); + + if (kind == FULL_BUILD) + fullBuild(monitor); + else { + IResourceDelta delta = getDelta(getProject()); + if (delta == null) { + fullBuild(monitor); + } else { + incrementalBuild(delta, monitor); + } + } + return null; + } + + + + protected void clean(IProgressMonitor monitor) throws CoreException { + // delete markers set and files created + getProject().deleteMarkers(MARKER_TYPE, true, IResource.DEPTH_INFINITE); + cleanBuild(monitor); + } + + protected void deleteMarkers(IFile file) { + try { + file.deleteMarkers(MARKER_TYPE, false, IResource.DEPTH_ZERO); + } catch (CoreException ce) { + ce.printStackTrace(); + } + } + + private void cleanBuild(IProgressMonitor monitor) { + try { + //clean(monitor); + getProject().accept(new CleanResourceVisitor()); + } catch (CoreException e) { + e.printStackTrace(); + } + } + + protected void fullBuild(final IProgressMonitor monitor) throws CoreException { + try { + //clean(monitor); + getProject().accept(new BuildResourceVisitor()); + } catch (CoreException e) { + e.printStackTrace(); + } + } + + protected void incrementalBuild(IResourceDelta delta, IProgressMonitor monitor) throws CoreException { + try { + //clean(monitor); + delta.accept(new BuildDeltaVisitor()); + } catch (CoreException e) { + e.printStackTrace(); + } + } + + @Override + public void added(IExtension[] extensions) { + // TODO Auto-generated method stub + + } + + @Override + public void removed(IExtension[] extensions) { + // TODO Auto-generated method stub + + } + + @Override + public void added(IExtensionPoint[] extensionPoints) { + // TODO Auto-generated method stub + + } + + @Override + public void removed(IExtensionPoint[] extensionPoints) { + // TODO Auto-generated method stub + + } + + @Override + public void selectionChanged(IWorkbenchPart part, ISelection selection) { + // TODO Auto-generated method stub + + } + + + + + +} + diff --git a/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/handlers/LinkOntologiesHandler.java b/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/handlers/LinkOntologiesHandler.java index 5d29a08..b489534 100644 --- a/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/handlers/LinkOntologiesHandler.java +++ b/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/handlers/LinkOntologiesHandler.java @@ -1,168 +1,180 @@ -package eu.scasefp7.eclipse.core.handlers; - -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.resources.IProject; - -import eu.scasefp7.eclipse.core.ontology.DynamicOntologyAPI; -import eu.scasefp7.eclipse.core.ontology.LinkedOntologyAPI; -import eu.scasefp7.eclipse.core.ontology.StaticOntologyAPI; - -/** - * Links the static and the dynamic ontologies into one linked ontology. - * - * @author themis - */ -public class LinkOntologiesHandler extends ProjectAwareHandler { - - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - IProject project = getProjectOfExecutionEvent(event); - if (project != null) { - - // Load the two ontologies - StaticOntologyAPI staticOntology = new StaticOntologyAPI(project); - DynamicOntologyAPI dynamicOntology = new DynamicOntologyAPI(project); - - // Create a new file for the linked ontology and instantiate it - LinkedOntologyAPI linkedOntology = new LinkedOntologyAPI(project, true); - - // Link the ontologies - linkOntologies(staticOntology, dynamicOntology, linkedOntology); - - // Close the linked ontology. The other two ontologies are not closed since they do not need to be saved. - linkedOntology.close(); - return null; - } else { - throw new ExecutionException("No project selected"); - } - } - - /** - * Instantiates the linked ontology given a static ontology instantiation and a dynamic ontology instantiation. All - * three ontology objects have to be created before calling this method. After calling this method, the linked - * ontology has to be saved using the {@link eu.scasefp7.eclipse.core.ontology.LinkedOntologyAPI#close()} method. - * - * @param staticOntology an instantiation of the static ontology. - * @param dynamicOntology an instantiation of the static ontology. - * @param linkedOntology the linked ontology that is instantiated. - */ - public void linkOntologies(StaticOntologyAPI staticOntology, DynamicOntologyAPI dynamicOntology, - LinkedOntologyAPI linkedOntology) { - - // Iterate over all objects of the static ontology - for (String object : staticOntology.getObjects()) { - - // Add the object as a resource in the linked ontology - linkedOntology.addResource(object); - - // Iterate over all related objects of the object and add them to the linked ontology - for (String relatedObject : staticOntology.getRelatedObjectsOfObject(object)) { - linkedOntology.addResource(relatedObject); - linkedOntology.addRelatedResourceToResource(object, relatedObject); - for (String requirement : staticOntology.getRequirementsOfConcept(relatedObject)) { - linkedOntology.addRequirement(requirement, staticOntology.getTextOfRequirement(requirement)); - linkedOntology.connectRequirementToElement(requirement, relatedObject); - } - } - - // Iterate over all properties of the object and add them to the linked ontology - for (String property : staticOntology.getPropertiesOfObject(object)) { - linkedOntology.addPropertyToResource(object, property); - for (String requirement : staticOntology.getRequirementsOfConcept(property)) { - linkedOntology.addRequirement(requirement, staticOntology.getTextOfRequirement(requirement)); - linkedOntology.connectRequirementToElement(requirement, property); - } - } - - // Iterate over all actions of the object and add them to the linked ontology - for (String action : staticOntology.getActionsOfObject(object)) { - String activity = action + " " + object; - linkedOntology.addActivityToResource(object, activity); - linkedOntology.addActionToActivity(activity, action); - for (String requirement : staticOntology.getRequirementsOfOperation(action)) { - linkedOntology.addRequirement(requirement, staticOntology.getTextOfRequirement(requirement)); - linkedOntology.connectRequirementToElement(requirement, activity); - linkedOntology.connectRequirementToElement(requirement, action); - } - } - - // Iterate over all requirements containing the object and add them to the linked ontology - for (String requirement : staticOntology.getRequirementsOfConcept(object)) { - linkedOntology.addRequirement(requirement, staticOntology.getTextOfRequirement(requirement)); - linkedOntology.connectRequirementToElement(requirement, object); - } - } - - // Iterate over all activities of the dynamic ontology - for (String dynactivity : dynamicOntology.getActivities()) { - - // Get the object of the activity and add it as a resource in the linked ontology - String object = dynamicOntology.getObjectOfActivity(dynactivity); - if (object != null) { - linkedOntology.addResource(object); - for (String diagram : dynamicOntology.getDiagramsOfConcept(dynactivity)) { - linkedOntology.addActivityDiagram(diagram, dynamicOntology.getTextOfActivityDiagram(diagram)); - linkedOntology.connectActivityDiagramToElement(diagram, object); - } - - // Get the action of the activity and add it to the linked ontology - String action = dynamicOntology.getActionOfActivity(dynactivity); - if (action != null) { - String activity = action + " " + object; - linkedOntology.addActivityToResource(object, activity, - dynamicOntology.getActivityTypeOfActivity(dynactivity)); - linkedOntology.addActionToActivity(activity, action); - for (String diagram : dynamicOntology.getDiagramsOfConcept(dynactivity)) { - linkedOntology.addActivityDiagram(diagram, dynamicOntology.getTextOfActivityDiagram(diagram)); - linkedOntology.connectActivityDiagramToElement(diagram, object); - linkedOntology.connectActivityDiagramToElement(diagram, action); - linkedOntology.connectActivityDiagramToElement(diagram, activity); - } - } - - // Iterate over all properties of activity and add them as properties of object to the ontology - for (String property : dynamicOntology.getPropertiesOfActivity(dynactivity)) { - linkedOntology.addPropertyToResource(object, property); - for (String diagram : dynamicOntology.getDiagramsOfConcept(property)) { - linkedOntology.addActivityDiagram(diagram, dynamicOntology.getTextOfActivityDiagram(diagram)); - linkedOntology.connectActivityDiagramToElement(diagram, property); - } - } - } - } - - // Iterate over all transitions of the dynamic ontology - for (String transition : dynamicOntology.getTransitions()) { - - // Get the condition of the transition - String condition = dynamicOntology.getConditionOfTransition(transition); - - // Get the source activity of the transition - String sourcedynactivity = dynamicOntology.getSourceActivityOfTransition(transition); - String saction = dynamicOntology.getActionOfActivity(sourcedynactivity); - String sobject = dynamicOntology.getObjectOfActivity(sourcedynactivity); - String sactivity = saction + " " + sobject; - - // Get the target activity of the transition - String targetdynactivity = dynamicOntology.getTargetActivityOfTransition(transition); - String taction = dynamicOntology.getActionOfActivity(targetdynactivity); - String tobject = dynamicOntology.getObjectOfActivity(targetdynactivity); - String tactivity = taction + " " + tobject; - - // Connect the activities - if (taction != null && saction != null) - linkedOntology.addNextActivityToActivity(sactivity, tactivity); - - // Add the condition of the transition to the respective activity of the linked ontology. - if (condition != null && taction != null && saction != null) { - linkedOntology.addConditionToActivity(tactivity, condition); - for (String diagram : dynamicOntology.getDiagramsOfConcept(condition)) { - linkedOntology.addActivityDiagram(diagram, dynamicOntology.getTextOfActivityDiagram(diagram)); - linkedOntology.connectActivityDiagramToElement(diagram, condition); - } - } - } - } - -} +package eu.scasefp7.eclipse.core.handlers; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.Path; + +import eu.scasefp7.eclipse.core.ontology.DynamicOntologyAPI; +import eu.scasefp7.eclipse.core.ontology.LinkedOntologyAPI; +import eu.scasefp7.eclipse.core.ontology.StaticOntologyAPI; + +/** + * Links the static and the dynamic ontologies into one linked ontology. + * + * @author themis + */ +public class LinkOntologiesHandler extends ProjectAwareHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + IProject project = getProjectOfExecutionEvent(event); + String fileName = event.getParameter("fileName"); + + //When handler is called from builder + if(fileName != null){ + Path path = new Path(fileName); + IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); + project = file.getProject(); + } + if (project != null) { + + // Load the two ontologies + StaticOntologyAPI staticOntology = new StaticOntologyAPI(project); + DynamicOntologyAPI dynamicOntology = new DynamicOntologyAPI(project); + + // Create a new file for the linked ontology and instantiate it + LinkedOntologyAPI linkedOntology = new LinkedOntologyAPI(project, true); + + // Link the ontologies + linkOntologies(staticOntology, dynamicOntology, linkedOntology); + + // Close the linked ontology. The other two ontologies are not closed since they do not need to be saved. + linkedOntology.close(); + return null; + } else { + throw new ExecutionException("No project selected"); + } + } + + /** + * Instantiates the linked ontology given a static ontology instantiation and a dynamic ontology instantiation. All + * three ontology objects have to be created before calling this method. After calling this method, the linked + * ontology has to be saved using the {@link eu.scasefp7.eclipse.core.ontology.LinkedOntologyAPI#close()} method. + * + * @param staticOntology an instantiation of the static ontology. + * @param dynamicOntology an instantiation of the static ontology. + * @param linkedOntology the linked ontology that is instantiated. + */ +public void linkOntologies(StaticOntologyAPI staticOntology, DynamicOntologyAPI dynamicOntology, + LinkedOntologyAPI linkedOntology) { + + // Iterate over all objects of the static ontology + for (String object : staticOntology.getObjects()) { + + // Add the object as a resource in the linked ontology + linkedOntology.addResource(object); + + // Iterate over all related objects of the object and add them to the linked ontology + for (String relatedObject : staticOntology.getRelatedObjectsOfObject(object)) { + linkedOntology.addResource(relatedObject); + linkedOntology.addRelatedResourceToResource(object, relatedObject); + for (String requirement : staticOntology.getRequirementsOfConcept(relatedObject)) { + linkedOntology.addRequirement(requirement, staticOntology.getTextOfRequirement(requirement)); + linkedOntology.connectRequirementToElement(requirement, relatedObject); + } + } + + // Iterate over all properties of the object and add them to the linked ontology + for (String property : staticOntology.getPropertiesOfObject(object)) { + linkedOntology.addPropertyToResource(object, property); + for (String requirement : staticOntology.getRequirementsOfConcept(property)) { + linkedOntology.addRequirement(requirement, staticOntology.getTextOfRequirement(requirement)); + linkedOntology.connectRequirementToElement(requirement, property); + } + } + + // Iterate over all actions of the object and add them to the linked ontology + for (String action : staticOntology.getActionsOfObject(object)) { + String activity = action + " " + object; + linkedOntology.addActivityToResource(object, activity); + linkedOntology.addActionToActivity(activity, action); + for (String requirement : staticOntology.getRequirementsOfOperation(action)) { + linkedOntology.addRequirement(requirement, staticOntology.getTextOfRequirement(requirement)); + linkedOntology.connectRequirementToElement(requirement, activity); + linkedOntology.connectRequirementToElement(requirement, action); + } + } + + // Iterate over all requirements containing the object and add them to the linked ontology + for (String requirement : staticOntology.getRequirementsOfConcept(object)) { + linkedOntology.addRequirement(requirement, staticOntology.getTextOfRequirement(requirement)); + linkedOntology.connectRequirementToElement(requirement, object); + } + } + + // Iterate over all activities of the dynamic ontology + for (String dynactivity : dynamicOntology.getActivities()) { + + // Get the object of the activity and add it as a resource in the linked ontology + String object = dynamicOntology.getObjectOfActivity(dynactivity); + if (object != null) { + linkedOntology.addResource(object); + for (String diagram : dynamicOntology.getDiagramsOfConcept(dynactivity)) { + linkedOntology.addActivityDiagram(diagram, dynamicOntology.getTextOfActivityDiagram(diagram)); + linkedOntology.connectActivityDiagramToElement(diagram, object); + } + + // Get the action of the activity and add it to the linked ontology + String action = dynamicOntology.getActionOfActivity(dynactivity); + if (action != null) { + String activity = action + " " + object; + linkedOntology.addActivityToResource(object, activity, + dynamicOntology.getActivityTypeOfActivity(dynactivity)); + linkedOntology.addActionToActivity(activity, action); + for (String diagram : dynamicOntology.getDiagramsOfConcept(dynactivity)) { + linkedOntology.addActivityDiagram(diagram, dynamicOntology.getTextOfActivityDiagram(diagram)); + linkedOntology.connectActivityDiagramToElement(diagram, object); + linkedOntology.connectActivityDiagramToElement(diagram, action); + linkedOntology.connectActivityDiagramToElement(diagram, activity); + } + } + + // Iterate over all properties of activity and add them as properties of object to the ontology + for (String property : dynamicOntology.getPropertiesOfActivity(dynactivity)) { + linkedOntology.addPropertyToResource(object, property); + for (String diagram : dynamicOntology.getDiagramsOfConcept(property)) { + linkedOntology.addActivityDiagram(diagram, dynamicOntology.getTextOfActivityDiagram(diagram)); + linkedOntology.connectActivityDiagramToElement(diagram, property); + } + } + } + } + + // Iterate over all transitions of the dynamic ontology + for (String transition : dynamicOntology.getTransitions()) { + + // Get the condition of the transition + String condition = dynamicOntology.getConditionOfTransition(transition); + + // Get the source activity of the transition + String sourcedynactivity = dynamicOntology.getSourceActivityOfTransition(transition); + String saction = dynamicOntology.getActionOfActivity(sourcedynactivity); + String sobject = dynamicOntology.getObjectOfActivity(sourcedynactivity); + String sactivity = saction + " " + sobject; + + // Get the target activity of the transition + String targetdynactivity = dynamicOntology.getTargetActivityOfTransition(transition); + String taction = dynamicOntology.getActionOfActivity(targetdynactivity); + String tobject = dynamicOntology.getObjectOfActivity(targetdynactivity); + String tactivity = taction + " " + tobject; + + // Connect the activities + if (taction != null && saction != null) + linkedOntology.addNextActivityToActivity(sactivity, tactivity); + + // Add the condition of the transition to the respective activity of the linked ontology. + if (condition != null && taction != null && saction != null) { + linkedOntology.addConditionToActivity(tactivity, condition); + for (String diagram : dynamicOntology.getDiagramsOfConcept(condition)) { + linkedOntology.addActivityDiagram(diagram, dynamicOntology.getTextOfActivityDiagram(diagram)); + linkedOntology.connectActivityDiagramToElement(diagram, condition); + } + } + } + } + +} + diff --git a/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/handlers/OntologyToYamlHandler.java b/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/handlers/OntologyToYamlHandler.java index 26d5758..1df3ed3 100644 --- a/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/handlers/OntologyToYamlHandler.java +++ b/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/handlers/OntologyToYamlHandler.java @@ -1,234 +1,242 @@ -package eu.scasefp7.eclipse.core.handlers; - -import java.io.ByteArrayInputStream; -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.io.PrintWriter; -import java.io.UnsupportedEncodingException; -import java.nio.charset.StandardCharsets; -import java.util.LinkedList; - -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -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.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.QualifiedName; - -import eu.scasefp7.eclipse.core.Activator; -import eu.scasefp7.eclipse.core.ontology.LinkedOntologyAPI; -import eu.scasefp7.eclipse.core.ontologytoyamltools.Operation; -import eu.scasefp7.eclipse.core.ontologytoyamltools.Property; -import eu.scasefp7.eclipse.core.ontologytoyamltools.Resource; -import eu.scasefp7.eclipse.core.ontologytoyamltools.Resources; -import eu.scasefp7.eclipse.core.ontologytoyamltools.Stemmer; -import eu.scasefp7.eclipse.core.ontologytoyamltools.StringHelpers; -import eu.scasefp7.eclipse.core.ontologytoyamltools.VerbTypeFinder; - -/** - * Class used to read data from the linked ontology and create a CIM in YAML - * format. - * - * @author themis - */ -public class OntologyToYamlHandler extends ProjectAwareHandler { - - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - IProject project = getProjectOfExecutionEvent(event); - if (project != null) { - // Load the ontology - LinkedOntologyAPI linkedOntology = new LinkedOntologyAPI(project); - Resources resources = createResources(linkedOntology); - writeYamlFile(project, resources); - return null; - } else { - throw new ExecutionException("No project selected"); - } - } - - /** - * Creates the resources for the YAML file given the linked ontology. - * - * @param linkedOntology the linked ontology that contains all the elements. - * @return a list of resources. - */ - private Resources createResources(LinkedOntologyAPI linkedOntology) throws ExecutionException { - // Verb type finder determining whether a verb is CRUD - VerbTypeFinder verbTypeFinder = new VerbTypeFinder(); - - // Iterate over all resources - Resources resources = new Resources(); - for (String resourceName : linkedOntology.getResources()) { - Resource resource = resources.getResourceByName( - StringHelpers.underscoreToCamelCase(Stemmer.stemNounConstruct(resourceName)), false, - linkedOntology.resourceIsExternalService(resourceName)); - - // Iterate over each related resource of this resource - for (String relatedResourceName : linkedOntology.getRelatedResourcesOfResource(resourceName)) { - resource.addRelatedResource(StringHelpers.underscoreToCamelCase(Stemmer - .stemNounConstruct(relatedResourceName))); - } - - // Iterate over each activity of this resource - for (String activity : linkedOntology.getActivitiesOfResource(resourceName)) { - String action = linkedOntology.getActionOfActivity(activity); - String actiontype = linkedOntology.getActivityTypeOfActivity(activity); - if (actiontype == null || actiontype.equals("Other")) { - // Use automatic verb type finder - String verbtype = verbTypeFinder.getVerbType(action); - if (verbTypeFinder.getVerbType(action).equals("Other")) { - // Verb is of type Other - String stemmedAction = Stemmer.stemVerb(action); - String algorithmicResourceName = StringHelpers.underscoreToCamelCase(Stemmer - .stemNounConstruct(resourceName)) - + stemmedAction.substring(0, 1).toUpperCase() - + stemmedAction.substring(1); - resources.addResourceIfItDoesNotExist(algorithmicResourceName, true); - resource.addRelatedResource(algorithmicResourceName); - } else - // Verb is CRUD - resource.addCRUDActivity(verbtype); - } else - // Verb is CRUD - resource.addCRUDActivity(actiontype); - - // Iterate over next activities - for (String next_activity : linkedOntology.getNextActivitiesOfActivity(activity)) { - String relatedResource = linkedOntology.getResourceOfActivity(next_activity); - resource.addRelatedResource(StringHelpers.underscoreToCamelCase(Stemmer - .stemNounConstruct(relatedResource))); - } - } - - // Iterate over each property of this resource - for (String property : linkedOntology.getPropertiesOfResource(resourceName)) { - resource.addProperty(new Property(StringHelpers.underscoreToCamelCase(Stemmer - .stemNounConstruct(property)))); - } - - // Add information about external web services - if (linkedOntology.resourceIsExternalService(resourceName)) { - - // Get the operation of this resource - String operationName = linkedOntology.getOperationOfResource(resourceName); - Operation operation = new Operation(operationName, linkedOntology.getOperationElements(operationName)); - - // Add query parameters - for (String parameterName : linkedOntology.getQueryParametersOfOperation(operationName)) { - LinkedList nonPrimitiveProperties = operation.addQueryParameter(parameterName, - linkedOntology.getQueryParameterElements(parameterName), - linkedOntology.getParameterTypeElements(parameterName)); - while (!nonPrimitiveProperties.isEmpty()) { - String nonPrimitiveProperty = nonPrimitiveProperties.remove(); - nonPrimitiveProperties.addAll(operation.addNonPrimitiveProperty(nonPrimitiveProperty, - linkedOntology.getQueryParameterElements(nonPrimitiveProperty), - linkedOntology.getParameterTypeElements(nonPrimitiveProperty))); - } - } - - // Add input parameters - for (String parameterName : linkedOntology.getInputParametersOfOperation(operationName)) { - LinkedList nonPrimitiveProperties = operation.addInputProperty(parameterName, - linkedOntology.getInputParameterElements(parameterName), - linkedOntology.getParameterTypeElements(parameterName)); - while (!nonPrimitiveProperties.isEmpty()) { - String nonPrimitiveProperty = nonPrimitiveProperties.remove(); - nonPrimitiveProperties.addAll(operation.addNonPrimitiveProperty(nonPrimitiveProperty, - linkedOntology.getInputParameterElements(nonPrimitiveProperty), - linkedOntology.getParameterTypeElements(nonPrimitiveProperty))); - } - } - - // Add output parameters - for (String parameterName : linkedOntology.getOutputParametersOfOperation(operationName)) { - LinkedList nonPrimitiveProperties = operation.addOutputProperty(parameterName, - linkedOntology.getOutputParameterElements(parameterName), - linkedOntology.getParameterTypeElements(parameterName)); - while (!nonPrimitiveProperties.isEmpty()) { - String nonPrimitiveProperty = nonPrimitiveProperties.remove(); - nonPrimitiveProperties.addAll(operation.addNonPrimitiveProperty(nonPrimitiveProperty, - linkedOntology.getOutputParameterElements(nonPrimitiveProperty), - linkedOntology.getParameterTypeElements(nonPrimitiveProperty))); - } - } - - // Add URI parameters - for (String parameterName : linkedOntology.getURIParametersOfOperation(operationName)) { - operation.addURIParameter(parameterName); - } - - // Add the operation to the resource - resource.addOperation(operation); - } - } - return resources; - } - - /** - * Writes the YAML file of the project given the list of its resources. - * - * @param project the project in which the YAML file is written. - * @param resources the resources to be written in the YAML file. - */ - private void writeYamlFile(IProject project, Resources resources) throws ExecutionException { - // Open a new YAML file in the project - String modelsFolderLocation = null; - try { - modelsFolderLocation = project.getPersistentProperty(new QualifiedName("", - "eu.scasefp7.eclipse.core.ui.modelsFolder")); - } catch (CoreException e) { - Activator.log("Error retrieving project property (models folder location)", e); - } - IContainer container = project; - if (modelsFolderLocation != null) { - if (project.findMember(new Path(modelsFolderLocation)).exists()) - container = (IContainer) project.findMember(new Path(modelsFolderLocation)); - } - IFile file = container.getFile(new Path("service.yml")); - if (file.exists()) { - try { - file.delete(IResource.FORCE, null); - } catch (CoreException e) { - Activator.log("Unable to delete YAML file (service.yml).", e); - } - } - - // Write the resources to file - String ymlContents = ""; - for (Resource resource : resources) { - ymlContents += resource.toYAMLString() + "\n\n"; - } - InputStream ymlStream = new ByteArrayInputStream(ymlContents.getBytes(StandardCharsets.UTF_8)); - try { - file.create(ymlStream, IResource.FORCE, null); - } catch (CoreException e) { - Activator.log("Unable to create YAML file (service.yml).", e); - } - } - - /** - * Test function for creating the YAML file from the linked ontology. - * - * @param args unused parameter. - */ - public static void main(String[] args) { - LinkedOntologyAPI linkedOntology = new LinkedOntologyAPI("Restmarks", false); - try { - Resources resources = new OntologyToYamlHandler().createResources(linkedOntology); - String ymlContents = ""; - for (Resource resource : resources) { - ymlContents += resource.toYAMLString() + "\n\n"; - } - PrintWriter out = new PrintWriter("Restmarks.yaml", StandardCharsets.UTF_8.name()); - out.print(ymlContents); - out.close(); - } catch (ExecutionException | FileNotFoundException | UnsupportedEncodingException e) { - e.printStackTrace(); - } - } - -} +package eu.scasefp7.eclipse.core.handlers; + +import java.io.ByteArrayInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; +import java.util.LinkedList; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +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.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.QualifiedName; + +import eu.scasefp7.eclipse.core.Activator; +import eu.scasefp7.eclipse.core.ontology.LinkedOntologyAPI; +import eu.scasefp7.eclipse.core.ontologytoyamltools.Operation; +import eu.scasefp7.eclipse.core.ontologytoyamltools.Property; +import eu.scasefp7.eclipse.core.ontologytoyamltools.Resource; +import eu.scasefp7.eclipse.core.ontologytoyamltools.Resources; +import eu.scasefp7.eclipse.core.ontologytoyamltools.Stemmer; +import eu.scasefp7.eclipse.core.ontologytoyamltools.StringHelpers; +import eu.scasefp7.eclipse.core.ontologytoyamltools.VerbTypeFinder; + +/** + * Class used to read data from the linked ontology and create a CIM in YAML + * format. + * + * @author themis + */ +public class OntologyToYamlHandler extends ProjectAwareHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + IProject project = getProjectOfExecutionEvent(event); + String fileName = event.getParameter("fileName"); + //When handler is called from builder + if(fileName != null){ + Path path = new Path(fileName); + IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); + project = file.getProject(); + } + if (project != null) { + // Load the ontology + LinkedOntologyAPI linkedOntology = new LinkedOntologyAPI(project); + Resources resources = createResources(linkedOntology); + writeYamlFile(project, resources); + return null; + } else { + throw new ExecutionException("No project selected"); + } + } + + /** + * Creates the resources for the YAML file given the linked ontology. + * + * @param linkedOntology the linked ontology that contains all the elements. + * @return a list of resources. + */ + private Resources createResources(LinkedOntologyAPI linkedOntology) throws ExecutionException { + // Verb type finder determining whether a verb is CRUD + VerbTypeFinder verbTypeFinder = new VerbTypeFinder(); + + // Iterate over all resources + Resources resources = new Resources(); + for (String resourceName : linkedOntology.getResources()) { + Resource resource = resources.getResourceByName( + StringHelpers.underscoreToCamelCase(Stemmer.stemNounConstruct(resourceName)), false, + linkedOntology.resourceIsExternalService(resourceName)); + + // Iterate over each related resource of this resource + for (String relatedResourceName : linkedOntology.getRelatedResourcesOfResource(resourceName)) { + resource.addRelatedResource(StringHelpers.underscoreToCamelCase(Stemmer + .stemNounConstruct(relatedResourceName))); + } + + // Iterate over each activity of this resource + for (String activity : linkedOntology.getActivitiesOfResource(resourceName)) { + String action = linkedOntology.getActionOfActivity(activity); + String actiontype = linkedOntology.getActivityTypeOfActivity(activity); + if (actiontype == null || actiontype.equals("Other")) { + // Use automatic verb type finder + String verbtype = verbTypeFinder.getVerbType(action); + if (verbTypeFinder.getVerbType(action).equals("Other")) { + // Verb is of type Other + String stemmedAction = Stemmer.stemVerb(action); + String algorithmicResourceName = StringHelpers.underscoreToCamelCase(Stemmer + .stemNounConstruct(resourceName)) + + stemmedAction.substring(0, 1).toUpperCase() + + stemmedAction.substring(1); + resources.addResourceIfItDoesNotExist(algorithmicResourceName, true); + resource.addRelatedResource(algorithmicResourceName); + } else + // Verb is CRUD + resource.addCRUDActivity(verbtype); + } else + // Verb is CRUD + resource.addCRUDActivity(actiontype); + + // Iterate over next activities + for (String next_activity : linkedOntology.getNextActivitiesOfActivity(activity)) { + String relatedResource = linkedOntology.getResourceOfActivity(next_activity); + resource.addRelatedResource(StringHelpers.underscoreToCamelCase(Stemmer + .stemNounConstruct(relatedResource))); + } + } + + // Iterate over each property of this resource + for (String property : linkedOntology.getPropertiesOfResource(resourceName)) { + resource.addProperty(new Property(StringHelpers.underscoreToCamelCase(Stemmer + .stemNounConstruct(property)))); + } + + // Add information about external web services + if (linkedOntology.resourceIsExternalService(resourceName)) { + + // Get the operation of this resource + String operationName = linkedOntology.getOperationOfResource(resourceName); + Operation operation = new Operation(operationName, linkedOntology.getOperationElements(operationName)); + + // Add query parameters + for (String parameterName : linkedOntology.getQueryParametersOfOperation(operationName)) { + LinkedList nonPrimitiveProperties = operation.addQueryParameter(parameterName, + linkedOntology.getQueryParameterElements(parameterName), + linkedOntology.getParameterTypeElements(parameterName)); + while (!nonPrimitiveProperties.isEmpty()) { + String nonPrimitiveProperty = nonPrimitiveProperties.remove(); + nonPrimitiveProperties.addAll(operation.addNonPrimitiveProperty(nonPrimitiveProperty, + linkedOntology.getQueryParameterElements(nonPrimitiveProperty), + linkedOntology.getParameterTypeElements(nonPrimitiveProperty))); + } + } + + // Add input parameters + for (String parameterName : linkedOntology.getInputParametersOfOperation(operationName)) { + LinkedList nonPrimitiveProperties = operation.addInputProperty(parameterName, + linkedOntology.getInputParameterElements(parameterName), + linkedOntology.getParameterTypeElements(parameterName)); + while (!nonPrimitiveProperties.isEmpty()) { + String nonPrimitiveProperty = nonPrimitiveProperties.remove(); + nonPrimitiveProperties.addAll(operation.addNonPrimitiveProperty(nonPrimitiveProperty, + linkedOntology.getInputParameterElements(nonPrimitiveProperty), + linkedOntology.getParameterTypeElements(nonPrimitiveProperty))); + } + } + + // Add output parameters + for (String parameterName : linkedOntology.getOutputParametersOfOperation(operationName)) { + LinkedList nonPrimitiveProperties = operation.addOutputProperty(parameterName, + linkedOntology.getOutputParameterElements(parameterName), + linkedOntology.getParameterTypeElements(parameterName)); + while (!nonPrimitiveProperties.isEmpty()) { + String nonPrimitiveProperty = nonPrimitiveProperties.remove(); + nonPrimitiveProperties.addAll(operation.addNonPrimitiveProperty(nonPrimitiveProperty, + linkedOntology.getOutputParameterElements(nonPrimitiveProperty), + linkedOntology.getParameterTypeElements(nonPrimitiveProperty))); + } + } + + // Add URI parameters + for (String parameterName : linkedOntology.getURIParametersOfOperation(operationName)) { + operation.addURIParameter(parameterName); + } + + // Add the operation to the resource + resource.addOperation(operation); + } + } + return resources; + } + + /** + * Writes the YAML file of the project given the list of its resources. + * + * @param project the project in which the YAML file is written. + * @param resources the resources to be written in the YAML file. + */ + private void writeYamlFile(IProject project, Resources resources) throws ExecutionException { + // Open a new YAML file in the project + String modelsFolderLocation = null; + try { + modelsFolderLocation = project.getPersistentProperty(new QualifiedName("", + "eu.scasefp7.eclipse.core.ui.modelsFolder")); + } catch (CoreException e) { + Activator.log("Error retrieving project property (models folder location)", e); + } + IContainer container = project; + if (modelsFolderLocation != null) { + if (project.findMember(new Path(modelsFolderLocation))!=null) + container = (IContainer) project.findMember(new Path(modelsFolderLocation)); + } + IFile file = container.getFile(new Path("service.yml")); + if (file.exists()) { + try { + file.delete(IResource.FORCE, null); + } catch (CoreException e) { + Activator.log("Unable to delete YAML file (service.yml).", e); + } + } + + // Write the resources to file + String ymlContents = ""; + for (Resource resource : resources) { + ymlContents += resource.toYAMLString() + "\n\n"; + } + InputStream ymlStream = new ByteArrayInputStream(ymlContents.getBytes(StandardCharsets.UTF_8)); + try { + file.create(ymlStream, IResource.FORCE, null); + } catch (CoreException e) { + Activator.log("Unable to create YAML file (service.yml).", e); + } + } + + /** + * Test function for creating the YAML file from the linked ontology. + * + * @param args unused parameter. + */ + public static void main(String[] args) { + LinkedOntologyAPI linkedOntology = new LinkedOntologyAPI("Restmarks", false); + try { + Resources resources = new OntologyToYamlHandler().createResources(linkedOntology); + String ymlContents = ""; + for (Resource resource : resources) { + ymlContents += resource.toYAMLString() + "\n\n"; + } + PrintWriter out = new PrintWriter("Restmarks.yaml", StandardCharsets.UTF_8.name()); + out.print(ymlContents); + out.close(); + } catch (ExecutionException | FileNotFoundException | UnsupportedEncodingException e) { + e.printStackTrace(); + } + } + +} diff --git a/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/ontology/DynamicOntologyAPI.java b/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/ontology/DynamicOntologyAPI.java index 596e090..c044300 100644 --- a/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/ontology/DynamicOntologyAPI.java +++ b/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/ontology/DynamicOntologyAPI.java @@ -342,4 +342,4 @@ public void addConditionToTransition(String condition, String sourceActivity, St dynamicOntology.addPropertyAndReverseBetweenIndividuals(transitionName, "has_condition", condition); } -} +} diff --git a/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/ontology/LinkedOntologyAPI.java b/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/ontology/LinkedOntologyAPI.java index 76bc067..85a1645 100644 --- a/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/ontology/LinkedOntologyAPI.java +++ b/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/ontology/LinkedOntologyAPI.java @@ -676,4 +676,4 @@ public ArrayList getParameterTypeElements(String parameterName) { public void close() { linkedOntology.close(); } -} +} diff --git a/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/ontology/OntologyJenaAPI.java b/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/ontology/OntologyJenaAPI.java index 3b56647..c4c9c82 100644 --- a/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/ontology/OntologyJenaAPI.java +++ b/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/ontology/OntologyJenaAPI.java @@ -140,7 +140,7 @@ private IFile getPathOfOntologyFile(IProject project, OntologyType ontologyType) } IContainer container = project; if (modelsFolderLocation != null) { - if (project.findMember(new Path(modelsFolderLocation)).exists()) + if (project.findMember(new Path(modelsFolderLocation)) != null) container = (IContainer) project.findMember(new Path(modelsFolderLocation)); } file = container.getFile(new Path(filename)); diff --git a/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/ontology/StaticOntologyAPI.java b/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/ontology/StaticOntologyAPI.java index b34020c..0e3772c 100644 --- a/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/ontology/StaticOntologyAPI.java +++ b/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/ontology/StaticOntologyAPI.java @@ -266,4 +266,4 @@ public void addProperty(String property) { public void connectElementToProperty(String element, String property) { staticOntology.addPropertyAndReverseBetweenIndividuals(element, "has_property", property); } -} +} diff --git a/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/splashHandlers/InteractiveSplashHandler.java b/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/splashHandlers/InteractiveSplashHandler.java new file mode 100644 index 0000000..603388c --- /dev/null +++ b/eu.scasefp7.eclipse.core/src/eu/scasefp7/eclipse/core/splashHandlers/InteractiveSplashHandler.java @@ -0,0 +1,293 @@ + +package eu.scasefp7.eclipse.core.splashHandlers; + +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +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.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.splash.AbstractSplashHandler; + +/** + * @since 3.3 + * + */ +public class InteractiveSplashHandler extends AbstractSplashHandler { + + private final static int F_LABEL_HORIZONTAL_INDENT = 175; + + private final static int F_BUTTON_WIDTH_HINT = 80; + + private final static int F_TEXT_WIDTH_HINT = 175; + + private final static int F_COLUMN_COUNT = 3; + + private Composite fCompositeLogin; + + private Text fTextUsername; + + private Text fTextPassword; + + private Button fButtonOK; + + private Button fButtonCancel; + + private boolean fAuthenticated; + + /** + * + */ + public InteractiveSplashHandler() { + fCompositeLogin = null; + fTextUsername = null; + fTextPassword = null; + fButtonOK = null; + fButtonCancel = null; + fAuthenticated = false; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.splash.AbstractSplashHandler#init(org.eclipse.swt.widgets.Shell) + */ + public void init(final Shell splash) { + // Store the shell + super.init(splash); + // Configure the shell layout + configureUISplash(); + // Create UI + createUI(); + // Create UI listeners + createUIListeners(); + // Force the splash screen to layout + splash.layout(true); + // Keep the splash screen visible and prevent the RCP application from + // loading until the close button is clicked. + doEventLoop(); + } + + /** + * + */ + private void doEventLoop() { + Shell splash = getSplash(); + while (fAuthenticated == false) { + if (splash.getDisplay().readAndDispatch() == false) { + splash.getDisplay().sleep(); + } + } + } + + /** + * + */ + private void createUIListeners() { + // Create the OK button listeners + createUIListenersButtonOK(); + // Create the cancel button listeners + createUIListenersButtonCancel(); + } + + /** + * + */ + private void createUIListenersButtonCancel() { + fButtonCancel.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleButtonCancelWidgetSelected(); + } + }); + } + + /** + * + */ + private void handleButtonCancelWidgetSelected() { + // Abort the loading of the RCP application + getSplash().getDisplay().close(); + System.exit(0); + } + + /** + * + */ + private void createUIListenersButtonOK() { + fButtonOK.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleButtonOKWidgetSelected(); + } + }); + } + + /** + * + */ + private void handleButtonOKWidgetSelected() { + String username = fTextUsername.getText(); + String password = fTextPassword.getText(); + // Aunthentication is successful if a user provides any username and + // any password + if ((username.length() > 0) && + (password.length() > 0)) { + fAuthenticated = true; + } else { + MessageDialog.openError( + getSplash(), + "Authentication Failed", //$NON-NLS-1$ + "A username and password must be specified to login."); //$NON-NLS-1$ + } + } + + /** + * + */ + private void createUI() { + // Create the login panel + createUICompositeLogin(); + // Create the blank spanner + createUICompositeBlank(); + // Create the user name label + createUILabelUserName(); + // Create the user name text widget + createUITextUserName(); + // Create the password label + createUILabelPassword(); + // Create the password text widget + createUITextPassword(); + // Create the blank label + createUILabelBlank(); + // Create the OK button + createUIButtonOK(); + // Create the cancel button + createUIButtonCancel(); + } + + /** + * + */ + private void createUIButtonCancel() { + // Create the button + fButtonCancel = new Button(fCompositeLogin, SWT.PUSH); + fButtonCancel.setText("Cancel"); //$NON-NLS-1$ + // Configure layout data + GridData data = new GridData(SWT.NONE, SWT.NONE, false, false); + data.widthHint = F_BUTTON_WIDTH_HINT; + data.verticalIndent = 10; + fButtonCancel.setLayoutData(data); + } + + /** + * + */ + private void createUIButtonOK() { + // Create the button + fButtonOK = new Button(fCompositeLogin, SWT.PUSH); + fButtonOK.setText("OK"); //$NON-NLS-1$ + // Configure layout data + GridData data = new GridData(SWT.NONE, SWT.NONE, false, false); + data.widthHint = F_BUTTON_WIDTH_HINT; + data.verticalIndent = 10; + fButtonOK.setLayoutData(data); + } + + /** + * + */ + private void createUILabelBlank() { + Label label = new Label(fCompositeLogin, SWT.NONE); + label.setVisible(false); + } + + /** + * + */ + private void createUITextPassword() { + // Create the text widget + int style = SWT.PASSWORD | SWT.BORDER; + fTextPassword = new Text(fCompositeLogin, style); + // Configure layout data + GridData data = new GridData(SWT.NONE, SWT.NONE, false, false); + data.widthHint = F_TEXT_WIDTH_HINT; + data.horizontalSpan = 2; + fTextPassword.setLayoutData(data); + } + + /** + * + */ + private void createUILabelPassword() { + // Create the label + Label label = new Label(fCompositeLogin, SWT.NONE); + label.setText("&Password:"); //$NON-NLS-1$ + // Configure layout data + GridData data = new GridData(); + data.horizontalIndent = F_LABEL_HORIZONTAL_INDENT; + label.setLayoutData(data); + } + + /** + * + */ + private void createUITextUserName() { + // Create the text widget + fTextUsername = new Text(fCompositeLogin, SWT.BORDER); + // Configure layout data + GridData data = new GridData(SWT.NONE, SWT.NONE, false, false); + data.widthHint = F_TEXT_WIDTH_HINT; + data.horizontalSpan = 2; + fTextUsername.setLayoutData(data); + } + + /** + * + */ + private void createUILabelUserName() { + // Create the label + Label label = new Label(fCompositeLogin, SWT.NONE); + label.setText("&User Name:"); //$NON-NLS-1$ + // Configure layout data + GridData data = new GridData(); + data.horizontalIndent = F_LABEL_HORIZONTAL_INDENT; + label.setLayoutData(data); + } + + /** + * + */ + private void createUICompositeBlank() { + Composite spanner = new Composite(fCompositeLogin, SWT.NONE); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + data.horizontalSpan = F_COLUMN_COUNT; + spanner.setLayoutData(data); + } + + /** + * + */ + private void createUICompositeLogin() { + // Create the composite + fCompositeLogin = new Composite(getSplash(), SWT.BORDER); + GridLayout layout = new GridLayout(F_COLUMN_COUNT, false); + fCompositeLogin.setLayout(layout); + } + + /** + * + */ + private void configureUISplash() { + // Configure layout + FillLayout layout = new FillLayout(); + getSplash().setLayout(layout); + // Force shell to inherit the splash background + getSplash().setBackgroundMode(SWT.INHERIT_DEFAULT); + } + +} diff --git a/pom.xml b/pom.xml index dc1a408..02e906c 100755 --- a/pom.xml +++ b/pom.xml @@ -78,7 +78,36 @@ true - + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.jacoco + + jacoco-maven-plugin + + + [0.7.2.201409121644,) + + + prepare-agent + + + + + + + + + + +