Commit b9d2c808 authored by Johannes Eder's avatar Johannes Eder
Browse files

refactored mira editors

Issue-Ref: 3886
Issue-Url: https://af3-developer.fortiss.org/issues/3886

Signed-off-by: Johannes Eder's avatarJohannes Eder <eder@fortiss.org>
parent 0a9d4ab9
......@@ -63,7 +63,7 @@
</modelElementClass>
</modelEditorBinding>
<modelEditorBinding
binding="org.fortiss.af3.mira.ui.editorbinding.GlossaryEntryEditorBindings$GlossaryEntryEditorBinding">
binding="org.fortiss.af3.mira.ui.editorbinding.GlossaryEntryEditorBinding">
<modelElementClass
modelElementClass="org.fortiss.af3.mira.model.glossary.GlossaryEntry">
</modelElementClass>
......
AnalysisEditor.java 8af36c33588b3a8ceff2fe713326d5f306c66280 YELLOW
DateToStringConverter.java c969b068ea1dfd77b7153dd8937dca2e4b5630b7 GREEN
RequirementEditor.java 74ab37b7f37696f70a761ce3d8008a4bf10089fb RED
RequirementsContainerEditor.java 849211b697048e34b72364548e3c10213494718e GREEN
RequirementsPackageEditor.java 8bc993fb55747e1799af477f0a720543924c596b GREEN
StringToIDValidator.java b301021d7b05369de1ffc5048f80b8da19052253 RED
RequirementEditor.java 2bee8b1a6a13fb89edc8e4365723dc2cfdd09682 YELLOW
StringToIDValidator.java 25674733b3bc6a0189ea7e1f52357c2e69ac1025 YELLOW
/*-------------------------------------------------------------------------+
| Copyright 2011 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 java.text.SimpleDateFormat;
import java.util.Date;
import org.eclipse.core.databinding.conversion.Converter;
import org.eclipse.core.databinding.conversion.IConverter;
/**
* {@link IConverter} to convert a date to string.
*
* @author mou
*/
public final class DateToStringConverter extends Converter {
/** the format for output string. */
private final String format;
/** Constructor with a format string. */
public DateToStringConverter(String format) {
super(Date.class, String.class);
this.format = format;
}
/** {@inheritDoc} */
@Override
public Object convert(Object fromObject) {
if(fromObject != null) {
Date date = (Date)fromObject;
SimpleDateFormat formatter = new SimpleDateFormat(format);
return formatter.format(date);
}
return null;
}
}
......@@ -209,6 +209,7 @@ public class RequirementEditor<T extends Requirement> extends FormsEditorBase<T>
}
/** Create bindings to glossary. */
@SuppressWarnings({"unchecked", "rawtypes"})
private void createBindings() {
dbc.bindList(ScannerManager.getScanner(analysis).getObservableList(),
EMFObservables.observeList(analysis,
......@@ -275,6 +276,7 @@ public class RequirementEditor<T extends Requirement> extends FormsEditorBase<T>
}
/** Create a single line field of a requirement with given input. */
@SuppressWarnings({"unchecked", "deprecation"})
private ComboViewer createSingleLineFixedInputRequirementField(Composite composite,
String labelName, Object inputValues, EObject object,
EStructuralFeature observedStructuralFeature) {
......@@ -295,234 +297,6 @@ public class RequirementEditor<T extends Requirement> extends FormsEditorBase<T>
return comboViewer;
}
// /** Edit document references. */
// private void createEditDocumentReferences(Composite composite) {
// Label docrefLabel = toolkit.createLabel(composite, "Document ", SWT.READ_ONLY);
// singleLineLabelFactory.applyTo(docrefLabel);
//
// Composite docrefEditPart = toolkit.createComposite(composite);
// docrefEditPart.setLayout(new GridLayout(4, false));
// singleLineInputFactory.applyTo(docrefEditPart);
//
// final Hyperlink docrefLink = toolkit.createHyperlink(docrefEditPart,
// getDocumentPathName(editedObject), SWT.NONE);
// singleLineInputFactory.applyTo(docrefLink);
//
// Button docrefEditButton = toolkit.createButton(docrefEditPart, "", SWT.FLAT);
// docrefEditButton.setImage(getPluginImage(PLUGIN_ID, "/icons/Icon_add.png"));
// singleLineLabelFactory.applyTo(docrefEditButton);
//
// final Button docrefPageButton = toolkit.createButton(docrefEditPart, "Page", SWT.FLAT);
// singleLineLabelFactory.applyTo(docrefPageButton);
//
// final Button docrefDeleteButton = toolkit.createButton(docrefEditPart, "", SWT.FLAT);
// docrefDeleteButton.setImage(getPluginImage(PLUGIN_ID, "/icons/Icon_delete.png"));
// singleLineLabelFactory.applyTo(docrefDeleteButton);
//
// toggleDocumentEditFields(docrefLink, docrefPageButton, docrefDeleteButton);
//
// docrefLink.addMouseListener(new MouseAdapter() {
// @Override
// public void mouseUp(MouseEvent e) {
//
// try {
// FileItem fileItem = editedObject.getDocument().getDocument();
// File file = new File(getDefaultGeneralProjectPath(), fileItem.getUri());
// // open the file in the system file viewer when the user
// // double clicks on the link
// if(fileItem.isIsLocal()) {
// if(!openPDFWithPage(file, editedObject.getDocument().getPage()))
// getDesktop().open(file);
// } else {
// getDesktop().browse(java.net.URI.create(fileItem.getUri()));
// }
// } catch(Exception e2) {
// showError("Open document", "Cannot open document");
// }
// }
// });
//
// docrefEditButton.addSelectionListener(
// createDocRefListener(docrefLink, docrefPageButton, docrefDeleteButton));
// docrefPageButton.addSelectionListener(setPageNumberListener(docrefLink));
// docrefDeleteButton.addSelectionListener(
// deleteDocRefListener(docrefLink, docrefPageButton, docrefDeleteButton));
// }
// /** Listener for creating document reference. */
// private SelectionAdapter createDocRefListener(final Hyperlink docrefLink,
// final Button docrefPageButton, final Button docrefDeleteButton) {
// return new SelectionAdapter() {
// /** {@inheritDoc} */
// @Override
// public void widgetSelected(SelectionEvent e) {
// List<Analysis> analysises = Arrays.asList(editedObject.getAnalysis());
// final ElementTreeSingleSelectDialog dialog = new ElementTreeSingleSelectDialog(
// getSite().getShell(), analysises, null,
// editDocRefContentProvider(analysises), editDocRefLabelProvider(), null) {
// /** {@inheritDoc} */
// @Override
// public boolean acceptElement(Object element) {
// return element instanceof FileItem;
// }
// };
//
// if(Window.OK == dialog.open()) {
// executeCommand(new Runnable() {
// @Override
// public void run() {
// editedObject.setDocument(createDocumentReference(
// (FileItem)dialog.getSelectedElement(), 1));
// }
// });
// docrefLink.setText(getDocumentPathName(editedObject));
// }
//
// toggleDocumentEditFields(docrefLink, docrefPageButton, docrefDeleteButton);
// }
//
// /** Label provider for button to edit document references. */
// private ModelElementLabelProvider editDocRefLabelProvider() {
// return new ModelElementLabelProvider() {
// @Override
// public String getText(Object element) {
// if(element instanceof FileItem)
// return RequirementUtils.toString((FileItem)element);
// return super.getText(element);
// }
// };
// }
//
// /** Content provider for button to edit document references. */
// private ModelElementTreeContentProvider
// editDocRefContentProvider(List<Analysis> analysises) {
// return new ModelElementTreeContentProvider(analysises) {
// /** {@inheritDoc} */
// @Override
// public List<? extends EObject> getChildren(EObject parent) {
// if(parent instanceof Analysis) {
// return pickInstanceOf(RequirementSource.class,
// ((Analysis)parent).getContainedElements());
// } else if(parent instanceof RequirementSource) {
// return pickInstanceOf(RequirementDocument.class,
// ((RequirementSource)parent).getContainedElements());
// } else if(parent instanceof RequirementDocument) {
// return pickInstanceOf(FileItem.class,
// ((RequirementDocument)parent).getContainedElements());
// }
// return Collections.emptyList();
// }
// };
// }
// };
// }
// /** Listener for setting page number for document reference. */
// private SelectionAdapter setPageNumberListener(final Hyperlink docrefLink) {
// return new SelectionAdapter() {
// @Override
// public void widgetSelected(SelectionEvent e) {
// if(!hasDocument(editedObject)) {
// return;
// }
//
// InputDialog inputDialog = new InputDialog(getSite().getShell(), "Page number",
// "Please input the page number:", "" + editedObject.getDocument().getPage(),
// new IInputValidator() {
//
// @Override
// public String isValid(String newText) {
// try {
// if(Integer.parseInt(newText) < 0) {
// return "Hint: number must be greater than or equal to 0";
// }
// return null;
// } catch(Exception e2) {
// return "Hint: invalid number";
// }
// }
// });
// if(Window.OK != inputDialog.open())
// return;
//
// final int value = Integer.parseInt(inputDialog.getValue());
// executeCommand(new Runnable() {
// @Override
// public void run() {
// editedObject.setDocument(createDocumentReference(
// editedObject.getDocument().getDocument(), value));
// }
// });
// docrefLink.setText(getDocumentPathName(editedObject));
// }
// };
// }
// /**
// * Listener for deleting document references and disable {@link Button}s and {@link Hyperlink}
// * accordingly.
// */
// private SelectionAdapter deleteDocRefListener(final Hyperlink docrefLink,
// final Button docrefPageButton, final Button docrefDeleteButton) {
// return new SelectionAdapter() {
// @Override
// public void widgetSelected(SelectionEvent e) {
// if(!hasDocument(editedObject)) {
// return;
// }
//
// if(confirm("Requirements Document", "Delete this reference?")) {
// executeCommand(new Runnable() {
// @Override
// public void run() {
// editedObject.setDocument(null);
// }
// });
// docrefLink.setText("");
// }
//
// toggleDocumentEditFields(docrefLink, docrefPageButton, docrefDeleteButton);
// }
// };
// }
// /** Enable or disable document buttons and fields. */
// private void toggleDocumentEditFields(final Hyperlink docrefLink, final Button
// docrefPageButton,
// final Button docrefDeleteButton) {
// if(hasDocument(editedObject)) {
// docrefPageButton.setEnabled(true);
// docrefDeleteButton.setEnabled(true);
// docrefLink.setEnabled(true);
// } else {
// docrefPageButton.setEnabled(false);
// docrefDeleteButton.setEnabled(false);
// docrefLink.setEnabled(false);
// }
// }
// /** Transform a {@link DocumentReference} to string. */
// private String getDocumentPathName(T editedObject) {
// if(hasDocument(editedObject)) {
// String link = RequirementUtils.toString(editedObject.getDocument().getDocument());
// if(link == null) {
// return "broken link";
// }
// if(editedObject.getDocument().getPage() > 1) {
// link += "#" + editedObject.getDocument().getPage();
// }
//
// return link;
// }
// return "";
// }
// /** Edited object has document attached. */
// private boolean hasDocument(T editedObject) {
// return editedObject.getDocument() != null &&
// editedObject.getDocument().getDocument() != null;
// }
/** Edit requirement ID. */
private void createIdEdit(Composite composite) {
Label idLabel = toolkit.createLabel(composite, "ID ", SWT.READ_ONLY);
......
......@@ -28,7 +28,7 @@ import org.fortiss.af3.mira.model.Requirement;
*
* @author teufl
*/
public class StringToIDValidator implements IValidator {
public class StringToIDValidator implements IValidator<Object> {
/** Stores the analysis node. */
private Requirement editedObject;
......
ContextElementEditorBase.java 2971888af6f7f87a939332fb469ed668da2835ac RED
ContextElementOtherEditor.java eefa00833f733581a5862b94138353e9685a6406 RED
ContextElementStringValidator.java 1d1523a4a836e4cedc40f703d755ad228d2464e6 GREEN
GlossaryEntryEditorBase.java 9d0e3e04cff47fdb54bb429170bcd5bb6e985af4 YELLOW
TrimStringConverter.java e207497003e1e974bebc5ba9f06d66b42db8e64a GREEN
WordElementEditingSupport.java e801c2b9314d934be5c7497fab2850887a5eac2b GREEN
......@@ -57,9 +57,11 @@ import org.fortiss.af3.mira.model.Analysis;
import org.fortiss.af3.mira.model.ContextElement;
import org.fortiss.af3.mira.model.Requirement;
import org.fortiss.af3.mira.model.glossary.Glossary;
import org.fortiss.af3.mira.model.glossary.GlossaryEntry;
import org.fortiss.af3.mira.ui.editor.highlight.AnalysisToWordRuleConverter;
import org.fortiss.af3.mira.ui.editor.highlight.ListToWordRuleUpdateStrategy;
import org.fortiss.af3.mira.ui.editor.highlight.ScannerManager;
import org.fortiss.af3.mira.ui.editor.images.ImageSection;
import org.fortiss.tooling.base.ui.editor.FormsEditorBase;
import org.fortiss.tooling.kernel.ui.service.IActionService;
......@@ -69,8 +71,7 @@ import org.fortiss.tooling.kernel.ui.service.IActionService;
*
* @author wenwenchen
*/
public abstract class ContextElementEditorBase<T extends ContextElement>
extends FormsEditorBase<T> {
public class GlossaryEntryEditorBase extends FormsEditorBase<GlossaryEntry> {
/** Single line input grid data factory. */
protected static GridDataFactory singleLineInputFactory =
......@@ -155,7 +156,9 @@ public abstract class ContextElementEditorBase<T extends ContextElement>
}
/** Return type title at the top of the editor. */
protected abstract String getTypeUpCase();
protected String getTypeUpCase() {
return "Glossary entry";
}
/** {@inheritDoc} */
@Override
......@@ -168,6 +171,7 @@ public abstract class ContextElementEditorBase<T extends ContextElement>
/**
* Create the bindings to glossary.
*/
@SuppressWarnings({"unchecked", "rawtypes"})
private void createBindings() {
dbc.bindList(ScannerManager.getScanner(analysis).getObservableList(),
......@@ -185,6 +189,7 @@ public abstract class ContextElementEditorBase<T extends ContextElement>
}
/** Create the general section. */
@SuppressWarnings({"unchecked", "rawtypes"})
private void createGeneralSection() {
Composite generalComposite = createNewSection("General", "General information");
......@@ -222,5 +227,15 @@ public abstract class ContextElementEditorBase<T extends ContextElement>
}
/** Create section for images. */
abstract protected void createSpecificSection();
protected void createSpecificSection() {
createImageSection();
}
/** Create section for images. */
private void createImageSection() {
Composite imageSection = createNewSection("Images", "");
imageSection.setLayout(new GridLayout(1, false));
new ImageSection(this, imageSection, editedObject, toolkit, dbc, form,
registeredSourceViewers);
}
}
/*-------------------------------------------------------------------------+
| Copyright 2012 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.glossary;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.fortiss.af3.mira.model.glossary.GlossaryEntry;
import org.fortiss.af3.mira.ui.editor.contextElement.ContextElementEditorBase;
import org.fortiss.af3.mira.ui.editor.images.ImageSection;
/**
* Editor to edit a {@link GlossaryEntry}.
*
* @author kisslinger
*/
public class GlossaryEntryEditor extends ContextElementEditorBase<GlossaryEntry> {
/** {@inheritDoc} */
@Override
protected String getTypeUpCase() {
return "Glossary entry";
}
/** {@inheritDoc} */
@Override
protected void createSpecificSection() {
createImageSection();
}
/** Create section for images. */
private void createImageSection() {
Composite imageSection = createNewSection("Images", "");
imageSection.setLayout(new GridLayout(1, false));
new ImageSection(this, imageSection, editedObject, toolkit, dbc, form,
registeredSourceViewers);
}
}
OverviewComparator.java 199353dde8e35028e2ab69002aaa62b2875a23f8 GREEN
OverviewEditorBase.java e34f577a7bd0aab89317fe5c62cf6d79b9b1cfd8 GREEN
OverviewLabelProvider.java 0873700a1ebcdd97a758490788d271135dd3e78e YELLOW
OverviewLabelProvider.java b5cecccc2c00791f8b4997bb91b0bea239a90b9b YELLOW
OverviewTreeContentProvider.java 408a2098d6ea2bf29ed0d52077f0cf40650da3a5 GREEN
RequirementsOverviewEditor.java 463f63e9f053226d46978c9c3ede608e70bbc8b0 YELLOW
......@@ -32,10 +32,11 @@ import org.fortiss.af3.mira.model.RequirementsContainer;
import org.fortiss.af3.mira.model.RequirementsPackage;
import org.fortiss.af3.mira.model.glossary.Glossary;
import org.fortiss.af3.mira.model.glossary.GlossaryEntry;
import org.fortiss.af3.mira.ui.editor.RequirementEditor;
import org.fortiss.tooling.kernel.model.INamedCommentedElement;
/**
* The {@link LabelProvider} for the {@link AnalysisEditor}.
* The {@link LabelProvider} for the {@link RequirementEditor}.
*
* @author teufl
*/
......@@ -106,7 +107,6 @@ public class OverviewLabelProvider implements ITableLabelProvider {
if(element instanceof GlossaryEntry) {
return entryIcon;
}
}
return null;
}
......
......@@ -17,10 +17,6 @@ package org.fortiss.af3.mira.ui.editor.overview;
import static org.conqat.lib.commons.string.StringUtils.isEmpty;
import static org.eclipse.emf.ecore.util.EcoreUtil.getAllContents;
import static org.fortiss.af3.mira.ui.editor.overview.OverviewEditorBase.StatisticEntries.NO_ALL;
import static org.fortiss.af3.mira.ui.editor.overview.OverviewEditorBase.StatisticEntries.NO_GLOSSARY_ENTRIES;
import static org.fortiss.af3.mira.ui.editor.overview.OverviewEditorBase.StatisticEntries.NO_REQS;
import static org.fortiss.af3.mira.ui.editor.overview.OverviewEditorBase.StatisticEntries.NO_REQS_TOTAL;
import static org.fortiss.af3.mira.ui.utils.ListenerUtils.openClassEditorListener;
import static org.fortiss.af3.mira.ui.utils.MiraLayoutUtils.fillControlFactory;
import static org.fortiss.af3.mira.ui.utils.MiraLayoutUtils.singleLineInputFactory;
......@@ -29,9 +25,7 @@ import static org.fortiss.af3.mira.utils.MiraUtils.getDisplayTypeFor;
import static org.fortiss.tooling.kernel.ui.util.DataBindingUtils.DECORATION_KEY;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.BasicEList;
......@@ -55,7 +49,6 @@ import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.ui.actions.TextStyledTextActionHandler;
import org.fortiss.af3.mira.model.Analysis;
import org.fortiss.af3.mira.model.ContextElement;
import org.fortiss.af3.mira.model.Requirement;
import org.fortiss.af3.mira.model.RequirementsContainer;
......@@ -71,7 +64,7 @@ import org.fortiss.tooling.kernel.model.INamedCommentedElement;
*
* @author wenwenchen
*/
public class OverviewEditorBase<T extends IHierarchicElement> extends FormsEditorBase<T> {
public class RequirementsOverviewEditor<T extends IHierarchicElement> extends FormsEditorBase<T> {
/** Enum for Statistics list entries. */
protected enum StatisticEntries {
......@@ -102,16 +95,6 @@ public class OverviewEditorBase<T extends IHierarchicElement> extends FormsEdito
}
}
/** Returns a map "label -> number" for the enum above. */
private Map<String, Integer> statisticEntriesMap() {
Map<String, Integer> res = new HashMap<String, Integer>();
StatisticEntries[] vals = StatisticEntries.values();
for(int i = 0; i < vals.length; i++) {
res.put(vals[i].getLabel().trim(), vals[i].ordinal());
}
return res;
}
/** Filter text. */
protected Text overviewFilterText;
......@@ -154,57 +137,6 @@ public class OverviewEditorBase<T extends IHierarchicElement> extends FormsEdito
textStyledTextActionHandler.addText(overviewFilterText);
}
/**
* Create a single line field for statistics.
*
* @param generalComposite
* The composite of field.
* @param elementName
* Name of the single line field.
* @param numberOfElements
* Total number of the element.
*/
private void createSingleLineStatisticsField(Composite generalComposite, String elementName,
String numberOfElements) {
Label elementLabel =
toolkit.createLabel(generalComposite, elementName + " ", SWT.READ_ONLY);
singleLineLabelFactory.applyTo(elementLabel);
Label numberLabel =
toolkit.createLabel(generalComposite, numberOfElements + " ", SWT.READ_ONLY);
singleLineLabelFactory.applyTo(numberLabel);
}
/** Calculates numbers for statistics. */
private List<Integer> calculateStatistics() {
List<Integer> result = new ArrayList<Integer>();
int numGlossaryEntries = 0;
int numStakeholders = 0;
int numDocuments = 0;
int numExternalSystems = 0;
int numReq = 0;
// For Analysis overview.
if(editedObject instanceof Analysis) {
for(Glossary glossary : ((Analysis)editedObject).getGlossariesList())
numGlossaryEntries += glossary.getGlossaryEntryList().size();
}
// For glossary overview.
else if(editedObject instanceof Glossary) {
numGlossaryEntries = ((Glossary)editedObject).getGlossaryEntryList().size();