import eu.etaxonomy.cdm.api.service.ITermTreeService;
import eu.etaxonomy.cdm.api.service.IVocabularyService;
import eu.etaxonomy.cdm.api.service.UpdateResult;
+import eu.etaxonomy.cdm.format.description.CharacterLabelBuilder;
import eu.etaxonomy.cdm.model.common.Language;
import eu.etaxonomy.cdm.model.description.Character;
import eu.etaxonomy.cdm.model.description.Feature;
import eu.etaxonomy.taxeditor.editor.AppModelId;
import eu.etaxonomy.taxeditor.editor.definedterm.TermTreeViewerComparator;
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
+import eu.etaxonomy.taxeditor.event.EventUtility;
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
import eu.etaxonomy.taxeditor.model.AbstractUtility;
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
private TermVocabulary vocabulary;
private TreeViewer structureViewer;
private TreeViewer propertyViewer;
+ private Button btnAddCharacter;
+ private Button btnAddRatioTo;
private List<AbstractPostOperation> operations = new ArrayList<>();
composite_1.setLayout(gl_composite_1);
propertyViewer = createTreeViewer(composite_1, TermType.Property, Messages.CharacterEditor_PROPERTIES);
+ propertyViewer.addSelectionChangedListener(this);
int ops = DND.DROP_COPY | DND.DROP_MOVE;
Transfer[] transfers = new Transfer[] {CharacterTransfer.getInstance()};
gl_composite_4.marginWidth = 0;
composite_4.setLayout(gl_composite_4);
- Button btnAddCharacter = new Button(composite_4, SWT.NONE);
+ btnAddCharacter = new Button(composite_4, SWT.NONE);
btnAddCharacter.setText(">>"); //$NON-NLS-1$
formToolkit.adapt(btnAddCharacter, true, true);
btnAddCharacter.addSelectionListener(new SelectionAdapter() {
}
Collection<Character> characters = createCharacters((TreeSelection)structureTreeSelection, (TreeSelection)propertyTreeSelection);
TermNodeDto parent = characterTreeEditorComposite.getFeatureTree().getRoot();
+ ISelection sel = characterTreeEditorComposite.getViewer().getSelection();
+
+ TermNodeDto parentNode = parent;
+ if (sel instanceof TreeSelection){
+ TreeSelection treeSel = (TreeSelection)sel;
+ Object o = treeSel.getFirstElement();
+ if (o instanceof CharacterNodeDto){
+ parentNode = (TermNodeDto)o;
+ }
+ }
for (Character character : characters) {
//add new Character to feature tree
- CharacterNodeDto nodeDto = new CharacterNodeDto(CharacterDto.fromCharacter(character), parent, 0, parent.getTree(), null, null, null);
+ CharacterNodeDto nodeDto = new CharacterNodeDto(CharacterDto.fromCharacter(character), parentNode, 0, parent.getTree(), null, null, null);
nodesToSave.put(character, nodeDto);
setDirty();
// result = CdmStore.getService(IFeatureNodeService.class).createChildFeatureNode(parent.getUuid(), character, vocabulary.getUuid());
refresh();
}
});
+ btnAddCharacter.setEnabled(false);
- Button btnAddRatioTo = new Button(composite_4, SWT.NONE);
+ btnAddRatioTo = new Button(composite_4, SWT.NONE);
btnAddRatioTo.setText("ratio to"); //$NON-NLS-1$
btnAddRatioTo.setSize(btnAddCharacter.getSize());
+ btnAddRatioTo.setEnabled(false);
formToolkit.adapt(btnAddRatioTo, true, true);
btnAddRatioTo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- if(!isVocabularySet()){
- return;
- }
+
if (confirmSaveDirty()){
return;
}
return;
}
TermDto termDto = character.getTerm();
+ TermNodeDto structure = null;
+ TermNodeDto property = null;
+ Representation structureRepresentation = null;
+ Representation propertyRepresentation = null;
+ Representation ratioToRepresentation = ratioToNode.getTerm().getRepresentation(CdmStore.getDefaultLanguage());
if (termDto instanceof CharacterDto){
CharacterDto dto = (CharacterDto)termDto;
dto.setRatioTo(TermNodeDto.fromNode(ratioToNode, null));
+ structure = dto.getStructure();
+ structureRepresentation = structure.getTerm().getPreferredRepresentation(CdmStore.getDefaultLanguage());
+ property = dto.getProperty();
+ propertyRepresentation = property.getTerm().getPreferredRepresentation(CdmStore.getDefaultLanguage());
}
-// Collection<Character> characters = createCharacters((TreeSelection)structureTreeSelection, (TreeSelection)propertyTreeSelection);
- TermNodeDto parent = characterTreeEditorComposite.getFeatureTree().getRoot();
+ String label = null;
+ String abbrevLabel = null;
+
+ if(structureRepresentation!=null && propertyRepresentation!=null){
+ if(structureRepresentation.getLabel() != null && propertyRepresentation.getLabel() != null && ratioToRepresentation.getLabel() != null){
+ label = propertyRepresentation.getLabel() + " ratio " +structureRepresentation.getLabel()+" to " +ratioToRepresentation.getLabel() ;
+ }
+ if(structureRepresentation.getAbbreviatedLabel()!=null && propertyRepresentation.getAbbreviatedLabel()!=null && ratioToRepresentation.getAbbreviatedLabel() != null){
+ abbrevLabel = propertyRepresentation.getAbbreviatedLabel() + " ratio " +structureRepresentation.getAbbreviatedLabel()+ " to " + ratioToRepresentation.getAbbreviatedLabel();
+ }
+ }
+ if(label==null){
+ //default label
+ label = property.getTerm().getRepresentation_L10n()+ " ratio " +structure.getTerm().getRepresentation_L10n()+ " to " + ratioToNode.getTerm().getLabel() ;
+ }
+ character.getTerm().getRepresentation(CdmStore.getDefaultLanguage()).setLabel(label);
+ character.getTerm().getRepresentation(CdmStore.getDefaultLanguage()).setAbbreviatedLabel(abbrevLabel);
-// for (Character character : characters) {
-// //add new Character to feature tree
-// CharacterNodeDto nodeDto = new CharacterNodeDto(CharacterDto.fromCharacter(character), parent, 0, parent.getTree(), null, null, null);
-// nodesToSave.put(character, nodeDto);
-// setDirty();
-// // result = CdmStore.getService(IFeatureNodeService.class).createChildFeatureNode(parent.getUuid(), character, vocabulary.getUuid());
-//
-// }
setDirty();
nodesToUpdate.add(character);
refresh();
+
characterTreeEditorComposite.getViewer().setSelection(new StructuredSelection(character));
+ EventUtility.postEvent(WorkbenchEventConstants.REFRESH_DETAILS, true);
}
});
//create all combinations of structures and properties
while(structureIterator.hasNext()){
- TermNode<DefinedTerm> structureNode = structureIterator.next();
+ Object o = structureIterator.next();
+ TermNode<DefinedTerm> structureNode = null;
+ if (o instanceof TermNode){
+ structureNode = (TermNode<DefinedTerm>) o;
+ }else{
+ return null;
+
+ }
+
Iterator<TermNode<DefinedTerm>> propertiesIterator = propertyTreeSelection.iterator();
while(propertiesIterator.hasNext()){
TermNode<DefinedTerm> propertyNode = propertiesIterator.next();
label = structureNode.getTerm().getLabel()+" "+propertyNode.getTerm().getLabel();
}
Character character = Character.NewInstance(structureNode, propertyNode, null, label, abbrevLabel);
+ CharacterLabelBuilder labelBuilder = CharacterLabelBuilder.NewDefaultInstance();
+ character.setLabel(labelBuilder.buildLabel(character, CdmStore.getDefaultLanguage()));
characters.add(character);
}
public void selectionChanged(SelectionChangedEvent event) {
//propagate selection
selService.setSelection(event.getSelection());
+ ISelection selStructure = null;
+ ISelection selProperty = null;
+ selStructure = structureViewer.getSelection();
+ selProperty = propertyViewer.getSelection();
+
+ if (selStructure != null && selProperty != null && selStructure instanceof TreeSelection && selProperty instanceof TreeSelection && ((TreeSelection)selStructure).getFirstElement() instanceof TermNode && ((TreeSelection)selProperty).getFirstElement() instanceof TermNode && this.vocabulary != null) {
+ btnAddCharacter.setEnabled(true);
+ }else {
+ btnAddCharacter.setEnabled(false);
+ }
+ ISelection selCharacter = this.characterTreeEditorComposite.getViewer().getSelection();
+ if (selStructure != null && selCharacter != null && selStructure instanceof TreeSelection && selCharacter instanceof TreeSelection && ((TreeSelection)selStructure).getFirstElement() instanceof TermNode && ((TreeSelection)selCharacter).getFirstElement() instanceof CharacterNodeDto) {
+ btnAddRatioTo.setEnabled(true);
+ }else {
+ btnAddRatioTo.setEnabled(false);
+ }
}