Java Code Examples for org.openide.util.Utilities#compareObjects()

The following examples show how to use org.openide.util.Utilities#compareObjects() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DBSchemaManager.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static FileObject updateDBSchemas(SchemaElement schemaElement, DBSchemaFileList dbschemaFileList) throws IOException {
    FileObject updatedDBSchemaFile = null;
    DBIdentifier schemaFullName = schemaElement.getSchema();
    String schemaName = schemaFullName != null ? schemaFullName.getName() : null;

    for (FileObject dbschemaFile : dbschemaFileList.getFileList()) {
        SchemaElement existingSchemaElement = SchemaElementUtil.forName(dbschemaFile);
        DBIdentifier existingSchemaFullName = existingSchemaElement.getSchema();
        String existingSchemaName = existingSchemaFullName != null ? existingSchemaFullName.getName() : null;

        if (Utilities.compareObjects(existingSchemaElement.getUrl(), schemaElement.getUrl()) &&
                Utilities.compareObjects(existingSchemaName, schemaName)) {
            DBIdentifier existingDBSchemaName = existingSchemaElement.getName();
            overwriteDBSchema(schemaElement, dbschemaFile, existingDBSchemaName);
            updatedDBSchemaFile = dbschemaFile;
        }
    }

    return updatedDBSchemaFile;
}
 
Example 2
Source File: JFXProjectConfigurations.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
* Updates the value of existing property in editable properties if value differs.
* If value is not set or is set empty, removes property from editable properties
* unless storeEmpty==true, in which case the property is preserved and set to empty
* in editable properties.
* 
* @param name property to be updated
* @param value new property value
* @param projectProperties project editable properties
* @param privateProperties private project editable properties
* @param storeEmpty true==keep empty properties in editable properties, false==remove empty properties
* @return true if private properties have been edited
*/
private boolean updateProperty(@NonNull String name, String value, @NonNull EditableProperties projectProperties, @NonNull EditableProperties privateProperties, boolean storeEmpty) {
    boolean changePrivate = PRIVATE_PROPERTIES.contains(name) || privateProperties.containsKey(name);
    EditableProperties ep = changePrivate ? privateProperties : projectProperties;
    if(changePrivate) {
        projectProperties.remove(name);
    }
    if (!Utilities.compareObjects(value, ep.getProperty(name))) {
        if (value != null && (value.length() > 0 || storeEmpty)) {
            ep.setProperty(name, value);
        } else {
            ep.remove(name);
        }
        return changePrivate;
    }
    return false;
}
 
Example 3
Source File: EditorSettingsStorageTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void setOneColoring(String mimeType, AttributeSet coloring) {
    String coloringName = (String) coloring.getAttribute(StyleConstants.NameAttribute);
    FontColorSettingsFactory fcsf = EditorSettingsImpl.getDefault().getFontColorSettings(new String [] { mimeType });
    Collection<AttributeSet> all = new ArrayList<AttributeSet>(fcsf.getAllFontColors(EditorSettingsImpl.DEFAULT_PROFILE));
    
    for(Iterator<AttributeSet> i = all.iterator(); i.hasNext(); ) {
        AttributeSet attribs = (AttributeSet) i.next();
        String name = (String) attribs.getAttribute(StyleConstants.NameAttribute);
        if (Utilities.compareObjects(name, coloringName)) {
            i.remove();
            break;
        }
    }
    
    all.add(coloring);
    fcsf.setAllFontColors(EditorSettingsImpl.DEFAULT_PROFILE, all);
}
 
Example 4
Source File: NbPresenter.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void updateHelp() {
    //System.err.println ("Updating help for NbDialog...");
    HelpCtx help = getHelpCtx();
    // Handle help from the inner component automatically (see docs
    // in DialogDescriptor):
    if (HelpCtx.DEFAULT_HELP.equals(help)) {
        Object msg = descriptor.getMessage();
        if (msg instanceof Component) {
            help = HelpCtx.findHelp((Component) msg);
        }
        if (HelpCtx.DEFAULT_HELP.equals(help)) help = null;
    }
    if (! Utilities.compareObjects(currentHelp, help)) {
        currentHelp = help;
        if (help != null && help.getHelpID() != null) {
            //System.err.println ("New help ID for root pane: " + help.getHelpID ());
            HelpCtx.setHelpIDString(getRootPane(), help.getHelpID());
        }
        // Refresh button list if it had already been created.
        if (haveCalledInitializeButtons) initializeButtons();
    }
}
 
