Commit 8c3527a2 authored by Ashmi Banerjee's avatar Ashmi Banerjee
Browse files

added editor for assets

refs 3238
parent 6d75a3b0
/*-------------------------------------------------------------------------+
| Copyright 2017 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT 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 org.fortiss.af3.mira.ui.editor;
import static org.fortiss.af3.mira.ui.utils.HighlightUtils.createSourceViewer;
import static org.fortiss.af3.mira.ui.utils.MiraLayoutUtils.singleLineInputFactory;
import static org.fortiss.af3.mira.ui.utils.MiraLayoutUtils.singleLineLabelFactory;
import static org.fortiss.tooling.kernel.model.FortissToolingKernelPackage.Literals.INAMED_ELEMENT__NAME;
import static org.fortiss.tooling.kernel.ui.util.DataBindingUtils.bind;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
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.fortiss.af3.mira.model.Requirement;
import org.fortiss.af3.mira.model.security.Assets;
import org.fortiss.af3.project.model.ParameterDefinition;
import org.fortiss.tooling.base.model.element.IModelElementSpecification;
import org.fortiss.tooling.kernel.service.IElementCompositorService;
/**
*
* @author ashmi
*/
public class AssetsEditor<T extends Requirement> extends AspectEditorBase<T> {
/** {@inheritDoc} */
@Override
protected void createAspectSection() {
for(IModelElementSpecification spec : editedObject.getSpecifications()) {
if(spec instanceof ParameterDefinition) {
addAssetsDefinitionSection((Assets)spec);
}
}
}
/**
* Section for adding assets definition
*/
private Composite addAssetsDefinitionSection(Assets as) {
Composite parameterSection =
createNewSection("Assets definition",
"This requirement defines the following Asset value:");
parameterSection.setLayout(new GridLayout(2, false));
Label nameLabel = toolkit.createLabel(parameterSection, "AssetValue ", SWT.READ_ONLY);
singleLineLabelFactory.applyTo(nameLabel);
SourceViewer inputName = createSourceViewer(form, parameterSection, SWT.BORDER, analysis);
registeredSourceViewers.add(inputName);
singleLineInputFactory.applyTo(inputName.getControl());
bind(dbc, inputName.getTextWidget(), as, INAMED_ELEMENT__NAME);
Button deleteButton = toolkit.createButton(parameterSection, "Remove parameter", SWT.None);
deleteButton.addSelectionListener(new SelectionAdapter() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
modelContext.runAsCommand(() -> {
IElementCompositorService.getInstance().decompose(as);
});
}
});
return parameterSection;
}
/** {@inheritDoc} */
@Override
protected List<IModelElementSpecification> getElementsToDelete() {
ArrayList<IModelElementSpecification> res = new ArrayList<IModelElementSpecification>();
res.addAll(pickInstanceOf(Assets.class, editedObject.getSpecifications()));
return res;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment