/** * Get all linked objects for linktype and write their names to the text field. Uses a runtime * callback (reference resolver) to do this. */ private void writeLinkedObjectsToTextField() { String referencedCnaLinkType = type.getReferencedCnaLinkType(); String names = type.getReferenceResolver() .getTitlesOfLinkedObjects(referencedCnaLinkType, entity.getUuid()); text.setText(names); }
public void createLinks() { // create new link to object String linkType = type.getReferencedCnaLinkType(); String referencedEntityType = type.getReferencedEntityTypeId(); type.getReferenceResolver().createLinks(referencedEntityType, linkType, entity.getUuid()); writeLinkedObjectsToTextField(); }
/** * Creates new SyncAttribute instances out of the properties of an entity. The newly created * instances are added to syncAttributeList. * * <p>SyncLSyncAttributeink is a JAXB Xml class generated out of verinice import and export XML * schema files: sernet/verinice/service/sync sync.xsd data.xsd mapping.xsd * * @param entity * @param syncAttributeList * @param typeId * @param huiTypeFactory */ public static void transform( Entity entity, List<SyncAttribute> syncAttributeList, String typeId, HUITypeFactory huiTypeFactory, ExportReferenceTypes exportReferenceTypes) { Map<String, PropertyList> properties = entity.getTypedPropertyLists(); for (String propertyTypeId : properties.keySet()) { PropertyType propertyType = huiTypeFactory.getPropertyType(typeId, propertyTypeId); if (propertyType == null) { LOG.warn("Property type not found in SNCA.xml: " + propertyTypeId + ", typeId: " + typeId); } if (propertyType == null || propertyType.isReportable()) { SyncAttribute syncAttribute = new SyncAttribute(); // Add <syncAttribute> to this <syncObject>: syncAttribute.setName(propertyTypeId); // transform dbid to uuid for the export if (isReference(propertyType)) { PropertyList propertyList = entity.getProperties(propertyTypeId); exportReferenceTypes.mapEntityDatabaseId2ExtId(syncAttribute, propertyList); } else { entity.exportProperties(propertyTypeId, syncAttribute.getValue()); } if (!syncAttribute.getValue().isEmpty()) { syncAttributeList.add(syncAttribute); } } } }
/** * Adds SyncMapping for all EntityTypes that have been exported. This is going to be an identity * mapping. * * @param mapObjectTypeList */ private void createMapping(final List<MapObjectType> mapObjectTypeList) { for (final EntityType entityType : exportedEntityTypes) { if (entityType != null) { // Add <mapObjectType> element for this entity type to <syncMapping>: final MapObjectType mapObjectType = new MapObjectType(); mapObjectType.setIntId(entityType.getId()); mapObjectType.setExtId(entityType.getId()); final List<MapAttributeType> mapAttributeTypes = mapObjectType.getMapAttributeType(); for (final PropertyType propertyType : entityType.getAllPropertyTypes()) { // Add <mapAttributeType> for this property type to current <mapObjectType>: final MapAttributeType mapAttributeType = new MapAttributeType(); mapAttributeType.setExtId(propertyType.getId()); mapAttributeType.setIntId(propertyType.getId()); mapAttributeTypes.add(mapAttributeType); } mapObjectTypeList.add(mapObjectType); } } // For all exported objects that had no entity type (e.g. category objects) // we create a simple 1-to-1 mapping using their type id. for (final String typeId : exportedTypes) { final MapObjectType mapObjectType = new MapObjectType(); mapObjectType.setIntId(typeId); mapObjectType.setExtId(typeId); mapObjectTypeList.add(mapObjectType); } }
public void create() { label = new Label(parent, SWT.NULL); String labelText = type.getName(); if (showValidationHint && useValidationGUIHints) { refontLabel(true); } label.setText(type.getName()); Composite container = new Composite(parent, SWT.NULL); GridLayout contLayout = new GridLayout(3, false); contLayout.horizontalSpacing = 5; contLayout.marginLeft = 0; contLayout.marginWidth = 0; contLayout.marginHeight = 0; container.setLayout(contLayout); GridData containerLData = new GridData(); containerLData.horizontalAlignment = GridData.FILL; containerLData.grabExcessHorizontalSpace = true; container.setLayoutData(containerLData); link = new Link(container, SWT.NONE); link.setToolTipText(this.type.getTooltiptext()); link.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 1, 1)); link.addListener( SWT.Selection, new Listener() { public void handleEvent(Event event) { if (getHref() != null && getHref().length() > 0) Program.launch(getHref()); } }); Button editBtn = new Button(container, SWT.PUSH); editBtn.setText(Messages.getString("URLControl.1")); // $NON-NLS-1$ editBtn.setToolTipText(this.type.getTooltiptext()); editBtn.setEnabled(editable); editBtn.addSelectionListener( new SelectionListener() { public void widgetSelected(SelectionEvent arg0) { showLinkEditDialog(); } public void widgetDefaultSelected(SelectionEvent arg0) { showLinkEditDialog(); } }); setLinkText(); }
private void setLinkText() { PropertyList propList = entity.getProperties(type.getId()); savedProp = propList != null ? propList.getProperty(0) : null; if (savedProp == null) { savedProp = entity.createNewProperty(type, ""); // $NON-NLS-1$ } if (savedProp.getPropertyValue() != null) { link.setText(savedProp.getPropertyValue()); } link.pack(); }
public boolean validate() { boolean valid = true; for (Entry<String, Boolean> entry : type.validate(link.getText(), null).entrySet()) { if (!entry.getValue().booleanValue()) { valid = false; break; } } if (valid) { refontLabel(false); return true; } if (useValidationGUIHints) { refontLabel(true); } return false; }
public void update() { PropertyList propList = entity.getProperties(type.getId()); Property entityProp; entityProp = propList != null ? propList.getProperty(0) : null; if (entityProp != null && !link.getText().equals(entityProp.getPropertyValue())) { savedProp = entityProp; if (Display.getCurrent() != null) { setLinkText(); } else { Display.getDefault() .asyncExec( new Runnable() { public void run() { setLinkText(); } }); } } }
public boolean validate() { boolean valid = true; for (Entry<String, Boolean> entry : type.validate(text.getText(), null).entrySet()) { if (!entry.getValue().booleanValue()) { valid = false; break; } } if (valid) { text.setForeground(fgColor); text.setBackground(bgColor); refontLabel(false); return true; } if (useValidationGUIHints) { text.setForeground(Colors.BLACK); text.setBackground(Colors.YELLOW); refontLabel(true); } return false; }
/** This is currently only implemented for "roles" in Configuration objects as a special case. */ void showAddDialog() { InputDialog dialog = new InputDialog( Display.getCurrent().getActiveShell(), Messages.MultiSelectionControl_3, Messages.MultiSelectionControl_4, "", new IInputValidator() { public String isValid(String newText) { if (newText.length() < 1) { return Messages.MultiSelectionControl_5; } return null; } }); if (dialog.open() == Window.OK) { type.getReferenceResolver().addNewEntity(this.entity, dialog.getValue()); } writeToTextField(); }
public void create() { label = new Label(parent, SWT.NULL); label.setText(type.getName()); Composite container = new Composite(parent, SWT.NULL); GridLayout contLayout = new GridLayout(2, false); contLayout.horizontalSpacing = 5; contLayout.marginLeft = 0; contLayout.marginWidth = 0; contLayout.marginHeight = 0; container.setLayout(contLayout); GridData containerLData = new GridData(); containerLData.horizontalAlignment = GridData.FILL; containerLData.grabExcessHorizontalSpace = true; container.setLayoutData(containerLData); text = new Text(container, SWT.BORDER); text.setEditable(false); text.setToolTipText(this.type.getTooltiptext()); text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); bgColor = text.getBackground(); fgColor = text.getForeground(); Button editBtn = new Button(container, SWT.PUSH); editBtn.setText(Messages.MultiSelectionControl_1); editBtn.setToolTipText(this.type.getTooltiptext()); editBtn.setEnabled(editable); editBtn.addSelectionListener( new SelectionListener() { public void widgetSelected(SelectionEvent arg0) { showSelectionDialog(); } public void widgetDefaultSelected(SelectionEvent arg0) { showSelectionDialog(); } }); // buttons not available for cnalink references if (crudButtons && !cnalinkreference) { // create buttons to add / delete new properties: Button addBtn = new Button(container, SWT.PUSH); addBtn.setText(Messages.MultiSelectionControl_2); addBtn.setEnabled(editable); addBtn.addSelectionListener( new SelectionListener() { public void widgetSelected(SelectionEvent arg0) { showAddDialog(); } public void widgetDefaultSelected(SelectionEvent arg0) { widgetSelected(arg0); } }); } writeToTextField(); if (showValidationHint && useValidationGUIHints) { refontLabel(true); } }
private static boolean isReference(PropertyType propertyType) { return propertyType != null && propertyType.isReference(); }