public static XSDConstrainingFacet addOrSetFacetValue( XSDSimpleTypeDefinition type, String facetName, FacetValue fv) { XSDConstrainingFacet workFacet = fv.facet; // do we need to add? if (fv.facet == null || fv.facet.getContainer() != type) { // need to add to this type: boolean inclusiveness = false; if (fv.value instanceof InclusiveInteger) { inclusiveness = ((InclusiveInteger) fv.value).isInclusive; } // endif // remove any facets with opposite inclusiveness: if (facetName == FAKE_FACET_MAXIMUM || facetName == FAKE_FACET_MINIMUM) { // go ahead and remove: removeFacet(type, facetName); } // endif -- using fake facets? workFacet = createFacet(facetName, inclusiveness); try { ModelerCore.getModelEditor().addValue(type, workFacet, type.getFacetContents()); } catch (ModelerCoreException err) { ModelerXsdUiConstants.Util.log(err); } // endtry } // endif // set main value: if (!FormUtil.safeEquals(fv.value, getMainFacetValue(workFacet))) { // only set if changed: workFacet = setMainFacetValue(type, workFacet, fv.value); // in case this is a bounds facet and we swapped them out: fv.facet = workFacet; } // endif // set description: String existingDesc = ModelObjectUtilities.getDescription(workFacet); if (fv.description != null) { // new not null: if (!fv.description.equals(existingDesc)) { // description changed to a nonnull value: ModelObjectUtilities.setDescription(workFacet, fv.description, type); } // endif -- different } else if (existingDesc != null && existingDesc.length() > 0) { // new null, old not null: ModelObjectUtilities.setDescription(workFacet, " ", type); // $NON-NLS-1$ } // endif // Lastly, set fixed if applicable: setFixed(workFacet, fv.isFixedLocal); return workFacet; }
/** * @see org.teiid.designer.ui.common.actions.IActionWorker#getEnableState() * @since 4.2 */ @Override public boolean setEnabledState() { boolean enable = false; Object selection = getSelection(); boolean foundResource = false; if (selection instanceof ISelection) { ISelection iSelection = (ISelection) selection; if (!iSelection.isEmpty() && !isReadOnly() && canLegallyEditResource()) { if (SelectionUtilities.isAllEObjects(iSelection)) { enable = true; // check each object, break out if false for (Iterator iter = SelectionUtilities.getSelectedEObjects(iSelection).iterator(); iter.hasNext() && enable; ) { EObject obj = (EObject) iter.next(); // Check Read-Only, Check if Diagram (ask diagram), Check Helper if (obj == null || ModelObjectUtilities.isReadOnly(obj)) { enable = false; // and quit checking } else { if (obj instanceof Diagram) { enable = DiagramHelperManager.canDelete((Diagram) obj); } else { enable = ModelObjectEditHelperManager.canDelete(obj); // and keep checking } // We got this far, now we need to cache up a focused object for opening an editor // so it reveals the proper container (i.e. package diagram) // Only do this once for effiency if (!foundResource && enable) { focusedObject = obj; foundResource = true; modelResource = ModelUtilities.getModelResourceForModelObject(obj); } } if (!enable) break; } } } } if (!enable) { modelResource = null; focusedObject = null; } if (UiPlugin.getDefault().getCurrentWorkbenchWindow().getActivePage() != null) { IWorkbenchPart theActivePart = UiPlugin.getDefault().getCurrentWorkbenchWindow().getActivePage().getActivePart(); if (theActivePart != null) { // System.out.println(" >>> DeleteWorker.setEnabledState() Active Part = " + // theActivePart); } } return enable; }
/** Configures the action by setting text, image, and enabled state. */ private void configureAllowedState() { Object result = descriptor.getResult().iterator().next(); // If the descriptor represents a disabled command then extract the // underlying command to use when getting labels Command cmd = descriptor; if (descriptor instanceof DisabledCommand) { cmd = ((DisabledCommand) descriptor).getDisabledCommand(); } // Use the CreateChildCommand label for the menu text String label = cmd.getLabel(); // If the label does not exist of if we are creating a new root entity // in a model (i.e. AddCommand) then use the label provider's text since // AddCommand labels do not provide meaningful text for a "new" child if (label == null || label.length() == 0 || cmd instanceof AddCommand) { label = provider.getText(result); } // Remove the "New" prefix present in labels from CreateChildCommand instances if (label != null && label.startsWith("New ")) { // $NON-NLS-1$ label = label.substring(4); } setText(label); if (result instanceof Diagram) { setImage(diagramProvider.getImage(result)); } else if (result instanceof EObject) { setImage(provider.getImage((EObject) result, ModelObjectUtilities.isVirtual(sibling))); } else { setImage(provider.getImage(result)); } setToolTipText(cmd.getDescription()); setEnabled(true); }
public static FacetValue getFacetValue(XSDSimpleTypeDefinition type, XSDConstrainingFacet facet) { FacetValue fv = new FacetValue(); fv.description = ModelObjectUtilities.getDescription(facet); fv.type = type; fv.facet = facet; Object mainVal = getMainFacetValue(facet); if (mainVal != null) { fv.value = mainVal; } else { fv.value = getDefaultMainFacetValue(facet.getFacetName()); } // endif if (type == facet.getContainer()) { // this facet set in the specified type, so it is not default: fv.defaultValue = null; // getMainFacetValue(type.getBaseTypeDefinition(), facet.getFacetName()); } else { // facet set by a parent, so it is default: fv.defaultValue = fv.value; } // endif fv.isFixedLocal = isFixed(facet); return fv; }
@Override public void setName(String name) { // aspect.setSignature(getModelObject(),name); ModelObjectUtilities.rename(getModelObject(), name, this); // super.setName(name); }