Example 5
Source File: NbUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates unmodifiable copy of the original map converting <code>AttributeSet</code>s
 * to their immutable versions.
 */
public static Map<String, AttributeSet> immutize(Map<String, ? extends AttributeSet> map, Object... filterOutKeys) {
    Map<String, AttributeSet> immutizedMap = new HashMap<>();
    
    for(String name : map.keySet()) {
        AttributeSet attribs = map.get(name);
        
        if (filterOutKeys.length == 0) {
            immutizedMap.put(name, AttributesUtilities.createImmutable(attribs));
        } else {
            List<Object> pairs = new ArrayList<>();

            // filter out attributes specified by filterOutKeys
            first:
            for(Enumeration<? extends Object> keys = attribs.getAttributeNames(); keys.hasMoreElements(); ) {
                Object key = keys.nextElement();
                
                for(Object filterOutKey : filterOutKeys) {
                    if (Utilities.compareObjects(key, filterOutKey)) {
                        continue first;
                    }
                }
                
                pairs.add(key);
                pairs.add(attribs.getAttribute(key));
            }

            immutizedMap.put(name, AttributesUtilities.createImmutable(pairs.toArray()));
        }
    }
    
    return Collections.unmodifiableMap(immutizedMap);
}
 
Example 6
Source File: BrandingSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void setBrandingSource(@NonNull URL brandingSource) {
    Parameters.notNull("brandingSource", brandingSource);
    if (!Utilities.compareObjects(brandingSource, this.brandingSource)) {
        modified = true;
    }
    this.brandingSource = brandingSource;
}
 
Example 7
Source File: EditorSettingsStorageTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void setOneKeyBinding(String mimeType, MultiKeyBinding keyBinding) {
    KeyBindingSettingsFactory kbsf = EditorSettingsImpl.getDefault().getKeyBindingSettings(new String [] { mimeType });
    List<MultiKeyBinding> all = new ArrayList<MultiKeyBinding>(kbsf.getKeyBindingDefaults(EditorSettingsImpl.DEFAULT_PROFILE));

    for(Iterator<MultiKeyBinding> i = all.iterator(); i.hasNext(); ) {
        MultiKeyBinding kb = (MultiKeyBinding) i.next();
        if (Utilities.compareObjects(kb.getActionName(), keyBinding.getActionName())) {
            i.remove();
            break;
        }
    }

    all.add(keyBinding);
    kbsf.setKeyBindings(EditorSettingsImpl.DEFAULT_PROFILE, all);
}
 
Example 8
Source File: LibrariesCustomizer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean isValidName(
        final @NonNull LibrariesModel model,
        final @NonNull String name,
        final @NullAllowed LibraryStorageArea area) {
    for (LibraryImplementation lib : model.getLibraries()) {
        if (lib.getName().equals(name) && Utilities.compareObjects(model.getArea(lib), area)) {
            return false;
        }
    }
    return true;
}
 
Example 9
Source File: HudsonJobImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override boolean equals(Object o) {
    if (!(o instanceof HudsonJobImpl)) {
        return false;
    }
    
    final HudsonJobImpl j = (HudsonJobImpl) o;
    
    if (!Utilities.compareObjects(getDisplayName(), j.getDisplayName())) {
        return false;
    }
    if (!Utilities.compareObjects(getName(), j.getName())) {
        return false;
    }
    if (!Utilities.compareObjects(getUrl(), j.getUrl())) {
        return false;
    }
    if (!Utilities.compareObjects(getColor(), j.getColor())) {
        return false;
    }
    if (isInQueue() != j.isInQueue()) {
        return false;
    }
    if (isBuildable() != j.isBuildable()) {
        return false;
    }
    if (!Utilities.compareObjects(views, j.views)) {
        return false;
    }
    if (getLastCompletedBuild() != j.getLastCompletedBuild()) {
        return false;
    }
    if (!mavenModules.equals(j.mavenModules)) {
        return false;
    }
    
    return true;
}
 
Example 10
Source File: Mnemonics.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void propertyChange(PropertyChangeEvent evt) {
    AbstractButton b = (AbstractButton) evt.getSource();
    if (b.getDisplayedMnemonicIndex() == -1) {
        Integer mnemonic = (Integer) b.getClientProperty(PROP_MNEMONIC);
        Integer index = (Integer) b.getClientProperty(PROP_DISPLAYED_MNEMONIC_INDEX);
        if (mnemonic != null && index != null && Utilities.compareObjects(b.getText(), b.getClientProperty(PROP_TEXT))) {
            b.setMnemonic(mnemonic);
            b.setDisplayedMnemonicIndex(index);
        }
    }
}
 
