From 7a7e786fa3d960ba081c09e3e7ed8228ecf82b9d Mon Sep 17 00:00:00 2001 From: Krishna Date: Mon, 19 Oct 2020 17:18:52 +0200 Subject: [PATCH 01/50] Include task integrator as an update site --- .../.project | 17 +++ .../build.properties | 2 + .../feature.xml | 117 ++++++++++++++++++ .../pom.xml | 12 ++ .../META-INF/MANIFEST.MF | 9 +- .../build.properties | 6 +- pom.xml | 1 + repository/category.xml | 4 + 8 files changed, 166 insertions(+), 2 deletions(-) create mode 100644 features/de.cognicrypt.integrator.task.feature/.project create mode 100644 features/de.cognicrypt.integrator.task.feature/build.properties create mode 100644 features/de.cognicrypt.integrator.task.feature/feature.xml create mode 100644 features/de.cognicrypt.integrator.task.feature/pom.xml diff --git a/features/de.cognicrypt.integrator.task.feature/.project b/features/de.cognicrypt.integrator.task.feature/.project new file mode 100644 index 000000000..e5a8b4d44 --- /dev/null +++ b/features/de.cognicrypt.integrator.task.feature/.project @@ -0,0 +1,17 @@ + + + de.cognicrypt.integrator.task.feature + + + + + + org.eclipse.pde.FeatureBuilder + + + + + + org.eclipse.pde.FeatureNature + + diff --git a/features/de.cognicrypt.integrator.task.feature/build.properties b/features/de.cognicrypt.integrator.task.feature/build.properties new file mode 100644 index 000000000..cc2efe007 --- /dev/null +++ b/features/de.cognicrypt.integrator.task.feature/build.properties @@ -0,0 +1,2 @@ +bin.includes = feature.xml +src.includes = feature.xml diff --git a/features/de.cognicrypt.integrator.task.feature/feature.xml b/features/de.cognicrypt.integrator.task.feature/feature.xml new file mode 100644 index 000000000..4244412b2 --- /dev/null +++ b/features/de.cognicrypt.integrator.task.feature/feature.xml @@ -0,0 +1,117 @@ + + + + + CogniCrypt is an Eclipse plugin that supports Java developers in using cryptographic APIs. It supports developers in two ways. First, it may generate code snippets for a number of programming tasks that involve cryptography, e.g., communication over a secure channel, data encryption, and long-term archiving. Second, it continuously runs a suite of static analyses in the background that check the developer's code for misuses of cryptographic APIs. + + + + Copyrights reserved. + + + + Eclipse Public License - v 2.0 +THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE (“AGREEMENT”). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. +1. DEFINITIONS + +“Contribution” means: + + a) in the case of the initial Contributor, the initial content Distributed under this Agreement, and + b) in the case of each subsequent Contributor: + i) changes to the Program, and + ii) additions to the Program; + where such changes and/or additions to the Program originate from and are Distributed by that particular Contributor. A Contribution “originates” from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include changes or additions to the Program that are not Modified Works. + +“Contributor” means any person or entity that Distributes the Program. + +“Licensed Patents” mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. + +“Program” means the Contributions Distributed in accordance with this Agreement. + +“Recipient” means anyone who receives the Program under this Agreement or any Secondary License (as applicable), including Contributors. + +“Derivative Works” shall mean any work, whether in Source Code or other form, that is based on (or derived from) the Program and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. + +“Modified Works” shall mean any work in Source Code or other form that results from an addition to, deletion from, or modification of the contents of the Program, including, for purposes of clarity any new file in Source Code form that contains any contents of the Program. Modified Works shall not include works that contain only declarations, interfaces, types, classes, structures, or files of the Program solely in each case in order to link to, bind by name, or subclass the Program or Modified Works thereof. + +“Distribute” means the acts of a) distributing or b) making available in any manner that enables the transfer of a copy. + +“Source Code” means the form of a Program preferred for making modifications, including but not limited to software source code, documentation source, and configuration files. + +“Secondary License” means either the GNU General Public License, Version 2.0, or any later versions of that license, including any exceptions or additional permissions as identified by the initial Contributor. +2. GRANT OF RIGHTS + + a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, Distribute and sublicense the Contribution of such Contributor, if any, and such Derivative Works. + b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in Source Code or other form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. + c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to Distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program. + d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. + e) Notwithstanding the terms of any Secondary License, no Contributor makes additional grants to any Recipient (other than those set forth in this Agreement) as a result of such Recipient's receipt of the Program under the terms of a Secondary License (if permitted under the terms of Section 3). + +3. REQUIREMENTS + +3.1 If a Contributor Distributes the Program in any form, then: + + a) the Program must also be made available as Source Code, in accordance with section 3.2, and the Contributor must accompany the Program with a statement that the Source Code for the Program is available under this Agreement, and informs Recipients how to obtain it in a reasonable manner on or through a medium customarily used for software exchange; and + b) the Contributor may Distribute the Program under a license different than this Agreement, provided that such license: + i) effectively disclaims on behalf of all other Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; + ii) effectively excludes on behalf of all other Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; + iii) does not attempt to limit or alter the recipients' rights in the Source Code under section 3.2; and + iv) requires any subsequent distribution of the Program by any party to be under a license that satisfies the requirements of this section 3. + +3.2 When the Program is Distributed as Source Code: + + a) it must be made available under this Agreement, or if the Program (i) is combined with other material in a separate file or files made available under a Secondary License, and (ii) the initial Contributor attached to the Source Code the notice described in Exhibit A of this Agreement, then the Program may be made available under the terms of such Secondary Licenses, and + b) a copy of this Agreement must be included with each copy of the Program. + +3.3 Contributors may not remove or alter any copyright, patent, trademark, attribution notices, disclaimers of warranty, or limitations of liability (‘notices’) contained within the Program from any copy of the Program which they Distribute, provided that Contributors may add their own appropriate notices. +4. COMMERCIAL DISTRIBUTION + +Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor (“Commercial Contributor”) hereby agrees to defend and indemnify every other Contributor (“Indemnified Contributor”) against any losses, damages and costs (collectively “Losses”) arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense. + +For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages. +5. NO WARRANTY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE PROGRAM IS PROVIDED ON AN “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement, including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. +6. DISCLAIMER OF LIABILITY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT PERMITTED BY APPLICABLE LAW, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +7. GENERAL + +If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. + +If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. + +All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. + +Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be Distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to Distribute the Program (including its Contributions) under the new version. + +Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved. Nothing in this Agreement is intended to be enforceable by any entity that is not a Contributor or Recipient. No third-party beneficiary rights are created under this Agreement. + + + + + + + + + + + + + + + + + + + + diff --git a/features/de.cognicrypt.integrator.task.feature/pom.xml b/features/de.cognicrypt.integrator.task.feature/pom.xml new file mode 100644 index 000000000..fada20f57 --- /dev/null +++ b/features/de.cognicrypt.integrator.task.feature/pom.xml @@ -0,0 +1,12 @@ + + 4.0.0 + de.cognicrypt.integrator.task.feature + eclipse-feature + + de.cognicrypt + de.cognicrypt.parent + 1.0.0-SNAPSHOT + ../../pom.xml + + diff --git a/plugins/de.cognicrypt.integrator.task/META-INF/MANIFEST.MF b/plugins/de.cognicrypt.integrator.task/META-INF/MANIFEST.MF index 5c514a22a..7601fcdba 100644 --- a/plugins/de.cognicrypt.integrator.task/META-INF/MANIFEST.MF +++ b/plugins/de.cognicrypt.integrator.task/META-INF/MANIFEST.MF @@ -18,4 +18,11 @@ Automatic-Module-Name: de.cognicrypt.integrator.task Bundle-ActivationPolicy: lazy Bundle-ClassPath: lib/claferchocoig.jar, lib/dom4j-2.0.0.jar, - . + ., + src/main/ +Export-Package: de.cognicrypt.integrator.task, + de.cognicrypt.integrator.task.actions, + de.cognicrypt.integrator.task.controllers, + de.cognicrypt.integrator.task.models, + de.cognicrypt.integrator.task.widgets, + de.cognicrypt.integrator.task.wizard diff --git a/plugins/de.cognicrypt.integrator.task/build.properties b/plugins/de.cognicrypt.integrator.task/build.properties index aaf867404..3c7434086 100644 --- a/plugins/de.cognicrypt.integrator.task/build.properties +++ b/plugins/de.cognicrypt.integrator.task/build.properties @@ -4,4 +4,8 @@ output.. = bin/ bin.includes = META-INF/,\ .,\ lib/claferchocoig.jar,\ - lib/dom4j-2.0.0.jar + lib/dom4j-2.0.0.jar,\ + src/main/,\ + plugin.xml,\ + pom.xml,\ + build.properties diff --git a/pom.xml b/pom.xml index bcf0a5b92..ce80fadca 100644 --- a/pom.xml +++ b/pom.xml @@ -97,6 +97,7 @@ plugins/de.cognicrypt.integrator.primitive/ features/de.cognicrypt.core.feature/ features/de.cognicrypt.codegenerator.feature/ + features/de.cognicrypt.integrator.task.feature/ features/de.cognicrypt.cryslhandler.feature/ features/de.cognicrypt.staticanalyzer.feature/ repository/ diff --git a/repository/category.xml b/repository/category.xml index ccf2d7011..4eaa2cc4c 100644 --- a/repository/category.xml +++ b/repository/category.xml @@ -15,8 +15,12 @@ + + + + From 61882e26c6ad426215fbe2e3e0025fdfca1f4de1 Mon Sep 17 00:00:00 2001 From: Krishna Date: Mon, 19 Oct 2020 23:54:24 +0200 Subject: [PATCH 02/50] Minor fix to the Crysl based code generator --- .../codegenerator/generator/CrySLBasedCodeGenerator.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/de.cognicrypt.codegenerator/src/main/java/de/cognicrypt/codegenerator/generator/CrySLBasedCodeGenerator.java b/plugins/de.cognicrypt.codegenerator/src/main/java/de/cognicrypt/codegenerator/generator/CrySLBasedCodeGenerator.java index d232f36e2..0da9cde20 100644 --- a/plugins/de.cognicrypt.codegenerator/src/main/java/de/cognicrypt/codegenerator/generator/CrySLBasedCodeGenerator.java +++ b/plugins/de.cognicrypt.codegenerator/src/main/java/de/cognicrypt/codegenerator/generator/CrySLBasedCodeGenerator.java @@ -1264,6 +1264,14 @@ public boolean visit(MethodInvocation node) { crySLRule = crySLRuleFromSootRunner; } } + if(crySLRule == null) { + try { + crySLRule = CrySLUtils.getCrySLRule(simpleRuleName); + } catch (MalformedURLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } for (CodeGenCrySLObject o : pars) { for (TransitionEdge edge : crySLRule.getUsagePattern().getEdges()) { for (CrySLMethod method : edge.getLabel()) { From 3ce0b5ef3e94266c72761c1df2862e456f1e7879 Mon Sep 17 00:00:00 2001 From: felixdaas Date: Thu, 14 Jan 2021 14:41:16 +0100 Subject: [PATCH 03/50] UI Update --- .../task/widgets/BrowseFilePopUp.java | 184 ++++++++++++++++ .../task/widgets/CompositeBrowseForFile.java | 2 +- .../CompositeChoiceForModeOfWizard.java | 198 +++++++++++++----- ...positeGranularUIForHighLevelQuestions.java | 51 ++--- .../widgets/CompositeModifyDeleteButtons.java | 7 +- .../CompositeToHoldGranularUIElements.java | 23 +- .../CompositeToHoldSmallerUIElements.java | 26 +-- .../integrator/task/widgets/GroupAnswer.java | 54 +++-- .../wizard/PageForTaskIntegratorWizard.java | 31 ++- .../task/wizard/QuestionDialog.java | 90 ++++---- .../integrator/task/wizard/QuestionsPage.java | 15 +- 11 files changed, 503 insertions(+), 178 deletions(-) create mode 100644 plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/BrowseFilePopUp.java diff --git a/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/BrowseFilePopUp.java b/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/BrowseFilePopUp.java new file mode 100644 index 000000000..5430927e9 --- /dev/null +++ b/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/BrowseFilePopUp.java @@ -0,0 +1,184 @@ +package de.cognicrypt.integrator.task.widgets; + +import java.awt.Dimension; +import java.awt.Toolkit; +import java.io.File; +import java.util.ArrayList; +import java.util.LinkedList; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; + +import de.cognicrypt.core.Constants; +import de.cognicrypt.integrator.task.wizard.PageForTaskIntegratorWizard; + + +public class BrowseFilePopUp extends Dialog { + PageForTaskIntegratorWizard pageForTaskIntegratorWizard; + CompositeChoiceForModeOfWizard compositeChoiceForModeOfWizard; + CompositeBrowseForFile compCryslTemplate; + CompositeBrowseForFile compCryslTemplateAtInit; + LinkedList listOfCompCryslTemplate = new LinkedList(); + Dimension windowSize; + + BrowseFilePopUp(final Shell parentShell, PageForTaskIntegratorWizard pageForTaskIntegratorWizard, CompositeChoiceForModeOfWizard compositeChoiceForModeOfWizard) { + super(parentShell); + this.pageForTaskIntegratorWizard = pageForTaskIntegratorWizard; + this.compositeChoiceForModeOfWizard = compositeChoiceForModeOfWizard; + windowSize = Toolkit.getDefaultToolkit().getScreenSize(); + } + + protected Control createDialogArea(Composite parent) { + final Composite container = (Composite) super.createDialogArea(parent); + container.setLayout(new GridLayout(1, false)); + + //v1 + /*final Label reminder = new Label(container, SWT.NONE); + reminder.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); + reminder.setText("Please make sure your identifier is unique!"); + + final Composite compositeBrowse = new Composite(container, SWT.NONE); + compositeBrowse.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + compositeBrowse.setLayout(new GridLayout(1, false)); + + final Composite composite = new Composite(container, SWT.NONE); + composite.setLayout(new GridLayout(1, false)); + composite.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + + compCryslTemplate = new CompositeBrowseForFile(composite, SWT.NONE, + Constants.WIDGET_DATA_LOCATION_OF_CRYSLTEMPLATE_FILE, new String[] { "*.java" }, + "Select crysl template file that contains the code details", pageForTaskIntegratorWizard); + compCryslTemplate.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true)); + listOfCompCryslTemplate.add(compCryslTemplate);*/ + + // v2 + final Label reminder = new Label(container, SWT.NONE); + reminder.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); + reminder.setText("Please make sure your identifier is unique!"); + + final Composite compositeAllModes = new Composite(container, SWT.NONE); + compositeAllModes.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); + compositeAllModes.setVisible(true); + compositeAllModes.setLayout(new GridLayout(1, false)); + + final ScrolledComposite scrolledComposite = new ScrolledComposite(compositeAllModes, + SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); + scrolledComposite.setExpandHorizontal(true); + scrolledComposite.setExpandVertical(true); + scrolledComposite.setMinWidth((int) (/*windowSize.getWidth()*0.27)*/ 800)); + scrolledComposite.setMinHeight((int) (/*windowSize.getHeight()*0.1)*/150)); + + final Composite composite = new Composite(scrolledComposite, SWT.NONE); + composite.setLayout(new GridLayout(1, false)); + scrolledComposite.setContent(composite); + + final Composite composite_2 = new Composite(composite, SWT.NONE); + composite_2.setLayout(new GridLayout(1, false)); + composite_2.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + + final Composite composite_3 = new Composite(composite, SWT.NONE); + composite_3.setLayout(new GridLayout()); + composite_3.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + + compCryslTemplateAtInit = new CompositeBrowseForFile(composite_2, SWT.NONE, + Constants.WIDGET_DATA_LOCATION_OF_CRYSLTEMPLATE_FILE, new String[] { "*.java" }, + "Select crysl template file that contains the code details", pageForTaskIntegratorWizard); + compCryslTemplateAtInit.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true)); + + listOfCompCryslTemplate.add(compCryslTemplateAtInit); + + final Button btnAdd = new Button(composite_3, SWT.NONE); + btnAdd.setText("Add"); + + btnAdd.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(final SelectionEvent e) { + compCryslTemplate = new CompositeBrowseForFile(composite_2, SWT.NONE, + Constants.WIDGET_DATA_LOCATION_OF_CRYSLTEMPLATE_FILE, new String[] { "*.java" }, + "Select crysl template file that contains the code details", pageForTaskIntegratorWizard); + compCryslTemplate.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true)); + + listOfCompCryslTemplate.add(compCryslTemplate); + + scrolledComposite.layout(true, true); + scrolledComposite.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); + } + }); + + return container; + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText("Selection dialog"); + } + + @Override + protected Point getInitialSize() { + return new Point((int) (1000/*windowSize.getWidth()*0.3*/), (int) (300/*windowSize.getHeight()*0.2*/)); // 1000, 350 + } + + + LinkedList listOfIdentifier = new LinkedList(); + + @Override + protected void okPressed() { + // check if id was used already and is in the template list + boolean warningIdAlreadyUsed = false; + try { + ArrayList listOfIdentifierTemplateList = compositeChoiceForModeOfWizard.getIdentifiers(); + for(int i = 0; i < listOfCompCryslTemplate.size(); i++) { + for(int k = 0; k < listOfIdentifierTemplateList.size(); k++) { + if(listOfCompCryslTemplate.get(i).getTxtBoxOption().equals(listOfIdentifierTemplateList.get(k))) { + listOfCompCryslTemplate.remove(i); //check that it actually isn't added + warningIdAlreadyUsed = true; + } + } + } + }catch (Exception e) {} + + // check if identifier is unique in terms of the add window + boolean warning = false; + for(int i = 0; i < listOfCompCryslTemplate.size(); i++) { + int identifierUnique = 0; + for(int k = 0; k < listOfIdentifier.size(); k++) { + if (listOfIdentifier.get(k).equals(listOfCompCryslTemplate.get(i).getTxtBoxOption())) { + identifierUnique++; + compositeChoiceForModeOfWizard.addTemplate(listOfCompCryslTemplate.get(i).getTxtBoxOption() + ":Copy(" + identifierUnique + ")", new File(listOfCompCryslTemplate.get(i).getText())); + } + } + + if(identifierUnique != 0) + warning = true; + else + compositeChoiceForModeOfWizard.addTemplate(listOfCompCryslTemplate.get(i).getTxtBoxOption(), new File(listOfCompCryslTemplate.get(i).getText())); + + identifierUnique = 0; + listOfIdentifier.add(listOfCompCryslTemplate.get(i).getTxtBoxOption()); + } + + // add warnings + if(warningIdAlreadyUsed) { + MessageDialog.openError(getShell(), "Warning", "Because one or more identifier you chose are already in use the chosen file or files could not be added!"); + warningIdAlreadyUsed = false; + } + + if(warning) + MessageDialog.openError(getShell(), "Warning", "You used the same identifier more than once therefore the identifier was changed!"); + + super.okPressed(); + } +} \ No newline at end of file diff --git a/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/CompositeBrowseForFile.java b/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/CompositeBrowseForFile.java index 27e013e7c..9795f4bb7 100644 --- a/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/CompositeBrowseForFile.java +++ b/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/CompositeBrowseForFile.java @@ -85,7 +85,7 @@ public CompositeBrowseForFile(final Composite parent, final int style, final Str super(parent, style); // this object is required in the text box listener. Should not be called too // often. - setObjectForDataInNonGuidedMode(findAncestor(getParent()).getObjectForDataInNonGuidedMode()); + //setObjectForDataInNonGuidedMode(findAncestor(getParent()).getObjectForDataInNonGuidedMode()); setTheLocalContainerPage(theContainerpageForValidation); final GridLayout gridLayout = new GridLayout(3, false); diff --git a/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/CompositeChoiceForModeOfWizard.java b/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/CompositeChoiceForModeOfWizard.java index 5d2ddbbd1..eaa4fc2ce 100644 --- a/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/CompositeChoiceForModeOfWizard.java +++ b/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/CompositeChoiceForModeOfWizard.java @@ -13,6 +13,8 @@ import java.io.File; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; import org.eclipse.core.runtime.ICoreRunnable; import org.eclipse.core.runtime.jobs.Job; @@ -25,11 +27,15 @@ import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.layout.RowData; +import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import de.cognicrypt.core.Constants; import de.cognicrypt.integrator.task.UIConstants; @@ -45,6 +51,9 @@ public class CompositeChoiceForModeOfWizard extends Composite { private ControlDecoration decNameOfTheTask; // Decoration variable to be able to access it in the events. private PageForTaskIntegratorWizard theLocalContainerPage; // this is needed to set whether the page has been // completed yet or not. + + final List templateList; + private ArrayList lstCryslTemplates = new ArrayList(); public ArrayList getLstCryslTemplates() { @@ -79,7 +88,7 @@ public CompositeChoiceForModeOfWizard(final Composite parent, final int style, compositeChooseTheMode.setLayout(new GridLayout(1, false)); final Label lblNameOfTheTask = new Label(compositeChooseTheMode, SWT.NONE); - lblNameOfTheTask.setText("Name of the Task "); + lblNameOfTheTask.setText("Task"); // Initialize the decorator for the label for the text box. setDecNameOfTheTask(new ControlDecoration(lblNameOfTheTask, SWT.TOP | SWT.RIGHT)); @@ -94,45 +103,62 @@ public CompositeChoiceForModeOfWizard(final Composite parent, final int style, this.txtTaskName.setTextLimit(Constants.SINGLE_LINE_TEXT_BOX_LIMIT); final Label lblDescriptionOfThe = new Label(compositeChooseTheMode, SWT.NONE); - lblDescriptionOfThe.setText("Description of the Task :"); + lblDescriptionOfThe.setText("Description"); setTxtDescriptionOfTask(new Text(compositeChooseTheMode, SWT.BORDER | SWT.WRAP | SWT.MULTI)); final GridData gd_txtDescriptionOfTask = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1); gd_txtDescriptionOfTask.heightHint = 67; getTxtTaskDescription().setLayoutData(gd_txtDescriptionOfTask); getTxtTaskDescription().setTextLimit(Constants.MULTI_LINE_TEXT_BOX_LIMIT); - - final Button btnCustomLibrary = new Button(compositeChooseTheMode, SWT.CHECK); - btnCustomLibrary.setText("Include a custom library"); - - final Composite compositeContainerGroupForLibrary = new Composite(compositeChooseTheMode, SWT.NONE); - compositeContainerGroupForLibrary.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - compositeContainerGroupForLibrary.setVisible(false); - compositeContainerGroupForLibrary.setLayout(new GridLayout(1, false)); - - // Updated the composite to deal with directory instead of a jar file for the - // custom library. - final CompositeBrowseForFile compLib = new CompositeBrowseForFile(compositeContainerGroupForLibrary, SWT.NONE, - Constants.WIDGET_DATA_LIBRARY_LOCATION_OF_THE_TASK, null, "Select file that contains the library", - getTheLocalContainerPage()); - compLib.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - - final Button btnDoYouWishToUseTheGuidedMode = new Button(compositeChooseTheMode, SWT.CHECK); - btnDoYouWishToUseTheGuidedMode.setText("Use the guided mode"); - // Guided mode set by default. - btnDoYouWishToUseTheGuidedMode.setSelection(true); - getObjectForDataInNonGuidedMode().setGuidedModeChosen(btnDoYouWishToUseTheGuidedMode.getSelection()); - - final Composite compositeNonguidedMode = new Composite(compositeChooseTheMode, SWT.NONE); - compositeNonguidedMode.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); - compositeNonguidedMode.setVisible(false); - compositeNonguidedMode.setLayout(new GridLayout(1, false)); - - final Composite compositeAllModes = new Composite(compositeChooseTheMode, SWT.NONE); - compositeAllModes.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); - compositeAllModes.setVisible(true); - compositeAllModes.setLayout(new GridLayout(1, false)); - + + Label spacer = new Label(compositeChooseTheMode, SWT.HORIZONTAL); + spacer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL, 30)); + + /** Template Start **/ + final Label lblTemplateList = new Label(compositeChooseTheMode, SWT.NONE); + lblTemplateList.setText("Templates"); + + templateList = new List(compositeChooseTheMode, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); + final GridData gd_templateList = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1); + gd_templateList.heightHint = 25*5; + templateList.setLayoutData(gd_templateList); + + final Composite compositeTemplateBtns = new Composite(compositeChooseTheMode, SWT.NONE); + //compositeTemplateBtns.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1); + compositeTemplateBtns.setVisible(true); + compositeTemplateBtns.setLayout(new RowLayout(SWT.HORIZONTAL)); + + final Button btnAddTemplate = new Button(compositeTemplateBtns, SWT.NONE); + btnAddTemplate.setText("Add"); + + final Button btnRemoveTemplate = new Button(compositeTemplateBtns, SWT.NONE); + btnRemoveTemplate.setText("Remove"); + + + ModelAdvancedMode objectForDataInNonGuidedModeTmp = getObjectForDataInNonGuidedMode(); + HashMap crylTemplatesWithOption = objectForDataInNonGuidedModeTmp.getCrylTemplatesWithOption(); + + CompositeChoiceForModeOfWizard compositeChoiceForModeOfWizard = this; + + btnAddTemplate.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(final SelectionEvent e) { + // Open new page for User Story 3 which calls addTemplate(String identifier, File path) + BrowseFilePopUp fileBrowse = new BrowseFilePopUp(parent.getShell(), getTheLocalContainerPage(), compositeChoiceForModeOfWizard); + fileBrowse.open(); + } + }); + + btnRemoveTemplate.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(final SelectionEvent e) { + removeTemplates(templateList.getSelection()); + } + }); + + + /** Legacy Template Code + final ScrolledComposite scrolledComposite = new ScrolledComposite(compositeAllModes, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); scrolledComposite.setExpandHorizontal(true); @@ -162,7 +188,7 @@ public CompositeChoiceForModeOfWizard(final Composite parent, final int style, public void widgetSelected(final SelectionEvent e) { final CompositeBrowseForFile compCryslTemplate = new CompositeBrowseForFile(composite_2, SWT.NONE, Constants.WIDGET_DATA_LOCATION_OF_CRYSLTEMPLATE_FILE, new String[] { "*.java" }, - "Select crysl tempplate file that contains the code details", getTheLocalContainerPage()); + "Select crysl template file that contains the code details", getTheLocalContainerPage()); compCryslTemplate.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true)); lstCryslTemplates.add(compCryslTemplate); @@ -184,10 +210,40 @@ public void widgetSelected(final SelectionEvent e) { for (CompositeBrowseForFile cryslTemplateOpts : lstCryslTemplates) { File locationOfCryslTemplate = new File(cryslTemplateOpts.getText()); crylTemplatesWithOption.put(cryslTemplateOpts.getTxtBoxOption(), locationOfCryslTemplate); + System.out.println(cryslTemplateOpts.getTxtBoxOption()); } } - }); + }); **/ + + Label spacerBeforeFileImports = new Label(this, SWT.HORIZONTAL); + spacerBeforeFileImports.setLayoutData(new GridData(GridData.FILL_HORIZONTAL, 30)); + + final Composite compositeFileImports = new Composite(this, SWT.NONE); + compositeFileImports.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); + compositeFileImports.setVisible(true); + compositeFileImports.setLayout(new GridLayout(1, false)); + + final CompositeBrowseForFile compPNG = new CompositeBrowseForFile(compositeFileImports, SWT.NONE, + Constants.WIDGET_DATA_LOCATION_OF_PNG_FILE, new String[] { "*.png" }, + "Select png file that contains the icon for the task you wish to integrate", + getTheLocalContainerPage()); + compPNG.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + + Label spacerBeforeGuidedMode = new Label(compositeFileImports, SWT.HORIZONTAL); + spacerBeforeGuidedMode.setLayoutData(new GridData(GridData.FILL_HORIZONTAL, 30)); + + final Button btnDoYouWishToUseTheGuidedMode = new Button(compositeFileImports, SWT.CHECK); + btnDoYouWishToUseTheGuidedMode.setText("Use guided mode"); + // Guided mode set by default. + btnDoYouWishToUseTheGuidedMode.setSelection(true); + getObjectForDataInNonGuidedMode().setGuidedModeChosen(btnDoYouWishToUseTheGuidedMode.getSelection()); + final Composite compositeNonguidedMode = new Composite(compositeFileImports, SWT.NONE); + compositeNonguidedMode.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); + compositeNonguidedMode.setVisible(false); + compositeNonguidedMode.setLayout(new GridLayout(1, false)); + /* * final CompositeBrowseForFile compCryslTemplate = new * CompositeBrowseForFile(compositeAllModes, SWT.NONE, @@ -200,11 +256,7 @@ public void widgetSelected(final SelectionEvent e) { Constants.WIDGET_DATA_LOCATION_OF_JSON_FILE, new String[] { "*.json" }, "Select json file that contains the high level questions", getTheLocalContainerPage()); compJson.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - final CompositeBrowseForFile compPNG = new CompositeBrowseForFile(compositeAllModes, SWT.NONE, - Constants.WIDGET_DATA_LOCATION_OF_PNG_FILE, new String[] { "*.png" }, - "Select png file that contains the icon for the task you wish to integrate", - getTheLocalContainerPage()); - compPNG.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + layout(); // moved all the event listeners at the bottom. @@ -233,21 +285,6 @@ public void widgetSelected(final SelectionEvent e) { } }); - btnCustomLibrary.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(final SelectionEvent e) { - final boolean tempSelectionStatus = btnCustomLibrary.getSelection(); - // Show the widget to get the file data if the check box is selected. - getObjectForDataInNonGuidedMode().setCustomLibraryRequired(tempSelectionStatus); - // Set the data value. - compositeContainerGroupForLibrary.setVisible(tempSelectionStatus); - - // Check if the page can be completed. - getTheLocalContainerPage().checkIfModeSelectionPageIsComplete(); - } - }); - /* * TODO removed for the user study. btnForceGuidedMode.addSelectionListener(new * SelectionAdapter() { @@ -362,4 +399,53 @@ public Text getTxtTaskDescription() { public void setTxtDescriptionOfTask(final Text txtDescriptionOfTask) { this.txtTaskDescription = txtDescriptionOfTask; } + + + public void redrawTable() { + ModelAdvancedMode objectForDataInNonGuidedModeTmp = getObjectForDataInNonGuidedMode(); + HashMap templates = objectForDataInNonGuidedModeTmp.getCrylTemplatesWithOption(); + + templateList.removeAll(); + + for(String identifier : templates.keySet()) { + templateList.add(identifier); + } + } + + public void addTemplate(String identifier, File path) { + ModelAdvancedMode objectForDataInNonGuidedModeTmp = getObjectForDataInNonGuidedMode(); + HashMap templates = objectForDataInNonGuidedModeTmp.getCrylTemplatesWithOption(); + + if (templates == null) { + objectForDataInNonGuidedModeTmp.setCrylTemplatesWithOption(new HashMap()); + templates = objectForDataInNonGuidedModeTmp.getCrylTemplatesWithOption(); + } + + templates.put(identifier, path); + + redrawTable(); + } + + public void removeTemplates(String[] identifiers) { + ModelAdvancedMode objectForDataInNonGuidedModeTmp = getObjectForDataInNonGuidedMode(); + HashMap templates = objectForDataInNonGuidedModeTmp.getCrylTemplatesWithOption(); + + if (templates == null) + return; + + for(String identifier : identifiers) { + templates.remove(identifier); + } + + redrawTable(); + } + + public ArrayList getIdentifiers(){ + ModelAdvancedMode objectForDataInNonGuidedModeTmp = getObjectForDataInNonGuidedMode(); + ArrayList ident = new ArrayList(); + HashMap templates = objectForDataInNonGuidedModeTmp.getCrylTemplatesWithOption(); + ident.addAll(templates.keySet()); + return ident; + }; + } diff --git a/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/CompositeGranularUIForHighLevelQuestions.java b/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/CompositeGranularUIForHighLevelQuestions.java index 27de6c923..cf566f947 100644 --- a/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/CompositeGranularUIForHighLevelQuestions.java +++ b/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/CompositeGranularUIForHighLevelQuestions.java @@ -32,9 +32,10 @@ public class CompositeGranularUIForHighLevelQuestions extends Composite { private final Text txtQuestionID; public Text txtQuestion; - private final Text txtAnswerType; + //private final Text txtAnswerType; private Question question; + /** * Create the composite. @@ -42,7 +43,8 @@ public class CompositeGranularUIForHighLevelQuestions extends Composite { * @param parent * @param style */ - public CompositeGranularUIForHighLevelQuestions(final Composite parent, final int style, final Question questionParam, final boolean linkAnswerPage) { + public CompositeGranularUIForHighLevelQuestions(final Composite parent, final int style, final Question questionParam, final boolean linkAnswerPage, + ArrayList ident) { super(parent, SWT.BORDER); setQuestion(questionParam); @@ -53,7 +55,7 @@ public CompositeGranularUIForHighLevelQuestions(final Composite parent, final in setLayout(new GridLayout(2, false)); - final CompositeModifyDeleteButtons grpModifyDeleteButtons = new CompositeModifyDeleteButtons(this, this.question); + final CompositeModifyDeleteButtons grpModifyDeleteButtons = new CompositeModifyDeleteButtons(this, this.question, ident); grpModifyDeleteButtons.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); // Only visible for "pageForHighLevelQuestions" page @@ -66,7 +68,7 @@ public CompositeGranularUIForHighLevelQuestions(final Composite parent, final in final Group grpQuestionDetails = new Group(this, SWT.NONE); grpQuestionDetails.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 4)); - grpQuestionDetails.setLayout(new GridLayout(4, false)); + grpQuestionDetails.setLayout(new GridLayout(2, false)); @@ -78,12 +80,12 @@ public CompositeGranularUIForHighLevelQuestions(final Composite parent, final in this.txtQuestionID = new Text(grpQuestionDetails, SWT.BORDER); this.txtQuestionID.setEditable(false); - final GridData gdTxtQuestionID = new GridData(SWT.FILL, SWT.CENTER, true, false); + final GridData gdTxtQuestionID = new GridData(SWT.FILL, SWT.CENTER, false, false); gdTxtQuestionID.widthHint = 0; this.txtQuestionID.setLayoutData(gdTxtQuestionID); this.txtQuestionID.setText(Integer.toString(this.question.getId())); - final Label lblType = new Label(grpQuestionDetails, SWT.NONE); + /*final Label lblType = new Label(grpQuestionDetails, SWT.NONE); lblType.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); lblType.setText("Type:"); @@ -91,7 +93,7 @@ public CompositeGranularUIForHighLevelQuestions(final Composite parent, final in this.txtAnswerType.setEditable(false); final GridData gdTxtAnswerType = new GridData(SWT.FILL, SWT.CENTER, true, false); gdTxtAnswerType.widthHint = 0; - this.txtAnswerType.setLayoutData(gdTxtAnswerType); + this.txtAnswerType.setLayoutData(gdTxtAnswerType);*/ final Label lblQuestion = new Label(grpQuestionDetails, SWT.NONE); lblQuestion.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); @@ -99,33 +101,34 @@ public CompositeGranularUIForHighLevelQuestions(final Composite parent, final in this.txtQuestion = new Text(grpQuestionDetails, SWT.BORDER); this.txtQuestion.setEditable(false); - final GridData gdTxtQuestion = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1); + final GridData gdTxtQuestion = new GridData(SWT.FILL, SWT.CENTER, false, false); gdTxtQuestion.widthHint = 0; this.txtQuestion.setLayoutData(gdTxtQuestion); setTextQuestion(this.question.getQuestionText()); - if (this.question.getElement().equals(Constants.GUIElements.combo)) { + /*if (this.question.getElement().equals(Constants.GUIElements.combo)) { this.txtAnswerType.setText(Constants.dropDown); } else if (this.question.getElement().equals(Constants.GUIElements.text)) { this.txtAnswerType.setText(Constants.textBox); } else if (this.question.getElement().equals(Constants.GUIElements.radio)) { this.txtAnswerType.setText(Constants.radioButton); + }*/ + + final Label lblAnswers = new Label(grpQuestionDetails, SWT.NONE); + lblAnswers.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + lblAnswers.setText("Answers:"); + + final CompositeToHoldSmallerUIElements compositeForAnswers = new CompositeToHoldSmallerUIElements( + grpQuestionDetails, SWT.None, null, false); + final GridData gdCompositeForAnswers = new GridData(SWT.LEFT, SWT.FILL, true, false, 2, 2); + gdCompositeForAnswers.heightHint = 100; + gdCompositeForAnswers.widthHint = 500; + compositeForAnswers.setLayoutData(gdCompositeForAnswers); + for (final Answer answer : this.question.getAnswers()) { + compositeForAnswers.addAnswer(answer, false, ident); } - if (!this.question.getElement().equals(Constants.GUIElements.text)) { - final Label lblAnswers = new Label(grpQuestionDetails, SWT.NONE); - lblAnswers.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); - lblAnswers.setText("Answers:"); - - final CompositeToHoldSmallerUIElements compositeForAnswers = new CompositeToHoldSmallerUIElements(grpQuestionDetails, SWT.None, null, false); - final GridData gdCompositeForAnswers = new GridData(SWT.FILL, SWT.FILL, true, false, 3, 1); - gdCompositeForAnswers.heightHint = 100; - compositeForAnswers.setLayoutData(gdCompositeForAnswers); - for (final Answer answer : this.question.getAnswers()) { - compositeForAnswers.addAnswer(answer, false); - } - } } @Override @@ -155,7 +158,7 @@ public String getTextQuestion() { return this.txtQuestion.getText(); } - public String getAnswerType() { + /*public String getAnswerType() { return this.txtAnswerType.getText(); - } + }*/ } diff --git a/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/CompositeModifyDeleteButtons.java b/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/CompositeModifyDeleteButtons.java index b44f79cbd..76221ab68 100644 --- a/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/CompositeModifyDeleteButtons.java +++ b/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/CompositeModifyDeleteButtons.java @@ -30,7 +30,7 @@ public class CompositeModifyDeleteButtons extends Composite { int counter = 0; // private ArrayList claferFeatures; - public CompositeModifyDeleteButtons(final Composite parent, final Question questionParam) { + public CompositeModifyDeleteButtons(final Composite parent, final Question questionParam, ArrayList ident) { super(parent, SWT.RIGHT_TO_LEFT); // setClaferFeatures(claferFeatures); /* @@ -67,11 +67,12 @@ public void widgetSelected(final SelectionEvent e) { @Override public void widgetSelected(final SelectionEvent e) { final ArrayList listOfAllQuestions = ((CompositeToHoldGranularUIElements) btnModify.getParent().getParent().getParent().getParent()).getListOfAllQuestions(); - final QuestionDialog qstnDialog = new QuestionDialog(parent.getShell(), questionParam, listOfAllQuestions); + final QuestionDialog qstnDialog = new QuestionDialog(parent.getShell(), questionParam, listOfAllQuestions); //change later + qstnDialog.setlistCryslTemplatesIdentifier(ident); final int response = qstnDialog.open(); if (response == Window.OK) { final Question modifiedQuestion = qstnDialog.getQuestionDetails(); - ((CompositeToHoldGranularUIElements) btnModify.getParent().getParent().getParent().getParent()).modifyHighLevelQuestion(questionParam, modifiedQuestion); + ((CompositeToHoldGranularUIElements) btnModify.getParent().getParent().getParent().getParent()).modifyHighLevelQuestion(questionParam, modifiedQuestion, ident); } } }); diff --git a/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/CompositeToHoldGranularUIElements.java b/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/CompositeToHoldGranularUIElements.java index 789721237..4b430dfa2 100644 --- a/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/CompositeToHoldGranularUIElements.java +++ b/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/CompositeToHoldGranularUIElements.java @@ -21,10 +21,11 @@ public class CompositeToHoldGranularUIElements extends ScrolledComposite { private String targetPageName; private int lowestWidgetYAxisValue = Constants.PADDING_BETWEEN_GRANULAR_UI_ELEMENTS; - private ArrayList listOfAllQuestions; + int counter; + /** * Create the composite. * @@ -71,10 +72,10 @@ public void updateClaferContainer() { - public void addQuestionUIElements(final Question question, final boolean linkAnswerPage) { + public void addQuestionUIElements(final Question question, final boolean linkAnswerPage, ArrayList ident) { new CompositeGranularUIForHighLevelQuestions((Composite) getContent(), // the content composite of ScrolledComposite. - SWT.NONE, question, linkAnswerPage); + SWT.NONE, question, linkAnswerPage, ident); setMinSize(((Composite) getContent()).computeSize(SWT.DEFAULT, SWT.DEFAULT)); } @@ -96,7 +97,7 @@ public void moveUpTheQuestion(final Question question) { } Collections.swap(this.listOfAllQuestions, questionToBeMoveUp, questionToBeMoveDown); updateQuestionsID(); - updateQuestionContainer(); + updateQuestionContainer(new ArrayList()); } /** @@ -116,7 +117,7 @@ public void moveDownTheQuestion(final Question question) { } Collections.swap(this.listOfAllQuestions, questionToBeMoveUp, questionToBeMoveDown); updateQuestionsID(); - updateQuestionContainer(); + updateQuestionContainer(new ArrayList()); } /** @@ -128,7 +129,7 @@ public void deleteQuestion(final Question questionToBeDeleted) { this.listOfAllQuestions.remove(questionToBeDeleted); updateQuestionsID(); - updateQuestionContainer(); + updateQuestionContainer(new ArrayList()); } @@ -149,13 +150,13 @@ private void updateQuestionsID() { */ public void deleteAllQuestion() { this.listOfAllQuestions.clear(); - updateQuestionContainer(); + updateQuestionContainer(new ArrayList()); } /** * Updates the question container */ - public void updateQuestionContainer() { + public void updateQuestionContainer(ArrayList ident) { final Composite compositeContentOfThisScrolledComposite = (Composite) getContent(); // first dispose all the granular UI elements (which includes the deleted one). @@ -169,7 +170,7 @@ public void updateQuestionContainer() { // add all the clafer features excluding the deleted one. for (final Question questionUnderConsideration : this.listOfAllQuestions) { - addQuestionUIElements(questionUnderConsideration, false); + addQuestionUIElements(questionUnderConsideration, false, ident); } updateLayout(); } @@ -188,7 +189,7 @@ public void updateLayout() { * @param modifiedQuestion the modified question */ - public void modifyHighLevelQuestion(final Question originalQuestion, final Question modifiedQuestion) { + public void modifyHighLevelQuestion(final Question originalQuestion, final Question modifiedQuestion, ArrayList ident) { for (final Question questionUnderConsideration : this.listOfAllQuestions) { if (questionUnderConsideration.equals(originalQuestion)) { questionUnderConsideration.setQuestionText(modifiedQuestion.getQuestionText()); @@ -203,7 +204,7 @@ public void modifyHighLevelQuestion(final Question originalQuestion, final Quest break; } } - updateQuestionContainer(); + updateQuestionContainer(ident); } @Override diff --git a/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/CompositeToHoldSmallerUIElements.java b/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/CompositeToHoldSmallerUIElements.java index 118b27cd9..ff3cfe6b7 100644 --- a/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/CompositeToHoldSmallerUIElements.java +++ b/plugins/de.cognicrypt.integrator.task/src/main/java/de/cognicrypt/integrator/task/widgets/CompositeToHoldSmallerUIElements.java @@ -67,7 +67,6 @@ public CompositeToHoldSmallerUIElements(final Composite parent, final int style, this.XSLAttributes = new ArrayList(); - } @@ -97,11 +96,12 @@ public void removeXSLAttribute(final XSLAttribute xslAttribute) { * * @param answer * @param showRemoveButton + * @param templateIdentifier */ - public void addAnswer(final Answer answer, final boolean showRemoveButton) { - final GroupAnswer groupForAnswer = new GroupAnswer((Composite) getContent(), SWT.NONE, answer, showRemoveButton); - groupForAnswer.setBounds(Constants.PADDING_BETWEEN_SMALLER_UI_ELEMENTS, getLowestWidgetYAxisValue(), 890, 39); - setLowestWidgetYAxisValue(getLowestWidgetYAxisValue() + 39); + public void addAnswer(final Answer answer, final boolean showRemoveButton, ArrayList ident) { + GroupAnswer groupForAnswer = new GroupAnswer((Composite) getContent(), SWT.NONE, answer, showRemoveButton, ident); + groupForAnswer.setBounds(Constants.PADDING_BETWEEN_SMALLER_UI_ELEMENTS, getLowestWidgetYAxisValue(), 850, 50); + setLowestWidgetYAxisValue(getLowestWidgetYAxisValue() + 50); setMinHeight(getLowestWidgetYAxisValue()); } @@ -111,13 +111,13 @@ public void addAnswer(final Answer answer, final boolean showRemoveButton) { * * @param answerToBeDeleted */ - public void deleteAnswer(final Answer answerToBeDeleted) { + public void deleteAnswer(final Answer answerToBeDeleted, ArrayList ident) { this.arrayAnswer.remove(answerToBeDeleted); this.btnList.clear(); - updateAnswerContainer(); + updateAnswerContainer(ident); } - public void updateAnswerContainer() { + public void updateAnswerContainer(ArrayList ident) { final Composite contentOfThisScrolledComposite = (Composite) getContent(); for (final Control answerToDelete : contentOfThisScrolledComposite.getChildren()) { @@ -128,7 +128,7 @@ public void updateAnswerContainer() { setMinHeight(getLowestWidgetYAxisValue()); for (final Answer answer : this.arrayAnswer) { - addAnswer(answer, true); + addAnswer(answer, true, ident); //change late } } @@ -146,8 +146,8 @@ public ArrayList