Example 11
Source File: LibrariesCustomizer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static boolean isExistingDisplayName(
        final @NonNull LibrariesModel model,
        final @NonNull String name,
        final @NullAllowed LibraryStorageArea area) {
    for (LibraryImplementation lib : model.getLibraries()) {
        if (LibrariesSupport.getLocalizedName(lib).equals(name) && Utilities.compareObjects(model.getArea(lib), area)) {
            return true;
        }
    }
    return false;
}
 
Example 12
Source File: MacrosModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void setCode(String code) {
    if (Utilities.compareObjects(getCode(), code)) {
        return;
    }
    
    cloneOnModify();
    
    String oldCode = this.code;
    this.code = code;

    pcs.firePropertyChange(PROP_CODE, oldCode, code);
    model.fireChanged();
}
 
Example 13
Source File: IntrospectedInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (!(o instanceof IntrospectedClass)) {
        return false;
    }
    IntrospectedClass other = (IntrospectedClass)o;
    return supportsText == other.supportsText &&
        Utilities.compareObjects(attrs, other.attrs) &&
        Utilities.compareObjects(subs, other.subs) &&
        Utilities.compareObjects(enumTags, other.enumTags);
}
 
Example 14
Source File: ActionsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public boolean equals(Object obj) {
    if (!(obj instanceof AntTargetInvocation)) {
        return false;
    }
    AntTargetInvocation other = (AntTargetInvocation) obj;
    return other.scriptFile == scriptFile &&
        Utilities.compareObjects(other.targetNameArray, targetNameArray) &&
        other.normalizedProps().equals(normalizedProps());
}
 
Example 15
Source File: CPExtender.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean addRemoveJAR(File jar, POMModel mdl, String scope, boolean add) throws IOException {
    if (!add) {
        throw new UnsupportedOperationException("removing JARs not yet supported");
    }
    NBVersionInfo dep = null;
    for (NBVersionInfo _dep : RepositoryQueries.findBySHA1Result(jar, RepositoryPreferences.getInstance().getRepositoryInfos()).getResults()) {
        if (!"unknown.binary".equals(_dep.getGroupId())) {
            dep = _dep;
            break;
        }
    }
    if (dep == null) {
        dep = new NBVersionInfo(null, "unknown.binary", jar.getName().replaceFirst("[.]jar$", ""), "SNAPSHOT", null, null, null, null, null);
        addJarToPrivateRepo(jar, mdl, dep);
    }
    //if not found anywhere, add to a custom file:// based repository structure within the project's directory.
    boolean added = false;
    Dependency dependency = ModelUtils.checkModelDependency(mdl, dep.getGroupId(), dep.getArtifactId(), false);
    if (dependency == null) {
        dependency = ModelUtils.checkModelDependency(mdl, dep.getGroupId(), dep.getArtifactId(), true);
        LOG.log(Level.FINE, "added new dep {0} as {1}", new Object[] {jar, dep});
        added = true;
    }
    if (!Utilities.compareObjects(dep.getVersion(), dependency.getVersion())) {
        dependency.setVersion(dep.getVersion());
        LOG.log(Level.FINE, "upgraded version on {0} as {1}", new Object[] {jar, dep});
        added = true;
    }
    if (!Utilities.compareObjects(scope, dependency.getScope())) {
        dependency.setScope(scope);
        LOG.log(Level.FINE, "changed scope on {0} as {1}", new Object[] {jar, dep});
        added = true;
    }
    return added;
}
 
Example 16
Source File: ComboBoxUpdater.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Messages("HINT_inherited=Value is inherited from parent POM.")
    private void setComboValue(T value, T projectValue, JComboBox field) {
        if (!Utilities.compareObjects(value, projectValue)) {
            field.setSelectedItem(value != null ? value : field.getModel().getElementAt(0));
            component.setToolTipText(null);
            inherited = false;
            label.setFont(label.getFont().deriveFont(Font.BOLD));
        } else {
            field.setSelectedItem(projectValue != null ? projectValue : field.getModel().getElementAt(0));
//            field.setBackground(INHERITED);
            label.setFont(label.getFont().deriveFont(Font.PLAIN));
            component.setToolTipText(HINT_inherited());
            inherited = true;
      }
    }
 
Example 17
Source File: SingleModuleProperties.java    From netbeans with Apache License 2.0 4 votes vote down vote up
void setMajorReleaseVersion(String ver) {
    if (!Utilities.compareObjects(majorReleaseVersion, ver)) {
        majorReleaseVersion = ver;
        majorReleaseVersionChanged = true;
    }
}
 
Example 18
Source File: SingleModuleProperties.java    From netbeans with Apache License 2.0 4 votes vote down vote up
void setSpecificationVersion(String ver) {
    if (!Utilities.compareObjects(specificationVersion, ver)) {
        specificationVersion = ver;
        specificationVersionChanged = true;
    }
}
 
Example 19
Source File: SingleModuleProperties.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void setAutoUpdateShowInClient(Boolean autoUpdateShowInClient) {
    if (!Utilities.compareObjects(this.autoUpdateShowInClient, autoUpdateShowInClient)) {
        this.autoUpdateShowInClient = autoUpdateShowInClient;
        autoUpdateShowInClientChanged = true;
    }
}
 
Example 20
Source File: ActionsList.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static Pair convertImpl(List<FileObject> keys, boolean ignoreFolders,
        boolean prohibitSeparatorsAndActionNames)
{
    List<Object> all = new ArrayList<Object>();
    List<Action> actions = new ArrayList<Action>();

    for (FileObject item : keys) {
        DataObject dob;
        try {
            dob = DataObject.find(item);
            if (dob == null && prohibitSeparatorsAndActionNames) {
                if (LOG.isLoggable(Level.INFO)) {
                    LOG.info("ActionsList: DataObject is null for item=" + item + "\n"); //NOI18N
                }
            }
        } catch (DataObjectNotFoundException dnfe) {
            if (prohibitSeparatorsAndActionNames) {
                if (LOG.isLoggable(Level.INFO)) {
                    LOG.info("ActionsList: DataObject not found for item=" + item + "\n"); //NOI18N
                }
            } else {
                if (LOG.isLoggable(Level.FINE)) {
                    LOG.log(Level.FINE, "DataObject not found for action fileObject=" + item); //NOI18N
                }
            }
            continue; // ignore
        }

        Object toAdd = null;
        InstanceCookie ic = dob.getLookup().lookup(InstanceCookie.class);
        if (prohibitSeparatorsAndActionNames && ic == null) {
            if (LOG.isLoggable(Level.INFO)) {
                LOG.info("ActionsList: InstanceCookie not found for item=" + item + "\n"); //NOI18N
            }
            continue;
        }
        if (ic != null) {
            try {
                if (!isSeparator(ic)) {
                    toAdd = ic.instanceCreate();
                    if (toAdd == null && prohibitSeparatorsAndActionNames) {
                        if (LOG.isLoggable(Level.INFO)) {
                            LOG.info("ActionsList: InstanceCookie.instanceCreate() null for item=" + item + "\n"); //NOI18N
                        }
                    }
                }
            } catch (Exception e) {
                LOG.log(Level.INFO, "Can't instantiate object", e); //NOI18N
                continue;
            }
        } else if (dob instanceof DataFolder) {
            toAdd = dob;
        } else {
            toAdd = dob.getName();
        }

        // Filter out the same succeding items
        if (all.size() > 0) {
            Object lastOne = all.get(all.size() - 1);
            if (Utilities.compareObjects(lastOne, toAdd)) {
                continue;
            }
            if (isSeparator(lastOne) && isSeparator(toAdd)) {
                continue;
            }
        }
        
        if (toAdd instanceof Action) {
            Action action = (Action) toAdd;
            actions.add(action);
            AcceleratorBinding.setAccelerator(action, item);
        } else if (isSeparator(toAdd)) {
            if (prohibitSeparatorsAndActionNames) {
                if (LOG.isLoggable(Level.INFO)) {
                    LOG.info("ActionsList: Separator for item=" + item + "\n"); //NOI18N
                }
            }
            actions.add(null);
        }
        all.add(toAdd);
    }

    Pair p = new Pair();
    p.all = all.isEmpty() ? Collections.emptyList() : Collections.unmodifiableList(all);
    p.actions = actions.isEmpty() ? Collections.<Action>emptyList() : Collections.unmodifiableList(actions);
    return p;
}